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

Unified Diff: src/codec/SkSwizzler.cpp

Issue 1557403002: Delete reallyHasAlpha() from SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 11 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/SkSwizzler.h ('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 aa58120451e135b76ad8d109ff78c4f337c01e2b..3e7387795b61c59b3b06f202218d78417680cae2 100644
--- a/src/codec/SkSwizzler.cpp
+++ b/src/codec/SkSwizzler.cpp
@@ -10,16 +10,8 @@
#include "SkSwizzler.h"
#include "SkTemplates.h"
-SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha,
- uint8_t maxAlpha) {
- // In the transparent case, this returns 0x0000
- // In the opaque case, this returns 0xFFFF
- // If the row is neither transparent nor opaque, returns something else
- return (((uint16_t) maxAlpha) << 8) | zeroAlpha;
-}
-
// samples the row. Does not do anything else but sampling
-static SkSwizzler::ResultAlpha sample565(void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src,
+static void sample565(void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src,
int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[]){
src += offset;
@@ -28,8 +20,6 @@ static SkSwizzler::ResultAlpha sample565(void* SK_RESTRICT dstRow, const uint8_t
dst[x] = src[1] << 8 | src[0];
src += deltaSrc;
}
- // 565 is always opaque
- return SkSwizzler::kOpaque_ResultAlpha;
}
// TODO (msarett): Investigate SIMD optimizations for swizzle routines.
@@ -42,7 +32,7 @@ static SkSwizzler::ResultAlpha sample565(void* SK_RESTRICT dstRow, const uint8_t
// same as swizzle_bit_to_index and swizzle_bit_to_n32 except for value assigned to dst[x]
-static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale(
+static void swizzle_bit_to_grayscale(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
@@ -61,15 +51,13 @@ static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale(
currByte = *(src += bitOffset / 8);
dst[x] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK;
}
-
- return SkSwizzler::kOpaque_ResultAlpha;
}
#undef GRAYSCALE_BLACK
#undef GRAYSCALE_WHITE
// same as swizzle_bit_to_grayscale and swizzle_bit_to_n32 except for value assigned to dst[x]
-static SkSwizzler::ResultAlpha swizzle_bit_to_index(
+static void swizzle_bit_to_index(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
@@ -87,12 +75,10 @@ static SkSwizzler::ResultAlpha swizzle_bit_to_index(
currByte = *(src += bitOffset / 8);
dst[x] = ((currByte >> (7-bitIndex)) & 1);
}
-
- return SkSwizzler::kOpaque_ResultAlpha;
}
// same as swizzle_bit_to_grayscale and swizzle_bit_to_index except for value assigned to dst[x]
-static SkSwizzler::ResultAlpha swizzle_bit_to_n32(
+static void swizzle_bit_to_n32(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
@@ -110,14 +96,12 @@ static SkSwizzler::ResultAlpha swizzle_bit_to_n32(
currByte = *(src += bitOffset / 8);
dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
}
-
- return SkSwizzler::kOpaque_ResultAlpha;
}
#define RGB565_BLACK 0
#define RGB565_WHITE 0xFFFF
-static SkSwizzler::ResultAlpha swizzle_bit_to_565(
+static void swizzle_bit_to_565(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
@@ -135,8 +119,6 @@ static SkSwizzler::ResultAlpha swizzle_bit_to_565(
currByte = *(src += bitOffset / 8);
dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLACK;
}
-
- return SkSwizzler::kOpaque_ResultAlpha;
}
#undef RGB565_BLACK
@@ -144,19 +126,17 @@ static SkSwizzler::ResultAlpha swizzle_bit_to_565(
// kIndex1, kIndex2, kIndex4
-static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
+static void swizzle_small_index_to_index(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
uint8_t* dst = (uint8_t*) dstRow;
- INIT_RESULT_ALPHA;
src += offset / 8;
int bitIndex = offset % 8;
uint8_t currByte = *src;
const uint8_t mask = (1 << bpp) - 1;
uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask;
dst[0] = index;
- UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
for (int x = 1; x < dstWidth; x++) {
int bitOffset = bitIndex + deltaSrc;
@@ -164,12 +144,10 @@ static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
currByte = *(src += bitOffset / 8);
index = (currByte >> (8 - bpp - bitIndex)) & mask;
dst[x] = index;
- UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
}
- return COMPUTE_RESULT_ALPHA;
}
-static SkSwizzler::ResultAlpha swizzle_small_index_to_565(
+static void swizzle_small_index_to_565(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
@@ -188,22 +166,19 @@ static SkSwizzler::ResultAlpha swizzle_small_index_to_565(
index = (currByte >> (8 - bpp - bitIndex)) & mask;
dst[x] = SkPixel32ToPixel16(ctable[index]);
}
- return SkAlphaType::kOpaque_SkAlphaType;
}
-static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
+static void swizzle_small_index_to_n32(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
SkPMColor* dst = (SkPMColor*) dstRow;
- INIT_RESULT_ALPHA;
src += offset / 8;
int bitIndex = offset % 8;
uint8_t currByte = *src;
const uint8_t mask = (1 << bpp) - 1;
uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask;
dst[0] = ctable[index];
- UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
for (int x = 1; x < dstWidth; x++) {
int bitOffset = bitIndex + deltaSrc;
@@ -211,92 +186,69 @@ static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
currByte = *(src += bitOffset / 8);
index = (currByte >> (8 - bpp - bitIndex)) & mask;
dst[x] = ctable[index];
- UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
}
- return COMPUTE_RESULT_ALPHA;
}
// kIndex
-static SkSwizzler::ResultAlpha swizzle_index_to_index(
+static void swizzle_index_to_index(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
src += offset;
uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
- INIT_RESULT_ALPHA;
- // TODO (msarett): Should we skip the loop here and guess that the row is opaque/not opaque?
- // SkScaledBitmap sampler just guesses that it is opaque. This is dangerous
- // and probably wrong since gif and bmp (rarely) may have alpha.
if (1 == deltaSrc) {
memcpy(dst, src, dstWidth);
- for (int x = 0; x < dstWidth; x++) {
- UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT);
- }
} else {
for (int x = 0; x < dstWidth; x++) {
dst[x] = *src;
- UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT);
src += deltaSrc;
}
}
- return COMPUTE_RESULT_ALPHA;
}
-static SkSwizzler::ResultAlpha swizzle_index_to_n32(
+static void swizzle_index_to_n32(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
src += offset;
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
- INIT_RESULT_ALPHA;
for (int x = 0; x < dstWidth; x++) {
SkPMColor c = ctable[*src];
- UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
dst[x] = c;
src += deltaSrc;
}
- return COMPUTE_RESULT_ALPHA;
}
-static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ(
+static void swizzle_index_to_n32_skipZ(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
src += offset;
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
- INIT_RESULT_ALPHA;
for (int x = 0; x < dstWidth; x++) {
SkPMColor c = ctable[*src];
- UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
if (c != 0) {
dst[x] = c;
}
src += deltaSrc;
}
- return COMPUTE_RESULT_ALPHA;
}
-static SkSwizzler::ResultAlpha swizzle_index_to_565(
+static void swizzle_index_to_565(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) {
- // FIXME: Support dithering? Requires knowing y, which I think is a bigger
- // change.
src += offset;
uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
for (int x = 0; x < dstWidth; x++) {
dst[x] = SkPixel32ToPixel16(ctable[*src]);
src += deltaSrc;
}
- return SkSwizzler::kOpaque_ResultAlpha;
}
-
-#undef A32_MASK_IN_PLACE
-
// kGray
-static SkSwizzler::ResultAlpha swizzle_gray_to_n32(
+static void swizzle_gray_to_n32(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
@@ -306,10 +258,9 @@ static SkSwizzler::ResultAlpha swizzle_gray_to_n32(
dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src);
src += deltaSrc;
}
- return SkSwizzler::kOpaque_ResultAlpha;
}
-static SkSwizzler::ResultAlpha swizzle_gray_to_gray(
+static void swizzle_gray_to_gray(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
@@ -323,25 +274,23 @@ static SkSwizzler::ResultAlpha swizzle_gray_to_gray(
src += deltaSrc;
}
}
- return SkSwizzler::kOpaque_ResultAlpha;
}
-static SkSwizzler::ResultAlpha swizzle_gray_to_565(
+static void swizzle_gray_to_565(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) {
- // FIXME: Support dithering?
+
src += offset;
uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
for (int x = 0; x < dstWidth; x++) {
dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]);
src += deltaSrc;
}
- return SkSwizzler::kOpaque_ResultAlpha;
}
// kBGRX
-static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32(
+static void swizzle_bgrx_to_n32(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
@@ -351,58 +300,50 @@ static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32(
dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]);
src += deltaSrc;
}
- return SkSwizzler::kOpaque_ResultAlpha;
}
-static SkSwizzler::ResultAlpha swizzle_bgrx_to_565(
+static void swizzle_bgrx_to_565(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
- // FIXME: Support dithering?
+
src += offset;
uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
for (int x = 0; x < dstWidth; x++) {
dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]);
src += deltaSrc;
}
- return SkSwizzler::kOpaque_ResultAlpha;
}
// kBGRA
-static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul(
+static void swizzle_bgra_to_n32_unpremul(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
src += offset;
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
- INIT_RESULT_ALPHA;
for (int x = 0; x < dstWidth; x++) {
uint8_t alpha = src[3];
- UPDATE_RESULT_ALPHA(alpha);
dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]);
src += deltaSrc;
}
- return COMPUTE_RESULT_ALPHA;
}
-static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul(
+static void swizzle_bgra_to_n32_premul(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
src += offset;
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
- INIT_RESULT_ALPHA;
for (int x = 0; x < dstWidth; x++) {
uint8_t alpha = src[3];
- UPDATE_RESULT_ALPHA(alpha);
dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]);
src += deltaSrc;
}
- return COMPUTE_RESULT_ALPHA;
}
// kRGBX
-static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32(
+static void swizzle_rgbx_to_n32(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
@@ -412,72 +353,61 @@ static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32(
dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]);
src += deltaSrc;
}
- return SkSwizzler::kOpaque_ResultAlpha;
}
-static SkSwizzler::ResultAlpha swizzle_rgbx_to_565(
+static void swizzle_rgbx_to_565(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) {
- // FIXME: Support dithering?
+
src += offset;
uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
for (int x = 0; x < dstWidth; x++) {
dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]);
src += deltaSrc;
}
- return SkSwizzler::kOpaque_ResultAlpha;
}
// kRGBA
-static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul(
+static void swizzle_rgba_to_n32_premul(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
src += offset;
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
- INIT_RESULT_ALPHA;
for (int x = 0; x < dstWidth; x++) {
unsigned alpha = src[3];
- UPDATE_RESULT_ALPHA(alpha);
dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]);
src += deltaSrc;
}
- return COMPUTE_RESULT_ALPHA;
}
-static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul(
+static void swizzle_rgba_to_n32_unpremul(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
src += offset;
uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
- INIT_RESULT_ALPHA;
for (int x = 0; x < dstWidth; x++) {
unsigned alpha = src[3];
- UPDATE_RESULT_ALPHA(alpha);
dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]);
src += deltaSrc;
}
- return COMPUTE_RESULT_ALPHA;
}
-static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ(
+static void swizzle_rgba_to_n32_premul_skipZ(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
src += offset;
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
- INIT_RESULT_ALPHA;
for (int x = 0; x < dstWidth; x++) {
unsigned alpha = src[3];
- UPDATE_RESULT_ALPHA(alpha);
if (0 != alpha) {
dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]);
}
src += deltaSrc;
}
- return COMPUTE_RESULT_ALPHA;
}
// kCMYK
@@ -525,7 +455,7 @@ static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ(
// R = C * K / 255
// G = M * K / 255
// B = Y * K / 255
-static SkSwizzler::ResultAlpha swizzle_cmyk_to_n32(
+static void swizzle_cmyk_to_n32(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
@@ -539,12 +469,9 @@ static SkSwizzler::ResultAlpha swizzle_cmyk_to_n32(
dst[x] = SkPackARGB32NoCheck(0xFF, r, g, b);
src += deltaSrc;
}
-
- // CMYK is always opaque
- return SkSwizzler::kOpaque_ResultAlpha;
}
-static SkSwizzler::ResultAlpha swizzle_cmyk_to_565(
+static void swizzle_cmyk_to_565(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
@@ -558,9 +485,6 @@ static SkSwizzler::ResultAlpha swizzle_cmyk_to_565(
dst[x] = SkPack888ToRGB16(r, g, b);
src += deltaSrc;
}
-
- // CMYK is always opaque
- return SkSwizzler::kOpaque_ResultAlpha;
}
/**
@@ -828,8 +752,8 @@ int SkSwizzler::onSetSampleX(int sampleX) {
return fAllocatedWidth;
}
-SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) {
+void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) {
SkASSERT(nullptr != dst && nullptr != src);
- return fRowProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP,
+ fRowProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP,
fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable);
}
« no previous file with comments | « src/codec/SkSwizzler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698