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

Unified Diff: src/codec/SkMaskSwizzler.cpp

Issue 1907593004: Support the non-native (RGBA/BGRA) swizzle (Closed) Base URL: https://skia.googlesource.com/skia.git@tryagain
Patch Set: Multiple bug fixes Created 4 years, 8 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/SkJpegCodec.cpp ('k') | src/codec/SkPngCodec.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkMaskSwizzler.cpp
diff --git a/src/codec/SkMaskSwizzler.cpp b/src/codec/SkMaskSwizzler.cpp
index 7630a7b59f063b403cee46295ee1d59380a88456..2df10ee24cbc8f5d97bf2fd8dbd0e48756dbeffa 100644
--- a/src/codec/SkMaskSwizzler.cpp
+++ b/src/codec/SkMaskSwizzler.cpp
@@ -9,7 +9,7 @@
#include "SkColorPriv.h"
#include "SkMaskSwizzler.h"
-static void swizzle_mask16_to_n32_opaque(
+static void swizzle_mask16_to_rgba_opaque(
void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
uint32_t startX, uint32_t sampleX) {
@@ -21,12 +21,29 @@ static void swizzle_mask16_to_n32_opaque(
uint8_t red = masks->getRed(p);
uint8_t green = masks->getGreen(p);
uint8_t blue = masks->getBlue(p);
- dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue);
+ dstPtr[i] = SkPackARGB_as_RGBA(0xFF, red, green, blue);
srcPtr += sampleX;
}
}
-static void swizzle_mask16_to_n32_unpremul(
+static void swizzle_mask16_to_bgra_opaque(
+ void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
+ uint32_t startX, uint32_t sampleX) {
+
+ // Use the masks to decode to the destination
+ uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
+ SkPMColor* dstPtr = (SkPMColor*) dstRow;
+ for (int i = 0; i < width; i++) {
+ uint16_t p = srcPtr[0];
+ uint8_t red = masks->getRed(p);
+ uint8_t green = masks->getGreen(p);
+ uint8_t blue = masks->getBlue(p);
+ dstPtr[i] = SkPackARGB_as_BGRA(0xFF, red, green, blue);
+ srcPtr += sampleX;
+ }
+}
+
+static void swizzle_mask16_to_rgba_unpremul(
void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
uint32_t startX, uint32_t sampleX) {
@@ -39,12 +56,12 @@ static void swizzle_mask16_to_n32_unpremul(
uint8_t green = masks->getGreen(p);
uint8_t blue = masks->getBlue(p);
uint8_t alpha = masks->getAlpha(p);
- dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue);
+ dstPtr[i] = SkPackARGB_as_RGBA(alpha, red, green, blue);
srcPtr += sampleX;
}
}
-static void swizzle_mask16_to_n32_premul(
+static void swizzle_mask16_to_bgra_unpremul(
void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
uint32_t startX, uint32_t sampleX) {
@@ -57,7 +74,43 @@ static void swizzle_mask16_to_n32_premul(
uint8_t green = masks->getGreen(p);
uint8_t blue = masks->getBlue(p);
uint8_t alpha = masks->getAlpha(p);
- dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue);
+ dstPtr[i] = SkPackARGB_as_BGRA(alpha, red, green, blue);
+ srcPtr += sampleX;
+ }
+}
+
+static void swizzle_mask16_to_rgba_premul(
+ void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
+ uint32_t startX, uint32_t sampleX) {
+
+ // Use the masks to decode to the destination
+ uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
+ SkPMColor* dstPtr = (SkPMColor*) dstRow;
+ for (int i = 0; i < width; i++) {
+ uint16_t p = srcPtr[0];
+ uint8_t red = masks->getRed(p);
+ uint8_t green = masks->getGreen(p);
+ uint8_t blue = masks->getBlue(p);
+ uint8_t alpha = masks->getAlpha(p);
+ dstPtr[i] = premultiply_argb_as_rgba(alpha, red, green, blue);
+ srcPtr += sampleX;
+ }
+}
+
+static void swizzle_mask16_to_bgra_premul(
+ void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
+ uint32_t startX, uint32_t sampleX) {
+
+ // Use the masks to decode to the destination
+ uint16_t* srcPtr = ((uint16_t*) srcRow) + startX;
+ SkPMColor* dstPtr = (SkPMColor*) dstRow;
+ for (int i = 0; i < width; i++) {
+ uint16_t p = srcPtr[0];
+ uint8_t red = masks->getRed(p);
+ uint8_t green = masks->getGreen(p);
+ uint8_t blue = masks->getBlue(p);
+ uint8_t alpha = masks->getAlpha(p);
+ dstPtr[i] = premultiply_argb_as_bgra(alpha, red, green, blue);
srcPtr += sampleX;
}
}
@@ -81,7 +134,41 @@ static void swizzle_mask16_to_565(
}
}
-static void swizzle_mask24_to_n32_opaque(
+static void swizzle_mask24_to_rgba_opaque(
+ void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
+ uint32_t startX, uint32_t sampleX) {
+
+ // Use the masks to decode to the destination
+ srcRow += 3 * startX;
+ SkPMColor* dstPtr = (SkPMColor*) dstRow;
+ for (int i = 0; i < width; i++) {
+ uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
+ uint8_t red = masks->getRed(p);
+ uint8_t green = masks->getGreen(p);
+ uint8_t blue = masks->getBlue(p);
+ dstPtr[i] = SkPackARGB_as_RGBA(0xFF, red, green, blue);
+ srcRow += 3 * sampleX;
+ }
+}
+
+static void swizzle_mask24_to_bgra_opaque(
+ void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
+ uint32_t startX, uint32_t sampleX) {
+
+ // Use the masks to decode to the destination
+ srcRow += 3 * startX;
+ SkPMColor* dstPtr = (SkPMColor*) dstRow;
+ for (int i = 0; i < width; i++) {
+ uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
+ uint8_t red = masks->getRed(p);
+ uint8_t green = masks->getGreen(p);
+ uint8_t blue = masks->getBlue(p);
+ dstPtr[i] = SkPackARGB_as_BGRA(0xFF, red, green, blue);
+ srcRow += 3 * sampleX;
+ }
+}
+
+static void swizzle_mask24_to_rgba_unpremul(
void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
uint32_t startX, uint32_t sampleX) {
@@ -93,12 +180,13 @@ static void swizzle_mask24_to_n32_opaque(
uint8_t red = masks->getRed(p);
uint8_t green = masks->getGreen(p);
uint8_t blue = masks->getBlue(p);
- dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue);
+ uint8_t alpha = masks->getAlpha(p);
+ dstPtr[i] = SkPackARGB_as_RGBA(alpha, red, green, blue);
srcRow += 3 * sampleX;
}
}
-static void swizzle_mask24_to_n32_unpremul(
+static void swizzle_mask24_to_bgra_unpremul(
void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
uint32_t startX, uint32_t sampleX) {
@@ -111,12 +199,12 @@ static void swizzle_mask24_to_n32_unpremul(
uint8_t green = masks->getGreen(p);
uint8_t blue = masks->getBlue(p);
uint8_t alpha = masks->getAlpha(p);
- dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue);
+ dstPtr[i] = SkPackARGB_as_BGRA(alpha, red, green, blue);
srcRow += 3 * sampleX;
}
}
-static void swizzle_mask24_to_n32_premul(
+static void swizzle_mask24_to_rgba_premul(
void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
uint32_t startX, uint32_t sampleX) {
@@ -129,7 +217,25 @@ static void swizzle_mask24_to_n32_premul(
uint8_t green = masks->getGreen(p);
uint8_t blue = masks->getBlue(p);
uint8_t alpha = masks->getAlpha(p);
- dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue);
+ dstPtr[i] = premultiply_argb_as_rgba(alpha, red, green, blue);
+ srcRow += 3 * sampleX;
+ }
+}
+
+static void swizzle_mask24_to_bgra_premul(
+ void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
+ uint32_t startX, uint32_t sampleX) {
+
+ // Use the masks to decode to the destination
+ srcRow += 3 * startX;
+ SkPMColor* dstPtr = (SkPMColor*) dstRow;
+ for (int i = 0; i < width; i++) {
+ uint32_t p = srcRow[0] | (srcRow[1] << 8) | srcRow[2] << 16;
+ uint8_t red = masks->getRed(p);
+ uint8_t green = masks->getGreen(p);
+ uint8_t blue = masks->getBlue(p);
+ uint8_t alpha = masks->getAlpha(p);
+ dstPtr[i] = premultiply_argb_as_bgra(alpha, red, green, blue);
srcRow += 3 * sampleX;
}
}
@@ -151,7 +257,59 @@ static void swizzle_mask24_to_565(
}
}
-static void swizzle_mask32_to_n32_opaque(
+static void swizzle_mask32_to_rgba_opaque(
+ void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
+ uint32_t startX, uint32_t sampleX) {
+
+ // Use the masks to decode to the destination
+ uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
+ SkPMColor* dstPtr = (SkPMColor*) dstRow;
+ for (int i = 0; i < width; i++) {
+ uint32_t p = srcPtr[0];
+ uint8_t red = masks->getRed(p);
+ uint8_t green = masks->getGreen(p);
+ uint8_t blue = masks->getBlue(p);
+ dstPtr[i] = SkPackARGB_as_RGBA(0xFF, red, green, blue);
+ srcPtr += sampleX;
+ }
+}
+
+static void swizzle_mask32_to_bgra_opaque(
+ void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
+ uint32_t startX, uint32_t sampleX) {
+
+ // Use the masks to decode to the destination
+ uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
+ SkPMColor* dstPtr = (SkPMColor*) dstRow;
+ for (int i = 0; i < width; i++) {
+ uint32_t p = srcPtr[0];
+ uint8_t red = masks->getRed(p);
+ uint8_t green = masks->getGreen(p);
+ uint8_t blue = masks->getBlue(p);
+ dstPtr[i] = SkPackARGB_as_BGRA(0xFF, red, green, blue);
+ srcPtr += sampleX;
+ }
+}
+
+static void swizzle_mask32_to_rgba_unpremul(
+ void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
+ uint32_t startX, uint32_t sampleX) {
+
+ // Use the masks to decode to the destination
+ uint32_t* srcPtr = ((uint32_t*) srcRow) + startX;
+ SkPMColor* dstPtr = (SkPMColor*) dstRow;
+ for (int i = 0; i < width; i++) {
+ uint32_t p = srcPtr[0];
+ uint8_t red = masks->getRed(p);
+ uint8_t green = masks->getGreen(p);
+ uint8_t blue = masks->getBlue(p);
+ uint8_t alpha = masks->getAlpha(p);
+ dstPtr[i] = SkPackARGB_as_RGBA(alpha, red, green, blue);
+ srcPtr += sampleX;
+ }
+}
+
+static void swizzle_mask32_to_bgra_unpremul(
void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
uint32_t startX, uint32_t sampleX) {
@@ -163,12 +321,13 @@ static void swizzle_mask32_to_n32_opaque(
uint8_t red = masks->getRed(p);
uint8_t green = masks->getGreen(p);
uint8_t blue = masks->getBlue(p);
- dstPtr[i] = SkPackARGB32NoCheck(0xFF, red, green, blue);
+ uint8_t alpha = masks->getAlpha(p);
+ dstPtr[i] = SkPackARGB_as_BGRA(alpha, red, green, blue);
srcPtr += sampleX;
}
}
-static void swizzle_mask32_to_n32_unpremul(
+static void swizzle_mask32_to_rgba_premul(
void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
uint32_t startX, uint32_t sampleX) {
@@ -181,12 +340,12 @@ static void swizzle_mask32_to_n32_unpremul(
uint8_t green = masks->getGreen(p);
uint8_t blue = masks->getBlue(p);
uint8_t alpha = masks->getAlpha(p);
- dstPtr[i] = SkPackARGB32NoCheck(alpha, red, green, blue);
+ dstPtr[i] = premultiply_argb_as_rgba(alpha, red, green, blue);
srcPtr += sampleX;
}
}
-static void swizzle_mask32_to_n32_premul(
+static void swizzle_mask32_to_bgra_premul(
void* dstRow, const uint8_t* srcRow, int width, SkMasks* masks,
uint32_t startX, uint32_t sampleX) {
@@ -199,7 +358,7 @@ static void swizzle_mask32_to_n32_premul(
uint8_t green = masks->getGreen(p);
uint8_t blue = masks->getBlue(p);
uint8_t alpha = masks->getAlpha(p);
- dstPtr[i] = SkPreMultiplyARGB(alpha, red, green, blue);
+ dstPtr[i] = premultiply_argb_as_bgra(alpha, red, green, blue);
srcPtr += sampleX;
}
}
@@ -234,16 +393,32 @@ SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo,
switch (bitsPerPixel) {
case 16:
switch (dstInfo.colorType()) {
- case kN32_SkColorType:
+ case kRGBA_8888_SkColorType:
+ if (kOpaque_SkAlphaType == srcInfo.alphaType()) {
+ proc = &swizzle_mask16_to_rgba_opaque;
+ } else {
+ switch (dstInfo.alphaType()) {
+ case kUnpremul_SkAlphaType:
+ proc = &swizzle_mask16_to_rgba_unpremul;
+ break;
+ case kPremul_SkAlphaType:
+ proc = &swizzle_mask16_to_rgba_premul;
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case kBGRA_8888_SkColorType:
if (kOpaque_SkAlphaType == srcInfo.alphaType()) {
- proc = &swizzle_mask16_to_n32_opaque;
+ proc = &swizzle_mask16_to_bgra_opaque;
} else {
switch (dstInfo.alphaType()) {
case kUnpremul_SkAlphaType:
- proc = &swizzle_mask16_to_n32_unpremul;
+ proc = &swizzle_mask16_to_bgra_unpremul;
break;
case kPremul_SkAlphaType:
- proc = &swizzle_mask16_to_n32_premul;
+ proc = &swizzle_mask16_to_bgra_premul;
break;
default:
break;
@@ -259,16 +434,32 @@ SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo,
break;
case 24:
switch (dstInfo.colorType()) {
- case kN32_SkColorType:
+ case kRGBA_8888_SkColorType:
+ if (kOpaque_SkAlphaType == srcInfo.alphaType()) {
+ proc = &swizzle_mask24_to_rgba_opaque;
+ } else {
+ switch (dstInfo.alphaType()) {
+ case kUnpremul_SkAlphaType:
+ proc = &swizzle_mask24_to_rgba_unpremul;
+ break;
+ case kPremul_SkAlphaType:
+ proc = &swizzle_mask24_to_rgba_premul;
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case kBGRA_8888_SkColorType:
if (kOpaque_SkAlphaType == srcInfo.alphaType()) {
- proc = &swizzle_mask24_to_n32_opaque;
+ proc = &swizzle_mask24_to_bgra_opaque;
} else {
switch (dstInfo.alphaType()) {
case kUnpremul_SkAlphaType:
- proc = &swizzle_mask24_to_n32_unpremul;
+ proc = &swizzle_mask24_to_bgra_unpremul;
break;
case kPremul_SkAlphaType:
- proc = &swizzle_mask24_to_n32_premul;
+ proc = &swizzle_mask24_to_bgra_premul;
break;
default:
break;
@@ -284,16 +475,32 @@ SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo,
break;
case 32:
switch (dstInfo.colorType()) {
- case kN32_SkColorType:
+ case kRGBA_8888_SkColorType:
+ if (kOpaque_SkAlphaType == srcInfo.alphaType()) {
+ proc = &swizzle_mask32_to_rgba_opaque;
+ } else {
+ switch (dstInfo.alphaType()) {
+ case kUnpremul_SkAlphaType:
+ proc = &swizzle_mask32_to_rgba_unpremul;
+ break;
+ case kPremul_SkAlphaType:
+ proc = &swizzle_mask32_to_rgba_premul;
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case kBGRA_8888_SkColorType:
if (kOpaque_SkAlphaType == srcInfo.alphaType()) {
- proc = &swizzle_mask32_to_n32_opaque;
+ proc = &swizzle_mask32_to_bgra_opaque;
} else {
switch (dstInfo.alphaType()) {
case kUnpremul_SkAlphaType:
- proc = &swizzle_mask32_to_n32_unpremul;
+ proc = &swizzle_mask32_to_bgra_unpremul;
break;
case kPremul_SkAlphaType:
- proc = &swizzle_mask32_to_n32_premul;
+ proc = &swizzle_mask32_to_bgra_premul;
break;
default:
break;
« no previous file with comments | « src/codec/SkJpegCodec.cpp ('k') | src/codec/SkPngCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698