-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcub3d_bitmap_write.c
executable file
·59 lines (54 loc) · 1.96 KB
/
cub3d_bitmap_write.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d_bitmap_write.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mg <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/15 23:47:30 by mg #+# #+# */
/* Updated: 2020/10/07 14:55:03 by mg ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int c3d_bitmap_write_header(int fd, t_image *img)
{
int y;
int tmp;
unsigned char bmpfileheader[54];
unsigned long filesize;
y = 0;
filesize = c3d_bitmap_size(img->width, img->height);
ft_printf("Bitmap File Size: %u\n", filesize);
while (y < 54)
bmpfileheader[y++] = (unsigned char)(0);
bmpfileheader[0] = (unsigned char)('B');
bmpfileheader[1] = (unsigned char)('M');
c3d_bitmap_write_int_in_char(bmpfileheader + 2, filesize);
bmpfileheader[10] = (unsigned char)(54);
bmpfileheader[14] = (unsigned char)(40);
tmp = img->width;
c3d_bitmap_write_int_in_char(bmpfileheader + 18, tmp);
tmp = img->height;
c3d_bitmap_write_int_in_char(bmpfileheader + 22, tmp);
bmpfileheader[27] = (unsigned char)(1);
bmpfileheader[28] = (unsigned char)(24);
return (!(write(fd, bmpfileheader, 54) < 0));
}
int c3d_bitmap_write_data(int fd, t_image *img)
{
int y;
int x;
uint32_t color;
y = img->height;
while (y--)
{
x = -1;
while (++x < img->width)
{
color = c3d_pixel_get_color(img, x, y);
if (write(fd, &color, 3) < 0)
return (0);
}
}
return (1);
}