diff options
author | msarett <msarett@google.com> | 2016-06-01 14:47:18 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-01 14:47:18 -0700 |
commit | 9876ac5b3016e5353c072378ac1545a0a2270757 (patch) | |
tree | 2ca6c3c24f94550d2e8c71f2a1b57d0eea5a0f1c /src/codec | |
parent | 81e4cc7723ea87de8b8917e52cc25f524225fa43 (diff) |
Create SkColorSpaceXform to handle color conversions
Also adds testing of qcms color correction, so we can compare
SkColorSpaceXform outputs to qcms outputs.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1952063002
Committed: https://skia.googlesource.com/skia/+/740cc88ee3d63c75e52d31238f2a32600cc57a8c
Review-Url: https://codereview.chromium.org/1952063002
Diffstat (limited to 'src/codec')
-rw-r--r-- | src/codec/SkJpegCodec.cpp | 23 | ||||
-rw-r--r-- | src/codec/SkJpegCodec.h | 7 |
2 files changed, 22 insertions, 8 deletions
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp index 85de356118..0413f79a3c 100644 --- a/src/codec/SkJpegCodec.cpp +++ b/src/codec/SkJpegCodec.cpp @@ -120,7 +120,7 @@ static bool is_icc_marker(jpeg_marker_struct* marker) { * (1) Discover all ICC profile markers and verify that they are numbered properly. * (2) Copy the data from each marker into a contiguous ICC profile. */ -static sk_sp<SkColorSpace> get_icc_profile(jpeg_decompress_struct* dinfo) { +static sk_sp<SkData> get_icc_profile(jpeg_decompress_struct* dinfo) { // Note that 256 will be enough storage space since each markerIndex is stored in 8-bits. jpeg_marker_struct* markerSequence[256]; memset(markerSequence, 0, sizeof(markerSequence)); @@ -165,8 +165,8 @@ static sk_sp<SkColorSpace> get_icc_profile(jpeg_decompress_struct* dinfo) { } // Combine the ICC marker data into a contiguous profile. - SkAutoMalloc iccData(totalBytes); - void* dst = iccData.get(); + sk_sp<SkData> iccData = SkData::MakeUninitialized(totalBytes); + void* dst = iccData->writable_data(); for (uint32_t i = 1; i <= numMarkers; i++) { jpeg_marker_struct* marker = markerSequence[i]; if (!marker) { @@ -180,7 +180,7 @@ static sk_sp<SkColorSpace> get_icc_profile(jpeg_decompress_struct* dinfo) { dst = SkTAddOffset<void>(dst, bytes); } - return SkColorSpace::NewICC(iccData.get(), totalBytes); + return iccData; } bool SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut, @@ -221,7 +221,14 @@ bool SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut, SkEncodedInfo info = SkEncodedInfo::Make(color, SkEncodedInfo::kOpaque_Alpha, 8); Origin orientation = get_exif_orientation(decoderMgr->dinfo()); - sk_sp<SkColorSpace> colorSpace = get_icc_profile(decoderMgr->dinfo()); + sk_sp<SkData> iccData = get_icc_profile(decoderMgr->dinfo()); + sk_sp<SkColorSpace> colorSpace = nullptr; + if (iccData) { + colorSpace = SkColorSpace::NewICC(iccData->data(), iccData->size()); + if (!colorSpace) { + SkCodecPrintf("Could not create SkColorSpace from ICC data.\n"); + } + } if (!colorSpace) { // Treat unmarked jpegs as sRGB. colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); @@ -230,7 +237,7 @@ bool SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut, const int width = decoderMgr->dinfo()->image_width; const int height = decoderMgr->dinfo()->image_height; *codecOut = new SkJpegCodec(width, height, info, stream, decoderMgr.release(), - std::move(colorSpace), orientation); + std::move(colorSpace), orientation, std::move(iccData)); } else { SkASSERT(nullptr != decoderMgrOut); *decoderMgrOut = decoderMgr.release(); @@ -251,11 +258,13 @@ SkCodec* SkJpegCodec::NewFromStream(SkStream* stream) { } SkJpegCodec::SkJpegCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream, - JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origin) + JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origin, + sk_sp<SkData> iccData) : INHERITED(width, height, info, stream, std::move(colorSpace), origin) , fDecoderMgr(decoderMgr) , fReadyState(decoderMgr->dinfo()->global_state) , fSwizzlerSubset(SkIRect::MakeEmpty()) + , fICCData(std::move(iccData)) {} /* diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h index f8cddd0221..7aa275ce4e 100644 --- a/src/codec/SkJpegCodec.h +++ b/src/codec/SkJpegCodec.h @@ -58,6 +58,8 @@ protected: bool onDimensionsSupported(const SkISize&) override; + sk_sp<SkData> getICCData() const override { return fICCData; } + private: /* @@ -92,7 +94,8 @@ private: * takes ownership */ SkJpegCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream, - JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origin); + JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origin, + sk_sp<SkData> iccData); /* * Checks if the conversion between the input image and the requested output @@ -123,6 +126,8 @@ private: SkIRect fSwizzlerSubset; SkAutoTDelete<SkSwizzler> fSwizzler; + sk_sp<SkData> fICCData; + typedef SkCodec INHERITED; }; |