Chromium Code Reviews| Index: src/codec/SkSwizzler.h |
| diff --git a/src/codec/SkSwizzler.h b/src/codec/SkSwizzler.h |
| index 1adb14db0e6d409a295964257bc32a0049ad3e20..88d9af9122cda52a8dff92717746387bb6ec7a1e 100644 |
| --- a/src/codec/SkSwizzler.h |
| +++ b/src/codec/SkSwizzler.h |
| @@ -18,26 +18,78 @@ 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_RowOrder, |
| + kBottomUp_RowOrder |
| + }; |
| + |
| + /** |
| + * Describes if we will render fully transparent images as opaque. |
| + * TODO: should we consider merging this SkAlphaType? |
|
scroggo
2015/03/04 17:10:31
I don't think so. (I don't think we'll want to inc
|
| + * kOpaque_AlphaOption corresponds to kIgnore_SkAlphaType |
| + * kNormal_AlphaOption corresponds to kPremul_SkAlphaType |
|
scroggo
2015/03/04 17:10:31
Keep in mind we want to support unpremul as well.
|
| + * kTransparentAsOpaque_AlphaOption does not correspond to an |
| + * existing SkAlphaType |
| + */ |
| + enum AlphaOption { |
| + kOpaque_AlphaOption, |
| + kNormal_AlphaOption, |
| + kTransparentAsOpaque_AlphaOption |
| + }; |
| + |
| + 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 +102,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 alphaOption 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 alphaOption 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); |
| + static SkSwizzler* CreateSwizzler( |
| + SrcConfig sc, const SkPMColor* ctable, const SkImageInfo& info, |
| + void* dst, size_t dstRowBytes, bool skipZeroes, |
| + const ColorMasks bitMasks = { 0, 0, 0, 0 }, |
|
scroggo
2015/03/04 17:10:31
I'm glad you're using the Swizzler, but:
A lot of
|
| + const AlphaOption alphaOption = kNormal_AlphaOption, |
| + const RowOrder rowOrder = kTopDown_RowOrder); |
| /** |
| * Swizzle the next line. Call height times, once for each row of source. |
| * @param src The next row of the source data. |
| @@ -70,22 +133,49 @@ 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 alphaOption 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 alphaOption is |
| + * kTransparentAsOpaque, completely transparent images should |
| + * be rendered as opaque. Images that are not completely |
| + * transparent should be treated normally. |
| + * @param seenNonAlphaOption, |
| + kTransparentAsOpaque_AlphaOptionPtr 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 alphaOption 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 alphaOption 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 AlphaOption alphaOption, |
| + bool* seenNonZeroAlpha, bool* zeroPrevRowsPtr); |
| const RowProc fRowProc; |
| const SkPMColor* fColorTable; // Unowned pointer |
| - const int fSrcPixelSize; |
| + const ColorMasks fBitMasks; |
| + const int fSrcBitsPerPixel; |
| const SkImageInfo fDstInfo; |
| void* fDstRow; |
| const size_t fDstRowBytes; |
| int fCurrY; |
| + const AlphaOption fAlphaOption; |
| + 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 AlphaOption alphaOption, |
| + const RowOrder rowOrder); |
| }; |
| #endif // SkSwizzler_DEFINED |