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

Unified Diff: src/codec/SkSwizzler.cpp

Issue 1285173003: Revert of SkScaledCodec class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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 44277614c650a075cdcb298e8fdfba8021ae660e..b2b7f927ac262913d86fcfd6c89af7cf430723cb 100644
--- a/src/codec/SkSwizzler.cpp
+++ b/src/codec/SkSwizzler.cpp
@@ -7,7 +7,6 @@
#include "SkCodecPriv.h"
#include "SkColorPriv.h"
-#include "SkScaledCodec.h"
#include "SkSwizzler.h"
#include "SkTemplates.h"
#include "SkUtils.h"
@@ -20,116 +19,114 @@
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, int offset, const SkPMColor ctable[]){
-
- 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
-
-// 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(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
-
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) {
uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
- // increment src by byte offset and bitIndex by bit offset
- src += offset / 8;
- int bitIndex = offset % 8;
- uint8_t currByte = *src;
-
- dst[0] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK;
-
- for (int x = 1; x < dstWidth; x++) {
- int bitOffset = bitIndex + deltaSrc;
- bitIndex = bitOffset % 8;
- currByte = *(src += bitOffset / 8);
- dst[x] = ((currByte >> (7-bitIndex)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK;
- }
-
+ // 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;
+ }
+ 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;
+ }
+ }
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(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) {
uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
- // increment src by byte offset and bitIndex by bit offset
- src += offset / 8;
- int bitIndex = offset % 8;
- uint8_t currByte = *src;
-
- dst[0] = ((currByte >> (7-bitIndex)) & 1);
-
- for (int x = 1; x < dstWidth; x++) {
- int bitOffset = bitIndex + deltaSrc;
- bitIndex = bitOffset % 8;
- 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]
+ // 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;
+ }
+ 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;
+ }
+ }
+ return SkSwizzler::kOpaque_ResultAlpha;
+}
+
static SkSwizzler::ResultAlpha swizzle_bit_to_n32(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int deltaSrc, int offset, const SkPMColor* /*ctable*/) {
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) {
SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
- // increment src by byte offset and bitIndex by bit offset
- src += offset / 8;
- int bitIndex = offset % 8;
- uint8_t currByte = *src;
-
- dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
-
- for (int x = 1; x < dstWidth; x++) {
- int bitOffset = bitIndex + deltaSrc;
- bitIndex = bitOffset % 8;
- currByte = *(src += bitOffset / 8);
- dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
- }
-
+ // 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;
+ }
+ 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;
+ }
+ }
return SkSwizzler::kOpaque_ResultAlpha;
}
// kIndex1, kIndex2, kIndex4
static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int bitsPerPixel, int offset, const SkPMColor ctable[]) {
-
- src += offset;
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bitsPerPixel, const SkPMColor ctable[]) {
+
uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
INIT_RESULT_ALPHA;
const uint32_t pixelsPerByte = 8 / bitsPerPixel;
- const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte);
+ const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
const uint8_t mask = (1 << bitsPerPixel) - 1;
int x = 0;
for (uint32_t byte = 0; byte < rowBytes; byte++) {
uint8_t pixelData = src[byte];
- for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) {
+ for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) {
uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
dst[x] = index;
@@ -141,19 +138,18 @@
}
static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int bitsPerPixel, int offset, const SkPMColor ctable[]) {
-
- src += offset;
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bitsPerPixel, const SkPMColor ctable[]) {
+
SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
INIT_RESULT_ALPHA;
const uint32_t pixelsPerByte = 8 / bitsPerPixel;
- const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte);
+ const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
const uint8_t mask = (1 << bitsPerPixel) - 1;
int x = 0;
for (uint32_t byte = 0; byte < rowBytes; byte++) {
uint8_t pixelData = src[byte];
- for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) {
+ for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) {
uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
SkPMColor c = ctable[index];
UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
@@ -168,75 +164,58 @@
// kIndex
static SkSwizzler::ResultAlpha swizzle_index_to_index(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int deltaSrc, int offset, const SkPMColor ctable[]) {
-
- src += offset;
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, const SkPMColor ctable[]) {
+
uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
- INIT_RESULT_ALPHA;
+ memcpy(dst, src, width);
// 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) {
- // A non-zero offset is only used when sampling, meaning that deltaSrc will be
- // greater than 1. The below loop relies on the fact that src remains unchanged.
- SkASSERT(0 == offset);
- 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;
- }
+ INIT_RESULT_ALPHA;
+ for (int x = 0; x < width; x++) {
+ UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT);
}
return COMPUTE_RESULT_ALPHA;
}
static SkSwizzler::ResultAlpha swizzle_index_to_n32(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- 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];
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, const SkPMColor ctable[]) {
+
+ SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
+ INIT_RESULT_ALPHA;
+ for (int x = 0; x < width; x++) {
+ SkPMColor c = ctable[src[x]];
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 dstWidth,
- 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];
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, const SkPMColor ctable[]) {
+
+ SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
+ INIT_RESULT_ALPHA;
+ for (int x = 0; x < width; x++) {
+ SkPMColor c = ctable[src[x]];
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 dstWidth,
- int bytesPerPixel, int offset, const SkPMColor ctable[]) {
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, 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++) {
+ for (int x = 0; x < width; x++) {
dst[x] = SkPixel32ToPixel16(ctable[*src]);
src += bytesPerPixel;
}
@@ -249,42 +228,29 @@
// kGray
static SkSwizzler::ResultAlpha swizzle_gray_to_n32(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int deltaSrc, int offset, const SkPMColor ctable[]) {
-
- src += offset;
- SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
- for (int x = 0; x < dstWidth; x++) {
- dst[x] = SkPackARGB32NoCheck(0xFF, *src, *src, *src);
- src += deltaSrc;
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, 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]);
}
return SkSwizzler::kOpaque_ResultAlpha;
}
static SkSwizzler::ResultAlpha swizzle_gray_to_gray(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int deltaSrc, int offset, const SkPMColor ctable[]) {
-
- src += offset;
- uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
- if (1 == deltaSrc) {
- memcpy(dstRow, src, dstWidth);
- } else {
- for (int x = 0; x < dstWidth; x++) {
- dst[x] = src[0];
- src += deltaSrc;
- }
- }
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, const SkPMColor ctable[]) {
+ memcpy(dstRow, src, width);
return SkSwizzler::kOpaque_ResultAlpha;
}
static SkSwizzler::ResultAlpha swizzle_gray_to_565(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int bytesPerPixel, int offset, const SkPMColor ctable[]) {
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, const SkPMColor ctable[]) {
// FIXME: Support dithering?
- src += offset;
uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
- for (int x = 0; x < dstWidth; x++) {
+ for (int x = 0; x < width; x++) {
dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]);
src += bytesPerPixel;
}
@@ -294,14 +260,13 @@
// kBGRX
static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int deltaSrc, int offset, const SkPMColor ctable[]) {
-
- src += offset;
- SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
- for (int x = 0; x < dstWidth; x++) {
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, 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 += deltaSrc;
+ src += bytesPerPixel;
}
return SkSwizzler::kOpaque_ResultAlpha;
}
@@ -309,58 +274,54 @@
// kBGRA
static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- 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++) {
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, const SkPMColor ctable[]) {
+
+ 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 += deltaSrc;
+ src += bytesPerPixel;
}
return COMPUTE_RESULT_ALPHA;
}
static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- 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++) {
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, const SkPMColor ctable[]) {
+
+ 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 += deltaSrc;
+ src += bytesPerPixel;
}
return COMPUTE_RESULT_ALPHA;
}
// kRGBX
static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int deltaSrc, int offset, const SkPMColor ctable[]) {
-
- src += offset;
- SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
- for (int x = 0; x < dstWidth; x++) {
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, 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 += deltaSrc;
+ src += bytesPerPixel;
}
return SkSwizzler::kOpaque_ResultAlpha;
}
static SkSwizzler::ResultAlpha swizzle_rgbx_to_565(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int bytesPerPixel, int offset, const SkPMColor ctable[]) {
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, const SkPMColor ctable[]) {
// FIXME: Support dithering?
- src += offset;
uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
- for (int x = 0; x < dstWidth; x++) {
+ for (int x = 0; x < width; x++) {
dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]);
src += bytesPerPixel;
}
@@ -370,51 +331,48 @@
// kRGBA
static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- 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++) {
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, const SkPMColor ctable[]) {
+
+ 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 += deltaSrc;
+ src += bytesPerPixel;
}
return COMPUTE_RESULT_ALPHA;
}
static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_unpremul(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- int deltaSrc, int offset, const SkPMColor ctable[]) {
-
- src += offset;
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, const SkPMColor ctable[]) {
+
uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
INIT_RESULT_ALPHA;
- for (int x = 0; x < dstWidth; x++) {
+ 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 += deltaSrc;
+ src += bytesPerPixel;
}
return COMPUTE_RESULT_ALPHA;
}
static SkSwizzler::ResultAlpha swizzle_rgba_to_n32_premul_skipZ(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
- 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++) {
+ void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
+ int bytesPerPixel, const SkPMColor ctable[]) {
+
+ SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
+ INIT_RESULT_ALPHA;
+ for (int x = 0; x < width; x++) {
unsigned alpha = src[3];
UPDATE_RESULT_ALPHA(alpha);
if (0 != alpha) {
dst[x] = SkPreMultiplyARGB(alpha, src[0], src[1], src[2]);
}
- src += deltaSrc;
+ src += bytesPerPixel;
}
return COMPUTE_RESULT_ALPHA;
}
@@ -427,12 +385,11 @@
decide whether to switch to unpremul default.
static bool swizzle_rgba_to_n32_unpremul_skipZ(void* SK_RESTRICT dstRow,
const uint8_t* SK_RESTRICT src,
- int dstWidth, int bitsPerPixel, int offset,
+ int width, int bitsPerPixel,
const SkPMColor[]) {
- src += offset;
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
unsigned alphaMask = 0xFF;
- for (int x = 0; x < dstWidth; x++) {
+ for (int x = 0; x < width; x++) {
unsigned alpha = src[3];
// NOTE: We cheat here. The caller requested unpremul and skip zeroes. It's possible
// the color components are not zero, but we skip them anyway, meaning they'll remain
@@ -449,10 +406,9 @@
SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
const SkPMColor* ctable,
- const SkImageInfo& dstInfo,
- SkCodec::ZeroInitialized zeroInit,
- const SkImageInfo& srcInfo) {
- if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) {
+ const SkImageInfo& info,
+ SkCodec::ZeroInitialized zeroInit) {
+ if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) {
return NULL;
}
if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc)
@@ -460,10 +416,9 @@
return NULL;
}
RowProc proc = NULL;
-
switch (sc) {
case kBit:
- switch (dstInfo.colorType()) {
+ switch (info.colorType()) {
case kN32_SkColorType:
proc = &swizzle_bit_to_n32;
break;
@@ -480,7 +435,7 @@
case kIndex1:
case kIndex2:
case kIndex4:
- switch (dstInfo.colorType()) {
+ switch (info.colorType()) {
case kN32_SkColorType:
proc = &swizzle_small_index_to_n32;
break;
@@ -492,7 +447,7 @@
}
break;
case kIndex:
- switch (dstInfo.colorType()) {
+ switch (info.colorType()) {
case kN32_SkColorType:
// We assume the color premultiplied ctable (or not) as desired.
if (SkCodec::kYes_ZeroInitialized == zeroInit) {
@@ -514,7 +469,7 @@
}
break;
case kGray:
- switch (dstInfo.colorType()) {
+ switch (info.colorType()) {
case kN32_SkColorType:
proc = &swizzle_gray_to_n32;
break;
@@ -530,7 +485,7 @@
break;
case kBGR:
case kBGRX:
- switch (dstInfo.colorType()) {
+ switch (info.colorType()) {
case kN32_SkColorType:
proc = &swizzle_bgrx_to_n32;
break;
@@ -539,9 +494,9 @@
}
break;
case kBGRA:
- switch (dstInfo.colorType()) {
- case kN32_SkColorType:
- switch (dstInfo.alphaType()) {
+ switch (info.colorType()) {
+ case kN32_SkColorType:
+ switch (info.alphaType()) {
case kUnpremul_SkAlphaType:
proc = &swizzle_bgra_to_n32_unpremul;
break;
@@ -558,7 +513,7 @@
break;
case kRGBX:
// TODO: Support other swizzles.
- switch (dstInfo.colorType()) {
+ switch (info.colorType()) {
case kN32_SkColorType:
proc = &swizzle_rgbx_to_n32;
break;
@@ -569,9 +524,9 @@
}
break;
case kRGBA:
- switch (dstInfo.colorType()) {
- case kN32_SkColorType:
- if (dstInfo.alphaType() == kUnpremul_SkAlphaType) {
+ switch (info.colorType()) {
+ case kN32_SkColorType:
+ if (info.alphaType() == kUnpremul_SkAlphaType) {
// Respect zeroInit?
proc = &swizzle_rgba_to_n32_unpremul;
} else {
@@ -587,7 +542,7 @@
}
break;
case kRGB:
- switch (dstInfo.colorType()) {
+ switch (info.colorType()) {
case kN32_SkColorType:
proc = &swizzle_rgbx_to_n32;
break;
@@ -595,14 +550,6 @@
break;
}
break;
- case kRGB_565:
- switch (dstInfo.colorType()) {
- case kRGB_565_SkColorType:
- proc = &sample565;
- break;
- default:
- break;
- }
default:
break;
}
@@ -611,31 +558,22 @@
}
// Store deltaSrc in bytes if it is an even multiple, otherwise use bits
- int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel(sc);
-
- // get sampleX based on srcInfo and dstInfo dimensions
- int sampleX;
- SkScaledCodec::ComputeSampleSize(dstInfo, srcInfo, &sampleX, NULL);
-
- return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, dstInfo, sampleX));
+ int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) :
+ BitsPerPixel(sc);
+ return SkNEW_ARGS(SkSwizzler, (proc, ctable, deltaSrc, info));
}
SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable,
- int deltaSrc, const SkImageInfo& info, int sampleX)
+ int deltaSrc, const SkImageInfo& info)
: 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(), fSampleX * fDeltaSrc, fX0 * fDeltaSrc, fColorTable);
+ return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fColorTable);
}
void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstRowBytes,
« 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