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 // Color flags. | |
112 enum ColorFlags { | |
113 // Luminosity. | |
114 LIGHT = 1, | |
115 NORMAL = 1 << 1, | |
116 DARK = 1 << 2, | |
117 // Saturation. | |
118 VIBRANT = 1 << 3, | |
119 MUTED = 1 << 4, | |
120 }; | |
121 | |
122 // Returns a single RGB color that represents the bitmap. |color_profile| is a | |
123 // bitwise combination of ColorFlags values (precisely one from each category | |
124 // should be used). If a value is succesfully calculated, the return value is | |
sadrul
2017/02/10 19:36:44
I think it'd be better to use two different enums,
Evan Stade
2017/02/13 19:01:13
Done.
| |
125 // fully opaque. For failure, the return value is transparent. This currently | |
126 // calculates one color at a time. We could save computation by calculating | |
127 // multiple colors at once, but there's currently no need to calculate multiple | |
128 // colors. | |
129 GFX_EXPORT SkColor CalculateProminentColorOfBitmap(const SkBitmap& bitmap, | |
130 int color_profile); | |
131 | |
111 // Compute color covariance matrix for the input bitmap. | 132 // Compute color covariance matrix for the input bitmap. |
112 GFX_EXPORT gfx::Matrix3F ComputeColorCovariance(const SkBitmap& bitmap); | 133 GFX_EXPORT gfx::Matrix3F ComputeColorCovariance(const SkBitmap& bitmap); |
113 | 134 |
114 // Apply a color reduction transform defined by |color_transform| vector to | 135 // Apply a color reduction transform defined by |color_transform| vector to |
115 // |source_bitmap|. The result is put into |target_bitmap|, which is expected | 136 // |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). | 137 // 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. | 138 // If |fit_to_range|, result is transfored linearly to fit 0-0xFF range. |
118 // Otherwise, data is clipped. | 139 // Otherwise, data is clipped. |
119 // Returns true if the target has been computed. | 140 // Returns true if the target has been computed. |
120 GFX_EXPORT bool ApplyColorReduction(const SkBitmap& source_bitmap, | 141 GFX_EXPORT bool ApplyColorReduction(const SkBitmap& source_bitmap, |
121 const gfx::Vector3dF& color_transform, | 142 const gfx::Vector3dF& color_transform, |
122 bool fit_to_range, | 143 bool fit_to_range, |
123 SkBitmap* target_bitmap); | 144 SkBitmap* target_bitmap); |
124 | 145 |
125 // Compute a monochrome image representing the principal color component of | 146 // Compute a monochrome image representing the principal color component of |
126 // the |source_bitmap|. The result is stored in |target_bitmap|, which must be | 147 // the |source_bitmap|. The result is stored in |target_bitmap|, which must be |
127 // initialized to the required size and type (SkBitmap::kA8_Config). | 148 // initialized to the required size and type (SkBitmap::kA8_Config). |
128 // Returns true if the conversion succeeded. Note that there might be legitimate | 149 // 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 | 150 // reasons for the process to fail even if all input was correct. This is a |
130 // condition the caller must be able to handle. | 151 // condition the caller must be able to handle. |
131 GFX_EXPORT bool ComputePrincipalComponentImage(const SkBitmap& source_bitmap, | 152 GFX_EXPORT bool ComputePrincipalComponentImage(const SkBitmap& source_bitmap, |
132 SkBitmap* target_bitmap); | 153 SkBitmap* target_bitmap); |
133 | 154 |
134 } // namespace color_utils | 155 } // namespace color_utils |
135 | 156 |
136 #endif // UI_GFX_COLOR_ANALYSIS_H_ | 157 #endif // UI_GFX_COLOR_ANALYSIS_H_ |
OLD | NEW |