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 26 matching lines...) Expand all Loading... | |
37 SkPMColor c = ctable[index]; | 37 SkPMColor c = ctable[index]; |
38 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 38 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
39 dst[x] = c; | 39 dst[x] = c; |
40 pixelData <<= bitsPerPixel; | 40 pixelData <<= bitsPerPixel; |
41 x++; | 41 x++; |
42 } | 42 } |
43 } | 43 } |
44 return COMPUTE_RESULT_ALPHA; | 44 return COMPUTE_RESULT_ALPHA; |
45 } | 45 } |
46 | 46 |
47 static SkSwizzler::ResultAlpha swizzle_small_index_to_565( | |
48 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | |
49 int bitsPerPixel, int y, const SkPMColor ctable[]) { | |
50 | |
51 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; | |
52 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | |
53 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); | |
54 const uint8_t mask = (1 << bitsPerPixel) - 1; | |
55 int x = 0; | |
56 for (uint32_t byte = 0; byte < rowBytes; byte++) { | |
57 uint8_t pixelData = src[byte]; | |
58 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { | |
59 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; | |
60 uint16_t c = SkPixel32ToPixel16(ctable[index]); | |
61 dst[x] = c; | |
62 pixelData <<= bitsPerPixel; | |
63 x++; | |
64 } | |
65 } | |
66 return SkSwizzler::kOpaque_ResultAlpha; | |
67 } | |
68 | |
47 // kIndex | 69 // kIndex |
48 | 70 |
49 static SkSwizzler::ResultAlpha swizzle_index_to_n32( | 71 static SkSwizzler::ResultAlpha swizzle_index_to_n32( |
50 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 72 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
51 int bytesPerPixel, int y, const SkPMColor ctable[]) { | 73 int bytesPerPixel, int y, const SkPMColor ctable[]) { |
52 | 74 |
53 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 75 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
54 INIT_RESULT_ALPHA; | 76 INIT_RESULT_ALPHA; |
55 for (int x = 0; x < width; x++) { | 77 for (int x = 0; x < width; x++) { |
56 SkPMColor c = ctable[*src]; | 78 SkPMColor c = ctable[*src]; |
(...skipping 14 matching lines...) Expand all Loading... | |
71 SkPMColor c = ctable[*src]; | 93 SkPMColor c = ctable[*src]; |
72 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); | 94 UPDATE_RESULT_ALPHA(c >> SK_A32_SHIFT); |
73 if (c != 0) { | 95 if (c != 0) { |
74 dst[x] = c; | 96 dst[x] = c; |
75 } | 97 } |
76 src++; | 98 src++; |
77 } | 99 } |
78 return COMPUTE_RESULT_ALPHA; | 100 return COMPUTE_RESULT_ALPHA; |
79 } | 101 } |
80 | 102 |
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 | |
81 #undef A32_MASK_IN_PLACE | 116 #undef A32_MASK_IN_PLACE |
82 | 117 |
83 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( | 118 static SkSwizzler::ResultAlpha swizzle_bgrx_to_n32( |
84 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 119 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
85 int bytesPerPixel, int y, const SkPMColor ctable[]) { | 120 int bytesPerPixel, int y, const SkPMColor ctable[]) { |
86 | 121 |
87 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 122 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
88 for (int x = 0; x < width; x++) { | 123 for (int x = 0; x < width; x++) { |
89 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 124 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
90 src += bytesPerPixel; | 125 src += bytesPerPixel; |
91 } | 126 } |
92 return SkSwizzler::kOpaque_ResultAlpha; | 127 return SkSwizzler::kOpaque_ResultAlpha; |
93 } | 128 } |
94 | 129 |
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 | |
95 // kBGRA | 142 // kBGRA |
96 | 143 |
97 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32( | 144 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( |
98 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 145 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
99 int bytesPerPixel, int y, const SkPMColor ctable[]) { | 146 int bytesPerPixel, int y, const SkPMColor ctable[]) { |
100 | 147 |
101 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 148 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
102 INIT_RESULT_ALPHA; | 149 INIT_RESULT_ALPHA; |
103 for (int x = 0; x < width; x++) { | 150 for (int x = 0; x < width; x++) { |
104 uint8_t alpha = src[3]; | 151 uint8_t alpha = src[3]; |
105 UPDATE_RESULT_ALPHA(alpha); | 152 UPDATE_RESULT_ALPHA(alpha); |
106 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); | 153 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); |
107 src += bytesPerPixel; | 154 src += bytesPerPixel; |
108 } | 155 } |
109 return COMPUTE_RESULT_ALPHA; | 156 return COMPUTE_RESULT_ALPHA; |
110 } | 157 } |
111 | 158 |
159 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_premul( | |
160 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | |
161 int bytesPerPixel, int y, const SkPMColor ctable[]) { | |
162 | |
163 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | |
164 INIT_RESULT_ALPHA; | |
165 for (int x = 0; x < width; x++) { | |
166 uint8_t alpha = src[3]; | |
167 UPDATE_RESULT_ALPHA(alpha); | |
168 dst[x] = SkPreMultiplyARGB(alpha, src[2], src[1], src[0]); | |
169 src += bytesPerPixel; | |
170 } | |
171 return COMPUTE_RESULT_ALPHA; | |
172 } | |
173 | |
174 static SkSwizzler::ResultAlpha swizzle_bgra_to_565_premul( | |
175 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | |
176 int bytesPerPixel, int y, const SkPMColor ctable[]) { | |
177 | |
178 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | |
179 INIT_RESULT_ALPHA; | |
180 for (int x = 0; x < width; x++) { | |
181 uint8_t alpha = src[3]; | |
182 UPDATE_RESULT_ALPHA(alpha); | |
183 dst[x] = SkPixel32ToPixel16( | |
184 SkPreMultiplyARGB(alpha, src[2], src[1], src[0])); | |
185 src += bytesPerPixel; | |
186 } | |
187 return COMPUTE_RESULT_ALPHA; | |
188 } | |
189 | |
112 // n32 | 190 // n32 |
113 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( | 191 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( |
114 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 192 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
115 int bytesPerPixel, int y, const SkPMColor ctable[]) { | 193 int bytesPerPixel, int y, const SkPMColor ctable[]) { |
116 | 194 |
117 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 195 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
118 for (int x = 0; x < width; x++) { | 196 for (int x = 0; x < width; x++) { |
119 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); | 197 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); |
120 src += bytesPerPixel; | 198 src += bytesPerPixel; |
121 } | 199 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 } | 290 } |
213 RowProc proc = NULL; | 291 RowProc proc = NULL; |
214 switch (sc) { | 292 switch (sc) { |
215 case kIndex1: | 293 case kIndex1: |
216 case kIndex2: | 294 case kIndex2: |
217 case kIndex4: | 295 case kIndex4: |
218 switch (info.colorType()) { | 296 switch (info.colorType()) { |
219 case kN32_SkColorType: | 297 case kN32_SkColorType: |
220 proc = &swizzle_small_index_to_n32; | 298 proc = &swizzle_small_index_to_n32; |
221 break; | 299 break; |
300 case kRGB_565_SkColorType: | |
301 proc = &swizzle_small_index_to_565; | |
302 break; | |
222 default: | 303 default: |
223 break; | 304 break; |
224 } | 305 } |
225 break; | 306 break; |
226 case kIndex: | 307 case kIndex: |
227 switch (info.colorType()) { | 308 switch (info.colorType()) { |
228 case kN32_SkColorType: | 309 case kN32_SkColorType: |
229 if (skipZeroes) { | 310 if (skipZeroes) { |
230 proc = &swizzle_index_to_n32_skipZ; | 311 proc = &swizzle_index_to_n32_skipZ; |
312 break; | |
231 } else { | 313 } else { |
232 proc = &swizzle_index_to_n32; | 314 proc = &swizzle_index_to_n32; |
315 break; | |
233 } | 316 } |
234 break; | 317 break; |
318 case kRGB_565_SkColorType: | |
319 proc = &swizzle_index_to_565; | |
320 break; | |
235 default: | 321 default: |
236 break; | 322 break; |
237 } | 323 } |
238 break; | 324 break; |
239 case kBGR: | 325 case kBGR: |
240 case kBGRX: | 326 case kBGRX: |
241 switch (info.colorType()) { | 327 switch (info.colorType()) { |
242 case kN32_SkColorType: | 328 case kN32_SkColorType: |
243 proc = &swizzle_bgrx_to_n32; | 329 proc = &swizzle_bgrx_to_n32; |
244 break; | 330 break; |
331 case kRGB_565_SkColorType: | |
332 proc = &swizzle_bgrx_to_565; | |
333 break; | |
245 default: | 334 default: |
246 break; | 335 break; |
247 } | 336 } |
248 break; | 337 break; |
249 case kBGRA: | 338 case kBGRA: |
250 switch (info.colorType()) { | 339 switch (info.colorType()) { |
251 case kN32_SkColorType: | 340 case kN32_SkColorType: |
252 proc = &swizzle_bgra_to_n32; | 341 switch (info.alphaType()) { |
342 case kUnpremul_SkAlphaType: | |
343 proc = &swizzle_bgra_to_n32_unpremul; | |
344 break; | |
345 case kPremul_SkAlphaType: | |
346 proc = &swizzle_bgra_to_n32_premul; | |
347 break; | |
348 default: | |
349 break; | |
350 } | |
351 break; | |
352 case kRGB_565_SkColorType: | |
353 // TODO: I'm guessing swizzles to we should assume premul | |
354 // on swizzles to 565. | |
355 proc = &swizzle_bgra_to_565_premul; | |
msarett
2015/03/16 20:21:53
If the image is not opaque, I always premultiply b
scroggo
2015/03/17 13:27:23
If the image is 565, we should not allow using pre
msarett
2015/03/17 16:54:06
Done. I will disallow in conversion possible and
| |
253 break; | 356 break; |
254 default: | 357 default: |
255 break; | 358 break; |
256 } | 359 } |
257 break; | 360 break; |
258 case kRGBX: | 361 case kRGBX: |
259 // TODO: Support other swizzles. | 362 // TODO: Support other swizzles. |
260 switch (info.colorType()) { | 363 switch (info.colorType()) { |
261 case kN32_SkColorType: | 364 case kN32_SkColorType: |
262 proc = &swizzle_rgbx_to_n32; | 365 proc = &swizzle_rgbx_to_n32; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 SkASSERT(kConsecutive_NextMode != fNextMode); | 443 SkASSERT(kConsecutive_NextMode != fNextMode); |
341 SkDEBUGCODE(fNextMode = kDesignateRow_NextMode); | 444 SkDEBUGCODE(fNextMode = kDesignateRow_NextMode); |
342 | 445 |
343 // Choose the row | 446 // Choose the row |
344 void* row = SkTAddOffset<void>(fDstRow, y*fDstRowBytes); | 447 void* row = SkTAddOffset<void>(fDstRow, y*fDstRowBytes); |
345 | 448 |
346 // Decode the row | 449 // Decode the row |
347 return fRowProc(row, src, fDstInfo.width(), fDeltaSrc, fCurrY, | 450 return fRowProc(row, src, fDstInfo.width(), fDeltaSrc, fCurrY, |
348 fColorTable); | 451 fColorTable); |
349 } | 452 } |
OLD | NEW |