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 "SkBmpCodec.h" | 8 #include "SkBmpCodec.h" |
9 #include "SkBmpMaskCodec.h" | 9 #include "SkBmpMaskCodec.h" |
10 #include "SkBmpRLECodec.h" | 10 #include "SkBmpRLECodec.h" |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 return height - y - 1; | 549 return height - y - 1; |
550 } | 550 } |
551 | 551 |
552 /* | 552 /* |
553 * Get the destination row to start filling from | 553 * Get the destination row to start filling from |
554 * Used to fill the remainder of the image on incomplete input for bmps | 554 * Used to fill the remainder of the image on incomplete input for bmps |
555 * This is tricky since bmps may be kTopDown or kBottomUp. For kTopDown, | 555 * This is tricky since bmps may be kTopDown or kBottomUp. For kTopDown, |
556 * we start filling from where we left off, but for kBottomUp we start | 556 * we start filling from where we left off, but for kBottomUp we start |
557 * filling at the top of the image. | 557 * filling at the top of the image. |
558 */ | 558 */ |
559 void* SkBmpCodec::getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const
{ | 559 void* SkBmpCodec::onGetFillDst(void* dst, size_t dstRowBytes, uint32_t decodedSc
anlines) const { |
560 return (SkScanlineDecoder::kTopDown_SkScanlineOrder == fRowOrder) ? | 560 return (SkScanlineDecoder::kTopDown_SkScanlineOrder == fRowOrder) ? |
561 SkTAddOffset<void*>(dst, y * dstRowBytes) : dst; | 561 INHERITED::onGetFillDst(dst, dstRowBytes, decodedScanlines) : dst; |
562 } | 562 } |
563 | 563 |
564 /* | 564 /* |
565 * Compute the number of colors in the color table | 565 * Compute the number of colors in the color table |
566 */ | 566 */ |
567 uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) { | 567 uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) { |
568 // Zero is a default for maxColors | 568 // Zero is a default for maxColors |
569 // Also set numColors to maxColors when it is too large | 569 // Also set numColors to maxColors when it is too large |
570 uint32_t maxColors = 1 << fBitsPerPixel; | 570 uint32_t maxColors = 1 << fBitsPerPixel; |
571 if (numColors == 0 || numColors >= maxColors) { | 571 if (numColors == 0 || numColors >= maxColors) { |
572 return maxColors; | 572 return maxColors; |
573 } | 573 } |
574 return numColors; | 574 return numColors; |
575 } | 575 } |
576 | 576 |
577 /* | 577 /* |
578 * Scanline decoder for bmps | 578 * Scanline decoder for bmps |
579 */ | 579 */ |
580 class SkBmpScanlineDecoder : public SkScanlineDecoder { | 580 class SkBmpScanlineDecoder : public SkScanlineDecoder { |
581 public: | 581 public: |
582 SkBmpScanlineDecoder(SkBmpCodec* codec) | 582 SkBmpScanlineDecoder(SkBmpCodec* codec) |
583 : INHERITED(codec->getInfo()) | 583 : INHERITED(codec, codec->getInfo()) |
584 , fCodec(codec) | 584 , fCodec(codec) |
585 {} | 585 {} |
586 | 586 |
587 SkEncodedFormat onGetEncodedFormat() const override { | 587 SkEncodedFormat onGetEncodedFormat() const override { |
588 return kBMP_SkEncodedFormat; | 588 return kBMP_SkEncodedFormat; |
589 } | 589 } |
590 | 590 |
591 SkCodec::Result onStart(const SkImageInfo& dstInfo, const SkCodec::Options&
options, | 591 SkCodec::Result onStart(const SkImageInfo& dstInfo, const SkCodec::Options&
options, |
592 SkPMColor inputColorPtr[], int* inputColorCount) ove
rride { | 592 SkPMColor inputColorPtr[], int* inputColorCount) ove
rride { |
593 if (!fCodec->rewindIfNeeded()) { | 593 if (!fCodec->rewindIfNeeded()) { |
594 return SkCodec::kCouldNotRewind; | 594 return SkCodec::kCouldNotRewind; |
595 } | 595 } |
596 if (options.fSubset) { | 596 if (options.fSubset) { |
597 // Subsets are not supported. | 597 // Subsets are not supported. |
598 return SkCodec::kUnimplemented; | 598 return SkCodec::kUnimplemented; |
599 } | 599 } |
600 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | 600 if (dstInfo.dimensions() != this->getInfo().dimensions()) { |
601 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(),
dstInfo)) { | 601 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(),
dstInfo)) { |
602 return SkCodec::kInvalidScale; | 602 return SkCodec::kInvalidScale; |
603 } | 603 } |
604 } | 604 } |
605 if (!conversion_possible(dstInfo, this->getInfo())) { | 605 if (!conversion_possible(dstInfo, this->getInfo())) { |
606 SkCodecPrintf("Error: cannot convert input type to output type.\n"); | 606 SkCodecPrintf("Error: cannot convert input type to output type.\n"); |
607 return SkCodec::kInvalidConversion; | 607 return SkCodec::kInvalidConversion; |
608 } | 608 } |
609 | 609 |
610 return fCodec->prepareToDecode(dstInfo, options, inputColorPtr, inputCol
orCount); | 610 return fCodec->prepareToDecode(dstInfo, options, inputColorPtr, inputCol
orCount); |
611 } | 611 } |
612 | 612 |
613 SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) overri
de { | 613 uint32_t onGetScanlines(void* dst, int count, size_t rowBytes) override { |
614 // Create a new image info representing the portion of the image to deco
de | 614 // Create a new image info representing the portion of the image to deco
de |
615 SkImageInfo rowInfo = this->dstInfo().makeWH(this->dstInfo().width(), co
unt); | 615 SkImageInfo rowInfo = this->dstInfo().makeWH(this->dstInfo().width(), co
unt); |
616 | 616 |
617 // Decode the requested rows | 617 // Decode the requested rows |
618 return fCodec->decodeRows(rowInfo, dst, rowBytes, this->options()); | 618 return fCodec->decodeRows(rowInfo, dst, rowBytes, this->options()); |
619 } | 619 } |
620 | 620 |
621 SkScanlineOrder onGetScanlineOrder() const override { | 621 SkScanlineOrder onGetScanlineOrder() const override { |
622 return fCodec->fRowOrder; | 622 return fCodec->fRowOrder; |
623 } | 623 } |
624 | 624 |
625 int onGetY() const override { | 625 int onGetY(int encodedY) const override { |
626 return fCodec->getDstRow(this->INHERITED::onGetY(), this->dstInfo().heig
ht()); | 626 return fCodec->getDstRow(encodedY, this->dstInfo().height()); |
627 } | 627 } |
628 | 628 |
629 // TODO(msarett): Override default skipping with something more clever. | 629 // TODO(msarett): Override default skipping with something more clever. |
630 | 630 |
631 private: | 631 private: |
632 SkAutoTDelete<SkBmpCodec> fCodec; | 632 SkBmpCodec* fCodec; // Owned by parent class |
633 | 633 |
634 typedef SkScanlineDecoder INHERITED; | 634 typedef SkScanlineDecoder INHERITED; |
635 }; | 635 }; |
636 | 636 |
637 SkScanlineDecoder* SkBmpCodec::NewSDFromStream(SkStream* stream) { | 637 SkScanlineDecoder* SkBmpCodec::NewSDFromStream(SkStream* stream) { |
638 SkAutoTDelete<SkBmpCodec> codec(static_cast<SkBmpCodec*>(SkBmpCodec::NewFrom
Stream(stream))); | 638 SkAutoTDelete<SkBmpCodec> codec(static_cast<SkBmpCodec*>(SkBmpCodec::NewFrom
Stream(stream))); |
639 if (!codec) { | 639 if (!codec) { |
640 return NULL; | 640 return NULL; |
641 } | 641 } |
642 | 642 |
643 return SkNEW_ARGS(SkBmpScanlineDecoder, (codec.detach())); | 643 return SkNEW_ARGS(SkBmpScanlineDecoder, (codec.detach())); |
644 } | 644 } |
OLD | NEW |