diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-04 16:24:10 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-04 16:24:10 +0100 |
commit | 93e9d655f14a89477e495aece6d91b07594076d8 (patch) | |
tree | e75e792139891fb6007cef8e68cd7f022672c2c0 /src | |
parent | Tab (diff) | |
download | 42-cub3d-93e9d655f14a89477e495aece6d91b07594076d8.tar.gz 42-cub3d-93e9d655f14a89477e495aece6d91b07594076d8.tar.bz2 42-cub3d-93e9d655f14a89477e495aece6d91b07594076d8.tar.xz 42-cub3d-93e9d655f14a89477e495aece6d91b07594076d8.tar.zst 42-cub3d-93e9d655f14a89477e495aece6d91b07594076d8.zip |
Structs inited
Diffstat (limited to '')
-rw-r--r-- | src/ft_draw_scene.c | 8 | ||||
-rw-r--r-- | src/ft_init_bmp.c | 45 | ||||
-rw-r--r-- | src/ft_parse_map.c | 6 | ||||
-rw-r--r-- | src/ft_save_to_bmp.c | 9 |
4 files changed, 48 insertions, 20 deletions
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 9dcc8df..846c2fb 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -33,15 +33,15 @@ void void ft_draw_scene_bmp(t_cub *clist) { - t_bmp bmp; + t_bmp_file bmp_file; clist->img.img = mlx_new_image(clist->wlist.wlx, clist->wlist.x_size, clist->wlist.y_size); clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, &clist->img.sizeline, &clist->img.endian); ft_castray(clist); - bmp = ft_init_bmp(); - if (ft_save_to_bmp(bmp, clist->img.img, clist) < 0) - ft_error(FT_ERR_WR_BMP, clist); + ft_init_bmp(&bmp_file); + if (ft_save_to_bmp(&bmp_file, clist->img.img, clist) < 0) + ft_error(FT_RET_BMP_ERR, FT_ERR_WR_BMP, clist); mlx_destroy_image(clist->wlist.wlx, clist->img.img); } diff --git a/src/ft_init_bmp.c b/src/ft_init_bmp.c index 3236e2f..b123e52 100644 --- a/src/ft_init_bmp.c +++ b/src/ft_init_bmp.c @@ -10,18 +10,45 @@ /* */ /* ************************************************************************** */ +#include <libft.h> #include <cub3d.h> #include <stdint.h> -int8_t - ft_init_bmp(t_bmp_file *bmp_file) +static void + ft_init_bmp_colors(t_bmp_colors *bmp_colors) { - t_bmp_file bmp_file; + bmp_colors->red_mask = 0x00ff0000; + bmp_colors->green_mask = 0x0000ff00; + bmp_colors->blue_mask = 0x000000ff; + bmp_colors->alpha_mask = 0xff000000; + bmp_colors->color_space_type = 0x73524742; + ft_bzero(bmp_colors, 16); +} - bmp_file.file_type = 0x4d42; - bmp_file.file_size = 0; - bmp_file.reserv_one = 0; - bmp_file.reserv_two = 0; - bmp_file.offset_data = 0; - return (bmp_file); +static void + ft_init_bmp_info(t_bmp_info *bmp_info) +{ + bmp_info->size = 0; + bmp_info->width = 0; + bmp_info->height = 0; + bmp_info->planes = 1; + bmp_info->bit_count = 0; + bmp_info->compression = 0; + bmp_info->size_image = 0; + bmp_info->x_pixels_per_meter = 0; + bmp_info->y_pixels_per_meter = 0; + bmp_info->colors_used = 0; + bmp_info->colors_important = 0; +} + +void + ft_init_bmp(t_bmp_file *bmp_file) +{ + bmp_file->file_type = 0x4d42; + bmp_file->file_size = 0; + bmp_file->reserv_one = 0; + bmp_file->reserv_two = 0; + bmp_file->offset_data = 0; + ft_init_bmp_info(&bmp_file->bmp_info); + ft_init_bmp_colors(&bmp_file->bmp_colors); } diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index d3a90af..6a9c5af 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -75,13 +75,13 @@ static int8_t } void - ft_save_name(t_map *mlist, t_cub *clist) + ft_save_name(const char *map_path, t_map *mlist, t_cub *clist) { ft_memdel((void**)mlist->filename); if (!(mlist->filename = (char*)malloc((ft_strlen(map_path) + 1) * sizeof(char)))) ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); - ft_sprintf(mlist->filename, map_path); + ft_sprintf(mlist->filename, "%s", map_path); } void @@ -92,10 +92,10 @@ void if (ft_check_ext(map_path, ".cub") < 0) ft_map_error(FT_ERR_NOT_A_CUB, clist); - ft_save_name(&clist->mlist, clist); fd = open(map_path, O_RDONLY); if (fd < 0) ft_error(FT_RET_NO_MAP, FT_ERR_NO_MAP, clist); + ft_save_name(map_path, &clist->mlist, clist); ret = 1; while (ret != 12 && ret >= 0) ret = ft_parse_it(fd, clist); diff --git a/src/ft_save_to_bmp.c b/src/ft_save_to_bmp.c index f69316f..4bfaace 100644 --- a/src/ft_save_to_bmp.c +++ b/src/ft_save_to_bmp.c @@ -16,23 +16,24 @@ #include <stdint.h> static int8_t - ft_convert_image_to_bmp(void *img, t_cub *cl) + ft_convert_image_to_bmp(t_bmp_file *bmp_file, void *img, t_cub *cl) { int32_t filelen; uint8_t *bmp; (void)img; + (void)bmp_file; filelen = 54 + 3 * cl->wlist.x_size * cl->wlist.y_size; if (!(bmp = (uint8_t*)malloc((filelen - 54) * sizeof(uint8_t)))) return (-1); - ft_memdel((void**)&bmp) + ft_memdel((void**)&bmp); return (0); } int8_t - ft_save_to_bmp(t_bmp bmp, void *img, t_cub *cl) + ft_save_to_bmp(t_bmp_file *bmp_file, void *img, t_cub *cl) { - if (ft_convert_image_to_bmp(img, cl) < 0) + if (ft_convert_image_to_bmp(bmp_file, img, cl) < 0) return (-1); return (0); } |