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

Unified Diff: src/images/transform_scanline.h

Issue 2325223002: Support RGBA/BGRA Premul/Unpremul from SkPNGImageEncoder (Closed)
Patch Set: Created 4 years, 3 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/images/transform_scanline.h
diff --git a/src/images/transform_scanline.h b/src/images/transform_scanline.h
index 4baf6b6c6be25cecbf150ef31509afd45203ae1a..ab970aed4cb1b1ee81ee62b9b34bd5c5f14a1cc0 100644
--- a/src/images/transform_scanline.h
+++ b/src/images/transform_scanline.h
@@ -48,17 +48,32 @@ static void transform_scanline_565(const char* SK_RESTRICT src, int width,
}
/**
- * Transform from kARGB_8888_Config to 3-bytes-per-pixel RGB.
- * Alpha channel data, if any, is abandoned.
+ * Transform from kRGBA_8888_SkColorType to 3-bytes-per-pixel RGB.
+ * Alpha channel data is abandoned.
*/
-static void transform_scanline_888(const char* SK_RESTRICT src, int width,
- char* SK_RESTRICT dst) {
+static void transform_scanline_RGB1(const char* SK_RESTRICT src, int width,
+ char* SK_RESTRICT dst) {
+ const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
+ for (int i = 0; i < width; i++) {
+ SkPMColor c = *srcP++;
+ *dst++ = (c >> 0) & 0xFF;
+ *dst++ = (c >> 8) & 0xFF;
+ *dst++ = (c >> 16) & 0xFF;
+ }
+}
+
+/**
+ * Transform from kBGRA_8888_SkColorType to 3-bytes-per-pixel RGB.
+ * Alpha channel data is abandoned.
+ */
+static void transform_scanline_BGR1(const char* SK_RESTRICT src, int width,
+ char* SK_RESTRICT dst) {
const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
for (int i = 0; i < width; i++) {
SkPMColor c = *srcP++;
- *dst++ = SkGetPackedR32(c);
- *dst++ = SkGetPackedG32(c);
- *dst++ = SkGetPackedB32(c);
+ *dst++ = (c >> 16) & 0xFF;
+ *dst++ = (c >> 8) & 0xFF;
+ *dst++ = (c >> 0) & 0xFF;
}
}
@@ -78,11 +93,9 @@ static void transform_scanline_444(const char* SK_RESTRICT src, int width,
}
/**
- * Transform from kARGB_8888_Config to 4-bytes-per-pixel RGBA.
- * (This would be the identity transformation, except for byte-order and
- * scaling of RGB based on alpha channel).
+ * Transform from kPremul, kRGBA_8888_SkColorType to 4-bytes-per-pixel unpremultiplied RGBA.
*/
-static void transform_scanline_8888(const char* SK_RESTRICT src, int width,
+static void transform_scanline_rgbA(const char* SK_RESTRICT src, int width,
char* SK_RESTRICT dst) {
const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
const SkUnPreMultiply::Scale* SK_RESTRICT table =
@@ -90,10 +103,10 @@ static void transform_scanline_8888(const char* SK_RESTRICT src, int width,
for (int i = 0; i < width; i++) {
SkPMColor c = *srcP++;
- unsigned a = SkGetPackedA32(c);
- unsigned r = SkGetPackedR32(c);
- unsigned g = SkGetPackedG32(c);
- unsigned b = SkGetPackedB32(c);
+ unsigned r = (c >> 0) & 0xFF;
+ unsigned g = (c >> 8) & 0xFF;
+ unsigned b = (c >> 16) & 0xFF;
+ unsigned a = (c >> 24) & 0xFF;
if (0 != a && 255 != a) {
SkUnPreMultiply::Scale scale = table[a];
@@ -109,6 +122,56 @@ static void transform_scanline_8888(const char* SK_RESTRICT src, int width,
}
/**
+ * Transform from kPremul, kBGRA_8888_SkColorType to 4-bytes-per-pixel unpremultiplied RGBA.
+ */
+static void transform_scanline_bgrA(const char* SK_RESTRICT src, int width,
+ char* SK_RESTRICT dst) {
+ const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
+ const SkUnPreMultiply::Scale* SK_RESTRICT table =
+ SkUnPreMultiply::GetScaleTable();
+
+ for (int i = 0; i < width; i++) {
+ SkPMColor c = *srcP++;
+ unsigned r = (c >> 16) & 0xFF;
+ unsigned g = (c >> 8) & 0xFF;
+ unsigned b = (c >> 0) & 0xFF;
+ unsigned a = (c >> 24) & 0xFF;
+
+ if (0 != a && 255 != a) {
+ SkUnPreMultiply::Scale scale = table[a];
+ r = SkUnPreMultiply::ApplyScale(scale, r);
+ g = SkUnPreMultiply::ApplyScale(scale, g);
+ b = SkUnPreMultiply::ApplyScale(scale, b);
+ }
+ *dst++ = r;
+ *dst++ = g;
+ *dst++ = b;
+ *dst++ = a;
+ }
+}
+
+/**
+ * Transform from kUnpremul, kRGBA_8888_SkColorType to 4-bytes-per-pixel unpremultiplied RGBA.
+ */
+static void transform_scanline_RGBA(const char* SK_RESTRICT src, int width, char* SK_RESTRICT dst) {
+ memcpy(dst, src, sizeof(SkPMColor) * width);
+}
+
+/**
+ * Transform from kUnpremul, kBGRA_8888_SkColorType to 4-bytes-per-pixel unpremultiplied RGBA.
+ */
+static void transform_scanline_BGRA(const char* SK_RESTRICT src, int width, char* SK_RESTRICT dst) {
+ const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
+ for (int i = 0; i < width; i++) {
+ SkPMColor c = *srcP++;
+ *dst++ = (c >> 0) & 0xFF;
+ *dst++ = (c >> 8) & 0xFF;
+ *dst++ = (c >> 16) & 0xFF;
+ *dst++ = (c >> 24) & 0xFF;
+ }
+}
+
+/**
* Transform from kARGB_8888_Config to 4-bytes-per-pixel RGBA,
* with scaling of RGB based on alpha channel.
*/

Powered by Google App Engine
This is Rietveld 408576698