-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcub3d_texture_xpm_to_image.c
More file actions
executable file
·62 lines (55 loc) · 2.13 KB
/
cub3d_texture_xpm_to_image.c
File metadata and controls
executable file
·62 lines (55 loc) · 2.13 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d_texture_xpm_to_image.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mg <mg@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/29 15:52:15 by mg #+# #+# */
/* Updated: 2020/10/07 22:36:00 by mg ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
/*
** texture->file = xpm;
*/
void c3d_texture_xpm_to_image(t_param *cub3d, t_image *texture)
{
int fd;
char *xpm;
if (!texture->file)
c3d_print_error(cub3d, "MISSING TEXTURE FILE");
else if (!(xpm = c3d_texture_is_xpm_extension(texture->file)))
c3d_print_error_sys(cub3d, texture->file);
else
ft_strcpy(texture->file, xpm);
if ((fd = open(texture->file, O_RDONLY)) == -1)
c3d_print_error_sys(cub3d, texture->file);
close(fd);
c3d_texture_xpm_to_image_internal(cub3d, texture);
}
void c3d_texture_xpm_to_image_internal(t_param *cub3d, t_image *texture)
{
texture->img_ptr = mlx_xpm_file_to_image(cub3d->mlx, texture->file,
&texture->width, &texture->height);
if (!texture->img_ptr)
c3d_print_error_sys(cub3d, "MLX XPM IMAGE MALLOC");
texture->img_data = mlx_get_data_addr(texture->img_ptr,
&texture->bits_per_pixel, &texture->size_line, &texture->endian);
if (!texture->img_data)
c3d_print_error_sys(cub3d, "MLX XPM IMAGE DATA");
}
char *c3d_texture_is_xpm_extension(char *line)
{
char *file_extension;
char *path;
path = NULL;
file_extension = line + ft_strlen(line) - 4;
if (!ft_strncmp(file_extension, ".xpm", 4))
{
while (!ft_isblank(*(--file_extension)))
;
path = ++file_extension;
}
return (path);
}