diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-02-07 22:06:24 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-02-07 22:06:24 +0100 |
commit | 6992106dc7894fab3f620263e99b4083b36bf9e8 (patch) | |
tree | 2a3554cf7bfabfeee0cc56ca58b04773a902cb76 /image | |
parent | 0b6d9a47051be9ef4d064c6f7c60717da91d0bc2 (diff) | |
download | UXP-6992106dc7894fab3f620263e99b4083b36bf9e8.tar UXP-6992106dc7894fab3f620263e99b4083b36bf9e8.tar.gz UXP-6992106dc7894fab3f620263e99b4083b36bf9e8.tar.lz UXP-6992106dc7894fab3f620263e99b4083b36bf9e8.tar.xz UXP-6992106dc7894fab3f620263e99b4083b36bf9e8.zip |
Use existing image decoders to handle clipboard BMP data.
This gets rid of the old nsImageClipboard widget code in favor of using
the nsBMPDecoder in imglib.
Diffstat (limited to 'image')
-rw-r--r-- | image/DecoderFactory.cpp | 7 | ||||
-rw-r--r-- | image/DecoderFactory.h | 1 | ||||
-rw-r--r-- | image/decoders/nsBMPDecoder.cpp | 17 | ||||
-rw-r--r-- | image/decoders/nsBMPDecoder.h | 6 |
4 files changed, 26 insertions, 5 deletions
diff --git a/image/DecoderFactory.cpp b/image/DecoderFactory.cpp index 2085fb7c4..dffe4dc21 100644 --- a/image/DecoderFactory.cpp +++ b/image/DecoderFactory.cpp @@ -58,6 +58,10 @@ DecoderFactory::GetDecoderType(const char* aMimeType) } else if (!strcmp(aMimeType, IMAGE_BMP_MS)) { type = DecoderType::BMP; + // BMP_CLIPBOARD + } else if (!strcmp(aMimeType, IMAGE_BMP_MS_CLIPBOARD)) { + type = DecoderType::BMP_CLIPBOARD; + // ICO } else if (!strcmp(aMimeType, IMAGE_ICO)) { type = DecoderType::ICO; @@ -100,6 +104,9 @@ DecoderFactory::GetDecoder(DecoderType aType, case DecoderType::BMP: decoder = new nsBMPDecoder(aImage); break; + case DecoderType::BMP_CLIPBOARD: + decoder = new nsBMPDecoder(aImage, /* aForClipboard */ true); + break; case DecoderType::ICO: decoder = new nsICODecoder(aImage); break; diff --git a/image/DecoderFactory.h b/image/DecoderFactory.h index f8cf64cc6..5638789ff 100644 --- a/image/DecoderFactory.h +++ b/image/DecoderFactory.h @@ -34,6 +34,7 @@ enum class DecoderType GIF, JPEG, BMP, + BMP_CLIPBOARD, ICO, ICON, WEBP, diff --git a/image/decoders/nsBMPDecoder.cpp b/image/decoders/nsBMPDecoder.cpp index 42bb3486a..fc79c223d 100644 --- a/image/decoders/nsBMPDecoder.cpp +++ b/image/decoders/nsBMPDecoder.cpp @@ -185,9 +185,11 @@ nsBMPDecoder::nsBMPDecoder(RasterImage* aImage, State aState, size_t aLength) { } -// Constructor for normal BMP files. -nsBMPDecoder::nsBMPDecoder(RasterImage* aImage) - : nsBMPDecoder(aImage, State::FILE_HEADER, FILE_HEADER_LENGTH) +// Constructor for normal BMP files or from the clipboard. +nsBMPDecoder::nsBMPDecoder(RasterImage* aImage, bool aForClipboard) + : nsBMPDecoder(aImage, + aForClipboard ? State::CLIPBOARD_HEADER : State::FILE_HEADER, + aForClipboard ? BIHSIZE_FIELD_LENGTH : FILE_HEADER_LENGTH) { } @@ -455,6 +457,7 @@ nsBMPDecoder::DoDecode(SourceBufferIterator& aIterator, IResumable* aOnResume) [=](State aState, const char* aData, size_t aLength) { switch (aState) { case State::FILE_HEADER: return ReadFileHeader(aData, aLength); + case State::CLIPBOARD_HEADER: return ReadClipboardHeader(aData, aLength); case State::INFO_HEADER_SIZE: return ReadInfoHeaderSize(aData, aLength); case State::INFO_HEADER_REST: return ReadInfoHeaderRest(aData, aLength); case State::BITFIELDS: return ReadBitfields(aData, aLength); @@ -488,6 +491,14 @@ nsBMPDecoder::ReadFileHeader(const char* aData, size_t aLength) return Transition::To(State::INFO_HEADER_SIZE, BIHSIZE_FIELD_LENGTH); } +LexerTransition<nsBMPDecoder::State> +nsBMPDecoder::ReadClipboardHeader(const char* aData, size_t aLength) +{ + // With the clipboard, the data offset is the header length. + mH.mDataOffset = LittleEndian::readUint32(aData); + return ReadInfoHeaderSize(aData, aLength); +} + // We read the info header in two steps: (a) read the mBIHSize field to // determine how long the header is; (b) read the rest of the header. LexerTransition<nsBMPDecoder::State> diff --git a/image/decoders/nsBMPDecoder.h b/image/decoders/nsBMPDecoder.h index 0cf2af689..258381649 100644 --- a/image/decoders/nsBMPDecoder.h +++ b/image/decoders/nsBMPDecoder.h @@ -152,6 +152,7 @@ private: enum class State { FILE_HEADER, + CLIPBOARD_HEADER, INFO_HEADER_SIZE, INFO_HEADER_REST, BITFIELDS, @@ -164,8 +165,8 @@ private: RLE_ABSOLUTE }; - // This is the constructor used for normal BMP images. - explicit nsBMPDecoder(RasterImage* aImage); + // This is the constructor used for normal and clipboard BMP images. + explicit nsBMPDecoder(RasterImage* aImage, bool aForClipboard = false); // This is the constructor used for BMP resources in ICO images. nsBMPDecoder(RasterImage* aImage, uint32_t aDataOffset); @@ -180,6 +181,7 @@ private: void FinishRow(); LexerTransition<State> ReadFileHeader(const char* aData, size_t aLength); + LexerTransition<State> ReadClipboardHeader(const char* aData, size_t aLength); LexerTransition<State> ReadInfoHeaderSize(const char* aData, size_t aLength); LexerTransition<State> ReadInfoHeaderRest(const char* aData, size_t aLength); LexerTransition<State> ReadBitfields(const char* aData, size_t aLength); |