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