| 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 360 |
| 361 // Use the parametric transfer function if no other option is available. | 361 // Use the parametric transfer function if no other option is available. |
| 362 SkColorSpaceTransferFn fn; | 362 SkColorSpaceTransferFn fn; |
| 363 if (!GetTransferFunction(&fn)) { | 363 if (!GetTransferFunction(&fn)) { |
| 364 DLOG(ERROR) << "Failed to parameterize transfer function for SkColorSpace"; | 364 DLOG(ERROR) << "Failed to parameterize transfer function for SkColorSpace"; |
| 365 return nullptr; | 365 return nullptr; |
| 366 } | 366 } |
| 367 return SkColorSpace::MakeRGB(fn, to_xyz_d50); | 367 return SkColorSpace::MakeRGB(fn, to_xyz_d50); |
| 368 } | 368 } |
| 369 | 369 |
| 370 sk_sp<SkColorSpace> ColorSpace::ToNonlinearBlendedSkColorSpace() const { |
| 371 if (!IsValid()) { |
| 372 DLOG(ERROR) << "Cannot create SkColorSpace for invalid space."; |
| 373 return nullptr; |
| 374 } |
| 375 if (matrix_ != MatrixID::RGB) { |
| 376 DLOG(ERROR) << "Not creating non-RGB SkColorSpace"; |
| 377 return nullptr; |
| 378 } |
| 379 if (range_ != RangeID::FULL) { |
| 380 DLOG(ERROR) << "Not creating non-full-range SkColorSpace"; |
| 381 return nullptr; |
| 382 } |
| 383 |
| 384 SkMatrix44 primaries; |
| 385 GetPrimaryMatrix(&primaries); |
| 386 SkColorSpaceTransferFn tr_fn; |
| 387 bool get_tr_fn_result = GetTransferFunction(&tr_fn); |
| 388 if (!get_tr_fn_result) { |
| 389 DLOG(ERROR) << "Failed to parameterize transfer function for SkColorSpace"; |
| 390 CreateSRGB().GetTransferFunction(&tr_fn); |
| 391 } |
| 392 sk_sp<SkColorSpace> result = SkColorSpace::MakeRGB( |
| 393 tr_fn, primaries, SkColorSpace::kNonLinearBlending_ColorSpaceFlag); |
| 394 if (!result) { |
| 395 DLOG(ERROR) << "Failed to create nonlinearly blended SkColorSpace"; |
| 396 CreateSRGB().GetTransferFunction(&tr_fn); |
| 397 } |
| 398 return result; |
| 399 } |
| 400 |
| 370 bool ColorSpace::GetICCProfile(ICCProfile* icc_profile) const { | 401 bool ColorSpace::GetICCProfile(ICCProfile* icc_profile) const { |
| 371 if (!IsValid()) | 402 if (!IsValid()) |
| 372 return false; | 403 return false; |
| 373 | 404 |
| 374 // If this was created from an ICC profile, retrieve that exact profile. | 405 // If this was created from an ICC profile, retrieve that exact profile. |
| 375 ICCProfile result; | 406 ICCProfile result; |
| 376 if (ICCProfile::FromId(icc_profile_id_, false, icc_profile)) | 407 if (ICCProfile::FromId(icc_profile_id_, false, icc_profile)) |
| 377 return true; | 408 return true; |
| 378 | 409 |
| 379 // Otherwise, construct an ICC profile based on the best approximated | 410 // Otherwise, construct an ICC profile based on the best approximated |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 case MatrixID::BT2020_NCL: | 764 case MatrixID::BT2020_NCL: |
| 734 case MatrixID::BT2020_CL: | 765 case MatrixID::BT2020_CL: |
| 735 case MatrixID::YDZDX: | 766 case MatrixID::YDZDX: |
| 736 matrix->setScale(255.0f/219.0f, 255.0f/224.0f, 255.0f/224.0f); | 767 matrix->setScale(255.0f/219.0f, 255.0f/224.0f, 255.0f/224.0f); |
| 737 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); | 768 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); |
| 738 break; | 769 break; |
| 739 } | 770 } |
| 740 } | 771 } |
| 741 | 772 |
| 742 } // namespace gfx | 773 } // namespace gfx |
| OLD | NEW |