OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef UI_GFX_COLOR_ANALYSIS_H_ | 5 #ifndef UI_GFX_COLOR_ANALYSIS_H_ |
6 #define UI_GFX_COLOR_ANALYSIS_H_ | 6 #define UI_GFX_COLOR_ANALYSIS_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 private: | 45 private: |
46 // The number of times GetSample has been called. | 46 // The number of times GetSample has been called. |
47 int calls_; | 47 int calls_; |
48 }; | 48 }; |
49 | 49 |
50 // Returns the color in an ARGB |image| that is closest in RGB-space to the | 50 // Returns the color in an ARGB |image| that is closest in RGB-space to the |
51 // provided |color|. Exported for testing. | 51 // provided |color|. Exported for testing. |
52 GFX_EXPORT SkColor FindClosestColor(const uint8_t* image, int width, int height, | 52 GFX_EXPORT SkColor FindClosestColor(const uint8_t* image, int width, int height, |
53 SkColor color); | 53 SkColor color); |
54 | 54 |
55 // Returns an SkColor that represents the calculated dominant color in the png. | 55 // Returns an SkColor that represents the calculated dominant color in the |
56 // image. | |
Matt Giuca
2014/05/22 06:10:42
nit: Join the next line onto this one.
calamity
2014/05/22 07:46:53
Done.
| |
56 // This uses a KMean clustering algorithm to find clusters of pixel colors in | 57 // This uses a KMean clustering algorithm to find clusters of pixel colors in |
57 // RGB space. | 58 // RGB space. |
58 // |png| represents the data of a png encoded image. | 59 // |png/bitmap| represents the data of a png/bitmap encoded image. |
59 // |darkness_limit| represents the minimum sum of the RGB components that is | 60 // |darkness_limit| represents the minimum sum of the RGB components that is |
60 // acceptable as a color choice. This can be from 0 to 765. | 61 // acceptable as a color choice. This can be from 0 to 765. |
61 // |brightness_limit| represents the maximum sum of the RGB components that is | 62 // |brightness_limit| represents the maximum sum of the RGB components that is |
62 // acceptable as a color choice. This can be from 0 to 765. | 63 // acceptable as a color choice. This can be from 0 to 765. |
63 // | 64 // |
64 // RGB KMean Algorithm (N clusters, M iterations): | 65 // RGB KMean Algorithm (N clusters, M iterations): |
65 // 1.Pick N starting colors by randomly sampling the pixels. If you see a | 66 // 1.Pick N starting colors by randomly sampling the pixels. If you see a |
66 // color you already saw keep sampling. After a certain number of tries | 67 // color you already saw keep sampling. After a certain number of tries |
67 // just remove the cluster and continue with N = N-1 clusters (for an image | 68 // just remove the cluster and continue with N = N-1 clusters (for an image |
68 // with just one color this should devolve to N=1). These colors are the | 69 // with just one color this should devolve to N=1). These colors are the |
(...skipping 18 matching lines...) Expand all Loading... | |
87 // If no color fulfills that requirement return the color with the largest | 88 // If no color fulfills that requirement return the color with the largest |
88 // weight regardless of whether or not it fulfills the equation above. | 89 // weight regardless of whether or not it fulfills the equation above. |
89 // | 90 // |
90 // Note: Switching to HSV space did not improve the results of this algorithm | 91 // Note: Switching to HSV space did not improve the results of this algorithm |
91 // for typical favicon images. | 92 // for typical favicon images. |
92 GFX_EXPORT SkColor CalculateKMeanColorOfPNG( | 93 GFX_EXPORT SkColor CalculateKMeanColorOfPNG( |
93 scoped_refptr<base::RefCountedMemory> png, | 94 scoped_refptr<base::RefCountedMemory> png, |
94 uint32_t darkness_limit, | 95 uint32_t darkness_limit, |
95 uint32_t brightness_limit, | 96 uint32_t brightness_limit, |
96 KMeanImageSampler* sampler); | 97 KMeanImageSampler* sampler); |
98 GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap, | |
99 uint32_t darkness_limit, | |
100 uint32_t brightness_limit, | |
101 KMeanImageSampler* sampler); | |
97 | 102 |
98 // Computes a dominant color for an SkBitmap using the above algorithm and | 103 // Computes a dominant color using the above algorithm and reasonable defaults |
99 // reasonable defaults for |darkness_limit|, |brightness_limit| and |sampler|. | 104 // for |darkness_limit|, |brightness_limit| and |sampler|. |
105 GFX_EXPORT SkColor | |
106 CalculateKMeanColorOfPNG(scoped_refptr<base::RefCountedMemory> png); | |
Matt Giuca
2014/05/22 06:10:42
All overloads of a function should appear together
calamity
2014/05/22 07:46:53
Done.
| |
100 GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap); | 107 GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap); |
101 | 108 |
102 // Compute color covariance matrix for the input bitmap. | 109 // Compute color covariance matrix for the input bitmap. |
103 GFX_EXPORT gfx::Matrix3F ComputeColorCovariance(const SkBitmap& bitmap); | 110 GFX_EXPORT gfx::Matrix3F ComputeColorCovariance(const SkBitmap& bitmap); |
104 | 111 |
105 // Apply a color reduction transform defined by |color_transform| vector to | 112 // Apply a color reduction transform defined by |color_transform| vector to |
106 // |source_bitmap|. The result is put into |target_bitmap|, which is expected | 113 // |source_bitmap|. The result is put into |target_bitmap|, which is expected |
107 // to be initialized to the required size and type (SkBitmap::kA8_Config). | 114 // to be initialized to the required size and type (SkBitmap::kA8_Config). |
108 // If |fit_to_range|, result is transfored linearly to fit 0-0xFF range. | 115 // If |fit_to_range|, result is transfored linearly to fit 0-0xFF range. |
109 // Otherwise, data is clipped. | 116 // Otherwise, data is clipped. |
110 // Returns true if the target has been computed. | 117 // Returns true if the target has been computed. |
111 GFX_EXPORT bool ApplyColorReduction(const SkBitmap& source_bitmap, | 118 GFX_EXPORT bool ApplyColorReduction(const SkBitmap& source_bitmap, |
112 const gfx::Vector3dF& color_transform, | 119 const gfx::Vector3dF& color_transform, |
113 bool fit_to_range, | 120 bool fit_to_range, |
114 SkBitmap* target_bitmap); | 121 SkBitmap* target_bitmap); |
115 | 122 |
116 // Compute a monochrome image representing the principal color component of | 123 // Compute a monochrome image representing the principal color component of |
117 // the |source_bitmap|. The result is stored in |target_bitmap|, which must be | 124 // the |source_bitmap|. The result is stored in |target_bitmap|, which must be |
118 // initialized to the required size and type (SkBitmap::kA8_Config). | 125 // initialized to the required size and type (SkBitmap::kA8_Config). |
119 // Returns true if the conversion succeeded. Note that there might be legitimate | 126 // Returns true if the conversion succeeded. Note that there might be legitimate |
120 // reasons for the process to fail even if all input was correct. This is a | 127 // reasons for the process to fail even if all input was correct. This is a |
121 // condition the caller must be able to handle. | 128 // condition the caller must be able to handle. |
122 GFX_EXPORT bool ComputePrincipalComponentImage(const SkBitmap& source_bitmap, | 129 GFX_EXPORT bool ComputePrincipalComponentImage(const SkBitmap& source_bitmap, |
123 SkBitmap* target_bitmap); | 130 SkBitmap* target_bitmap); |
124 | 131 |
125 } // namespace color_utils | 132 } // namespace color_utils |
126 | 133 |
127 #endif // UI_GFX_COLOR_ANALYSIS_H_ | 134 #endif // UI_GFX_COLOR_ANALYSIS_H_ |
OLD | NEW |