-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenshot.c
executable file
·101 lines (89 loc) · 2.32 KB
/
screenshot.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* screenshot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bmerchin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/23 11:07:48 by bmerchin #+# #+# */
/* Updated: 2021/02/23 11:07:49 by bmerchin ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void bmp_top_info(t_data *data, int fd)
{
int buff;
int i;
write(fd, "BM", 2);
buff = 14 + 40 + 4 * data->x_screen_size * data->y_screen_size;
write(fd, &buff, 4);
buff = 0;
write(fd, &buff, 4);
buff = 54;
write(fd, &buff, 4);
buff = 40;
write(fd, &buff, 4);
buff = data->x_screen_size;
write(fd, &buff, 4);
buff = data->y_screen_size;
write(fd, &buff, 4);
buff = 1;
write(fd, &buff, 2);
buff = data->bits_per_pixel;
write(fd, &buff, 2);
buff = 0;
i = 0;
while (i++ < 6)
write(fd, &buff, 4);
}
void screenshot(t_data *data)
{
int fd;
int x;
int y;
fd = open("screenshot.bmp", O_CREAT | O_RDWR);
bmp_top_info(data, fd);
y = data->y_screen_size - 1;
while (y >= 0)
{
x = 0;
while (x < data->x_screen_size)
{
write(fd, &data->addr[y * data->line_length + x * 4], 4);
x++;
}
y--;
}
}
void save_image(t_data *data)
{
if (data->save == 1)
{
if (MINIMAP_SIZE * data->x_map <= data->x_screen_size &&
MINIMAP_SIZE * data->y_map <= data->y_screen_size && BONUS)
{
add_minimap_and_company(data);
add_lifebar(data);
add_hud(data);
}
screenshot(data);
exit_free(data);
}
}
#if LINUX == 1
void screen_resize(t_data *data)
{
int x;
int y;
mlx_get_screen_size(data->mlx, &x, &y);
if (data->x_screen_size > x && data->save == 0)
data->x_screen_size = x;
if (data->y_screen_size > y && data->save == 0)
data->y_screen_size = y;
}
#else
void screen_resize(t_data *data)
{
(void)data;
}
#endif