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 "SkColorSpace.h" | 10 #include "SkColorSpace.h" |
10 #include "SkColorTable.h" | 11 #include "SkColorTable.h" |
11 #include "SkImageInfo.h" | 12 #include "SkImageInfo.h" |
12 #include "SkSwizzler.h" | 13 #include "SkSwizzler.h" |
13 | 14 |
14 struct GifFileType; | 15 struct GifFileType; |
15 struct SavedImage; | 16 struct SavedImage; |
16 | 17 |
17 /* | 18 /* |
18 * | 19 * |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 /* | 58 /* |
58 * Performs the full gif decode | 59 * Performs the full gif decode |
59 */ | 60 */ |
60 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, | 61 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, |
61 SkPMColor*, int*, int*) override; | 62 SkPMColor*, int*, int*) override; |
62 | 63 |
63 SkEncodedFormat onGetEncodedFormat() const override { | 64 SkEncodedFormat onGetEncodedFormat() const override { |
64 return kGIF_SkEncodedFormat; | 65 return kGIF_SkEncodedFormat; |
65 } | 66 } |
66 | 67 |
67 bool onRewind() override; | |
68 | |
69 uint64_t onGetFillValue(const SkImageInfo&) const override; | 68 uint64_t onGetFillValue(const SkImageInfo&) const override; |
70 | 69 |
71 int onOutputScanline(int inputScanline) const override; | 70 std::vector<FrameInfo> onGetFrameInfo() override; |
72 | 71 |
73 private: | 72 private: |
74 | 73 |
75 /* | |
76 * A gif can contain multiple image frames. We will only decode the first | |
77 * frame. This function reads up to the first image frame, processing | |
78 * transparency and/or animation information that comes before the image | |
79 * data. | |
80 * | |
81 * @param gif Pointer to the library type that manages the gif decode | |
82 * @param transIndex This call will set the transparent index based on the | |
83 * extension data. | |
84 */ | |
85 static Result ReadUpToFirstImage(GifFileType* gif, uint32_t* transIndex); | |
86 | |
87 /* | 74 /* |
88 * A gif may contain many image frames, all of different sizes. | 75 * A gif may contain many image frames, all of different sizes. |
89 * This function checks if the gif dimensions are valid, based on the frame | 76 * This function checks if the gif dimensions are valid, based on the frame |
90 * dimensions, and corrects the gif dimensions if necessary. | 77 * dimensions, and corrects the gif dimensions if necessary. |
91 * | 78 * |
92 * @param gif Pointer to the library type that manages the gif decode | 79 * @param gif Pointer to the library type that manages the gif decode |
93 * @param size Size of the image that we will decode. | 80 * @param size Size of the image that we will decode. |
94 * Will be set by this function if the return value is tru
e. | 81 * Will be set by this function if the return value is tru
e. |
95 * @param frameRect Contains the dimenions and offset of the first image fr
ame. | |
96 * Will be set by this function if the return value is tru
e. | |
97 * | 82 * |
98 * @return true on success, false otherwise | 83 * @return true on success, false otherwise |
99 */ | 84 */ |
100 static bool GetDimensions(GifFileType* gif, SkISize* size, SkIRect* frameRe
ct); | 85 static bool GetDimensions(GifFileType* gif, SkISize* size); |
101 | 86 |
102 /* | 87 /* |
103 * Initializes the color table that we will use for decoding. | 88 * Initializes the color table that we will use for decoding. |
104 * | 89 * |
105 * @param dstInfo Contains the requested dst color type. | 90 * @param dstInfo Contains the requested dst color type. |
106 * @param inputColorPtr Copies the encoded color table to the client's | 91 * @param inputColorPtr Copies the encoded color table to the client's |
107 * input color table if the client requests kIndex8. | 92 * input color table if the client requests kIndex8. |
108 * @param inputColorCount If the client requests kIndex8, sets | 93 * @param inputColorCount If the client requests kIndex8, sets |
109 * inputColorCount to 256. Since gifs always | 94 * inputColorCount to 256. Since gifs always |
110 * contain 8-bit indices, we need a 256 entry color | 95 * contain 8-bit indices, we need a 256 entry color |
111 * table to ensure that indexing is always in | 96 * table to ensure that indexing is always in |
112 * bounds. | 97 * bounds. |
113 */ | 98 */ |
114 void initializeColorTable(const SkImageInfo& dstInfo, SkPMColor* colorPtr, | 99 bool initializeColorTable(const SkImageInfo& dstInfo, SkPMColor* colorPtr, |
115 int* inputColorCount); | 100 int* inputColorCount); |
116 | 101 |
117 /* | 102 /* |
118 * Checks for invalid inputs and calls setFrameDimensions(), and | 103 * Checks for invalid inputs and calls setFrameDimensions(), and |
119 * initializeColorTable() in the proper sequence. | 104 * initializeColorTable() in the proper sequence. |
120 */ | 105 */ |
121 Result prepareToDecode(const SkImageInfo& dstInfo, SkPMColor* inputColorPtr, | 106 Result prepareToDecode(const SkImageInfo& dstInfo, SkPMColor* inputColorPtr, |
122 int* inputColorCount, const Options& opts); | 107 int* inputColorCount, const Options& opts); |
123 | 108 |
124 /* | 109 /* |
125 * Initializes the swizzler. | 110 * Recursive function to decode a frame. |
126 * | 111 * |
127 * @param dstInfo Output image information. Dimensions may have been | 112 * If !opts.fHasPriorFrame, and the frame is not independent, it will first |
128 * adjusted if the image frame size does not match the size | 113 * decode the frame that it depends on. |
129 * indicated in the header. | |
130 * @param options Informs the swizzler if destination memory is zero initia
lized. | |
131 * Contains subset information. | |
132 */ | 114 */ |
133 void initializeSwizzler(const SkImageInfo& dstInfo, | 115 void decodeFrame(const SkImageInfo& dstInfo, void* pixels, size_t dstRowByte
s, |
134 const Options& options); | 116 const Options& opts); |
135 | 117 |
136 SkSampler* getSampler(bool createIfNecessary) override { | 118 // FIXME: Old patch deletes this. Was that really necessary? |
137 SkASSERT(fSwizzler); | 119 // void initializeSwizzler(const SkImageInfo& dstInfo, |
138 return fSwizzler; | 120 // const Options& options); |
139 } | |
140 | |
141 /* | |
142 * @return true if the read is successful and false if the read fails. | |
143 */ | |
144 bool readRow(); | |
145 | |
146 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opts
, | |
147 SkPMColor inputColorPtr[], int* inputColorCount) override; | |
148 | |
149 int onGetScanlines(void* dst, int count, size_t rowBytes) override; | |
150 | |
151 bool onSkipScanlines(int count) override; | |
152 | |
153 /* | |
154 * For a scanline decode of "count" lines, this function indicates how | |
155 * many of the "count" lines should be skipped until we reach the top of | |
156 * the image frame and how many of the "count" lines are actually inside | |
157 * the image frame. | |
158 * | |
159 * @param count The number of scanlines requested. | |
160 * @param rowsBeforeFrame Output variable. The number of lines before | |
161 * we reach the top of the image frame. | |
162 * @param rowsInFrame Output variable. The number of lines to decode | |
163 * inside the image frame. | |
164 */ | |
165 void handleScanlineFrame(int count, int* rowsBeforeFrame, int* rowsInFrame); | |
166 | |
167 SkScanlineOrder onGetScanlineOrder() const override; | |
168 | 121 |
169 /* | 122 /* |
170 * This function cleans up the gif object after the decode completes | 123 * This function cleans up the gif object after the decode completes |
171 * It is used in a SkAutoTCallIProc template | 124 * It is used in a SkAutoTCallIProc template |
172 */ | 125 */ |
173 static void CloseGif(GifFileType* gif); | 126 static void CloseGif(GifFileType* gif); |
174 | 127 |
175 /* | 128 /* |
176 * Frees any extension data used in the decode | 129 * Frees any extension data used in the decode |
177 * Used in a SkAutoTCallVProc | 130 * Used in a SkAutoTCallVProc |
178 */ | 131 */ |
179 static void FreeExtension(SavedImage* image); | 132 static void FreeExtension(SavedImage* image); |
180 | 133 |
181 /* | 134 /* |
182 * Creates an instance of the decoder | 135 * Creates an instance of the decoder |
183 * Called only by NewFromStream | 136 * Called only by NewFromStream |
184 * | 137 * |
185 * @param info contains properties of the encoded data | 138 * @param info contains properties of the encoded data |
186 * @param stream the stream of image data | 139 * @param stream the stream of image data |
187 * @param gif pointer to library type that manages gif decode | 140 * @param gif pointer to library type that manages gif decode |
188 * takes ownership | 141 * takes ownership |
189 * @param transIndex The transparent index. An invalid value | 142 * @param transIndex The transparent index. An invalid value |
190 * indicates that there is no transparent index. | 143 * indicates that there is no transparent index. |
191 */ | 144 */ |
192 SkGifCodec(int width, int height, const SkEncodedInfo& info, SkStream* strea
m, | 145 SkGifCodec(int width, int height, const SkEncodedInfo& info, SkStream* strea
m, |
193 GifFileType* gif, uint32_t transIndex, const SkIRect& frameRect, boo
l frameIsSubset); | 146 GifFileType* gif, uint32_t transIndex); |
| 147 |
| 148 |
| 149 struct GifFrameInfo : public SkCodecAnimation::FrameInfo { |
| 150 uint32_t fTransIndex; |
| 151 }; |
194 | 152 |
195 SkAutoTCallVProc<GifFileType, CloseGif> fGif; // owned | 153 SkAutoTCallVProc<GifFileType, CloseGif> fGif; // owned |
196 SkAutoTDeleteArray<uint8_t> fSrcBuffer; | 154 SkAutoTDeleteArray<uint8_t> fSrcBuffer; |
197 const SkIRect fFrameRect; | |
198 const uint32_t fTransIndex; | |
199 uint32_t fFillIndex; | 155 uint32_t fFillIndex; |
200 const bool fFrameIsSubset; | |
201 SkAutoTDelete<SkSwizzler> fSwizzler; | 156 SkAutoTDelete<SkSwizzler> fSwizzler; |
202 SkAutoTUnref<SkColorTable> fColorTable; | 157 SkAutoTUnref<SkColorTable> fColorTable; |
| 158 std::vector<GifFrameInfo> fFrameInfos; |
203 | 159 |
204 typedef SkCodec INHERITED; | 160 typedef SkCodec INHERITED; |
205 }; | 161 }; |
OLD | NEW |