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

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 wbmp, add tests 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 if (width > 0) { 105 if (width > 0) {
106 U8CPU currByte = src[i]; 106 U8CPU currByte = src[i];
107 for (int j = 0; j < width; j++) { 107 for (int j = 0; j < width; j++) {
108 dst[j] = ((currByte >> 7) & 1) ? SK_ColorWHITE : SK_ColorBLACK; 108 dst[j] = ((currByte >> 7) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
109 currByte <<= 1; 109 currByte <<= 1;
110 } 110 }
111 } 111 }
112 return SkSwizzler::kOpaque_ResultAlpha; 112 return SkSwizzler::kOpaque_ResultAlpha;
113 } 113 }
114 114
115 #define RGB565_BLACK 0
116 #define RGB565_WHITE 0xFFFF
117
118 static SkSwizzler::ResultAlpha swizzle_bit_to_565(
scroggo 2015/08/13 18:09:43 This method is the same as the other swizzle_bit m
119 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
120 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) {
121 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
122
123 // Determine how many full bytes are in the row
124 int bytesInRow = width >> 3;
125 int i;
126 for (i = 0; i < bytesInRow; i++) {
127 U8CPU currByte = src[i];
128 for (int j = 0; j < 8; j++) {
129 dst[j] = ((currByte >> (7 - j)) & 1) ? RGB565_WHITE : RGB565_BLACK;
130 }
131 dst += 8;
132 }
133
134 // Finish the remaining bits
135 width &= 7;
136 if (width > 0) {
137 U8CPU currByte = src[i];
138 for (int j = 0; j < width; j++) {
139 dst[j] = ((currByte >> 7) & 1) ? RGB565_WHITE : RGB565_BLACK;
140 currByte <<= 1;
141 }
142 }
143 return SkSwizzler::kOpaque_ResultAlpha;
144 }
145
146 #undef RGB565_BLACK
147 #undef RGB565_WHITE
148
115 // kIndex1, kIndex2, kIndex4 149 // kIndex1, kIndex2, kIndex4
116 150
117 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( 151 static SkSwizzler::ResultAlpha swizzle_small_index_to_index(
118 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 152 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
119 int bitsPerPixel, const SkPMColor ctable[]) { 153 int bitsPerPixel, const SkPMColor ctable[]) {
120 154
121 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 155 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
122 INIT_RESULT_ALPHA; 156 INIT_RESULT_ALPHA;
123 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 157 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
124 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); 158 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
125 const uint8_t mask = (1 << bitsPerPixel) - 1; 159 const uint8_t mask = (1 << bitsPerPixel) - 1;
126 int x = 0; 160 int x = 0;
127 for (uint32_t byte = 0; byte < rowBytes; byte++) { 161 for (uint32_t byte = 0; byte < rowBytes; byte++) {
128 uint8_t pixelData = src[byte]; 162 uint8_t pixelData = src[byte];
129 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { 163 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) {
130 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; 164 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
131 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); 165 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT);
132 dst[x] = index; 166 dst[x] = index;
133 pixelData <<= bitsPerPixel; 167 pixelData <<= bitsPerPixel;
134 x++; 168 x++;
135 } 169 }
136 } 170 }
137 return COMPUTE_RESULT_ALPHA; 171 return COMPUTE_RESULT_ALPHA;
138 } 172 }
139 173
174 static SkSwizzler::ResultAlpha swizzle_small_index_to_565(
175 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
176 int bitsPerPixel, const SkPMColor ctable[]) {
177
178 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
179 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
180 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
181 const uint8_t mask = (1 << bitsPerPixel) - 1;
182 int x = 0;
183 for (uint32_t byte = 0; byte < rowBytes; byte++) {
184 uint8_t pixelData = src[byte];
185 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) {
186 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask;
187 uint16_t c = SkPixel32ToPixel16(ctable[index]);
188 dst[x] = c;
189 pixelData <<= bitsPerPixel;
190 x++;
191 }
192 }
193 return SkSwizzler::kOpaque_ResultAlpha;
194 }
195
140 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( 196 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32(
141 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 197 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
142 int bitsPerPixel, const SkPMColor ctable[]) { 198 int bitsPerPixel, const SkPMColor ctable[]) {
143 199
144 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; 200 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow;
145 INIT_RESULT_ALPHA; 201 INIT_RESULT_ALPHA;
146 const uint32_t pixelsPerByte = 8 / bitsPerPixel; 202 const uint32_t pixelsPerByte = 8 / bitsPerPixel;
147 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); 203 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte);
148 const uint8_t mask = (1 << bitsPerPixel) - 1; 204 const uint8_t mask = (1 << bitsPerPixel) - 1;
149 int x = 0; 205 int x = 0;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 int bytesPerPixel, const SkPMColor ctable[]) { 320 int bytesPerPixel, const SkPMColor ctable[]) {
265 321
266 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 322 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
267 for (int x = 0; x < width; x++) { 323 for (int x = 0; x < width; x++) {
268 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); 324 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]);
269 src += bytesPerPixel; 325 src += bytesPerPixel;
270 } 326 }
271 return SkSwizzler::kOpaque_ResultAlpha; 327 return SkSwizzler::kOpaque_ResultAlpha;
272 } 328 }
273 329
330 static SkSwizzler::ResultAlpha swizzle_bgrx_to_565(
331 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
332 int bytesPerPixel, const SkPMColor ctable[]) {
333 // FIXME: Support dithering?
334 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
335 for (int x = 0; x < width; x++) {
336 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]);
337 src += bytesPerPixel;
338 }
339 return SkSwizzler::kOpaque_ResultAlpha;
340 }
341
274 // kBGRA 342 // kBGRA
275 343
276 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( 344 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul(
277 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, 345 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width,
278 int bytesPerPixel, const SkPMColor ctable[]) { 346 int bytesPerPixel, const SkPMColor ctable[]) {
279 347
280 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 348 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
281 INIT_RESULT_ALPHA; 349 INIT_RESULT_ALPHA;
282 for (int x = 0; x < width; x++) { 350 for (int x = 0; x < width; x++) {
283 uint8_t alpha = src[3]; 351 uint8_t alpha = src[3];
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 RowProc proc = NULL; 486 RowProc proc = NULL;
419 switch (sc) { 487 switch (sc) {
420 case kBit: 488 case kBit:
421 switch (info.colorType()) { 489 switch (info.colorType()) {
422 case kN32_SkColorType: 490 case kN32_SkColorType:
423 proc = &swizzle_bit_to_n32; 491 proc = &swizzle_bit_to_n32;
424 break; 492 break;
425 case kIndex_8_SkColorType: 493 case kIndex_8_SkColorType:
426 proc = &swizzle_bit_to_index; 494 proc = &swizzle_bit_to_index;
427 break; 495 break;
496 case kRGB_565_SkColorType:
497 proc = &swizzle_bit_to_565;
498 break;
428 case kGray_8_SkColorType: 499 case kGray_8_SkColorType:
429 proc = &swizzle_bit_to_grayscale; 500 proc = &swizzle_bit_to_grayscale;
430 break; 501 break;
431 default: 502 default:
432 break; 503 break;
433 } 504 }
434 break; 505 break;
435 case kIndex1: 506 case kIndex1:
436 case kIndex2: 507 case kIndex2:
437 case kIndex4: 508 case kIndex4:
438 switch (info.colorType()) { 509 switch (info.colorType()) {
439 case kN32_SkColorType: 510 case kN32_SkColorType:
440 proc = &swizzle_small_index_to_n32; 511 proc = &swizzle_small_index_to_n32;
441 break; 512 break;
513 case kRGB_565_SkColorType:
514 proc = &swizzle_small_index_to_565;
515 break;
442 case kIndex_8_SkColorType: 516 case kIndex_8_SkColorType:
443 proc = &swizzle_small_index_to_index; 517 proc = &swizzle_small_index_to_index;
444 break; 518 break;
445 default: 519 default:
446 break; 520 break;
447 } 521 }
448 break; 522 break;
449 case kIndex: 523 case kIndex:
450 switch (info.colorType()) { 524 switch (info.colorType()) {
451 case kN32_SkColorType: 525 case kN32_SkColorType:
(...skipping 30 matching lines...) Expand all
482 default: 556 default:
483 break; 557 break;
484 } 558 }
485 break; 559 break;
486 case kBGR: 560 case kBGR:
487 case kBGRX: 561 case kBGRX:
488 switch (info.colorType()) { 562 switch (info.colorType()) {
489 case kN32_SkColorType: 563 case kN32_SkColorType:
490 proc = &swizzle_bgrx_to_n32; 564 proc = &swizzle_bgrx_to_n32;
491 break; 565 break;
566 case kRGB_565_SkColorType:
567 proc = &swizzle_bgrx_to_565;
568 break;
492 default: 569 default:
493 break; 570 break;
494 } 571 }
495 break; 572 break;
496 case kBGRA: 573 case kBGRA:
497 switch (info.colorType()) { 574 switch (info.colorType()) {
498 case kN32_SkColorType: 575 case kN32_SkColorType:
499 switch (info.alphaType()) { 576 switch (info.alphaType()) {
500 case kUnpremul_SkAlphaType: 577 case kUnpremul_SkAlphaType:
501 proc = &swizzle_bgra_to_n32_unpremul; 578 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 712 // bits of SK_ColorBLACK are identical to the 565 representation
636 // for black. 713 // for black.
637 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); 714 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill);
638 break; 715 break;
639 default: 716 default:
640 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); 717 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
641 SkASSERT(false); 718 SkASSERT(false);
642 break; 719 break;
643 } 720 }
644 } 721 }
OLDNEW
« no previous file with comments | « src/codec/SkMaskSwizzler.cpp ('k') | src/codec/SkWebpCodec.cpp » ('j') | tests/CodexTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698