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
11 #include "webp/demux.h"
12 #include "StreamingLexer.h"
13 #include "SurfacePipe.h"
19 class nsWebPDecoder final
: public Decoder
{
21 virtual ~nsWebPDecoder();
23 DecoderType
GetType() const override
{ return DecoderType::WEBP
; }
26 LexerResult
DoDecode(SourceBufferIterator
& aIterator
,
27 IResumable
* aOnResume
) override
;
28 Maybe
<Telemetry::HistogramID
> SpeedHistogram() const override
;
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
);
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.
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.
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.
83 /// Number of decoded frames.
84 uint32_t mCurrentFrame
;
86 /// Pointer to the start of the contiguous encoded image data.
89 /// Length of data pointed to by mData.
92 /// True if the iterator has reached its end.
93 bool mIteratorComplete
;
95 /// True if this decoding pass requires a WebPDemuxer.
98 /// True if we have setup the color profile for the image.
99 bool mGotColorProfile
;
103 } // namespace mozilla
105 #endif // mozilla_image_decoders_nsWebPDecoder_h