some improvements to bmp_write_file function (still untested!)
[my-code/api.git] / bmp / bmp.h
1 /* bmp.h -- bmp headers */
2
3 #ifndef BMP_H
4 #define BMP_H
5
6 /* includes */
7 #define _GNU_SOURCE
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11
12 /* defines */
13 #define B_SUCCESS 1
14 #define B_ERROR -1
15 #define B_WRONG_MODE -2
16 #define B_NO_FILE -3
17 #define B_NO_HI -4
18 #define B_NO_SUPPORT -5
19 #define B_HI_FAIL -6
20 #define B_E_MEM -7
21 #define B_E_READ_DATA -8
22 #define B_E_WRITE_DATA -9
23 #define MAX_CHARS_FILE 32
24 #define BMP_H_SIZE 14
25 #define BMP_I_SIZE 40
26
27 /* bmp specific variables */
28 typedef struct s_bmp_hdr {
29   unsigned short int identifier;
30   unsigned int size;
31   unsigned short int reserved1;
32   unsigned short int reserved2;
33   unsigned int offset; /* <- 14 + 40 bytes = 0x36 */
34 } t_bmp_hdr; /* 14 bytes */
35
36 typedef struct s_bmp_info {
37   unsigned int size; /* 40 bytes = 0x28 */
38   int width;
39   int height;
40   unsigned short int planes;
41   unsigned short int bpp;
42   unsigned int compression;
43   unsigned int imagesize;
44   unsigned int xres;
45   unsigned int yres;
46   unsigned int noc;
47   unsigned int ic;
48 } t_bmp_info; /* 40 bytes */
49
50 typedef struct s_pixel {
51   unsigned char r;
52   unsigned char g;
53   unsigned char b;
54 } t_pixel;
55
56 typedef struct s_bmp {
57   int outfd;
58   int width;
59   int height;
60   unsigned char mode;
61 #define READ (1<<0)
62 #define WRITE (1<<1)
63   char file[MAX_CHARS_FILE];
64   int fd;
65   t_bmp_hdr hdr;
66   t_bmp_info info;
67   t_pixel *map;
68 } t_bmp;
69
70 /* function prototypes */
71 int bmp_init(t_bmp *bmp);
72 int bmp_shutdown(t_bmp *bmp);
73
74 #endif