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" |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 uint32_t SkGifCodec::onGetFillValue(SkColorType colorType, SkAlphaType alphaType
) const { | 499 uint32_t SkGifCodec::onGetFillValue(SkColorType colorType, SkAlphaType alphaType
) const { |
500 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); | 500 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); |
501 return get_color_table_fill_value(colorType, colorPtr, fFillIndex); | 501 return get_color_table_fill_value(colorType, colorPtr, fFillIndex); |
502 } | 502 } |
503 | 503 |
504 SkCodec::Result SkGifCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, | 504 SkCodec::Result SkGifCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, |
505 const SkCodec::Options& opts, SkPMColor inputColorPtr[], int* inputColor
Count) { | 505 const SkCodec::Options& opts, SkPMColor inputColorPtr[], int* inputColor
Count) { |
506 return this->prepareToDecode(dstInfo, inputColorPtr, inputColorCount, this->
options()); | 506 return this->prepareToDecode(dstInfo, inputColorPtr, inputColorCount, this->
options()); |
507 } | 507 } |
508 | 508 |
| 509 void SkGifCodec::handleScanlineFrame(int count, int* rowsBeforeFrame, int* rowsI
nFrame) { |
| 510 if (fFrameIsSubset) { |
| 511 const int currRow = this->INHERITED::nextScanline(); |
| 512 |
| 513 // The number of rows that remain to be skipped before reaching rows tha
t we |
| 514 // actually must decode into. |
| 515 // This must be at least zero. We also make sure that it is less than o
r |
| 516 // equal to count, since we will skip at most count rows. |
| 517 *rowsBeforeFrame = SkTMin(count, SkTMax(0, fFrameRect.top() - currRow)); |
| 518 |
| 519 // Rows left to decode once we reach the start of the frame. |
| 520 const int rowsLeft = count - *rowsBeforeFrame; |
| 521 |
| 522 // Count the number of that extend beyond the bottom of the frame. We d
o not |
| 523 // need to decode into these rows. |
| 524 const int rowsAfterFrame = SkTMax(0, currRow + rowsLeft - fFrameRect.bot
tom()); |
| 525 |
| 526 // Set the actual number of source rows that we need to decode. |
| 527 *rowsInFrame = rowsLeft - rowsAfterFrame; |
| 528 } else { |
| 529 *rowsBeforeFrame = 0; |
| 530 *rowsInFrame = count; |
| 531 } |
| 532 } |
| 533 |
509 int SkGifCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { | 534 int SkGifCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { |
510 int rowsBeforeFrame = 0; | 535 int rowsBeforeFrame; |
511 int rowsAfterFrame = 0; | 536 int rowsInFrame; |
512 int rowsInFrame = count; | 537 this->handleScanlineFrame(count, &rowsBeforeFrame, &rowsInFrame); |
| 538 |
513 if (fFrameIsSubset) { | 539 if (fFrameIsSubset) { |
514 // Fill the requested rows | 540 // Fill the requested rows |
515 SkImageInfo fillInfo = this->dstInfo().makeWH(this->dstInfo().width(), c
ount); | 541 SkImageInfo fillInfo = this->dstInfo().makeWH(this->dstInfo().width(), c
ount); |
516 uint32_t fillValue = this->onGetFillValue(this->dstInfo().colorType(), | 542 uint32_t fillValue = this->onGetFillValue(this->dstInfo().colorType(), |
517 this->dstInfo().alphaType()); | 543 this->dstInfo().alphaType()); |
518 fSwizzler->fill(fillInfo, dst, rowBytes, fillValue, this->options().fZer
oInitialized); | 544 fSwizzler->fill(fillInfo, dst, rowBytes, fillValue, this->options().fZer
oInitialized); |
519 | 545 |
520 // Do nothing for rows before the image frame | 546 // Start to write pixels at the start of the image frame |
521 rowsBeforeFrame = SkTMax(0, fFrameRect.top() - this->INHERITED::nextScan
line()); | |
522 rowsInFrame = SkTMax(0, rowsInFrame - rowsBeforeFrame); | |
523 dst = SkTAddOffset<void>(dst, rowBytes * rowsBeforeFrame); | 547 dst = SkTAddOffset<void>(dst, rowBytes * rowsBeforeFrame); |
524 | |
525 // Do nothing for rows after the image frame | |
526 rowsAfterFrame = SkTMax(0, | |
527 this->INHERITED::nextScanline() + rowsInFrame - fFrameRect.botto
m()); | |
528 rowsInFrame = SkTMax(0, rowsInFrame - rowsAfterFrame); | |
529 } | 548 } |
530 | 549 |
531 for (int i = 0; i < rowsInFrame; i++) { | 550 for (int i = 0; i < rowsInFrame; i++) { |
532 if (!this->readRow()) { | 551 if (!this->readRow()) { |
533 return i + rowsBeforeFrame; | 552 return i + rowsBeforeFrame; |
534 } | 553 } |
535 fSwizzler->swizzle(dst, fSrcBuffer.get()); | 554 fSwizzler->swizzle(dst, fSrcBuffer.get()); |
536 dst = SkTAddOffset<void>(dst, rowBytes); | 555 dst = SkTAddOffset<void>(dst, rowBytes); |
537 } | 556 } |
538 | 557 |
539 return count; | 558 return count; |
540 } | 559 } |
541 | 560 |
| 561 bool SkGifCodec::onSkipScanlines(int count) { |
| 562 int rowsBeforeFrame; |
| 563 int rowsInFrame; |
| 564 this->handleScanlineFrame(count, &rowsBeforeFrame, &rowsInFrame); |
| 565 |
| 566 for (int i = 0; i < rowsInFrame; i++) { |
| 567 if (!this->readRow()) { |
| 568 return false; |
| 569 } |
| 570 } |
| 571 |
| 572 return true; |
| 573 } |
| 574 |
542 SkCodec::SkScanlineOrder SkGifCodec::onGetScanlineOrder() const { | 575 SkCodec::SkScanlineOrder SkGifCodec::onGetScanlineOrder() const { |
543 if (fGif->Image.Interlace) { | 576 if (fGif->Image.Interlace) { |
544 return kOutOfOrder_SkScanlineOrder; | 577 return kOutOfOrder_SkScanlineOrder; |
545 } | 578 } |
546 return kTopDown_SkScanlineOrder; | 579 return kTopDown_SkScanlineOrder; |
547 } | 580 } |
548 | 581 |
549 int SkGifCodec::onOutputScanline(int inputScanline) const { | 582 int SkGifCodec::onOutputScanline(int inputScanline) const { |
550 if (fGif->Image.Interlace) { | 583 if (fGif->Image.Interlace) { |
551 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott
om()) { | 584 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott
om()) { |
552 return inputScanline; | 585 return inputScanline; |
553 } | 586 } |
554 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram
eRect.height()) + | 587 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram
eRect.height()) + |
555 fFrameRect.top(); | 588 fFrameRect.top(); |
556 } | 589 } |
557 return inputScanline; | 590 return inputScanline; |
558 } | 591 } |
OLD | NEW |