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

Unified Diff: ui/gfx/color_space.cc

Issue 2351823002: cc: Add conversion between gfx::ColorSpace and SkColorSpace (Closed)
Patch Set: Add warnings Created 4 years, 3 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') | no next file » | 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 8bb9bddca8882614957505d47eceb70e18d15af9..b64e1aed0539dadb07db55dd6cb26c86fbfa3e98 100644
--- a/ui/gfx/color_space.cc
+++ b/ui/gfx/color_space.cc
@@ -8,6 +8,7 @@
#include "base/lazy_instance.h"
#include "base/synchronization/lock.h"
+#include "third_party/skia/include/core/SkColorSpace.h"
#include "ui/gfx/icc_profile.h"
namespace gfx {
@@ -59,8 +60,14 @@ ColorSpace ColorSpace::CreateREC709() {
}
bool ColorSpace::operator==(const ColorSpace& other) const {
- return primaries_ == other.primaries_ && transfer_ == other.transfer_ &&
- matrix_ == other.matrix_ && range_ == other.range_;
+ if (primaries_ != other.primaries_ || transfer_ != other.transfer_ ||
+ matrix_ != other.matrix_ || range_ != other.range_)
+ return false;
+ if (primaries_ == PrimaryID::CUSTOM &&
+ memcmp(custom_primary_matrix_, other.custom_primary_matrix_,
+ sizeof(custom_primary_matrix_)))
+ return false;
+ return true;
}
bool ColorSpace::operator!=(const ColorSpace& other) const {
@@ -83,12 +90,32 @@ bool ColorSpace::operator<(const ColorSpace& other) const {
if (range_ < other.range_)
return true;
if (range_ > other.range_)
- return true;
-
- // TODO(hubbe): For "CUSTOM" primaries or tranfer functions, compare their
- // coefficients here
-
+ return false;
+ if (primaries_ == PrimaryID::CUSTOM) {
+ int primary_result =
+ memcmp(custom_primary_matrix_, other.custom_primary_matrix_,
+ sizeof(custom_primary_matrix_));
+ if (primary_result < 0)
+ return true;
+ if (primary_result > 0)
+ return false;
+ }
return false;
}
+sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const {
+ // Unspecified color spaces are represented as nullptr SkColorSpaces.
+ if (*this == gfx::ColorSpace())
Justin Novosad 2016/09/20 19:09:50 Just checking... in skia, unspecified colorspace m
ccameron 2016/09/20 19:12:07 Yes. The default ctor for gfx::ColorSpace also mea
+ return nullptr;
+
+ // TODO(crbug.com/634102): Support more than just ICC profile based color
+ // spaces. The DCHECK here is to ensure that callers that expect a valid
+ // result are notified of this incomplete functionality.
+ std::vector<char> icc_data = gfx::ICCProfile::FromColorSpace(*this).GetData();
+ sk_sp<SkColorSpace> result =
+ SkColorSpace::NewICC(icc_data.data(), icc_data.size());
+ DCHECK(result);
+ return result;
+}
+
} // namespace gfx
« no previous file with comments | « ui/gfx/color_space.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698