| Index: src/images/transform_scanline.h
|
| diff --git a/src/images/transform_scanline.h b/src/images/transform_scanline.h
|
| index 4baf6b6c6be25cecbf150ef31509afd45203ae1a..a02e98ab07326584cc0ab75924f94628d6212d33 100644
|
| --- a/src/images/transform_scanline.h
|
| +++ b/src/images/transform_scanline.h
|
| @@ -19,16 +19,17 @@
|
| * Function template for transforming scanlines.
|
| * Transform 'width' pixels from 'src' buffer into 'dst' buffer,
|
| * repacking color channel data as appropriate for the given transformation.
|
| + * 'bpp' is bytes per pixel in the 'src' buffer.
|
| */
|
| -typedef void (*transform_scanline_proc)(const char* SK_RESTRICT src,
|
| - int width, char* SK_RESTRICT dst);
|
| +typedef void (*transform_scanline_proc)(char* SK_RESTRICT dst, const char* SK_RESTRICT src,
|
| + int width, int bpp);
|
|
|
| /**
|
| * Identity transformation: just copy bytes from src to dst.
|
| */
|
| -static void transform_scanline_memcpy(const char* SK_RESTRICT src, int width,
|
| - char* SK_RESTRICT dst) {
|
| - memcpy(dst, src, width);
|
| +static void transform_scanline_memcpy(char* SK_RESTRICT dst, const char* SK_RESTRICT src,
|
| + int width, int bpp) {
|
| + memcpy(dst, src, width * bpp);
|
| }
|
|
|
| /**
|
| @@ -36,9 +37,9 @@ static void transform_scanline_memcpy(const char* SK_RESTRICT src, int width,
|
| * Alpha channel data is not present in kRGB_565_Config format, so there is no
|
| * alpha channel data to preserve.
|
| */
|
| -static void transform_scanline_565(const char* SK_RESTRICT src, int width,
|
| - char* SK_RESTRICT dst) {
|
| - const uint16_t* SK_RESTRICT srcP = (const uint16_t*)src;
|
| +static void transform_scanline_565(char* SK_RESTRICT dst, const char* SK_RESTRICT src,
|
| + int width, int) {
|
| + const uint16_t* srcP = (const uint16_t*)src;
|
| for (int i = 0; i < width; i++) {
|
| unsigned c = *srcP++;
|
| *dst++ = SkPacked16ToR32(c);
|
| @@ -48,17 +49,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_RGBX(char* SK_RESTRICT dst, const char* SK_RESTRICT src,
|
| + int width, int) {
|
| + const uint32_t* srcP = (const SkPMColor*)src;
|
| + for (int i = 0; i < width; i++) {
|
| + uint32_t 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_888(const char* SK_RESTRICT src, int width,
|
| - char* SK_RESTRICT dst) {
|
| - const SkPMColor* SK_RESTRICT srcP = (const SkPMColor*)src;
|
| +static void transform_scanline_BGRX(char* SK_RESTRICT dst, const char* SK_RESTRICT src,
|
| + int width, int) {
|
| + const uint32_t* srcP = (const SkPMColor*)src;
|
| for (int i = 0; i < width; i++) {
|
| - SkPMColor c = *srcP++;
|
| - *dst++ = SkGetPackedR32(c);
|
| - *dst++ = SkGetPackedG32(c);
|
| - *dst++ = SkGetPackedB32(c);
|
| + uint32_t c = *srcP++;
|
| + *dst++ = (c >> 16) & 0xFF;
|
| + *dst++ = (c >> 8) & 0xFF;
|
| + *dst++ = (c >> 0) & 0xFF;
|
| }
|
| }
|
|
|
| @@ -66,9 +82,9 @@ static void transform_scanline_888(const char* SK_RESTRICT src, int width,
|
| * Transform from kARGB_4444_Config to 3-bytes-per-pixel RGB.
|
| * Alpha channel data, if any, is abandoned.
|
| */
|
| -static void transform_scanline_444(const char* SK_RESTRICT src, int width,
|
| - char* SK_RESTRICT dst) {
|
| - const SkPMColor16* SK_RESTRICT srcP = (const SkPMColor16*)src;
|
| +static void transform_scanline_444(char* SK_RESTRICT dst, const char* SK_RESTRICT src,
|
| + int width, int) {
|
| + const SkPMColor16* srcP = (const SkPMColor16*)src;
|
| for (int i = 0; i < width; i++) {
|
| SkPMColor16 c = *srcP++;
|
| *dst++ = SkPacked4444ToR32(c);
|
| @@ -77,23 +93,26 @@ 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).
|
| - */
|
| -static void transform_scanline_8888(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();
|
| +template <bool kIsRGBA>
|
| +static inline void transform_scanline_unpremultiply(char* SK_RESTRICT dst,
|
| + const char* SK_RESTRICT src, int width, int) {
|
| + const uint32_t* srcP = (const SkPMColor*)src;
|
| + const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable();
|
|
|
| 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);
|
| + uint32_t c = *srcP++;
|
| + unsigned r, g, b, a;
|
| + if (kIsRGBA) {
|
| + r = (c >> 0) & 0xFF;
|
| + g = (c >> 8) & 0xFF;
|
| + b = (c >> 16) & 0xFF;
|
| + a = (c >> 24) & 0xFF;
|
| + } else {
|
| + r = (c >> 16) & 0xFF;
|
| + g = (c >> 8) & 0xFF;
|
| + b = (c >> 0) & 0xFF;
|
| + a = (c >> 24) & 0xFF;
|
| + }
|
|
|
| if (0 != a && 255 != a) {
|
| SkUnPreMultiply::Scale scale = table[a];
|
| @@ -109,14 +128,44 @@ static void transform_scanline_8888(const char* SK_RESTRICT src, int width,
|
| }
|
|
|
| /**
|
| + * Transform from kPremul, kRGBA_8888_SkColorType to 4-bytes-per-pixel unpremultiplied RGBA.
|
| + */
|
| +static void transform_scanline_rgbA(char* SK_RESTRICT dst, const char* SK_RESTRICT src,
|
| + int width, int bpp) {
|
| + transform_scanline_unpremultiply<true>(dst, src, width, bpp);
|
| +}
|
| +
|
| +/**
|
| + * Transform from kPremul, kBGRA_8888_SkColorType to 4-bytes-per-pixel unpremultiplied RGBA.
|
| + */
|
| +static void transform_scanline_bgrA(char* SK_RESTRICT dst, const char* SK_RESTRICT src,
|
| + int width, int bpp) {
|
| + transform_scanline_unpremultiply<false>(dst, src, width, bpp);
|
| +}
|
| +
|
| +/**
|
| + * Transform from kUnpremul, kBGRA_8888_SkColorType to 4-bytes-per-pixel unpremultiplied RGBA.
|
| + */
|
| +static void transform_scanline_BGRA(char* SK_RESTRICT dst, const char* SK_RESTRICT src,
|
| + int width, int) {
|
| + const uint32_t* srcP = (const SkPMColor*)src;
|
| + for (int i = 0; i < width; i++) {
|
| + uint32_t c = *srcP++;
|
| + *dst++ = (c >> 16) & 0xFF;
|
| + *dst++ = (c >> 8) & 0xFF;
|
| + *dst++ = (c >> 0) & 0xFF;
|
| + *dst++ = (c >> 24) & 0xFF;
|
| + }
|
| +}
|
| +
|
| +/**
|
| * Transform from kARGB_8888_Config to 4-bytes-per-pixel RGBA,
|
| * with scaling of RGB based on alpha channel.
|
| */
|
| -static void transform_scanline_4444(const char* SK_RESTRICT src, int width,
|
| - char* SK_RESTRICT dst) {
|
| - const SkPMColor16* SK_RESTRICT srcP = (const SkPMColor16*)src;
|
| - const SkUnPreMultiply::Scale* SK_RESTRICT table =
|
| - SkUnPreMultiply::GetScaleTable();
|
| +static void transform_scanline_4444(char* SK_RESTRICT dst, const char* SK_RESTRICT src,
|
| + int width, int) {
|
| + const SkPMColor16* srcP = (const SkPMColor16*)src;
|
| + const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable();
|
|
|
| for (int i = 0; i < width; i++) {
|
| SkPMColor16 c = *srcP++;
|
|
|