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_libgif.h" | 8 #include "SkCodec_libgif.h" |
9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 || | 23 memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 || |
24 memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) | 24 memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) |
25 { | 25 { |
26 return true; | 26 return true; |
27 } | 27 } |
28 } | 28 } |
29 return false; | 29 return false; |
30 } | 30 } |
31 | 31 |
32 /* | 32 /* |
33 * Warning reporting function | |
34 */ | |
35 static void gif_warning(const char* msg) { | |
36 SkCodecPrintf("Gif Warning: %s\n", msg); | |
37 } | |
38 | |
39 /* | |
40 * Error function | 33 * Error function |
41 */ | 34 */ |
42 static SkCodec::Result gif_error(const char* msg, SkCodec::Result result = SkCod ec::kInvalidInput) { | 35 static SkCodec::Result gif_error(const char* msg, SkCodec::Result result = SkCod ec::kInvalidInput) { |
43 SkCodecPrintf("Gif Error: %s\n", msg); | 36 SkCodecPrintf("Gif Error: %s\n", msg); |
44 return result; | 37 return result; |
45 } | 38 } |
46 | 39 |
47 | 40 |
48 /* | 41 /* |
49 * Read function that will be passed to gif_lib | 42 * Read function that will be passed to gif_lib |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 return false; | 174 return false; |
182 } | 175 } |
183 // If reading the image descriptor is successful, the image count will be | 176 // If reading the image descriptor is successful, the image count will be |
184 // incremented. | 177 // incremented. |
185 SkASSERT(gif->ImageCount >= 1); | 178 SkASSERT(gif->ImageCount >= 1); |
186 | 179 |
187 if (nullptr != codecOut) { | 180 if (nullptr != codecOut) { |
188 SkISize size; | 181 SkISize size; |
189 SkIRect frameRect; | 182 SkIRect frameRect; |
190 if (!GetDimensions(gif, &size, &frameRect)) { | 183 if (!GetDimensions(gif, &size, &frameRect)) { |
191 gif_error("Invalid gif size.\n"); | 184 gif_error("Invalid gif size.\n"); |
scroggo
2015/10/15 12:49:54
I think this should return false. Otherwise, we go
msarett
2015/10/15 13:06:41
Of course, this is missing a return statement. I
| |
192 } | 185 } |
193 bool frameIsSubset = (size != frameRect.size()); | 186 bool frameIsSubset = (size != frameRect.size()); |
194 | 187 |
195 // Determine the recommended alpha type. The transIndex might be valid if it less | 188 // Determine the recommended alpha type. The transIndex might be valid if it less |
196 // than 256. We are not certain that the index is valid until we proces s the color | 189 // than 256. We are not certain that the index is valid until we proces s the color |
197 // table, since some gifs have color tables with less than 256 colors. If | 190 // table, since some gifs have color tables with less than 256 colors. If |
198 // there might be a valid transparent index, we must indicate that the i mage has | 191 // there might be a valid transparent index, we must indicate that the i mage has |
199 // alpha. | 192 // alpha. |
200 // In the case where we must support alpha, we have the option to set th e | 193 // In the case where we must support alpha, we have the option to set th e |
201 // suggested alpha type to kPremul or kUnpremul. Both are valid since t he alpha | 194 // suggested alpha type to kPremul or kUnpremul. Both are valid since t he alpha |
(...skipping 28 matching lines...) Expand all Loading... | |
230 return codec; | 223 return codec; |
231 } | 224 } |
232 return nullptr; | 225 return nullptr; |
233 } | 226 } |
234 | 227 |
235 SkGifCodec::SkGifCodec(const SkImageInfo& srcInfo, SkStream* stream, GifFileType * gif, | 228 SkGifCodec::SkGifCodec(const SkImageInfo& srcInfo, SkStream* stream, GifFileType * gif, |
236 uint32_t transIndex, const SkIRect& frameRect, bool frameIsSubset) | 229 uint32_t transIndex, const SkIRect& frameRect, bool frameIsSubset) |
237 : INHERITED(srcInfo, stream) | 230 : INHERITED(srcInfo, stream) |
238 , fGif(gif) | 231 , fGif(gif) |
239 , fSrcBuffer(new uint8_t[this->getInfo().width()]) | 232 , fSrcBuffer(new uint8_t[this->getInfo().width()]) |
233 , fFrameRect(frameRect) | |
240 // If it is valid, fTransIndex will be used to set fFillIndex. We don't kno w if | 234 // If it is valid, fTransIndex will be used to set fFillIndex. We don't kno w if |
241 // fTransIndex is valid until we process the color table, since fTransIndex may | 235 // fTransIndex is valid until we process the color table, since fTransIndex may |
242 // be greater than the size of the color table. | 236 // be greater than the size of the color table. |
243 , fTransIndex(transIndex) | 237 , fTransIndex(transIndex) |
244 // Default fFillIndex is 0. We will overwrite this if fTransIndex is valid, or if | 238 // Default fFillIndex is 0. We will overwrite this if fTransIndex is valid, or if |
245 // there is a valid background color. | 239 // there is a valid background color. |
246 , fFillIndex(0) | 240 , fFillIndex(0) |
247 , fFrameRect(frameRect) | |
248 , fFrameIsSubset(frameIsSubset) | 241 , fFrameIsSubset(frameIsSubset) |
242 , fSwizzler(NULL) | |
249 , fColorTable(NULL) | 243 , fColorTable(NULL) |
250 , fSwizzler(NULL) | |
251 {} | 244 {} |
252 | 245 |
253 bool SkGifCodec::onRewind() { | 246 bool SkGifCodec::onRewind() { |
254 GifFileType* gifOut = nullptr; | 247 GifFileType* gifOut = nullptr; |
255 if (!ReadHeader(this->stream(), nullptr, &gifOut)) { | 248 if (!ReadHeader(this->stream(), nullptr, &gifOut)) { |
256 return false; | 249 return false; |
257 } | 250 } |
258 | 251 |
259 SkASSERT(nullptr != gifOut); | 252 SkASSERT(nullptr != gifOut); |
260 fGif.reset(gifOut); | 253 fGif.reset(gifOut); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 | 353 |
361 // Ensure that the decode dimensions are large enough to contain the frame | 354 // Ensure that the decode dimensions are large enough to contain the frame |
362 width = SkTMax(width, frameWidth + frameLeft); | 355 width = SkTMax(width, frameWidth + frameLeft); |
363 height = SkTMax(height, frameHeight + frameTop); | 356 height = SkTMax(height, frameHeight + frameTop); |
364 | 357 |
365 // All of these dimensions should be positive, as they are encoded as unsign ed 16-bit integers. | 358 // All of these dimensions should be positive, as they are encoded as unsign ed 16-bit integers. |
366 // It is unclear why giflib casts them to ints. We will go ahead and check that they are | 359 // It is unclear why giflib casts them to ints. We will go ahead and check that they are |
367 // in fact positive. | 360 // in fact positive. |
368 if (frameLeft < 0 || frameTop < 0 || frameWidth < 0 || frameHeight < 0 || wi dth <= 0 || | 361 if (frameLeft < 0 || frameTop < 0 || frameWidth < 0 || frameHeight < 0 || wi dth <= 0 || |
369 height <= 0) { | 362 height <= 0) { |
363 size->set(0, 0); | |
scroggo
2015/10/15 12:49:53
I take it this fixes a warning that we read these
msarett
2015/10/15 13:06:40
Acknowledged.
| |
364 frameRect->setXYWH(0, 0, 0, 0); | |
370 return false; | 365 return false; |
371 } | 366 } |
372 | 367 |
373 frameRect->setXYWH(frameLeft, frameTop, frameWidth, frameHeight); | 368 frameRect->setXYWH(frameLeft, frameTop, frameWidth, frameHeight); |
374 size->set(width, height); | 369 size->set(width, height); |
375 return true; | 370 return true; |
376 } | 371 } |
377 | 372 |
378 void SkGifCodec::initializeColorTable(const SkImageInfo& dstInfo, SkPMColor* inp utColorPtr, | 373 void SkGifCodec::initializeColorTable(const SkImageInfo& dstInfo, SkPMColor* inp utColorPtr, |
379 int* inputColorCount) { | 374 int* inputColorCount) { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 | 582 |
588 int SkGifCodec::onOutputScanline(int inputScanline) const { | 583 int SkGifCodec::onOutputScanline(int inputScanline) const { |
589 if (fGif->Image.Interlace) { | 584 if (fGif->Image.Interlace) { |
590 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott om()) { | 585 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott om()) { |
591 return inputScanline; | 586 return inputScanline; |
592 } | 587 } |
593 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram eRect.height()); | 588 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram eRect.height()); |
594 } | 589 } |
595 return inputScanline; | 590 return inputScanline; |
596 } | 591 } |
OLD | NEW |