OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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" | 9 #include "base/scoped_handle.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
11 #include "gfx/size.h" | 11 #include "gfx/size.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 169 |
170 // Finding out whether the bitmap has an alpha channel. | 170 // Finding out whether the bitmap has an alpha channel. |
171 bool bitmap_has_alpha_channel = PixelsHaveAlpha( | 171 bool bitmap_has_alpha_channel = PixelsHaveAlpha( |
172 static_cast<const uint32*>(bitmap->getPixels()), num_pixels); | 172 static_cast<const uint32*>(bitmap->getPixels()), num_pixels); |
173 | 173 |
174 // If the bitmap does not have an alpha channel, we need to build it using | 174 // If the bitmap does not have an alpha channel, we need to build it using |
175 // the previously captured AND mask. Otherwise, we are done. | 175 // the previously captured AND mask. Otherwise, we are done. |
176 if (!bitmap_has_alpha_channel) { | 176 if (!bitmap_has_alpha_channel) { |
177 unsigned int* p = static_cast<unsigned int*>(bitmap->getPixels()); | 177 unsigned int* p = static_cast<unsigned int*>(bitmap->getPixels()); |
178 for (size_t i = 0; i < num_pixels; ++p, ++i) { | 178 for (size_t i = 0; i < num_pixels; ++p, ++i) { |
179 DCHECK_EQ((*p & 0xff000000), 0u); | 179 DCHECK_EQ((*p & 0xff000000), 0); |
180 if (opaque[i]) | 180 if (opaque[i]) |
181 *p |= 0xff000000; | 181 *p |= 0xff000000; |
182 else | 182 else |
183 *p &= 0x00ffffff; | 183 *p &= 0x00ffffff; |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 delete [] opaque; | 187 delete [] opaque; |
188 ::DeleteDC(dib_dc); | 188 ::DeleteDC(dib_dc); |
189 ::DeleteObject(dib); | 189 ::DeleteObject(dib); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 &icon_image_size); | 252 &icon_image_size); |
253 DCHECK_GT(icon_image_size, 0); | 253 DCHECK_GT(icon_image_size, 0); |
254 offset += icon_image_size; | 254 offset += icon_image_size; |
255 } | 255 } |
256 DCHECK_EQ(offset, buffer_size); | 256 DCHECK_EQ(offset, buffer_size); |
257 | 257 |
258 // Finally, writing the data info the file. | 258 // Finally, writing the data info the file. |
259 DWORD bytes_written; | 259 DWORD bytes_written; |
260 bool delete_file = false; | 260 bool delete_file = false; |
261 if (!WriteFile(icon_file.Get(), buffer, buffer_size, &bytes_written, NULL) || | 261 if (!WriteFile(icon_file.Get(), buffer, buffer_size, &bytes_written, NULL) || |
262 static_cast<int>(bytes_written) != buffer_size) { | 262 bytes_written != buffer_size) { |
263 delete_file = true; | 263 delete_file = true; |
264 } | 264 } |
265 | 265 |
266 ::CloseHandle(icon_file.Take()); | 266 ::CloseHandle(icon_file.Take()); |
267 delete [] buffer; | 267 delete [] buffer; |
268 if (delete_file) { | 268 if (delete_file) { |
269 bool success = file_util::Delete(icon_file_name, false); | 269 bool success = file_util::Delete(icon_file_name, false); |
270 DCHECK(success); | 270 DCHECK(success); |
271 } | 271 } |
272 | 272 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 // Once we compute the size for a singe AND mask scan line, we multiply that | 480 // Once we compute the size for a singe AND mask scan line, we multiply that |
481 // number by the image height in order to get the total number of bytes for | 481 // number by the image height in order to get the total number of bytes for |
482 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes | 482 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes |
483 // for the monochrome bitmap representing the AND mask. | 483 // for the monochrome bitmap representing the AND mask. |
484 int and_line_length = (bitmap.width() + 7) >> 3; | 484 int and_line_length = (bitmap.width() + 7) >> 3; |
485 and_line_length = (and_line_length + 3) & ~3; | 485 and_line_length = (and_line_length + 3) & ~3; |
486 *and_mask_size = and_line_length * bitmap.height(); | 486 *and_mask_size = and_line_length * bitmap.height(); |
487 int masks_size = *xor_mask_size + *and_mask_size; | 487 int masks_size = *xor_mask_size + *and_mask_size; |
488 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); | 488 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); |
489 } | 489 } |
OLD | NEW |