Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: src/images/SkImageDecoder_libgif.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/images/SkImageDecoder_libbmp.cpp ('k') | src/images/SkImageDecoder_libico.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkColor.h" 8 #include "SkColor.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkColorTable.h" 10 #include "SkColorTable.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 SkASSERT(fDeltaYPtr); 70 SkASSERT(fDeltaYPtr);
71 71
72 int y = fCurrY + fDeltaY; 72 int y = fCurrY + fDeltaY;
73 // We went from an if statement to a while loop so that we iterate 73 // We went from an if statement to a while loop so that we iterate
74 // through fStartYPtr until a valid row is found. This is so that images 74 // through fStartYPtr until a valid row is found. This is so that images
75 // that are smaller than 5x5 will not trash memory. 75 // that are smaller than 5x5 will not trash memory.
76 while (y >= fHeight) { 76 while (y >= fHeight) {
77 if (gStartingIterlaceYValue + 77 if (gStartingIterlaceYValue +
78 SK_ARRAY_COUNT(gStartingIterlaceYValue) == fStartYPtr) { 78 SK_ARRAY_COUNT(gStartingIterlaceYValue) == fStartYPtr) {
79 // we done 79 // we done
80 SkDEBUGCODE(fStartYPtr = NULL;) 80 SkDEBUGCODE(fStartYPtr = nullptr;)
81 SkDEBUGCODE(fDeltaYPtr = NULL;) 81 SkDEBUGCODE(fDeltaYPtr = nullptr;)
82 y = 0; 82 y = 0;
83 } else { 83 } else {
84 y = *fStartYPtr++; 84 y = *fStartYPtr++;
85 fDeltaY = *fDeltaYPtr++; 85 fDeltaY = *fDeltaYPtr++;
86 } 86 }
87 } 87 }
88 fCurrY = y; 88 fCurrY = y;
89 } 89 }
90 90
91 private: 91 private:
(...skipping 15 matching lines...) Expand all
107 void CheckFreeExtension(SavedImage* Image) { 107 void CheckFreeExtension(SavedImage* Image) {
108 if (Image->ExtensionBlocks) { 108 if (Image->ExtensionBlocks) {
109 #if GIFLIB_MAJOR < 5 109 #if GIFLIB_MAJOR < 5
110 FreeExtension(Image); 110 FreeExtension(Image);
111 #else 111 #else
112 GifFreeExtensions(&Image->ExtensionBlockCount, &Image->ExtensionBlocks); 112 GifFreeExtensions(&Image->ExtensionBlockCount, &Image->ExtensionBlocks);
113 #endif 113 #endif
114 } 114 }
115 } 115 }
116 116
117 // return NULL on failure 117 // return nullptr on failure
118 static const ColorMapObject* find_colormap(const GifFileType* gif) { 118 static const ColorMapObject* find_colormap(const GifFileType* gif) {
119 const ColorMapObject* cmap = gif->Image.ColorMap; 119 const ColorMapObject* cmap = gif->Image.ColorMap;
120 if (NULL == cmap) { 120 if (nullptr == cmap) {
121 cmap = gif->SColorMap; 121 cmap = gif->SColorMap;
122 } 122 }
123 123
124 if (NULL == cmap) { 124 if (nullptr == cmap) {
125 // no colormap found 125 // no colormap found
126 return NULL; 126 return nullptr;
127 } 127 }
128 // some sanity checks 128 // some sanity checks
129 if (cmap && ((unsigned)cmap->ColorCount > 256 || 129 if (cmap && ((unsigned)cmap->ColorCount > 256 ||
130 cmap->ColorCount != (1 << cmap->BitsPerPixel))) { 130 cmap->ColorCount != (1 << cmap->BitsPerPixel))) {
131 cmap = NULL; 131 cmap = nullptr;
132 } 132 }
133 return cmap; 133 return cmap;
134 } 134 }
135 135
136 // return -1 if not found (i.e. we're completely opaque) 136 // return -1 if not found (i.e. we're completely opaque)
137 static int find_transpIndex(const SavedImage& image, int colorCount) { 137 static int find_transpIndex(const SavedImage& image, int colorCount) {
138 int transpIndex = -1; 138 int transpIndex = -1;
139 for (int i = 0; i < image.ExtensionBlockCount; ++i) { 139 for (int i = 0; i < image.ExtensionBlockCount; ++i) {
140 const ExtensionBlock* eb = image.ExtensionBlocks + i; 140 const ExtensionBlock* eb = image.ExtensionBlocks + i;
141 if (eb->Function == 0xF9 && eb->ByteCount == 4) { 141 if (eb->Function == 0xF9 && eb->ByteCount == 4) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 * GIFs with fewer then 256 color entries will sometimes index out of 190 * GIFs with fewer then 256 color entries will sometimes index out of
191 * bounds of the color table (this is malformed, but libgif does not 191 * bounds of the color table (this is malformed, but libgif does not
192 * check sicne it is rare). This function checks for this error and 192 * check sicne it is rare). This function checks for this error and
193 * fixes it. This makes the output image consistantly deterministic. 193 * fixes it. This makes the output image consistantly deterministic.
194 */ 194 */
195 static void sanitize_indexed_bitmap(SkBitmap* bm) { 195 static void sanitize_indexed_bitmap(SkBitmap* bm) {
196 if ((kIndex_8_SkColorType == bm->colorType()) && !(bm->empty())) { 196 if ((kIndex_8_SkColorType == bm->colorType()) && !(bm->empty())) {
197 SkAutoLockPixels alp(*bm); 197 SkAutoLockPixels alp(*bm);
198 if (bm->getPixels()) { 198 if (bm->getPixels()) {
199 SkColorTable* ct = bm->getColorTable(); // Index8 must have it. 199 SkColorTable* ct = bm->getColorTable(); // Index8 must have it.
200 SkASSERT(ct != NULL); 200 SkASSERT(ct != nullptr);
201 uint32_t count = ct->count(); 201 uint32_t count = ct->count();
202 SkASSERT(count > 0); 202 SkASSERT(count > 0);
203 SkASSERT(count <= 0x100); 203 SkASSERT(count <= 0x100);
204 if (count != 0x100) { // Full colortables can't go wrong. 204 if (count != 0x100) { // Full colortables can't go wrong.
205 // Count is a power of 2; asserted elsewhere. 205 // Count is a power of 2; asserted elsewhere.
206 uint8_t byteMask = (~(count - 1)); 206 uint8_t byteMask = (~(count - 1));
207 bool warning = false; 207 bool warning = false;
208 uint8_t* addr = static_cast<uint8_t*>(bm->getPixels()); 208 uint8_t* addr = static_cast<uint8_t*>(bm->getPixels());
209 int height = bm->height(); 209 int height = bm->height();
210 int width = bm->width(); 210 int width = bm->width();
(...skipping 17 matching lines...) Expand all
228 } 228 }
229 } 229 }
230 } 230 }
231 231
232 namespace { 232 namespace {
233 // This function is a template argument, so can't be static. 233 // This function is a template argument, so can't be static.
234 int close_gif(GifFileType* gif) { 234 int close_gif(GifFileType* gif) {
235 #if GIFLIB_MAJOR < 5 || (GIFLIB_MAJOR == 5 && GIFLIB_MINOR == 0) 235 #if GIFLIB_MAJOR < 5 || (GIFLIB_MAJOR == 5 && GIFLIB_MINOR == 0)
236 return DGifCloseFile(gif); 236 return DGifCloseFile(gif);
237 #else 237 #else
238 return DGifCloseFile(gif, NULL); 238 return DGifCloseFile(gif, nullptr);
239 #endif 239 #endif
240 } 240 }
241 }//namespace 241 }//namespace
242 242
243 SkImageDecoder::Result SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap * bm, Mode mode) { 243 SkImageDecoder::Result SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap * bm, Mode mode) {
244 #if GIFLIB_MAJOR < 5 244 #if GIFLIB_MAJOR < 5
245 GifFileType* gif = DGifOpen(sk_stream, DecodeCallBackProc); 245 GifFileType* gif = DGifOpen(sk_stream, DecodeCallBackProc);
246 #else 246 #else
247 GifFileType* gif = DGifOpen(sk_stream, DecodeCallBackProc, NULL); 247 GifFileType* gif = DGifOpen(sk_stream, DecodeCallBackProc, nullptr);
248 #endif 248 #endif
249 if (NULL == gif) { 249 if (nullptr == gif) {
250 return error_return(*bm, "DGifOpen"); 250 return error_return(*bm, "DGifOpen");
251 } 251 }
252 252
253 SkAutoTCallIProc<GifFileType, close_gif> acp(gif); 253 SkAutoTCallIProc<GifFileType, close_gif> acp(gif);
254 254
255 SavedImage temp_save; 255 SavedImage temp_save;
256 temp_save.ExtensionBlocks=NULL; 256 temp_save.ExtensionBlocks=nullptr;
257 temp_save.ExtensionBlockCount=0; 257 temp_save.ExtensionBlockCount=0;
258 SkAutoTCallVProc<SavedImage, CheckFreeExtension> acp2(&temp_save); 258 SkAutoTCallVProc<SavedImage, CheckFreeExtension> acp2(&temp_save);
259 259
260 int width, height; 260 int width, height;
261 GifRecordType recType; 261 GifRecordType recType;
262 GifByteType *extData; 262 GifByteType *extData;
263 #if GIFLIB_MAJOR >= 5 263 #if GIFLIB_MAJOR >= 5
264 int extFunction; 264 int extFunction;
265 #endif 265 #endif
266 int transpIndex = -1; // -1 means we don't have it (yet) 266 int transpIndex = -1; // -1 means we don't have it (yet)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 return kSuccess; 330 return kSuccess;
331 } 331 }
332 332
333 333
334 // now we decode the colortable 334 // now we decode the colortable
335 int colorCount = 0; 335 int colorCount = 0;
336 { 336 {
337 // Declare colorPtr here for scope. 337 // Declare colorPtr here for scope.
338 SkPMColor colorPtr[256]; // storage for worst-case 338 SkPMColor colorPtr[256]; // storage for worst-case
339 const ColorMapObject* cmap = find_colormap(gif); 339 const ColorMapObject* cmap = find_colormap(gif);
340 if (cmap != NULL) { 340 if (cmap != nullptr) {
341 SkASSERT(cmap->ColorCount == (1 << (cmap->BitsPerPixel))); 341 SkASSERT(cmap->ColorCount == (1 << (cmap->BitsPerPixel)));
342 colorCount = cmap->ColorCount; 342 colorCount = cmap->ColorCount;
343 if (colorCount > 256) { 343 if (colorCount > 256) {
344 colorCount = 256; // our kIndex8 can't support more 344 colorCount = 256; // our kIndex8 can't support more
345 } 345 }
346 for (int index = 0; index < colorCount; index++) { 346 for (int index = 0; index < colorCount; index++) {
347 colorPtr[index] = SkPackARGB32(0xFF, 347 colorPtr[index] = SkPackARGB32(0xFF,
348 cmap->Colors[index].Red, 348 cmap->Colors[index].Red,
349 cmap->Colors[index].Green , 349 cmap->Colors[index].Green ,
350 cmap->Colors[index].Blue) ; 350 cmap->Colors[index].Blue) ;
351 } 351 }
352 } else { 352 } else {
353 // find_colormap() returned NULL. Some (rare, broken) 353 // find_colormap() returned nullptr. Some (rare, broken)
354 // GIFs don't have a color table, so we force one. 354 // GIFs don't have a color table, so we force one.
355 gif_warning(*bm, "missing colormap"); 355 gif_warning(*bm, "missing colormap");
356 colorCount = 256; 356 colorCount = 256;
357 sk_memset32(colorPtr, SK_ColorWHITE, colorCount); 357 sk_memset32(colorPtr, SK_ColorWHITE, colorCount);
358 } 358 }
359 transpIndex = find_transpIndex(temp_save, colorCount); 359 transpIndex = find_transpIndex(temp_save, colorCount);
360 if (transpIndex >= 0) { 360 if (transpIndex >= 0) {
361 colorPtr[transpIndex] = SK_ColorTRANSPARENT; // ram in a tra nsparent SkPMColor 361 colorPtr[transpIndex] = SK_ColorTRANSPARENT; // ram in a tra nsparent SkPMColor
362 fillIndex = transpIndex; 362 fillIndex = transpIndex;
363 } else if (fillIndex >= colorCount) { 363 } else if (fillIndex >= colorCount) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 case EXTENSION_RECORD_TYPE: 464 case EXTENSION_RECORD_TYPE:
465 #if GIFLIB_MAJOR < 5 465 #if GIFLIB_MAJOR < 5
466 if (DGifGetExtension(gif, &temp_save.Function, 466 if (DGifGetExtension(gif, &temp_save.Function,
467 &extData) == GIF_ERROR) { 467 &extData) == GIF_ERROR) {
468 #else 468 #else
469 if (DGifGetExtension(gif, &extFunction, &extData) == GIF_ERROR) { 469 if (DGifGetExtension(gif, &extFunction, &extData) == GIF_ERROR) {
470 #endif 470 #endif
471 return error_return(*bm, "DGifGetExtension"); 471 return error_return(*bm, "DGifGetExtension");
472 } 472 }
473 473
474 while (extData != NULL) { 474 while (extData != nullptr) {
475 /* Create an extension block with our data */ 475 /* Create an extension block with our data */
476 #if GIFLIB_MAJOR < 5 476 #if GIFLIB_MAJOR < 5
477 if (AddExtensionBlock(&temp_save, extData[0], 477 if (AddExtensionBlock(&temp_save, extData[0],
478 &extData[1]) == GIF_ERROR) { 478 &extData[1]) == GIF_ERROR) {
479 #else 479 #else
480 if (GifAddExtensionBlock(&temp_save.ExtensionBlockCount, 480 if (GifAddExtensionBlock(&temp_save.ExtensionBlockCount,
481 &temp_save.ExtensionBlocks, 481 &temp_save.ExtensionBlocks,
482 extFunction, 482 extFunction,
483 extData[0], 483 extData[0],
484 &extData[1]) == GIF_ERROR) { 484 &extData[1]) == GIF_ERROR) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 return true; 519 return true;
520 } 520 }
521 } 521 }
522 return false; 522 return false;
523 } 523 }
524 524
525 static SkImageDecoder* sk_libgif_dfactory(SkStreamRewindable* stream) { 525 static SkImageDecoder* sk_libgif_dfactory(SkStreamRewindable* stream) {
526 if (is_gif(stream)) { 526 if (is_gif(stream)) {
527 return new SkGIFImageDecoder; 527 return new SkGIFImageDecoder;
528 } 528 }
529 return NULL; 529 return nullptr;
530 } 530 }
531 531
532 static SkImageDecoder_DecodeReg gReg(sk_libgif_dfactory); 532 static SkImageDecoder_DecodeReg gReg(sk_libgif_dfactory);
533 533
534 static SkImageDecoder::Format get_format_gif(SkStreamRewindable* stream) { 534 static SkImageDecoder::Format get_format_gif(SkStreamRewindable* stream) {
535 if (is_gif(stream)) { 535 if (is_gif(stream)) {
536 return SkImageDecoder::kGIF_Format; 536 return SkImageDecoder::kGIF_Format;
537 } 537 }
538 return SkImageDecoder::kUnknown_Format; 538 return SkImageDecoder::kUnknown_Format;
539 } 539 }
540 540
541 static SkImageDecoder_FormatReg gFormatReg(get_format_gif); 541 static SkImageDecoder_FormatReg gFormatReg(get_format_gif);
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libbmp.cpp ('k') | src/images/SkImageDecoder_libico.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698