From 35f9b857b0d7edbbd167d6a230ea9ad945bcbac8 Mon Sep 17 00:00:00 2001 From: Andrew Osmond Date: Sat, 22 Jul 2017 07:50:31 -0400 Subject: [PATCH] Bug 1315554 - Part 4. Combine nsICODecoder::ReadBMP and ::ReadPNG. r=tnikkel --- image/decoders/nsICODecoder.cpp | 24 ++++++------------------ image/decoders/nsICODecoder.h | 6 ++---- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/image/decoders/nsICODecoder.cpp b/image/decoders/nsICODecoder.cpp index 18a11473f6ea..b630633110fb 100644 --- a/image/decoders/nsICODecoder.cpp +++ b/image/decoders/nsICODecoder.cpp @@ -280,7 +280,7 @@ nsICODecoder::SniffResource(const char* aData) // Read in the rest of the PNG unbuffered. size_t toRead = mDirEntry.mBytesInRes - PNGSIGNATURESIZE; return Transition::ToUnbuffered(ICOState::FINISHED_RESOURCE, - ICOState::READ_PNG, + ICOState::READ_RESOURCE, toRead); } else { // Make sure we have a sane size for the bitmap information header. @@ -299,13 +299,13 @@ nsICODecoder::SniffResource(const char* aData) } LexerTransition -nsICODecoder::ReadPNG(const char* aData, uint32_t aLen) +nsICODecoder::ReadResource(const char* aData, uint32_t aLen) { if (!WriteToContainedDecoder(aData, aLen)) { return Transition::TerminateFailure(); } - return Transition::ContinueUnbuffered(ICOState::READ_PNG); + return Transition::ContinueUnbuffered(ICOState::READ_RESOURCE); } LexerTransition @@ -365,20 +365,10 @@ nsICODecoder::ReadBIH(const char* aData) // Read in the rest of the BMP unbuffered. return Transition::ToUnbuffered(afterBMPState, - ICOState::READ_BMP, + ICOState::READ_RESOURCE, bmpDataLength); } -LexerTransition -nsICODecoder::ReadBMP(const char* aData, uint32_t aLen) -{ - if (!WriteToContainedDecoder(aData, aLen)) { - return Transition::TerminateFailure(); - } - - return Transition::ContinueUnbuffered(ICOState::READ_BMP); -} - LexerTransition nsICODecoder::PrepareForMask() { @@ -568,12 +558,10 @@ nsICODecoder::DoDecode(SourceBufferIterator& aIterator, IResumable* aOnResume) return Transition::To(ICOState::SNIFF_RESOURCE, PNGSIGNATURESIZE); case ICOState::SNIFF_RESOURCE: return SniffResource(aData); - case ICOState::READ_PNG: - return ReadPNG(aData, aLength); + case ICOState::READ_RESOURCE: + return ReadResource(aData, aLength); case ICOState::READ_BIH: return ReadBIH(aData); - case ICOState::READ_BMP: - return ReadBMP(aData, aLength); case ICOState::PREPARE_FOR_MASK: return PrepareForMask(); case ICOState::READ_MASK_ROW: diff --git a/image/decoders/nsICODecoder.h b/image/decoders/nsICODecoder.h index 75206db333be..3fa5a31500dc 100644 --- a/image/decoders/nsICODecoder.h +++ b/image/decoders/nsICODecoder.h @@ -27,9 +27,8 @@ enum class ICOState SKIP_TO_RESOURCE, FOUND_RESOURCE, SNIFF_RESOURCE, - READ_PNG, + READ_RESOURCE, READ_BIH, - READ_BMP, PREPARE_FOR_MASK, READ_MASK_ROW, FINISH_MASK, @@ -93,9 +92,8 @@ private: LexerTransition ReadHeader(const char* aData); LexerTransition ReadDirEntry(const char* aData); LexerTransition SniffResource(const char* aData); - LexerTransition ReadPNG(const char* aData, uint32_t aLen); + LexerTransition ReadResource(const char* aData, uint32_t aLen); LexerTransition ReadBIH(const char* aData); - LexerTransition ReadBMP(const char* aData, uint32_t aLen); LexerTransition PrepareForMask(); LexerTransition ReadMaskRow(const char* aData); LexerTransition FinishMask();