| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/graphics/BitmapImageMetrics.h" | 5 #include "platform/graphics/BitmapImageMetrics.h" |
| 6 | 6 |
| 7 #include "platform/Histogram.h" | 7 #include "platform/Histogram.h" |
| 8 #include "third_party/skia/include/core/SkColorSpaceXform.h" | 8 #include "platform/graphics/ColorSpace.h" |
| 9 #include "wtf/Threading.h" | 9 #include "wtf/Threading.h" |
| 10 #include "wtf/text/WTFString.h" | 10 #include "wtf/text/WTFString.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 void BitmapImageMetrics::countDecodedImageType(const String& type) { | 14 void BitmapImageMetrics::countDecodedImageType(const String& type) { |
| 15 DecodedImageType decodedImageType = | 15 DecodedImageType decodedImageType = |
| 16 type == "jpg" | 16 type == "jpg" |
| 17 ? ImageJPEG | 17 ? ImageJPEG |
| 18 : type == "png" | 18 : type == "png" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 void BitmapImageMetrics::countImageGammaAndGamut(SkColorSpace* colorSpace) { | 46 void BitmapImageMetrics::countImageGammaAndGamut(SkColorSpace* colorSpace) { |
| 47 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 47 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 48 EnumerationHistogram, gammaNamedHistogram, | 48 EnumerationHistogram, gammaNamedHistogram, |
| 49 new EnumerationHistogram("Blink.ColorSpace.Source", GammaEnd)); | 49 new EnumerationHistogram("Blink.ColorSpace.Source", GammaEnd)); |
| 50 gammaNamedHistogram.count(getColorSpaceGamma(colorSpace)); | 50 gammaNamedHistogram.count(getColorSpaceGamma(colorSpace)); |
| 51 | 51 |
| 52 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 52 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 53 EnumerationHistogram, gamutNamedHistogram, | 53 EnumerationHistogram, gamutNamedHistogram, |
| 54 new EnumerationHistogram("Blink.ColorGamut.Source", GamutEnd)); | 54 new EnumerationHistogram("Blink.ColorGamut.Source", |
| 55 gamutNamedHistogram.count(getColorSpaceGamut(colorSpace)); | 55 static_cast<int>(ColorSpaceGamut::End))); |
| 56 gamutNamedHistogram.count( |
| 57 static_cast<int>(ColorSpaceUtilities::getColorSpaceGamut(colorSpace))); |
| 56 } | 58 } |
| 57 | 59 |
| 58 void BitmapImageMetrics::countOutputGammaAndGamut(SkColorSpace* colorSpace) { | 60 void BitmapImageMetrics::countOutputGammaAndGamut(SkColorSpace* colorSpace) { |
| 59 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 61 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 60 EnumerationHistogram, gammaNamedHistogram, | 62 EnumerationHistogram, gammaNamedHistogram, |
| 61 new EnumerationHistogram("Blink.ColorSpace.Destination", GammaEnd)); | 63 new EnumerationHistogram("Blink.ColorSpace.Destination", GammaEnd)); |
| 62 gammaNamedHistogram.count(getColorSpaceGamma(colorSpace)); | 64 gammaNamedHistogram.count(getColorSpaceGamma(colorSpace)); |
| 63 | 65 |
| 64 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 66 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 65 EnumerationHistogram, gamutNamedHistogram, | 67 EnumerationHistogram, gamutNamedHistogram, |
| 66 new EnumerationHistogram("Blink.ColorGamut.Destination", GamutEnd)); | 68 new EnumerationHistogram("Blink.ColorGamut.Destination", |
| 67 gamutNamedHistogram.count(getColorSpaceGamut(colorSpace)); | 69 static_cast<int>(ColorSpaceGamut::End))); |
| 70 gamutNamedHistogram.count( |
| 71 static_cast<int>(ColorSpaceUtilities::getColorSpaceGamut(colorSpace))); |
| 68 } | 72 } |
| 69 | 73 |
| 70 BitmapImageMetrics::Gamma BitmapImageMetrics::getColorSpaceGamma( | 74 BitmapImageMetrics::Gamma BitmapImageMetrics::getColorSpaceGamma( |
| 71 SkColorSpace* colorSpace) { | 75 SkColorSpace* colorSpace) { |
| 72 Gamma gamma = GammaNull; | 76 Gamma gamma = GammaNull; |
| 73 if (colorSpace) { | 77 if (colorSpace) { |
| 74 if (colorSpace->gammaCloseToSRGB()) { | 78 if (colorSpace->gammaCloseToSRGB()) { |
| 75 gamma = GammaSRGB; | 79 gamma = GammaSRGB; |
| 76 } else if (colorSpace->gammaIsLinear()) { | 80 } else if (colorSpace->gammaIsLinear()) { |
| 77 gamma = GammaLinear; | 81 gamma = GammaLinear; |
| 78 } else { | 82 } else { |
| 79 gamma = GammaNonStandard; | 83 gamma = GammaNonStandard; |
| 80 } | 84 } |
| 81 } | 85 } |
| 82 return gamma; | 86 return gamma; |
| 83 } | 87 } |
| 84 | 88 |
| 85 BitmapImageMetrics::Gamut BitmapImageMetrics::getColorSpaceGamut( | |
| 86 SkColorSpace* colorSpace) { | |
| 87 sk_sp<SkColorSpace> scRGB( | |
| 88 SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named)); | |
| 89 std::unique_ptr<SkColorSpaceXform> transform( | |
| 90 SkColorSpaceXform::New(colorSpace, scRGB.get())); | |
| 91 | |
| 92 if (!transform) | |
| 93 return GamutUnknown; | |
| 94 | |
| 95 unsigned char in[3][4]; | |
| 96 float out[3][4]; | |
| 97 memset(in, 0, sizeof(in)); | |
| 98 in[0][0] = 255; | |
| 99 in[1][1] = 255; | |
| 100 in[2][2] = 255; | |
| 101 in[0][3] = 255; | |
| 102 in[1][3] = 255; | |
| 103 in[2][3] = 255; | |
| 104 transform->apply(SkColorSpaceXform::kRGBA_F32_ColorFormat, out, | |
| 105 SkColorSpaceXform::kRGBA_8888_ColorFormat, in, 3, | |
| 106 kOpaque_SkAlphaType); | |
| 107 float score = out[0][0] * out[1][1] * out[2][2]; | |
| 108 | |
| 109 if (score < 0.9) | |
| 110 return GamutLessThanNTSC; | |
| 111 if (score < 0.95) | |
| 112 return GamutNTSC; // actual score 0.912839 | |
| 113 if (score < 1.1) | |
| 114 return GamutSRGB; // actual score 1.0 | |
| 115 if (score < 1.3) | |
| 116 return GamutAlmostP3; | |
| 117 if (score < 1.425) | |
| 118 return GamutP3; // actual score 1.401899 | |
| 119 if (score < 1.5) | |
| 120 return GamutAdobeRGB; // actual score 1.458385 | |
| 121 if (score < 2.0) | |
| 122 return GamutWide; | |
| 123 if (score < 2.2) | |
| 124 return GamutBT2020; // actual score 2.104520 | |
| 125 if (score < 2.7) | |
| 126 return GamutProPhoto; // actual score 2.913247 | |
| 127 return GamutUltraWide; | |
| 128 } | |
| 129 | |
| 130 } // namespace blink | 89 } // namespace blink |
| OLD | NEW |