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

Side by Side Diff: ui/gfx/color_space.cc

Issue 2652503002: Use SkICC in gfx::ICCProfile and gfx::ColorSpace (Closed)
Patch Set: Clean up negatives Created 3 years, 11 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
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"
(...skipping 23 matching lines...) Expand all
34 ColorSpace::MatrixID ColorSpace::MatrixIDFromInt(int matrix_id) { 34 ColorSpace::MatrixID ColorSpace::MatrixIDFromInt(int matrix_id) {
35 if (matrix_id < 0 || matrix_id > static_cast<int>(MatrixID::LAST)) 35 if (matrix_id < 0 || matrix_id > static_cast<int>(MatrixID::LAST))
36 return MatrixID::UNKNOWN; 36 return MatrixID::UNKNOWN;
37 if (matrix_id > static_cast<int>(MatrixID::LAST_STANDARD_VALUE) && 37 if (matrix_id > static_cast<int>(MatrixID::LAST_STANDARD_VALUE) &&
38 matrix_id < 1000) 38 matrix_id < 1000)
39 return MatrixID::UNKNOWN; 39 return MatrixID::UNKNOWN;
40 return static_cast<MatrixID>(matrix_id); 40 return static_cast<MatrixID>(matrix_id);
41 } 41 }
42 42
43 ColorSpace::ColorSpace() { 43 ColorSpace::ColorSpace() {
44 memset(custom_transfer_params_, 0, sizeof(custom_transfer_params_));
44 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); 45 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_));
45 } 46 }
46 47
47 ColorSpace::ColorSpace(PrimaryID primaries, 48 ColorSpace::ColorSpace(PrimaryID primaries,
48 TransferID transfer, 49 TransferID transfer,
49 MatrixID matrix, 50 MatrixID matrix,
50 RangeID range) 51 RangeID range)
51 : primaries_(primaries), 52 : primaries_(primaries),
52 transfer_(transfer), 53 transfer_(transfer),
53 matrix_(matrix), 54 matrix_(matrix),
54 range_(range) { 55 range_(range) {
56 memset(custom_transfer_params_, 0, sizeof(custom_transfer_params_));
55 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); 57 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_));
56 // TODO: Set profile_id_
57 } 58 }
58 59
59 ColorSpace::ColorSpace(int primaries, int transfer, int matrix, RangeID range) 60 ColorSpace::ColorSpace(int primaries, int transfer, int matrix, RangeID range)
60 : primaries_(PrimaryIDFromInt(primaries)), 61 : primaries_(PrimaryIDFromInt(primaries)),
61 transfer_(TransferIDFromInt(transfer)), 62 transfer_(TransferIDFromInt(transfer)),
62 matrix_(MatrixIDFromInt(matrix)), 63 matrix_(MatrixIDFromInt(matrix)),
63 range_(range) { 64 range_(range) {
65 memset(custom_transfer_params_, 0, sizeof(custom_transfer_params_));
64 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); 66 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_));
65 // TODO: Set profile_id_
66 } 67 }
67 68
68 ColorSpace::ColorSpace(const ColorSpace& other) 69 ColorSpace::ColorSpace(const ColorSpace& other)
69 : primaries_(other.primaries_), 70 : primaries_(other.primaries_),
70 transfer_(other.transfer_), 71 transfer_(other.transfer_),
71 matrix_(other.matrix_), 72 matrix_(other.matrix_),
72 range_(other.range_), 73 range_(other.range_),
73 icc_profile_id_(other.icc_profile_id_), 74 icc_profile_id_(other.icc_profile_id_),
74 sk_color_space_(other.sk_color_space_) { 75 sk_color_space_(other.sk_color_space_) {
76 memcpy(custom_transfer_params_, other.custom_transfer_params_,
77 sizeof(custom_transfer_params_));
75 memcpy(custom_primary_matrix_, other.custom_primary_matrix_, 78 memcpy(custom_primary_matrix_, other.custom_primary_matrix_,
76 sizeof(custom_primary_matrix_)); 79 sizeof(custom_primary_matrix_));
77 } 80 }
78 81
79 ColorSpace::~ColorSpace() = default; 82 ColorSpace::~ColorSpace() = default;
80 83
81 // static 84 // static
82 ColorSpace ColorSpace::CreateSRGB() { 85 ColorSpace ColorSpace::CreateSRGB() {
83 ColorSpace result(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, 86 ColorSpace result(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB,
84 RangeID::FULL); 87 RangeID::FULL);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 120 }
118 121
119 bool ColorSpace::operator==(const ColorSpace& other) const { 122 bool ColorSpace::operator==(const ColorSpace& other) const {
120 if (primaries_ != other.primaries_ || transfer_ != other.transfer_ || 123 if (primaries_ != other.primaries_ || transfer_ != other.transfer_ ||
121 matrix_ != other.matrix_ || range_ != other.range_) 124 matrix_ != other.matrix_ || range_ != other.range_)
122 return false; 125 return false;
123 if (primaries_ == PrimaryID::CUSTOM && 126 if (primaries_ == PrimaryID::CUSTOM &&
124 memcmp(custom_primary_matrix_, other.custom_primary_matrix_, 127 memcmp(custom_primary_matrix_, other.custom_primary_matrix_,
125 sizeof(custom_primary_matrix_))) 128 sizeof(custom_primary_matrix_)))
126 return false; 129 return false;
130 if (transfer_ == TransferID::CUSTOM &&
131 memcmp(custom_transfer_params_, other.custom_transfer_params_,
132 sizeof(custom_transfer_params_)))
133 return false;
127 return true; 134 return true;
128 } 135 }
129 136
130 bool ColorSpace::IsHDR() const { 137 bool ColorSpace::IsHDR() const {
131 return transfer_ == TransferID::SMPTEST2084 || 138 return transfer_ == TransferID::SMPTEST2084 ||
132 transfer_ == TransferID::ARIB_STD_B67; 139 transfer_ == TransferID::ARIB_STD_B67;
133 } 140 }
134 141
135 bool ColorSpace::operator!=(const ColorSpace& other) const { 142 bool ColorSpace::operator!=(const ColorSpace& other) const {
136 return !(*this == other); 143 return !(*this == other);
(...skipping 18 matching lines...) Expand all
155 return false; 162 return false;
156 if (primaries_ == PrimaryID::CUSTOM) { 163 if (primaries_ == PrimaryID::CUSTOM) {
157 int primary_result = 164 int primary_result =
158 memcmp(custom_primary_matrix_, other.custom_primary_matrix_, 165 memcmp(custom_primary_matrix_, other.custom_primary_matrix_,
159 sizeof(custom_primary_matrix_)); 166 sizeof(custom_primary_matrix_));
160 if (primary_result < 0) 167 if (primary_result < 0)
161 return true; 168 return true;
162 if (primary_result > 0) 169 if (primary_result > 0)
163 return false; 170 return false;
164 } 171 }
172 if (transfer_ == TransferID::CUSTOM) {
173 int transfer_result =
174 memcmp(custom_transfer_params_, other.custom_transfer_params_,
175 sizeof(custom_transfer_params_));
176 if (transfer_result < 0)
177 return true;
178 if (transfer_result > 0)
179 return false;
180 }
165 return false; 181 return false;
166 } 182 }
167 183
168 ColorSpace ColorSpace::FromSkColorSpace( 184 ColorSpace ColorSpace::FromSkColorSpace(
169 const sk_sp<SkColorSpace>& sk_color_space) { 185 const sk_sp<SkColorSpace>& sk_color_space) {
170 if (!sk_color_space) 186 if (!sk_color_space)
171 return gfx::ColorSpace(); 187 return gfx::ColorSpace();
172 if (SkColorSpace::Equals( 188 if (SkColorSpace::Equals(
173 sk_color_space.get(), 189 sk_color_space.get(),
174 SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get())) 190 SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get()))
175 return gfx::ColorSpace::CreateSRGB(); 191 return gfx::ColorSpace::CreateSRGB();
176 192
177 // TODO(crbug.com/634102): Add conversion to gfx::ColorSpace for 193 // TODO(crbug.com/634102): Add conversion to gfx::ColorSpace for
178 // non-ICC-profile based color spaces. 194 // non-ICC-profile based color spaces.
179 ICCProfile icc_profile = ICCProfile::FromSkColorSpace(sk_color_space); 195 ICCProfile icc_profile = ICCProfile::FromSkColorSpace(sk_color_space);
180 return icc_profile.GetColorSpace(); 196 return icc_profile.GetColorSpace();
181 } 197 }
182 198
199 bool ColorSpace::GetPrimaryMatrix(SkMatrix44* to_XYZD50) const {
200 if (primaries_ == PrimaryID::CUSTOM) {
201 to_XYZD50->set3x3RowMajorf(custom_primary_matrix_);
202 return true;
203 }
204 // TODO(ccameron): Merge with primary look-up in ColorTransform.
205 return false;
206 }
207
208 bool ColorSpace::GetTransferFunction(SkColorSpaceTransferFn* fn) const {
209 if (transfer_ == TransferID::CUSTOM) {
210 fn->fA = custom_transfer_params_[0];
211 fn->fB = custom_transfer_params_[1];
212 fn->fC = custom_transfer_params_[2];
213 fn->fD = custom_transfer_params_[3];
214 fn->fE = custom_transfer_params_[4];
215 fn->fF = custom_transfer_params_[5];
216 fn->fG = custom_transfer_params_[6];
217 return true;
218 }
219 // TODO(ccameron): Add transfer look-up for non-CUSTOM transfer functions.
220 return false;
221 }
222
183 } // namespace gfx 223 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/color_space.h ('k') | ui/gfx/color_transform.cc » ('j') | ui/gfx/icc_profile.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698