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 "SkCodecPriv.h" | 8 #include "SkCodecPriv.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkColorTable.h" | 10 #include "SkColorTable.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 */ | 42 */ |
43 static int32_t read_bytes_callback(GifFileType* fileType, GifByteType* out, int3
2_t size) { | 43 static int32_t read_bytes_callback(GifFileType* fileType, GifByteType* out, int3
2_t size) { |
44 SkStream* stream = (SkStream*) fileType->UserData; | 44 SkStream* stream = (SkStream*) fileType->UserData; |
45 return (int32_t) stream->read(out, size); | 45 return (int32_t) stream->read(out, size); |
46 } | 46 } |
47 | 47 |
48 /* | 48 /* |
49 * Open the gif file | 49 * Open the gif file |
50 */ | 50 */ |
51 static GifFileType* open_gif(SkStream* stream) { | 51 static GifFileType* open_gif(SkStream* stream) { |
| 52 #if GIFLIB_MAJOR < 5 |
| 53 return DGifOpen(stream, read_bytes_callback); |
| 54 #else |
52 return DGifOpen(stream, read_bytes_callback, nullptr); | 55 return DGifOpen(stream, read_bytes_callback, nullptr); |
| 56 #endif |
53 } | 57 } |
54 | 58 |
55 /* | 59 /* |
56 * Check if a there is an index of the color table for a transparent pixel | 60 * Check if a there is an index of the color table for a transparent pixel |
57 */ | 61 */ |
58 static uint32_t find_trans_index(const SavedImage& image) { | 62 static uint32_t find_trans_index(const SavedImage& image) { |
59 // If there is a transparent index specified, it will be contained in an | 63 // If there is a transparent index specified, it will be contained in an |
60 // extension block. We will loop through extension blocks in reverse order | 64 // extension block. We will loop through extension blocks in reverse order |
61 // to check the most recent extension blocks first. | 65 // to check the most recent extension blocks first. |
62 for (int32_t i = image.ExtensionBlockCount - 1; i >= 0; i--) { | 66 for (int32_t i = image.ExtensionBlockCount - 1; i >= 0; i--) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 114 } |
111 // Fourth pass | 115 // Fourth pass |
112 return 1 + 2 * (encodedRow - ceil_div(height, 2)); | 116 return 1 + 2 * (encodedRow - ceil_div(height, 2)); |
113 } | 117 } |
114 | 118 |
115 /* | 119 /* |
116 * This function cleans up the gif object after the decode completes | 120 * This function cleans up the gif object after the decode completes |
117 * It is used in a SkAutoTCallIProc template | 121 * It is used in a SkAutoTCallIProc template |
118 */ | 122 */ |
119 void SkGifCodec::CloseGif(GifFileType* gif) { | 123 void SkGifCodec::CloseGif(GifFileType* gif) { |
120 DGifCloseFile(gif, NULL); | 124 #if GIFLIB_MAJOR < 5 || (GIFLIB_MAJOR == 5 && GIFLIB_MINOR == 0) |
| 125 DGifCloseFile(gif); |
| 126 #else |
| 127 DGifCloseFile(gif, nullptr); |
| 128 #endif |
121 } | 129 } |
122 | 130 |
123 /* | 131 /* |
124 * This function free extension data that has been saved to assist the image | 132 * This function free extension data that has been saved to assist the image |
125 * decoder | 133 * decoder |
126 */ | 134 */ |
127 void SkGifCodec::FreeExtension(SavedImage* image) { | 135 void SkGifCodec::FreeExtension(SavedImage* image) { |
128 if (NULL != image->ExtensionBlocks) { | 136 if (NULL != image->ExtensionBlocks) { |
| 137 #if GIFLIB_MAJOR < 5 |
| 138 FreeExtension(image); |
| 139 #else |
129 GifFreeExtensions(&image->ExtensionBlockCount, &image->ExtensionBlocks); | 140 GifFreeExtensions(&image->ExtensionBlockCount, &image->ExtensionBlocks); |
| 141 #endif |
130 } | 142 } |
131 } | 143 } |
132 | 144 |
133 /* | 145 /* |
134 * Read enough of the stream to initialize the SkGifCodec. | 146 * Read enough of the stream to initialize the SkGifCodec. |
135 * Returns a bool representing success or failure. | 147 * Returns a bool representing success or failure. |
136 * | 148 * |
137 * @param codecOut | 149 * @param codecOut |
138 * If it returned true, and codecOut was not nullptr, | 150 * If it returned true, and codecOut was not nullptr, |
139 * codecOut will be set to a new SkGifCodec. | 151 * codecOut will be set to a new SkGifCodec. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // such as transparency or animation. | 316 // such as transparency or animation. |
305 case EXTENSION_RECORD_TYPE: | 317 case EXTENSION_RECORD_TYPE: |
306 // Read extension data | 318 // Read extension data |
307 if (GIF_ERROR == DGifGetExtension(gif, &extFunction, &extData))
{ | 319 if (GIF_ERROR == DGifGetExtension(gif, &extFunction, &extData))
{ |
308 return gif_error("Could not get extension.\n", kIncompleteIn
put); | 320 return gif_error("Could not get extension.\n", kIncompleteIn
put); |
309 } | 321 } |
310 | 322 |
311 // Create an extension block with our data | 323 // Create an extension block with our data |
312 while (nullptr != extData) { | 324 while (nullptr != extData) { |
313 // Add a single block | 325 // Add a single block |
| 326 |
| 327 #if GIFLIB_MAJOR < 5 |
| 328 if (AddExtensionBlock(&saveExt, extData[0], |
| 329 &extData[1]) == GIF_ERROR) { |
| 330 #else |
314 if (GIF_ERROR == GifAddExtensionBlock(&saveExt.ExtensionBloc
kCount, | 331 if (GIF_ERROR == GifAddExtensionBlock(&saveExt.ExtensionBloc
kCount, |
315 &saveExt.ExtensionBloc
ks, | 332 &saveExt.ExtensionBloc
ks, |
316 extFunction, extData[0
], &extData[1])) | 333 extFunction, extData[0
], &extData[1])) { |
317 { | 334 #endif |
318 return gif_error("Could not add extension block.\n", kIn
completeInput); | 335 return gif_error("Could not add extension block.\n", kIn
completeInput); |
319 } | 336 } |
320 // Move to the next block | 337 // Move to the next block |
321 if (GIF_ERROR == DGifGetExtensionNext(gif, &extData)) { | 338 if (GIF_ERROR == DGifGetExtensionNext(gif, &extData)) { |
322 return gif_error("Could not get next extension.\n", kInc
ompleteInput); | 339 return gif_error("Could not get next extension.\n", kInc
ompleteInput); |
323 } | 340 } |
324 } | 341 } |
325 break; | 342 break; |
326 | 343 |
327 // Signals the end of the gif file | 344 // Signals the end of the gif file |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 int SkGifCodec::onOutputScanline(int inputScanline) const { | 596 int SkGifCodec::onOutputScanline(int inputScanline) const { |
580 if (fGif->Image.Interlace) { | 597 if (fGif->Image.Interlace) { |
581 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott
om()) { | 598 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott
om()) { |
582 return inputScanline; | 599 return inputScanline; |
583 } | 600 } |
584 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram
eRect.height()) + | 601 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram
eRect.height()) + |
585 fFrameRect.top(); | 602 fFrameRect.top(); |
586 } | 603 } |
587 return inputScanline; | 604 return inputScanline; |
588 } | 605 } |
OLD | NEW |