Index: src/codec/SkSwizzler.h |
diff --git a/src/codec/SkSwizzler.h b/src/codec/SkSwizzler.h |
index 0bf2ee306a9377c64e5691260b2e9272ea853e06..bdf0ae7bffd02737312e6a6f4f4642eb83d85276 100644 |
--- a/src/codec/SkSwizzler.h |
+++ b/src/codec/SkSwizzler.h |
@@ -18,32 +18,63 @@ 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, |
}; |
- static int BytesPerPixel(SrcConfig sc) { |
+ /* |
+ * |
+ * Result code for the alpha components of a row. |
+ * |
+ */ |
+ enum ResultAlpha { |
+ kOpaque_ResultAlpha, // All pixels in a row have max alpha |
+ kTransparent_ResultAlpha, // All pixels in a row have zero alpha |
+ kNeither_ResultAlpha // Alpha is not completely maxed or zeroed |
+ }; |
+ |
+ static int BitsPerPixel(SrcConfig sc) { |
switch (sc) { |
+ case kIndex1: |
+ return 1; |
+ case kIndex2: |
+ return 2; |
+ case kIndex4: |
+ return 4; |
case kGray: |
case kIndex: |
- return 1; |
+ return 8; |
+ case kRGB_565: |
+ return 16; |
case kRGB: |
- return 3; |
+ case kBGR: |
+ return 24; |
case kRGBX: |
case kRGBA: |
- return 4; |
- case kRGB_565: |
- return 2; |
+ case kBGRX: |
+ case kBGRA: |
+ return 32; |
default: |
- SkDebugf("invalid source config passed to BytesPerPixel\n"); |
- return -1; |
+ SkASSERT(false); |
+ return 0; |
} |
} |
+ static int BytesPerPixel(SrcConfig sc) { |
+ SkASSERT(SkIsAlign4(BitsPerPixel(sc))); |
+ return (BitsPerPixel(sc)) >> 3; |
+ } |
+ |
/** |
* Create a new SkSwizzler. |
* @param sc SrcConfig |
@@ -55,39 +86,73 @@ public: |
* zero-initialized. The implementation may or may not respect this. |
* @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); |
+ |
+ /** |
+ * |
+ * Chooses the proper result alpha enum based on accumulated alpha masks |
+ * |
+ */ |
+ static ResultAlpha GetResult(uint8_t zeroAlpha, uint8_t maxAlpha); |
+ |
/** |
* Swizzle the next line. Call height times, once for each row of source. |
* @param src The next row of the source data. |
* @return Whether the row had non-opaque alpha. |
*/ |
- bool next(const uint8_t* SK_RESTRICT src); |
+ ResultAlpha next(const uint8_t* SK_RESTRICT src); |
+ |
+ /** |
+ * |
+ * Alternate version of next that allows the caller to specify the row. |
+ * It is very important to only use one version of next. Since the other |
+ * version modifies the dst pointer, it will change the behavior of this |
+ * function. We will check this in Debug mode. |
+ * |
+ */ |
+ ResultAlpha next(const uint8_t* SK_RESTRICT src, int y); |
private: |
+ |
+#ifdef SK_DEBUG |
+ /* |
+ * |
+ * Keep track of which version of next the caller is using |
+ * |
+ */ |
+ enum SwizzleMode { |
scroggo
2015/03/11 19:22:45
I think this name is not very informative. How abo
msarett
2015/03/11 20:03:11
Almost went with NextMode, and then I tried to be
|
+ kUninitialized_SwizzleMode, |
+ kConsecutive_SwizzleMode, |
+ kDesignateRow_SwizzleMode, |
+ }; |
+ |
+ SwizzleMode fSwizzleMode; |
+#endif |
+ |
/** |
* Method for converting raw data to Skia pixels. |
* @param dstRow Row in which to write the resulting pixels. |
* @param src Row of src data, in format specified by SrcConfig |
* @param width Width in pixels |
- * @param bpp bytes per pixel of the source. |
+ * @param bpp bits per pixel of the source. |
* @param y Line of source. |
* @param ctable Colors (used for kIndex source). |
*/ |
- typedef bool (*RowProc)(void* SK_RESTRICT dstRow, |
- const uint8_t* SK_RESTRICT src, |
- int width, int bpp, int y, |
- const SkPMColor ctable[]); |
+ typedef ResultAlpha (*RowProc)(void* SK_RESTRICT dstRow, |
+ const uint8_t* SK_RESTRICT src, |
+ int width, int bitsPerPixel, int y, |
+ const SkPMColor ctable[]); |
const RowProc fRowProc; |
- const SkPMColor* fColorTable; // Unowned pointer |
- const int fSrcPixelSize; |
+ const SkPMColor* fColorTable; // Unowned pointer |
+ const int fSrcBitsPerPixel; |
const SkImageInfo fDstInfo; |
void* fDstRow; |
const size_t fDstRowBytes; |
int fCurrY; |
- SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBpp, |
+ SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBPP, |
const SkImageInfo& info, void* dst, size_t rowBytes); |
}; |