Chromium Code Reviews| Index: src/codec/SkSwizzler.cpp |
| diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp |
| index 85f447a843d35d17dd04bab397b80c26a82a3181..325ecee4da2b134cdd43b2f2f7c38b1cff1c45f1 100644 |
| --- a/src/codec/SkSwizzler.cpp |
| +++ b/src/codec/SkSwizzler.cpp |
| @@ -9,13 +9,46 @@ |
| #include "SkSwizzler.h" |
| #include "SkTemplates.h" |
| -// index |
| - |
| #define A32_MASK_IN_PLACE (SkPMColor)(SK_A32_MASK << SK_A32_SHIFT) |
| +// kIndex1, kIndex2, kIndex4 |
| + |
| +static bool swizzle_small_index_to_n32(void* SK_RESTRICT dstRow, |
| + const uint8_t* SK_RESTRICT src, |
| + int width, int bitsPerPixel, int, |
| + const SkPMColor ctable[], |
| + const SkSwizzler::ColorMasks, |
| + const SkSwizzler::AlphaOption, bool*, |
| + bool*) { |
| + |
| + SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| + SkPMColor cc = A32_MASK_IN_PLACE; |
| + const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
| + const uint32_t rowBytes = (width + pixelsPerByte - 1) / pixelsPerByte; |
| + const uint8_t mask = (1 << bitsPerPixel) - 1; |
| + |
| + uint32_t x = 0; |
| + for (uint32_t byte = 0; byte < rowBytes; byte++) { |
| + uint8_t pixelData = src[byte]; |
| + for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { |
| + uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; |
| + dst[x] = ctable[index]; |
| + cc &= ctable[index]; |
| + pixelData <<= bitsPerPixel; |
| + x++; |
| + } |
| + } |
| + return cc != A32_MASK_IN_PLACE; |
| +} |
| + |
| +// kIndex |
| + |
| static bool swizzle_index_to_n32(void* SK_RESTRICT dstRow, |
| - const uint8_t* SK_RESTRICT src, |
| - int width, int deltaSrc, int, const SkPMColor ctable[]) { |
| + const uint8_t* SK_RESTRICT src, |
| + int width, int bitsPerPixel, int, |
| + const SkPMColor ctable[], |
| + const SkSwizzler::ColorMasks, |
| + const SkSwizzler::AlphaOption, bool*, bool*) { |
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| SkPMColor cc = A32_MASK_IN_PLACE; |
| @@ -23,15 +56,18 @@ static bool swizzle_index_to_n32(void* SK_RESTRICT dstRow, |
| SkPMColor c = ctable[*src]; |
| cc &= c; |
| dst[x] = c; |
| - src += deltaSrc; |
| + src++; |
| } |
| return cc != A32_MASK_IN_PLACE; |
| } |
| static bool swizzle_index_to_n32_skipZ(void* SK_RESTRICT dstRow, |
| - const uint8_t* SK_RESTRICT src, |
| - int width, int deltaSrc, int, |
| - const SkPMColor ctable[]) { |
| + const uint8_t* SK_RESTRICT src, |
| + int width, int bitsPerPixel, int, |
| + const SkPMColor ctable[], |
| + const SkSwizzler::ColorMasks, |
| + const SkSwizzler::AlphaOption, bool*, |
| + bool*) { |
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| SkPMColor cc = A32_MASK_IN_PLACE; |
| @@ -41,18 +77,311 @@ static bool swizzle_index_to_n32_skipZ(void* SK_RESTRICT dstRow, |
| if (c != 0) { |
| dst[x] = c; |
| } |
| - src += deltaSrc; |
| + src++; |
| } |
| return cc != A32_MASK_IN_PLACE; |
| } |
| #undef A32_MASK_IN_PLACE |
| +// mask |
| + |
| +/** |
| + * |
| + * Used to convert 1-7 bit color components into 8-bit color components |
| + * |
| + */ |
| +const uint8_t nBitTo8BitlookupTable[] = { |
| + // 1 bit |
| + 0, 255, |
| + // 2 bits |
| + 0, 85, 170, 255, |
| + // 3 bits |
| + 0, 36, 73, 109, 146, 182, 219, 255, |
| + // 4 bits |
| + 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, |
| + // 5 bits |
| + 0, 8, 16, 25, 33, 41, 49, 58, 66, 74, 82, 90, 99, 107, 115, 123, 132, 140, |
| + 148, 156, 165, 173, 181, 189, 197, 206, 214, 222, 230, 239, 247, 255, |
| + // 6 bits |
| + 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 45, 49, 53, 57, 61, 65, 69, 73, |
| + 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 130, 134, 138, |
| + 142, 146, 150, 154, 158, 162, 166, 170, 174, 178, 182, 186, 190, 194, 198, |
| + 202, 206, 210, 215, 219, 223, 227, 231, 235, 239, 243, 247, 251, 255, |
| + // 7 bits |
| + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, |
| + 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, |
| + 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, |
| + 112, 114, 116, 118, 120, 122, 124, 126, 129, 131, 133, 135, 137, 139, 141, |
| + 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 171, |
| + 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, |
| + 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, |
| + 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255 |
| +}; |
| + |
| +/* |
| + * |
| + * Convert an n bit component to an 8-bit component |
| + * |
| + */ |
| +static uint8_t convert_n_to_8(uint32_t component, uint32_t n) { |
| + if (0 == n) { |
| + return 0; |
| + } else if (8 > n) { |
| + return nBitTo8BitlookupTable[(1 << n) - 2 + component]; |
| + } else if (8 == n) { |
| + return component; |
| + } else { |
| + SkDebugf("Error: too many bits for lookup table.\n"); |
| + return 0; |
| + } |
| +} |
| + |
| +/* |
| + * |
| + * For a continuous bit mask (ex: 0011100), retrieves the size of the mask and |
| + * the trailing zeros |
| + * |
| + */ |
| +static void get_mask_info(uint32_t mask, uint32_t bPP, uint32_t* size, |
| + uint32_t* shift) { |
| + // For empty masks, set zeros and return |
| + uint32_t tempMask = mask; |
| + if (!tempMask) { |
| + *size = 0; |
| + *shift = 0; |
| + return; |
| + } |
| + |
| + // Count trailing zeros |
| + int zeros = 0; |
| + for (; !(tempMask & 1); tempMask >>= 1) { |
| + zeros++; |
| + } |
| + |
| + // Count mask size |
| + int count = 0; |
| + for (; tempMask & 1; tempMask >>= 1) { |
| + count++; |
| + } |
| + |
| + // We will use a maximum of 8 bits for the size, truncate some of the mask |
| + // bits if necessary |
| + if (count > 8) { |
| + *shift = count - 8 + zeros; |
| + *size = 8; |
| + } else { |
| + *shift = zeros; |
| + *size = count; |
| + } |
| + return; |
| +} |
| + |
| +/* |
| + * |
| + * Set the alpha channel value based on the input alpha type. The interesting |
| + * case is kTransparentAsOpaque. We must respect the alpha channel in this |
| + * case. However, if it is all zeros, we want to display the image as opaque |
| + * instead of transparent. This may require reseting the loop iterator and |
| + * reprocessing previous rows. |
| + * |
| + */ |
| +static uint8_t get_alpha(uint8_t alpha, SkSwizzler::AlphaOption opt, |
| + uint32_t* currIndex, int deltaSrc, |
| + bool* seenNonZeroAlphaPtr, bool* zeroPrevRowsPtr) { |
| + switch (opt) { |
| + case SkSwizzler::kOpaque_AlphaOption: |
| + return 0xFF; |
| + case SkSwizzler::kNormal_AlphaOption: |
| + return alpha; |
| + case SkSwizzler::kTransparentAsOpaque_AlphaOption: |
| + if (*seenNonZeroAlphaPtr) { |
| + return alpha; |
| + } else if(!alpha) { |
| + return 0xFF; |
| + } else { |
| + *zeroPrevRowsPtr = true; |
| + *seenNonZeroAlphaPtr = true; |
| + *currIndex = -deltaSrc; |
| + return alpha; |
| + } |
| + default: |
| + SkASSERT(false); |
| + return 0; |
| + } |
| +} |
| + |
| +// kMask16 |
| + |
| +static bool swizzle_mask16_to_n32(void* SK_RESTRICT dstRow, |
| + const uint8_t* SK_RESTRICT src, |
| + int width, int bitsPerPixel, int, |
| + const SkPMColor ctable[], |
| + const SkSwizzler::ColorMasks masks, |
| + const SkSwizzler::AlphaOption alphaOption, |
| + bool* seenNonZeroAlphaPtr, |
| + bool* zeroPrevRowsPtr) { |
| + // Load the bit masks |
| + uint32_t redMask = masks.redMask; |
|
scroggo
2015/03/04 17:10:31
Would it be possible to make a function that looks
|
| + uint32_t greenMask = masks.greenMask; |
| + uint32_t blueMask = masks.blueMask; |
| + uint32_t alphaMask = masks.alphaMask; |
| + uint32_t rBits, rShift, gBits, gShift, bBits, bShift, aBits, aShift; |
| + get_mask_info(redMask, bitsPerPixel, &rBits, &rShift); |
| + get_mask_info(greenMask, bitsPerPixel, &gBits, &gShift); |
| + get_mask_info(blueMask, bitsPerPixel, &bBits, &bShift); |
| + get_mask_info(alphaMask, bitsPerPixel, &aBits, &aShift); |
| + |
| + // Use the masks to decode to the destination |
| + SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| + int deltaSrc = 2; |
| + for (uint32_t p = 0; p < width * deltaSrc; p += deltaSrc) { |
| + uint16_t pixel = src[p] | (src[p + 1] << 8); |
| + uint8_t red = convert_n_to_8((pixel & redMask) >> rShift, rBits); |
| + uint8_t green = convert_n_to_8((pixel & greenMask) >> gShift, gBits); |
| + uint8_t blue = convert_n_to_8((pixel & blueMask) >> bShift, bBits); |
| + uint8_t alpha = convert_n_to_8((pixel & alphaMask) >> aShift, aBits); |
| + // Call to get_alpha may reset the loop iterator. |
| + // We will get a safe result cell before this call. |
| + SkPMColor* dstCell = &dst[p/deltaSrc]; |
| + uint8_t trueAlpha = get_alpha(alpha, alphaOption, &p, deltaSrc, |
| + seenNonZeroAlphaPtr, zeroPrevRowsPtr); |
| + *dstCell = SkPreMultiplyARGB(trueAlpha, red, green, blue); |
| + } |
| + return *seenNonZeroAlphaPtr; |
|
scroggo
2015/03/04 17:10:31
I think this is not want you want to return. The f
|
| +} |
| + |
| +// kMask24 |
| + |
| +static bool swizzle_mask24_to_n32(void* SK_RESTRICT dstRow, |
| + const uint8_t* SK_RESTRICT src, |
| + int width, int bitsPerPixel, int, |
| + const SkPMColor ctable[], |
| + const SkSwizzler::ColorMasks masks, |
| + const SkSwizzler::AlphaOption alphaOption, |
| + bool* seenNonZeroAlphaPtr, |
| + bool* zeroPrevRowsPtr) { |
|
scroggo
2015/03/04 17:10:31
I'm trying to figure out how we can cut down on th
|
| + // Load the bit masks |
| + uint32_t redMask = masks.redMask; |
| + uint32_t greenMask = masks.greenMask; |
| + uint32_t blueMask = masks.blueMask; |
| + uint32_t alphaMask = masks.alphaMask; |
| + uint32_t rBits, rShift, gBits, gShift, bBits, bShift, aBits, aShift; |
| + get_mask_info(redMask, bitsPerPixel, &rBits, &rShift); |
| + get_mask_info(greenMask, bitsPerPixel, &gBits, &gShift); |
| + get_mask_info(blueMask, bitsPerPixel, &bBits, &bShift); |
| + get_mask_info(alphaMask, bitsPerPixel, &aBits, &aShift); |
| + |
| + // Use the masks to decode to the destination |
| + SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| + int x = 0; |
| + int deltaSrc = 3; |
| + for (uint32_t p = 0; p < width * deltaSrc; p += deltaSrc) { |
| + uint32_t pixel = src[p] | (src[p + 1] << 8) | src[p + 2] << 16; |
| + uint8_t red = convert_n_to_8((pixel & redMask) >> rShift, rBits); |
| + uint8_t green = convert_n_to_8((pixel & greenMask) >> gShift, gBits); |
| + uint8_t blue = convert_n_to_8((pixel & blueMask) >> bShift, bBits); |
| + uint8_t alpha = convert_n_to_8((pixel & alphaMask) >> aShift, aBits); |
| + // Call to get_alpha may reset the loop iterator. |
| + // We will get a safe result cell before this call. |
| + SkPMColor* dstCell = &dst[p/deltaSrc]; |
| + uint8_t trueAlpha = get_alpha(alpha, alphaOption, &p, deltaSrc, |
| + seenNonZeroAlphaPtr, zeroPrevRowsPtr); |
| + *dstCell = SkPreMultiplyARGB(trueAlpha, red, green, blue); |
| + } |
| + return *seenNonZeroAlphaPtr; |
| +} |
| + |
| +// kMask32 |
| + |
| +static bool swizzle_mask32_to_n32(void* SK_RESTRICT dstRow, |
| + const uint8_t* SK_RESTRICT src, |
| + int width, int bitsPerPixel, int, |
| + const SkPMColor ctable[], |
| + const SkSwizzler::ColorMasks masks, |
| + const SkSwizzler::AlphaOption alphaOption, |
| + bool* seenNonZeroAlphaPtr, |
| + bool* zeroPrevRowsPtr) { |
| + // Load the bit masks |
| + uint32_t redMask = masks.redMask; |
| + uint32_t greenMask = masks.greenMask; |
| + uint32_t blueMask = masks.blueMask; |
| + uint32_t alphaMask = masks.alphaMask; |
| + uint32_t rBits, rShift, gBits, gShift, bBits, bShift, aBits, aShift; |
| + get_mask_info(redMask, bitsPerPixel, &rBits, &rShift); |
| + get_mask_info(greenMask, bitsPerPixel, &gBits, &gShift); |
| + get_mask_info(blueMask, bitsPerPixel, &bBits, &bShift); |
| + get_mask_info(alphaMask, bitsPerPixel, &aBits, &aShift); |
| + |
| + // Use the masks to decode to the destination |
| + SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| + int x = 0; |
| + int deltaSrc = 4; |
| + for (uint32_t p = 0; p < width * deltaSrc; p += deltaSrc) { |
| + uint32_t pixel = src[p] | (src[p + 1] << 8) | src[p + 2] << 16 | |
| + src[p + 3] << 24; |
| + uint8_t red = convert_n_to_8((pixel & redMask) >> rShift, rBits); |
| + uint8_t green = convert_n_to_8((pixel & greenMask) >> gShift, gBits); |
| + uint8_t blue = convert_n_to_8((pixel & blueMask) >> bShift, bBits); |
| + uint8_t alpha = convert_n_to_8((pixel & alphaMask) >> aShift, aBits); |
| + // Call to get_alpha may reset the loop iterator. |
| + // We will get a safe result cell before this call. |
| + SkPMColor* dstCell = &dst[p/deltaSrc]; |
| + uint8_t trueAlpha = get_alpha(alpha, alphaOption, &p, deltaSrc, |
| + seenNonZeroAlphaPtr, zeroPrevRowsPtr); |
| + *dstCell = SkPreMultiplyARGB(trueAlpha, red, green, blue); |
| + } |
| + return *seenNonZeroAlphaPtr; |
| +} |
| + |
| +// kBGRX and kBGR |
| + |
| +static bool swizzle_bgrx_to_n32(void* SK_RESTRICT dstRow, |
| + const uint8_t* SK_RESTRICT src, |
| + int width, int bitsPerPixel, int, |
| + const SkPMColor[], |
| + const SkSwizzler::ColorMasks, |
| + const SkSwizzler::AlphaOption, bool*, bool*) { |
| + SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| + int deltaSrc = bitsPerPixel / 8; |
| + for (int x = 0; x < width; x++) { |
| + dst[x] = SkPackARGB32(0xFF, src[2], src[1], src[0]); |
| + src += deltaSrc; |
| + } |
| + return false; |
| +} |
| + |
| +// kBGRA |
| + |
| +static bool swizzle_bgra_to_n32(void* SK_RESTRICT dstRow, |
| + const uint8_t* SK_RESTRICT src, |
| + int width, int bitsPerPixel, int, |
| + const SkPMColor[], |
| + const SkSwizzler::ColorMasks masks, |
| + const SkSwizzler::AlphaOption alphaOption, |
| + bool* seenNonZeroAlphaPtr, |
| + bool* zeroPrevRowsPtr) { |
| + SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| + uint32_t alphaMask = masks.alphaMask; |
| + for (uint32_t x = 0; x < width; x++) { |
| + uint8_t alpha = alphaMask & src[4*x + 3]; |
| + SkPMColor* dstCell = &dst[x]; |
| + uint8_t trueAlpha = get_alpha(alpha, alphaOption, &x, 1, |
| + seenNonZeroAlphaPtr, zeroPrevRowsPtr); |
| + dst[x] = SkPreMultiplyARGB(alpha, src[4*x + 2], src[4*x + 1], src[4*x]); |
| + } |
| + return *seenNonZeroAlphaPtr; |
| +} |
| + |
| // n32 |
| static bool swizzle_rgbx_to_n32(void* SK_RESTRICT dstRow, |
| const uint8_t* SK_RESTRICT src, |
| - int width, int deltaSrc, int, const SkPMColor[]) { |
| + int width, int bitsPerPixel, int, |
| + const SkPMColor[], |
| + const SkSwizzler::ColorMasks, |
| + const SkSwizzler::AlphaOption, bool*, bool*) { |
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| + int deltaSrc = bitsPerPixel / 8; |
| for (int x = 0; x < width; x++) { |
| dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); |
| src += deltaSrc; |
| @@ -62,8 +391,13 @@ static bool swizzle_rgbx_to_n32(void* SK_RESTRICT dstRow, |
| static bool swizzle_rgba_to_n32_premul(void* SK_RESTRICT dstRow, |
| const uint8_t* SK_RESTRICT src, |
| - int width, int deltaSrc, int, const SkPMColor[]) { |
| + int width, int bitsPerPixel, int, |
| + const SkPMColor[], |
| + const SkSwizzler::ColorMasks, |
| + const SkSwizzler::AlphaOption, bool*, |
| + bool*) { |
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| + int deltaSrc = bitsPerPixel / 8; |
| unsigned alphaMask = 0xFF; |
| for (int x = 0; x < width; x++) { |
| unsigned alpha = src[3]; |
| @@ -76,9 +410,13 @@ static bool swizzle_rgba_to_n32_premul(void* SK_RESTRICT dstRow, |
| static bool swizzle_rgba_to_n32_unpremul(void* SK_RESTRICT dstRow, |
| const uint8_t* SK_RESTRICT src, |
| - int width, int deltaSrc, int, |
| - const SkPMColor[]) { |
| + int width, int bitsPerPixel, int, |
| + const SkPMColor[], |
| + const SkSwizzler::ColorMasks, |
| + const SkSwizzler::AlphaOption, bool*, |
| + bool*) { |
| uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
| + int deltaSrc = bitsPerPixel / 8; |
| unsigned alphaMask = 0xFF; |
| for (int x = 0; x < width; x++) { |
| unsigned alpha = src[3]; |
| @@ -91,9 +429,13 @@ static bool swizzle_rgba_to_n32_unpremul(void* SK_RESTRICT dstRow, |
| static bool swizzle_rgba_to_n32_premul_skipZ(void* SK_RESTRICT dstRow, |
| const uint8_t* SK_RESTRICT src, |
| - int width, int deltaSrc, int, |
| - const SkPMColor[]) { |
| + int width, int bitsPerPixel, int, |
| + const SkPMColor[], |
| + const SkSwizzler::ColorMasks, |
| + const SkSwizzler::AlphaOption, |
| + bool*, bool*) { |
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| + int deltaSrc = bitsPerPixel / 8; |
| unsigned alphaMask = 0xFF; |
| for (int x = 0; x < width; x++) { |
| unsigned alpha = src[3]; |
| @@ -114,7 +456,7 @@ static bool swizzle_rgba_to_n32_premul_skipZ(void* SK_RESTRICT dstRow, |
| decide whether to switch to unpremul default. |
| static bool swizzle_rgba_to_n32_unpremul_skipZ(void* SK_RESTRICT dstRow, |
| const uint8_t* SK_RESTRICT src, |
| - int width, int deltaSrc, int, |
| + int width, int bitsPerPixel, |
| const SkPMColor[]) { |
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| unsigned alphaMask = 0xFF; |
| @@ -133,31 +475,87 @@ static bool swizzle_rgba_to_n32_unpremul_skipZ(void* SK_RESTRICT dstRow, |
| } |
| */ |
| -SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, const SkPMColor* ctable, |
| +SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| + const SkPMColor* ctable, |
| const SkImageInfo& info, void* dst, |
| - size_t dstRowBytes, bool skipZeroes) { |
| - if (info.colorType() == kUnknown_SkColorType) { |
| + size_t dstRowBytes, bool skipZeroes, |
| + const ColorMasks bitMasks, |
| + const AlphaOption alphaOption, |
| + const RowOrder rowOrder) { |
| + if (kUnknown_SkColorType == info.colorType()) { |
| return NULL; |
| } |
| if (info.minRowBytes() > dstRowBytes) { |
| return NULL; |
| } |
| - if (kIndex == sc && NULL == ctable) { |
| + if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) |
| + && NULL == ctable) { |
| return NULL; |
| } |
| RowProc proc = NULL; |
| switch (sc) { |
| + case kIndex1: |
| + case kIndex2: |
| + case kIndex4: |
| + switch (info.colorType()) { |
| + case kN32_SkColorType: |
| + proc = &swizzle_small_index_to_n32; |
| + break; |
| + default: |
| + break; |
| + } |
| + break; |
| case kIndex: |
| switch (info.colorType()) { |
| case kN32_SkColorType: |
| - // We assume the color premultiplied ctable (or not) as desired. |
| - if (skipZeroes) { |
| - proc = &swizzle_index_to_n32_skipZ; |
| - } else { |
| - proc = &swizzle_index_to_n32; |
| - } |
| + proc = &swizzle_index_to_n32; |
| + break; |
| + default: |
| + break; |
| + } |
| + break; |
| + case kMask16: |
| + switch (info.colorType()) { |
| + case kN32_SkColorType: |
| + proc = &swizzle_mask16_to_n32; |
| + break; |
| + default: |
| + break; |
| + } |
| + break; |
| + case kMask24: |
| + switch (info.colorType()) { |
| + case kN32_SkColorType: |
| + proc = &swizzle_mask24_to_n32; |
| + break; |
| + default: |
| + break; |
| + } |
| + break; |
| + case kMask32: |
| + switch (info.colorType()) { |
| + case kN32_SkColorType: |
| + proc = &swizzle_mask32_to_n32; |
| + break; |
| + default: |
| + break; |
| + } |
| + break; |
| + case kBGR: |
| + case kBGRX: |
| + switch (info.colorType()) { |
| + case kN32_SkColorType: |
| + proc = &swizzle_bgrx_to_n32; |
| + break; |
| + default: |
| + break; |
| + } |
| + break; |
| + case kBGRA: |
| + switch (info.colorType()) { |
| + case kN32_SkColorType: |
| + proc = &swizzle_bgra_to_n32; |
| break; |
| - |
| default: |
| break; |
| } |
| @@ -190,33 +588,80 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, const SkPMColor |
| break; |
| } |
| break; |
| + case kRGB: |
| + switch (info.colorType()) { |
| + case kN32_SkColorType: |
| + proc = &swizzle_rgbx_to_n32; |
| + break; |
| + default: |
| + break; |
| + } |
| + break; |
| default: |
| break; |
| } |
| if (NULL == proc) { |
| return NULL; |
| } |
| - return SkNEW_ARGS(SkSwizzler, (proc, ctable, BytesPerPixel(sc), info, dst, dstRowBytes)); |
| + return SkNEW_ARGS(SkSwizzler, (proc, ctable, BitsPerPixel(sc), info, dst, |
| + dstRowBytes, bitMasks, alphaOption, rowOrder)); |
| } |
| -SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBpp, |
| - const SkImageInfo& info, void* dst, size_t rowBytes) |
| +SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, |
| + int srcBitsPerPixel, const SkImageInfo& info, void* dst, |
| + size_t rowBytes, const ColorMasks bitMasks, |
| + const AlphaOption alphaOption, const RowOrder rowOrder) |
| : fRowProc(proc) |
| , fColorTable(ctable) |
| - , fSrcPixelSize(srcBpp) |
| + , fSrcBitsPerPixel(srcBitsPerPixel) |
| , fDstInfo(info) |
| , fDstRow(dst) |
| , fDstRowBytes(rowBytes) |
| , fCurrY(0) |
| + , fBitMasks(bitMasks) |
| + , fAlphaOption(alphaOption) |
| + , fRowOrder(rowOrder) |
| + , fSeenNonZeroAlpha(false) |
| + , fZeroPrevRows(false) |
| { |
| } |
| bool SkSwizzler::next(const uint8_t* SK_RESTRICT src) { |
| SkASSERT(fCurrY < fDstInfo.height()); |
| - const bool hadAlpha = fRowProc(fDstRow, src, fDstInfo.width(), fSrcPixelSize, |
| - fCurrY, fColorTable); |
| + |
| + // On the first iteration, if the image is inverted, start at the bottom |
| + if (0 == fCurrY && kBottomUp_RowOrder == fRowOrder) { |
|
scroggo
2015/03/04 17:10:31
I think the bottom up row order is only going to b
|
| + fDstRow = SkTAddOffset<void>(fDstRow, |
| + fDstRowBytes * (fDstInfo.height() - 1)); |
| + } |
| + |
| + // Decode a row |
| + const bool hadAlpha = fRowProc(fDstRow, src, fDstInfo.width(), |
| + fSrcBitsPerPixel, fCurrY, fColorTable, fBitMasks, fAlphaOption, |
| + &fSeenNonZeroAlpha, &fZeroPrevRows); |
| + |
| + // This flag indicates that we have decoded the image as opaque instead of |
| + // transparent, and we just realized that it should have been transparent. |
| + // To fix this, we zero the rows that have already been decoded. |
| + if (fZeroPrevRows) { |
|
scroggo
2015/03/04 17:10:31
Some thoughts:
1) I think this behavior is exclus
|
| + void* dstRow; |
| + if (kTopDown_RowOrder == fRowOrder) { |
| + void* dstStart = SkTAddOffset<void>(fDstRow, -fCurrY*fDstRowBytes); |
| + memset(dstStart, 0, fCurrY*fDstRowBytes); |
| + } else { |
| + void* dstStart = SkTAddOffset<void>(fDstRow, fDstRowBytes); |
| + memset(dstStart, 0, fCurrY*fDstRowBytes); |
| + } |
| + fZeroPrevRows = false; |
| + } |
| + |
| + // Move to the next row and return the result |
| fCurrY++; |
| - fDstRow = SkTAddOffset<void>(fDstRow, fDstRowBytes); |
| + if (kTopDown_RowOrder == fRowOrder) { |
| + fDstRow = SkTAddOffset<void>(fDstRow, fDstRowBytes); |
| + } else { |
| + fDstRow = SkTAddOffset<void>(fDstRow, -fDstRowBytes); |
| + } |
| return hadAlpha; |
| } |