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_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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 g += cg; | 235 g += cg; |
236 b += cb; | 236 b += cb; |
237 ++color_count; | 237 ++color_count; |
238 } | 238 } |
239 | 239 |
240 return color_count ? | 240 return color_count ? |
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(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.getConfig() == 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 |
262 SkColor AlphaBlend(SkColor foreground, SkColor background, SkAlpha alpha) { | 262 SkColor AlphaBlend(SkColor foreground, SkColor background, SkAlpha alpha) { |
263 if (alpha == 0) | 263 if (alpha == 0) |
264 return background; | 264 return background; |
265 if (alpha == 255) | 265 if (alpha == 255) |
266 return foreground; | 266 return foreground; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 SkColor GetSysSkColor(int which) { | 299 SkColor GetSysSkColor(int which) { |
300 #if defined(OS_WIN) | 300 #if defined(OS_WIN) |
301 return skia::COLORREFToSkColor(GetSysColor(which)); | 301 return skia::COLORREFToSkColor(GetSysColor(which)); |
302 #else | 302 #else |
303 NOTIMPLEMENTED(); | 303 NOTIMPLEMENTED(); |
304 return SK_ColorLTGRAY; | 304 return SK_ColorLTGRAY; |
305 #endif | 305 #endif |
306 } | 306 } |
307 | 307 |
308 } // namespace color_utils | 308 } // namespace color_utils |
OLD | NEW |