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

Side by Side Diff: src/core/SkColorSpace.cpp

Issue 1971203002: Recognize Adobe RGB profiles (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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 | « src/core/SkColorSpace.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkAtomics.h" 8 #include "SkAtomics.h"
9 #include "SkColorSpace.h" 9 #include "SkColorSpace.h"
10 #include "SkOnce.h" 10 #include "SkOnce.h"
(...skipping 25 matching lines...) Expand all
36 , fUniqueID(sk_atomic_inc(&gUniqueColorSpaceID)) 36 , fUniqueID(sk_atomic_inc(&gUniqueColorSpaceID))
37 , fNamed(kUnknown_Named) 37 , fNamed(kUnknown_Named)
38 {} 38 {}
39 39
40 const float gSRGB_toXYZD50[] { 40 const float gSRGB_toXYZD50[] {
41 0.4358f, 0.2224f, 0.0139f, // * R 41 0.4358f, 0.2224f, 0.0139f, // * R
42 0.3853f, 0.7170f, 0.0971f, // * G 42 0.3853f, 0.7170f, 0.0971f, // * G
43 0.1430f, 0.0606f, 0.7139f, // * B 43 0.1430f, 0.0606f, 0.7139f, // * B
44 }; 44 };
45 45
46 const float gAdobeRGB_toXYZD50[] {
47 0.6098f, 0.3111f, 0.0195f, // * R
48 0.2052f, 0.6257f, 0.0609f, // * G
49 0.1492f, 0.0632f, 0.7448f, // * B
50 };
51
52 static bool xyz_almost_equal(const SkMatrix44& toXYZD50, const float* standard) {
herb_g 2016/05/12 17:18:22 Add Comments stating that standard is a 3x3 matrix
msarett 2016/05/12 17:31:52 Done.
53 return color_space_almost_equal(toXYZD50.getFloat(0, 0), standard[0]) &&
54 color_space_almost_equal(toXYZD50.getFloat(0, 1), standard[1]) &&
55 color_space_almost_equal(toXYZD50.getFloat(0, 2), standard[2]) &&
56 color_space_almost_equal(toXYZD50.getFloat(1, 0), standard[3]) &&
57 color_space_almost_equal(toXYZD50.getFloat(1, 1), standard[4]) &&
58 color_space_almost_equal(toXYZD50.getFloat(1, 2), standard[5]) &&
59 color_space_almost_equal(toXYZD50.getFloat(2, 0), standard[6]) &&
60 color_space_almost_equal(toXYZD50.getFloat(2, 1), standard[7]) &&
61 color_space_almost_equal(toXYZD50.getFloat(2, 2), standard[8]) &&
62 color_space_almost_equal(toXYZD50.getFloat(0, 3), 0.0f) &&
63 color_space_almost_equal(toXYZD50.getFloat(1, 3), 0.0f) &&
64 color_space_almost_equal(toXYZD50.getFloat(2, 3), 0.0f) &&
65 color_space_almost_equal(toXYZD50.getFloat(3, 0), 0.0f) &&
66 color_space_almost_equal(toXYZD50.getFloat(3, 1), 0.0f) &&
67 color_space_almost_equal(toXYZD50.getFloat(3, 2), 0.0f) &&
68 color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f);
69 }
70
46 sk_sp<SkColorSpace> SkColorSpace::NewRGB(SkGammas gammas, const SkMatrix44& toXY ZD50) { 71 sk_sp<SkColorSpace> SkColorSpace::NewRGB(SkGammas gammas, const SkMatrix44& toXY ZD50) {
47 // Check if we really have sRGB 72 // Check if we really have sRGB or Adobe RGB
48 if (color_space_almost_equal(2.2f, gammas.fRed.fValue) && 73 if (color_space_almost_equal(2.2f, gammas.fRed.fValue) &&
49 color_space_almost_equal(2.2f, gammas.fGreen.fValue) && 74 color_space_almost_equal(2.2f, gammas.fGreen.fValue) &&
50 color_space_almost_equal(2.2f, gammas.fBlue.fValue) && 75 color_space_almost_equal(2.2f, gammas.fBlue.fValue))
51 color_space_almost_equal(toXYZD50.getFloat(0, 0), gSRGB_toXYZD50[0]) &&
52 color_space_almost_equal(toXYZD50.getFloat(0, 1), gSRGB_toXYZD50[1]) &&
53 color_space_almost_equal(toXYZD50.getFloat(0, 2), gSRGB_toXYZD50[2]) &&
54 color_space_almost_equal(toXYZD50.getFloat(1, 0), gSRGB_toXYZD50[3]) &&
55 color_space_almost_equal(toXYZD50.getFloat(1, 1), gSRGB_toXYZD50[4]) &&
56 color_space_almost_equal(toXYZD50.getFloat(1, 2), gSRGB_toXYZD50[5]) &&
57 color_space_almost_equal(toXYZD50.getFloat(2, 0), gSRGB_toXYZD50[6]) &&
58 color_space_almost_equal(toXYZD50.getFloat(2, 1), gSRGB_toXYZD50[7]) &&
59 color_space_almost_equal(toXYZD50.getFloat(2, 2), gSRGB_toXYZD50[8]) &&
60 color_space_almost_equal(toXYZD50.getFloat(0, 3), 0.0f) &&
61 color_space_almost_equal(toXYZD50.getFloat(1, 3), 0.0f) &&
62 color_space_almost_equal(toXYZD50.getFloat(2, 3), 0.0f) &&
63 color_space_almost_equal(toXYZD50.getFloat(3, 0), 0.0f) &&
64 color_space_almost_equal(toXYZD50.getFloat(3, 1), 0.0f) &&
65 color_space_almost_equal(toXYZD50.getFloat(3, 2), 0.0f) &&
66 color_space_almost_equal(toXYZD50.getFloat(3, 3), 1.0f))
67 { 76 {
68 return SkColorSpace::NewNamed(kSRGB_Named); 77 if (xyz_almost_equal(toXYZD50, gSRGB_toXYZD50)) {
78 return SkColorSpace::NewNamed(kSRGB_Named);
79 } else if (xyz_almost_equal(toXYZD50, gAdobeRGB_toXYZD50)) {
80 return SkColorSpace::NewNamed(kAdobeRGB_Named);
81 }
69 } 82 }
70 83
71 return sk_sp<SkColorSpace>(new SkColorSpace(std::move(gammas), toXYZD50, kUn known_Named)); 84 return sk_sp<SkColorSpace>(new SkColorSpace(std::move(gammas), toXYZD50, kUn known_Named));
72 } 85 }
73 86
74 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) { 87 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) {
75 static SkOnce once; 88 static SkOnce sRGBOnce;
76 static SkColorSpace* sRGB; 89 static SkColorSpace* sRGB;
90 static SkOnce adobeRGBOnce;
91 static SkColorSpace* adobeRGB;
77 92
78 switch (named) { 93 switch (named) {
79 case kSRGB_Named: { 94 case kSRGB_Named: {
80 once([] { 95 sRGBOnce([] {
81 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); 96 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor);
82 srgbToxyzD50.set3x3ColMajorf(gSRGB_toXYZD50); 97 srgbToxyzD50.set3x3ColMajorf(gSRGB_toXYZD50);
83 sRGB = new SkColorSpace(SkGammas(2.2f, 2.2f, 2.2f), srgbToxyzD50 , kSRGB_Named); 98 sRGB = new SkColorSpace(SkGammas(2.2f, 2.2f, 2.2f), srgbToxyzD50 , kSRGB_Named);
84 }); 99 });
85 return sk_ref_sp(sRGB); 100 return sk_ref_sp(sRGB);
86 } 101 }
102 case kAdobeRGB_Named: {
103 adobeRGBOnce([] {
104 SkMatrix44 adobergbToxyzD50(SkMatrix44::kUninitialized_Construct or);
105 adobergbToxyzD50.set3x3ColMajorf(gAdobeRGB_toXYZD50);
106 adobeRGB = new SkColorSpace(SkGammas(2.2f, 2.2f, 2.2f), adobergb ToxyzD50,
107 kAdobeRGB_Named);
108 });
109 return sk_ref_sp(adobeRGB);
110 }
87 default: 111 default:
88 break; 112 break;
89 } 113 }
90 return nullptr; 114 return nullptr;
91 } 115 }
92 116
93 //////////////////////////////////////////////////////////////////////////////// /////////////////// 117 //////////////////////////////////////////////////////////////////////////////// ///////////////////
94 118
95 #include "SkFixed.h" 119 #include "SkFixed.h"
96 #include "SkTemplates.h" 120 #include "SkTemplates.h"
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 toXYZ)); 683 toXYZ));
660 } 684 }
661 685
662 } 686 }
663 default: 687 default:
664 break; 688 break;
665 } 689 }
666 690
667 return_null("ICC profile contains unsupported colorspace"); 691 return_null("ICC profile contains unsupported colorspace");
668 } 692 }
OLDNEW
« no previous file with comments | « src/core/SkColorSpace.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698