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 // kBit | |
23 // These routines exclusively choose between white and black | |
24 | |
25 #define GRAYSCALE_BLACK 0 | |
26 #define GRAYSCALE_WHITE 0xFF | |
27 | |
28 static SkSwizzler::ResultAlpha swizzle_bit_to_grayscale( | |
29 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | |
30 int bitsPerPixel, const SkPMColor ctable[]) { | |
scroggo
2015/07/29 17:47:12
I believe these parameters are unused? I think we
msarett
2015/07/29 18:53:57
Done.
| |
31 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | |
32 int bytes = width >> 3; | |
33 for (int i = 0; i < bytes; i++) { | |
34 U8CPU mask = *src++; | |
scroggo
2015/07/29 17:47:12
I don't have an idea for a better name for this, b
msarett
2015/07/29 18:53:57
Yeah you're right. Renaming to currByte.
| |
35 for (int j = 0; j < 8; j++) { | |
36 dst[j] = ((mask >> (7 - j)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK ; | |
37 } | |
38 dst += 8; | |
scroggo
2015/07/29 17:47:12
It seems a little odd that here you index dst and
msarett
2015/07/29 18:53:57
There is no reason for this other than that is how
scroggo
2015/07/29 21:49:16
I do not have a problem with pointer arithmetic in
| |
39 } | |
40 width &= 7; | |
41 if (width > 0) { | |
42 U8CPU mask = *src; | |
43 do { | |
44 *dst++ = ((mask >> 7) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK; | |
45 mask <<= 1; | |
46 } while (--width != 0); | |
47 } | |
48 return SkSwizzler::kOpaque_ResultAlpha; | |
49 } | |
50 | |
51 #undef GRAYSCALE_BLACK | |
52 #undef GRAYSCALE_WHITE | |
53 | |
54 static SkSwizzler::ResultAlpha swizzle_bit_to_index( | |
55 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | |
56 int bitsPerPixel, const SkPMColor ctable[]) { | |
57 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | |
58 int bytes = width >> 3; | |
59 for (int i = 0; i < bytes; i++) { | |
60 U8CPU mask = *src++; | |
61 for (int j = 0; j < 8; j++) { | |
62 dst[j] = (mask >> (7 - j)) & 1; | |
63 } | |
64 dst += 8; | |
65 } | |
66 width &= 7; | |
67 if (width > 0) { | |
68 U8CPU mask = *src; | |
69 do { | |
70 *dst++ = (mask >> 7) & 1; | |
71 mask <<= 1; | |
72 } while (--width != 0); | |
73 } | |
74 return SkSwizzler::kOpaque_ResultAlpha; | |
75 } | |
76 | |
77 static SkSwizzler::ResultAlpha swizzle_bit_to_n32( | |
78 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | |
79 int bitsPerPixel, const SkPMColor ctable[]) { | |
80 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; | |
81 int bytes = width >> 3; | |
82 for (int i = 0; i < bytes; i++) { | |
83 U8CPU mask = *src++; | |
84 for (int j = 0; j < 8; j++) { | |
85 dst[j] = ((mask >> (7 - j)) & 1) ? SK_ColorWHITE : SK_ColorBLACK; | |
86 } | |
87 dst += 8; | |
88 } | |
89 width &= 7; | |
90 if (width > 0) { | |
91 U8CPU mask = *src; | |
92 do { | |
93 *dst++ = ((mask >> 7) & 1) ? SK_ColorWHITE : SK_ColorBLACK; | |
94 mask <<= 1; | |
95 } while (--width != 0); | |
96 } | |
97 return SkSwizzler::kOpaque_ResultAlpha; | |
98 } | |
99 | |
22 // kIndex1, kIndex2, kIndex4 | 100 // kIndex1, kIndex2, kIndex4 |
23 | 101 |
24 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( | 102 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( |
25 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 103 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
26 int bitsPerPixel, const SkPMColor ctable[]) { | 104 int bitsPerPixel, const SkPMColor ctable[]) { |
27 | 105 |
28 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 106 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
29 INIT_RESULT_ALPHA; | 107 INIT_RESULT_ALPHA; |
30 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 108 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
31 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); | 109 const size_t rowBytes = compute_row_bytes_ppb(width, pixelsPerByte); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 SkCodec::ZeroInitialized zeroInit) { | 355 SkCodec::ZeroInitialized zeroInit) { |
278 if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) { | 356 if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) { |
279 return NULL; | 357 return NULL; |
280 } | 358 } |
281 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) | 359 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) |
282 && NULL == ctable) { | 360 && NULL == ctable) { |
283 return NULL; | 361 return NULL; |
284 } | 362 } |
285 RowProc proc = NULL; | 363 RowProc proc = NULL; |
286 switch (sc) { | 364 switch (sc) { |
365 case kBit: | |
366 switch (info.colorType()) { | |
367 case kN32_SkColorType: | |
368 proc = &swizzle_bit_to_n32; | |
369 break; | |
370 case kIndex_8_SkColorType: | |
371 proc = &swizzle_bit_to_index; | |
372 break; | |
373 case kGray_8_SkColorType: | |
374 proc = &swizzle_bit_to_grayscale; | |
375 break; | |
376 default: | |
377 break; | |
378 } | |
379 break; | |
287 case kIndex1: | 380 case kIndex1: |
288 case kIndex2: | 381 case kIndex2: |
289 case kIndex4: | 382 case kIndex4: |
290 switch (info.colorType()) { | 383 switch (info.colorType()) { |
291 case kN32_SkColorType: | 384 case kN32_SkColorType: |
292 proc = &swizzle_small_index_to_n32; | 385 proc = &swizzle_small_index_to_n32; |
293 break; | 386 break; |
294 case kIndex_8_SkColorType: | 387 case kIndex_8_SkColorType: |
295 proc = &swizzle_small_index_to_index; | 388 proc = &swizzle_small_index_to_index; |
296 break; | 389 break; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 // bits of SK_ColorBLACK are identical to the grayscale representati on | 562 // bits of SK_ColorBLACK are identical to the grayscale representati on |
470 // for black. | 563 // for black. |
471 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill); | 564 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill); |
472 break; | 565 break; |
473 default: | 566 default: |
474 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); | 567 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); |
475 SkASSERT(false); | 568 SkASSERT(false); |
476 break; | 569 break; |
477 } | 570 } |
478 } | 571 } |
OLD | NEW |