| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 /* | 140 /* |
| 141 * If there is a color table, get a pointer to the colors, otherwise return null
ptr | 141 * If there is a color table, get a pointer to the colors, otherwise return null
ptr |
| 142 */ | 142 */ |
| 143 static inline const SkPMColor* get_color_ptr(SkColorTable* colorTable) { | 143 static inline const SkPMColor* get_color_ptr(SkColorTable* colorTable) { |
| 144 return nullptr != colorTable ? colorTable->readColors() : nullptr; | 144 return nullptr != colorTable ? colorTable->readColors() : nullptr; |
| 145 } | 145 } |
| 146 | 146 |
| 147 static inline SkColorSpaceXform::ColorFormat select_xform_format(SkColorType col
orType) { | |
| 148 switch (colorType) { | |
| 149 case kRGBA_8888_SkColorType: | |
| 150 return SkColorSpaceXform::kRGBA_8888_ColorFormat; | |
| 151 case kBGRA_8888_SkColorType: | |
| 152 return SkColorSpaceXform::kBGRA_8888_ColorFormat; | |
| 153 case kRGBA_F16_SkColorType: | |
| 154 return SkColorSpaceXform::kRGBA_F16_ColorFormat; | |
| 155 default: | |
| 156 SkASSERT(false); | |
| 157 return SkColorSpaceXform::kRGBA_8888_ColorFormat; | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 /* | 147 /* |
| 162 * Given that the encoded image uses a color table, return the fill value | 148 * Given that the encoded image uses a color table, return the fill value |
| 163 */ | 149 */ |
| 164 static inline uint64_t get_color_table_fill_value(SkColorType colorType, SkAlpha
Type alphaType, | 150 static inline uint64_t get_color_table_fill_value(SkColorType colorType, SkAlpha
Type alphaType, |
| 165 const SkPMColor* colorPtr, uint8_t fillIndex, SkColorSpaceXform* colorXf
orm) { | 151 const SkPMColor* colorPtr, uint8_t fillIndex, SkColorSpaceXform* colorXf
orm) { |
| 166 SkASSERT(nullptr != colorPtr); | 152 SkASSERT(nullptr != colorPtr); |
| 167 switch (colorType) { | 153 switch (colorType) { |
| 168 case kRGBA_8888_SkColorType: | 154 case kRGBA_8888_SkColorType: |
| 169 case kBGRA_8888_SkColorType: | 155 case kBGRA_8888_SkColorType: |
| 170 return colorPtr[fillIndex]; | 156 return colorPtr[fillIndex]; |
| 171 case kRGB_565_SkColorType: | 157 case kRGB_565_SkColorType: |
| 172 return SkPixel32ToPixel16(colorPtr[fillIndex]); | 158 return SkPixel32ToPixel16(colorPtr[fillIndex]); |
| 173 case kIndex_8_SkColorType: | 159 case kIndex_8_SkColorType: |
| 174 return fillIndex; | 160 return fillIndex; |
| 175 case kRGBA_F16_SkColorType: { | 161 case kRGBA_F16_SkColorType: { |
| 176 SkASSERT(colorXform); | 162 SkASSERT(colorXform); |
| 177 uint64_t dstColor; | 163 uint64_t dstColor; |
| 178 uint32_t srcColor = colorPtr[fillIndex]; | 164 uint32_t srcColor = colorPtr[fillIndex]; |
| 179 colorXform->apply(&dstColor, &srcColor, 1, select_xform_format(color
Type), alphaType); | 165 colorXform->apply(&dstColor, &srcColor, 1, colorType, alphaType); |
| 180 return dstColor; | 166 return dstColor; |
| 181 } | 167 } |
| 182 default: | 168 default: |
| 183 SkASSERT(false); | 169 SkASSERT(false); |
| 184 return 0; | 170 return 0; |
| 185 } | 171 } |
| 186 } | 172 } |
| 187 | 173 |
| 188 /* | 174 /* |
| 189 * | 175 * |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 336 |
| 351 // Need a color xform when dst space does not match the src. | 337 // Need a color xform when dst space does not match the src. |
| 352 bool srcDstNotEqual = !SkColorSpace::Equals(srcInfo.colorSpace(), dstInfo.co
lorSpace()); | 338 bool srcDstNotEqual = !SkColorSpace::Equals(srcInfo.colorSpace(), dstInfo.co
lorSpace()); |
| 353 | 339 |
| 354 // We never perform a color xform in legacy mode. | 340 // We never perform a color xform in legacy mode. |
| 355 bool isLegacy = nullptr == dstInfo.colorSpace(); | 341 bool isLegacy = nullptr == dstInfo.colorSpace(); |
| 356 | 342 |
| 357 return !isLegacy && (needsPremul || isF16 || srcDstNotEqual); | 343 return !isLegacy && (needsPremul || isF16 || srcDstNotEqual); |
| 358 } | 344 } |
| 359 | 345 |
| 360 static inline SkAlphaType select_xform_alpha(SkAlphaType dstAlphaType, SkAlphaTy
pe srcAlphaType) { | 346 static inline SkAlphaType select_alpha_xform(SkAlphaType dstAlphaType, SkAlphaTy
pe srcAlphaType) { |
| 361 return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlph
aType; | 347 return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlph
aType; |
| 362 } | 348 } |
| 363 | 349 |
| 364 /* | 350 /* |
| 365 * Alpha Type Conversions | 351 * Alpha Type Conversions |
| 366 * - kOpaque to kOpaque, kUnpremul, kPremul is valid | 352 * - kOpaque to kOpaque, kUnpremul, kPremul is valid |
| 367 * - kUnpremul to kUnpremul, kPremul is valid | 353 * - kUnpremul to kUnpremul, kPremul is valid |
| 368 * | 354 * |
| 369 * Color Type Conversions | 355 * Color Type Conversions |
| 370 * - Always support kRGBA_8888, kBGRA_8888 | 356 * - Always support kRGBA_8888, kBGRA_8888 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 392 return kOpaque_SkAlphaType == src.alphaType() && !needs_color_xform(
dst, src); | 378 return kOpaque_SkAlphaType == src.alphaType() && !needs_color_xform(
dst, src); |
| 393 case kGray_8_SkColorType: | 379 case kGray_8_SkColorType: |
| 394 return kGray_8_SkColorType == src.colorType() && | 380 return kGray_8_SkColorType == src.colorType() && |
| 395 kOpaque_SkAlphaType == src.alphaType() && !needs_color_xform(
dst, src); | 381 kOpaque_SkAlphaType == src.alphaType() && !needs_color_xform(
dst, src); |
| 396 default: | 382 default: |
| 397 return false; | 383 return false; |
| 398 } | 384 } |
| 399 } | 385 } |
| 400 | 386 |
| 401 #endif // SkCodecPriv_DEFINED | 387 #endif // SkCodecPriv_DEFINED |
| OLD | NEW |