| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return false; | 125 return false; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Ensure the alpha type is valid | 128 // Ensure the alpha type is valid |
| 129 if (!valid_alpha(dst.alphaType(), src.alphaType())) { | 129 if (!valid_alpha(dst.alphaType(), src.alphaType())) { |
| 130 return false; | 130 return false; |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Check for supported color types | 133 // Check for supported color types |
| 134 switch (dst.colorType()) { | 134 switch (dst.colorType()) { |
| 135 case kN32_SkColorType: | 135 case kRGBA_8888_SkColorType: |
| 136 case kBGRA_8888_SkColorType: |
| 136 return true; | 137 return true; |
| 137 case kRGB_565_SkColorType: | 138 case kRGB_565_SkColorType: |
| 138 return kOpaque_SkAlphaType == dst.alphaType(); | 139 return kOpaque_SkAlphaType == dst.alphaType(); |
| 139 case kGray_8_SkColorType: | 140 case kGray_8_SkColorType: |
| 140 if (kOpaque_SkAlphaType != dst.alphaType()) { | 141 if (kOpaque_SkAlphaType != dst.alphaType()) { |
| 141 return false; | 142 return false; |
| 142 } | 143 } |
| 143 // Fall through | 144 // Fall through |
| 144 default: | 145 default: |
| 145 return dst.colorType() == src.colorType(); | 146 return dst.colorType() == src.colorType(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 } | 269 } |
| 269 | 270 |
| 270 inline uint16_t get_endian_short(const uint8_t* data, bool littleEndian) { | 271 inline uint16_t get_endian_short(const uint8_t* data, bool littleEndian) { |
| 271 if (littleEndian) { | 272 if (littleEndian) { |
| 272 return (data[1] << 8) | (data[0]); | 273 return (data[1] << 8) | (data[0]); |
| 273 } | 274 } |
| 274 | 275 |
| 275 return (data[0] << 8) | (data[1]); | 276 return (data[0] << 8) | (data[1]); |
| 276 } | 277 } |
| 277 | 278 |
| 279 inline SkPMColor premultiply_argb_as_rgba(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { |
| 280 if (a != 255) { |
| 281 r = SkMulDiv255Round(r, a); |
| 282 g = SkMulDiv255Round(g, a); |
| 283 b = SkMulDiv255Round(b, a); |
| 284 } |
| 285 |
| 286 return SkPackARGB_as_RGBA(a, r, g, b); |
| 287 } |
| 288 |
| 289 inline SkPMColor premultiply_argb_as_bgra(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { |
| 290 if (a != 255) { |
| 291 r = SkMulDiv255Round(r, a); |
| 292 g = SkMulDiv255Round(g, a); |
| 293 b = SkMulDiv255Round(b, a); |
| 294 } |
| 295 |
| 296 return SkPackARGB_as_BGRA(a, r, g, b); |
| 297 } |
| 298 |
| 299 inline bool is_rgba(SkColorType colorType) { |
| 300 #ifdef SK_PMCOLOR_IS_RGBA |
| 301 return (kBGRA_8888_SkColorType != colorType); |
| 302 #else |
| 303 return (kRGBA_8888_SkColorType == colorType); |
| 304 #endif |
| 305 } |
| 306 |
| 307 // Method for coverting to a 32 bit pixel. |
| 308 typedef uint32_t (*PackColorProc)(U8CPU a, U8CPU r, U8CPU g, U8CPU b); |
| 309 |
| 310 inline PackColorProc choose_pack_color_proc(bool isPremul, SkColorType colorType
) { |
| 311 bool isRGBA = is_rgba(colorType); |
| 312 if (isPremul) { |
| 313 if (isRGBA) { |
| 314 return &premultiply_argb_as_rgba; |
| 315 } else { |
| 316 return &premultiply_argb_as_bgra; |
| 317 } |
| 318 } else { |
| 319 if (isRGBA) { |
| 320 return &SkPackARGB_as_RGBA; |
| 321 } else { |
| 322 return &SkPackARGB_as_BGRA; |
| 323 } |
| 324 } |
| 325 } |
| 326 |
| 278 #endif // SkCodecPriv_DEFINED | 327 #endif // SkCodecPriv_DEFINED |
| OLD | NEW |