3 * @brief The BMP library header
6 * Copyright (C) 2009 lidaibin(超越无限)
7 * mail: lidaibin@gmail.com
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
31 #define BMP_BEGIN_DECLS extern "C" {
32 #define BMP_END_DECLS }
34 #define BMP_BEGIN_DECLS
47 typedef unsigned char uint8_t;
51 typedef unsigned short uint16_t;
55 typedef unsigned int uint32_t;
65 } bmp_compression_method_t;
75 uint8_t magic[2]; /* the magic number used to identify the BMP file:
76 0x42 0x4D (Hex code points for B and M).
77 The following entries are possible:
78 BM - Windows 3.1x, 95, NT, ... etc
79 BA - OS/2 Bitmap Array
81 CP - OS/2 Color Pointer
84 uint32_t filesz; /* the size of the BMP file in bytes */
85 uint16_t creator1; /* reserved. */
86 uint16_t creator2; /* reserved. */
87 uint32_t offset; /* the offset, i.e. starting address,
88 of the byte where the bitmap data can be found. */
92 uint32_t header_sz; /* the size of this header (40 bytes) */
93 uint32_t width; /* the bitmap width in pixels */
94 uint32_t height; /* the bitmap height in pixels */
95 uint16_t nplanes; /* the number of color planes being used.
97 uint16_t depth; /* the number of bits per pixel,
98 which is the color depth of the image.
99 Typical values are 1, 4, 8, 16, 24 and 32. */
100 uint32_t compress_type; /* the compression method being used.
101 See also bmp_compression_method_t. */
102 uint32_t bmp_bytesz; /* the image size. This is the size of the raw bitmap
103 data (see below), and should not be confused
104 with the file size. */
105 uint32_t hres; /* the horizontal resolution of the image.
107 uint32_t vres; /* the vertical resolution of the image.
109 uint32_t ncolors; /* the number of colors in the color palette,
110 or 0 to default to 2<sup><i>n</i></sup>. */
111 uint32_t nimpcolors; /* the number of important colors used,
112 or 0 when every color is important;
113 generally ignored. */
114 } bmp_dib_v3_header_t;
116 typedef struct _bmpfile bmpfile_t;
118 bmpfile_t *bmp_create(uint32_t width, uint32_t height, uint32_t depth);
120 /* bmpfile_t *bmp_create_from_file(const char *filename); */
121 void bmp_destroy(bmpfile_t *bmp);
123 bmp_header_t bmp_get_header(bmpfile_t *bmp);
124 bmp_dib_v3_header_t bmp_get_dib(bmpfile_t *bmp);
126 uint32_t bmp_get_width(bmpfile_t *bmp);
127 uint32_t bmp_get_height(bmpfile_t *bmp);
128 uint32_t bmp_get_depth(bmpfile_t *bmp);
130 uint32_t bmp_get_dpi_x(bmpfile_t *bmp);
131 uint32_t bmp_get_dpi_y(bmpfile_t *bmp);
132 void bmp_set_dpi(bmpfile_t *bmp, uint32_t x, uint32_t y);
134 rgb_pixel_t *bmp_get_pixel(bmpfile_t *bmp, uint32_t x, uint32_t y);
135 bool bmp_set_pixel(bmpfile_t *bmp, uint32_t x, uint32_t y, rgb_pixel_t pixel);
137 bool bmp_save(bmpfile_t *bmp, const char *filename);
141 #endif /* __bmpfile_h__ */