nsWebPDecoder.h (3090B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_image_decoders_nsWebPDecoder_h 8 #define mozilla_image_decoders_nsWebPDecoder_h 9 10 #include "Decoder.h" 11 #include "webp/demux.h" 12 #include "StreamingLexer.h" 13 #include "SurfacePipe.h" 14 15 namespace mozilla { 16 namespace image { 17 class RasterImage; 18 19 class nsWebPDecoder final : public Decoder { 20 public: 21 virtual ~nsWebPDecoder(); 22 23 DecoderType GetType() const override { return DecoderType::WEBP; } 24 25 protected: 26 LexerResult DoDecode(SourceBufferIterator& aIterator, 27 IResumable* aOnResume) override; 28 Maybe<glean::impl::MemoryDistributionMetric> SpeedMetric() const override; 29 30 private: 31 friend class DecoderFactory; 32 33 // Decoders should only be instantiated via DecoderFactory. 34 explicit nsWebPDecoder(RasterImage* aImage); 35 36 void ApplyColorProfile(const char* aProfile, size_t aLength); 37 38 LexerResult UpdateBuffer(SourceBufferIterator& aIterator, 39 SourceBufferIterator::State aState); 40 LexerResult ReadData(); 41 LexerResult ReadHeader(WebPDemuxer* aDemuxer, bool aIsComplete); 42 LexerResult ReadPayload(WebPDemuxer* aDemuxer, bool aIsComplete); 43 44 nsresult CreateFrame(const OrientedIntRect& aFrameRect); 45 void EndFrame(); 46 47 LexerResult ReadSingle(const uint8_t* aData, size_t aLength, 48 const OrientedIntRect& aFrameRect); 49 50 LexerResult ReadMultiple(WebPDemuxer* aDemuxer, bool aIsComplete); 51 52 /// The SurfacePipe used to write to the output surface. 53 SurfacePipe mPipe; 54 55 /// The buffer used to accumulate data until the complete WebP header is 56 /// received, if and only if the iterator is discontiguous. 57 Vector<uint8_t> mBufferedData; 58 59 /// The libwebp output buffer descriptor pointing to the decoded data. 60 WebPDecBuffer mBuffer; 61 62 /// The libwebp incremental decoder descriptor, wraps mBuffer. 63 WebPIDecoder* mDecoder; 64 65 /// Blend method for the current frame. 66 BlendMethod mBlend; 67 68 /// Disposal method for the current frame. 69 DisposalMethod mDisposal; 70 71 /// Frame timeout for the current frame; 72 FrameTimeout mTimeout; 73 74 /// Surface format for the current frame. 75 gfx::SurfaceFormat mFormat; 76 77 /// Frame rect for the current frame. 78 OrientedIntRect mFrameRect; 79 80 /// The last row of decoded pixels written to mPipe. 81 int mLastRow; 82 83 /// Number of decoded frames. 84 uint32_t mCurrentFrame; 85 86 /// Pointer to the start of the contiguous encoded image data. 87 const uint8_t* mData; 88 89 /// Length of data pointed to by mData. 90 size_t mLength; 91 92 /// True if the iterator has reached its end. 93 bool mIteratorComplete; 94 95 /// True if this decoding pass requires a WebPDemuxer. 96 bool mNeedDemuxer; 97 98 /// True if we have setup the color profile for the image. 99 bool mGotColorProfile; 100 }; 101 102 } // namespace image 103 } // namespace mozilla 104 105 #endif // mozilla_image_decoders_nsWebPDecoder_h