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

Side by Side Diff: src/codec/SkSwizzler.cpp

Issue 1055743003: Swizzler changes Index8 and 565 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
« src/codec/SkCodec_libpng.cpp ('K') | « src/codec/SkMaskSwizzler.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkSwizzler.h" 10 #include "SkSwizzler.h"
11 #include "SkTemplates.h" 11 #include "SkTemplates.h"
12 12
13 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, 13 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha,
14 uint8_t maxAlpha) { 14 uint8_t maxAlpha) {
15 // In the transparent case, this returns 0x0000 15 // In the transparent case, this returns 0x0000
16 // In the opaque case, this returns 0xFFFF 16 // In the opaque case, this returns 0xFFFF
17 // If the row is neither transparent nor opaque, returns something else 17 // If the row is neither transparent nor opaque, returns something else
18 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; 18 return (((uint16_t) maxAlpha) << 8) | zeroAlpha;
19 } 19 }
20 20
21 // kIndex1, kIndex2, kIndex4 21 // kIndex1, kIndex2, kIndex4
22 22
23 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( 23 static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
24 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 24 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
25 int bitsPerPixel, int y, const SkPMColor ctable[]) { 25 int bitsPerPixel, int y, const SkPMColor ctable[]) {
26 26
27 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; 27 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
28 INIT_RESULT_ALPHA; 28 INIT_RESULT_ALPHA;
29 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 29 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
30 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); 30 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
31 const uint8_t mask = (1 << bitsPerPixel) - 1; 31 const uint8_t mask = (1 << bitsPerPixel) - 1;
32 int x = 0; 32 int x = 0;
33 for (uint32_t byte = 0; byte < rowBytes; byte++) { 33 for (uint32_t byte = 0; byte < rowBytes; byte++) {
34 uint8_t pixelData = src[byte]; 34 uint8_t pixelData = src[byte];
35 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { 35 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) {
36 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; 36 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
37 SkPMColor c = ctable[index]; 37 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
38 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 38 dst[x] = index;
39 dst[x] = c;
40 pixelData <<= bitsPerPixel; 39 pixelData <<= bitsPerPixel;
41 x++; 40 x++;
42 } 41 }
43 } 42 }
44 return COMPUTE_RESULT_ALPHA; 43 return COMPUTE_RESULT_ALPHA;
45 } 44 }
46 45
47 static SkSwizzler::ResultAlpha swizzle_small_index_to_565( 46 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
48 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 47 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
49 int bitsPerPixel, int y, const SkPMColor ctable[]) { 48 int bitsPerPixel, int y, const SkPMColor ctable[]) {
50 49
51 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; 50 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
51 INIT_RESULT_ALPHA;
52 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 52 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
53 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); 53 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
54 const uint8_t mask = (1 << bitsPerPixel) - 1; 54 const uint8_t mask = (1 << bitsPerPixel) - 1;
55 int x = 0; 55 int x = 0;
56 for (uint32_t byte = 0; byte < rowBytes; byte++) { 56 for (uint32_t byte = 0; byte < rowBytes; byte++) {
57 uint8_t pixelData = src[byte]; 57 uint8_t pixelData = src[byte];
58 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { 58 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) {
59 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; 59 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
60 uint16_t c = SkPixel32ToPixel16(ctable[index]); 60 SkPMColor c = ctable[index];
61 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
61 dst[x] = c; 62 dst[x] = c;
62 pixelData <<= bitsPerPixel; 63 pixelData <<= bitsPerPixel;
63 x++; 64 x++;
64 } 65 }
65 } 66 }
66 return SkSwizzler::kOpaque_ResultAlpha; 67 return COMPUTE_RESULT_ALPHA;
68 }
69
70 static SkSwizzler::ResultAlpha swizzle_index_to_index(
71 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
72 int bytesPerPixel, int y, const SkPMColor ctable[]) {
73
74 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
75 memcpy(dst, src, width);
76 INIT_RESULT_ALPHA;
77 for (int x = 0; x < width; x++) {
78 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT);
scroggo 2015/04/02 19:20:31 Interestingly, looking at the old SkScaledBitmapSa
msarett 2015/04/03 18:01:32 Hmmm seems like an interesting tradeoff. It does
79 }
80 return COMPUTE_RESULT_ALPHA;
67 } 81 }
68 82
69 // kIndex 83 // kIndex
70 84
71 static SkSwizzler::ResultAlpha swizzle_index_to_n32( 85 static SkSwizzler::ResultAlpha swizzle_index_to_n32(
72 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 86 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
73 int bytesPerPixel, int y, const SkPMColor ctable[]) { 87 int bytesPerPixel, int y, const SkPMColor ctable[]) {
74 88
75 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 89 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
76 INIT_RESULT_ALPHA; 90 INIT_RESULT_ALPHA;
77 for (int x = 0; x < width; x++) { 91 for (int x = 0; x < width; x++) {
78 SkPMColor c = ctable[*src]; 92 SkPMColor c = ctable[src[x]];
79 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 93 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
80 dst[x] = c; 94 dst[x] = c;
81 src++;
82 } 95 }
83 return COMPUTE_RESULT_ALPHA; 96 return COMPUTE_RESULT_ALPHA;
84 } 97 }
85 98
86 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ( 99 static SkSwizzler::ResultAlpha swizzle_index_to_n32_skipZ(
87 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 100 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
88 int bytesPerPixel, int y, const SkPMColor ctable[]) { 101 int bytesPerPixel, int y, const SkPMColor ctable[]) {
89 102
90 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 103 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
91 INIT_RESULT_ALPHA; 104 INIT_RESULT_ALPHA;
92 for (int x = 0; x < width; x++) { 105 for (int x = 0; x < width; x++) {
93 SkPMColor c = ctable[*src]; 106 SkPMColor c = ctable[src[x]];
94 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); 107 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT);
95 if (c != 0) { 108 if (c != 0) {
96 dst[x] = c; 109 dst[x] = c;
97 } 110 }
98 src++;
99 } 111 }
100 return COMPUTE_RESULT_ALPHA; 112 return COMPUTE_RESULT_ALPHA;
101 } 113 }
102 114
103 static SkSwizzler::ResultAlpha swizzle_index_to_565(
104 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
105 int bytesPerPixel, int y, const SkPMColor ctable[]) {
106
107 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
108 for (int x = 0; x < width; x++) {
109 uint16_t c = SkPixel32ToPixel16(ctable[*src]);
110 dst[x] = c;
111 src++;
112 }
113 return SkSwizzler::kOpaque_ResultAlpha;
114 }
115
116 #undef A32_MASK_IN_PLACE 115 #undef A32_MASK_IN_PLACE
117 116
118 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( 117 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32(
119 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 118 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
120 int bytesPerPixel, int y, const SkPMColor ctable[]) { 119 int bytesPerPixel, int y, const SkPMColor ctable[]) {
121 120
122 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 121 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
123 for (int x = 0; x < width; x++) { 122 for (int x = 0; x < width; x++) {
124 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); 123 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]);
125 src += bytesPerPixel; 124 src += bytesPerPixel;
126 } 125 }
127 return SkSwizzler::kOpaque_ResultAlpha; 126 return SkSwizzler::kOpaque_ResultAlpha;
128 } 127 }
129 128
130 static SkSwizzler::ResultAlpha swizzle_bgrx_to_565(
131 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
132 int bytesPerPixel, int y, const SkPMColor ctable[]) {
133
134 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
135 for (int x = 0; x < width; x++) {
136 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]);
137 src += bytesPerPixel;
138 }
139 return SkSwizzler::kOpaque_ResultAlpha;
140 }
141
142 // kBGRA 129 // kBGRA
143 130
144 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( 131 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul(
145 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 132 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
146 int bytesPerPixel, int y, const SkPMColor ctable[]) { 133 int bytesPerPixel, int y, const SkPMColor ctable[]) {
147 134
148 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 135 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
149 INIT_RESULT_ALPHA; 136 INIT_RESULT_ALPHA;
150 for (int x = 0; x < width; x++) { 137 for (int x = 0; x < width; x++) {
151 uint8_t alpha = src[3]; 138 uint8_t alpha = src[3];
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 } 262 }
276 RowProc proc = NULL; 263 RowProc proc = NULL;
277 switch (sc) { 264 switch (sc) {
278 case kIndex1: 265 case kIndex1:
279 case kIndex2: 266 case kIndex2:
280 case kIndex4: 267 case kIndex4:
281 switch (info.colorType()) { 268 switch (info.colorType()) {
282 case kN32_SkColorType: 269 case kN32_SkColorType:
283 proc = &swizzle_small_index_to_n32; 270 proc = &swizzle_small_index_to_n32;
284 break; 271 break;
285 case kRGB_565_SkColorType: 272 case kIndex_8_SkColorType:
286 proc = &swizzle_small_index_to_565; 273 proc = &swizzle_small_index_to_index;
287 break; 274 break;
288 default: 275 default:
289 break; 276 break;
290 } 277 }
291 break; 278 break;
292 case kIndex: 279 case kIndex:
293 switch (info.colorType()) { 280 switch (info.colorType()) {
294 case kN32_SkColorType: 281 case kN32_SkColorType:
295 // We assume the color premultiplied ctable (or not) as desi red. 282 // We assume the color premultiplied ctable (or not) as desi red.
296 if (SkImageGenerator::kYes_ZeroInitialized == zeroInit) { 283 if (SkImageGenerator::kYes_ZeroInitialized == zeroInit) {
297 proc = &swizzle_index_to_n32_skipZ; 284 proc = &swizzle_index_to_n32_skipZ;
298 break; 285 break;
299 } else { 286 } else {
300 proc = &swizzle_index_to_n32; 287 proc = &swizzle_index_to_n32;
301 break; 288 break;
302 } 289 }
303 break; 290 break;
304 case kRGB_565_SkColorType: 291 case kIndex_8_SkColorType:
305 proc = &swizzle_index_to_565; 292 proc = &swizzle_index_to_index;
306 break; 293 break;
307 default: 294 default:
308 break; 295 break;
309 } 296 }
310 break; 297 break;
311 case kBGR: 298 case kBGR:
312 case kBGRX: 299 case kBGRX:
313 switch (info.colorType()) { 300 switch (info.colorType()) {
314 case kN32_SkColorType: 301 case kN32_SkColorType:
315 proc = &swizzle_bgrx_to_n32; 302 proc = &swizzle_bgrx_to_n32;
316 break; 303 break;
317 case kRGB_565_SkColorType:
318 proc = &swizzle_bgrx_to_565;
319 break;
320 default: 304 default:
321 break; 305 break;
322 } 306 }
323 break; 307 break;
324 case kBGRA: 308 case kBGRA:
325 switch (info.colorType()) { 309 switch (info.colorType()) {
326 case kN32_SkColorType: 310 case kN32_SkColorType:
327 switch (info.alphaType()) { 311 switch (info.alphaType()) {
328 case kUnpremul_SkAlphaType: 312 case kUnpremul_SkAlphaType:
329 proc = &swizzle_bgra_to_n32_unpremul; 313 proc = &swizzle_bgra_to_n32_unpremul;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 SkASSERT(kConsecutive_NextMode != fNextMode); 410 SkASSERT(kConsecutive_NextMode != fNextMode);
427 SkDEBUGCODE(fNextMode = kDesignateRow_NextMode); 411 SkDEBUGCODE(fNextMode = kDesignateRow_NextMode);
428 412
429 // Choose the row 413 // Choose the row
430 void* row = SkTAddOffset<void>(fDstRow, y*fDstRowBytes); 414 void* row = SkTAddOffset<void>(fDstRow, y*fDstRowBytes);
431 415
432 // Decode the row 416 // Decode the row
433 return fRowProc(row, src, fDstInfo.width(), fDeltaSrc, fCurrY, 417 return fRowProc(row, src, fDstInfo.width(), fDeltaSrc, fCurrY,
434 fColorTable); 418 fColorTable);
435 } 419 }
OLDNEW
« src/codec/SkCodec_libpng.cpp ('K') | « src/codec/SkMaskSwizzler.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698