| OLD | NEW |
| 1 // Copyright (c) 2010 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 "gfx/icon_util.h" | 5 #include "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/scoped_handle.h" | |
| 10 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/win/scoped_handle.h" |
| 11 #include "gfx/size.h" | 11 #include "gfx/size.h" |
| 12 #include "skia/ext/image_operations.h" | 12 #include "skia/ext/image_operations.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 | 14 |
| 15 // Defining the dimensions for the icon images. We store only one value because | 15 // Defining the dimensions for the icon images. We store only one value because |
| 16 // we always resize to a square image; that is, the value 48 means that we are | 16 // we always resize to a square image; that is, the value 48 means that we are |
| 17 // going to resize the given bitmap to a 48 by 48 pixels bitmap. | 17 // going to resize the given bitmap to a 48 by 48 pixels bitmap. |
| 18 // | 18 // |
| 19 // The icon images appear in the icon file in same order in which their | 19 // The icon images appear in the icon file in same order in which their |
| 20 // corresponding dimensions appear in the |icon_dimensions_| array, so it is | 20 // corresponding dimensions appear in the |icon_dimensions_| array, so it is |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 const FilePath& icon_path) { | 190 const FilePath& icon_path) { |
| 191 // Only 32 bit ARGB bitmaps are supported. We also make sure the bitmap has | 191 // Only 32 bit ARGB bitmaps are supported. We also make sure the bitmap has |
| 192 // been properly initialized. | 192 // been properly initialized. |
| 193 SkAutoLockPixels bitmap_lock(bitmap); | 193 SkAutoLockPixels bitmap_lock(bitmap); |
| 194 if ((bitmap.getConfig() != SkBitmap::kARGB_8888_Config) || | 194 if ((bitmap.getConfig() != SkBitmap::kARGB_8888_Config) || |
| 195 (bitmap.height() <= 0) || (bitmap.width() <= 0) || | 195 (bitmap.height() <= 0) || (bitmap.width() <= 0) || |
| 196 (bitmap.getPixels() == NULL)) | 196 (bitmap.getPixels() == NULL)) |
| 197 return false; | 197 return false; |
| 198 | 198 |
| 199 // We start by creating the file. | 199 // We start by creating the file. |
| 200 ScopedHandle icon_file(::CreateFile(icon_path.value().c_str(), | 200 base::win::ScopedHandle icon_file(::CreateFile(icon_path.value().c_str(), |
| 201 GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); | 201 GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); |
| 202 | 202 |
| 203 if (icon_file.Get() == INVALID_HANDLE_VALUE) | 203 if (icon_file.Get() == INVALID_HANDLE_VALUE) |
| 204 return false; | 204 return false; |
| 205 | 205 |
| 206 // Creating a set of bitmaps corresponding to the icon images we'll end up | 206 // Creating a set of bitmaps corresponding to the icon images we'll end up |
| 207 // storing in the icon file. Each bitmap is created by resizing the given | 207 // storing in the icon file. Each bitmap is created by resizing the given |
| 208 // bitmap to the desired size. | 208 // bitmap to the desired size. |
| 209 std::vector<SkBitmap> bitmaps; | 209 std::vector<SkBitmap> bitmaps; |
| 210 CreateResizedBitmapSet(bitmap, &bitmaps); | 210 CreateResizedBitmapSet(bitmap, &bitmaps); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 // Once we compute the size for a singe AND mask scan line, we multiply that | 448 // Once we compute the size for a singe AND mask scan line, we multiply that |
| 449 // number by the image height in order to get the total number of bytes for | 449 // number by the image height in order to get the total number of bytes for |
| 450 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes | 450 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes |
| 451 // for the monochrome bitmap representing the AND mask. | 451 // for the monochrome bitmap representing the AND mask. |
| 452 size_t and_line_length = (bitmap.width() + 7) >> 3; | 452 size_t and_line_length = (bitmap.width() + 7) >> 3; |
| 453 and_line_length = (and_line_length + 3) & ~3; | 453 and_line_length = (and_line_length + 3) & ~3; |
| 454 size_t and_mask_size = and_line_length * bitmap.height(); | 454 size_t and_mask_size = and_line_length * bitmap.height(); |
| 455 size_t masks_size = *xor_mask_size + and_mask_size; | 455 size_t masks_size = *xor_mask_size + and_mask_size; |
| 456 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); | 456 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); |
| 457 } | 457 } |
| OLD | NEW |