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

Unified Diff: src/codec/SkSwizzler.cpp

Issue 1277213002: Support more swizzles to 565 in SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Support wbmp, add tests Created 5 years, 4 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.cpp
diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp
index b2b7f927ac262913d86fcfd6c89af7cf430723cb..16c7830d9989b220125477c9acd9146383305d2b 100644
--- a/src/codec/SkSwizzler.cpp
+++ b/src/codec/SkSwizzler.cpp
@@ -112,6 +112,40 @@ static SkSwizzler::ResultAlpha swizzle_bit_to_n32(
return SkSwizzler::kOpaque_ResultAlpha;
}
+#define RGB565_BLACK 0
+#define RGB565_WHITE 0xFFFF
+
+static SkSwizzler::ResultAlpha swizzle_bit_to_565(
scroggo 2015/08/13 18:09:43 This method is the same as the other swizzle_bit m
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) {
+ uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
+
+ // Determine how many full bytes are in the row
+ int bytesInRow = width >> 3;
+ int i;
+ for (i = 0; i < bytesInRow; i++) {
+ U8CPU currByte = src[i];
+ for (int j = 0; j < 8; j++) {
+ dst[j] = ((currByte >> (7 - j)) & 1) ? RGB565_WHITE : RGB565_BLACK;
+ }
+ dst += 8;
+ }
+
+ // Finish the remaining bits
+ width &= 7;
+ if (width > 0) {
+ U8CPU currByte = src[i];
+ for (int j = 0; j < width; j++) {
+ dst[j] = ((currByte >> 7) & 1) ? RGB565_WHITE : RGB565_BLACK;
+ currByte <<= 1;
+ }
+ }
+ return SkSwizzler::kOpaque_ResultAlpha;
+}
+
+#undef RGB565_BLACK
+#undef RGB565_WHITE
+
// kIndex1, kIndex2, kIndex4
static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
@@ -137,6 +171,28 @@ static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
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, 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;
+}
+
static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
int bitsPerPixel, const SkPMColor ctable[]) {
@@ -271,6 +327,18 @@ 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, const SkPMColor ctable[]) {
+ // FIXME: Support dithering?
+ 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_unpremul(
@@ -425,6 +493,9 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
case kIndex_8_SkColorType:
proc = &swizzle_bit_to_index;
break;
+ case kRGB_565_SkColorType:
+ proc = &swizzle_bit_to_565;
+ break;
case kGray_8_SkColorType:
proc = &swizzle_bit_to_grayscale;
break;
@@ -439,6 +510,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;
case kIndex_8_SkColorType:
proc = &swizzle_small_index_to_index;
break;
@@ -489,6 +563,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;
}
« no previous file with comments | « src/codec/SkMaskSwizzler.cpp ('k') | src/codec/SkWebpCodec.cpp » ('j') | tests/CodexTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698