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

Unified Diff: src/codec/SkSwizzler.cpp

Issue 1277593002: Support decoding PNG to 565. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/SkCodec_libpng.cpp ('k') | no next file » | 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 998fbeb851f6bb99c36190419ad59730311da1a7..321baf1dc5ea5b01fbaf91d3608413d96ee6a9b5 100644
--- a/src/codec/SkSwizzler.cpp
+++ b/src/codec/SkSwizzler.cpp
@@ -116,6 +116,20 @@ 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, const SkPMColor ctable[]) {
+ // FIXME: Support dithering? Requires knowing y, which I think is a bigger
+ // change.
+ uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
+ for (int x = 0; x < width; x++) {
+ dst[x] = SkPixel32ToPixel16(ctable[*src]);
+ src += bytesPerPixel;
+ }
+ return SkSwizzler::kOpaque_ResultAlpha;
+}
+
+
#undef A32_MASK_IN_PLACE
// kGray
@@ -138,6 +152,18 @@ static SkSwizzler::ResultAlpha swizzle_gray_to_gray(
return SkSwizzler::kOpaque_ResultAlpha;
}
+static SkSwizzler::ResultAlpha swizzle_gray_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[0], src[0], src[0]);
+ src += bytesPerPixel;
+ }
+ return SkSwizzler::kOpaque_ResultAlpha;
+}
+
// kBGRX
static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32(
@@ -184,7 +210,7 @@ static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul(
return COMPUTE_RESULT_ALPHA;
}
-// n32
+// kRGBX
static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
int bytesPerPixel, const SkPMColor ctable[]) {
@@ -197,6 +223,20 @@ static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32(
return SkSwizzler::kOpaque_ResultAlpha;
}
+static SkSwizzler::ResultAlpha swizzle_rgbx_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[0], src[1], src[2]);
+ src += bytesPerPixel;
+ }
+ return SkSwizzler::kOpaque_ResultAlpha;
+}
+
+
+// kRGBA
static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
int bytesPerPixel, const SkPMColor ctable[]) {
@@ -310,6 +350,9 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
break;
}
break;
+ case kRGB_565_SkColorType:
+ proc = &swizzle_index_to_565;
+ break;
case kIndex_8_SkColorType:
proc = &swizzle_index_to_index;
break;
@@ -324,6 +367,10 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
break;
case kGray_8_SkColorType:
proc = &swizzle_gray_to_gray;
+ break;
+ case kRGB_565_SkColorType:
+ proc = &swizzle_gray_to_565;
+ break;
default:
break;
}
@@ -362,6 +409,8 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
case kN32_SkColorType:
proc = &swizzle_rgbx_to_n32;
break;
+ case kRGB_565_SkColorType:
+ proc = &swizzle_rgbx_to_565;
default:
break;
}
« no previous file with comments | « src/codec/SkCodec_libpng.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698