| 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 "wtf/Threading.h" | 9 #include "wtf/Threading.h" |
| 9 #include "wtf/text/WTFString.h" | 10 #include "wtf/text/WTFString.h" |
| 10 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 void BitmapImageMetrics::countDecodedImageType(const String& type) { | 14 void BitmapImageMetrics::countDecodedImageType(const String& type) { |
| 14 DecodedImageType decodedImageType = | 15 DecodedImageType decodedImageType = |
| 15 type == "jpg" | 16 type == "jpg" |
| 16 ? ImageJPEG | 17 ? ImageJPEG |
| 17 : type == "png" | 18 : type == "png" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 35 | 36 |
| 36 void BitmapImageMetrics::countImageOrientation( | 37 void BitmapImageMetrics::countImageOrientation( |
| 37 const ImageOrientationEnum orientation) { | 38 const ImageOrientationEnum orientation) { |
| 38 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 39 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 39 EnumerationHistogram, orientationHistogram, | 40 EnumerationHistogram, orientationHistogram, |
| 40 new EnumerationHistogram("Blink.DecodedImage.Orientation", | 41 new EnumerationHistogram("Blink.DecodedImage.Orientation", |
| 41 ImageOrientationEnumEnd)); | 42 ImageOrientationEnumEnd)); |
| 42 orientationHistogram.count(orientation); | 43 orientationHistogram.count(orientation); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void BitmapImageMetrics::countImageGamma(SkColorSpace* colorSpace) { | 46 void BitmapImageMetrics::countImageGammaAndGamut(SkColorSpace* colorSpace) { |
| 46 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 47 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 47 EnumerationHistogram, gammaNamedHistogram, | 48 EnumerationHistogram, gammaNamedHistogram, |
| 48 new EnumerationHistogram("Blink.ColorSpace.Source", GammaEnd)); | 49 new EnumerationHistogram("Blink.ColorSpace.Source", GammaEnd)); |
| 49 gammaNamedHistogram.count(getColorSpaceGamma(colorSpace)); | 50 gammaNamedHistogram.count(getColorSpaceGamma(colorSpace)); |
| 51 |
| 52 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 53 EnumerationHistogram, gamutNamedHistogram, |
| 54 new EnumerationHistogram("Blink.ColorGamut.Source", GamutEnd)); |
| 55 gamutNamedHistogram.count(getColorSpaceGamut(colorSpace)); |
| 50 } | 56 } |
| 51 | 57 |
| 52 void BitmapImageMetrics::countOutputGamma(SkColorSpace* colorSpace) { | 58 void BitmapImageMetrics::countOutputGammaAndGamut(SkColorSpace* colorSpace) { |
| 53 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 59 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 54 EnumerationHistogram, gammaNamedHistogram, | 60 EnumerationHistogram, gammaNamedHistogram, |
| 55 new EnumerationHistogram("Blink.ColorSpace.Destination", GammaEnd)); | 61 new EnumerationHistogram("Blink.ColorSpace.Destination", GammaEnd)); |
| 56 gammaNamedHistogram.count(getColorSpaceGamma(colorSpace)); | 62 gammaNamedHistogram.count(getColorSpaceGamma(colorSpace)); |
| 63 |
| 64 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 65 EnumerationHistogram, gamutNamedHistogram, |
| 66 new EnumerationHistogram("Blink.ColorGamut.Destination", GamutEnd)); |
| 67 gamutNamedHistogram.count(getColorSpaceGamut(colorSpace)); |
| 57 } | 68 } |
| 58 | 69 |
| 59 BitmapImageMetrics::Gamma BitmapImageMetrics::getColorSpaceGamma( | 70 BitmapImageMetrics::Gamma BitmapImageMetrics::getColorSpaceGamma( |
| 60 SkColorSpace* colorSpace) { | 71 SkColorSpace* colorSpace) { |
| 61 Gamma gamma = GammaNull; | 72 Gamma gamma = GammaNull; |
| 62 if (colorSpace) { | 73 if (colorSpace) { |
| 63 if (colorSpace->gammaCloseToSRGB()) { | 74 if (colorSpace->gammaCloseToSRGB()) { |
| 64 gamma = GammaSRGB; | 75 gamma = GammaSRGB; |
| 65 } else if (colorSpace->gammaIsLinear()) { | 76 } else if (colorSpace->gammaIsLinear()) { |
| 66 gamma = GammaLinear; | 77 gamma = GammaLinear; |
| 67 } else { | 78 } else { |
| 68 gamma = GammaNonStandard; | 79 gamma = GammaNonStandard; |
| 69 } | 80 } |
| 70 } | 81 } |
| 71 return gamma; | 82 return gamma; |
| 72 } | 83 } |
| 73 | 84 |
| 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 |
| 74 } // namespace blink | 130 } // namespace blink |
| OLD | NEW |