| 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 #include "ui/gfx/color_analysis.h" | 5 #include "ui/gfx/color_analysis.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ui/gfx/codec/png_codec.h" | 10 #include "ui/gfx/codec/png_codec.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 int GridSampler::GetSample(int width, int height) { | 150 int GridSampler::GetSample(int width, int height) { |
| 151 calls_++; | 151 calls_++; |
| 152 // We may keep getting called after we've gone of the edge of the grid; in | 152 // We may keep getting called after we've gone of the edge of the grid; in |
| 153 // this case we offset future return values by the number of times we've gone | 153 // this case we offset future return values by the number of times we've gone |
| 154 // off the grid. | 154 // off the grid. |
| 155 return (width * height * calls_ / kNumberOfClusters) % (width * height) + | 155 return (width * height * calls_ / kNumberOfClusters) % (width * height) + |
| 156 calls_ / kNumberOfClusters; | 156 calls_ / kNumberOfClusters; |
| 157 } | 157 } |
| 158 | 158 |
| 159 SkColor CalculateRecommendedBgColorForPNG( | 159 SkColor CalculateRecommendedBgColorForPNG( |
| 160 scoped_refptr<RefCountedMemory> png) { | 160 scoped_refptr<base::RefCountedMemory> png) { |
| 161 RandomSampler sampler; | 161 RandomSampler sampler; |
| 162 return CalculateRecommendedBgColorForPNG(png, sampler); | 162 return CalculateRecommendedBgColorForPNG(png, sampler); |
| 163 } | 163 } |
| 164 | 164 |
| 165 SkColor CalculateKMeanColorOfPNG(scoped_refptr<RefCountedMemory> png, | 165 SkColor CalculateKMeanColorOfPNG(scoped_refptr<base::RefCountedMemory> png, |
| 166 uint32_t darkness_limit, | 166 uint32_t darkness_limit, |
| 167 uint32_t brightness_limit) { | 167 uint32_t brightness_limit) { |
| 168 RandomSampler sampler; | 168 RandomSampler sampler; |
| 169 return CalculateKMeanColorOfPNG(png, darkness_limit, brightness_limit, | 169 return CalculateKMeanColorOfPNG(png, darkness_limit, brightness_limit, |
| 170 sampler); | 170 sampler); |
| 171 } | 171 } |
| 172 | 172 |
| 173 SkColor CalculateRecommendedBgColorForPNG( | 173 SkColor CalculateRecommendedBgColorForPNG( |
| 174 scoped_refptr<RefCountedMemory> png, | 174 scoped_refptr<base::RefCountedMemory> png, |
| 175 KMeanImageSampler& sampler) { | 175 KMeanImageSampler& sampler) { |
| 176 return CalculateKMeanColorOfPNG(png, | 176 return CalculateKMeanColorOfPNG(png, |
| 177 kMinDarkness, | 177 kMinDarkness, |
| 178 kMaxBrightness, | 178 kMaxBrightness, |
| 179 sampler); | 179 sampler); |
| 180 } | 180 } |
| 181 | 181 |
| 182 SkColor CalculateKMeanColorOfPNG(scoped_refptr<RefCountedMemory> png, | 182 SkColor CalculateKMeanColorOfPNG(scoped_refptr<base::RefCountedMemory> png, |
| 183 uint32_t darkness_limit, | 183 uint32_t darkness_limit, |
| 184 uint32_t brightness_limit, | 184 uint32_t brightness_limit, |
| 185 KMeanImageSampler& sampler) { | 185 KMeanImageSampler& sampler) { |
| 186 int img_width, img_height; | 186 int img_width, img_height; |
| 187 std::vector<uint8_t> decoded_data; | 187 std::vector<uint8_t> decoded_data; |
| 188 SkColor color = kDefaultBgColor; | 188 SkColor color = kDefaultBgColor; |
| 189 | 189 |
| 190 if (png.get() && | 190 if (png.get() && |
| 191 png->size() && | 191 png->size() && |
| 192 gfx::PNGCodec::Decode(png->front(), | 192 gfx::PNGCodec::Decode(png->front(), |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 // set the color anyway to make sure we at least have a value here. | 316 // set the color anyway to make sure we at least have a value here. |
| 317 color = SkColorSetARGB(0xFF, r, g, b); | 317 color = SkColorSetARGB(0xFF, r, g, b); |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 | 321 |
| 322 return color; | 322 return color; |
| 323 } | 323 } |
| 324 | 324 |
| 325 } // color_utils | 325 } // color_utils |
| OLD | NEW |