OLD | NEW |
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 ColorSpace::ColorSpace(int primaries, int transfer, int matrix, RangeID range) | 59 ColorSpace::ColorSpace(int primaries, int transfer, int matrix, RangeID range) |
60 : primaries_(PrimaryIDFromInt(primaries)), | 60 : primaries_(PrimaryIDFromInt(primaries)), |
61 transfer_(TransferIDFromInt(transfer)), | 61 transfer_(TransferIDFromInt(transfer)), |
62 matrix_(MatrixIDFromInt(matrix)), | 62 matrix_(MatrixIDFromInt(matrix)), |
63 range_(range) { | 63 range_(range) { |
64 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); | 64 memset(custom_primary_matrix_, 0, sizeof(custom_primary_matrix_)); |
65 // TODO: Set profile_id_ | 65 // TODO: Set profile_id_ |
66 } | 66 } |
67 | 67 |
| 68 ColorSpace::ColorSpace(const ColorSpace& other) |
| 69 : primaries_(other.primaries_), |
| 70 transfer_(other.transfer_), |
| 71 matrix_(other.matrix_), |
| 72 range_(other.range_), |
| 73 icc_profile_id_(other.icc_profile_id_), |
| 74 sk_color_space_(other.sk_color_space_) { |
| 75 memcpy(custom_primary_matrix_, other.custom_primary_matrix_, |
| 76 sizeof(custom_primary_matrix_)); |
| 77 } |
| 78 |
| 79 ColorSpace::~ColorSpace() = default; |
| 80 |
68 // static | 81 // static |
69 ColorSpace ColorSpace::CreateSRGB() { | 82 ColorSpace ColorSpace::CreateSRGB() { |
70 return ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, | 83 ColorSpace result(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, |
71 RangeID::FULL); | 84 RangeID::FULL); |
| 85 result.sk_color_space_ = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
| 86 return result; |
72 } | 87 } |
73 | 88 |
74 // Static | 89 // Static |
75 ColorSpace ColorSpace::CreateXYZD50() { | 90 ColorSpace ColorSpace::CreateXYZD50() { |
76 return ColorSpace(PrimaryID::XYZ_D50, TransferID::LINEAR, MatrixID::RGB, | 91 return ColorSpace(PrimaryID::XYZ_D50, TransferID::LINEAR, MatrixID::RGB, |
77 RangeID::FULL); | 92 RangeID::FULL); |
78 } | 93 } |
79 | 94 |
80 // static | 95 // static |
81 ColorSpace ColorSpace::CreateJpeg() { | 96 ColorSpace ColorSpace::CreateJpeg() { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 sizeof(custom_primary_matrix_)); | 148 sizeof(custom_primary_matrix_)); |
134 if (primary_result < 0) | 149 if (primary_result < 0) |
135 return true; | 150 return true; |
136 if (primary_result > 0) | 151 if (primary_result > 0) |
137 return false; | 152 return false; |
138 } | 153 } |
139 return false; | 154 return false; |
140 } | 155 } |
141 | 156 |
142 sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const { | 157 sk_sp<SkColorSpace> ColorSpace::ToSkColorSpace() const { |
143 // Unspecified color spaces are represented as nullptr SkColorSpaces. | 158 return sk_color_space_; |
144 if (*this == gfx::ColorSpace()) | |
145 return nullptr; | |
146 if (*this == gfx::ColorSpace::CreateSRGB()) | |
147 return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); | |
148 | |
149 // TODO(crbug.com/634102): Support more than just ICC profile based color | |
150 // spaces. The DCHECK here is to ensure that callers that expect a valid | |
151 // result are notified of this incomplete functionality. | |
152 std::vector<char> icc_data = gfx::ICCProfile::FromColorSpace(*this).GetData(); | |
153 sk_sp<SkColorSpace> result = | |
154 SkColorSpace::MakeICC(icc_data.data(), icc_data.size()); | |
155 DCHECK(result); | |
156 return result; | |
157 } | 159 } |
158 | 160 |
159 ColorSpace ColorSpace::FromSkColorSpace( | 161 ColorSpace ColorSpace::FromSkColorSpace( |
160 const sk_sp<SkColorSpace>& sk_color_space) { | 162 const sk_sp<SkColorSpace>& sk_color_space) { |
161 if (!sk_color_space) | 163 if (!sk_color_space) |
162 return gfx::ColorSpace(); | 164 return gfx::ColorSpace(); |
163 if (SkColorSpace::Equals( | 165 if (SkColorSpace::Equals( |
164 sk_color_space.get(), | 166 sk_color_space.get(), |
165 SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get())) | 167 SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get())) |
166 return gfx::ColorSpace::CreateSRGB(); | 168 return gfx::ColorSpace::CreateSRGB(); |
167 | 169 |
168 // TODO(crbug.com/634102): Add conversion to gfx::ColorSpace. | 170 // TODO(crbug.com/634102): Add conversion to gfx::ColorSpace for |
169 return gfx::ColorSpace(); | 171 // non-ICC-profile based color spaces. |
| 172 ICCProfile icc_profile = ICCProfile::FromSkColorSpace(sk_color_space); |
| 173 return icc_profile.GetColorSpace(); |
170 } | 174 } |
171 | 175 |
172 } // namespace gfx | 176 } // namespace gfx |
OLD | NEW |