OLD | NEW |
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 15 matching lines...) Expand all Loading... |
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/ColorSpace.h" |
34 | 34 |
35 #include "platform/graphics/skia/SkiaUtils.h" | 35 #include "platform/graphics/skia/SkiaUtils.h" |
| 36 #include "public/platform/WebScreenInfo.h" |
| 37 #include "third_party/skia/include/core/SkColorSpaceXform.h" |
36 #include "third_party/skia/include/effects/SkTableColorFilter.h" | 38 #include "third_party/skia/include/effects/SkTableColorFilter.h" |
37 #include "wtf/MathExtras.h" | 39 #include "wtf/MathExtras.h" |
38 #include <algorithm> | 40 #include <algorithm> |
39 | 41 |
40 namespace blink { | 42 namespace blink { |
41 | 43 |
42 namespace ColorSpaceUtilities { | 44 namespace ColorSpaceUtilities { |
43 | 45 |
44 static const uint8_t* getLinearRgbLUT() { | 46 static const uint8_t* getLinearRgbLUT() { |
45 static uint8_t linearRgbLUT[256]; | 47 static uint8_t linearRgbLUT[256]; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 111 |
110 sk_sp<SkColorFilter> createColorSpaceFilter(ColorSpace srcColorSpace, | 112 sk_sp<SkColorFilter> createColorSpaceFilter(ColorSpace srcColorSpace, |
111 ColorSpace dstColorSpace) { | 113 ColorSpace dstColorSpace) { |
112 const uint8_t* lookupTable = getConversionLUT(dstColorSpace, srcColorSpace); | 114 const uint8_t* lookupTable = getConversionLUT(dstColorSpace, srcColorSpace); |
113 if (!lookupTable) | 115 if (!lookupTable) |
114 return nullptr; | 116 return nullptr; |
115 | 117 |
116 return SkTableColorFilter::MakeARGB(0, lookupTable, lookupTable, lookupTable); | 118 return SkTableColorFilter::MakeARGB(0, lookupTable, lookupTable, lookupTable); |
117 } | 119 } |
118 | 120 |
| 121 ColorSpaceGamut getColorSpaceGamut(const WebScreenInfo& screenInfo) { |
| 122 const gfx::ICCProfile& profile = screenInfo.iccProfile; |
| 123 if (profile == gfx::ICCProfile()) |
| 124 return ColorSpaceGamut::Unknown; |
| 125 |
| 126 return ColorSpaceUtilities::getColorSpaceGamut( |
| 127 profile.GetColorSpace().ToSkColorSpace().get()); |
| 128 } |
| 129 |
| 130 ColorSpaceGamut getColorSpaceGamut(SkColorSpace* colorSpace) { |
| 131 sk_sp<SkColorSpace> scRGB( |
| 132 SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named)); |
| 133 std::unique_ptr<SkColorSpaceXform> transform( |
| 134 SkColorSpaceXform::New(colorSpace, scRGB.get())); |
| 135 |
| 136 if (!transform) |
| 137 return ColorSpaceGamut::Unknown; |
| 138 |
| 139 unsigned char in[3][4]; |
| 140 float out[3][4]; |
| 141 memset(in, 0, sizeof(in)); |
| 142 in[0][0] = 255; |
| 143 in[1][1] = 255; |
| 144 in[2][2] = 255; |
| 145 in[0][3] = 255; |
| 146 in[1][3] = 255; |
| 147 in[2][3] = 255; |
| 148 transform->apply(SkColorSpaceXform::kRGBA_F32_ColorFormat, out, |
| 149 SkColorSpaceXform::kRGBA_8888_ColorFormat, in, 3, |
| 150 kOpaque_SkAlphaType); |
| 151 float score = out[0][0] * out[1][1] * out[2][2]; |
| 152 |
| 153 if (score < 0.9) |
| 154 return ColorSpaceGamut::LessThanNTSC; |
| 155 if (score < 0.95) |
| 156 return ColorSpaceGamut::NTSC; // actual score 0.912839 |
| 157 if (score < 1.1) |
| 158 return ColorSpaceGamut::SRGB; // actual score 1.0 |
| 159 if (score < 1.3) |
| 160 return ColorSpaceGamut::AlmostP3; |
| 161 if (score < 1.425) |
| 162 return ColorSpaceGamut::P3; // actual score 1.401899 |
| 163 if (score < 1.5) |
| 164 return ColorSpaceGamut::AdobeRGB; // actual score 1.458385 |
| 165 if (score < 2.0) |
| 166 return ColorSpaceGamut::Wide; |
| 167 if (score < 2.2) |
| 168 return ColorSpaceGamut::BT2020; // actual score 2.104520 |
| 169 if (score < 2.7) |
| 170 return ColorSpaceGamut::ProPhoto; // actual score 2.913247 |
| 171 return ColorSpaceGamut::UltraWide; |
| 172 } |
| 173 |
119 } // namespace ColorSpaceUtilities | 174 } // namespace ColorSpaceUtilities |
120 | 175 |
121 } // namespace blink | 176 } // namespace blink |
OLD | NEW |