OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
14 #include "ui/ui_api.h" | 14 #include "ui/base/ui_export.h" |
15 | 15 |
16 namespace color_utils { | 16 namespace color_utils { |
17 | 17 |
18 // This class exposes the sampling method to the caller, which allows | 18 // This class exposes the sampling method to the caller, which allows |
19 // stubbing out for things like unit tests. Might be useful to pass more | 19 // stubbing out for things like unit tests. Might be useful to pass more |
20 // arguments into the GetSample method in the future (such as which | 20 // arguments into the GetSample method in the future (such as which |
21 // cluster is being worked on, etc.). | 21 // cluster is being worked on, etc.). |
22 class UI_API KMeanImageSampler { | 22 class UI_EXPORT KMeanImageSampler { |
23 public: | 23 public: |
24 virtual int GetSample(int width, int height) = 0; | 24 virtual int GetSample(int width, int height) = 0; |
25 | 25 |
26 protected: | 26 protected: |
27 KMeanImageSampler(); | 27 KMeanImageSampler(); |
28 virtual ~KMeanImageSampler(); | 28 virtual ~KMeanImageSampler(); |
29 }; | 29 }; |
30 | 30 |
31 // This sampler will pick a random pixel as a sample centroid. | 31 // This sampler will pick a random pixel as a sample centroid. |
32 class RandomSampler : public KMeanImageSampler { | 32 class RandomSampler : public KMeanImageSampler { |
33 public: | 33 public: |
34 RandomSampler(); | 34 RandomSampler(); |
35 virtual ~RandomSampler(); | 35 virtual ~RandomSampler(); |
36 | 36 |
37 virtual int GetSample(int width, int height) OVERRIDE; | 37 virtual int GetSample(int width, int height) OVERRIDE; |
38 }; | 38 }; |
39 | 39 |
40 // This sampler will pick pixels from an evenly spaced grid. | 40 // This sampler will pick pixels from an evenly spaced grid. |
41 class UI_API GridSampler : public KMeanImageSampler { | 41 class UI_EXPORT GridSampler : public KMeanImageSampler { |
42 public: | 42 public: |
43 GridSampler(); | 43 GridSampler(); |
44 virtual ~GridSampler(); | 44 virtual ~GridSampler(); |
45 | 45 |
46 virtual int GetSample(int width, int height) OVERRIDE; | 46 virtual int GetSample(int width, int height) OVERRIDE; |
47 | 47 |
48 private: | 48 private: |
49 // The number of times GetSample has been called. | 49 // The number of times GetSample has been called. |
50 int calls_; | 50 int calls_; |
51 }; | 51 }; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // this cluster). | 96 // this cluster). |
97 // 6.Going through the sorted list of clusters, pick the first cluster with the | 97 // 6.Going through the sorted list of clusters, pick the first cluster with the |
98 // largest weight that's centroid fulfills the equation | 98 // largest weight that's centroid fulfills the equation |
99 // |darkness_limit| < SUM(R, G, B) < |brightness_limit|. Return that color. | 99 // |darkness_limit| < SUM(R, G, B) < |brightness_limit|. Return that color. |
100 // If no color fulfills that requirement return the color with the largest | 100 // If no color fulfills that requirement return the color with the largest |
101 // weight regardless of whether or not it fulfills the equation above. | 101 // weight regardless of whether or not it fulfills the equation above. |
102 SkColor CalculateKMeanColorOfPNG(scoped_refptr<RefCountedMemory> png, | 102 SkColor CalculateKMeanColorOfPNG(scoped_refptr<RefCountedMemory> png, |
103 uint32_t darkness_limit, | 103 uint32_t darkness_limit, |
104 uint32_t brightness_limit); | 104 uint32_t brightness_limit); |
105 | 105 |
106 UI_API SkColor CalculateKMeanColorOfPNG(scoped_refptr<RefCountedMemory> png, | 106 UI_EXPORT SkColor CalculateKMeanColorOfPNG(scoped_refptr<RefCountedMemory> png, |
107 uint32_t darkness_limit, | 107 uint32_t darkness_limit, |
108 uint32_t brightness_limit, | 108 uint32_t brightness_limit, |
109 KMeanImageSampler& sampler); | 109 KMeanImageSampler& sampler); |
110 | 110 |
111 } // namespace color_utils | 111 } // namespace color_utils |
112 | 112 |
113 #endif // UI_GFX_COLOR_ANALYSIS_H_ | 113 #endif // UI_GFX_COLOR_ANALYSIS_H_ |
OLD | NEW |