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/icon_util.h" | 5 #include "ui/gfx/icon_util.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/win/resource_util.h" | 10 #include "base/win/resource_util.h" |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 337 |
338 ::SelectObject(dib_dc, old_obj); | 338 ::SelectObject(dib_dc, old_obj); |
339 ::DeleteObject(dib); | 339 ::DeleteObject(dib); |
340 ::DeleteDC(dib_dc); | 340 ::DeleteDC(dib_dc); |
341 | 341 |
342 return bitmap; | 342 return bitmap; |
343 } | 343 } |
344 | 344 |
345 bool IconUtil::CreateIconFileFromSkBitmap(const SkBitmap& bitmap, | 345 bool IconUtil::CreateIconFileFromSkBitmap(const SkBitmap& bitmap, |
346 const SkBitmap& large_bitmap, | 346 const SkBitmap& large_bitmap, |
347 const FilePath& icon_path) { | 347 const base::FilePath& icon_path) { |
348 // Only 32 bit ARGB bitmaps are supported. We also make sure the bitmap has | 348 // Only 32 bit ARGB bitmaps are supported. We also make sure the bitmap has |
349 // been properly initialized. | 349 // been properly initialized. |
350 SkAutoLockPixels bitmap_lock(bitmap); | 350 SkAutoLockPixels bitmap_lock(bitmap); |
351 if ((bitmap.config() != SkBitmap::kARGB_8888_Config) || | 351 if ((bitmap.config() != SkBitmap::kARGB_8888_Config) || |
352 (bitmap.height() <= 0) || (bitmap.width() <= 0) || | 352 (bitmap.height() <= 0) || (bitmap.width() <= 0) || |
353 (bitmap.getPixels() == NULL)) { | 353 (bitmap.getPixels() == NULL)) { |
354 return false; | 354 return false; |
355 } | 355 } |
356 | 356 |
357 // If |large_bitmap| was specified, validate its dimension and convert to PNG. | 357 // If |large_bitmap| was specified, validate its dimension and convert to PNG. |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 // Once we compute the size for a singe AND mask scan line, we multiply that | 637 // Once we compute the size for a singe AND mask scan line, we multiply that |
638 // number by the image height in order to get the total number of bytes for | 638 // number by the image height in order to get the total number of bytes for |
639 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes | 639 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes |
640 // for the monochrome bitmap representing the AND mask. | 640 // for the monochrome bitmap representing the AND mask. |
641 size_t and_line_length = (bitmap.width() + 7) >> 3; | 641 size_t and_line_length = (bitmap.width() + 7) >> 3; |
642 and_line_length = (and_line_length + 3) & ~3; | 642 and_line_length = (and_line_length + 3) & ~3; |
643 size_t and_mask_size = and_line_length * bitmap.height(); | 643 size_t and_mask_size = and_line_length * bitmap.height(); |
644 size_t masks_size = *xor_mask_size + and_mask_size; | 644 size_t masks_size = *xor_mask_size + and_mask_size; |
645 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); | 645 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); |
646 } | 646 } |
OLD | NEW |