| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 return SkColorSetARGB(alpha, | 190 return SkColorSetARGB(alpha, |
| 191 static_cast<int>(r), | 191 static_cast<int>(r), |
| 192 static_cast<int>(g), | 192 static_cast<int>(g), |
| 193 static_cast<int>(b)); | 193 static_cast<int>(b)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void BuildLumaHistogram(const SkBitmap& bitmap, int histogram[256]) { | 196 void BuildLumaHistogram(const SkBitmap& bitmap, int histogram[256]) { |
| 197 DCHECK_EQ(SkBitmap::kARGB_8888_Config, bitmap.config()); | 197 DCHECK_EQ(SkBitmap::kARGB_8888_Config, bitmap.config()); |
| 198 | 198 |
| 199 SkAutoLockPixels bitmap_lock(bitmap); | 199 SkAutoLockPixels bitmap_lock(bitmap); |
| 200 if (!bitmap.getPixels()) | |
| 201 return; | |
| 202 | 200 |
| 203 int pixel_width = bitmap.width(); | 201 int pixel_width = bitmap.width(); |
| 204 int pixel_height = bitmap.height(); | 202 int pixel_height = bitmap.height(); |
| 205 for (int y = 0; y < pixel_height; ++y) { | 203 for (int y = 0; y < pixel_height; ++y) { |
| 206 SkColor* current_color = static_cast<uint32_t*>(bitmap.getAddr32(0, y)); | 204 for (int x = 0; x < pixel_width; ++x) |
| 207 for (int x = 0; x < pixel_width; ++x, ++current_color) | 205 ++histogram[GetLuminanceForColor(bitmap.getColor(x, y))]; |
| 208 histogram[GetLuminanceForColor(*current_color)]++; | |
| 209 } | 206 } |
| 210 } | 207 } |
| 211 | 208 |
| 212 SkColor AlphaBlend(SkColor foreground, SkColor background, SkAlpha alpha) { | 209 SkColor AlphaBlend(SkColor foreground, SkColor background, SkAlpha alpha) { |
| 213 if (alpha == 0) | 210 if (alpha == 0) |
| 214 return background; | 211 return background; |
| 215 if (alpha == 255) | 212 if (alpha == 255) |
| 216 return foreground; | 213 return foreground; |
| 217 | 214 |
| 218 int f_alpha = SkColorGetA(foreground); | 215 int f_alpha = SkColorGetA(foreground); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 SkColor GetSysSkColor(int which) { | 254 SkColor GetSysSkColor(int which) { |
| 258 #if defined(OS_WIN) | 255 #if defined(OS_WIN) |
| 259 return skia::COLORREFToSkColor(GetSysColor(which)); | 256 return skia::COLORREFToSkColor(GetSysColor(which)); |
| 260 #else | 257 #else |
| 261 NOTIMPLEMENTED(); | 258 NOTIMPLEMENTED(); |
| 262 return SK_ColorLTGRAY; | 259 return SK_ColorLTGRAY; |
| 263 #endif | 260 #endif |
| 264 } | 261 } |
| 265 | 262 |
| 266 } // namespace color_utils | 263 } // namespace color_utils |
| OLD | NEW |