Index: src/codec/SkSwizzler.cpp |
diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp |
index 71cb82a08bc5803fd6f8877044b452a3d1591cd3..9f5d10d13e19e5816e8ef5d8beaa6816d702001c 100644 |
--- a/src/codec/SkSwizzler.cpp |
+++ b/src/codec/SkSwizzler.cpp |
@@ -72,10 +72,17 @@ static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( |
static SkSwizzler::ResultAlpha swizzle_index_to_index( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
- int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ int deltaSrc, int y, const SkPMColor ctable[]) { |
uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
- memcpy(dst, src, width); |
+ if (1 == deltaSrc) { |
+ memcpy(dst, src, width); |
+ } else { |
+ for (int x = 0; x < width; x++) { |
+ dst[x] = src[0]; |
+ src += deltaSrc; |
+ } |
+ } |
// 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. |
@@ -88,30 +95,32 @@ static SkSwizzler::ResultAlpha swizzle_index_to_index( |
static SkSwizzler::ResultAlpha swizzle_index_to_n32( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
- int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ int deltaSrc, int y, const SkPMColor ctable[]) { |
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
INIT_RESULT_ALPHA; |
for (int x = 0; x < width; x++) { |
- SkPMColor c = ctable[src[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( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
- int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ int deltaSrc, int y, const SkPMColor ctable[]) { |
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
INIT_RESULT_ALPHA; |
for (int x = 0; x < width; x++) { |
- SkPMColor c = ctable[src[x]]; |
+ SkPMColor c = ctable[*src]; |
UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
if (c != 0) { |
dst[x] = c; |
} |
+ src += deltaSrc; |
} |
return COMPUTE_RESULT_ALPHA; |
} |
@@ -122,19 +131,29 @@ static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( |
static SkSwizzler::ResultAlpha swizzle_gray_to_n32( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
- int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ int deltaSrc, int y, const SkPMColor ctable[]) { |
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
for (int x = 0; x < width; x++) { |
- dst[x] = SkPackARGB32NoCheck(0xFF, src[x], src[x], src[x]); |
+ dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src); |
+ src += deltaSrc; |
} |
return SkSwizzler::kOpaque_ResultAlpha; |
} |
static SkSwizzler::ResultAlpha swizzle_gray_to_gray( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
- int bytesPerPixel, int y, const SkPMColor ctable[]) { |
- memcpy(dstRow, src, width); |
+ int deltaSrc, int y, const SkPMColor ctable[]) { |
+ |
+ uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
+ if (1 == deltaSrc) { |
+ memcpy(dstRow, src, width); |
+ } else { |
+ for (int x = 0; x < width; x++) { |
+ dst[x] = src[0]; |
+ src += deltaSrc; |
+ } |
+ } |
return SkSwizzler::kOpaque_ResultAlpha; |
} |
@@ -142,12 +161,12 @@ static SkSwizzler::ResultAlpha swizzle_gray_to_gray( |
static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
- int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ int deltaSrc, int y, const SkPMColor ctable[]) { |
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
for (int x = 0; x < width; x++) { |
dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
- src += bytesPerPixel; |
+ src += deltaSrc; |
} |
return SkSwizzler::kOpaque_ResultAlpha; |
} |
@@ -156,7 +175,7 @@ static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( |
static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
- int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ int deltaSrc, int y, const SkPMColor ctable[]) { |
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
INIT_RESULT_ALPHA; |
@@ -164,14 +183,14 @@ static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( |
uint8_t alpha = src[3]; |
UPDATE_RESULT_ALPHA(alpha); |
dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); |
- src += bytesPerPixel; |
+ src += deltaSrc; |
} |
return COMPUTE_RESULT_ALPHA; |
} |
static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
- int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ int deltaSrc, int y, const SkPMColor ctable[]) { |
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
INIT_RESULT_ALPHA; |
@@ -179,7 +198,7 @@ static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( |
uint8_t alpha = src[3]; |
UPDATE_RESULT_ALPHA(alpha); |
dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); |
- src += bytesPerPixel; |
+ src += deltaSrc; |
} |
return COMPUTE_RESULT_ALPHA; |
} |
@@ -187,19 +206,19 @@ static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( |
// n32 |
static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
- int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ int deltaSrc, int y, const SkPMColor ctable[]) { |
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
for (int x = 0; x < width; x++) { |
dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); |
- src += bytesPerPixel; |
+ src += deltaSrc; |
} |
return SkSwizzler::kOpaque_ResultAlpha; |
} |
static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
- int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ int deltaSrc, int y, const SkPMColor ctable[]) { |
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
INIT_RESULT_ALPHA; |
@@ -207,14 +226,14 @@ static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( |
unsigned alpha = src[3]; |
UPDATE_RESULT_ALPHA(alpha); |
dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); |
- src += bytesPerPixel; |
+ src += deltaSrc; |
} |
return COMPUTE_RESULT_ALPHA; |
} |
static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
- int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ int deltaSrc, int y, const SkPMColor ctable[]) { |
uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
INIT_RESULT_ALPHA; |
@@ -222,14 +241,14 @@ static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul( |
unsigned alpha = src[3]; |
UPDATE_RESULT_ALPHA(alpha); |
dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); |
- src += bytesPerPixel; |
+ src += deltaSrc; |
} |
return COMPUTE_RESULT_ALPHA; |
} |
static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( |
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
- int bytesPerPixel, int y, const SkPMColor ctable[]) { |
+ int deltaSrc, int y, const SkPMColor ctable[]) { |
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
INIT_RESULT_ALPHA; |
@@ -239,7 +258,7 @@ static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ( |
if (0 != alpha) { |
dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]); |
} |
- src += bytesPerPixel; |
+ src += deltaSrc; |
} |
return COMPUTE_RESULT_ALPHA; |
} |
@@ -275,7 +294,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
const SkPMColor* ctable, |
const SkImageInfo& info, void* dst, |
size_t dstRowBytes, |
- SkCodec::ZeroInitialized zeroInit) { |
+ SkCodec::ZeroInitialized zeroInit, int sampleX) { |
if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) { |
return NULL; |
} |
@@ -408,12 +427,12 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : |
BitsPerPixel(sc); |
return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, info, dst, |
- dstRowBytes)); |
+ dstRowBytes, sampleX)); |
} |
SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, |
int deltaSrc, const SkImageInfo& info, void* dst, |
- size_t rowBytes) |
+ size_t rowBytes, int sampleX) |
: fRowProc(proc) |
, fColorTable(ctable) |
, fDeltaSrc(deltaSrc) |
@@ -421,7 +440,16 @@ SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, |
, fDstRow(dst) |
, fDstRowBytes(rowBytes) |
, fCurrY(0) |
+ , fSampleX(sampleX) |
{ |
+ if (1 == sampleX) { |
+ fX0 = 0; |
+ } else { |
+ // offset first x pixel for more even sampling |
+ fX0 = fSampleX >> 1; |
+ } |
+ // check that fX0 is less than original width |
+ SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); |
SkDEBUGCODE(fNextMode = kUninitialized_NextMode); |
} |
@@ -432,8 +460,8 @@ SkSwizzler::ResultAlpha SkSwizzler::next(const uint8_t* SK_RESTRICT src) { |
SkDEBUGCODE(fNextMode = kConsecutive_NextMode); |
// Decode a row |
- const ResultAlpha result = fRowProc(fDstRow, src, fDstInfo.width(), |
- fDeltaSrc, fCurrY, fColorTable); |
+ const ResultAlpha result = fRowProc(fDstRow, src + fX0 * fDeltaSrc, fDstInfo.width(), |
+ fSampleX * fDeltaSrc, fCurrY, fColorTable); |
// Move to the next row and return the result |
fCurrY++; |
@@ -451,7 +479,7 @@ SkSwizzler::ResultAlpha SkSwizzler::next(const uint8_t* SK_RESTRICT src, |
void* row = SkTAddOffset<void>(fDstRow, y*fDstRowBytes); |
// Decode the row |
- return fRowProc(row, src, fDstInfo.width(), fDeltaSrc, fCurrY, |
+ return fRowProc(row, src + fX0 * fDeltaSrc, fDstInfo.width(), fSampleX * fDeltaSrc, fCurrY, |
fColorTable); |
} |