| 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 = | |
| 294 reinterpret_cast<const unsigned char*>(png_data); | |
| 295 gfx::Image image = gfx::Image::CreateFrom1xPNGBytes( | 293 gfx::Image image = gfx::Image::CreateFrom1xPNGBytes( |
| 296 new base::RefCountedStaticMemory(png_bytes, png_size)); | 294 new base::RefCountedStaticMemory(png_data, png_size)); |
| 297 return scoped_ptr<SkBitmap>(new SkBitmap(image.AsBitmap())); | 295 return scoped_ptr<SkBitmap>(new SkBitmap(image.AsBitmap())); |
| 298 } | 296 } |
| 299 | 297 |
| 300 SkBitmap* IconUtil::CreateSkBitmapFromHICON(HICON icon) { | 298 SkBitmap* IconUtil::CreateSkBitmapFromHICON(HICON icon) { |
| 301 // We start with validating parameters. | 299 // We start with validating parameters. |
| 302 if (!icon) | 300 if (!icon) |
| 303 return NULL; | 301 return NULL; |
| 304 | 302 |
| 305 ScopedICONINFO icon_info; | 303 ScopedICONINFO icon_info; |
| 306 BITMAP bitmap_info = { 0 }; | 304 BITMAP bitmap_info = { 0 }; |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 // Once we compute the size for a singe AND mask scan line, we multiply that | 677 // Once we compute the size for a singe AND mask scan line, we multiply that |
| 680 // number by the image height in order to get the total number of bytes for | 678 // number by the image height in order to get the total number of bytes for |
| 681 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes | 679 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes |
| 682 // for the monochrome bitmap representing the AND mask. | 680 // for the monochrome bitmap representing the AND mask. |
| 683 size_t and_line_length = (bitmap.width() + 7) >> 3; | 681 size_t and_line_length = (bitmap.width() + 7) >> 3; |
| 684 and_line_length = (and_line_length + 3) & ~3; | 682 and_line_length = (and_line_length + 3) & ~3; |
| 685 size_t and_mask_size = and_line_length * bitmap.height(); | 683 size_t and_mask_size = and_line_length * bitmap.height(); |
| 686 size_t masks_size = *xor_mask_size + and_mask_size; | 684 size_t masks_size = *xor_mask_size + and_mask_size; |
| 687 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); | 685 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); |
| 688 } | 686 } |
| OLD | NEW |