Assign sRGB color space to unmarked jpegs and pngs
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2009813003
Review-Url: https://codereview.chromium.org/2009813003
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index 07ece6c..5d24694 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -222,11 +222,15 @@
Origin orientation = get_exif_orientation(decoderMgr->dinfo());
sk_sp<SkColorSpace> colorSpace = get_icc_profile(decoderMgr->dinfo());
+ if (!colorSpace) {
+ // Treat unmarked jpegs as sRGB.
+ colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+ }
const int width = decoderMgr->dinfo()->image_width;
const int height = decoderMgr->dinfo()->image_height;
- *codecOut = new SkJpegCodec(width, height, info, stream, decoderMgr.release(), colorSpace,
- orientation);
+ *codecOut = new SkJpegCodec(width, height, info, stream, decoderMgr.release(),
+ std::move(colorSpace), orientation);
} else {
SkASSERT(nullptr != decoderMgrOut);
*decoderMgrOut = decoderMgr.release();
@@ -248,7 +252,7 @@
SkJpegCodec::SkJpegCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origin)
- : INHERITED(width, height, info, stream, colorSpace, origin)
+ : INHERITED(width, height, info, stream, std::move(colorSpace), origin)
, fDecoderMgr(decoderMgr)
, fReadyState(decoderMgr->dinfo()->global_state)
, fSwizzlerSubset(SkIRect::MakeEmpty())
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index 84d2575..43d1580 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -608,6 +608,11 @@
if (outCodec) {
sk_sp<SkColorSpace> colorSpace = read_color_space(png_ptr, info_ptr);
+ if (!colorSpace) {
+ // Treat unmarked pngs as sRGB.
+ colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+ }
+
SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8);
if (1 == numberPasses) {