Chromium Code Reviews| Index: src/codec/SkSwizzler.cpp |
| diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp |
| index b2b7f927ac262913d86fcfd6c89af7cf430723cb..0b7e07f982b80373057323f360548f1915c50735 100644 |
| --- a/src/codec/SkSwizzler.cpp |
| +++ b/src/codec/SkSwizzler.cpp |
| @@ -7,6 +7,7 @@ |
| #include "SkCodecPriv.h" |
| #include "SkColorPriv.h" |
| +#include "SkScaledCodec.h" |
| #include "SkSwizzler.h" |
| #include "SkTemplates.h" |
| #include "SkUtils.h" |
| @@ -19,36 +20,54 @@ SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, |
| 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, |
| + int width, int deltaSrc, const SkPMColor ctable[], int offset){ |
| + |
| + src += offset; |
| + uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; |
| + for (int x = 0; x < width; x++) { |
| + dst[x] = src[1] << 8 | src[0]; |
| + src += deltaSrc; |
| + } |
| + // 565 is always opaque |
| + return SkSwizzler::kOpaque_ResultAlpha; |
| +} |
| + |
| // kBit |
| // These routines exclusively choose between white and black |
| #define GRAYSCALE_BLACK 0 |
| #define GRAYSCALE_WHITE 0xFF |
| + |
| static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
|
scroggo
2015/08/07 19:39:48
Refresh my memory: is width the full width of the
emmaleer
2015/08/11 20:10:35
Width is the scaled dstWidth.
The offset is used
scroggo
2015/08/11 21:33:30
Yes, I think that would make it more clear.
emmaleer
2015/08/12 14:04:33
Acknowledged.
|
| - int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { |
| + int deltaSrc, const SkPMColor* /*ctable*/, int offset) { |
| + |
| uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| - // Determine how many full bytes are in the row |
| - int bytesInRow = width >> 3; |
| - int i; |
| - for (i = 0; i < bytesInRow; i++) { |
| - U8CPU currByte = src[i]; |
| - for (int j = 0; j < 8; j++) { |
| - dst[j] = ((currByte >> (7 - j)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK; |
| + int x = 0; |
| + // increment src by byte offset and currBit by bit offset |
| + src += offset / 8; |
|
scroggo
2015/08/07 19:39:48
We can do this divide much faster with:
offset >>
emmaleer
2015/08/11 20:10:35
Acknowledged.
mtklein
2015/08/12 21:51:11
Woah woah, there's absolutely no way the compiler'
emmaleer
2015/08/12 22:19:20
Okay, I've changed this back to use / and %.
Thank
scroggo
2015/08/13 16:10:45
Maybe we should use SkTDivMod then?
|
| + int currBit = offset % 8; |
|
scroggo
2015/08/07 19:39:48
On the other hand, if you also want to do a mod, I
emmaleer
2015/08/11 20:10:35
I looked at SkTDivMod, and it does a divide /, not
scroggo
2015/08/11 21:33:30
Right, of course! The fact that you are using a po
emmaleer
2015/08/12 14:04:33
Acknowledged.
|
| + |
| + U8CPU currByte = src[0]; |
|
scroggo
2015/08/07 19:39:48
nit: curByte is a value, while currBit is an index
emmaleer
2015/08/11 20:10:35
Acknowledged.
|
| + int sample = deltaSrc; |
| + |
| + while (x < width) { |
| + if (currBit == 8) { |
|
scroggo
2015/08/07 19:39:48
nit: constant should go on the left
emmaleer
2015/08/11 20:10:35
Acknowledged.
|
| + src++; |
| + currByte = src[0]; |
|
scroggo
2015/08/07 19:39:48
nit: This works, but is confusing to read - you've
emmaleer
2015/08/11 20:10:35
I changed this to:
src++
currByte = *src
scroggo
2015/08/11 21:33:30
FWIW, this is the same as:
currByte = ++src;
You
emmaleer
2015/08/12 14:04:33
I don't think it's the same thing.
Since src is a
scroggo
2015/08/12 14:35:22
Oops; yes, I need to dereference the pointer. I'm
|
| + currBit = 0; |
| } |
| - dst += 8; |
| - } |
| - |
| - // Finish the remaining bits |
| - width &= 7; |
| - if (width > 0) { |
| - U8CPU currByte = src[i]; |
| - for (int j = 0; j < width; j++) { |
| - dst[j] = ((currByte >> 7) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK; |
| - currByte <<= 1; |
| + if (deltaSrc == sample) { |
| + dst[x] = ((currByte >> (7-currBit)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK; |
| + sample = 0; |
| + x++; |
| } |
| + sample++; |
| + currBit++; |
| } |
| return SkSwizzler::kOpaque_ResultAlpha; |
| } |
| @@ -58,56 +77,61 @@ static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale( |
| static SkSwizzler::ResultAlpha swizzle_bit_to_index( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| - int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { |
| + int deltaSrc, const SkPMColor* /*ctable*/, int offset) { |
| uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| - // Determine how many full bytes are in the row |
| - int bytesInRow = width >> 3; |
| - int i; |
| - for (i = 0; i < bytesInRow; i++) { |
| - U8CPU currByte = src[i]; |
| - for (int j = 0; j < 8; j++) { |
| - dst[j] = (currByte >> (7 - j)) & 1; |
| + int x = 0; |
| + // increment src by byte offset and currBit by bit offset |
| + src += offset / 8; |
| + int currBit = offset % 8; |
| + |
| + U8CPU currByte = src[0]; |
| + int sample = deltaSrc; |
| + |
| + while (x < width) { |
| + if (currBit == 8) { |
| + src++; |
| + currByte = src[0]; |
| + currBit = 0; |
| } |
| - dst += 8; |
| - } |
| - |
| - // Finish the remaining bits |
| - width &= 7; |
| - if (width > 0) { |
| - U8CPU currByte = src[i]; |
| - for (int j = 0; j < width; j++) { |
| - dst[j] = ((currByte >> 7) & 1); |
| - currByte <<= 1; |
| + if (deltaSrc == sample) { |
| + dst[x] = ((currByte >> (7-currBit)) & 1); |
|
scroggo
2015/08/07 19:39:48
Is this the only line that is different in the thr
emmaleer
2015/08/11 20:10:35
Yes this is the only line that's different
I thoug
scroggo
2015/08/11 21:33:30
Yes, the point is to go fast, and I think it's oka
emmaleer
2015/08/12 14:04:33
Acknowledged.
|
| + sample = 0; |
| + x++; |
| } |
| + sample++; |
| + currBit++; |
| } |
| return SkSwizzler::kOpaque_ResultAlpha; |
| } |
| + |
| static SkSwizzler::ResultAlpha swizzle_bit_to_n32( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| - int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { |
| + int deltaSrc, const SkPMColor* /*ctable*/, int offset) { |
| SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; |
| - // Determine how many full bytes are in the row |
| - int bytesInRow = width >> 3; |
| - int i; |
| - for (i = 0; i < bytesInRow; i++) { |
| - U8CPU currByte = src[i]; |
| - for (int j = 0; j < 8; j++) { |
| - dst[j] = ((currByte >> (7 - j)) & 1) ? SK_ColorWHITE : SK_ColorBLACK; |
| + int x = 0; |
| + // increment src by byte offset and currBit by bit offset |
| + src += offset / 8; |
| + int currBit = offset % 8; |
| + |
| + U8CPU currByte = src[0]; |
| + int sample = deltaSrc; |
| + |
| + while (x < width) { |
| + if (currBit == 8) { |
| + src++; |
| + currByte = src[0]; |
| + currBit = 0; |
| } |
| - dst += 8; |
| - } |
| - |
| - // Finish the remaining bits |
| - width &= 7; |
| - if (width > 0) { |
| - U8CPU currByte = src[i]; |
| - for (int j = 0; j < width; j++) { |
| - dst[j] = ((currByte >> 7) & 1) ? SK_ColorWHITE : SK_ColorBLACK; |
| - currByte <<= 1; |
| + if (deltaSrc == sample) { |
| + dst[x] = ((currByte >> (7 - currBit)) & 1) ? SK_ColorWHITE : SK_ColorBLACK; |
| + sample = 0; |
| + x++; |
| } |
| + sample++; |
| + currBit++; |
| } |
| return SkSwizzler::kOpaque_ResultAlpha; |
| } |
| @@ -116,8 +140,9 @@ static SkSwizzler::ResultAlpha swizzle_bit_to_n32( |
| static SkSwizzler::ResultAlpha swizzle_small_index_to_index( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| - int bitsPerPixel, const SkPMColor ctable[]) { |
| + int bitsPerPixel, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| INIT_RESULT_ALPHA; |
| const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
| @@ -139,8 +164,9 @@ static SkSwizzler::ResultAlpha swizzle_small_index_to_index( |
| static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| - int bitsPerPixel, const SkPMColor ctable[]) { |
| + int bitsPerPixel, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; |
| INIT_RESULT_ALPHA; |
| const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
| @@ -165,10 +191,18 @@ 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, const SkPMColor ctable[]) { |
| + int deltaSrc, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| 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. |
| @@ -181,39 +215,44 @@ 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, const SkPMColor ctable[]) { |
| + int deltaSrc, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| 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, const SkPMColor ctable[]) { |
| + int deltaSrc, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| 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; |
| } |
| static SkSwizzler::ResultAlpha swizzle_index_to_565( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| - int bytesPerPixel, const SkPMColor ctable[]) { |
| + int bytesPerPixel, const SkPMColor ctable[], int offset) { |
| // 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 < width; x++) { |
| dst[x] = SkPixel32ToPixel16(ctable[*src]); |
| @@ -229,26 +268,39 @@ static SkSwizzler::ResultAlpha swizzle_index_to_565( |
| static SkSwizzler::ResultAlpha swizzle_gray_to_n32( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| - int bytesPerPixel, const SkPMColor ctable[]) { |
| + int deltaSrc, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| 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, const SkPMColor ctable[]) { |
| - memcpy(dstRow, src, width); |
| + int deltaSrc, const SkPMColor ctable[], int offset) { |
| + |
| + src += offset; |
| + 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; |
| } |
| static SkSwizzler::ResultAlpha swizzle_gray_to_565( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| - int bytesPerPixel, const SkPMColor ctable[]) { |
| + int bytesPerPixel, const SkPMColor ctable[], int offset) { |
| // FIXME: Support dithering? |
| + src += offset; |
| uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| for (int x = 0; x < width; x++) { |
| dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); |
| @@ -261,12 +313,13 @@ static SkSwizzler::ResultAlpha swizzle_gray_to_565( |
| static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| - int bytesPerPixel, const SkPMColor ctable[]) { |
| + int deltaSrc, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| 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; |
| } |
| @@ -275,30 +328,32 @@ 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, const SkPMColor ctable[]) { |
| + int deltaSrc, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| INIT_RESULT_ALPHA; |
| for (int x = 0; x < width; x++) { |
| 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, const SkPMColor ctable[]) { |
| + int deltaSrc, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| INIT_RESULT_ALPHA; |
| for (int x = 0; x < width; x++) { |
| 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; |
| } |
| @@ -306,20 +361,22 @@ static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( |
| // kRGBX |
| static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| - int bytesPerPixel, const SkPMColor ctable[]) { |
| + int deltaSrc, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| 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_rgbx_to_565( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| - int bytesPerPixel, const SkPMColor ctable[]) { |
| + int bytesPerPixel, const SkPMColor ctable[], int offset) { |
| // FIXME: Support dithering? |
| + src += offset; |
| uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| for (int x = 0; x < width; x++) { |
| dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); |
| @@ -332,38 +389,41 @@ static SkSwizzler::ResultAlpha swizzle_rgbx_to_565( |
| // kRGBA |
| static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| - int bytesPerPixel, const SkPMColor ctable[]) { |
| + int deltaSrc, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| INIT_RESULT_ALPHA; |
| for (int x = 0; x < width; x++) { |
| 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, const SkPMColor ctable[]) { |
| + int deltaSrc, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
| INIT_RESULT_ALPHA; |
| for (int x = 0; x < width; x++) { |
| 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, const SkPMColor ctable[]) { |
| + int deltaSrc, const SkPMColor ctable[], int offset) { |
| + src += offset; |
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| INIT_RESULT_ALPHA; |
| for (int x = 0; x < width; x++) { |
| @@ -372,7 +432,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; |
| } |
| @@ -406,9 +466,10 @@ static bool swizzle_rgba_to_n32_unpremul_skipZ(void* SK_RESTRICT dstRow, |
| SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| const SkPMColor* ctable, |
| - const SkImageInfo& info, |
| - SkCodec::ZeroInitialized zeroInit) { |
| - if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) { |
| + const SkImageInfo& dstInfo, |
| + SkCodec::ZeroInitialized zeroInit, |
| + int srcWidth) { |
| + if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { |
| return NULL; |
| } |
| if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) |
| @@ -416,9 +477,10 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| return NULL; |
| } |
| RowProc proc = NULL; |
| + |
| switch (sc) { |
| case kBit: |
| - switch (info.colorType()) { |
| + switch (dstInfo.colorType()) { |
| case kN32_SkColorType: |
| proc = &swizzle_bit_to_n32; |
| break; |
| @@ -435,7 +497,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| case kIndex1: |
| case kIndex2: |
| case kIndex4: |
| - switch (info.colorType()) { |
| + switch (dstInfo.colorType()) { |
| case kN32_SkColorType: |
| proc = &swizzle_small_index_to_n32; |
| break; |
| @@ -447,7 +509,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| } |
| break; |
| case kIndex: |
| - switch (info.colorType()) { |
| + switch (dstInfo.colorType()) { |
| case kN32_SkColorType: |
| // We assume the color premultiplied ctable (or not) as desired. |
| if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| @@ -469,7 +531,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| } |
| break; |
| case kGray: |
| - switch (info.colorType()) { |
| + switch (dstInfo.colorType()) { |
| case kN32_SkColorType: |
| proc = &swizzle_gray_to_n32; |
| break; |
| @@ -485,7 +547,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| break; |
| case kBGR: |
| case kBGRX: |
| - switch (info.colorType()) { |
| + switch (dstInfo.colorType()) { |
| case kN32_SkColorType: |
| proc = &swizzle_bgrx_to_n32; |
| break; |
| @@ -494,9 +556,9 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| } |
| break; |
| case kBGRA: |
| - switch (info.colorType()) { |
| + switch (dstInfo.colorType()) { |
| case kN32_SkColorType: |
| - switch (info.alphaType()) { |
| + switch (dstInfo.alphaType()) { |
| case kUnpremul_SkAlphaType: |
| proc = &swizzle_bgra_to_n32_unpremul; |
| break; |
| @@ -513,7 +575,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| break; |
| case kRGBX: |
| // TODO: Support other swizzles. |
| - switch (info.colorType()) { |
| + switch (dstInfo.colorType()) { |
| case kN32_SkColorType: |
| proc = &swizzle_rgbx_to_n32; |
| break; |
| @@ -524,9 +586,9 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| } |
| break; |
| case kRGBA: |
| - switch (info.colorType()) { |
| + switch (dstInfo.colorType()) { |
| case kN32_SkColorType: |
| - if (info.alphaType() == kUnpremul_SkAlphaType) { |
| + if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
| // Respect zeroInit? |
| proc = &swizzle_rgba_to_n32_unpremul; |
| } else { |
| @@ -542,7 +604,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| } |
| break; |
| case kRGB: |
| - switch (info.colorType()) { |
| + switch (dstInfo.colorType()) { |
| case kN32_SkColorType: |
| proc = &swizzle_rgbx_to_n32; |
| break; |
| @@ -550,6 +612,14 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| break; |
| } |
| break; |
| + case kRGB_565: |
| + switch (dstInfo.colorType()) { |
| + case kRGB_565_SkColorType: |
| + proc = &sample565; |
| + break; |
| + default: |
| + break; |
| + } |
| default: |
| break; |
| } |
| @@ -558,22 +628,30 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| } |
| // Store deltaSrc in bytes if it is an even multiple, otherwise use bits |
| - int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : |
| - BitsPerPixel(sc); |
| - return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, info)); |
| + int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel(sc); |
| + |
| + int sampleX = SkScaledCodec::GetSampleSize(srcWidth, dstInfo.width()); |
| + |
| + return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, dstInfo, sampleX)); |
| } |
| SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, |
| - int deltaSrc, const SkImageInfo& info) |
| + int deltaSrc, const SkImageInfo& info, int sampleX) |
| : fRowProc(proc) |
| , fColorTable(ctable) |
| , fDeltaSrc(deltaSrc) |
| , fDstInfo(info) |
| -{} |
| + , fSampleX(sampleX) |
| + , fX0(sampleX == 1 ? 0 : sampleX >> 1) |
| +{ |
| + // check that fX0 is less than original width |
| + SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); |
| +} |
| SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
| SkASSERT(NULL != dst && NULL != src); |
| - return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fColorTable); |
| + return fRowProc(dst, src, fDstInfo.width(), fSampleX * fDeltaSrc, |
| + fColorTable, fX0 * fDeltaSrc); |
| } |
| void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstRowBytes, |