Bug 1708519 [wpt PR 28744] - Fix #28743: make the status checkboxes on the th.js...
[gecko.git] / image / decoders / nsWebPDecoder.h
blob94ccce2f31f9ad77c10336cb8cd16cafceb86b6a
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 nsIntRect& aFrameRect);
45 void EndFrame();
47 LexerResult ReadSingle(const uint8_t* aData, size_t aLength,
48 const gfx::IntRect& 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 gfx::IntRect 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