Index: src/codec/SkJpegCodec.cpp |
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp |
index 0413f79a3c358466f4542d5812461adab209104e..85de356118ccda95e314c7b2ec7376100bb6684b 100644 |
--- a/src/codec/SkJpegCodec.cpp |
+++ b/src/codec/SkJpegCodec.cpp |
@@ -120,7 +120,7 @@ |
* (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<SkData> get_icc_profile(jpeg_decompress_struct* dinfo) { |
+static sk_sp<SkColorSpace> 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 @@ |
} |
// Combine the ICC marker data into a contiguous profile. |
- sk_sp<SkData> iccData = SkData::MakeUninitialized(totalBytes); |
- void* dst = iccData->writable_data(); |
+ SkAutoMalloc iccData(totalBytes); |
+ void* dst = iccData.get(); |
for (uint32_t i = 1; i <= numMarkers; i++) { |
jpeg_marker_struct* marker = markerSequence[i]; |
if (!marker) { |
@@ -180,7 +180,7 @@ |
dst = SkTAddOffset<void>(dst, bytes); |
} |
- return iccData; |
+ return SkColorSpace::NewICC(iccData.get(), totalBytes); |
} |
bool SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut, |
@@ -221,14 +221,7 @@ |
SkEncodedInfo info = SkEncodedInfo::Make(color, SkEncodedInfo::kOpaque_Alpha, 8); |
Origin orientation = get_exif_orientation(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"); |
- } |
- } |
+ sk_sp<SkColorSpace> colorSpace = get_icc_profile(decoderMgr->dinfo()); |
if (!colorSpace) { |
// Treat unmarked jpegs as sRGB. |
colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
@@ -237,7 +230,7 @@ |
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(iccData)); |
+ std::move(colorSpace), orientation); |
} else { |
SkASSERT(nullptr != decoderMgrOut); |
*decoderMgrOut = decoderMgr.release(); |
@@ -258,13 +251,11 @@ |
} |
SkJpegCodec::SkJpegCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream, |
- JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origin, |
- sk_sp<SkData> iccData) |
+ JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origin) |
: INHERITED(width, height, info, stream, std::move(colorSpace), origin) |
, fDecoderMgr(decoderMgr) |
, fReadyState(decoderMgr->dinfo()->global_state) |
, fSwizzlerSubset(SkIRect::MakeEmpty()) |
- , fICCData(std::move(iccData)) |
{} |
/* |