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

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

Issue 1277213002: Support more swizzles to 565 in SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Support more Created 5 years, 4 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
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"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; 130 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
131 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); 131 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
132 dst[x] = index; 132 dst[x] = index;
133 pixelData <<= bitsPerPixel; 133 pixelData <<= bitsPerPixel;
134 x++; 134 x++;
135 } 135 }
136 } 136 }
137 return COMPUTE_RESULT_ALPHA; 137 return COMPUTE_RESULT_ALPHA;
138 } 138 }
139 139
140 static SkSwizzler::ResultAlpha swizzle_small_index_to_565(
141 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
142 int bitsPerPixel, const SkPMColor ctable[]) {
143
144 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
145 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
146 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
147 const uint8_t mask = (1 << bitsPerPixel) - 1;
148 int x = 0;
149 for (uint32_t byte = 0; byte < rowBytes; byte++) {
150 uint8_t pixelData = src[byte];
151 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) {
152 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
153 uint16_t c = SkPixel32ToPixel16(ctable[index]);
154 dst[x] = c;
155 pixelData <<= bitsPerPixel;
156 x++;
157 }
158 }
159 return SkSwizzler::kOpaque_ResultAlpha;
160 }
161
140 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( 162 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
141 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 163 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
142 int bitsPerPixel, const SkPMColor ctable[]) { 164 int bitsPerPixel, const SkPMColor ctable[]) {
143 165
144 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; 166 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
145 INIT_RESULT_ALPHA; 167 INIT_RESULT_ALPHA;
146 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 168 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
147 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); 169 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
148 const uint8_t mask = (1 << bitsPerPixel) - 1; 170 const uint8_t mask = (1 << bitsPerPixel) - 1;
149 int x = 0; 171 int x = 0;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 int bytesPerPixel, const SkPMColor ctable[]) { 286 int bytesPerPixel, const SkPMColor ctable[]) {
265 287
266 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 288 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
267 for (int x = 0; x < width; x++) { 289 for (int x = 0; x < width; x++) {
268 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); 290 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]);
269 src += bytesPerPixel; 291 src += bytesPerPixel;
270 } 292 }
271 return SkSwizzler::kOpaque_ResultAlpha; 293 return SkSwizzler::kOpaque_ResultAlpha;
272 } 294 }
273 295
296 static SkSwizzler::ResultAlpha swizzle_bgrx_to_565(
297 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
298 int bytesPerPixel, const SkPMColor ctable[]) {
299 // FIXME: Support dithering?
300 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
301 for (int x = 0; x < width; x++) {
302 // FIXME: I believe this is correct - still need to test.
scroggo_chromium 2015/08/10 17:26:16 Oops. Will remove this in a followup
msarett 2015/08/10 17:44:24 Acknowledged.
303 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]);
304 src += bytesPerPixel;
305 }
306 return SkSwizzler::kOpaque_ResultAlpha;
307 }
308
274 // kBGRA 309 // kBGRA
275 310
276 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( 311 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul(
277 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 312 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
278 int bytesPerPixel, const SkPMColor ctable[]) { 313 int bytesPerPixel, const SkPMColor ctable[]) {
279 314
280 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 315 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
281 INIT_RESULT_ALPHA; 316 INIT_RESULT_ALPHA;
282 for (int x = 0; x < width; x++) { 317 for (int x = 0; x < width; x++) {
283 uint8_t alpha = src[3]; 318 uint8_t alpha = src[3];
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 case kGray_8_SkColorType: 463 case kGray_8_SkColorType:
429 proc = &swizzle_bit_to_grayscale; 464 proc = &swizzle_bit_to_grayscale;
430 break; 465 break;
431 default: 466 default:
432 break; 467 break;
433 } 468 }
434 break; 469 break;
435 case kIndex1: 470 case kIndex1:
436 case kIndex2: 471 case kIndex2:
437 case kIndex4: 472 case kIndex4:
438 switch (info.colorType()) { 473 switch (info.colorType()) {
msarett 2015/08/10 17:44:24 I believe you need to add a 565 case to this switc
scroggo 2015/08/10 17:50:45 Yep. I added the proc swizzle_small_index_to_565 b
439 case kN32_SkColorType: 474 case kN32_SkColorType:
440 proc = &swizzle_small_index_to_n32; 475 proc = &swizzle_small_index_to_n32;
441 break; 476 break;
442 case kIndex_8_SkColorType: 477 case kIndex_8_SkColorType:
443 proc = &swizzle_small_index_to_index; 478 proc = &swizzle_small_index_to_index;
444 break; 479 break;
445 default: 480 default:
446 break; 481 break;
447 } 482 }
448 break; 483 break;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 default: 517 default:
483 break; 518 break;
484 } 519 }
485 break; 520 break;
486 case kBGR: 521 case kBGR:
487 case kBGRX: 522 case kBGRX:
488 switch (info.colorType()) { 523 switch (info.colorType()) {
489 case kN32_SkColorType: 524 case kN32_SkColorType:
490 proc = &swizzle_bgrx_to_n32; 525 proc = &swizzle_bgrx_to_n32;
491 break; 526 break;
527 case kRGB_565_SkColorType:
528 proc = &swizzle_bgrx_to_565;
529 break;
492 default: 530 default:
493 break; 531 break;
494 } 532 }
495 break; 533 break;
496 case kBGRA: 534 case kBGRA:
497 switch (info.colorType()) { 535 switch (info.colorType()) {
498 case kN32_SkColorType: 536 case kN32_SkColorType:
499 switch (info.alphaType()) { 537 switch (info.alphaType()) {
500 case kUnpremul_SkAlphaType: 538 case kUnpremul_SkAlphaType:
501 proc = &swizzle_bgra_to_n32_unpremul; 539 proc = &swizzle_bgra_to_n32_unpremul;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 // bits of SK_ColorBLACK are identical to the 565 representation 673 // bits of SK_ColorBLACK are identical to the 565 representation
636 // for black. 674 // for black.
637 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); 675 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill);
638 break; 676 break;
639 default: 677 default:
640 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); 678 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
641 SkASSERT(false); 679 SkASSERT(false);
642 break; 680 break;
643 } 681 }
644 } 682 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698