OLD | NEW |
---|---|
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" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 SkPMColor c = ctable[index]; | 61 SkPMColor c = ctable[index]; |
62 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 62 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
63 dst[x] = c; | 63 dst[x] = c; |
64 pixelData <<= bitsPerPixel; | 64 pixelData <<= bitsPerPixel; |
65 x++; | 65 x++; |
66 } | 66 } |
67 } | 67 } |
68 return COMPUTE_RESULT_ALPHA; | 68 return COMPUTE_RESULT_ALPHA; |
69 } | 69 } |
70 | 70 |
71 // kIndex | |
72 | |
71 static SkSwizzler::ResultAlpha swizzle_index_to_index( | 73 static SkSwizzler::ResultAlpha swizzle_index_to_index( |
72 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 74 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
73 int bytesPerPixel, int y, const SkPMColor ctable[]) { | 75 int bytesPerPixel, int y, const SkPMColor ctable[]) { |
74 | 76 |
75 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 77 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
76 memcpy(dst, src, width); | 78 memcpy(dst, src, width); |
77 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? | 79 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? |
78 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous | 80 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous |
79 // and probably wrong since gif and bmp (rarely) may have al pha. | 81 // and probably wrong since gif and bmp (rarely) may have al pha. |
80 INIT_RESULT_ALPHA; | 82 INIT_RESULT_ALPHA; |
81 for (int x = 0; x < width; x++) { | 83 for (int x = 0; x < width; x++) { |
82 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); | 84 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); |
83 } | 85 } |
84 return COMPUTE_RESULT_ALPHA; | 86 return COMPUTE_RESULT_ALPHA; |
85 } | 87 } |
86 | 88 |
87 // kIndex | |
88 | |
89 static SkSwizzler::ResultAlpha swizzle_index_to_n32( | 89 static SkSwizzler::ResultAlpha swizzle_index_to_n32( |
90 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 90 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
91 int bytesPerPixel, int y, const SkPMColor ctable[]) { | 91 int bytesPerPixel, int y, const SkPMColor ctable[]) { |
92 | 92 |
93 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 93 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
94 INIT_RESULT_ALPHA; | 94 INIT_RESULT_ALPHA; |
95 for (int x = 0; x < width; x++) { | 95 for (int x = 0; x < width; x++) { |
96 SkPMColor c = ctable[src[x]]; | 96 SkPMColor c = ctable[src[x]]; |
97 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 97 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
98 dst[x] = c; | 98 dst[x] = c; |
(...skipping 12 matching lines...) Expand all Loading... | |
111 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 111 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
112 if (c != 0) { | 112 if (c != 0) { |
113 dst[x] = c; | 113 dst[x] = c; |
114 } | 114 } |
115 } | 115 } |
116 return COMPUTE_RESULT_ALPHA; | 116 return COMPUTE_RESULT_ALPHA; |
117 } | 117 } |
118 | 118 |
119 #undef A32_MASK_IN_PLACE | 119 #undef A32_MASK_IN_PLACE |
120 | 120 |
121 // kGray | |
122 | |
123 static SkSwizzler::ResultAlpha swizzle_gray_to_n32( | |
124 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | |
125 int bytesPerPixel, int y, const SkPMColor ctable[]) { | |
126 | |
127 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | |
128 for (int x = 0; x < width; x++) { | |
129 dst[x] = SkPackARGB32NoCheck(0xFF, src[x], src[x], src[x]); | |
130 } | |
131 return SkSwizzler::kOpaque_ResultAlpha; | |
132 } | |
133 | |
134 static SkSwizzler::ResultAlpha swizzle_gray_to_gray( | |
135 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | |
136 int bytesPerPixel, int y, const SkPMColor ctable[]) { | |
137 memcpy(dstRow, src, width); | |
138 return SkSwizzler::kOpaque_ResultAlpha; | |
139 } | |
140 | |
141 // kBGRX | |
142 | |
121 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( | 143 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( |
122 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 144 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
123 int bytesPerPixel, int y, const SkPMColor ctable[]) { | 145 int bytesPerPixel, int y, const SkPMColor ctable[]) { |
124 | 146 |
125 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 147 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
126 for (int x = 0; x < width; x++) { | 148 for (int x = 0; x < width; x++) { |
127 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 149 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
128 src += bytesPerPixel; | 150 src += bytesPerPixel; |
129 } | 151 } |
130 return SkSwizzler::kOpaque_ResultAlpha; | 152 return SkSwizzler::kOpaque_ResultAlpha; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 break; | 314 break; |
293 } | 315 } |
294 break; | 316 break; |
295 case kIndex_8_SkColorType: | 317 case kIndex_8_SkColorType: |
296 proc = &swizzle_index_to_index; | 318 proc = &swizzle_index_to_index; |
297 break; | 319 break; |
298 default: | 320 default: |
299 break; | 321 break; |
300 } | 322 } |
301 break; | 323 break; |
324 case kGray: | |
325 switch (info.colorType()) { | |
326 case kN32_SkColorType: | |
327 proc = &swizzle_gray_to_n32; | |
328 break; | |
329 case kGray_8_SkColorType: | |
330 proc = &swizzle_gray_to_gray; | |
331 default: | |
332 break; | |
333 } | |
334 break; | |
302 case kBGR: | 335 case kBGR: |
303 case kBGRX: | 336 case kBGRX: |
304 switch (info.colorType()) { | 337 switch (info.colorType()) { |
305 case kN32_SkColorType: | 338 case kN32_SkColorType: |
306 proc = &swizzle_bgrx_to_n32; | 339 proc = &swizzle_bgrx_to_n32; |
307 break; | 340 break; |
308 default: | 341 default: |
309 break; | 342 break; |
310 } | 343 } |
311 break; | 344 break; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 } | 490 } |
458 dstRow = SkTAddOffset<uint32_t>(dstRow, dstRowBytes); | 491 dstRow = SkTAddOffset<uint32_t>(dstRow, dstRowBytes); |
459 } | 492 } |
460 } | 493 } |
461 break; | 494 break; |
462 // On an index destination color type, always assume the input is an ind ex | 495 // On an index destination color type, always assume the input is an ind ex |
463 case kIndex_8_SkColorType: | 496 case kIndex_8_SkColorType: |
464 SkASSERT(colorOrIndex == (uint8_t) colorOrIndex); | 497 SkASSERT(colorOrIndex == (uint8_t) colorOrIndex); |
465 memset(dstStartRow, colorOrIndex, bytesToFill); | 498 memset(dstStartRow, colorOrIndex, bytesToFill); |
466 break; | 499 break; |
500 case kGray_8_SkColorType: | |
501 // Always fill kGray with black | |
502 memset(dstStartRow, 0xFF, bytesToFill); | |
msarett
2015/04/13 20:54:06
I'm not exactly sure what the best decision is her
scroggo
2015/04/14 13:10:33
I am not familiar with kGray, but is 0xFF black? I
msarett
2015/04/14 19:30:36
Wow yes you are right. This is a nice reminder to
| |
503 break; | |
467 default: | 504 default: |
468 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); | 505 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); |
469 SkASSERT(false); | 506 SkASSERT(false); |
470 break; | 507 break; |
471 } | 508 } |
472 } | 509 } |
OLD | NEW |