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

Unified Diff: src/codec/SkSwizzler.h

Issue 947283002: Bmp Image Decoding (Closed) Base URL: https://skia.googlesource.com/skia.git@decode-leon-3
Patch Set: Minor fixes 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/SkSwizzler.h
diff --git a/src/codec/SkSwizzler.h b/src/codec/SkSwizzler.h
index 1adb14db0e6d409a295964257bc32a0049ad3e20..1a92772da08a250d6019707445499980e53b190f 100644
--- a/src/codec/SkSwizzler.h
+++ b/src/codec/SkSwizzler.h
@@ -18,26 +18,72 @@ public:
* Enum describing the config of the source data.
*/
enum SrcConfig {
- kGray, // 1 byte per pixel
- kIndex, // 1 byte per pixel
- kRGB, // 3 bytes per pixel
- kRGBX, // 4 byes per pixel (ignore 4th)
- kRGBA, // 4 bytes per pixel
- kRGB_565 // 2 bytes per pixel
+ kGray,
+ kIndex1,
+ kIndex2,
+ kIndex4,
+ kIndex,
+ kRGB,
+ kBGR,
+ kRGBX,
+ kBGRX,
+ kRGBA,
+ kBGRA,
+ kRGB_565,
+ kMask16,
+ kMask24,
+ kMask32
};
- static int BytesPerPixel(SrcConfig sc) {
+ /**
+ * In mask SrcConfigs, used as bit masks for color components.
+ */
+ struct ColorMasks {
+ uint32_t redMask;
+ uint32_t greenMask;
+ uint32_t blueMask;
+ uint32_t alphaMask;
+ };
+
+ /**
+ * Describes if rows of the input start at the top or bottom of the image.
+ */
+ enum RowOrder {
+ kTopDown,
+ kBottomUp
+ };
+
+ /**
+ * Describes if we will render fully transparent images as opaque.
+ */
+ enum ZeroAlpha {
+ kTransparentAsOpaque,
+ kNormal
+ };
+
+ static int BitsPerPixel(SrcConfig sc) {
switch (sc) {
- case kGray:
- case kIndex:
+ case kIndex1:
return 1;
+ case kIndex2:
+ return 2;
+ case kIndex4:
+ return 4;
+ case kIndex:
+ return 8;
+ case kRGB_565:
+ case kMask16:
+ return 16;
case kRGB:
- return 3;
+ case kBGR:
+ case kMask24:
+ return 24;
case kRGBX:
case kRGBA:
- return 4;
- case kRGB_565:
- return 2;
+ case kBGRX:
+ case kBGRA:
+ case kMask32:
+ return 32;
}
}
@@ -50,11 +96,22 @@ public:
* @param dstRowBytes rowBytes for dst.
* @param skipZeroes Whether to skip writing zeroes. Useful if dst is
* zero-initialized. The implementation may or may not respect this.
+ * @param bitMasks Masks used to separate the color components of a pixel
+ * @param zeroAlpha Some inputs (bmp) have an alpha channel that is unused.
+ * Users of this channel often fill it with zeros, but still
+ * expect the image to be opaque. When zeroAlpha is
+ * kTransparentAsOpaque, completely transparent images should
+ * be rendered as opaque. Images that are not completely
+ * transparent should be treated normally.
+ * @param rowOrder Order in which input rows are swizzled
* @return A new SkSwizzler or NULL on failure.
*/
static SkSwizzler* CreateSwizzler(SrcConfig sc, const SkPMColor* ctable,
const SkImageInfo& info, void* dst,
- size_t dstRowBytes, bool skipZeroes);
+ size_t dstRowBytes, bool skipZeroes,
+ const ColorMasks* bitMasks = NULL,
+ const ZeroAlpha zeroAlpha = kNormal,
+ const RowOrder rowOrder = kTopDown);
/**
* Swizzle the next line. Call height times, once for each row of source.
* @param src The next row of the source data.
@@ -70,22 +127,48 @@ private:
* @param bpp bytes per pixel of the source.
* @param y Line of source.
* @param ctable Colors (used for kIndex source).
+ * @param masks Bit masks used to separate the color components of a pixel
+ * @param zeroAlpha Some inputs (bmp) have an alpha channel that is unused.
+ * Users of this channel often fill it with zeros, but still
+ * expect the image to be opaque. When zeroAlpha is
+ * kTransparentAsOpaque, completely transparent images should
+ * be rendered as opaque. Images that are not completely
+ * transparent should be treated normally.
+ * @param seenNonZeroAlphaPtr A ptr to the field that indicates if we have
+ * seen a non-zero alpha value in an image. This is used in
+ * conjunction with zeroAlpha to ensure accidentally fully
+ * transparent images are rendered as opaque.
+ * @param zeroPrevRowsPtr A ptr to the field that indicates if we need
+ * to set all previously decoded rows as transparent. This
+ * occurs when we have decoded transparent rows as opaque
+ * (because zeroAlpha is true), but then find a pixel that is
+ * not transparent. On this event, we must return to
+ * previously decoded rows and set them as transparent.
*/
typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
const uint8_t* SK_RESTRICT src,
- int width, int bpp, int y,
- const SkPMColor ctable[]);
+ int width, int bitsPerPixel, int y,
+ const SkPMColor ctable[], const ColorMasks* masks,
+ const ZeroAlpha zeroAlpha,
+ bool* seenNonZeroAlphaPtr, bool* zeroPrevRowsPtr);
const RowProc fRowProc;
const SkPMColor* fColorTable; // Unowned pointer
- const int fSrcPixelSize;
+ const ColorMasks* fBitMasks; // Unowned pointer
+ const int fSrcBitsPerPixel;
const SkImageInfo fDstInfo;
void* fDstRow;
const size_t fDstRowBytes;
int fCurrY;
+ const ZeroAlpha fZeroAlpha;
+ const RowOrder fRowOrder;
+ bool fSeenNonZeroAlpha;
+ bool fZeroPrevRows;
- SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBpp,
- const SkImageInfo& info, void* dst, size_t rowBytes);
+ SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBPP,
+ const SkImageInfo& info, void* dst, size_t rowBytes,
+ const ColorMasks* bitMasks, const ZeroAlpha zeroAlpha,
+ const RowOrder rowOrder);
};
#endif // SkSwizzler_DEFINED

Powered by Google App Engine
This is Rietveld 408576698