AImageDecoder: allow no color conversion
Bug: 135133301
Test: I5e8bdcdae6837db23c0f4ef08f931f3bebe0ce0d
Previously the default SkColorSpace for AImageDecoder was set to the
result of SkAndroidCodec::computeOutputColorSpace. If the image has a
profile that does not map to an SkColorSpace, it will return either
DISPLAY_P3 or SRGB. Using that at decode time will result in color
conversion.
Instead, default to a null SkColorSpace for such a profile, resulting in
no color conversion. If the image has no profile, default to SRGB, as
usual.
A client that wants SRGB can still request and get that, but this allows
getting the raw pixels for an advanced client that may want to do its
own conversion.
Change-Id: I489f31fef79dec11e97c8e8fb9207adb77a3d0c7
diff --git a/native/graphics/jni/imagedecoder.cpp b/native/graphics/jni/imagedecoder.cpp
index c1143ce..2e4d214 100644
--- a/native/graphics/jni/imagedecoder.cpp
+++ b/native/graphics/jni/imagedecoder.cpp
@@ -213,12 +213,12 @@
return ANDROID_IMAGE_DECODER_BAD_PARAMETER;
}
- // Note: This recomputes the data space because it's possible the client has
- // changed the output color space, so we cannot rely on it. Alternatively,
+ // Note: This recomputes the color type because it's possible the client has
+ // changed the output color type, so we cannot rely on it. Alternatively,
// we could store the ADataSpace in the ImageDecoder.
const ImageDecoder* imageDecoder = toDecoder(info);
SkColorType colorType = imageDecoder->mCodec->computeOutputColorType(kN32_SkColorType);
- sk_sp<SkColorSpace> colorSpace = imageDecoder->mCodec->computeOutputColorSpace(colorType);
+ sk_sp<SkColorSpace> colorSpace = imageDecoder->getDefaultColorSpace();
return uirenderer::ColorSpaceToADataSpace(colorSpace.get(), colorType);
}