Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: ui/gfx/color_utils.cc

Issue 7064024: Check for no pixels after calling lockPixels(). If so, we return rather than (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 return (abs(r - average) < kAverageBoundary) && 201 return (abs(r - average) < kAverageBoundary) &&
202 (abs(g - average) < kAverageBoundary) && 202 (abs(g - average) < kAverageBoundary) &&
203 (abs(b - average) < kAverageBoundary); 203 (abs(b - average) < kAverageBoundary);
204 } 204 }
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)
212 return SkColorSetARGB(alpha, 0, 0, 0);
213
211 // Assume ARGB_8888 format. 214 // Assume ARGB_8888 format.
212 DCHECK(favicon->getConfig() == SkBitmap::kARGB_8888_Config); 215 DCHECK(favicon->getConfig() == SkBitmap::kARGB_8888_Config);
213 SkColor* current_color = pixels; 216 SkColor* current_color = pixels;
214 217
215 DCHECK(favicon->width() <= 16 && favicon->height() <= 16); 218 DCHECK(favicon->width() <= 16 && favicon->height() <= 16);
216 219
217 int pixel_count = favicon->width() * favicon->height(); 220 int pixel_count = favicon->width() * favicon->height();
218 int color_count = 0; 221 int color_count = 0;
219 for (int i = 0; i < pixel_count; ++i, ++current_color) { 222 for (int i = 0; i < pixel_count; ++i, ++current_color) {
220 // 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
(...skipping 13 matching lines...) Expand all
234 ++color_count; 237 ++color_count;
235 } 238 }
236 239
237 return color_count ? 240 return color_count ?
238 SkColorSetARGB(alpha, r / color_count, g / color_count, b / color_count) : 241 SkColorSetARGB(alpha, r / color_count, g / color_count, b / color_count) :
239 SkColorSetARGB(alpha, 0, 0, 0); 242 SkColorSetARGB(alpha, 0, 0, 0);
240 } 243 }
241 244
242 void BuildLumaHistogram(SkBitmap* bitmap, int histogram[256]) { 245 void BuildLumaHistogram(SkBitmap* bitmap, int histogram[256]) {
243 SkAutoLockPixels bitmap_lock(*bitmap); 246 SkAutoLockPixels bitmap_lock(*bitmap);
247 if (!bitmap->getPixels())
248 return;
249
244 // Assume ARGB_8888 format. 250 // Assume ARGB_8888 format.
245 DCHECK(bitmap->getConfig() == SkBitmap::kARGB_8888_Config); 251 DCHECK(bitmap->getConfig() == SkBitmap::kARGB_8888_Config);
246 252
247 int pixel_width = bitmap->width(); 253 int pixel_width = bitmap->width();
248 int pixel_height = bitmap->height(); 254 int pixel_height = bitmap->height();
249 for (int y = 0; y < pixel_height; ++y) { 255 for (int y = 0; y < pixel_height; ++y) {
250 SkColor* current_color = static_cast<uint32_t*>(bitmap->getAddr32(0, y)); 256 SkColor* current_color = static_cast<uint32_t*>(bitmap->getAddr32(0, y));
251 for (int x = 0; x < pixel_width; ++x, ++current_color) 257 for (int x = 0; x < pixel_width; ++x, ++current_color)
252 histogram[GetLuminanceForColor(*current_color)]++; 258 histogram[GetLuminanceForColor(*current_color)]++;
253 } 259 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 SkColor GetSysSkColor(int which) { 299 SkColor GetSysSkColor(int which) {
294 #if defined(OS_WIN) 300 #if defined(OS_WIN)
295 return skia::COLORREFToSkColor(GetSysColor(which)); 301 return skia::COLORREFToSkColor(GetSysColor(which));
296 #else 302 #else
297 NOTIMPLEMENTED(); 303 NOTIMPLEMENTED();
298 return SK_ColorLTGRAY; 304 return SK_ColorLTGRAY;
299 #endif 305 #endif
300 } 306 }
301 307
302 } // namespace color_utils 308 } // namespace color_utils
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698