| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return MatrixID::UNKNOWN; | 56 return MatrixID::UNKNOWN; |
| 57 if (matrix_id > static_cast<int>(MatrixID::LAST_STANDARD_VALUE) && | 57 if (matrix_id > static_cast<int>(MatrixID::LAST_STANDARD_VALUE) && |
| 58 matrix_id < 1000) | 58 matrix_id < 1000) |
| 59 return MatrixID::UNKNOWN; | 59 return MatrixID::UNKNOWN; |
| 60 return static_cast<MatrixID>(matrix_id); | 60 return static_cast<MatrixID>(matrix_id); |
| 61 } | 61 } |
| 62 | 62 |
| 63 ColorSpace::ColorSpace() {} | 63 ColorSpace::ColorSpace() {} |
| 64 | 64 |
| 65 ColorSpace::ColorSpace(PrimaryID primaries, | 65 ColorSpace::ColorSpace(PrimaryID primaries, |
| 66 TransferID transfer) |
| 67 : primaries_(primaries), |
| 68 transfer_(transfer), |
| 69 matrix_(MatrixID::RGB), |
| 70 range_(RangeID::FULL) {} |
| 71 |
| 72 ColorSpace::ColorSpace(PrimaryID primaries, |
| 66 TransferID transfer, | 73 TransferID transfer, |
| 67 MatrixID matrix, | 74 MatrixID matrix, |
| 68 RangeID range) | 75 RangeID range) |
| 69 : primaries_(primaries), | 76 : primaries_(primaries), |
| 70 transfer_(transfer), | 77 transfer_(transfer), |
| 71 matrix_(matrix), | 78 matrix_(matrix), |
| 72 range_(range) {} | 79 range_(range) {} |
| 73 | 80 |
| 74 ColorSpace::ColorSpace(int primaries, int transfer, int matrix, RangeID range) | 81 ColorSpace::ColorSpace(int primaries, int transfer, int matrix, RangeID range) |
| 75 : primaries_(PrimaryIDFromInt(primaries)), | 82 : primaries_(PrimaryIDFromInt(primaries)), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 89 sizeof(custom_transfer_params_)); | 96 sizeof(custom_transfer_params_)); |
| 90 } | 97 } |
| 91 if (primaries_ == PrimaryID::CUSTOM) { | 98 if (primaries_ == PrimaryID::CUSTOM) { |
| 92 memcpy(custom_primary_matrix_, other.custom_primary_matrix_, | 99 memcpy(custom_primary_matrix_, other.custom_primary_matrix_, |
| 93 sizeof(custom_primary_matrix_)); | 100 sizeof(custom_primary_matrix_)); |
| 94 } | 101 } |
| 95 } | 102 } |
| 96 | 103 |
| 97 ColorSpace::~ColorSpace() = default; | 104 ColorSpace::~ColorSpace() = default; |
| 98 | 105 |
| 106 bool ColorSpace::IsValid() const { |
| 107 return (*this != gfx::ColorSpace()); |
| 108 } |
| 109 |
| 99 // static | 110 // static |
| 100 ColorSpace ColorSpace::CreateSRGB() { | 111 ColorSpace ColorSpace::CreateSRGB() { |
| 101 return ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, | 112 return ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1, MatrixID::RGB, |
| 102 RangeID::FULL); | 113 RangeID::FULL); |
| 103 } | 114 } |
| 104 | 115 |
| 105 // static | 116 // static |
| 106 ColorSpace ColorSpace::CreateSCRGBLinear() { | 117 ColorSpace ColorSpace::CreateSCRGBLinear() { |
| 107 return ColorSpace(PrimaryID::BT709, TransferID::LINEAR_HDR, MatrixID::RGB, | 118 return ColorSpace(PrimaryID::BT709, TransferID::LINEAR_HDR, MatrixID::RGB, |
| 108 RangeID::FULL); | 119 RangeID::FULL); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 251 |
| 241 // Use the parametric transfer function if no other option is available. | 252 // Use the parametric transfer function if no other option is available. |
| 242 SkColorSpaceTransferFn fn; | 253 SkColorSpaceTransferFn fn; |
| 243 if (!GetTransferFunction(&fn)) { | 254 if (!GetTransferFunction(&fn)) { |
| 244 DLOG(ERROR) << "Failed to parameterize transfer function for SkColorSpace"; | 255 DLOG(ERROR) << "Failed to parameterize transfer function for SkColorSpace"; |
| 245 return nullptr; | 256 return nullptr; |
| 246 } | 257 } |
| 247 return SkColorSpace::MakeRGB(fn, to_xyz_d50); | 258 return SkColorSpace::MakeRGB(fn, to_xyz_d50); |
| 248 } | 259 } |
| 249 | 260 |
| 250 ColorSpace ColorSpace::FromSkColorSpace( | |
| 251 const sk_sp<SkColorSpace>& sk_color_space) { | |
| 252 if (!sk_color_space) | |
| 253 return gfx::ColorSpace(); | |
| 254 if (SkColorSpace::Equals( | |
| 255 sk_color_space.get(), | |
| 256 SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get())) | |
| 257 return gfx::ColorSpace::CreateSRGB(); | |
| 258 | |
| 259 // TODO(crbug.com/634102): Add conversion to gfx::ColorSpace for | |
| 260 // non-ICC-profile based color spaces. | |
| 261 ICCProfile icc_profile = ICCProfile::FromSkColorSpace(sk_color_space); | |
| 262 return icc_profile.GetColorSpace(); | |
| 263 } | |
| 264 | |
| 265 void ColorSpace::GetPrimaryMatrix(SkMatrix44* to_XYZD50) const { | 261 void ColorSpace::GetPrimaryMatrix(SkMatrix44* to_XYZD50) const { |
| 266 SkColorSpacePrimaries primaries = {0}; | 262 SkColorSpacePrimaries primaries = {0}; |
| 267 switch (primaries_) { | 263 switch (primaries_) { |
| 268 case ColorSpace::PrimaryID::CUSTOM: | 264 case ColorSpace::PrimaryID::CUSTOM: |
| 269 to_XYZD50->set3x3RowMajorf(custom_primary_matrix_); | 265 to_XYZD50->set3x3RowMajorf(custom_primary_matrix_); |
| 270 return; | 266 return; |
| 271 | 267 |
| 272 case ColorSpace::PrimaryID::RESERVED0: | 268 case ColorSpace::PrimaryID::RESERVED0: |
| 273 case ColorSpace::PrimaryID::RESERVED: | 269 case ColorSpace::PrimaryID::RESERVED: |
| 274 case ColorSpace::PrimaryID::UNSPECIFIED: | 270 case ColorSpace::PrimaryID::UNSPECIFIED: |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 case ColorSpace::PrimaryID::XYZ_D50: | 376 case ColorSpace::PrimaryID::XYZ_D50: |
| 381 primaries.fRX = 1.0f; | 377 primaries.fRX = 1.0f; |
| 382 primaries.fRY = 0.0f; | 378 primaries.fRY = 0.0f; |
| 383 primaries.fGX = 0.0f; | 379 primaries.fGX = 0.0f; |
| 384 primaries.fGY = 1.0f; | 380 primaries.fGY = 1.0f; |
| 385 primaries.fBX = 0.0f; | 381 primaries.fBX = 0.0f; |
| 386 primaries.fBY = 0.0f; | 382 primaries.fBY = 0.0f; |
| 387 primaries.fWX = 0.34567f; | 383 primaries.fWX = 0.34567f; |
| 388 primaries.fWY = 0.35850f; | 384 primaries.fWY = 0.35850f; |
| 389 break; | 385 break; |
| 386 |
| 387 case ColorSpace::PrimaryID::ADOBE_RGB: |
| 388 primaries.fRX = 0.6400f; |
| 389 primaries.fRY = 0.3300f; |
| 390 primaries.fGX = 0.2100f; |
| 391 primaries.fGY = 0.7100f; |
| 392 primaries.fBX = 0.1500f; |
| 393 primaries.fBY = 0.0600f; |
| 394 primaries.fWX = 0.3127f; |
| 395 primaries.fWY = 0.3290f; |
| 396 break; |
| 390 } | 397 } |
| 391 primaries.toXYZD50(to_XYZD50); | 398 primaries.toXYZD50(to_XYZD50); |
| 392 } | 399 } |
| 393 | 400 |
| 394 bool ColorSpace::GetTransferFunction(SkColorSpaceTransferFn* fn) const { | 401 bool ColorSpace::GetTransferFunction(SkColorSpaceTransferFn* fn) const { |
| 395 // Default to F(x) = pow(x, 1) | 402 // Default to F(x) = pow(x, 1) |
| 396 fn->fA = 1; | 403 fn->fA = 1; |
| 397 fn->fB = 0; | 404 fn->fB = 0; |
| 398 fn->fC = 1; | 405 fn->fC = 1; |
| 399 fn->fD = 0; | 406 fn->fD = 0; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 } | 481 } |
| 475 | 482 |
| 476 bool ColorSpace::GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const { | 483 bool ColorSpace::GetInverseTransferFunction(SkColorSpaceTransferFn* fn) const { |
| 477 if (!GetTransferFunction(fn)) | 484 if (!GetTransferFunction(fn)) |
| 478 return false; | 485 return false; |
| 479 *fn = InvertTransferFn(*fn); | 486 *fn = InvertTransferFn(*fn); |
| 480 return true; | 487 return true; |
| 481 } | 488 } |
| 482 | 489 |
| 483 } // namespace gfx | 490 } // namespace gfx |
| OLD | NEW |