OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCodec.h" | 8 #include "SkCodec.h" |
9 #include "SkCodecAnimation.h" | 9 #include "SkCodecAnimation.h" |
10 #include "SkColorSpace.h" | 10 #include "SkColorSpace.h" |
11 #include "SkColorTable.h" | 11 #include "SkColorTable.h" |
12 #include "SkImageInfo.h" | 12 #include "SkImageInfo.h" |
13 #include "SkSwizzler.h" | 13 #include "SkSwizzler.h" |
14 | 14 |
15 #include "GIFImageReader.h" | 15 #include "SkGifImageReader.h" |
16 | 16 |
17 /* | 17 /* |
18 * | 18 * |
19 * This class implements the decoding for gif images | 19 * This class implements the decoding for gif images |
20 * | 20 * |
21 */ | 21 */ |
22 class SkGifCodec : public SkCodec { | 22 class SkGifCodec : public SkCodec { |
23 public: | 23 public: |
24 static bool IsGif(const void*, size_t); | 24 static bool IsGif(const void*, size_t); |
25 | 25 |
26 /* | 26 /* |
27 * Assumes IsGif was called and returned true | 27 * Assumes IsGif was called and returned true |
28 * Creates a gif decoder | 28 * Creates a gif decoder |
29 * Reads enough of the stream to determine the image format | 29 * Reads enough of the stream to determine the image format |
30 */ | 30 */ |
31 static SkCodec* NewFromStream(SkStream*); | 31 static SkCodec* NewFromStream(SkStream*); |
32 | 32 |
33 // Callback for GIFImageReader when a row is available. | 33 // Callback for SkGifImageReader when a row is available. |
34 bool haveDecodedRow(size_t frameIndex, const unsigned char* rowBegin, | 34 bool haveDecodedRow(size_t frameIndex, const unsigned char* rowBegin, |
35 size_t rowNumber, unsigned repeatCount, bool writeTransp
arentPixels); | 35 size_t rowNumber, unsigned repeatCount, bool writeTransp
arentPixels); |
36 protected: | 36 protected: |
37 /* | 37 /* |
38 * Performs the full gif decode | 38 * Performs the full gif decode |
39 */ | 39 */ |
40 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, | 40 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, |
41 SkPMColor*, int*, int*) override; | 41 SkPMColor*, int*, int*) override; |
42 | 42 |
43 SkEncodedFormat onGetEncodedFormat() const override { | 43 SkEncodedFormat onGetEncodedFormat() const override { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 * it had to fill), including rows decoded by prior | 120 * it had to fill), including rows decoded by prior |
121 * calls to onIncrementalDecode. | 121 * calls to onIncrementalDecode. |
122 * @return kSuccess if the frame is complete, kIncompleteInput | 122 * @return kSuccess if the frame is complete, kIncompleteInput |
123 * otherwise. | 123 * otherwise. |
124 */ | 124 */ |
125 Result decodeFrame(bool firstAttempt, const Options& opts, int* rowsDecoded)
; | 125 Result decodeFrame(bool firstAttempt, const Options& opts, int* rowsDecoded)
; |
126 | 126 |
127 /* | 127 /* |
128 * Creates an instance of the decoder | 128 * Creates an instance of the decoder |
129 * Called only by NewFromStream | 129 * Called only by NewFromStream |
130 * Takes ownership of the GIFImageReader | 130 * Takes ownership of the SkGifImageReader |
131 */ | 131 */ |
132 SkGifCodec(const SkEncodedInfo&, const SkImageInfo&, GIFImageReader*); | 132 SkGifCodec(const SkEncodedInfo&, const SkImageInfo&, SkGifImageReader*); |
133 | 133 |
134 std::unique_ptr<GIFImageReader> fReader; | 134 std::unique_ptr<SkGifImageReader> fReader; |
135 std::unique_ptr<uint8_t[]> fTmpBuffer; | 135 std::unique_ptr<uint8_t[]> fTmpBuffer; |
136 std::unique_ptr<SkSwizzler> fSwizzler; | 136 std::unique_ptr<SkSwizzler> fSwizzler; |
137 sk_sp<SkColorTable> fCurrColorTable; | 137 sk_sp<SkColorTable> fCurrColorTable; |
138 // We may create a dummy table if there is not a Map in the input data. In | 138 // We may create a dummy table if there is not a Map in the input data. In |
139 // that case, we set this value to false, and we can skip a lot of decoding | 139 // that case, we set this value to false, and we can skip a lot of decoding |
140 // work (which would not be meaningful anyway). We create a "fake"/"dummy" | 140 // work (which would not be meaningful anyway). We create a "fake"/"dummy" |
141 // one in that case, so the client and the swizzler have something to draw. | 141 // one in that case, so the client and the swizzler have something to draw. |
142 bool fCurrColorTableIsReal; | 142 bool fCurrColorTableIsReal; |
143 // Whether the background was filled. | 143 // Whether the background was filled. |
144 bool fFilledBackground; | 144 bool fFilledBackground; |
145 // True on the first call to onIncrementalDecode. This value is passed to | 145 // True on the first call to onIncrementalDecode. This value is passed to |
146 // decodeFrame. | 146 // decodeFrame. |
147 bool fFirstCallToIncrementalDecode; | 147 bool fFirstCallToIncrementalDecode; |
148 | 148 |
149 void* fDst; | 149 void* fDst; |
150 size_t fDstRowBytes; | 150 size_t fDstRowBytes; |
151 | 151 |
152 // Updated inside haveDecodedRow when rows are decoded, unless we filled | 152 // Updated inside haveDecodedRow when rows are decoded, unless we filled |
153 // the background, in which case it is set once and left alone. | 153 // the background, in which case it is set once and left alone. |
154 int fRowsDecoded; | 154 int fRowsDecoded; |
155 | 155 |
156 typedef SkCodec INHERITED; | 156 typedef SkCodec INHERITED; |
157 }; | 157 }; |
OLD | NEW |