OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 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 "gfx/gdi_util.h" | |
6 | |
7 namespace gfx { | |
8 | |
9 void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) { | |
10 CreateBitmapHeaderWithColorDepth(width, height, 32, hdr); | |
11 } | |
12 | |
13 void CreateBitmapHeaderWithColorDepth(int width, int height, int color_depth, | |
14 BITMAPINFOHEADER* hdr) { | |
15 // These values are shared with gfx::PlatformDevice | |
16 hdr->biSize = sizeof(BITMAPINFOHEADER); | |
17 hdr->biWidth = width; | |
18 hdr->biHeight = -height; // minus means top-down bitmap | |
19 hdr->biPlanes = 1; | |
20 hdr->biBitCount = color_depth; | |
21 hdr->biCompression = BI_RGB; // no compression | |
22 hdr->biSizeImage = 0; | |
23 hdr->biXPelsPerMeter = 1; | |
24 hdr->biYPelsPerMeter = 1; | |
25 hdr->biClrUsed = 0; | |
26 hdr->biClrImportant = 0; | |
27 } | |
28 | |
29 | |
30 void CreateBitmapV4Header(int width, int height, BITMAPV4HEADER* hdr) { | |
31 // Because bmp v4 header is just an extension, we just create a v3 header and | |
32 // copy the bits over to the v4 header. | |
33 BITMAPINFOHEADER header_v3; | |
34 CreateBitmapHeader(width, height, &header_v3); | |
35 memset(hdr, 0, sizeof(BITMAPV4HEADER)); | |
36 memcpy(hdr, &header_v3, sizeof(BITMAPINFOHEADER)); | |
37 | |
38 // Correct the size of the header and fill in the mask values. | |
39 hdr->bV4Size = sizeof(BITMAPV4HEADER); | |
40 hdr->bV4RedMask = 0x00ff0000; | |
41 hdr->bV4GreenMask = 0x0000ff00; | |
42 hdr->bV4BlueMask = 0x000000ff; | |
43 hdr->bV4AlphaMask = 0xff000000; | |
44 } | |
45 | |
46 // Creates a monochrome bitmap header. | |
47 void CreateMonochromeBitmapHeader(int width, | |
48 int height, | |
49 BITMAPINFOHEADER* hdr) { | |
50 hdr->biSize = sizeof(BITMAPINFOHEADER); | |
51 hdr->biWidth = width; | |
52 hdr->biHeight = -height; | |
53 hdr->biPlanes = 1; | |
54 hdr->biBitCount = 1; | |
55 hdr->biCompression = BI_RGB; | |
56 hdr->biSizeImage = 0; | |
57 hdr->biXPelsPerMeter = 1; | |
58 hdr->biYPelsPerMeter = 1; | |
59 hdr->biClrUsed = 0; | |
60 hdr->biClrImportant = 0; | |
61 } | |
62 | |
63 void SubtractRectanglesFromRegion(HRGN hrgn, | |
64 const std::vector<gfx::Rect>& cutouts) { | |
65 if (cutouts.size()) { | |
66 HRGN cutout = ::CreateRectRgn(0, 0, 0, 0); | |
67 for (size_t i = 0; i < cutouts.size(); i++) { | |
68 ::SetRectRgn(cutout, | |
69 cutouts[i].x(), | |
70 cutouts[i].y(), | |
71 cutouts[i].right(), | |
72 cutouts[i].bottom()); | |
73 ::CombineRgn(hrgn, hrgn, cutout, RGN_DIFF); | |
74 } | |
75 ::DeleteObject(cutout); | |
76 } | |
77 } | |
78 | |
79 } // namespace gfx | |
OLD | NEW |