-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpscreen.c
87 lines (78 loc) · 2.64 KB
/
pscreen.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pscreen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbozhko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/07/21 18:33:39 by rbozhko #+# #+# */
/* Updated: 2018/07/21 18:33:41 by rbozhko ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
char *ft_get_fname(const t_map *map)
{
time_t rawtime;
char *filename;
char *temp;
struct tm *timeinfo;
char *fractol_name;
time(&rawtime);
timeinfo = localtime(&rawtime);
filename = ft_get_time_part(asctime(timeinfo));
temp = ft_strjoin(filename, ".jpg");
ft_strdel(&filename);
fractol_name = ft_get_fractol_name(map);
filename = ft_strjoin(fractol_name, temp);
ft_strdel(&fractol_name);
ft_strdel(&temp);
return (filename);
}
FILE *ft_get_file(t_map *map)
{
char *filename;
FILE *outfile;
filename = ft_get_fname(map);
outfile = fopen(filename, "wb");
ft_strdel(&filename);
if (!outfile)
ft_throw_exception("Error opening output jpeg file.\n");
return (outfile);
}
void ft_init_st(struct jpeg_compress_struct *c, t_map *m, FILE *o)
{
struct jpeg_error_mgr jerr;
c->err = jpeg_std_error(&jerr);
jpeg_create_compress(c);
jpeg_stdio_dest(c, o);
c->image_width = m->win_width;
c->image_height = m->win_height;
c->input_components = 3;
c->in_color_space = JCS_RGB;
jpeg_set_defaults(c);
jpeg_start_compress(c, TRUE);
}
int ft_make_printscreen(t_map *map)
{
FILE *outfile;
struct jpeg_compress_struct cinfo;
JSAMPROW row_pointer[1];
unsigned char *temp;
outfile = ft_get_file(map);
ft_init_st(&cinfo, map, outfile);
if ((map->win_height * map->win_width) < ALLOWED_WIN_AREA_FOR_THREADS_COEF)
temp = ft_get_proper(map);
else
temp = ft_get_threads(map, cinfo.input_components, 0, 0);
while (cinfo.next_scanline < cinfo.image_height)
{
row_pointer[0] = &temp[cinfo.next_scanline * cinfo.image_width
* cinfo.input_components];
jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
fclose(outfile);
ft_strdel((char**)&temp);
return (1);
}