Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: ui/gfx/color_analysis.h

Issue 2690513002: Port Android palette API for deriving a prominent color from an image. (Closed)
Patch Set: git cl try Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/gfx/color_analysis.cc » ('j') | ui/gfx/color_analysis.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
113 enum class LumaRange {
sky 2017/02/17 21:42:20 Without any context and looking at these enum valu
Evan Stade 2017/02/17 23:23:19 CalculateProminentColorOfBitmap() translates these
sky 2017/02/18 00:01:34 If you only intend to call with one value, I recom
Evan Stade 2017/02/18 00:05:00 There is no default. Each consumer of the API (i.e
114 LIGHT,
115 NORMAL,
116 DARK,
117 };
oshima 2017/02/14 02:18:08 nit: newline
Evan Stade 2017/02/17 23:23:19 Done.
118 enum class SaturationRange {
119 VIBRANT,
120 MUTED,
121 };
122
123 // Returns a single RGB color that represents the bitmap. If a value is
124 // succesfully calculated, the return value is fully opaque. For failure, the
125 // return value is transparent. This currently calculates one color at a time.
Nico 2017/02/17 21:37:06 Maybe base::Optional<SkColor> or bool and SkColor
Evan Stade 2017/02/17 23:23:19 This function should only return fully opaque colo
126 // We could save computation by calculating multiple colors at once, but there's
127 // currently no need to calculate multiple colors.
128 GFX_EXPORT SkColor CalculateProminentColorOfBitmap(const SkBitmap& bitmap,
129 LumaRange luma,
130 SaturationRange saturation);
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_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/color_analysis.cc » ('j') | ui/gfx/color_analysis.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698