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

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

Issue 291653004: Add extra overloads for color analysis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nits Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/gfx/color_analysis.cc » ('j') | no next file with comments »
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 "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
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 // This uses a KMean clustering algorithm to find clusters of pixel colors in 56 // image. This uses a KMean clustering algorithm to find clusters of pixel
57 // RGB space. 57 // colors in RGB space.
58 // |png| represents the data of a png encoded image. 58 // |png|/|bitmap| represents the data of a png/bitmap encoded image.
59 // |darkness_limit| represents the minimum sum of the RGB components that is 59 // |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. 60 // 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 61 // |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. 62 // acceptable as a color choice. This can be from 0 to 765.
63 // 63 //
64 // RGB KMean Algorithm (N clusters, M iterations): 64 // RGB KMean Algorithm (N clusters, M iterations):
65 // 1.Pick N starting colors by randomly sampling the pixels. If you see a 65 // 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 66 // 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 67 // 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 68 // with just one color this should devolve to N=1). These colors are the
(...skipping 18 matching lines...) Expand all
87 // If no color fulfills that requirement return the color with the largest 87 // If no color fulfills that requirement return the color with the largest
88 // weight regardless of whether or not it fulfills the equation above. 88 // weight regardless of whether or not it fulfills the equation above.
89 // 89 //
90 // Note: Switching to HSV space did not improve the results of this algorithm 90 // Note: Switching to HSV space did not improve the results of this algorithm
91 // for typical favicon images. 91 // for typical favicon images.
92 GFX_EXPORT SkColor CalculateKMeanColorOfPNG( 92 GFX_EXPORT SkColor CalculateKMeanColorOfPNG(
93 scoped_refptr<base::RefCountedMemory> png, 93 scoped_refptr<base::RefCountedMemory> png,
94 uint32_t darkness_limit, 94 uint32_t darkness_limit,
95 uint32_t brightness_limit, 95 uint32_t brightness_limit,
96 KMeanImageSampler* sampler); 96 KMeanImageSampler* sampler);
97 // Computes a dominant color using the above algorithm and reasonable defaults
98 // for |darkness_limit|, |brightness_limit| and |sampler|.
99 GFX_EXPORT SkColor CalculateKMeanColorOfPNG(
100 scoped_refptr<base::RefCountedMemory> png);
97 101
98 // Computes a dominant color for an SkBitmap using the above algorithm and 102 // Returns an SkColor that represents the calculated dominant color in the
99 // reasonable defaults for |darkness_limit|, |brightness_limit| and |sampler|. 103 // image. See CalculateKMeanColorOfPNG() for details.
104 GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap,
105 uint32_t darkness_limit,
106 uint32_t brightness_limit,
107 KMeanImageSampler* sampler);
108 // Computes a dominant color using the above algorithm and reasonable defaults
109 // for |darkness_limit|, |brightness_limit| and |sampler|.
100 GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap); 110 GFX_EXPORT SkColor CalculateKMeanColorOfBitmap(const SkBitmap& bitmap);
101 111
102 // Compute color covariance matrix for the input bitmap. 112 // Compute color covariance matrix for the input bitmap.
103 GFX_EXPORT gfx::Matrix3F ComputeColorCovariance(const SkBitmap& bitmap); 113 GFX_EXPORT gfx::Matrix3F ComputeColorCovariance(const SkBitmap& bitmap);
104 114
105 // Apply a color reduction transform defined by |color_transform| vector to 115 // Apply a color reduction transform defined by |color_transform| vector to
106 // |source_bitmap|. The result is put into |target_bitmap|, which is expected 116 // |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). 117 // 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. 118 // If |fit_to_range|, result is transfored linearly to fit 0-0xFF range.
109 // Otherwise, data is clipped. 119 // Otherwise, data is clipped.
110 // Returns true if the target has been computed. 120 // Returns true if the target has been computed.
111 GFX_EXPORT bool ApplyColorReduction(const SkBitmap& source_bitmap, 121 GFX_EXPORT bool ApplyColorReduction(const SkBitmap& source_bitmap,
112 const gfx::Vector3dF& color_transform, 122 const gfx::Vector3dF& color_transform,
113 bool fit_to_range, 123 bool fit_to_range,
114 SkBitmap* target_bitmap); 124 SkBitmap* target_bitmap);
115 125
116 // Compute a monochrome image representing the principal color component of 126 // Compute a monochrome image representing the principal color component of
117 // the |source_bitmap|. The result is stored in |target_bitmap|, which must be 127 // the |source_bitmap|. The result is stored in |target_bitmap|, which must be
118 // initialized to the required size and type (SkBitmap::kA8_Config). 128 // initialized to the required size and type (SkBitmap::kA8_Config).
119 // Returns true if the conversion succeeded. Note that there might be legitimate 129 // 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 130 // reasons for the process to fail even if all input was correct. This is a
121 // condition the caller must be able to handle. 131 // condition the caller must be able to handle.
122 GFX_EXPORT bool ComputePrincipalComponentImage(const SkBitmap& source_bitmap, 132 GFX_EXPORT bool ComputePrincipalComponentImage(const SkBitmap& source_bitmap,
123 SkBitmap* target_bitmap); 133 SkBitmap* target_bitmap);
124 134
125 } // namespace color_utils 135 } // namespace color_utils
126 136
127 #endif // UI_GFX_COLOR_ANALYSIS_H_ 137 #endif // UI_GFX_COLOR_ANALYSIS_H_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/color_analysis.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698