changes in bmp api
[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 B_E_GEOMETRY -10
28 #define MAX_CHARS_FILE 32
29 #define BMP_H_SIZE 14
30 #define BMP_I_SIZE 40
31
32 /* bmp specific variables */
33 typedef struct s_bmp_hdr {
34   unsigned short int identifier;
35   unsigned int size;
36   unsigned short int reserved1;
37   unsigned short int reserved2;
38   unsigned int offset; /* <- 14 + 40 bytes = 0x36 */
39 } __attribute__ ((packed)) t_bmp_hdr; /* 14 bytes */
40
41 typedef struct s_bmp_info {
42   unsigned int size; /* 40 bytes = 0x28 */
43   int width;
44   int height;
45   unsigned short int planes;
46   unsigned short int bpp;
47   unsigned int compression;
48   unsigned int imagesize;
49   unsigned int xres;
50   unsigned int yres;
51   unsigned int noc;
52   unsigned int ic;
53 } __attribute__ ((packed)) t_bmp_info; /* 40 bytes */
54
55 typedef struct s_pixel {
56   unsigned char r;
57   unsigned char g;
58   unsigned char b;
59 } __attribute__ ((packed)) t_pixel;
60
61 typedef struct s_bmp {
62   int outfd;
63   int width;
64   int height;
65   unsigned char mode;
66 #define READ (1<<0)
67 #define WRITE (1<<1)
68   char file[MAX_CHARS_FILE];
69   int fd;
70   t_bmp_hdr hdr;
71   t_bmp_info info;
72   t_pixel *map;
73 } t_bmp;
74
75 /* function prototypes */
76 int bmp_init(t_bmp *bmp,int outfd);
77 int bmp_shutdown(t_bmp *bmp);
78 int bmp_check_header_and_info(t_bmp *bmp);
79 int bmp_alloc_map(t_bmp *bmp);
80 int bmp_write_file(t_bmp *bmp);
81 int bmp_cut_bottom(t_bmp *dst,t_bmp *src,int dz);
82 int bmp_read_file(t_bmp *bmp);
83
84 #endif