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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 | 71 |
72 if (best->Size() == size) { | 72 if (best->Size() == size) { |
73 resized_image_family->Add(*best); | 73 resized_image_family->Add(*best); |
74 } else { | 74 } else { |
75 // There is no |dimension|x|dimension| source image. | 75 // There is no |dimension|x|dimension| source image. |
76 // Resize this one to the desired size, and insert it. | 76 // Resize this one to the desired size, and insert it. |
77 SkBitmap best_bitmap = best->AsBitmap(); | 77 SkBitmap best_bitmap = best->AsBitmap(); |
78 // Only kARGB_8888 images are supported. | 78 // Only kARGB_8888 images are supported. |
79 // This will also filter out images with no pixels. | 79 // This will also filter out images with no pixels. |
80 if (best_bitmap.colorType() != kPMColor_SkColorType) | 80 if (best_bitmap.colorType() != kN32_SkColorType) |
81 return false; | 81 return false; |
82 SkBitmap resized_bitmap = skia::ImageOperations::Resize( | 82 SkBitmap resized_bitmap = skia::ImageOperations::Resize( |
83 best_bitmap, skia::ImageOperations::RESIZE_LANCZOS3, | 83 best_bitmap, skia::ImageOperations::RESIZE_LANCZOS3, |
84 dimension, dimension); | 84 dimension, dimension); |
85 resized_image_family->Add(gfx::Image::CreateFrom1xBitmap(resized_bitmap)); | 85 resized_image_family->Add(gfx::Image::CreateFrom1xBitmap(resized_bitmap)); |
86 } | 86 } |
87 } | 87 } |
88 return true; | 88 return true; |
89 } | 89 } |
90 | 90 |
(...skipping 21 matching lines...) Expand all Loading... |
112 DCHECK_GT(image.Width(), 0); | 112 DCHECK_GT(image.Width(), 0); |
113 DCHECK_LE(image.Width(), IconUtil::kLargeIconSize); | 113 DCHECK_LE(image.Width(), IconUtil::kLargeIconSize); |
114 DCHECK_GT(image.Height(), 0); | 114 DCHECK_GT(image.Height(), 0); |
115 DCHECK_LE(image.Height(), IconUtil::kLargeIconSize); | 115 DCHECK_LE(image.Height(), IconUtil::kLargeIconSize); |
116 | 116 |
117 SkBitmap bitmap = image.AsBitmap(); | 117 SkBitmap bitmap = image.AsBitmap(); |
118 | 118 |
119 // Only 32 bit ARGB bitmaps are supported. We also make sure the bitmap has | 119 // Only 32 bit ARGB bitmaps are supported. We also make sure the bitmap has |
120 // been properly initialized. | 120 // been properly initialized. |
121 SkAutoLockPixels bitmap_lock(bitmap); | 121 SkAutoLockPixels bitmap_lock(bitmap); |
122 if ((bitmap.colorType() != kPMColor_SkColorType) || | 122 if ((bitmap.colorType() != kN32_SkColorType) || |
123 (bitmap.getPixels() == NULL)) { | 123 (bitmap.getPixels() == NULL)) { |
124 return false; | 124 return false; |
125 } | 125 } |
126 | 126 |
127 // Special case: Icons exactly 256x256 are stored in PNG format. | 127 // Special case: Icons exactly 256x256 are stored in PNG format. |
128 if (image.Width() == IconUtil::kLargeIconSize && | 128 if (image.Width() == IconUtil::kLargeIconSize && |
129 image.Height() == IconUtil::kLargeIconSize) { | 129 image.Height() == IconUtil::kLargeIconSize) { |
130 *png_bytes = image.As1xPNGBytes(); | 130 *png_bytes = image.As1xPNGBytes(); |
131 } else { | 131 } else { |
132 bitmaps->push_back(bitmap); | 132 bitmaps->push_back(bitmap); |
(...skipping 26 matching lines...) Expand all Loading... |
159 256 // Used by Vista onwards for large icons. | 159 256 // Used by Vista onwards for large icons. |
160 }; | 160 }; |
161 | 161 |
162 const size_t IconUtil::kNumIconDimensions = arraysize(kIconDimensions); | 162 const size_t IconUtil::kNumIconDimensions = arraysize(kIconDimensions); |
163 const size_t IconUtil::kNumIconDimensionsUpToMediumSize = 9; | 163 const size_t IconUtil::kNumIconDimensionsUpToMediumSize = 9; |
164 | 164 |
165 HICON IconUtil::CreateHICONFromSkBitmap(const SkBitmap& bitmap) { | 165 HICON IconUtil::CreateHICONFromSkBitmap(const SkBitmap& bitmap) { |
166 // Only 32 bit ARGB bitmaps are supported. We also try to perform as many | 166 // Only 32 bit ARGB bitmaps are supported. We also try to perform as many |
167 // validations as we can on the bitmap. | 167 // validations as we can on the bitmap. |
168 SkAutoLockPixels bitmap_lock(bitmap); | 168 SkAutoLockPixels bitmap_lock(bitmap); |
169 if ((bitmap.colorType() != kPMColor_SkColorType) || | 169 if ((bitmap.colorType() != kN32_SkColorType) || |
170 (bitmap.width() <= 0) || (bitmap.height() <= 0) || | 170 (bitmap.width() <= 0) || (bitmap.height() <= 0) || |
171 (bitmap.getPixels() == NULL)) | 171 (bitmap.getPixels() == NULL)) |
172 return NULL; | 172 return NULL; |
173 | 173 |
174 // We start by creating a DIB which we'll use later on in order to create | 174 // We start by creating a DIB which we'll use later on in order to create |
175 // the HICON. We use BITMAPV5HEADER since the bitmap we are about to convert | 175 // the HICON. We use BITMAPV5HEADER since the bitmap we are about to convert |
176 // may contain an alpha channel and the V5 header allows us to specify the | 176 // may contain an alpha channel and the V5 header allows us to specify the |
177 // alpha mask for the DIB. | 177 // alpha mask for the DIB. |
178 BITMAPV5HEADER bitmap_header; | 178 BITMAPV5HEADER bitmap_header; |
179 InitializeBitmapHeader(&bitmap_header, bitmap.width(), bitmap.height()); | 179 InitializeBitmapHeader(&bitmap_header, bitmap.width(), bitmap.height()); |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 // Once we compute the size for a singe AND mask scan line, we multiply that | 681 // Once we compute the size for a singe AND mask scan line, we multiply that |
682 // number by the image height in order to get the total number of bytes for | 682 // number by the image height in order to get the total number of bytes for |
683 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes | 683 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes |
684 // for the monochrome bitmap representing the AND mask. | 684 // for the monochrome bitmap representing the AND mask. |
685 size_t and_line_length = (bitmap.width() + 7) >> 3; | 685 size_t and_line_length = (bitmap.width() + 7) >> 3; |
686 and_line_length = (and_line_length + 3) & ~3; | 686 and_line_length = (and_line_length + 3) & ~3; |
687 size_t and_mask_size = and_line_length * bitmap.height(); | 687 size_t and_mask_size = and_line_length * bitmap.height(); |
688 size_t masks_size = *xor_mask_size + and_mask_size; | 688 size_t masks_size = *xor_mask_size + and_mask_size; |
689 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); | 689 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); |
690 } | 690 } |
OLD | NEW |