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 #include "ui/gfx/color_utils.h" | 5 #include "ui/gfx/color_utils.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif | 10 #endif |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 205 |
206 SkColor GetAverageColorOfFavicon(SkBitmap* favicon, SkAlpha alpha) { | 206 SkColor GetAverageColorOfFavicon(SkBitmap* favicon, SkAlpha alpha) { |
207 int r = 0, g = 0, b = 0; | 207 int r = 0, g = 0, b = 0; |
208 | 208 |
209 SkAutoLockPixels favicon_lock(*favicon); | 209 SkAutoLockPixels favicon_lock(*favicon); |
210 SkColor* pixels = static_cast<SkColor*>(favicon->getPixels()); | 210 SkColor* pixels = static_cast<SkColor*>(favicon->getPixels()); |
211 if (!pixels) | 211 if (!pixels) |
212 return SkColorSetARGB(alpha, 0, 0, 0); | 212 return SkColorSetARGB(alpha, 0, 0, 0); |
213 | 213 |
214 // Assume ARGB_8888 format. | 214 // Assume ARGB_8888 format. |
215 DCHECK(favicon->getConfig() == SkBitmap::kARGB_8888_Config); | 215 DCHECK(favicon->config() == SkBitmap::kARGB_8888_Config); |
216 SkColor* current_color = pixels; | 216 SkColor* current_color = pixels; |
217 | 217 |
218 DCHECK(favicon->width() <= 16 && favicon->height() <= 16); | 218 DCHECK(favicon->width() <= 16 && favicon->height() <= 16); |
219 | 219 |
220 int pixel_count = favicon->width() * favicon->height(); | 220 int pixel_count = favicon->width() * favicon->height(); |
221 int color_count = 0; | 221 int color_count = 0; |
222 for (int i = 0; i < pixel_count; ++i, ++current_color) { | 222 for (int i = 0; i < pixel_count; ++i, ++current_color) { |
223 // Disregard this color if it is close to black, close to white, or close | 223 // Disregard this color if it is close to black, close to white, or close |
224 // to transparent since any of those pixels do not contribute much to the | 224 // to transparent since any of those pixels do not contribute much to the |
225 // color makeup of this icon. | 225 // color makeup of this icon. |
(...skipping 15 matching lines...) Expand all Loading... |
241 SkColorSetARGB(alpha, r / color_count, g / color_count, b / color_count) : | 241 SkColorSetARGB(alpha, r / color_count, g / color_count, b / color_count) : |
242 SkColorSetARGB(alpha, 0, 0, 0); | 242 SkColorSetARGB(alpha, 0, 0, 0); |
243 } | 243 } |
244 | 244 |
245 void BuildLumaHistogram(const SkBitmap& bitmap, int histogram[256]) { | 245 void BuildLumaHistogram(const SkBitmap& bitmap, int histogram[256]) { |
246 SkAutoLockPixels bitmap_lock(bitmap); | 246 SkAutoLockPixels bitmap_lock(bitmap); |
247 if (!bitmap.getPixels()) | 247 if (!bitmap.getPixels()) |
248 return; | 248 return; |
249 | 249 |
250 // Assume ARGB_8888 format. | 250 // Assume ARGB_8888 format. |
251 DCHECK(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); | 251 DCHECK(bitmap.config() == SkBitmap::kARGB_8888_Config); |
252 | 252 |
253 int pixel_width = bitmap.width(); | 253 int pixel_width = bitmap.width(); |
254 int pixel_height = bitmap.height(); | 254 int pixel_height = bitmap.height(); |
255 for (int y = 0; y < pixel_height; ++y) { | 255 for (int y = 0; y < pixel_height; ++y) { |
256 SkColor* current_color = static_cast<uint32_t*>(bitmap.getAddr32(0, y)); | 256 SkColor* current_color = static_cast<uint32_t*>(bitmap.getAddr32(0, y)); |
257 for (int x = 0; x < pixel_width; ++x, ++current_color) | 257 for (int x = 0; x < pixel_width; ++x, ++current_color) |
258 histogram[GetLuminanceForColor(*current_color)]++; | 258 histogram[GetLuminanceForColor(*current_color)]++; |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 SkColor GetSysSkColor(int which) { | 307 SkColor GetSysSkColor(int which) { |
308 #if defined(OS_WIN) | 308 #if defined(OS_WIN) |
309 return skia::COLORREFToSkColor(GetSysColor(which)); | 309 return skia::COLORREFToSkColor(GetSysColor(which)); |
310 #else | 310 #else |
311 NOTIMPLEMENTED(); | 311 NOTIMPLEMENTED(); |
312 return SK_ColorLTGRAY; | 312 return SK_ColorLTGRAY; |
313 #endif | 313 #endif |
314 } | 314 } |
315 | 315 |
316 } // namespace color_utils | 316 } // namespace color_utils |
OLD | NEW |