Index: src/codec/SkBmpCodec.cpp |
diff --git a/src/codec/SkBmpCodec.cpp b/src/codec/SkBmpCodec.cpp |
index fa4608ffeec513cacd753fc3efc721497d1eff3c..addcc80102d481265a220eeb151980e9138c55c3 100644 |
--- a/src/codec/SkBmpCodec.cpp |
+++ b/src/codec/SkBmpCodec.cpp |
@@ -44,16 +44,6 @@ enum BmpCompressionMethod { |
}; |
/* |
- * Used to define the input format of the bmp |
- */ |
-enum BmpInputFormat { |
- kStandard_BmpInputFormat, |
- kRLE_BmpInputFormat, |
- kBitMask_BmpInputFormat, |
- kUnknown_BmpInputFormat |
-}; |
- |
-/* |
* Checks the start of the stream to see if the image is a bitmap |
*/ |
bool SkBmpCodec::IsBmp(SkStream* stream) { |
@@ -472,7 +462,7 @@ bool SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, SkCodec** codecOut) { |
switch (inputFormat) { |
case kStandard_BmpInputFormat: |
*codecOut = SkNEW_ARGS(SkBmpStandardCodec, (imageInfo, stream, |
- bitsPerPixel, numColors, bytesPerColor, |
+ inputFormat, bitsPerPixel, numColors, bytesPerColor, |
offset - bytesRead, rowOrder, inIco)); |
return true; |
case kBitMask_BmpInputFormat: |
@@ -490,7 +480,7 @@ bool SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, SkCodec** codecOut) { |
} |
*codecOut = SkNEW_ARGS(SkBmpMaskCodec, (imageInfo, stream, |
- bitsPerPixel, masks.detach(), rowOrder)); |
+ inputFormat, bitsPerPixel, masks.detach(), rowOrder)); |
return true; |
case kRLE_BmpInputFormat: |
// Bmp-in-Ico must be standard mode |
@@ -499,7 +489,7 @@ bool SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, SkCodec** codecOut) { |
// Icos skip the header that contains totalBytes. |
SkASSERT(!inIco); |
*codecOut = SkNEW_ARGS(SkBmpRLECodec, ( |
- imageInfo, stream, bitsPerPixel, numColors, |
+ imageInfo, stream, inputFormat, bitsPerPixel, numColors, |
bytesPerColor, offset - bytesRead, rowOrder, RLEBytes)); |
return true; |
default: |
@@ -529,8 +519,9 @@ SkCodec* SkBmpCodec::NewFromStream(SkStream* stream, bool inIco) { |
} |
SkBmpCodec::SkBmpCodec(const SkImageInfo& info, SkStream* stream, |
- uint16_t bitsPerPixel, RowOrder rowOrder) |
+ BmpInputFormat inputFormat, uint16_t bitsPerPixel, RowOrder rowOrder) |
: INHERITED(info, stream) |
+ , fInputFormat(inputFormat) |
, fBitsPerPixel(bitsPerPixel) |
, fRowOrder(rowOrder) |
{} |
@@ -562,3 +553,60 @@ uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) { |
} |
return numColors; |
} |
+ |
+/* |
+ * Scanline decoder for bmps |
+ */ |
+class SkBmpScanlineDecoder : public SkScanlineDecoder { |
+public: |
+ SkBmpScanlineDecoder(SkBmpCodec* codec) |
+ : INHERITED(codec->getInfo()) |
+ , fCodec(codec) |
+ {} |
+ |
+ SkCodec::Result onStart(const SkImageInfo& dstInfo, const SkCodec::Options& options, |
+ SkPMColor inputColorPtr[], int* inputColorCount) override { |
+ if (!fCodec->rewindIfNeeded()) { |
+ return SkCodec::kCouldNotRewind; |
+ } |
+ if (options.fSubset) { |
+ // Subsets are not supported. |
+ return SkCodec::kUnimplemented; |
+ } |
+ if (dstInfo.dimensions() != fCodec->getInfo().dimensions()) { |
+ SkCodecPrintf("Error: scaling not supported.\n"); |
+ return SkCodec::kInvalidScale; |
+ } |
+ if (!conversion_possible(dstInfo, fCodec->getInfo())) { |
+ SkCodecPrintf("Error: cannot convert input type to output type.\n"); |
+ return SkCodec::kInvalidConversion; |
+ } |
+ |
+ return fCodec->onStart(dstInfo, options, inputColorPtr, inputColorCount); |
+ } |
+ |
+ SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) { |
+ // Create a new image info representing the portion of the image to decode |
+ SkImageInfo rowInfo = this->dstInfo().makeWH(this->dstInfo().width(), count); |
+ |
+ // Decode the requested rows |
+ return fCodec->decode(rowInfo, dst, rowBytes, this->options()); |
+ } |
+ |
+ // TODO(msarett): Override default skipping with something more clever. |
+ // TODO(msarett): Consider other optimizations for this codec. |
scroggo
2015/08/14 21:53:00
Do you have any optimizations in mind?
msarett
2015/08/17 19:16:13
Not in particular. I just don't think I've analyz
scroggo
2015/08/26 22:40:09
Great. These would be good candidates to specifica
|
+ |
+private: |
+ SkAutoTDelete<SkBmpCodec> fCodec; |
+ |
+ typedef SkScanlineDecoder INHERITED; |
+}; |
+ |
+SkScanlineDecoder* SkBmpCodec::NewSDFromStream(SkStream* stream) { |
+ SkAutoTDelete<SkBmpCodec> codec(static_cast<SkBmpCodec*>(SkBmpCodec::NewFromStream(stream))); |
+ if (!codec) { |
+ return NULL; |
+ } |
+ |
+ return SkNEW_ARGS(SkBmpScanlineDecoder, (codec)); |
+} |