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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // Returns an SkColor that represents the calculated dominant color in the | 101 // Returns an SkColor that represents the calculated dominant color in the |
102 // image. See CalculateKMeanColorOfPNG() for details. | 102 // image. See CalculateKMeanColorOfPNG() for details. |
103 GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap, | 103 GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap, |
104 const HSL& lower_bound, | 104 const HSL& lower_bound, |
105 const HSL& upper_bound, | 105 const HSL& upper_bound, |
106 KMeanImageSampler* sampler); | 106 KMeanImageSampler* sampler); |
107 // Computes a dominant color using the above algorithm and reasonable defaults | 107 // Computes a dominant color using the above algorithm and reasonable defaults |
108 // for |lower_bound|, |upper_bound| and |sampler|. | 108 // for |lower_bound|, |upper_bound| and |sampler|. |
109 GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap); | 109 GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap); |
110 | 110 |
| 111 // These enums specify general values to look for when calculating prominent |
| 112 // colors from an image. For example, a "light vibrant" prominent color would |
| 113 // tend to be brighter and more saturated. The best combination of color |
| 114 // attributes depends on how you plan to apply the color. |
| 115 enum class LumaRange { |
| 116 LIGHT, |
| 117 NORMAL, |
| 118 DARK, |
| 119 }; |
| 120 |
| 121 enum class SaturationRange { |
| 122 VIBRANT, |
| 123 MUTED, |
| 124 }; |
| 125 |
| 126 // Returns a single RGB color that represents the bitmap. If a value is |
| 127 // succesfully calculated, the return value is fully opaque. For failure, the |
| 128 // return value is transparent. This currently calculates one color at a time. |
| 129 // We could save computation by calculating multiple colors at once, but there's |
| 130 // currently no need to calculate multiple colors. |
| 131 GFX_EXPORT SkColor CalculateProminentColorOfBitmap(const SkBitmap& bitmap, |
| 132 LumaRange luma, |
| 133 SaturationRange saturation); |
| 134 |
111 // Compute color covariance matrix for the input bitmap. | 135 // Compute color covariance matrix for the input bitmap. |
112 GFX_EXPORT gfx::Matrix3F ComputeColorCovariance(const SkBitmap& bitmap); | 136 GFX_EXPORT gfx::Matrix3F ComputeColorCovariance(const SkBitmap& bitmap); |
113 | 137 |
114 // Apply a color reduction transform defined by |color_transform| vector to | 138 // Apply a color reduction transform defined by |color_transform| vector to |
115 // |source_bitmap|. The result is put into |target_bitmap|, which is expected | 139 // |source_bitmap|. The result is put into |target_bitmap|, which is expected |
116 // to be initialized to the required size and type (SkBitmap::kA8_Config). | 140 // to be initialized to the required size and type (SkBitmap::kA8_Config). |
117 // If |fit_to_range|, result is transfored linearly to fit 0-0xFF range. | 141 // If |fit_to_range|, result is transfored linearly to fit 0-0xFF range. |
118 // Otherwise, data is clipped. | 142 // Otherwise, data is clipped. |
119 // Returns true if the target has been computed. | 143 // Returns true if the target has been computed. |
120 GFX_EXPORT bool ApplyColorReduction(const SkBitmap& source_bitmap, | 144 GFX_EXPORT bool ApplyColorReduction(const SkBitmap& source_bitmap, |
121 const gfx::Vector3dF& color_transform, | 145 const gfx::Vector3dF& color_transform, |
122 bool fit_to_range, | 146 bool fit_to_range, |
123 SkBitmap* target_bitmap); | 147 SkBitmap* target_bitmap); |
124 | 148 |
125 // Compute a monochrome image representing the principal color component of | 149 // Compute a monochrome image representing the principal color component of |
126 // the |source_bitmap|. The result is stored in |target_bitmap|, which must be | 150 // the |source_bitmap|. The result is stored in |target_bitmap|, which must be |
127 // initialized to the required size and type (SkBitmap::kA8_Config). | 151 // initialized to the required size and type (SkBitmap::kA8_Config). |
128 // Returns true if the conversion succeeded. Note that there might be legitimate | 152 // Returns true if the conversion succeeded. Note that there might be legitimate |
129 // reasons for the process to fail even if all input was correct. This is a | 153 // reasons for the process to fail even if all input was correct. This is a |
130 // condition the caller must be able to handle. | 154 // condition the caller must be able to handle. |
131 GFX_EXPORT bool ComputePrincipalComponentImage(const SkBitmap& source_bitmap, | 155 GFX_EXPORT bool ComputePrincipalComponentImage(const SkBitmap& source_bitmap, |
132 SkBitmap* target_bitmap); | 156 SkBitmap* target_bitmap); |
133 | 157 |
134 } // namespace color_utils | 158 } // namespace color_utils |
135 | 159 |
136 #endif // UI_GFX_COLOR_ANALYSIS_H_ | 160 #endif // UI_GFX_COLOR_ANALYSIS_H_ |
OLD | NEW |