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 |
112 // n32 | 174 // n32 |
113 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( | 175 static SkSwizzler::ResultAlpha swizzle_rgbx_to_n32( |
114 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 176 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
115 int bytesPerPixel, int y, const SkPMColor ctable[]) { | 177 int bytesPerPixel, int y, const SkPMColor ctable[]) { |
116 | 178 |
117 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 179 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
118 for (int x = 0; x < width; x++) { | 180 for (int x = 0; x < width; x++) { |
119 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); | 181 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); |
120 src += bytesPerPixel; | 182 src += bytesPerPixel; |
121 } | 183 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 275 } |
214 RowProc proc = NULL; | 276 RowProc proc = NULL; |
215 switch (sc) { | 277 switch (sc) { |
216 case kIndex1: | 278 case kIndex1: |
217 case kIndex2: | 279 case kIndex2: |
218 case kIndex4: | 280 case kIndex4: |
219 switch (info.colorType()) { | 281 switch (info.colorType()) { |
220 case kN32_SkColorType: | 282 case kN32_SkColorType: |
221 proc = &swizzle_small_index_to_n32; | 283 proc = &swizzle_small_index_to_n32; |
222 break; | 284 break; |
| 285 case kRGB_565_SkColorType: |
| 286 proc = &swizzle_small_index_to_565; |
| 287 break; |
223 default: | 288 default: |
224 break; | 289 break; |
225 } | 290 } |
226 break; | 291 break; |
227 case kIndex: | 292 case kIndex: |
228 switch (info.colorType()) { | 293 switch (info.colorType()) { |
229 case kN32_SkColorType: | 294 case kN32_SkColorType: |
230 // We assume the color premultiplied ctable (or not) as desi
red. | 295 // We assume the color premultiplied ctable (or not) as desi
red. |
231 if (SkImageGenerator::kYes_ZeroInitialized == zeroInit) { | 296 if (SkImageGenerator::kYes_ZeroInitialized == zeroInit) { |
232 proc = &swizzle_index_to_n32_skipZ; | 297 proc = &swizzle_index_to_n32_skipZ; |
| 298 break; |
233 } else { | 299 } else { |
234 proc = &swizzle_index_to_n32; | 300 proc = &swizzle_index_to_n32; |
| 301 break; |
235 } | 302 } |
236 break; | 303 break; |
| 304 case kRGB_565_SkColorType: |
| 305 proc = &swizzle_index_to_565; |
| 306 break; |
237 default: | 307 default: |
238 break; | 308 break; |
239 } | 309 } |
240 break; | 310 break; |
241 case kBGR: | 311 case kBGR: |
242 case kBGRX: | 312 case kBGRX: |
243 switch (info.colorType()) { | 313 switch (info.colorType()) { |
244 case kN32_SkColorType: | 314 case kN32_SkColorType: |
245 proc = &swizzle_bgrx_to_n32; | 315 proc = &swizzle_bgrx_to_n32; |
246 break; | 316 break; |
| 317 case kRGB_565_SkColorType: |
| 318 proc = &swizzle_bgrx_to_565; |
| 319 break; |
247 default: | 320 default: |
248 break; | 321 break; |
249 } | 322 } |
250 break; | 323 break; |
251 case kBGRA: | 324 case kBGRA: |
252 switch (info.colorType()) { | 325 switch (info.colorType()) { |
253 case kN32_SkColorType: | 326 case kN32_SkColorType: |
254 proc = &swizzle_bgra_to_n32; | 327 switch (info.alphaType()) { |
| 328 case kUnpremul_SkAlphaType: |
| 329 proc = &swizzle_bgra_to_n32_unpremul; |
| 330 break; |
| 331 case kPremul_SkAlphaType: |
| 332 proc = &swizzle_bgra_to_n32_premul; |
| 333 break; |
| 334 default: |
| 335 break; |
| 336 } |
255 break; | 337 break; |
256 default: | 338 default: |
257 break; | 339 break; |
258 } | 340 } |
259 break; | 341 break; |
260 case kRGBX: | 342 case kRGBX: |
261 // TODO: Support other swizzles. | 343 // TODO: Support other swizzles. |
262 switch (info.colorType()) { | 344 switch (info.colorType()) { |
263 case kN32_SkColorType: | 345 case kN32_SkColorType: |
264 proc = &swizzle_rgbx_to_n32; | 346 proc = &swizzle_rgbx_to_n32; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 SkASSERT(kConsecutive_NextMode != fNextMode); | 424 SkASSERT(kConsecutive_NextMode != fNextMode); |
343 SkDEBUGCODE(fNextMode = kDesignateRow_NextMode); | 425 SkDEBUGCODE(fNextMode = kDesignateRow_NextMode); |
344 | 426 |
345 // Choose the row | 427 // Choose the row |
346 void* row = SkTAddOffset<void>(fDstRow, y*fDstRowBytes); | 428 void* row = SkTAddOffset<void>(fDstRow, y*fDstRowBytes); |
347 | 429 |
348 // Decode the row | 430 // Decode the row |
349 return fRowProc(row, src, fDstInfo.width(), fDeltaSrc, fCurrY, | 431 return fRowProc(row, src, fDstInfo.width(), fDeltaSrc, fCurrY, |
350 fColorTable); | 432 fColorTable); |
351 } | 433 } |
OLD | NEW |