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

Unified Diff: src/codec/SkCodec_libbmp.h

Issue 947283002: Bmp Image Decoding (Closed) Base URL: https://skia.googlesource.com/skia.git@decode-leon-3
Patch Set: Improved clarity of swizzler with regard to weird alpha Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
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..1a0c160fa51ce1d66d46d10da5f1521778a047ed
--- /dev/null
+++ b/src/codec/SkCodec_libbmp.h
@@ -0,0 +1,124 @@
+/*
+ * 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"
+
+#ifdef SK_SUPPORT_LEGACY_IMAGE_GENERATOR_RETURN
scroggo 2015/03/04 17:10:30 No longer needed
+ #define onGetPixels onGetPixelsEnum
+#endif
+
+/*
+ *
+ * This class implements the decoding for bmp images
+ *
+ */
+class SkBmpCodec : public SkCodec {
+public:
+
+ /*
+ *
+ * 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, SkPMColor*,
+ int*) SK_OVERRIDE;
+
+private:
+
+ /*
+ *
+ * Used to define the input format of the bitmap
+ *
+ */
+ enum BitmapInputFormat {
+ kStandard_BitmapInputFormat,
+ kRLE_BitmapInputFormat,
+ kBitMask_BitmapInputFormat,
+ kUnknown_BitmapInputFormat
+ };
+
+ /*
+ *
+ * Set an RLE pixel using the color table
+ *
+ */
+ void setRLEPixel(SkPMColor* dst, uint32_t dstRowBytes, int height,
+ uint32_t x, uint32_t y, uint8_t index);
+
+ /*
+ *
+ * Performs the bitmap decoding for standard and bit masks input format
+ *
+ */
+ Result decode(const SkImageInfo& dstInfo, void* dst, uint32_t dstRowBytes);
+
+ /*
+ *
+ * Performs the bitmap decoding for RLE input format
+ *
+ */
+ Result decodeRLE(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
+ passes ownership to SkBmpCodec
scroggo 2015/03/04 17:10:30 no longer true.
+ * @param colorTable color table for index-based bmp formats
scroggo 2015/03/04 17:10:30 nit: Maybe it's obvious, but this doesn't mention
+ * 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,
+ SkSwizzler::ColorMasks bitMasks, SkPMColor* colorTable,
+ SkSwizzler::RowOrder rowOrder, uint32_t remainingBytes);
+
+ // Fields
+ const uint16_t fBitsPerPixel;
+ const BitmapInputFormat fInputFormat;
+ const SkSwizzler::ColorMasks fBitMasks;
+ const SkAutoTDeleteArray<SkPMColor> fColorTable; // owned
+ const SkSwizzler::RowOrder fRowOrder;
+ const uint32_t fRemainingBytes;
+
+ typedef SkCodec INHERITED;
+};

Powered by Google App Engine
This is Rietveld 408576698