OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/media/desktop_media_list_ash.h" | |
6 | |
7 gfx::ImageSkia DesktopMediaList::CreateImageEncloseFavicon( | |
8 gfx::Size size, | |
9 gfx::Image& favicon) { | |
10 // Enlarge scale for favicon. | |
11 const int scale = 3; | |
miu
2015/12/12 00:00:33
style nit: kScale
GeorgeZ
2015/12/14 18:33:07
variable is removed
| |
12 // Thickness of image boundary. | |
13 const int thick = 5; | |
miu
2015/12/12 00:00:33
style nit: kBoundaryThickness
GeorgeZ
2015/12/14 18:33:07
variable is removed
| |
14 | |
15 // Sanity check. If failed, return a empty image. | |
miu
2015/12/12 00:00:33
The entire rest of this function is re-inventing c
GeorgeZ
2015/12/14 18:33:07
Done.
| |
16 if (size.width() < favicon.Width() * scale || | |
17 size.height() < favicon.Height() * scale) | |
18 return gfx::ImageSkia(); | |
19 | |
20 // Create a SkBitmap for faviocn. | |
21 SkBitmap icon = favicon.AsBitmap(); | |
22 | |
23 // Create a bitmap. | |
24 SkBitmap result; | |
25 result.allocN32Pixels(size.width(), size.height(), true); | |
26 | |
27 // Two SkBitmaps' color type need match to merge. | |
28 if (icon.colorType() != result.colorType()) | |
29 return gfx::ImageSkia(); | |
30 | |
31 result.lockPixels(); | |
32 uint8* pixels_data = reinterpret_cast<uint8*>(result.getPixels()); | |
33 | |
34 // Set background. | |
35 int span = result.rowBytes(); | |
36 int bpp = result.bytesPerPixel(); | |
37 for (int y = 0; y < result.height(); ++y) { | |
38 for (int x = 0; x < result.width(); ++x) { | |
39 if (y < thick || y >= result.height() - thick || x < thick || | |
40 x >= result.width() - thick) { | |
41 pixels_data[span * y + x * bpp] = 0; | |
42 pixels_data[span * y + x * bpp + 1] = 0; | |
43 pixels_data[span * y + x * bpp + 2] = 0; | |
44 } else { | |
45 pixels_data[span * y + x * bpp] = 0xff; | |
46 pixels_data[span * y + x * bpp + 1] = 0xff; | |
47 pixels_data[span * y + x * bpp + 2] = 0xff; | |
48 } | |
49 pixels_data[span * y + x * bpp + 3] = 0xff; | |
50 } | |
51 } | |
52 | |
53 // Copy enlarged favicon into center of result image. | |
54 icon.lockPixels(); | |
55 uint8* icon_data = reinterpret_cast<uint8*>(icon.getPixels()); | |
56 | |
57 int icon_span = icon.rowBytes(); | |
58 int icon_bpp = icon.bytesPerPixel(); | |
59 int offsety = (result.height() - icon.height() * scale) / 2; | |
60 int offsetx = (result.width() - icon.width() * scale) / 2; | |
61 for (int y = 0; y < icon.height() * scale; ++y) { | |
62 for (int x = 0; x < icon.width() * scale; ++x) { | |
63 pixels_data[span * (y + offsety) + (x + offsetx) * bpp] = | |
64 icon_data[icon_span * (y / scale) + (x / scale) * icon_bpp]; | |
65 pixels_data[span * (y + offsety) + (x + offsetx) * bpp + 1] = | |
66 icon_data[icon_span * (y / scale) + (x / scale) * icon_bpp + 1]; | |
67 pixels_data[span * (y + offsety) + (x + offsetx) * bpp + 2] = | |
68 icon_data[icon_span * (y / scale) + (x / scale) * icon_bpp + 2]; | |
69 } | |
70 } | |
71 icon.unlockPixels(); | |
72 result.unlockPixels(); | |
73 | |
74 // Create a skia image. | |
75 return gfx::ImageSkia::CreateFrom1xBitmap(result); | |
76 } | |
OLD | NEW |