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

Unified Diff: src/codec/SkSwizzler.cpp

Issue 1055743003: Swizzler changes Index8 and 565 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Avoid setting a field to a local variable Created 5 years, 9 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
« src/codec/SkSwizzler.h ('K') | « 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 0486cf27f13b693b7435ac1d182a58e1d3eddc6a..f1ff3ba9511a8d9c1c23a1ff0b414f9abf3980c2 100644
--- a/src/codec/SkSwizzler.cpp
+++ b/src/codec/SkSwizzler.cpp
@@ -9,6 +9,7 @@
#include "SkColorPriv.h"
#include "SkSwizzler.h"
#include "SkTemplates.h"
+#include "SkUtils.h"
SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha,
uint8_t maxAlpha) {
@@ -20,11 +21,11 @@ SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha,
// kIndex1, kIndex2, kIndex4
-static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
+static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
int bitsPerPixel, int y, const SkPMColor ctable[]) {
- SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
+ 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(width, pixelsPerByte);
@@ -34,9 +35,8 @@ static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
uint8_t pixelData = src[byte];
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);
- dst[x] = c;
+ UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
+ dst[x] = index;
pixelData <<= bitsPerPixel;
x++;
}
@@ -44,11 +44,12 @@ static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
return COMPUTE_RESULT_ALPHA;
}
-static SkSwizzler::ResultAlpha swizzle_small_index_to_565(
+static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
int bitsPerPixel, int y, const SkPMColor ctable[]) {
- uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
+ SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
+ INIT_RESULT_ALPHA;
const uint32_t pixelsPerByte = 8 / bitsPerPixel;
const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
const uint8_t mask = (1 << bitsPerPixel) - 1;
@@ -57,13 +58,30 @@ static SkSwizzler::ResultAlpha swizzle_small_index_to_565(
uint8_t pixelData = src[byte];
for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) {
uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
- uint16_t c = SkPixel32ToPixel16(ctable[index]);
+ SkPMColor c = ctable[index];
+ UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
dst[x] = c;
pixelData <<= bitsPerPixel;
x++;
}
}
- return SkSwizzler::kOpaque_ResultAlpha;
+ return COMPUTE_RESULT_ALPHA;
+}
+
+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[]) {
+
+ uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
+ 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.
+ INIT_RESULT_ALPHA;
+ for (int x = 0; x < width; x++) {
+ UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT);
+ }
+ return COMPUTE_RESULT_ALPHA;
}
// kIndex
@@ -75,10 +93,9 @@ static SkSwizzler::ResultAlpha swizzle_index_to_n32(
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
INIT_RESULT_ALPHA;
for (int x = 0; x < width; x++) {
- SkPMColor c = ctable[*src];
+ SkPMColor c = ctable[src[x]];
UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
dst[x] = c;
- src++;
}
return COMPUTE_RESULT_ALPHA;
}
@@ -90,29 +107,15 @@ static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ(
SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
INIT_RESULT_ALPHA;
for (int x = 0; x < width; x++) {
- SkPMColor c = ctable[*src];
+ SkPMColor c = ctable[src[x]];
UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
if (c != 0) {
dst[x] = c;
}
- src++;
}
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, int y, const SkPMColor ctable[]) {
-
- uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
- for (int x = 0; x < width; x++) {
- uint16_t c = SkPixel32ToPixel16(ctable[*src]);
- dst[x] = c;
- src++;
- }
- return SkSwizzler::kOpaque_ResultAlpha;
-}
-
#undef A32_MASK_IN_PLACE
static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32(
@@ -127,18 +130,6 @@ static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32(
return SkSwizzler::kOpaque_ResultAlpha;
}
-static SkSwizzler::ResultAlpha swizzle_bgrx_to_565(
- void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
- int bytesPerPixel, int y, const SkPMColor ctable[]) {
-
- uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
- for (int x = 0; x < width; x++) {
- dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]);
- src += bytesPerPixel;
- }
- return SkSwizzler::kOpaque_ResultAlpha;
-}
-
// kBGRA
static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul(
@@ -282,8 +273,8 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
case kN32_SkColorType:
proc = &swizzle_small_index_to_n32;
break;
- case kRGB_565_SkColorType:
- proc = &swizzle_small_index_to_565;
+ case kIndex_8_SkColorType:
+ proc = &swizzle_small_index_to_index;
break;
default:
break;
@@ -301,8 +292,8 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
break;
}
break;
- case kRGB_565_SkColorType:
- proc = &swizzle_index_to_565;
+ case kIndex_8_SkColorType:
+ proc = &swizzle_index_to_index;
break;
default:
break;
@@ -314,9 +305,6 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
case kN32_SkColorType:
proc = &swizzle_bgrx_to_n32;
break;
- case kRGB_565_SkColorType:
- proc = &swizzle_bgrx_to_565;
- break;
default:
break;
}
@@ -433,3 +421,36 @@ SkSwizzler::ResultAlpha SkSwizzler::next(const uint8_t* SK_RESTRICT src,
return fRowProc(row, src, fDstInfo.width(), fDeltaSrc, fCurrY,
fColorTable);
}
+
+void SkSwizzler::Fill(void* dst, const SkImageInfo& dstInfo, size_t dstRowBytes, uint32_t y,
+ uint32_t input, SkPMColor* colorTable) {
+ SkASSERT(dst != NULL);
+
+ // Get dst start row
+ void* dstRow = SkTAddOffset<void*>(dst, y * dstRowBytes);
+
+ // Calculate remaining bytes. This is tricky since the final row may not be padded.
+ size_t totalBytes = dstInfo.getSafeSize(dstRowBytes);
scroggo 2015/04/06 14:55:11 const
msarett 2015/04/06 18:10:56 Done.
+ size_t bytes = totalBytes - y * dstRowBytes;
scroggo 2015/04/06 14:55:11 const. Also, Maybe this is better described as re
msarett 2015/04/06 18:10:55 Agreed
+
+ // Use the proper memset routine to fill the remaining bytes
+ switch(dstInfo.colorType()) {
+ case kN32_SkColorType:
+ // Assume input is an index if we have a color table
+ if (NULL != colorTable) {
msarett 2015/04/03 18:01:32 My original version passed a bool parameter indica
scroggo 2015/04/06 14:55:11 It is a little bit confusing, although I think tha
msarett 2015/04/06 18:10:55 Added the comment. I don't think there isn't a gr
+ sk_memset32((uint32_t*) dstRow, colorTable[(uint8_t) input],
scroggo 2015/04/06 14:55:11 Is this cast just in case? I think it might be int
msarett 2015/04/06 18:10:55 Done.
+ bytes / sizeof(SkPMColor));
scroggo 2015/04/06 14:55:11 This seems potentially dangerous. In general, I wo
msarett 2015/04/06 18:10:55 Done
+ // Otherwise, assume the input is a color
+ } else {
+ sk_memset32((uint32_t*) dstRow, input, bytes / sizeof(SkPMColor));
+ }
+ break;
+ // On an index destination color type, always assume the input is an index
+ case kIndex_8_SkColorType:
+ memset(dstRow, (uint8_t) input, bytes);
+ break;
+ default:
+ SkCodecPrintf("Warning: Unsupported dst color type for fill(). Doing nothing.\n");
scroggo 2015/04/06 14:55:12 Maybe SkASSERT(false);
msarett 2015/04/06 18:10:55 Done.
+ break;
+ }
+}
« src/codec/SkSwizzler.h ('K') | « src/codec/SkSwizzler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698