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

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

Issue 1460073002: Implement SkGifCodec::onSkipScanlines() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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
« src/codec/SkCodec_libgif.h ('K') | « src/codec/SkCodec_libgif.h ('k') | no next file » | 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 "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
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) {
scroggo 2015/11/19 22:23:06 SkASSERT(fFrameIsSubset);
msarett 2015/11/19 22:39:22 Acknowledged.
510 // The number of rows that remain to be skipped before reaching rows that we
511 // actually must decode into.
512 // This must be at least zero. We also make sure that it is less than or
513 // equal to count, since we will skip at most count rows.
514 *rowsBeforeFrame = SkTMin(count, SkTMax(0, fFrameRect.top() - INHERITED::nex tScanline()));
scroggo 2015/11/19 22:23:06 Would it make sense to cache the value of nextScan
msarett 2015/11/19 22:39:22 Yeah I think so.
515
516 // Rows left to decode once we reach the start of the frame.
517 int rowsLeft = count - *rowsBeforeFrame;
scroggo 2015/11/19 22:23:06 could be const?
msarett 2015/11/19 22:39:22 Done.
518
519 // Count the number of that extend beyond the bottom of the frame. We do no t
520 // need to decode into these rows.
521 int rowsAfterFrame = SkTMax(0, INHERITED::nextScanline() + rowsLeft - fFrame Rect.bottom());
522
523 // Set the actual number of source rows that we need to decode.
524 *rowsInFrame = rowsLeft - rowsAfterFrame;
525 }
526
509 int SkGifCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { 527 int SkGifCodec::onGetScanlines(void* dst, int count, size_t rowBytes) {
510 int rowsBeforeFrame = 0; 528 int rowsBeforeFrame = 0;
511 int rowsAfterFrame = 0;
512 int rowsInFrame = count; 529 int rowsInFrame = count;
513 if (fFrameIsSubset) { 530 if (fFrameIsSubset) {
531 this->handleScanlineFrame(count, &rowsBeforeFrame, &rowsInFrame);
msarett 2015/11/19 21:37:23 We could do without the count parameter since we s
scroggo 2015/11/19 22:23:06 Either way. We sometimes use the same variable as
msarett 2015/11/19 22:39:22 Yeah I thought about doing it that way... I think
532
514 // Fill the requested rows 533 // Fill the requested rows
515 SkImageInfo fillInfo = this->dstInfo().makeWH(this->dstInfo().width(), c ount); 534 SkImageInfo fillInfo = this->dstInfo().makeWH(this->dstInfo().width(), c ount);
516 uint32_t fillValue = this->onGetFillValue(this->dstInfo().colorType(), 535 uint32_t fillValue = this->onGetFillValue(this->dstInfo().colorType(),
517 this->dstInfo().alphaType()); 536 this->dstInfo().alphaType());
518 fSwizzler->fill(fillInfo, dst, rowBytes, fillValue, this->options().fZer oInitialized); 537 fSwizzler->fill(fillInfo, dst, rowBytes, fillValue, this->options().fZer oInitialized);
519 538
520 // Do nothing for rows before the image frame 539 // 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); 540 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 } 541 }
530 542
531 for (int i = 0; i < rowsInFrame; i++) { 543 for (int i = 0; i < rowsInFrame; i++) {
532 if (!this->readRow()) { 544 if (!this->readRow()) {
533 return i + rowsBeforeFrame; 545 return i + rowsBeforeFrame;
534 } 546 }
535 fSwizzler->swizzle(dst, fSrcBuffer.get()); 547 fSwizzler->swizzle(dst, fSrcBuffer.get());
536 dst = SkTAddOffset<void>(dst, rowBytes); 548 dst = SkTAddOffset<void>(dst, rowBytes);
537 } 549 }
538 550
539 return count; 551 return count;
540 } 552 }
541 553
554 bool SkGifCodec::onSkipScanlines(int count) {
555 int rowsBeforeFrame = 0;
556 int rowsInFrame = count;
557 if (fFrameIsSubset) {
558 this->handleScanlineFrame(count, &rowsBeforeFrame, &rowsInFrame);
559 }
560
561 for (int i = 0; i < rowsInFrame; i++) {
562 if (!this->readRow()) {
563 return i + rowsBeforeFrame;
564 }
565 }
566
567 return count;
568 }
569
542 SkCodec::SkScanlineOrder SkGifCodec::onGetScanlineOrder() const { 570 SkCodec::SkScanlineOrder SkGifCodec::onGetScanlineOrder() const {
543 if (fGif->Image.Interlace) { 571 if (fGif->Image.Interlace) {
544 return kOutOfOrder_SkScanlineOrder; 572 return kOutOfOrder_SkScanlineOrder;
545 } 573 }
546 return kTopDown_SkScanlineOrder; 574 return kTopDown_SkScanlineOrder;
547 } 575 }
548 576
549 int SkGifCodec::onOutputScanline(int inputScanline) const { 577 int SkGifCodec::onOutputScanline(int inputScanline) const {
550 if (fGif->Image.Interlace) { 578 if (fGif->Image.Interlace) {
551 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott om()) { 579 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott om()) {
552 return inputScanline; 580 return inputScanline;
553 } 581 }
554 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram eRect.height()) + 582 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram eRect.height()) +
555 fFrameRect.top(); 583 fFrameRect.top();
556 } 584 }
557 return inputScanline; 585 return inputScanline;
558 } 586 }
OLDNEW
« src/codec/SkCodec_libgif.h ('K') | « src/codec/SkCodec_libgif.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698