Index: src/codec/SkBmpCodec.cpp |
diff --git a/src/codec/SkBmpCodec.cpp b/src/codec/SkBmpCodec.cpp |
index 20af2da06fe0db122b86b49bef63b5c7ba6da8bc..14414627cdcdd96e8fdb71de516a3ab751698d30 100644 |
--- a/src/codec/SkBmpCodec.cpp |
+++ b/src/codec/SkBmpCodec.cpp |
@@ -11,6 +11,7 @@ |
#include "SkBmpStandardCodec.h" |
#include "SkCodecPriv.h" |
#include "SkColorPriv.h" |
+#include "SkScaledCodec.h" |
#include "SkStream.h" |
/* |
@@ -44,16 +45,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) { |
@@ -563,3 +554,81 @@ 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) |
+ {} |
+ |
+ SkEncodedFormat onGetEncodedFormat() const override { |
+ return kBMP_SkEncodedFormat; |
+ } |
+ |
+ 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() != this->getInfo().dimensions()) { |
+ if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstInfo)) { |
+ return SkCodec::kInvalidScale; |
+ } |
+ } |
+ if (!conversion_possible(dstInfo, this->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) override { |
+ // Create a new image info representing the portion of the image to decode |
+ SkImageInfo rowInfo = this->dstInfo().makeWH(fCodec->getInfo().width(), count); |
+ |
+ // Decode the requested rows |
+ return fCodec->decode(rowInfo, dst, rowBytes, this->options()); |
+ } |
+ |
+ SkScanlineOrder onGetScanlineOrder() const override { |
+ if (SkBmpCodec::kTopDown_RowOrder == fCodec->fRowOrder) { |
+ return kTopDown_SkScanlineOrder; |
+ } else { |
scroggo
2015/08/26 22:40:09
nit: This else is unnecessary. Typically, this is
|
+ return kOutOfOrder_SkScanlineOrder; |
+ } |
+ } |
+ |
+ int onGetY() const override { |
+ if (SkBmpCodec::kTopDown_RowOrder == fCodec->fRowOrder) { |
+ return INHERITED::onGetY(); |
+ } else { |
+ return this->dstInfo().height() - INHERITED::onGetY() - 1; |
+ } |
+ } |
+ |
+ // TODO(msarett): Override default skipping with something more clever. |
+ // TODO(msarett): Consider other optimizations for this codec. |
+ |
+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.detach())); |
+} |