Index: src/codec/SkCodec_libbmp.h |
diff --git a/src/codec/SkCodec_libbmp.h b/src/codec/SkCodec_libbmp.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f7b1d455fdcde7fd3ac4e8f4ce24b291860d716e |
--- /dev/null |
+++ b/src/codec/SkCodec_libbmp.h |
@@ -0,0 +1,185 @@ |
+/* |
+ * Copyright 2015 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "SkCodec.h" |
+#include "SkImageInfo.h" |
+#include "SkStream.h" |
+#include "SkSwizzler.h" |
+#include "SkTypes.h" |
+ |
+// TODO: rename SkCodec_libbmp files to SkBmpCodec |
+// TODO: define a wrapper for SkDebugf that doesn't always print |
+/* |
+ * |
+ * This class implements the decoding for bmp images |
+ * |
+ */ |
+class SkBmpCodec : public SkCodec { |
+public: |
+ |
+ /* |
+ * |
+ * Bit masks used for color components in mask compression modes |
+ * |
+ */ |
+ struct BitMasks { |
+ uint32_t redMask; |
+ uint32_t greenMask; |
+ uint32_t blueMask; |
+ uint32_t alphaMask; |
+ }; |
+ |
+ /* |
+ * |
+ * Number of trailing zeros on bit masks used in mask compression modes |
+ * |
+ */ |
+ struct BitMaskShifts { |
+ uint32_t redShift; |
+ uint32_t greenShift; |
+ uint32_t blueShift; |
+ uint32_t alphaShift; |
+ }; |
+ |
+ /* |
+ * |
+ * Size of bit masks used in mask compression modes |
+ * |
+ */ |
+ struct BitMaskSizes { |
+ uint32_t redSize; |
+ uint32_t greenSize; |
+ uint32_t blueSize; |
+ uint32_t alphaSize; |
+ }; |
+ |
+ /* |
+ * |
+ * Describes if rows of the input start at the top or bottom of the image |
+ * |
+ */ |
+ enum RowOrder { |
+ kTopDown_RowOrder, |
+ kBottomUp_RowOrder |
+ }; |
+ |
+ /* |
+ * |
+ * Checks the start of the stream to see if the image is a bitmap |
+ * |
+ */ |
+ static bool IsBmp(SkStream*); |
+ |
+ /* |
+ * |
+ * Assumes IsBmp was called and returned true |
+ * Creates a bitmap decoder |
+ * Reads enough of the stream to determine the image format |
+ * |
+ */ |
+ static SkCodec* NewFromStream(SkStream*); |
+ |
+protected: |
+ |
+ /* |
+ * |
+ * Initiates the bitmap decode |
+ * |
+ */ |
+ virtual Result onGetPixels(const SkImageInfo& dstInfo, void* dst, |
+ size_t dstRowBytes, SkColor*, |
scroggo
2015/03/06 18:56:13
I think this happens to compile because SkColor an
|
+ int*) SK_OVERRIDE; |
+ |
+private: |
+ |
+ /* |
+ * |
+ * Used to define the input format of the bitmap |
+ * |
+ */ |
+ enum BitmapInputFormat { |
+ kStandard_BitmapInputFormat, |
+ kRLE_BitmapInputFormat, |
+ kBitMask_BitmapInputFormat, |
+ kUnknown_BitmapInputFormat |
+ }; |
+ |
+ /* |
+ * |
+ * For a continuous bit mask (ex: 0011100), retrieves the size of the mask |
+ * and the number of bits to shift the mask |
+ * |
+ */ |
+ void processMasks(); |
+ |
+ /* |
+ * |
+ * Performs the bitmap decoding for bit masks input format |
+ * |
+ */ |
+ Result decodeMask(const SkImageInfo& dstInfo, void* dst, |
+ uint32_t dstRowBytes); |
+ |
+ /* |
+ * |
+ * Set an RLE pixel using the color table |
+ * |
+ */ |
+ void setRLEPixel(SkColor* dst, uint32_t dstRowBytes, int height, |
scroggo
2015/03/06 18:56:14
SkPMColor (I think)
|
+ uint32_t x, uint32_t y, uint8_t index); |
+ |
+ /* |
+ * |
+ * Performs the bitmap decoding for RLE input format |
+ * |
+ */ |
+ Result decodeRLE(const SkImageInfo& dstInfo, void* dst, |
+ uint32_t dstRowBytes); |
+ |
+ /* |
+ * |
+ * Performs the bitmap decoding for standard input format |
+ * |
+ */ |
+ Result decode(const SkImageInfo& dstInfo, void* dst, uint32_t dstRowBytes); |
+ |
+ /* |
+ * |
+ * Creates an instance of the decoder |
+ * Called only by NewFromStream |
+ * |
+ * @param srcInfo contains the source width and height |
+ * @param stream the stream of image data |
+ * @param bitsPerPixel the number of bits used to store each pixel |
+ * @param format the format of the bmp file |
+ * @param bitMasks optional color masks for certain bmp formats |
+ * @param colorTable array representing the color table for index-based bmp |
+ * formats, passes ownership to SkBmpCodec |
+ * @param rowOrder indicates whether rows are ordered top-down or bottom-up |
+ * @param remainingBytes used only for RLE decodes, as we must decode all |
+ * of the data at once rather than row by row |
+ * it indicates the amount of data left in the stream |
+ * after decoding the headers |
+ * |
+ */ |
+ SkBmpCodec(const SkImageInfo& srcInfo, SkStream* stream, |
+ uint16_t bitsPerPixel, BitmapInputFormat format, |
+ BitMasks bitMasks, SkColor* colorTable, |
+ RowOrder rowOrder, uint32_t remainingBytes); |
+ |
+ // Fields |
+ const uint16_t fBitsPerPixel; |
+ const BitmapInputFormat fInputFormat; |
+ BitMasks fBitMasks; |
+ BitMaskShifts fMaskShifts; |
+ BitMaskSizes fMaskSizes; |
+ const SkAutoTDeleteArray<SkColor> fColorTable; // owned |
+ const RowOrder fRowOrder; |
+ const uint32_t fRemainingBytes; |
+ |
+ typedef SkCodec INHERITED; |
+}; |