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

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

Issue 1287423002: Scanline decoding for bmp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments from previous patch sets Created 5 years, 3 months 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
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 "SkBmpCodec.h" 8 #include "SkBmpCodec.h"
9 #include "SkBmpMaskCodec.h" 9 #include "SkBmpMaskCodec.h"
10 #include "SkBmpRLECodec.h" 10 #include "SkBmpRLECodec.h"
11 #include "SkBmpStandardCodec.h" 11 #include "SkBmpStandardCodec.h"
12 #include "SkCodecPriv.h" 12 #include "SkCodecPriv.h"
13 #include "SkColorPriv.h" 13 #include "SkColorPriv.h"
14 #include "SkScaledCodec.h"
14 #include "SkStream.h" 15 #include "SkStream.h"
15 16
16 /* 17 /*
17 * Defines the version and type of the second bitmap header 18 * Defines the version and type of the second bitmap header
18 */ 19 */
19 enum BmpHeaderType { 20 enum BmpHeaderType {
20 kInfoV1_BmpHeaderType, 21 kInfoV1_BmpHeaderType,
21 kInfoV2_BmpHeaderType, 22 kInfoV2_BmpHeaderType,
22 kInfoV3_BmpHeaderType, 23 kInfoV3_BmpHeaderType,
23 kInfoV4_BmpHeaderType, 24 kInfoV4_BmpHeaderType,
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 uint16_t bitsPerPixel, RowOrder rowOrder) 534 uint16_t bitsPerPixel, RowOrder rowOrder)
534 : INHERITED(info, stream) 535 : INHERITED(info, stream)
535 , fBitsPerPixel(bitsPerPixel) 536 , fBitsPerPixel(bitsPerPixel)
536 , fRowOrder(rowOrder) 537 , fRowOrder(rowOrder)
537 {} 538 {}
538 539
539 bool SkBmpCodec::onRewind() { 540 bool SkBmpCodec::onRewind() {
540 return SkBmpCodec::ReadHeader(this->stream(), this->inIco(), NULL); 541 return SkBmpCodec::ReadHeader(this->stream(), this->inIco(), NULL);
541 } 542 }
542 543
544 int32_t SkBmpCodec::getDstRow(int32_t y, int32_t height) {
545 if (SkBmpCodec::kTopDown_RowOrder == fRowOrder) {
546 return y;
547 } else {
548 return height - y - 1;
549 }
550 }
551
543 /* 552 /*
544 * Get the destination row to start filling from 553 * Get the destination row to start filling from
545 * 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
546 * 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,
547 * 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
548 * filling at the top of the image. 557 * filling at the top of the image.
549 */ 558 */
550 void* SkBmpCodec::getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const { 559 void* SkBmpCodec::getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const {
551 return (kTopDown_RowOrder == fRowOrder) ? SkTAddOffset<void*>(dst, y * dstRo wBytes) : dst; 560 return (kTopDown_RowOrder == fRowOrder) ? SkTAddOffset<void*>(dst, y * dstRo wBytes) : dst;
552 } 561 }
553 562
554 /* 563 /*
555 * Compute the number of colors in the color table 564 * Compute the number of colors in the color table
556 */ 565 */
557 uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) { 566 uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) {
558 // Zero is a default for maxColors 567 // Zero is a default for maxColors
559 // Also set numColors to maxColors when it is too large 568 // Also set numColors to maxColors when it is too large
560 uint32_t maxColors = 1 << fBitsPerPixel; 569 uint32_t maxColors = 1 << fBitsPerPixel;
561 if (numColors == 0 || numColors >= maxColors) { 570 if (numColors == 0 || numColors >= maxColors) {
562 return maxColors; 571 return maxColors;
563 } 572 }
564 return numColors; 573 return numColors;
565 } 574 }
575
576 /*
577 * Scanline decoder for bmps
578 */
579 class SkBmpScanlineDecoder : public SkScanlineDecoder {
580 public:
581 SkBmpScanlineDecoder(SkBmpCodec* codec)
582 : INHERITED(codec->getInfo())
583 , fCodec(codec)
584 {}
585
586 SkEncodedFormat onGetEncodedFormat() const override {
587 return kBMP_SkEncodedFormat;
588 }
589
590 SkCodec::Result onStart(const SkImageInfo& dstInfo, const SkCodec::Options& options,
591 SkPMColor inputColorPtr[], int* inputColorCount) ove rride {
592 if (!fCodec->rewindIfNeeded()) {
593 return SkCodec::kCouldNotRewind;
594 }
595 if (options.fSubset) {
596 // Subsets are not supported.
597 return SkCodec::kUnimplemented;
598 }
599 if (dstInfo.dimensions() != this->getInfo().dimensions()) {
600 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstInfo)) {
601 return SkCodec::kInvalidScale;
602 }
603 }
604 if (!conversion_possible(dstInfo, this->getInfo())) {
605 SkCodecPrintf("Error: cannot convert input type to output type.\n");
606 return SkCodec::kInvalidConversion;
607 }
608
609 return fCodec->prepareToDecode(dstInfo, options, inputColorPtr, inputCol orCount);
610 }
611
612 SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) overri de {
613 // Create a new image info representing the portion of the image to deco de
614 SkImageInfo rowInfo = this->dstInfo().makeWH(this->dstInfo().width(), co unt);
615
616 // Decode the requested rows
617 return fCodec->decodeRows(rowInfo, dst, rowBytes, this->options());
618 }
619
620 SkScanlineOrder onGetScanlineOrder() const override {
621 if (SkBmpCodec::kTopDown_RowOrder == fCodec->fRowOrder) {
622 return kTopDown_SkScanlineOrder;
623 } else {
624 return kOutOfOrder_SkScanlineOrder;
scroggo 2015/08/27 20:14:22 If SkScanlineOrder included an option for kBottomU
msarett 2015/08/27 21:21:46 I think it makes sense to share with SkScanlineOrd
scroggo 2015/08/28 13:28:46 That would be my preference. We can always treat t
625 }
626 }
627
628 int onGetY() const override {
629 return fCodec->getDstRow(this->INHERITED::onGetY(), this->dstInfo().heig ht());
630 }
631
632 // TODO(msarett): Override default skipping with something more clever.
633
634 private:
635 SkAutoTDelete<SkBmpCodec> fCodec;
636
637 typedef SkScanlineDecoder INHERITED;
638 };
639
640 SkScanlineDecoder* SkBmpCodec::NewSDFromStream(SkStream* stream) {
641 SkAutoTDelete<SkBmpCodec> codec(static_cast<SkBmpCodec*>(SkBmpCodec::NewFrom Stream(stream)));
642 if (!codec) {
643 return NULL;
644 }
645
646 return SkNEW_ARGS(SkBmpScanlineDecoder, (codec.detach()));
647 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698