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 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 return codec; | 528 return codec; |
529 } | 529 } |
530 return nullptr; | 530 return nullptr; |
531 } | 531 } |
532 | 532 |
533 SkBmpCodec::SkBmpCodec(const SkImageInfo& info, SkStream* stream, | 533 SkBmpCodec::SkBmpCodec(const SkImageInfo& info, SkStream* stream, |
534 uint16_t bitsPerPixel, SkCodec::SkScanlineOrder rowOrder) | 534 uint16_t bitsPerPixel, SkCodec::SkScanlineOrder rowOrder) |
535 : INHERITED(info, stream) | 535 : INHERITED(info, stream) |
536 , fBitsPerPixel(bitsPerPixel) | 536 , fBitsPerPixel(bitsPerPixel) |
537 , fRowOrder(rowOrder) | 537 , fRowOrder(rowOrder) |
| 538 , fSubsetLeft(0) |
| 539 , fSubsetWidth(this->getInfo().width()) |
538 {} | 540 {} |
539 | 541 |
540 bool SkBmpCodec::onRewind() { | 542 bool SkBmpCodec::onRewind() { |
541 return SkBmpCodec::ReadHeader(this->stream(), this->inIco(), nullptr); | 543 if (!SkBmpCodec::ReadHeader(this->stream(), this->inIco(), nullptr)) { |
| 544 return false; |
| 545 } |
| 546 |
| 547 fSubsetLeft = 0; |
| 548 fSubsetWidth = this->getInfo().width(); |
| 549 return true |
542 } | 550 } |
543 | 551 |
544 int32_t SkBmpCodec::getDstRow(int32_t y, int32_t height) const { | 552 int32_t SkBmpCodec::getDstRow(int32_t y, int32_t height) const { |
545 if (SkCodec::kTopDown_SkScanlineOrder == fRowOrder) { | 553 if (SkCodec::kTopDown_SkScanlineOrder == fRowOrder) { |
546 return y; | 554 return y; |
547 } | 555 } |
548 SkASSERT(SkCodec::kBottomUp_SkScanlineOrder == fRowOrder); | 556 SkASSERT(SkCodec::kBottomUp_SkScanlineOrder == fRowOrder); |
549 return height - y - 1; | 557 return height - y - 1; |
550 } | 558 } |
551 | 559 |
552 /* | 560 /* |
553 * Compute the number of colors in the color table | 561 * Compute the number of colors in the color table |
554 */ | 562 */ |
555 uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) { | 563 uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) { |
556 // Zero is a default for maxColors | 564 // Zero is a default for maxColors |
557 // Also set numColors to maxColors when it is too large | 565 // Also set numColors to maxColors when it is too large |
558 uint32_t maxColors = 1 << fBitsPerPixel; | 566 uint32_t maxColors = 1 << fBitsPerPixel; |
559 if (numColors == 0 || numColors >= maxColors) { | 567 if (numColors == 0 || numColors >= maxColors) { |
560 return maxColors; | 568 return maxColors; |
561 } | 569 } |
562 return numColors; | 570 return numColors; |
563 } | 571 } |
564 | 572 |
565 SkCodec::Result SkBmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, | 573 SkCodec::Result SkBmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, |
566 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { | 574 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount, |
| 575 int subsetLeft, int subsetWidth) { |
567 if (options.fSubset) { | 576 if (options.fSubset) { |
568 // Subsets are not supported. | 577 // Subsets are not supported. |
569 return kUnimplemented; | 578 return kUnimplemented; |
570 } | 579 } |
571 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | 580 if (dstInfo.dimensions() != this->getInfo().dimensions()) { |
572 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstI
nfo)) { | 581 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstI
nfo)) { |
573 return SkCodec::kInvalidScale; | 582 return SkCodec::kInvalidScale; |
574 } | 583 } |
575 } | 584 } |
576 if (!conversion_possible(dstInfo, this->getInfo())) { | 585 if (!conversion_possible(dstInfo, this->getInfo())) { |
577 SkCodecPrintf("Error: cannot convert input type to output type.\n"); | 586 SkCodecPrintf("Error: cannot convert input type to output type.\n"); |
578 return kInvalidConversion; | 587 return kInvalidConversion; |
579 } | 588 } |
580 | 589 |
581 return prepareToDecode(dstInfo, options, inputColorPtr, inputColorCount); | 590 this->fSubsetLeft = subsetLeft; |
| 591 this->fSubsetWidth = subsetWidth; |
| 592 return this->prepareToDecode(dstInfo, options, inputColorPtr, inputColorCoun
t); |
582 } | 593 } |
583 | 594 |
584 int SkBmpCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { | 595 int SkBmpCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { |
585 // Create a new image info representing the portion of the image to decode | 596 // Create a new image info representing the portion of the image to decode |
586 SkImageInfo rowInfo = this->dstInfo().makeWH(this->dstInfo().width(), count)
; | 597 SkImageInfo rowInfo = this->dstInfo().makeWH(this->dstInfo().width(), count)
; |
587 | 598 |
588 // Decode the requested rows | 599 // Decode the requested rows |
589 return this->decodeRows(rowInfo, dst, rowBytes, this->options()); | 600 return this->decodeRows(rowInfo, dst, rowBytes, this->options()); |
590 } | 601 } |
OLD | NEW |