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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/InterpolationSpace.cpp

Issue 2884313002: color: Rename blink::ColorSpace to blink::InterpolationSpace (Closed)
Patch Set: Incorporate review feedback Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008, Google Inc. All rights reserved. 2 * Copyright (c) 2008, Google Inc. All rights reserved.
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 12 matching lines...) Expand all
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33 #include "platform/graphics/ColorSpace.h" 33 #include "platform/graphics/InterpolationSpace.h"
34 34
35 #include <algorithm> 35 #include <algorithm>
36 #include "platform/graphics/skia/SkiaUtils.h" 36 #include "platform/graphics/skia/SkiaUtils.h"
37 #include "platform/wtf/MathExtras.h" 37 #include "platform/wtf/MathExtras.h"
38 #include "public/platform/WebScreenInfo.h"
39 #include "third_party/skia/include/core/SkColorSpaceXform.h"
40 #include "third_party/skia/include/effects/SkTableColorFilter.h" 38 #include "third_party/skia/include/effects/SkTableColorFilter.h"
41 39
42 namespace blink { 40 namespace blink {
43 41
44 namespace ColorSpaceUtilities { 42 namespace InterpolationSpaceUtilities {
45 43
46 static const uint8_t* GetLinearRgbLUT() { 44 static const uint8_t* GetLinearRgbLUT() {
47 static uint8_t linear_rgb_lut[256]; 45 static uint8_t linear_rgb_lut[256];
48 static bool initialized; 46 static bool initialized;
49 if (!initialized) { 47 if (!initialized) {
50 for (unsigned i = 0; i < 256; i++) { 48 for (unsigned i = 0; i < 256; i++) {
51 float color = i / 255.0f; 49 float color = i / 255.0f;
52 color = (color <= 0.04045f ? color / 12.92f 50 color = (color <= 0.04045f ? color / 12.92f
53 : pow((color + 0.055f) / 1.055f, 2.4f)); 51 : pow((color + 0.055f) / 1.055f, 2.4f));
54 color = std::max(0.0f, color); 52 color = std::max(0.0f, color);
(...skipping 14 matching lines...) Expand all
69 color = (powf(color, 1.0f / 2.4f) * 1.055f) - 0.055f; 67 color = (powf(color, 1.0f / 2.4f) * 1.055f) - 0.055f;
70 color = std::max(0.0f, color); 68 color = std::max(0.0f, color);
71 color = std::min(1.0f, color); 69 color = std::min(1.0f, color);
72 device_rgb_lut[i] = static_cast<uint8_t>(round(color * 255)); 70 device_rgb_lut[i] = static_cast<uint8_t>(round(color * 255));
73 } 71 }
74 initialized = true; 72 initialized = true;
75 } 73 }
76 return device_rgb_lut; 74 return device_rgb_lut;
77 } 75 }
78 76
79 const uint8_t* GetConversionLUT(ColorSpace dst_color_space, 77 const uint8_t* GetConversionLUT(InterpolationSpace dst_interpolation_space,
80 ColorSpace src_color_space) { 78 InterpolationSpace src_interpolation_space) {
81 // Identity. 79 // Identity.
82 if (src_color_space == dst_color_space) 80 if (src_interpolation_space == dst_interpolation_space)
83 return 0; 81 return 0;
84 82
85 // Only sRGB/DeviceRGB <-> linearRGB are supported at the moment. 83 // Only sRGB/DeviceRGB <-> linearRGB are supported at the moment.
86 if ((src_color_space != kColorSpaceLinearRGB && 84 if ((src_interpolation_space != kInterpolationSpaceLinear &&
87 src_color_space != kColorSpaceDeviceRGB) || 85 src_interpolation_space != kInterpolationSpaceSRGB) ||
88 (dst_color_space != kColorSpaceLinearRGB && 86 (dst_interpolation_space != kInterpolationSpaceLinear &&
89 dst_color_space != kColorSpaceDeviceRGB)) 87 dst_interpolation_space != kInterpolationSpaceSRGB))
90 return 0; 88 return 0;
91 89
92 if (dst_color_space == kColorSpaceLinearRGB) 90 if (dst_interpolation_space == kInterpolationSpaceLinear)
93 return GetLinearRgbLUT(); 91 return GetLinearRgbLUT();
94 if (dst_color_space == kColorSpaceDeviceRGB) 92 if (dst_interpolation_space == kInterpolationSpaceSRGB)
95 return GetDeviceRgbLUT(); 93 return GetDeviceRgbLUT();
96 94
97 NOTREACHED(); 95 NOTREACHED();
98 return 0; 96 return 0;
99 } 97 }
100 98
101 Color ConvertColor(const Color& src_color, 99 Color ConvertColor(const Color& src_color,
102 ColorSpace dst_color_space, 100 InterpolationSpace dst_interpolation_space,
103 ColorSpace src_color_space) { 101 InterpolationSpace src_interpolation_space) {
104 const uint8_t* lookup_table = 102 const uint8_t* lookup_table =
105 GetConversionLUT(dst_color_space, src_color_space); 103 GetConversionLUT(dst_interpolation_space, src_interpolation_space);
106 if (!lookup_table) 104 if (!lookup_table)
107 return src_color; 105 return src_color;
108 106
109 return Color(lookup_table[src_color.Red()], lookup_table[src_color.Green()], 107 return Color(lookup_table[src_color.Red()], lookup_table[src_color.Green()],
110 lookup_table[src_color.Blue()], src_color.Alpha()); 108 lookup_table[src_color.Blue()], src_color.Alpha());
111 } 109 }
112 110
113 sk_sp<SkColorFilter> CreateColorSpaceFilter(ColorSpace src_color_space, 111 sk_sp<SkColorFilter> CreateInterpolationSpaceFilter(
114 ColorSpace dst_color_space) { 112 InterpolationSpace src_interpolation_space,
113 InterpolationSpace dst_interpolation_space) {
115 const uint8_t* lookup_table = 114 const uint8_t* lookup_table =
116 GetConversionLUT(dst_color_space, src_color_space); 115 GetConversionLUT(dst_interpolation_space, src_interpolation_space);
117 if (!lookup_table) 116 if (!lookup_table)
118 return nullptr; 117 return nullptr;
119 118
120 return SkTableColorFilter::MakeARGB(0, lookup_table, lookup_table, 119 return SkTableColorFilter::MakeARGB(0, lookup_table, lookup_table,
121 lookup_table); 120 lookup_table);
122 } 121 }
123 122
124 ColorSpaceGamut GetColorSpaceGamut(const WebScreenInfo& screen_info) { 123 } // namespace InterpolationSpaceUtilities
125 const gfx::ICCProfile& profile = screen_info.icc_profile;
126 if (profile == gfx::ICCProfile())
127 return ColorSpaceGamut::kUnknown;
128
129 return ColorSpaceUtilities::GetColorSpaceGamut(
130 profile.GetColorSpace().ToSkColorSpace().get());
131 }
132
133 ColorSpaceGamut GetColorSpaceGamut(SkColorSpace* color_space) {
134 sk_sp<SkColorSpace> sc_rgb(SkColorSpace::MakeSRGBLinear());
135 std::unique_ptr<SkColorSpaceXform> transform(
136 SkColorSpaceXform::New(color_space, sc_rgb.get()));
137
138 if (!transform)
139 return ColorSpaceGamut::kUnknown;
140
141 unsigned char in[3][4];
142 float out[3][4];
143 memset(in, 0, sizeof(in));
144 in[0][0] = 255;
145 in[1][1] = 255;
146 in[2][2] = 255;
147 in[0][3] = 255;
148 in[1][3] = 255;
149 in[2][3] = 255;
150 transform->apply(SkColorSpaceXform::kRGBA_F32_ColorFormat, out,
151 SkColorSpaceXform::kRGBA_8888_ColorFormat, in, 3,
152 kOpaque_SkAlphaType);
153 float score = out[0][0] * out[1][1] * out[2][2];
154
155 if (score < 0.9)
156 return ColorSpaceGamut::kLessThanNTSC;
157 if (score < 0.95)
158 return ColorSpaceGamut::NTSC; // actual score 0.912839
159 if (score < 1.1)
160 return ColorSpaceGamut::SRGB; // actual score 1.0
161 if (score < 1.3)
162 return ColorSpaceGamut::kAlmostP3;
163 if (score < 1.425)
164 return ColorSpaceGamut::P3; // actual score 1.401899
165 if (score < 1.5)
166 return ColorSpaceGamut::kAdobeRGB; // actual score 1.458385
167 if (score < 2.0)
168 return ColorSpaceGamut::kWide;
169 if (score < 2.2)
170 return ColorSpaceGamut::BT2020; // actual score 2.104520
171 if (score < 2.7)
172 return ColorSpaceGamut::kProPhoto; // actual score 2.913247
173 return ColorSpaceGamut::kUltraWide;
174 }
175
176 } // namespace ColorSpaceUtilities
177 124
178 } // namespace blink 125 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698