OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif | 10 #endif |
(...skipping 17 matching lines...) Expand all Loading... |
28 // http://www.brucelindbloom.com/index.html?ColorCalculator.html | 28 // http://www.brucelindbloom.com/index.html?ColorCalculator.html |
29 | 29 |
30 static const double kCIEConversionAlpha = 0.055; | 30 static const double kCIEConversionAlpha = 0.055; |
31 static const double kCIEConversionGamma = 2.2; | 31 static const double kCIEConversionGamma = 2.2; |
32 static const double kE = 0.008856; | 32 static const double kE = 0.008856; |
33 static const double kK = 903.3; | 33 static const double kK = 903.3; |
34 | 34 |
35 static double CIEConvertNonLinear(uint8 color_component) { | 35 static double CIEConvertNonLinear(uint8 color_component) { |
36 double color_component_d = static_cast<double>(color_component) / 255.0; | 36 double color_component_d = static_cast<double>(color_component) / 255.0; |
37 if (color_component_d > 0.04045) { | 37 if (color_component_d > 0.04045) { |
38 double base = (color_component_d + kCIEConversionAlpha) / (1 + kCIEConversio
nAlpha); | 38 double base = (color_component_d + kCIEConversionAlpha) / |
| 39 (1 + kCIEConversionAlpha); |
39 return pow(base, kCIEConversionGamma); | 40 return pow(base, kCIEConversionGamma); |
40 } else { | 41 } else { |
41 return color_component_d / 12.92; | 42 return color_component_d / 12.92; |
42 } | 43 } |
43 } | 44 } |
44 | 45 |
45 // Note: this works only for sRGB. | 46 // Note: this works only for sRGB. |
46 void SkColorToCIEXYZ(SkColor c, CIE_XYZ* xyz) { | 47 void SkColorToCIEXYZ(SkColor c, CIE_XYZ* xyz) { |
47 uint8 r = SkColorGetR(c); | 48 uint8 r = SkColorGetR(c); |
48 uint8 g = SkColorGetG(c); | 49 uint8 g = SkColorGetG(c); |
(...skipping 30 matching lines...) Expand all Loading... |
79 lab->L = static_cast<int>(116 * fy) - 16; | 80 lab->L = static_cast<int>(116 * fy) - 16; |
80 lab->a = static_cast<int>(500 * (fx - fy)); | 81 lab->a = static_cast<int>(500 * (fx - fy)); |
81 lab->b = static_cast<int>(200 * (fy - fz)); | 82 lab->b = static_cast<int>(200 * (fy - fz)); |
82 } | 83 } |
83 | 84 |
84 static uint8 sRGBColorComponentFromLinearComponent(double component) { | 85 static uint8 sRGBColorComponentFromLinearComponent(double component) { |
85 double result; | 86 double result; |
86 if (component <= 0.0031308) { | 87 if (component <= 0.0031308) { |
87 result = 12.92 * component; | 88 result = 12.92 * component; |
88 } else { | 89 } else { |
89 result = (1 + kCIEConversionAlpha) * pow(component, (static_cast<double>(1)
/ 2.4)) - kCIEConversionAlpha; | 90 result = (1 + kCIEConversionAlpha) * |
| 91 pow(component, (static_cast<double>(1) / 2.4)) - |
| 92 kCIEConversionAlpha; |
90 } | 93 } |
91 return std::min(static_cast<uint8>(255), static_cast<uint8>(result * 255)); | 94 return std::min(static_cast<uint8>(255), static_cast<uint8>(result * 255)); |
92 } | 95 } |
93 | 96 |
94 SkColor CIEXYZToSkColor(SkAlpha alpha, const CIE_XYZ& xyz) { | 97 SkColor CIEXYZToSkColor(SkAlpha alpha, const CIE_XYZ& xyz) { |
95 double r_linear = 3.2410 * xyz.X - 1.5374 * xyz.Y - 0.4986 * xyz.Z; | 98 double r_linear = 3.2410 * xyz.X - 1.5374 * xyz.Y - 0.4986 * xyz.Z; |
96 double g_linear = -0.9692 * xyz.X + 1.8760 * xyz.Y + 0.0416 * xyz.Z; | 99 double g_linear = -0.9692 * xyz.X + 1.8760 * xyz.Y + 0.0416 * xyz.Z; |
97 double b_linear = 0.0556 * xyz.X - 0.2040 * xyz.Y + 1.0570 * xyz.Z; | 100 double b_linear = 0.0556 * xyz.X - 0.2040 * xyz.Y + 1.0570 * xyz.Z; |
98 uint8 r = sRGBColorComponentFromLinearComponent(r_linear); | 101 uint8 r = sRGBColorComponentFromLinearComponent(r_linear); |
99 uint8 g = sRGBColorComponentFromLinearComponent(g_linear); | 102 uint8 g = sRGBColorComponentFromLinearComponent(g_linear); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 #if defined(OS_WIN) | 260 #if defined(OS_WIN) |
258 return skia::COLORREFToSkColor(::GetSysColor(which)); | 261 return skia::COLORREFToSkColor(::GetSysColor(which)); |
259 #else | 262 #else |
260 NOTIMPLEMENTED(); | 263 NOTIMPLEMENTED(); |
261 return SK_ColorLTGRAY; | 264 return SK_ColorLTGRAY; |
262 #endif | 265 #endif |
263 } | 266 } |
264 | 267 |
265 } // namespace color_utils | 268 } // namespace color_utils |
266 | 269 |
OLD | NEW |