blob: acaf0c01f12819cfc8ff0750884f683f4193c392 [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// 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
3// found in the LICENSE file.
initial.commit3f4a7322008-07-27 06:49:38 +09004
5#include "base/gfx/bitmap_header.h"
6
7namespace gfx {
8
9void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) {
10 CreateBitmapHeaderWithColorDepth(width, height, 32, hdr);
11}
12
13void 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
30void 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.
47void 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} // namespace gfx
license.botf003cfe2008-08-24 09:55:55 +090064