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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/gfx/color_space.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/color_space.h" 5 #include "ui/gfx/color_space.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "third_party/skia/include/core/SkColorSpace.h"
11 #include "ui/gfx/icc_profile.h" 12 #include "ui/gfx/icc_profile.h"
12 13
13 namespace gfx { 14 namespace gfx {
14 15
15 ColorSpace::ColorSpace() { 16 ColorSpace::ColorSpace() {
16 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); 17 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_));
17 } 18 }
18 19
19 ColorSpace::ColorSpace(PrimaryID primaries, 20 ColorSpace::ColorSpace(PrimaryID primaries,
20 TransferID transfer, 21 TransferID transfer,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 MatrixID::SMPTE170M, RangeID::LIMITED); 53 MatrixID::SMPTE170M, RangeID::LIMITED);
53 } 54 }
54 55
55 // static 56 // static
56 ColorSpace ColorSpace::CreateREC709() { 57 ColorSpace ColorSpace::CreateREC709() {
57 return ColorSpace(PrimaryID::BT709, TransferID::BT709, MatrixID::BT709, 58 return ColorSpace(PrimaryID::BT709, TransferID::BT709, MatrixID::BT709,
58 RangeID::LIMITED); 59 RangeID::LIMITED);
59 } 60 }
60 61
61 bool ColorSpace::operator==(const ColorSpace& other) const { 62 bool ColorSpace::operator==(const ColorSpace& other) const {
62 return primaries_ == other.primaries_ && transfer_ == other.transfer_ && 63 if (primaries_ != other.primaries_ || transfer_ != other.transfer_ ||
63 matrix_ == other.matrix_ && range_ == other.range_; 64 matrix_ != other.matrix_ || range_ != other.range_)
65 return false;
66 if (primaries_ == PrimaryID::CUSTOM &&
67 memcmp(custom_primary_matrix_, other.custom_primary_matrix_,
68 sizeof(custom_primary_matrix_)))
69 return false;
70 return true;
64 } 71 }
65 72
66 bool ColorSpace::operator!=(const ColorSpace& other) const { 73 bool ColorSpace::operator!=(const ColorSpace& other) const {
67 return !(*this == other); 74 return !(*this == other);
68 } 75 }
69 76
70 bool ColorSpace::operator<(const ColorSpace& other) const { 77 bool ColorSpace::operator<(const ColorSpace& other) const {
71 if (primaries_ < other.primaries_) 78 if (primaries_ < other.primaries_)
72 return true; 79 return true;
73 if (primaries_ > other.primaries_) 80 if (primaries_ > other.primaries_)
74 return false; 81 return false;
75 if (transfer_ < other.transfer_) 82 if (transfer_ < other.transfer_)
76 return true; 83 return true;
77 if (transfer_ > other.transfer_) 84 if (transfer_ > other.transfer_)
78 return false; 85 return false;
79 if (matrix_ < other.matrix_) 86 if (matrix_ < other.matrix_)
80 return true; 87 return true;
81 if (matrix_ > other.matrix_) 88 if (matrix_ > other.matrix_)
82 return false; 89 return false;
83 if (range_ < other.range_) 90 if (range_ < other.range_)
84 return true; 91 return true;
85 if (range_ > other.range_) 92 if (range_ > other.range_)
86 return true; 93 return false;
87 94 if (primaries_ == PrimaryID::CUSTOM) {
88 // TODO(hubbe): For "CUSTOM" primaries or tranfer functions, compare their 95 int primary_result =
89 // coefficients here 96 memcmp(custom_primary_matrix_, other.custom_primary_matrix_,
90 97 sizeof(custom_primary_matrix_));
98 if (primary_result < 0)
99 return true;
100 if (primary_result > 0)
101 return false;
102 }
91 return false; 103 return false;
92 } 104 }
93 105
106 sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const {
107 // Unspecified color spaces are represented as nullptr SkColorSpaces.
108 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
109 return nullptr;
110
111 // TODO(crbug.com/634102): Support more than just ICC profile based color
112 // spaces. The DCHECK here is to ensure that callers that expect a valid
113 // result are notified of this incomplete functionality.
114 std::vector<char> icc_data = gfx::ICCProfile::FromColorSpace(*this).GetData();
115 sk_sp<SkColorSpace> result =
116 SkColorSpace::NewICC(icc_data.data(), icc_data.size());
117 DCHECK(result);
118 return result;
119 }
120
94 } // namespace gfx 121 } // namespace gfx
OLDNEW
« 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