-
Notifications
You must be signed in to change notification settings - Fork 0
/
save.c
66 lines (59 loc) · 2.02 KB
/
save.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* save.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jserrano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/02 14:19:38 by jserrano #+# #+# */
/* Updated: 2020/11/05 15:17:17 by jserrano ### ########.fr */
/* */
/* ************************************************************************** */
#include "raymarching.h"
static void dec_hex_endian(int len, unsigned char *size)
{
int i;
i = -1;
while (++i < 4)
{
size[i] = len % 256;
len /= 256;
}
}
static void write_header(t_data *param, int fd)
{
unsigned char bytes[4];
int len;
len = param->scr.y * param->img.line_length +
param->scr.x * (param->img.bits_per_pixel / 8);
write(fd, "BM", 2);
dec_hex_endian(len + 54, bytes);
write(fd, bytes, 4);
write(fd, "\0\0\0\0\66\0\0\0\50\0\0\0", 12);
dec_hex_endian(param->scr.x, bytes);
write(fd, bytes, 4);
dec_hex_endian(param->scr.y, bytes);
write(fd, bytes, 4);
write(fd, "\1\0\40\0\0\0\0\0", 8);
dec_hex_endian(0, bytes);
write(fd, bytes, 4);
dec_hex_endian(param->scr.x, bytes);
write(fd, bytes, 4);
dec_hex_endian(param->scr.y, bytes);
write(fd, bytes, 4);
write(fd, "\0\0\0\0\0\0\0\0", 8);
}
void save_scr(t_data *param)
{
int fd;
int i;
param->key = KEY_ENT;
show_obj(param);
fd = open("screenshot.bmp", O_WRONLY | O_CREAT);
write_header(param, fd);
i = param->scr.y;
while (--i >= 0)
write(fd, param->img.addr + i * param->img.line_length,
param->scr.x * (param->img.bits_per_pixel / 8));
close(fd);
}