| Index: src/codec/SkSwizzler.cpp
|
| diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp
|
| index 998fbeb851f6bb99c36190419ad59730311da1a7..677ac6085b2443b291f9ce8e56cd335560e93e24 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,6 +20,17 @@ 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[]){
|
| + 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 0xFFFF;
|
| +}
|
| // kIndex1, kIndex2, kIndex4
|
|
|
| static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
|
| @@ -72,10 +84,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, const SkPMColor ctable[]) {
|
| + int deltaSrc, 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 +107,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, const SkPMColor ctable[]) {
|
| + int deltaSrc, 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, const SkPMColor ctable[]) {
|
| + int deltaSrc, 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 +143,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, const SkPMColor ctable[]) {
|
| + int deltaSrc, 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, const SkPMColor ctable[]) {
|
| - memcpy(dstRow, src, width);
|
| + int deltaSrc, 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 +173,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, const SkPMColor ctable[]) {
|
| + int deltaSrc, 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 +187,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, const SkPMColor ctable[]) {
|
| + int deltaSrc, const SkPMColor ctable[]) {
|
|
|
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
|
| INIT_RESULT_ALPHA;
|
| @@ -164,14 +195,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, const SkPMColor ctable[]) {
|
| + int deltaSrc, const SkPMColor ctable[]) {
|
|
|
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
|
| INIT_RESULT_ALPHA;
|
| @@ -179,7 +210,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 +218,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, const SkPMColor ctable[]) {
|
| + int deltaSrc, 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, const SkPMColor ctable[]) {
|
| + int deltaSrc, const SkPMColor ctable[]) {
|
|
|
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
|
| INIT_RESULT_ALPHA;
|
| @@ -207,14 +238,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, const SkPMColor ctable[]) {
|
| + int deltaSrc, const SkPMColor ctable[]) {
|
|
|
| uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
|
| INIT_RESULT_ALPHA;
|
| @@ -222,14 +253,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, const SkPMColor ctable[]) {
|
| + int deltaSrc, const SkPMColor ctable[]) {
|
|
|
| SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
|
| INIT_RESULT_ALPHA;
|
| @@ -239,7 +270,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;
|
| }
|
| @@ -273,9 +304,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)
|
| @@ -283,11 +315,12 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
|
| return NULL;
|
| }
|
| RowProc proc = NULL;
|
| +
|
| switch (sc) {
|
| case kIndex1:
|
| case kIndex2:
|
| case kIndex4:
|
| - switch (info.colorType()) {
|
| + switch (dstInfo.colorType()) {
|
| case kN32_SkColorType:
|
| proc = &swizzle_small_index_to_n32;
|
| break;
|
| @@ -299,7 +332,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) {
|
| @@ -318,7 +351,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;
|
| @@ -330,7 +363,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;
|
| @@ -339,9 +372,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;
|
| @@ -358,7 +391,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;
|
| @@ -367,9 +400,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 {
|
| @@ -385,7 +418,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;
|
| @@ -393,6 +426,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;
|
| }
|
| @@ -401,22 +442,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 + fX0 * fDeltaSrc, fDstInfo.width(), fSampleX * fDeltaSrc,
|
| + fColorTable);
|
| }
|
|
|
| void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstRowBytes,
|
|
|