Chromium Code Reviews| Index: src/codec/SkSwizzler.cpp |
| diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp |
| index 71cb82a08bc5803fd6f8877044b452a3d1591cd3..e9ceb8bce6dc74145addc42c18e7632e15c7a888 100644 |
| --- a/src/codec/SkSwizzler.cpp |
| +++ b/src/codec/SkSwizzler.cpp |
| @@ -19,6 +19,14 @@ SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, |
| return (((uint16_t) maxAlpha) << 8) | zeroAlpha; |
| } |
| +static SkSwizzler::ResultAlpha sample(void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, |
|
scroggo
2015/07/30 17:53:01
Could you add a description?
emmaleer
2015/07/30 22:27:56
Yes.
Also, we can use the sample function for all
|
| + int width, int deltaSrc, int y, const SkPMColor ctable[]){ |
| + uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
|
scroggo
2015/07/30 17:53:01
Does this do what we want it to? It looks like it
emmaleer
2015/07/30 22:27:56
I think this is working somehow..
When I test it,
scroggo
2015/07/31 13:35:33
That is correct. For the "small index" versions (a
emmaleer
2015/07/31 18:41:56
I've fixed this to work with 565
|
| + for (int x = 0; x < width; x++) { |
| + dst[x] = src[0]; |
| + src += deltaSrc; |
| + } |
|
scroggo
2015/07/30 17:53:01
This method should return a value.
For 565, we do
emmaleer
2015/07/30 22:27:56
Acknowledged.
|
| +} |
| // kIndex1, kIndex2, kIndex4 |
| static SkSwizzler::ResultAlpha swizzle_small_index_to_index( |
| @@ -72,10 +80,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 +103,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 +139,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 +169,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 +183,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 +191,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 +206,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 +214,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 +234,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 +249,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 +266,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 +302,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; |
| } |
| @@ -286,7 +313,9 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| && NULL == ctable) { |
| return NULL; |
| } |
| + |
| RowProc proc = NULL; |
| + |
| switch (sc) { |
| case kIndex1: |
| case kIndex2: |
| @@ -397,6 +426,14 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| break; |
| } |
| break; |
| + case kRGB_565: |
| + switch (info.colorType()) { |
| + case kRGB_565_SkColorType: |
| + proc = &sample; |
| + break; |
| + default: |
| + break; |
| + } |
| default: |
| break; |
| } |
| @@ -408,12 +445,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 +458,11 @@ SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, |
| , fDstRow(dst) |
| , fDstRowBytes(rowBytes) |
| , fCurrY(0) |
| + , fSampleX(sampleX) |
| + , fX0(sampleX == 1 ? 0 : sampleX >> 1) |
| { |
| + // check that fX0 is less than original width |
| + SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); |
| SkDEBUGCODE(fNextMode = kUninitialized_NextMode); |
| } |
| @@ -432,8 +473,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(), |
|
msarett
2015/07/30 13:55:38
nit: extra space before src
emmaleer
2015/07/30 17:50:39
Acknowledged.
|
| + fSampleX * fDeltaSrc, fCurrY, fColorTable); |
| // Move to the next row and return the result |
| fCurrY++; |
| @@ -451,7 +492,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); |
| } |
| @@ -506,6 +547,7 @@ void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR |
| // for black. |
| memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill); |
| break; |
| + |
|
msarett
2015/07/30 13:55:38
nit: extra new line
Also, you might want to try r
emmaleer
2015/07/30 17:50:39
Acknowledged.
scroggo
2015/07/30 17:53:01
Just as a general piece of advice, I find it usefu
|
| default: |
| SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); |
| SkASSERT(false); |