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

Side by Side Diff: src/codec/SkGifCodec.cpp

Issue 1757333002: Fix bug in SkGifCodec / Switch SkImageDec tests to use Codec (Closed) Base URL: https://skia.googlesource.com/skia.git@m50
Patch Set: Created 4 years, 9 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 | « no previous file | tests/BadIcoTest.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 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 colorCount = colorMap->ColorCount; 411 colorCount = colorMap->ColorCount;
412 // giflib guarantees these properties 412 // giflib guarantees these properties
413 SkASSERT(colorCount == (unsigned) (1 << (colorMap->BitsPerPixel))); 413 SkASSERT(colorCount == (unsigned) (1 << (colorMap->BitsPerPixel)));
414 SkASSERT(colorCount <= 256); 414 SkASSERT(colorCount <= 256);
415 for (uint32_t i = 0; i < colorCount; i++) { 415 for (uint32_t i = 0; i < colorCount; i++) {
416 colorPtr[i] = SkPackARGB32(0xFF, colorMap->Colors[i].Red, 416 colorPtr[i] = SkPackARGB32(0xFF, colorMap->Colors[i].Red,
417 colorMap->Colors[i].Green, colorMap->Colors[i].Blue); 417 colorMap->Colors[i].Green, colorMap->Colors[i].Blue);
418 } 418 }
419 } 419 }
420 420
421 // Gifs have the option to specify the color at a single index of the color
422 // table as transparent. If the transparent index is greater than the
423 // colorCount, we know that there is no valid transparent color in the color
424 // table. If there is not valid transparent index, we will try to use the
425 // backgroundIndex as the fill index. If the backgroundIndex is also not
426 // valid, we will let fFillIndex default to 0 (it is set to zero in the
427 // constructor). This behavior is not specified but matches
428 // SkImageDecoder_libgif.
429 uint32_t backgroundIndex = fGif->SBackGroundColor;
430 if (fTransIndex < colorCount) {
431 colorPtr[fTransIndex] = SK_ColorTRANSPARENT;
432 fFillIndex = fTransIndex;
433 } else if (backgroundIndex < colorCount) {
434 fFillIndex = backgroundIndex;
435 }
436
437 // Fill in the color table for indices greater than color count. 421 // Fill in the color table for indices greater than color count.
438 // This allows for predictable, safe behavior. 422 // This allows for predictable, safe behavior.
439 for (uint32_t i = colorCount; i < maxColors; i++) { 423 if (colorCount > 0) {
440 colorPtr[i] = colorPtr[fFillIndex]; 424 // Gifs have the option to specify the color at a single index of the co lor
425 // table as transparent. If the transparent index is greater than the
426 // colorCount, we know that there is no valid transparent color in the c olor
427 // table. If there is not valid transparent index, we will try to use t he
428 // backgroundIndex as the fill index. If the backgroundIndex is also no t
429 // valid, we will let fFillIndex default to 0 (it is set to zero in the
430 // constructor). This behavior is not specified but matches
431 // SkImageDecoder_libgif.
432 uint32_t backgroundIndex = fGif->SBackGroundColor;
433 if (fTransIndex < colorCount) {
434 colorPtr[fTransIndex] = SK_ColorTRANSPARENT;
435 fFillIndex = fTransIndex;
436 } else if (backgroundIndex < colorCount) {
437 fFillIndex = backgroundIndex;
438 }
439
440 for (uint32_t i = colorCount; i < maxColors; i++) {
441 colorPtr[i] = colorPtr[fFillIndex];
442 }
443 } else {
444 sk_memset32(colorPtr, 0xFF000000, maxColors);
441 } 445 }
442 446
443 fColorTable.reset(new SkColorTable(colorPtr, maxColors)); 447 fColorTable.reset(new SkColorTable(colorPtr, maxColors));
444 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount) ; 448 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount) ;
445 } 449 }
446 450
447 SkCodec::Result SkGifCodec::prepareToDecode(const SkImageInfo& dstInfo, SkPMColo r* inputColorPtr, 451 SkCodec::Result SkGifCodec::prepareToDecode(const SkImageInfo& dstInfo, SkPMColo r* inputColorPtr,
448 int* inputColorCount, const Options& opts) { 452 int* inputColorCount, const Options& opts) {
449 // Check for valid input parameters 453 // Check for valid input parameters
450 if (!conversion_possible(dstInfo, this->getInfo())) { 454 if (!conversion_possible(dstInfo, this->getInfo())) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 int SkGifCodec::onOutputScanline(int inputScanline) const { 599 int SkGifCodec::onOutputScanline(int inputScanline) const {
596 if (fGif->Image.Interlace) { 600 if (fGif->Image.Interlace) {
597 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott om()) { 601 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott om()) {
598 return inputScanline; 602 return inputScanline;
599 } 603 }
600 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram eRect.height()) + 604 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram eRect.height()) +
601 fFrameRect.top(); 605 fFrameRect.top();
602 } 606 }
603 return inputScanline; 607 return inputScanline;
604 } 608 }
OLDNEW
« no previous file with comments | « no previous file | tests/BadIcoTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698