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

Unified Diff: src/codec/SkSwizzler.cpp

Issue 1254483004: Scanline decoding for wbmp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use SkSwizzler Created 5 years, 5 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 a91cf511ee99ce312fcafada4bd040f43d5e0394..faf7cc4630f4fc2c4d34a85ab8496603215dd73f 100644
--- a/src/codec/SkSwizzler.cpp
+++ b/src/codec/SkSwizzler.cpp
@@ -21,6 +21,37 @@ SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha,
// kIndex1, kIndex2, kIndex4
+#define GRAYSCALE_BLACK 0
scroggo 2015/07/28 14:03:34 I'm kind of surprised we do not have these already
msarett 2015/07/28 22:22:07 Me too, but I looked a little harder and I actuall
scroggo 2015/07/29 17:47:12 No, I think what you've done here is perfect!
+#define GRAYSCALE_WHITE 0xFF
+
+// This routine is currently expected to be used exclusively by wbmp.
scroggo 2015/07/28 14:03:34 What is wbmp-specific about it? I suppose just tha
msarett 2015/07/28 22:22:07 Agreed.
+static SkSwizzler::ResultAlpha swizzle_small_index_to_gray(
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bitsPerPixel, const SkPMColor ctable[]) {
+
+
+
+ uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
+ INIT_RESULT_ALPHA;
+ const uint32_t pixelsPerByte = 8 / bitsPerPixel;
scroggo 2015/07/28 14:03:34 It's too bad we have to have a divide for each row
msarett 2015/07/28 22:22:07 Yeah I wanted wbmp to share with small_index, but
+ 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 bit = (pixelData >> (8 - bitsPerPixel)) & mask;
+ dst[x] = bit ? GRAYSCALE_WHITE : GRAYSCALE_BLACK;
+ pixelData <<= bitsPerPixel;
+ x++;
+ }
+ }
+ return SkSwizzler::kOpaque_ResultAlpha;
+}
+
+#undef GRAYSCALE_BLACK
+#undef GRAYSCALE_WHITE
+
static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
int bitsPerPixel, const SkPMColor ctable[]) {
@@ -294,6 +325,8 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
case kIndex_8_SkColorType:
proc = &swizzle_small_index_to_index;
break;
+ case kGray_8_SkColorType:
+ proc = &swizzle_small_index_to_gray;
default:
break;
}

Powered by Google App Engine
This is Rietveld 408576698