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

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: Update new 565 swizzling functions for scaling 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
« no previous file with comments | « src/codec/SkMaskSwizzler.cpp ('k') | src/codec/SkWebpCodec.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkSwizzler.cpp
diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp
index 44277614c650a075cdcb298e8fdfba8021ae660e..8315cc7145a406f698f0f9ca40f91df9b5af2eff 100644
--- a/src/codec/SkSwizzler.cpp
+++ b/src/codec/SkSwizzler.cpp
@@ -114,6 +114,34 @@ 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(
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
+ int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
+ uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
+
+ // increment src by byte offset and bitIndex by bit offset
+ src += offset / 8;
+ int bitIndex = offset % 8;
+ uint8_t currByte = *src;
+
+ dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLACK;
scroggo_chromium 2015/08/14 15:17:23 I think this function looks just like swizzle_bit_
msarett 2015/08/14 15:21:06 Looks good.
+
+ for (int x = 1; x < dstWidth; x++) {
+ int bitOffset = bitIndex + deltaSrc;
+ bitIndex = bitOffset % 8;
+ currByte = *(src += bitOffset / 8);
+ dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLACK;
+ }
+
+ return SkSwizzler::kOpaque_ResultAlpha;
+}
+
+#undef RGB565_BLACK
+#undef RGB565_WHITE
+
// kIndex1, kIndex2, kIndex4
static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
@@ -140,6 +168,29 @@ 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 dstWidth,
+ int bitsPerPixel, int offset, const SkPMColor ctable[]) {
+
+ src += offset;
+ uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
+ const uint32_t pixelsPerByte = 8 / bitsPerPixel;
+ const size_t rowBytes = compute_row_bytes_ppb(dstWidth, 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 < dstWidth; 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 dstWidth,
int bitsPerPixel, int offset, const SkPMColor ctable[]) {
@@ -306,6 +357,19 @@ 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 dstWidth,
+ int deltaSrc, int offset, const SkPMColor ctable[]) {
+ // FIXME: Support dithering?
+ src += offset;
+ uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
+ for (int x = 0; x < dstWidth; x++) {
+ dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]);
+ src += deltaSrc;
+ }
+ return SkSwizzler::kOpaque_ResultAlpha;
+}
+
// kBGRA
static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul(
@@ -470,6 +534,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;
@@ -484,6 +551,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;
@@ -534,6 +604,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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698