| 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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 if (NULL == colorMap) { | 403 if (NULL == colorMap) { |
| 404 colorMap = fGif->SColorMap; | 404 colorMap = fGif->SColorMap; |
| 405 } | 405 } |
| 406 | 406 |
| 407 uint32_t colorCount = 0; | 407 uint32_t colorCount = 0; |
| 408 if (NULL != colorMap) { | 408 if (NULL != colorMap) { |
| 409 colorCount = colorMap->ColorCount; | 409 colorCount = colorMap->ColorCount; |
| 410 // giflib guarantees these properties | 410 // giflib guarantees these properties |
| 411 SkASSERT(colorCount == (unsigned) (1 << (colorMap->BitsPerPixel))); | 411 SkASSERT(colorCount == (unsigned) (1 << (colorMap->BitsPerPixel))); |
| 412 SkASSERT(colorCount <= 256); | 412 SkASSERT(colorCount <= 256); |
| 413 PackColorProc proc = choose_pack_color_proc(false, dstInfo.colorType()); |
| 413 for (uint32_t i = 0; i < colorCount; i++) { | 414 for (uint32_t i = 0; i < colorCount; i++) { |
| 414 colorPtr[i] = SkPackARGB32(0xFF, colorMap->Colors[i].Red, | 415 colorPtr[i] = proc(0xFF, colorMap->Colors[i].Red, |
| 415 colorMap->Colors[i].Green, colorMap->Colors[i].Blue); | 416 colorMap->Colors[i].Green, colorMap->Colors[i].Blue); |
| 416 } | 417 } |
| 417 } | 418 } |
| 418 | 419 |
| 419 // Fill in the color table for indices greater than color count. | 420 // Fill in the color table for indices greater than color count. |
| 420 // This allows for predictable, safe behavior. | 421 // This allows for predictable, safe behavior. |
| 421 if (colorCount > 0) { | 422 if (colorCount > 0) { |
| 422 // Gifs have the option to specify the color at a single index of the co
lor | 423 // Gifs have the option to specify the color at a single index of the co
lor |
| 423 // table as transparent. If the transparent index is greater than the | 424 // table as transparent. If the transparent index is greater than the |
| 424 // colorCount, we know that there is no valid transparent color in the c
olor | 425 // colorCount, we know that there is no valid transparent color in the c
olor |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 // Initialize color table and copy to the client if necessary | 458 // Initialize color table and copy to the client if necessary |
| 458 this->initializeColorTable(dstInfo, inputColorPtr, inputColorCount); | 459 this->initializeColorTable(dstInfo, inputColorPtr, inputColorCount); |
| 459 | 460 |
| 460 this->initializeSwizzler(dstInfo, opts); | 461 this->initializeSwizzler(dstInfo, opts); |
| 461 return kSuccess; | 462 return kSuccess; |
| 462 } | 463 } |
| 463 | 464 |
| 464 void SkGifCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& o
pts) { | 465 void SkGifCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& o
pts) { |
| 465 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); | 466 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); |
| 466 const SkIRect* frameRect = fFrameIsSubset ? &fFrameRect : nullptr; | 467 const SkIRect* frameRect = fFrameIsSubset ? &fFrameRect : nullptr; |
| 467 fSwizzler.reset(SkSwizzler::CreateSwizzler(SkSwizzler::kIndex, colorPtr, dst
Info, opts, | 468 fSwizzler.reset(SkSwizzler::CreateSwizzler(this->getEncodedInfo(), colorPtr,
dstInfo, opts, |
| 468 frameRect)); | 469 frameRect)); |
| 469 SkASSERT(fSwizzler); | 470 SkASSERT(fSwizzler); |
| 470 } | 471 } |
| 471 | 472 |
| 472 bool SkGifCodec::readRow() { | 473 bool SkGifCodec::readRow() { |
| 473 return GIF_ERROR != DGifGetLine(fGif, fSrcBuffer.get(), fFrameRect.width()); | 474 return GIF_ERROR != DGifGetLine(fGif, fSrcBuffer.get(), fFrameRect.width()); |
| 474 } | 475 } |
| 475 | 476 |
| 476 /* | 477 /* |
| 477 * Initiates the gif decode | 478 * Initiates the gif decode |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 int SkGifCodec::onOutputScanline(int inputScanline) const { | 598 int SkGifCodec::onOutputScanline(int inputScanline) const { |
| 598 if (fGif->Image.Interlace) { | 599 if (fGif->Image.Interlace) { |
| 599 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott
om()) { | 600 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott
om()) { |
| 600 return inputScanline; | 601 return inputScanline; |
| 601 } | 602 } |
| 602 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram
eRect.height()) + | 603 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram
eRect.height()) + |
| 603 fFrameRect.top(); | 604 fFrameRect.top(); |
| 604 } | 605 } |
| 605 return inputScanline; | 606 return inputScanline; |
| 606 } | 607 } |
| OLD | NEW |