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 "SkSwizzler.h" | 10 #include "SkSwizzler.h" |
| 11 #include "SkTemplates.h" | 11 #include "SkTemplates.h" |
| 12 #include "SkUtils.h" | 12 #include "SkUtils.h" |
| 13 | 13 |
| 14 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, | 14 SkSwizzler::ResultAlpha SkSwizzler::GetResult(uint8_t zeroAlpha, |
| 15 uint8_t maxAlpha) { | 15 uint8_t maxAlpha) { |
| 16 // In the transparent case, this returns 0x0000 | 16 // In the transparent case, this returns 0x0000 |
| 17 // In the opaque case, this returns 0xFFFF | 17 // In the opaque case, this returns 0xFFFF |
| 18 // If the row is neither transparent nor opaque, returns something else | 18 // If the row is neither transparent nor opaque, returns something else |
| 19 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; | 19 return (((uint16_t) maxAlpha) << 8) | zeroAlpha; |
| 20 } | 20 } |
| 21 | 21 |
| 22 // kIndex1, kIndex2, kIndex4 | 22 // kIndex1, kIndex2, kIndex4 |
| 23 | 23 |
| 24 #define GRAYSCALE_BLACK 0 | |
|
scroggo
2015/07/28 14:03:34
I'm kind of surprised we do not have these already
msarett
2015/07/28 22:22:07
Me too, but I looked a little harder and I actuall
scroggo
2015/07/29 17:47:12
No, I think what you've done here is perfect!
| |
| 25 #define GRAYSCALE_WHITE 0xFF | |
| 26 | |
| 27 // This routine is currently expected to be used exclusively by wbmp. | |
|
scroggo
2015/07/28 14:03:34
What is wbmp-specific about it? I suppose just tha
msarett
2015/07/28 22:22:07
Agreed.
| |
| 28 static SkSwizzler::ResultAlpha swizzle_small_index_to_gray( | |
| 29 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | |
| 30 int bitsPerPixel, const SkPMColor ctable[]) { | |
| 31 | |
| 32 | |
| 33 | |
| 34 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | |
| 35 INIT_RESULT_ALPHA; | |
| 36 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | |
|
scroggo
2015/07/28 14:03:34
It's too bad we have to have a divide for each row
msarett
2015/07/28 22:22:07
Yeah I wanted wbmp to share with small_index, but
| |
| 37 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); | |
| 38 const uint8_t mask = (1 << bitsPerPixel) - 1; | |
| 39 int x = 0; | |
| 40 for (uint32_t byte = 0; byte < rowBytes; byte++) { | |
| 41 uint8_t pixelData = src[byte]; | |
| 42 for (uint32_t p = 0; p < pixelsPerByte && x < width; p++) { | |
| 43 uint8_t bit = (pixelData >> (8 - bitsPerPixel)) & mask; | |
| 44 dst[x] = bit ? GRAYSCALE_WHITE : GRAYSCALE_BLACK; | |
| 45 pixelData <<= bitsPerPixel; | |
| 46 x++; | |
| 47 } | |
| 48 } | |
| 49 return SkSwizzler::kOpaque_ResultAlpha; | |
| 50 } | |
| 51 | |
| 52 #undef GRAYSCALE_BLACK | |
| 53 #undef GRAYSCALE_WHITE | |
| 54 | |
| 24 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( | 55 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( |
| 25 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 56 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 26 int bitsPerPixel, const SkPMColor ctable[]) { | 57 int bitsPerPixel, const SkPMColor ctable[]) { |
| 27 | 58 |
| 28 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 59 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| 29 INIT_RESULT_ALPHA; | 60 INIT_RESULT_ALPHA; |
| 30 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 61 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
| 31 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); | 62 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); |
| 32 const uint8_t mask = (1 << bitsPerPixel) - 1; | 63 const uint8_t mask = (1 << bitsPerPixel) - 1; |
| 33 int x = 0; | 64 int x = 0; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 case kIndex1: | 318 case kIndex1: |
| 288 case kIndex2: | 319 case kIndex2: |
| 289 case kIndex4: | 320 case kIndex4: |
| 290 switch (info.colorType()) { | 321 switch (info.colorType()) { |
| 291 case kN32_SkColorType: | 322 case kN32_SkColorType: |
| 292 proc = &swizzle_small_index_to_n32; | 323 proc = &swizzle_small_index_to_n32; |
| 293 break; | 324 break; |
| 294 case kIndex_8_SkColorType: | 325 case kIndex_8_SkColorType: |
| 295 proc = &swizzle_small_index_to_index; | 326 proc = &swizzle_small_index_to_index; |
| 296 break; | 327 break; |
| 328 case kGray_8_SkColorType: | |
| 329 proc = &swizzle_small_index_to_gray; | |
| 297 default: | 330 default: |
| 298 break; | 331 break; |
| 299 } | 332 } |
| 300 break; | 333 break; |
| 301 case kIndex: | 334 case kIndex: |
| 302 switch (info.colorType()) { | 335 switch (info.colorType()) { |
| 303 case kN32_SkColorType: | 336 case kN32_SkColorType: |
| 304 // We assume the color premultiplied ctable (or not) as desi red. | 337 // We assume the color premultiplied ctable (or not) as desi red. |
| 305 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 338 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 306 proc = &swizzle_index_to_n32_skipZ; | 339 proc = &swizzle_index_to_n32_skipZ; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 // bits of SK_ColorBLACK are identical to the grayscale representati on | 502 // bits of SK_ColorBLACK are identical to the grayscale representati on |
| 470 // for black. | 503 // for black. |
| 471 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill); | 504 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill); |
| 472 break; | 505 break; |
| 473 default: | 506 default: |
| 474 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); | 507 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); |
| 475 SkASSERT(false); | 508 SkASSERT(false); |
| 476 break; | 509 break; |
| 477 } | 510 } |
| 478 } | 511 } |
| OLD | NEW |