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 |
11 #include "SkColorPriv.h" | |
11 #include "SkColorTable.h" | 12 #include "SkColorTable.h" |
12 #include "SkImageInfo.h" | 13 #include "SkImageInfo.h" |
13 #include "SkSwizzler.h" | 14 #include "SkSwizzler.h" |
14 #include "SkTypes.h" | 15 #include "SkTypes.h" |
15 #include "SkUtils.h" | 16 #include "SkUtils.h" |
16 | 17 |
17 /* | 18 /* |
18 * | 19 * |
19 * Helper routine for alpha result codes | 20 * Helper routine for alpha result codes |
20 * | 21 * |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 } | 133 } |
133 | 134 |
134 /* | 135 /* |
135 * If there is a color table, get a pointer to the colors, otherwise return null ptr | 136 * If there is a color table, get a pointer to the colors, otherwise return null ptr |
136 */ | 137 */ |
137 static const SkPMColor* get_color_ptr(SkColorTable* colorTable) { | 138 static const SkPMColor* get_color_ptr(SkColorTable* colorTable) { |
138 return nullptr != colorTable ? colorTable->readColors() : nullptr; | 139 return nullptr != colorTable ? colorTable->readColors() : nullptr; |
139 } | 140 } |
140 | 141 |
141 /* | 142 /* |
143 * Given that the encoded image uses a color table, return the fill value | |
144 */ | |
145 static uint32_t get_color_table_fill_value(SkColorType colorType, const SkPMColo r* colorPtr, | |
scroggo
2015/09/22 18:02:48
inline, not static
msarett
2015/09/23 13:22:40
Yes! I'll go ahead and fix all of these.
| |
146 uint8_t fillIndex) { | |
147 SkASSERT(nullptr != colorPtr); | |
148 switch (colorType) { | |
149 case kN32_SkColorType: | |
150 return colorPtr[fillIndex]; | |
151 case kRGB_565_SkColorType: | |
152 return SkPixel32ToPixel16(colorPtr[fillIndex]); | |
153 case kIndex_8_SkColorType: | |
154 return fillIndex; | |
155 default: | |
156 SkASSERT(false); | |
157 return 0; | |
158 } | |
159 } | |
160 | |
161 /* | |
142 * | 162 * |
143 * Copy the codec color table back to the client when kIndex8 color type is requ ested | 163 * Copy the codec color table back to the client when kIndex8 color type is requ ested |
144 */ | 164 */ |
145 static inline void copy_color_table(const SkImageInfo& dstInfo, SkColorTable* co lorTable, | 165 static inline void copy_color_table(const SkImageInfo& dstInfo, SkColorTable* co lorTable, |
146 SkPMColor* inputColorPtr, int* inputColorCount) { | 166 SkPMColor* inputColorPtr, int* inputColorCount) { |
147 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 167 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
148 SkASSERT(nullptr != inputColorPtr); | 168 SkASSERT(nullptr != inputColorPtr); |
149 SkASSERT(nullptr != inputColorCount); | 169 SkASSERT(nullptr != inputColorCount); |
150 SkASSERT(nullptr != colorTable); | 170 SkASSERT(nullptr != colorTable); |
151 memcpy(inputColorPtr, colorTable->readColors(), *inputColorCount * sizeo f(SkPMColor)); | 171 memcpy(inputColorPtr, colorTable->readColors(), *inputColorCount * sizeo f(SkPMColor)); |
(...skipping 23 matching lines...) Expand all Loading... | |
175 const uint32_t pixelsPerByte = 8 / bitsPerPixel; | 195 const uint32_t pixelsPerByte = 8 / bitsPerPixel; |
176 return compute_row_bytes_ppb(width, pixelsPerByte); | 196 return compute_row_bytes_ppb(width, pixelsPerByte); |
177 } else { | 197 } else { |
178 SkASSERT(0 == bitsPerPixel % 8); | 198 SkASSERT(0 == bitsPerPixel % 8); |
179 const uint32_t bytesPerPixel = bitsPerPixel / 8; | 199 const uint32_t bytesPerPixel = bitsPerPixel / 8; |
180 return compute_row_bytes_bpp(width, bytesPerPixel); | 200 return compute_row_bytes_bpp(width, bytesPerPixel); |
181 } | 201 } |
182 } | 202 } |
183 | 203 |
184 /* | 204 /* |
185 * On incomplete images, get the color to fill with | |
186 */ | |
187 static inline SkPMColor get_fill_color_or_index(SkAlphaType alphaType) { | |
188 // This condition works properly for all supported output color types. | |
189 // kIndex8: The low 8-bits of both possible return values is 0, which is | |
190 // our desired default index. | |
191 // kGray8: The low 8-bits of both possible return values is 0, which is | |
192 // black, our desired fill value. | |
193 // kRGB565: The low 16-bits of both possible return values is 0, which is | |
194 // black, our desired fill value. | |
195 // kN32: Return black for opaque images and transparent for non-opaque | |
196 // images. | |
197 return kOpaque_SkAlphaType == alphaType ? | |
198 SK_ColorBLACK : SK_ColorTRANSPARENT; | |
199 } | |
200 | |
201 /* | |
202 * Get a byte from a buffer | 205 * Get a byte from a buffer |
203 * This method is unsafe, the caller is responsible for performing a check | 206 * This method is unsafe, the caller is responsible for performing a check |
204 */ | 207 */ |
205 static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) { | 208 static inline uint8_t get_byte(uint8_t* buffer, uint32_t i) { |
206 return buffer[i]; | 209 return buffer[i]; |
207 } | 210 } |
208 | 211 |
209 /* | 212 /* |
210 * Get a short from a buffer | 213 * Get a short from a buffer |
211 * This method is unsafe, the caller is responsible for performing a check | 214 * This method is unsafe, the caller is responsible for performing a check |
(...skipping 22 matching lines...) Expand all Loading... | |
234 #endif | 237 #endif |
235 } | 238 } |
236 | 239 |
237 #ifdef SK_PRINT_CODEC_MESSAGES | 240 #ifdef SK_PRINT_CODEC_MESSAGES |
238 #define SkCodecPrintf SkDebugf | 241 #define SkCodecPrintf SkDebugf |
239 #else | 242 #else |
240 #define SkCodecPrintf(...) | 243 #define SkCodecPrintf(...) |
241 #endif | 244 #endif |
242 | 245 |
243 #endif // SkCodecPriv_DEFINED | 246 #endif // SkCodecPriv_DEFINED |
OLD | NEW |