Chromium Code Reviews| 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 "SkScaledCodec.h" | 10 #include "SkScaledCodec.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 for (int x = 1; x < dstWidth; x++) { | 107 for (int x = 1; x < dstWidth; x++) { |
| 108 int bitOffset = bitIndex + deltaSrc; | 108 int bitOffset = bitIndex + deltaSrc; |
| 109 bitIndex = bitOffset % 8; | 109 bitIndex = bitOffset % 8; |
| 110 currByte = *(src += bitOffset / 8); | 110 currByte = *(src += bitOffset / 8); |
| 111 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBL ACK; | 111 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? SK_ColorWHITE : SK_ColorBL ACK; |
| 112 } | 112 } |
| 113 | 113 |
| 114 return SkSwizzler::kOpaque_ResultAlpha; | 114 return SkSwizzler::kOpaque_ResultAlpha; |
| 115 } | 115 } |
| 116 | 116 |
| 117 #define RGB565_BLACK 0 | |
| 118 #define RGB565_WHITE 0xFFFF | |
| 119 | |
| 120 static SkSwizzler::ResultAlpha swizzle_bit_to_565( | |
| 121 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | |
| 122 int deltaSrc, int offset, const SkPMColor* /*ctable*/) { | |
| 123 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; | |
| 124 | |
| 125 // increment src by byte offset and bitIndex by bit offset | |
| 126 src += offset / 8; | |
| 127 int bitIndex = offset % 8; | |
| 128 uint8_t currByte = *src; | |
| 129 | |
| 130 dst[0] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLACK; | |
|
scroggo_chromium
2015/08/14 15:17:23
I think this function looks just like swizzle_bit_
msarett
2015/08/14 15:21:06
Looks good.
| |
| 131 | |
| 132 for (int x = 1; x < dstWidth; x++) { | |
| 133 int bitOffset = bitIndex + deltaSrc; | |
| 134 bitIndex = bitOffset % 8; | |
| 135 currByte = *(src += bitOffset / 8); | |
| 136 dst[x] = ((currByte >> (7 - bitIndex)) & 1) ? RGB565_WHITE : RGB565_BLAC K; | |
| 137 } | |
| 138 | |
| 139 return SkSwizzler::kOpaque_ResultAlpha; | |
| 140 } | |
| 141 | |
| 142 #undef RGB565_BLACK | |
| 143 #undef RGB565_WHITE | |
| 144 | |
| 117 // kIndex1, kIndex2, kIndex4 | 145 // kIndex1, kIndex2, kIndex4 |
| 118 | 146 |
| 119 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( | 147 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( |
| 120 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 148 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 121 int bitsPerPixel, int offset, const SkPMColor ctable[]) { | 149 int bitsPerPixel, int offset, const SkPMColor ctable[]) { |
| 122 | 150 |
| 123 src += offset; | 151 src += offset; |
| 124 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 152 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| 125 INIT_RESULT_ALPHA; | 153 INIT_RESULT_ALPHA; |
| 126 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 154 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
| 127 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); | 155 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); |
| 128 const uint8_t mask = (1 << bitsPerPixel) - 1; | 156 const uint8_t mask = (1 << bitsPerPixel) - 1; |
| 129 int x = 0; | 157 int x = 0; |
| 130 for (uint32_t byte = 0; byte < rowBytes; byte++) { | 158 for (uint32_t byte = 0; byte < rowBytes; byte++) { |
| 131 uint8_t pixelData = src[byte]; | 159 uint8_t pixelData = src[byte]; |
| 132 for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) { | 160 for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) { |
| 133 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; | 161 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; |
| 134 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); | 162 UPDATE_RESULT_ALPHA(ctable[index] >> SK_A32_SHIFT); |
| 135 dst[x] = index; | 163 dst[x] = index; |
| 136 pixelData <<= bitsPerPixel; | 164 pixelData <<= bitsPerPixel; |
| 137 x++; | 165 x++; |
| 138 } | 166 } |
| 139 } | 167 } |
| 140 return COMPUTE_RESULT_ALPHA; | 168 return COMPUTE_RESULT_ALPHA; |
| 141 } | 169 } |
| 142 | 170 |
| 171 static SkSwizzler::ResultAlpha swizzle_small_index_to_565( | |
| 172 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | |
| 173 int bitsPerPixel, int offset, const SkPMColor ctable[]) { | |
| 174 | |
| 175 src += offset; | |
| 176 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; | |
| 177 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | |
| 178 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); | |
| 179 const uint8_t mask = (1 << bitsPerPixel) - 1; | |
| 180 int x = 0; | |
| 181 for (uint32_t byte = 0; byte < rowBytes; byte++) { | |
| 182 uint8_t pixelData = src[byte]; | |
| 183 for (uint32_t p = 0; p < pixelsPerByte && x < dstWidth; p++) { | |
| 184 uint8_t index = (pixelData >> (8 - bitsPerPixel)) & mask; | |
| 185 uint16_t c = SkPixel32ToPixel16(ctable[index]); | |
| 186 dst[x] = c; | |
| 187 pixelData <<= bitsPerPixel; | |
| 188 x++; | |
| 189 } | |
| 190 } | |
| 191 return SkSwizzler::kOpaque_ResultAlpha; | |
| 192 } | |
| 193 | |
| 143 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( | 194 static SkSwizzler::ResultAlpha swizzle_small_index_to_n32( |
| 144 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 195 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 145 int bitsPerPixel, int offset, const SkPMColor ctable[]) { | 196 int bitsPerPixel, int offset, const SkPMColor ctable[]) { |
| 146 | 197 |
| 147 src += offset; | 198 src += offset; |
| 148 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; | 199 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; |
| 149 INIT_RESULT_ALPHA; | 200 INIT_RESULT_ALPHA; |
| 150 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 201 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
| 151 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); | 202 const size_t rowBytes = compute_row_bytes_ppb(dstWidth, pixelsPerByte); |
| 152 const uint8_t mask = (1 << bitsPerPixel) - 1; | 203 const uint8_t mask = (1 << bitsPerPixel) - 1; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 | 350 |
| 300 src += offset; | 351 src += offset; |
| 301 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 352 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 302 for (int x = 0; x < dstWidth; x++) { | 353 for (int x = 0; x < dstWidth; x++) { |
| 303 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 354 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
| 304 src += deltaSrc; | 355 src += deltaSrc; |
| 305 } | 356 } |
| 306 return SkSwizzler::kOpaque_ResultAlpha; | 357 return SkSwizzler::kOpaque_ResultAlpha; |
| 307 } | 358 } |
| 308 | 359 |
| 360 static SkSwizzler::ResultAlpha swizzle_bgrx_to_565( | |
| 361 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | |
| 362 int deltaSrc, int offset, const SkPMColor ctable[]) { | |
| 363 // FIXME: Support dithering? | |
| 364 src += offset; | |
| 365 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | |
| 366 for (int x = 0; x < dstWidth; x++) { | |
| 367 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); | |
| 368 src += deltaSrc; | |
| 369 } | |
| 370 return SkSwizzler::kOpaque_ResultAlpha; | |
| 371 } | |
| 372 | |
| 309 // kBGRA | 373 // kBGRA |
| 310 | 374 |
| 311 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( | 375 static SkSwizzler::ResultAlpha swizzle_bgra_to_n32_unpremul( |
| 312 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 376 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 313 int deltaSrc, int offset, const SkPMColor ctable[]) { | 377 int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 314 | 378 |
| 315 src += offset; | 379 src += offset; |
| 316 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 380 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 317 INIT_RESULT_ALPHA; | 381 INIT_RESULT_ALPHA; |
| 318 for (int x = 0; x < dstWidth; x++) { | 382 for (int x = 0; x < dstWidth; x++) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 | 527 |
| 464 switch (sc) { | 528 switch (sc) { |
| 465 case kBit: | 529 case kBit: |
| 466 switch (dstInfo.colorType()) { | 530 switch (dstInfo.colorType()) { |
| 467 case kN32_SkColorType: | 531 case kN32_SkColorType: |
| 468 proc = &swizzle_bit_to_n32; | 532 proc = &swizzle_bit_to_n32; |
| 469 break; | 533 break; |
| 470 case kIndex_8_SkColorType: | 534 case kIndex_8_SkColorType: |
| 471 proc = &swizzle_bit_to_index; | 535 proc = &swizzle_bit_to_index; |
| 472 break; | 536 break; |
| 537 case kRGB_565_SkColorType: | |
| 538 proc = &swizzle_bit_to_565; | |
| 539 break; | |
| 473 case kGray_8_SkColorType: | 540 case kGray_8_SkColorType: |
| 474 proc = &swizzle_bit_to_grayscale; | 541 proc = &swizzle_bit_to_grayscale; |
| 475 break; | 542 break; |
| 476 default: | 543 default: |
| 477 break; | 544 break; |
| 478 } | 545 } |
| 479 break; | 546 break; |
| 480 case kIndex1: | 547 case kIndex1: |
| 481 case kIndex2: | 548 case kIndex2: |
| 482 case kIndex4: | 549 case kIndex4: |
| 483 switch (dstInfo.colorType()) { | 550 switch (dstInfo.colorType()) { |
| 484 case kN32_SkColorType: | 551 case kN32_SkColorType: |
| 485 proc = &swizzle_small_index_to_n32; | 552 proc = &swizzle_small_index_to_n32; |
| 486 break; | 553 break; |
| 554 case kRGB_565_SkColorType: | |
| 555 proc = &swizzle_small_index_to_565; | |
| 556 break; | |
| 487 case kIndex_8_SkColorType: | 557 case kIndex_8_SkColorType: |
| 488 proc = &swizzle_small_index_to_index; | 558 proc = &swizzle_small_index_to_index; |
| 489 break; | 559 break; |
| 490 default: | 560 default: |
| 491 break; | 561 break; |
| 492 } | 562 } |
| 493 break; | 563 break; |
| 494 case kIndex: | 564 case kIndex: |
| 495 switch (dstInfo.colorType()) { | 565 switch (dstInfo.colorType()) { |
| 496 case kN32_SkColorType: | 566 case kN32_SkColorType: |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 527 default: | 597 default: |
| 528 break; | 598 break; |
| 529 } | 599 } |
| 530 break; | 600 break; |
| 531 case kBGR: | 601 case kBGR: |
| 532 case kBGRX: | 602 case kBGRX: |
| 533 switch (dstInfo.colorType()) { | 603 switch (dstInfo.colorType()) { |
| 534 case kN32_SkColorType: | 604 case kN32_SkColorType: |
| 535 proc = &swizzle_bgrx_to_n32; | 605 proc = &swizzle_bgrx_to_n32; |
| 536 break; | 606 break; |
| 607 case kRGB_565_SkColorType: | |
| 608 proc = &swizzle_bgrx_to_565; | |
| 609 break; | |
| 537 default: | 610 default: |
| 538 break; | 611 break; |
| 539 } | 612 } |
| 540 break; | 613 break; |
| 541 case kBGRA: | 614 case kBGRA: |
| 542 switch (dstInfo.colorType()) { | 615 switch (dstInfo.colorType()) { |
| 543 case kN32_SkColorType: | 616 case kN32_SkColorType: |
| 544 switch (dstInfo.alphaType()) { | 617 switch (dstInfo.alphaType()) { |
| 545 case kUnpremul_SkAlphaType: | 618 case kUnpremul_SkAlphaType: |
| 546 proc = &swizzle_bgra_to_n32_unpremul; | 619 proc = &swizzle_bgra_to_n32_unpremul; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 697 // bits of SK_ColorBLACK are identical to the 565 representation | 770 // bits of SK_ColorBLACK are identical to the 565 representation |
| 698 // for black. | 771 // for black. |
| 699 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); | 772 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); |
| 700 break; | 773 break; |
| 701 default: | 774 default: |
| 702 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); | 775 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); |
| 703 SkASSERT(false); | 776 SkASSERT(false); |
| 704 break; | 777 break; |
| 705 } | 778 } |
| 706 } | 779 } |
| OLD | NEW |