OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The Android Open Source Project | 2 * Copyright 2015 The Android Open Source Project |
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 #ifndef SkCodecPriv_DEFINED | 8 #ifndef SkCodecPriv_DEFINED |
9 #define SkCodecPriv_DEFINED | 9 #define SkCodecPriv_DEFINED |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 uint8_t zeroAlpha = 0; \ | 23 uint8_t zeroAlpha = 0; \ |
24 uint8_t maxAlpha = 0xFF; | 24 uint8_t maxAlpha = 0xFF; |
25 | 25 |
26 #define UPDATE_RESULT_ALPHA(alpha) \ | 26 #define UPDATE_RESULT_ALPHA(alpha) \ |
27 zeroAlpha |= (alpha); \ | 27 zeroAlpha |= (alpha); \ |
28 maxAlpha &= (alpha); | 28 maxAlpha &= (alpha); |
29 | 29 |
30 #define COMPUTE_RESULT_ALPHA \ | 30 #define COMPUTE_RESULT_ALPHA \ |
31 SkSwizzler::GetResult(zeroAlpha, maxAlpha); | 31 SkSwizzler::GetResult(zeroAlpha, maxAlpha); |
32 | 32 |
| 33 static inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) { |
| 34 // Check for supported alpha types |
| 35 if (srcAlpha != dstAlpha) { |
| 36 if (kOpaque_SkAlphaType == srcAlpha) { |
| 37 // If the source is opaque, we must decode to opaque |
| 38 return false; |
| 39 } |
| 40 |
| 41 // The source is not opaque |
| 42 switch (dstAlpha) { |
| 43 case kPremul_SkAlphaType: |
| 44 case kUnpremul_SkAlphaType: |
| 45 // The source is not opaque, so either of these is okay |
| 46 break; |
| 47 default: |
| 48 // We cannot decode a non-opaque image to opaque (or unknown) |
| 49 return false; |
| 50 } |
| 51 } |
| 52 return true; |
| 53 } |
| 54 |
33 /* | 55 /* |
34 * | |
35 * Copy the codec color table back to the client when kIndex8 color type is requ
ested | 56 * Copy the codec color table back to the client when kIndex8 color type is requ
ested |
36 * | |
37 */ | 57 */ |
38 static inline void copy_color_table(const SkImageInfo& dstInfo, SkColorTable* co
lorTable, | 58 static inline void copy_color_table(const SkImageInfo& dstInfo, SkColorTable* co
lorTable, |
39 SkPMColor* inputColorPtr, int* inputColorCount) { | 59 SkPMColor* inputColorPtr, int* inputColorCount) { |
40 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 60 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
41 SkASSERT(NULL != inputColorPtr); | 61 SkASSERT(NULL != inputColorPtr); |
42 SkASSERT(NULL != inputColorCount); | 62 SkASSERT(NULL != inputColorCount); |
43 SkASSERT(NULL != colorTable); | 63 SkASSERT(NULL != colorTable); |
44 memcpy(inputColorPtr, colorTable->readColors(), *inputColorCount * 4); | 64 memcpy(inputColorPtr, colorTable->readColors(), *inputColorCount * 4); |
45 } | 65 } |
46 } | 66 } |
47 | 67 |
48 /* | 68 /* |
49 * | |
50 * Compute row bytes for an image using pixels per byte | 69 * Compute row bytes for an image using pixels per byte |
51 * | |
52 */ | 70 */ |
53 static inline size_t compute_row_bytes_ppb(int width, uint32_t pixelsPerByte) { | 71 static inline size_t compute_row_bytes_ppb(int width, uint32_t pixelsPerByte) { |
54 return (width + pixelsPerByte - 1) / pixelsPerByte; | 72 return (width + pixelsPerByte - 1) / pixelsPerByte; |
55 } | 73 } |
56 | 74 |
57 /* | 75 /* |
58 * | |
59 * Compute row bytes for an image using bytes per pixel | 76 * Compute row bytes for an image using bytes per pixel |
60 * | |
61 */ | 77 */ |
62 static inline size_t compute_row_bytes_bpp(int width, uint32_t bytesPerPixel) { | 78 static inline size_t compute_row_bytes_bpp(int width, uint32_t bytesPerPixel) { |
63 return width * bytesPerPixel; | 79 return width * bytesPerPixel; |
64 } | 80 } |
65 | 81 |
66 /* | 82 /* |
67 * | |
68 * Compute row bytes for an image | 83 * Compute row bytes for an image |
69 * | |
70 */ | 84 */ |
71 static inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) { | 85 static inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) { |
72 if (bitsPerPixel < 16) { | 86 if (bitsPerPixel < 16) { |
73 SkASSERT(0 == 8 % bitsPerPixel); | 87 SkASSERT(0 == 8 % bitsPerPixel); |
74 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 88 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
75 return compute_row_bytes_ppb(width, pixelsPerByte); | 89 return compute_row_bytes_ppb(width, pixelsPerByte); |
76 } else { | 90 } else { |
77 SkASSERT(0 == bitsPerPixel % 8); | 91 SkASSERT(0 == bitsPerPixel % 8); |
78 const uint32_t bytesPerPixel = bitsPerPixel / 8; | 92 const uint32_t bytesPerPixel = bitsPerPixel / 8; |
79 return compute_row_bytes_bpp(width, bytesPerPixel); | 93 return compute_row_bytes_bpp(width, bytesPerPixel); |
80 } | 94 } |
81 } | 95 } |
82 | 96 |
83 /* | 97 /* |
84 * | |
85 * Get a byte from a buffer | 98 * Get a byte from a buffer |
86 * This method is unsafe, the caller is responsible for performing a check | 99 * This method is unsafe, the caller is responsible for performing a check |
87 * | |
88 */ | 100 */ |
89 static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) { | 101 static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) { |
90 return buffer[i]; | 102 return buffer[i]; |
91 } | 103 } |
92 | 104 |
93 /* | 105 /* |
94 * | |
95 * Get a short from a buffer | 106 * Get a short from a buffer |
96 * This method is unsafe, the caller is responsible for performing a check | 107 * This method is unsafe, the caller is responsible for performing a check |
97 * | |
98 */ | 108 */ |
99 static inline uint16_t get_short(uint8_t* buffer, uint32_t i) { | 109 static inline uint16_t get_short(uint8_t* buffer, uint32_t i) { |
100 uint16_t result; | 110 uint16_t result; |
101 memcpy(&result, &(buffer[i]), 2); | 111 memcpy(&result, &(buffer[i]), 2); |
102 #ifdef SK_CPU_BENDIAN | 112 #ifdef SK_CPU_BENDIAN |
103 return SkEndianSwap16(result); | 113 return SkEndianSwap16(result); |
104 #else | 114 #else |
105 return result; | 115 return result; |
106 #endif | 116 #endif |
107 } | 117 } |
108 | 118 |
109 /* | 119 /* |
110 * | |
111 * Get an int from a buffer | 120 * Get an int from a buffer |
112 * This method is unsafe, the caller is responsible for performing a check | 121 * This method is unsafe, the caller is responsible for performing a check |
113 * | |
114 */ | 122 */ |
115 static inline uint32_t get_int(uint8_t* buffer, uint32_t i) { | 123 static inline uint32_t get_int(uint8_t* buffer, uint32_t i) { |
116 uint32_t result; | 124 uint32_t result; |
117 memcpy(&result, &(buffer[i]), 4); | 125 memcpy(&result, &(buffer[i]), 4); |
118 #ifdef SK_CPU_BENDIAN | 126 #ifdef SK_CPU_BENDIAN |
119 return SkEndianSwap32(result); | 127 return SkEndianSwap32(result); |
120 #else | 128 #else |
121 return result; | 129 return result; |
122 #endif | 130 #endif |
123 } | 131 } |
124 | 132 |
125 #ifdef SK_PRINT_CODEC_MESSAGES | 133 #ifdef SK_PRINT_CODEC_MESSAGES |
126 #define SkCodecPrintf SkDebugf | 134 #define SkCodecPrintf SkDebugf |
127 #else | 135 #else |
128 #define SkCodecPrintf(...) | 136 #define SkCodecPrintf(...) |
129 #endif | 137 #endif |
130 | 138 |
131 #endif // SkCodecPriv_DEFINED | 139 #endif // SkCodecPriv_DEFINED |
OLD | NEW |