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

Unified Diff: dm/DMSrcSink.cpp

Issue 1952063002: Create SkColorSpaceXform to handle color conversions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 7 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/DMSrcSink.h ('k') | gyp/core.gypi » ('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 f8c9bc0b586c858df22e23e1e497e6de763b0b43..356416035baaa809609d77c02b31c677b64e0989 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -6,11 +6,13 @@
*/
#include "DMSrcSink.h"
+#include "Resources.h"
#include "SkAndroidCodec.h"
#include "SkCodec.h"
#include "SkCodecImageGenerator.h"
#include "SkColorSpace.h"
#include "SkColorSpace_Base.h"
+#include "SkColorSpaceXform.h"
#include "SkCommonFlags.h"
#include "SkData.h"
#include "SkDocument.h"
@@ -39,6 +41,10 @@
#include "SkAutoCoInitialize.h"
#endif
+#if !defined(GOOGLE3)
+ #include "qcms.h"
+#endif
+
DEFINE_bool(multiPage, false, "For document-type backends, render the source"
" into multiple pages");
DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?");
@@ -827,10 +833,9 @@ Name ImageGenSrc::name() const {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-ColorCodecSrc::ColorCodecSrc(Path path, Mode mode, sk_sp<SkColorSpace> dstSpace)
+ColorCodecSrc::ColorCodecSrc(Path path, Mode mode)
: fPath(path)
, fMode(mode)
- , fDstSpace(dstSpace)
{}
bool ColorCodecSrc::veto(SinkFlags flags) const {
@@ -838,17 +843,6 @@ bool ColorCodecSrc::veto(SinkFlags flags) const {
return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
}
-static uint8_t clampFloatToByte(float v) {
- v = v * 255.0f;
- if (v > 255.0f) {
- return 255;
- } else if (v < 0.0f) {
- return 0;
- } else {
- return (uint8_t) (v + 0.5f);
- }
-}
-
Error ColorCodecSrc::draw(SkCanvas* canvas) const {
if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) {
return Error::Nonfatal("No need to test color correction to 565 backend.");
@@ -881,67 +875,76 @@ Error ColorCodecSrc::draw(SkCanvas* canvas) const {
return SkStringPrintf("Couldn't getPixels %s. Error code %d", fPath.c_str(), r);
}
+ // 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?";
+ }
+
switch (fMode) {
case kBaseline_Mode:
canvas->drawBitmap(bitmap, 0, 0);
break;
case kDst_HPZR30w_Mode: {
sk_sp<SkColorSpace> srcSpace = sk_ref_sp(codec->getColorSpace());
- if (!srcSpace) {
- return SkStringPrintf("Cannot test color correction without a src profile.");
- } else if (!as_CSB(srcSpace)->gammas()->isValues()) {
+ sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewICC(dstData->data(), dstData->size());
+ SkASSERT(dstSpace);
+
+ std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace, dstSpace);
+ if (!xform) {
// FIXME (msarett):
- // The conversion here doesn't cover all of the images that I've uploaded for
+ // I haven't implemented conversions for all of the images that I've uploaded for
// testing. Once we support all of them, this should be a fatal error.
- return Error::Nonfatal("Unimplemented gamma conversion.");
+ return Error::Nonfatal("Unimplemented color conversion.");
+ }
+
+ uint32_t* row = (uint32_t*) bitmap.getPixels();
+ for (int y = 0; y < info.height(); y++) {
+ xform->xform_RGBA_8888(row, row, info.width());
+ row = SkTAddOffset<uint32_t>(row, bitmap.rowBytes());
}
- // Build a matrix to transform to dst gamut.
- // srcToDst = inverse(dstToXYZ) * srcToXYZ
- const SkMatrix44& srcToXYZ = srcSpace->xyz();
- const SkMatrix44& dstToXYZ = fDstSpace->xyz();
- SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor);
- dstToXYZ.invert(&srcToDst);
- srcToDst.postConcat(srcToXYZ);
+ canvas->drawBitmap(bitmap, 0, 0);
+ break;
+ }
+#if !defined(GOOGLE3)
+ case kQCMS_HPZR30w_Mode: {
+ sk_sp<SkData> srcData = codec->getICCData();
+ SkAutoTCallVProc<qcms_profile, qcms_profile_release>
+ srcSpace(qcms_profile_from_memory(srcData->data(), srcData->size()));
+ if (!srcSpace) {
+ return Error::Nonfatal(SkStringPrintf("QCMS cannot create profile for %s.\n",
+ fPath.c_str()));
+ }
+
+ SkAutoTCallVProc<qcms_profile, qcms_profile_release>
+ dstSpace(qcms_profile_from_memory(dstData->data(), dstData->size()));
+ SkASSERT(dstSpace);
+ SkAutoTCallVProc<qcms_transform, qcms_transform_release>
+ transform (qcms_transform_create(srcSpace, QCMS_DATA_RGBA_8, dstSpace,
+ QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL));
+ if (!transform) {
+ return SkStringPrintf("QCMS cannot create transform for %s.\n", fPath.c_str());
+ }
+#ifdef SK_PMCOLOR_IS_RGBA
+ qcms_output_type outType = QCMS_OUTPUT_RGBX;
+#else
+ qcms_output_type outType = QCMS_OUTPUT_BGRX;
+#endif
+
+ // Perform color correction.
+ uint32_t* row = (uint32_t*) bitmap.getPixels();
for (int y = 0; y < info.height(); y++) {
- for (int x = 0; x < info.width(); x++) {
- // Extract floats.
- uint32_t* pixelPtr = (uint32_t*) bitmap.getAddr(x, y);
- float src[3];
- src[0] = ((*pixelPtr >> 0) & 0xFF) / 255.0f;
- src[1] = ((*pixelPtr >> 8) & 0xFF) / 255.0f;
- src[2] = ((*pixelPtr >> 16) & 0xFF) / 255.0f;
-
- // Convert to linear.
- src[0] = pow(src[0], as_CSB(srcSpace)->gammas()->fRed.fValue);
- src[1] = pow(src[1], as_CSB(srcSpace)->gammas()->fGreen.fValue);
- src[2] = pow(src[2], as_CSB(srcSpace)->gammas()->fBlue.fValue);
-
- // Convert to dst gamut.
- float dst[3];
- dst[0] = src[0]*srcToDst.getFloat(0, 0) + src[1]*srcToDst.getFloat(1, 0) +
- src[2]*srcToDst.getFloat(2, 0) + srcToDst.getFloat(3, 0);
- dst[1] = src[0]*srcToDst.getFloat(0, 1) + src[1]*srcToDst.getFloat(1, 1) +
- src[2]*srcToDst.getFloat(2, 1) + srcToDst.getFloat(3, 1);
- dst[2] = src[0]*srcToDst.getFloat(0, 2) + src[1]*srcToDst.getFloat(1, 2) +
- src[2]*srcToDst.getFloat(2, 2) + srcToDst.getFloat(3, 2);
-
- // Convert to dst gamma.
- dst[0] = pow(dst[0], 1.0f / as_CSB(fDstSpace)->gammas()->fRed.fValue);
- dst[1] = pow(dst[1], 1.0f / as_CSB(fDstSpace)->gammas()->fGreen.fValue);
- dst[2] = pow(dst[2], 1.0f / as_CSB(fDstSpace)->gammas()->fBlue.fValue);
-
- *pixelPtr = SkPackARGB32NoCheck(((*pixelPtr >> 24) & 0xFF),
- clampFloatToByte(dst[0]),
- clampFloatToByte(dst[1]),
- clampFloatToByte(dst[2]));
- }
+ qcms_transform_data_type(transform, row, row, info.width(), outType);
+ row = SkTAddOffset<uint32_t>(row, bitmap.rowBytes());
}
canvas->drawBitmap(bitmap, 0, 0);
break;
}
+#endif
default:
SkASSERT(false);
return "Invalid fMode";
« no previous file with comments | « dm/DMSrcSink.h ('k') | gyp/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698