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

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

Issue 2826513002: color: Use named gamuts in ToSkColorSpace (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | ui/gfx/color_space_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <sstream> 8 #include <sstream>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 420 }
421 421
422 // Use the named SRGB and linear-SRGB instead of the generic constructors. 422 // Use the named SRGB and linear-SRGB instead of the generic constructors.
423 if (primaries_ == PrimaryID::BT709) { 423 if (primaries_ == PrimaryID::BT709) {
424 if (transfer_ == TransferID::IEC61966_2_1) 424 if (transfer_ == TransferID::IEC61966_2_1)
425 return SkColorSpace::MakeSRGB(); 425 return SkColorSpace::MakeSRGB();
426 if (transfer_ == TransferID::LINEAR || transfer_ == TransferID::LINEAR_HDR) 426 if (transfer_ == TransferID::LINEAR || transfer_ == TransferID::LINEAR_HDR)
427 return SkColorSpace::MakeSRGBLinear(); 427 return SkColorSpace::MakeSRGBLinear();
428 } 428 }
429 429
430 // Prefer to used the named gamma and gamut, if possible.
431 bool has_named_gamma = true;
432 SkColorSpace::RenderTargetGamma named_gamma =
433 SkColorSpace::kSRGB_RenderTargetGamma;
434 switch (transfer_) {
435 case TransferID::IEC61966_2_1:
436 break;
437 case TransferID::LINEAR:
438 case TransferID::LINEAR_HDR:
439 named_gamma = SkColorSpace::kLinear_RenderTargetGamma;
440 break;
441 default:
442 has_named_gamma = false;
443 break;
444 }
445 bool has_named_gamut = true;
446 SkColorSpace::Gamut named_gamut = SkColorSpace::kSRGB_Gamut;
447 switch (primaries_) {
448 case PrimaryID::BT709:
449 break;
450 case PrimaryID::ADOBE_RGB:
451 named_gamut = SkColorSpace::kAdobeRGB_Gamut;
452 break;
453 case PrimaryID::SMPTEST432_1:
454 named_gamut = SkColorSpace::kDCIP3_D65_Gamut;
455 break;
456 case PrimaryID::BT2020:
457 named_gamut = SkColorSpace::kRec2020_Gamut;
458 break;
459 default:
460 has_named_gamut = false;
461 break;
462 }
463 if (has_named_gamut && has_named_gamma)
464 return SkColorSpace::MakeRGB(named_gamma, named_gamut);
465
466 // Use named gamma with custom primaries, if possible.
430 SkMatrix44 to_xyz_d50; 467 SkMatrix44 to_xyz_d50;
431 GetPrimaryMatrix(&to_xyz_d50); 468 GetPrimaryMatrix(&to_xyz_d50);
432 469 if (has_named_gamma)
433 // Use the named sRGB and linear transfer functions. 470 return SkColorSpace::MakeRGB(named_gamma, to_xyz_d50);
msarett1 2017/04/17 21:30:43 Is there ever a case where has_named_gamut is true
ccameron 2017/04/17 23:08:05 Good point -- added that case.
434 if (transfer_ == TransferID::IEC61966_2_1) {
435 return SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
436 to_xyz_d50);
437 }
438 if (transfer_ == TransferID::LINEAR || transfer_ == TransferID::LINEAR_HDR) {
439 return SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma,
440 to_xyz_d50);
441 }
442 471
443 // Use the parametric transfer function if no other option is available. 472 // Use the parametric transfer function if no other option is available.
444 SkColorSpaceTransferFn fn; 473 SkColorSpaceTransferFn fn;
445 if (!GetTransferFunction(&fn)) { 474 if (!GetTransferFunction(&fn)) {
446 DLOG(ERROR) << "Failed to parameterize transfer function for SkColorSpace"; 475 DLOG(ERROR) << "Failed to parameterize transfer function for SkColorSpace";
447 return nullptr; 476 return nullptr;
448 } 477 }
449 return SkColorSpace::MakeRGB(fn, to_xyz_d50); 478 return SkColorSpace::MakeRGB(fn, to_xyz_d50);
450 } 479 }
451 480
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f); 866 matrix->postTranslate(-16.0f/219.0f, -15.5f/224.0f, -15.5f/224.0f);
838 break; 867 break;
839 } 868 }
840 } 869 }
841 870
842 std::ostream& operator<<(std::ostream& out, const ColorSpace& color_space) { 871 std::ostream& operator<<(std::ostream& out, const ColorSpace& color_space) {
843 return out << color_space.ToString(); 872 return out << color_space.ToString();
844 } 873 }
845 874
846 } // namespace gfx 875 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/color_space_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698