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