aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec/SkCodecPriv.h
diff options
context:
space:
mode:
authorGravatar Matt Sarett <msarett@google.com>2017-04-03 16:01:10 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-04 15:22:04 +0000
commit19aff5dd5cd83141f12c234c4255a35f63e564cd (patch)
treecde4a5f4723319325bff3491368e408232b26e0b /src/codec/SkCodecPriv.h
parent114e6b33d67537f034b749e77f68d168ef9bfbc6 (diff)
565 codec color xform support: fix colortable / incomplete image behavior
This fixes a bug that was exposed when I added color space support for 565 decodes. Before this CL, we would sometimes fill incomplete images with R and B swapped. This fixes that issue. Part of the fix is the decision to do 565 xforms when building the color table (then just swizzle to 565), rather than do them per pixel after swizzling. Bug: skia: Change-Id: I09e1ec75aba09a4e288015ea746465d0c3f7d59f Reviewed-on: https://skia-review.googlesource.com/11137 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Matt Sarett <msarett@google.com>
Diffstat (limited to 'src/codec/SkCodecPriv.h')
-rw-r--r--src/codec/SkCodecPriv.h33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/codec/SkCodecPriv.h b/src/codec/SkCodecPriv.h
index 56a1900220..5c8dc8747a 100644
--- a/src/codec/SkCodecPriv.h
+++ b/src/codec/SkCodecPriv.h
@@ -120,7 +120,7 @@ static inline const SkPMColor* get_color_ptr(SkColorTable* colorTable) {
* Given that the encoded image uses a color table, return the fill value
*/
static inline uint64_t get_color_table_fill_value(SkColorType dstColorType, SkAlphaType alphaType,
- const SkPMColor* colorPtr, uint8_t fillIndex, SkColorSpaceXform* colorXform) {
+ const SkPMColor* colorPtr, uint8_t fillIndex, SkColorSpaceXform* colorXform, bool isRGBA) {
SkASSERT(nullptr != colorPtr);
switch (dstColorType) {
case kRGBA_8888_SkColorType:
@@ -134,8 +134,11 @@ static inline uint64_t get_color_table_fill_value(SkColorType dstColorType, SkAl
SkASSERT(colorXform);
uint64_t dstColor;
uint32_t srcColor = colorPtr[fillIndex];
+ SkColorSpaceXform::ColorFormat srcFormat =
+ isRGBA ? SkColorSpaceXform::kRGBA_8888_ColorFormat
+ : SkColorSpaceXform::kBGRA_8888_ColorFormat;
SkAssertResult(colorXform->apply(select_xform_format(dstColorType), &dstColor,
- SkColorSpaceXform::kRGBA_8888_ColorFormat, &srcColor, 1, alphaType));
+ srcFormat, &srcColor, 1, alphaType));
return dstColor;
}
default:
@@ -321,11 +324,8 @@ static inline SkAlphaType select_xform_alpha(SkAlphaType dstAlphaType, SkAlphaTy
}
static inline bool apply_xform_on_decode(SkColorType dstColorType, SkEncodedInfo::Color srcColor) {
- // We will apply the color xform when reading the color table if a form of 8888 is requested.
- return SkEncodedInfo::kPalette_Color != srcColor ||
- (kRGBA_8888_SkColorType != dstColorType &&
- kBGRA_8888_SkColorType != dstColorType &&
- kIndex_8_SkColorType != dstColorType);
+ // We will apply the color xform when reading the color table unless F16 is requested.
+ return SkEncodedInfo::kPalette_Color != srcColor || kRGBA_F16_SkColorType == dstColorType;
}
/*
@@ -365,4 +365,23 @@ static inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo
}
}
+static inline SkColorSpaceXform::ColorFormat select_xform_format_ct(SkColorType colorType) {
+ switch (colorType) {
+ case kRGBA_8888_SkColorType:
+ return SkColorSpaceXform::kRGBA_8888_ColorFormat;
+ case kBGRA_8888_SkColorType:
+ return SkColorSpaceXform::kBGRA_8888_ColorFormat;
+ case kRGB_565_SkColorType:
+ case kIndex_8_SkColorType:
+#ifdef SK_PMCOLOR_IS_RGBA
+ return SkColorSpaceXform::kRGBA_8888_ColorFormat;
+#else
+ return SkColorSpaceXform::kBGRA_8888_ColorFormat;
+#endif
+ default:
+ SkASSERT(false);
+ return SkColorSpaceXform::kRGBA_8888_ColorFormat;
+ }
+}
+
#endif // SkCodecPriv_DEFINED