Index: src/codec/SkSwizzler.cpp |
diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp |
index 0668db6db9e45a25091189fa0dff0946f1c64df4..7789c187fa6a79533cab969d73a59380830dd266 100644 |
--- a/src/codec/SkSwizzler.cpp |
+++ b/src/codec/SkSwizzler.cpp |
@@ -44,6 +44,28 @@ static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( |
return COMPUTE_RESULT_ALPHA; |
} |
+static SkSwizzler::ResultAlpha swizzle_small_index_to_565( |
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
+ int bitsPerPixel, int y, const SkPMColor ctable[]) { |
+ |
+ uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; |
+ const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
+ const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); |
+ const uint8_t mask = (1 << bitsPerPixel) - 1; |
+ int 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; |
+ uint16_t c = SkPixel32ToPixel16(ctable[index]); |
+ dst[x] = c; |
+ pixelData <<= bitsPerPixel; |
+ x++; |
+ } |
+ } |
+ return SkSwizzler::kOpaque_ResultAlpha; |
+} |
+ |
// kIndex |
static SkSwizzler::ResultAlpha swizzle_index_to_n32( |
@@ -78,6 +100,19 @@ static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( |
return COMPUTE_RESULT_ALPHA; |
} |
+static SkSwizzler::ResultAlpha swizzle_index_to_565( |
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
+ int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ |
+ uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
+ for (int x = 0; x < width; x++) { |
+ uint16_t c = SkPixel32ToPixel16(ctable[*src]); |
+ dst[x] = c; |
+ src++; |
+ } |
+ return SkSwizzler::kOpaque_ResultAlpha; |
+} |
+ |
#undef A32_MASK_IN_PLACE |
static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( |
@@ -92,9 +127,21 @@ static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( |
return SkSwizzler::kOpaque_ResultAlpha; |
} |
+static SkSwizzler::ResultAlpha swizzle_bgrx_to_565( |
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
+ int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ |
+ uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
+ for (int x = 0; x < width; x++) { |
+ dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); |
+ src += bytesPerPixel; |
+ } |
+ return SkSwizzler::kOpaque_ResultAlpha; |
+} |
+ |
// kBGRA |
-static SkSwizzler::ResultAlpha swizzle_bgra_to_n32( |
+static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
int bytesPerPixel, int y, const SkPMColor ctable[]) { |
@@ -109,6 +156,37 @@ static SkSwizzler::ResultAlpha swizzle_bgra_to_n32( |
return COMPUTE_RESULT_ALPHA; |
} |
+static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( |
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
+ int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ |
+ SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
+ INIT_RESULT_ALPHA; |
+ for (int x = 0; x < width; x++) { |
+ uint8_t alpha = src[3]; |
+ UPDATE_RESULT_ALPHA(alpha); |
+ dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); |
+ src += bytesPerPixel; |
+ } |
+ return COMPUTE_RESULT_ALPHA; |
+} |
+ |
+static SkSwizzler::ResultAlpha swizzle_bgra_to_565_premul( |
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
+ int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ |
+ uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
+ INIT_RESULT_ALPHA; |
+ for (int x = 0; x < width; x++) { |
+ uint8_t alpha = src[3]; |
+ UPDATE_RESULT_ALPHA(alpha); |
+ dst[x] = SkPixel32ToPixel16( |
+ SkPreMultiplyARGB(alpha, src[2], src[1], src[0])); |
+ src += bytesPerPixel; |
+ } |
+ return COMPUTE_RESULT_ALPHA; |
+} |
+ |
// n32 |
static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
@@ -219,6 +297,9 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
case kN32_SkColorType: |
proc = &swizzle_small_index_to_n32; |
break; |
+ case kRGB_565_SkColorType: |
+ proc = &swizzle_small_index_to_565; |
+ break; |
default: |
break; |
} |
@@ -228,10 +309,15 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
case kN32_SkColorType: |
if (skipZeroes) { |
proc = &swizzle_index_to_n32_skipZ; |
+ break; |
} else { |
proc = &swizzle_index_to_n32; |
+ break; |
} |
break; |
+ case kRGB_565_SkColorType: |
+ proc = &swizzle_index_to_565; |
+ break; |
default: |
break; |
} |
@@ -242,6 +328,9 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
case kN32_SkColorType: |
proc = &swizzle_bgrx_to_n32; |
break; |
+ case kRGB_565_SkColorType: |
+ proc = &swizzle_bgrx_to_565; |
+ break; |
default: |
break; |
} |
@@ -249,7 +338,21 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
case kBGRA: |
switch (info.colorType()) { |
case kN32_SkColorType: |
- proc = &swizzle_bgra_to_n32; |
+ switch (info.alphaType()) { |
+ case kUnpremul_SkAlphaType: |
+ proc = &swizzle_bgra_to_n32_unpremul; |
+ break; |
+ case kPremul_SkAlphaType: |
+ proc = &swizzle_bgra_to_n32_premul; |
+ break; |
+ default: |
+ break; |
+ } |
+ break; |
+ case kRGB_565_SkColorType: |
+ // TODO: I'm guessing swizzles to we should assume premul |
+ // on swizzles to 565. |
+ proc = &swizzle_bgra_to_565_premul; |
msarett
2015/03/16 20:21:53
If the image is not opaque, I always premultiply b
scroggo
2015/03/17 13:27:23
If the image is 565, we should not allow using pre
msarett
2015/03/17 16:54:06
Done. I will disallow in conversion possible and
|
break; |
default: |
break; |