| 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/files/important_file_writer.h" | 8 #include "base/files/important_file_writer.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 | 283 |
| 284 void* png_data = NULL; | 284 void* png_data = NULL; |
| 285 size_t png_size = 0; | 285 size_t png_size = 0; |
| 286 if (!base::win::GetResourceFromModule(module, large_icon_entry->nID, RT_ICON, | 286 if (!base::win::GetResourceFromModule(module, large_icon_entry->nID, RT_ICON, |
| 287 &png_data, &png_size)) { | 287 &png_data, &png_size)) { |
| 288 return scoped_ptr<SkBitmap>(); | 288 return scoped_ptr<SkBitmap>(); |
| 289 } | 289 } |
| 290 DCHECK(png_data); | 290 DCHECK(png_data); |
| 291 DCHECK_EQ(png_size, large_icon_entry->dwBytesInRes); | 291 DCHECK_EQ(png_size, large_icon_entry->dwBytesInRes); |
| 292 | 292 |
| 293 const unsigned char* png_bytes = | 293 gfx::Image image = gfx::Image::CreateFrom1xPNGBytes(png_data, png_size); |
| 294 reinterpret_cast<const unsigned char*>(png_data); | |
| 295 gfx::Image image = gfx::Image::CreateFrom1xPNGBytes(png_bytes, png_size); | |
| 296 return scoped_ptr<SkBitmap>(new SkBitmap(image.AsBitmap())); | 294 return scoped_ptr<SkBitmap>(new SkBitmap(image.AsBitmap())); |
| 297 } | 295 } |
| 298 | 296 |
| 299 SkBitmap* IconUtil::CreateSkBitmapFromHICON(HICON icon) { | 297 SkBitmap* IconUtil::CreateSkBitmapFromHICON(HICON icon) { |
| 300 // We start with validating parameters. | 298 // We start with validating parameters. |
| 301 if (!icon) | 299 if (!icon) |
| 302 return NULL; | 300 return NULL; |
| 303 | 301 |
| 304 ScopedICONINFO icon_info; | 302 ScopedICONINFO icon_info; |
| 305 BITMAP bitmap_info = { 0 }; | 303 BITMAP bitmap_info = { 0 }; |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 // Once we compute the size for a singe AND mask scan line, we multiply that | 676 // Once we compute the size for a singe AND mask scan line, we multiply that |
| 679 // number by the image height in order to get the total number of bytes for | 677 // number by the image height in order to get the total number of bytes for |
| 680 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes | 678 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes |
| 681 // for the monochrome bitmap representing the AND mask. | 679 // for the monochrome bitmap representing the AND mask. |
| 682 size_t and_line_length = (bitmap.width() + 7) >> 3; | 680 size_t and_line_length = (bitmap.width() + 7) >> 3; |
| 683 and_line_length = (and_line_length + 3) & ~3; | 681 and_line_length = (and_line_length + 3) & ~3; |
| 684 size_t and_mask_size = and_line_length * bitmap.height(); | 682 size_t and_mask_size = and_line_length * bitmap.height(); |
| 685 size_t masks_size = *xor_mask_size + and_mask_size; | 683 size_t masks_size = *xor_mask_size + and_mask_size; |
| 686 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); | 684 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); |
| 687 } | 685 } |
| OLD | NEW |