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

Unified Diff: ui/gfx/color_space.cc

Issue 2691213007: color: Don't use QCMS for transforms unless necessary (Closed)
Patch Set: Incorporate review feedback Created 3 years, 10 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 | « ui/gfx/color_space.h ('k') | ui/gfx/color_transform.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/color_space.cc
diff --git a/ui/gfx/color_space.cc b/ui/gfx/color_space.cc
index 74836636a4ebfa86ca43e6ee8aa449d644f9e2fb..a20f011a9a11fcfb9491ae9086446a4f64f8dcb7 100644
--- a/ui/gfx/color_space.cc
+++ b/ui/gfx/color_space.cc
@@ -9,6 +9,8 @@
#include "base/lazy_instance.h"
#include "base/synchronization/lock.h"
#include "third_party/skia/include/core/SkColorSpace.h"
+#include "third_party/skia/include/core/SkData.h"
+#include "third_party/skia/include/core/SkICC.h"
#include "ui/gfx/icc_profile.h"
#include "ui/gfx/skia_color_space_util.h"
#include "ui/gfx/transform.h"
@@ -199,6 +201,28 @@ ColorSpace ColorSpace::CreateSRGB() {
}
// static
+ColorSpace ColorSpace::CreateCustom(const SkMatrix44& to_XYZD50,
+ const SkColorSpaceTransferFn& fn) {
+ ColorSpace result(ColorSpace::PrimaryID::CUSTOM,
+ ColorSpace::TransferID::CUSTOM, ColorSpace::MatrixID::RGB,
+ ColorSpace::RangeID::FULL);
+ for (int row = 0; row < 3; ++row) {
+ for (int col = 0; col < 3; ++col) {
+ result.custom_primary_matrix_[3 * row + col] = to_XYZD50.get(row, col);
+ }
+ }
+ result.custom_transfer_params_[0] = fn.fA;
+ result.custom_transfer_params_[1] = fn.fB;
+ result.custom_transfer_params_[2] = fn.fC;
+ result.custom_transfer_params_[3] = fn.fD;
+ result.custom_transfer_params_[4] = fn.fE;
+ result.custom_transfer_params_[5] = fn.fF;
+ result.custom_transfer_params_[6] = fn.fG;
+ // TODO(ccameron): Use enums for near matches to know color spaces.
+ return result;
+}
+
+// static
ColorSpace ColorSpace::CreateSCRGBLinear() {
return ColorSpace(PrimaryID::BT709, TransferID::LINEAR_HDR, MatrixID::RGB,
RangeID::FULL);
@@ -343,6 +367,34 @@ sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const {
return SkColorSpace::MakeRGB(fn, to_xyz_d50);
}
+bool ColorSpace::GetICCProfile(ICCProfile* icc_profile) const {
+ if (!IsValid())
+ return false;
+
+ // If this was created from an ICC profile, retrieve that exact profile.
+ ICCProfile result;
+ if (ICCProfile::FromId(icc_profile_id_, false, icc_profile))
+ return true;
+
+ // Otherwise, construct an ICC profile based on the best approximated
+ // primaries and matrix.
+ SkMatrix44 to_XYZD50_matrix;
+ GetPrimaryMatrix(&to_XYZD50_matrix);
+ SkColorSpaceTransferFn fn;
+ if (!GetTransferFunction(&fn)) {
+ DLOG(ERROR) << "Failed to get ColorSpace transfer function for ICCProfile.";
+ return false;
+ }
+ sk_sp<SkData> data = SkICC::WriteToICC(fn, to_XYZD50_matrix);
+ if (!data) {
+ DLOG(ERROR) << "Failed to create SkICC.";
+ return false;
+ }
+ *icc_profile = ICCProfile::FromData(data->data(), data->size());
+ DCHECK(icc_profile->IsValid());
+ return true;
+}
+
void ColorSpace::GetPrimaryMatrix(SkMatrix44* to_XYZD50) const {
SkColorSpacePrimaries primaries = {0};
switch (primaries_) {
« no previous file with comments | « ui/gfx/color_space.h ('k') | ui/gfx/color_transform.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698