OLD | NEW |
---|---|
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/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/scoped_handle.h" | 10 #include "base/win/scoped_handle.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 SkAutoLockPixels bitmap_lock(bitmap); | 236 SkAutoLockPixels bitmap_lock(bitmap); |
237 if ((bitmap.getConfig() != SkBitmap::kARGB_8888_Config) || | 237 if ((bitmap.getConfig() != SkBitmap::kARGB_8888_Config) || |
238 (bitmap.height() <= 0) || (bitmap.width() <= 0) || | 238 (bitmap.height() <= 0) || (bitmap.width() <= 0) || |
239 (bitmap.getPixels() == NULL)) | 239 (bitmap.getPixels() == NULL)) |
240 return false; | 240 return false; |
241 | 241 |
242 // We start by creating the file. | 242 // We start by creating the file. |
243 base::win::ScopedHandle icon_file(::CreateFile(icon_path.value().c_str(), | 243 base::win::ScopedHandle icon_file(::CreateFile(icon_path.value().c_str(), |
244 GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); | 244 GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); |
245 | 245 |
246 if (icon_file.Get() == INVALID_HANDLE_VALUE) | 246 if (icon_file.Get() == INVALID_HANDLE_VALUE || icon_file.Get() == NULL) |
grt (UTC plus 2)
2011/12/05 14:48:27
what you really want here is:
if (!icon_file.IsVal
SteveT
2011/12/05 15:24:46
Cool, thanks.
| |
247 return false; | 247 return false; |
248 | 248 |
249 // Creating a set of bitmaps corresponding to the icon images we'll end up | 249 // Creating a set of bitmaps corresponding to the icon images we'll end up |
250 // storing in the icon file. Each bitmap is created by resizing the given | 250 // storing in the icon file. Each bitmap is created by resizing the given |
251 // bitmap to the desired size. | 251 // bitmap to the desired size. |
252 std::vector<SkBitmap> bitmaps; | 252 std::vector<SkBitmap> bitmaps; |
253 CreateResizedBitmapSet(bitmap, &bitmaps); | 253 CreateResizedBitmapSet(bitmap, &bitmaps); |
254 DCHECK(!bitmaps.empty()); | 254 DCHECK(!bitmaps.empty()); |
255 size_t bitmap_count = bitmaps.size(); | 255 size_t bitmap_count = bitmaps.size(); |
256 | 256 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 // Once we compute the size for a singe AND mask scan line, we multiply that | 491 // Once we compute the size for a singe AND mask scan line, we multiply that |
492 // number by the image height in order to get the total number of bytes for | 492 // number by the image height in order to get the total number of bytes for |
493 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes | 493 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes |
494 // for the monochrome bitmap representing the AND mask. | 494 // for the monochrome bitmap representing the AND mask. |
495 size_t and_line_length = (bitmap.width() + 7) >> 3; | 495 size_t and_line_length = (bitmap.width() + 7) >> 3; |
496 and_line_length = (and_line_length + 3) & ~3; | 496 and_line_length = (and_line_length + 3) & ~3; |
497 size_t and_mask_size = and_line_length * bitmap.height(); | 497 size_t and_mask_size = and_line_length * bitmap.height(); |
498 size_t masks_size = *xor_mask_size + and_mask_size; | 498 size_t masks_size = *xor_mask_size + and_mask_size; |
499 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); | 499 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); |
500 } | 500 } |
OLD | NEW |