libbmp: Add libbmp version 0.1.3
[platform/upstream/libbmp.git] / src / bmpfile.h
1 /**
2  * @file bmpfile.h
3  * @brief The BMP library header
4  *
5  * libbmp - BMP library
6  * Copyright (C) 2009 lidaibin(超越无限)
7  * mail: lidaibin@gmail.com
8  *
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.
13  *
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.
18  *
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.
23  *
24  * $Id$
25  */
26
27 #ifndef __bmpfile_h__
28 #define __bmpfile_h__
29
30 #ifdef __cplusplus
31 #define BMP_BEGIN_DECLS extern "C" {
32 #define BMP_END_DECLS }
33 #else
34 #define BMP_BEGIN_DECLS
35 #define BMP_END_DECLS
36 #endif
37
38 BMP_BEGIN_DECLS
39
40 #ifndef bool
41 typedef int bool;
42 #define FALSE (0)
43 #define TRUE !FALSE
44 #endif
45
46 #ifndef uint8_t
47 typedef unsigned char uint8_t;
48 #endif
49
50 #ifndef uint16_t
51 typedef unsigned short uint16_t;
52 #endif
53
54 #ifndef uint32_t
55 typedef unsigned int uint32_t;
56 #endif
57
58 typedef enum {
59   BI_RGB = 0,
60   BI_RLE8,
61   BI_RLE4,
62   BI_BITFIELDS,
63   BI_JPEG,
64   BI_PNG,
65 } bmp_compression_method_t;
66
67 typedef struct {
68   uint8_t blue;
69   uint8_t green;
70   uint8_t red;
71   uint8_t alpha;
72 } rgb_pixel_t;
73
74 typedef struct {
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
80                          CI - OS/2 Color Icon
81                          CP - OS/2 Color Pointer
82                          IC - OS/2 Icon
83                          PT - OS/2 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. */
89 } bmp_header_t;
90
91 typedef struct {
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.
96                              Must be set to 1. */
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.
106                              (pixel per meter) */
107   uint32_t vres;          /* the vertical resolution of the image.
108                              (pixel per meter) */
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;
115
116 typedef struct _bmpfile bmpfile_t;
117
118 bmpfile_t *bmp_create(uint32_t width, uint32_t height, uint32_t depth);
119 /* TODO */
120 /* bmpfile_t *bmp_create_from_file(const char *filename); */
121 void bmp_destroy(bmpfile_t *bmp);
122
123 bmp_header_t bmp_get_header(bmpfile_t *bmp);
124 bmp_dib_v3_header_t bmp_get_dib(bmpfile_t *bmp);
125
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);
129
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);
133
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);
136
137 bool bmp_save(bmpfile_t *bmp, const char *filename);
138
139 BMP_END_DECLS
140
141 #endif /* __bmpfile_h__ */