no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / image / decoders / nsWebPDecoder.h
blobe69122d19a945787dda048cba6fcb4b245e2c019
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
7 #ifndef mozilla_image_decoders_nsWebPDecoder_h
8 #define mozilla_image_decoders_nsWebPDecoder_h
10 #include "Decoder.h"
11 #include "webp/demux.h"
12 #include "StreamingLexer.h"
13 #include "SurfacePipe.h"
15 namespace mozilla {
16 namespace image {
17 class RasterImage;
19 class nsWebPDecoder final : public Decoder {
20 public:
21 virtual ~nsWebPDecoder();
23 DecoderType GetType() const override { return DecoderType::WEBP; }
25 protected:
26 LexerResult DoDecode(SourceBufferIterator& aIterator,
27 IResumable* aOnResume) override;
28 Maybe<Telemetry::HistogramID> SpeedHistogram() const override;
30 private:
31 friend class DecoderFactory;
33 // Decoders should only be instantiated via DecoderFactory.
34 explicit nsWebPDecoder(RasterImage* aImage);
36 void ApplyColorProfile(const char* aProfile, size_t aLength);
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);
44 nsresult CreateFrame(const OrientedIntRect& aFrameRect);
45 void EndFrame();
47 LexerResult ReadSingle(const uint8_t* aData, size_t aLength,
48 const OrientedIntRect& aFrameRect);
50 LexerResult ReadMultiple(WebPDemuxer* aDemuxer, bool aIsComplete);
52 /// The SurfacePipe used to write to the output surface.
53 SurfacePipe mPipe;
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;
59 /// The libwebp output buffer descriptor pointing to the decoded data.
60 WebPDecBuffer mBuffer;
62 /// The libwebp incremental decoder descriptor, wraps mBuffer.
63 WebPIDecoder* mDecoder;
65 /// Blend method for the current frame.
66 BlendMethod mBlend;
68 /// Disposal method for the current frame.
69 DisposalMethod mDisposal;
71 /// Frame timeout for the current frame;
72 FrameTimeout mTimeout;
74 /// Surface format for the current frame.
75 gfx::SurfaceFormat mFormat;
77 /// Frame rect for the current frame.
78 OrientedIntRect mFrameRect;
80 /// The last row of decoded pixels written to mPipe.
81 int mLastRow;
83 /// Number of decoded frames.
84 uint32_t mCurrentFrame;
86 /// Pointer to the start of the contiguous encoded image data.
87 const uint8_t* mData;
89 /// Length of data pointed to by mData.
90 size_t mLength;
92 /// True if the iterator has reached its end.
93 bool mIteratorComplete;
95 /// True if this decoding pass requires a WebPDemuxer.
96 bool mNeedDemuxer;
98 /// True if we have setup the color profile for the image.
99 bool mGotColorProfile;
102 } // namespace image
103 } // namespace mozilla
105 #endif // mozilla_image_decoders_nsWebPDecoder_h