Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: dm/DMSrcSink.cpp

Issue 2174493002: Add color space xform support to SkJpegCodec (includes F16!) (Closed) Base URL: https://skia.googlesource.com/skia.git@drop
Patch Set: Fix MSAN suppression Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dm/DM.cpp ('k') | include/codec/SkCodec.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DMSrcSink.cpp
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index f3f5f78b57c2909b39f7df15484a60c03fd0f500..c03a8c4c984161c9a7c1aade3cc4b8f70b3b796f 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -867,75 +867,46 @@ Error ColorCodecSrc::draw(SkCanvas* canvas) const {
return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
}
- SkImageInfo info = codec->getInfo().makeColorType(fColorType);
- SkBitmap bitmap;
- if (!bitmap.tryAllocPixels(info)) {
- return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(),
- info.width(), info.height());
+ // Load the dst ICC profile. This particular dst is fairly similar to Adobe RGB.
+ sk_sp<SkData> dstData = SkData::MakeFromFileName(
+ GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str());
+ if (!dstData) {
+ return "Cannot read monitor profile. Is the resource path set correctly?";
}
- SkImageInfo decodeInfo = info;
- size_t srcRowBytes = sizeof(SkPMColor) * info.width();
- SkAutoMalloc src(srcRowBytes * info.height());
- void* srcPixels = src.get();
- if (kBaseline_Mode == fMode) {
- srcPixels = bitmap.getPixels();
- } else {
- decodeInfo = decodeInfo.makeColorType(kRGBA_8888_SkColorType);
+ sk_sp<SkColorSpace> dstSpace = nullptr;
+ if (kDst_sRGB_Mode == fMode) {
+ dstSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+ } else if (kDst_HPZR30w_Mode == fMode) {
+ dstSpace = SkColorSpace::NewICC(dstData->data(), dstData->size());
}
- SkCodec::Result r = codec->getPixels(decodeInfo, srcPixels, srcRowBytes);
- if (SkCodec::kSuccess != r) {
- return SkStringPrintf("Couldn't getPixels %s. Error code %d", fPath.c_str(), r);
+ SkImageInfo decodeInfo = codec->getInfo().makeColorType(fColorType).makeColorSpace(dstSpace);
+ SkImageInfo bitmapInfo = decodeInfo;
+ if (kRGBA_8888_SkColorType == decodeInfo.colorType() ||
+ kBGRA_8888_SkColorType == decodeInfo.colorType())
+ {
+ bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType);
}
- // Load the dst ICC profile. This particular dst is fairly similar to Adobe RGB.
- sk_sp<SkData> dstData = SkData::MakeFromFileName(
- GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str());
- if (!dstData) {
- return "Cannot read monitor profile. Is the resource path set correctly?";
+ SkBitmap bitmap;
+ if (!bitmap.tryAllocPixels(bitmapInfo)) {
+ return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(),
+ bitmapInfo.width(), bitmapInfo.height());
+ }
+
+ size_t rowBytes = bitmap.rowBytes();
+ SkCodec::Result r = codec->getPixels(decodeInfo, bitmap.getPixels(), rowBytes);
+ if (SkCodec::kSuccess != r) {
+ return SkStringPrintf("Couldn't getPixels %s. Error code %d", fPath.c_str(), r);
}
switch (fMode) {
case kBaseline_Mode:
- canvas->drawBitmap(bitmap, 0, 0);
- break;
case kDst_sRGB_Mode:
- case kDst_HPZR30w_Mode: {
- sk_sp<SkColorSpace> srcSpace = sk_ref_sp(codec->getInfo().colorSpace());
- sk_sp<SkColorSpace> dstSpace = (kDst_sRGB_Mode == fMode) ?
- SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) :
- SkColorSpace::NewICC(dstData->data(), dstData->size());
- SkASSERT(dstSpace);
-
- std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace, dstSpace);
- if (!xform) {
- return "Unimplemented color conversion.";
- }
-
- if (kN32_SkColorType == fColorType) {
- uint32_t* srcRow = (uint32_t*) srcPixels;
- uint32_t* dstRow = (uint32_t*) bitmap.getPixels();
- for (int y = 0; y < info.height(); y++) {
- xform->applyTo8888(dstRow, srcRow, info.width());
- srcRow = SkTAddOffset<uint32_t>(srcRow, srcRowBytes);
- dstRow = SkTAddOffset<uint32_t>(dstRow, bitmap.rowBytes());
- }
- } else {
- SkASSERT(kRGBA_F16_SkColorType == fColorType);
-
- uint32_t* srcRow = (uint32_t*) srcPixels;
- uint64_t* dstRow = (uint64_t*) bitmap.getPixels();
- for (int y = 0; y < info.height(); y++) {
- xform->applyToF16(dstRow, srcRow, info.width());
- srcRow = SkTAddOffset<uint32_t>(srcRow, srcRowBytes);
- dstRow = SkTAddOffset<uint64_t>(dstRow, bitmap.rowBytes());
- }
- }
-
+ case kDst_HPZR30w_Mode:
canvas->drawBitmap(bitmap, 0, 0);
break;
- }
#if defined(SK_TEST_QCMS)
case kQCMS_HPZR30w_Mode: {
sk_sp<SkData> srcData = codec->getICCData();
@@ -967,12 +938,10 @@ Error ColorCodecSrc::draw(SkCanvas* canvas) const {
#endif
// Perform color correction.
- uint32_t* srcRow = (uint32_t*) srcPixels;
- uint32_t* dstRow = (uint32_t*) bitmap.getPixels();
- for (int y = 0; y < info.height(); y++) {
- qcms_transform_data_type(transform, srcRow, dstRow, info.width(), outType);
- srcRow = SkTAddOffset<uint32_t>(srcRow, srcRowBytes);
- dstRow = SkTAddOffset<uint32_t>(dstRow, bitmap.rowBytes());
+ uint32_t* row = (uint32_t*) bitmap.getPixels();
+ for (int y = 0; y < decodeInfo.height(); y++) {
+ qcms_transform_data_type(transform, row, row, decodeInfo.width(), outType);
+ row = SkTAddOffset<uint32_t>(row, rowBytes);
}
canvas->drawBitmap(bitmap, 0, 0);
« no previous file with comments | « dm/DM.cpp ('k') | include/codec/SkCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698