| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // will treat the encoded data as linear regardless of what the client | 121 // will treat the encoded data as linear regardless of what the client |
| 122 // requests. | 122 // requests. |
| 123 | 123 |
| 124 // Ensure the alpha type is valid | 124 // Ensure the alpha type is valid |
| 125 if (!valid_alpha(dst.alphaType(), src.alphaType())) { | 125 if (!valid_alpha(dst.alphaType(), src.alphaType())) { |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Check for supported color types | 129 // Check for supported color types |
| 130 switch (dst.colorType()) { | 130 switch (dst.colorType()) { |
| 131 case kN32_SkColorType: | 131 case kRGBA_8888_SkColorType: |
| 132 case kBGRA_8888_SkColorType: |
| 132 return true; | 133 return true; |
| 133 case kRGB_565_SkColorType: | 134 case kRGB_565_SkColorType: |
| 134 return kOpaque_SkAlphaType == dst.alphaType(); | 135 return kOpaque_SkAlphaType == dst.alphaType(); |
| 135 case kGray_8_SkColorType: | 136 case kGray_8_SkColorType: |
| 136 if (kOpaque_SkAlphaType != dst.alphaType()) { | 137 if (kOpaque_SkAlphaType != dst.alphaType()) { |
| 137 return false; | 138 return false; |
| 138 } | 139 } |
| 139 // Fall through | 140 // Fall through |
| 140 default: | 141 default: |
| 141 return dst.colorType() == src.colorType(); | 142 return dst.colorType() == src.colorType(); |
| 142 } | 143 } |
| 143 } | 144 } |
| 144 | 145 |
| 145 /* | 146 /* |
| 146 * If there is a color table, get a pointer to the colors, otherwise return null
ptr | 147 * If there is a color table, get a pointer to the colors, otherwise return null
ptr |
| 147 */ | 148 */ |
| 148 inline const SkPMColor* get_color_ptr(SkColorTable* colorTable) { | 149 inline const SkPMColor* get_color_ptr(SkColorTable* colorTable) { |
| 149 return nullptr != colorTable ? colorTable->readColors() : nullptr; | 150 return nullptr != colorTable ? colorTable->readColors() : nullptr; |
| 150 } | 151 } |
| 151 | 152 |
| 152 /* | 153 /* |
| 153 * Given that the encoded image uses a color table, return the fill value | 154 * Given that the encoded image uses a color table, return the fill value |
| 154 */ | 155 */ |
| 155 inline uint32_t get_color_table_fill_value(SkColorType colorType, const SkPMColo
r* colorPtr, | 156 inline uint32_t get_color_table_fill_value(SkColorType colorType, const SkPMColo
r* colorPtr, |
| 156 uint8_t fillIndex) { | 157 uint8_t fillIndex) { |
| 157 SkASSERT(nullptr != colorPtr); | 158 SkASSERT(nullptr != colorPtr); |
| 158 switch (colorType) { | 159 switch (colorType) { |
| 159 case kN32_SkColorType: | 160 case kRGBA_8888_SkColorType: |
| 161 case kBGRA_8888_SkColorType: |
| 160 return colorPtr[fillIndex]; | 162 return colorPtr[fillIndex]; |
| 161 case kRGB_565_SkColorType: | 163 case kRGB_565_SkColorType: |
| 162 return SkPixel32ToPixel16(colorPtr[fillIndex]); | 164 return SkPixel32ToPixel16(colorPtr[fillIndex]); |
| 163 case kIndex_8_SkColorType: | 165 case kIndex_8_SkColorType: |
| 164 return fillIndex; | 166 return fillIndex; |
| 165 default: | 167 default: |
| 166 SkASSERT(false); | 168 SkASSERT(false); |
| 167 return 0; | 169 return 0; |
| 168 } | 170 } |
| 169 } | 171 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 } | 266 } |
| 265 | 267 |
| 266 inline uint16_t get_endian_short(const uint8_t* data, bool littleEndian) { | 268 inline uint16_t get_endian_short(const uint8_t* data, bool littleEndian) { |
| 267 if (littleEndian) { | 269 if (littleEndian) { |
| 268 return (data[1] << 8) | (data[0]); | 270 return (data[1] << 8) | (data[0]); |
| 269 } | 271 } |
| 270 | 272 |
| 271 return (data[0] << 8) | (data[1]); | 273 return (data[0] << 8) | (data[1]); |
| 272 } | 274 } |
| 273 | 275 |
| 276 inline SkPMColor premultiply_argb_as_rgba(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { |
| 277 if (a != 255) { |
| 278 r = SkMulDiv255Round(r, a); |
| 279 g = SkMulDiv255Round(g, a); |
| 280 b = SkMulDiv255Round(b, a); |
| 281 } |
| 282 |
| 283 return SkPackARGB_as_RGBA(a, r, g, b); |
| 284 } |
| 285 |
| 286 inline SkPMColor premultiply_argb_as_bgra(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { |
| 287 if (a != 255) { |
| 288 r = SkMulDiv255Round(r, a); |
| 289 g = SkMulDiv255Round(g, a); |
| 290 b = SkMulDiv255Round(b, a); |
| 291 } |
| 292 |
| 293 return SkPackARGB_as_BGRA(a, r, g, b); |
| 294 } |
| 295 |
| 296 inline bool is_rgba(SkColorType colorType) { |
| 297 #ifdef SK_PMCOLOR_IS_RGBA |
| 298 return (kBGRA_8888_SkColorType != colorType); |
| 299 #else |
| 300 return (kRGBA_8888_SkColorType == colorType); |
| 301 #endif |
| 302 } |
| 303 |
| 304 // Method for coverting to a 32 bit pixel. |
| 305 typedef uint32_t (*PackColorProc)(U8CPU a, U8CPU r, U8CPU g, U8CPU b); |
| 306 |
| 307 inline PackColorProc choose_pack_color_proc(bool isPremul, SkColorType colorType
) { |
| 308 bool isRGBA = is_rgba(colorType); |
| 309 if (isPremul) { |
| 310 if (isRGBA) { |
| 311 return &premultiply_argb_as_rgba; |
| 312 } else { |
| 313 return &premultiply_argb_as_bgra; |
| 314 } |
| 315 } else { |
| 316 if (isRGBA) { |
| 317 return &SkPackARGB_as_RGBA; |
| 318 } else { |
| 319 return &SkPackARGB_as_BGRA; |
| 320 } |
| 321 } |
| 322 } |
| 323 |
| 274 #endif // SkCodecPriv_DEFINED | 324 #endif // SkCodecPriv_DEFINED |
| OLD | NEW |