4dd47f5267cf826d8e7e905830b5b0c28260d45f
[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 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14 #include <unistd.h>
15
16 /* defines */
17 #define B_SUCCESS 1
18 #define B_ERROR -1
19 #define B_WRONG_MODE -2
20 #define B_NO_FILE -3
21 #define B_NO_HI -4
22 #define B_NO_SUPPORT -5
23 #define B_HI_FAIL -6
24 #define B_E_MEM -7
25 #define B_E_READ_DATA -8
26 #define B_E_WRITE_DATA -9
27 #define MAX_CHARS_FILE 32
28 #define BMP_H_SIZE 14
29 #define BMP_I_SIZE 40
30
31 /* bmp specific variables */
32 typedef struct s_bmp_hdr {
33   unsigned short int identifier;
34   unsigned int size;
35   unsigned short int reserved1;
36   unsigned short int reserved2;
37   unsigned int offset; /* <- 14 + 40 bytes = 0x36 */
38 } __attribute__ ((packed)) t_bmp_hdr; /* 14 bytes */
39
40 typedef struct s_bmp_info {
41   unsigned int size; /* 40 bytes = 0x28 */
42   int width;
43   int height;
44   unsigned short int planes;
45   unsigned short int bpp;
46   unsigned int compression;
47   unsigned int imagesize;
48   unsigned int xres;
49   unsigned int yres;
50   unsigned int noc;
51   unsigned int ic;
52 } __attribute__ ((packed)) t_bmp_info; /* 40 bytes */
53
54 typedef struct s_pixel {
55   unsigned char r;
56   unsigned char g;
57   unsigned char b;
58 } __attribute__ ((packed)) t_pixel;
59
60 typedef struct s_bmp {
61   int outfd;
62   int width;
63   int height;
64   unsigned char mode;
65 #define READ (1<<0)
66 #define WRITE (1<<1)
67   char file[MAX_CHARS_FILE];
68   int fd;
69   t_bmp_hdr hdr;
70   t_bmp_info info;
71   t_pixel *map;
72 } t_bmp;
73
74 /* function prototypes */
75 int bmp_init(t_bmp *bmp,int outfd);
76 int bmp_shutdown(t_bmp *bmp);
77 int bmp_check_header_and_info(t_bmp *bmp);
78 int bmp_alloc_map(t_bmp *bmp);
79 int bmp_write_file(t_bmp *bmp);
80 int bmp_read_file(t_bmp *bmp);
81
82 #endif