| 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" |
| 11 #include "SkColorTable.h" | 11 #include "SkColorTable.h" |
| 12 #include "SkScaledCodec.h" | |
| 13 #include "SkStream.h" | 12 #include "SkStream.h" |
| 14 #include "SkSwizzler.h" | 13 #include "SkSwizzler.h" |
| 15 #include "SkUtils.h" | 14 #include "SkUtils.h" |
| 16 | 15 |
| 17 /* | 16 /* |
| 18 * Checks the start of the stream to see if the image is a gif | 17 * Checks the start of the stream to see if the image is a gif |
| 19 */ | 18 */ |
| 20 bool SkGifCodec::IsGif(SkStream* stream) { | 19 bool SkGifCodec::IsGif(SkStream* stream) { |
| 21 char buf[GIF_STAMP_LEN]; | 20 char buf[GIF_STAMP_LEN]; |
| 22 if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) { | 21 if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) { |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 477 |
| 479 // Initialize color table and copy to the client if necessary | 478 // Initialize color table and copy to the client if necessary |
| 480 this->initializeColorTable(dstInfo, inputColorPtr, inputColorCount); | 479 this->initializeColorTable(dstInfo, inputColorPtr, inputColorCount); |
| 481 return kSuccess; | 480 return kSuccess; |
| 482 } | 481 } |
| 483 | 482 |
| 484 SkCodec::Result SkGifCodec::initializeSwizzler(const SkImageInfo& dstInfo, | 483 SkCodec::Result SkGifCodec::initializeSwizzler(const SkImageInfo& dstInfo, |
| 485 ZeroInitialized zeroInit) { | 484 ZeroInitialized zeroInit) { |
| 486 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); | 485 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); |
| 487 fSwizzler.reset(SkSwizzler::CreateSwizzler(SkSwizzler::kIndex, | 486 fSwizzler.reset(SkSwizzler::CreateSwizzler(SkSwizzler::kIndex, |
| 488 colorPtr, dstInfo, zeroInit, this->getInfo())); | 487 colorPtr, dstInfo, zeroInit)); |
| 489 if (nullptr != fSwizzler.get()) { | 488 if (nullptr != fSwizzler.get()) { |
| 490 return kSuccess; | 489 return kSuccess; |
| 491 } | 490 } |
| 492 return kUnimplemented; | 491 return kUnimplemented; |
| 493 } | 492 } |
| 494 | 493 |
| 495 SkCodec::Result SkGifCodec::readRow() { | 494 SkCodec::Result SkGifCodec::readRow() { |
| 496 if (GIF_ERROR == DGifGetLine(fGif, fSrcBuffer.get(), fFrameDims.width())) { | 495 if (GIF_ERROR == DGifGetLine(fGif, fSrcBuffer.get(), fFrameDims.width())) { |
| 497 return kIncompleteInput; | 496 return kIncompleteInput; |
| 498 } | 497 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 } | 577 } |
| 579 | 578 |
| 580 SkCodec::Result SkGifCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, | 579 SkCodec::Result SkGifCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, |
| 581 const SkCodec::Options& opts, SkPMColor inputColorPtr[], int* inputColor
Count) { | 580 const SkCodec::Options& opts, SkPMColor inputColorPtr[], int* inputColor
Count) { |
| 582 Result result = this->prepareToDecode(dstInfo, inputColorPtr, inputColorCoun
t, | 581 Result result = this->prepareToDecode(dstInfo, inputColorPtr, inputColorCoun
t, |
| 583 this->options()); | 582 this->options()); |
| 584 if (kSuccess != result) { | 583 if (kSuccess != result) { |
| 585 return result; | 584 return result; |
| 586 } | 585 } |
| 587 | 586 |
| 588 // Check to see if scaling was requested. | |
| 589 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | |
| 590 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstI
nfo)) { | |
| 591 return gif_error("Scaling not supported.\n", SkCodec::kInvalidScale)
; | |
| 592 } | |
| 593 } | |
| 594 | |
| 595 // Initialize the swizzler | 587 // Initialize the swizzler |
| 596 if (fFrameIsSubset) { | 588 if (fFrameIsSubset) { |
| 597 int sampleX; | 589 const SkImageInfo subsetDstInfo = dstInfo.makeWH(fFrameDims.width(), fFr
ameDims.height()); |
| 598 SkScaledCodec::ComputeSampleSize(dstInfo, this->getInfo(), &sampleX, NUL
L); | |
| 599 const SkImageInfo subsetDstInfo = dstInfo.makeWH( | |
| 600 get_scaled_dimension(fFrameDims.width(), sampleX), | |
| 601 fFrameDims.height()); | |
| 602 if (kSuccess != this->initializeSwizzler(subsetDstInfo, opts.fZeroInitia
lized)) { | 590 if (kSuccess != this->initializeSwizzler(subsetDstInfo, opts.fZeroInitia
lized)) { |
| 603 return gif_error("Could not initialize swizzler.\n", kUnimplemented)
; | 591 return gif_error("Could not initialize swizzler.\n", kUnimplemented)
; |
| 604 } | 592 } |
| 605 } else { | 593 } else { |
| 606 if (kSuccess != this->initializeSwizzler(dstInfo, opts.fZeroInitialized)
) { | 594 if (kSuccess != this->initializeSwizzler(dstInfo, opts.fZeroInitialized)
) { |
| 607 return gif_error("Could not initialize swizzler.\n", kUnimplemented)
; | 595 return gif_error("Could not initialize swizzler.\n", kUnimplemented)
; |
| 608 } | 596 } |
| 609 } | 597 } |
| 610 | 598 |
| 611 return kSuccess; | 599 return kSuccess; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 } | 649 } |
| 662 | 650 |
| 663 int SkGifCodec::onNextScanline() const { | 651 int SkGifCodec::onNextScanline() const { |
| 664 if (fGif->Image.Interlace) { | 652 if (fGif->Image.Interlace) { |
| 665 return get_output_row_interlaced(this->INHERITED::onNextScanline(), this
->dstInfo().height()); | 653 return get_output_row_interlaced(this->INHERITED::onNextScanline(), this
->dstInfo().height()); |
| 666 } else { | 654 } else { |
| 667 return this->INHERITED::onNextScanline(); | 655 return this->INHERITED::onNextScanline(); |
| 668 } | 656 } |
| 669 } | 657 } |
| 670 | 658 |
| OLD | NEW |