aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-04 15:21:10 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-04 15:21:10 +0100
commit5db7c4f7d445373d92c41a7cc9aa667e223e5507 (patch)
tree1dff7a6452ad593cf0c7f92d7db35580fb619d94 /src
parentRemoved map print (diff)
download42-cub3d-5db7c4f7d445373d92c41a7cc9aa667e223e5507.tar.gz
42-cub3d-5db7c4f7d445373d92c41a7cc9aa667e223e5507.tar.bz2
42-cub3d-5db7c4f7d445373d92c41a7cc9aa667e223e5507.tar.xz
42-cub3d-5db7c4f7d445373d92c41a7cc9aa667e223e5507.tar.zst
42-cub3d-5db7c4f7d445373d92c41a7cc9aa667e223e5507.zip
tryna save
Diffstat (limited to 'src')
-rw-r--r--src/ft_draw_scene.c3
-rw-r--r--src/ft_error.c (renamed from src/ft_map_error.c)14
-rw-r--r--src/ft_save_to_bmp.c23
3 files changed, 35 insertions, 5 deletions
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c
index 1e16ba5..78a56b4 100644
--- a/src/ft_draw_scene.c
+++ b/src/ft_draw_scene.c
@@ -38,6 +38,7 @@ void
clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp,
&clist->img.sizeline, &clist->img.endian);
ft_castray(clist);
- ft_save_to_bmp();
+ if (ft_save_to_bmp(clist->img.img, clist) < 0)
+ ft_error(FT_ERR_WR_BMP, clist);
mlx_destroy_image(clist->wlist.wlx, clist->img.img);
}
diff --git a/src/ft_map_error.c b/src/ft_error.c
index b777415..b793b96 100644
--- a/src/ft_map_error.c
+++ b/src/ft_error.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_map_error.c :+: :+: :+: */
+/* ft_error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -15,6 +15,16 @@
#include <unistd.h>
int
+ ft_error(const char *errmsg, t_cub *clist)
+{
+ ft_dprintf(STDERR_FILENO, "Error\n");
+ ft_dprintf(STDERR_FILENO,
+ "\033[1;31m%s\033[0m\n",
+ errmsg);
+ return (ft_exit(FT_RET_BMP_ERR, clist));
+}
+
+int
ft_map_error(const char *errmsg, t_cub *clist)
{
ft_dprintf(STDERR_FILENO, "Error\n");
@@ -22,5 +32,5 @@ int
"\033[1;31mMap error: line %lu: %s\033[0m\n",
clist->mlist.line_chk,
errmsg);
- return (ft_exit(4, clist));
+ return (ft_exit(FT_RET_MAP_ERR, clist));
}
diff --git a/src/ft_save_to_bmp.c b/src/ft_save_to_bmp.c
index a510d6b..1118384 100644
--- a/src/ft_save_to_bmp.c
+++ b/src/ft_save_to_bmp.c
@@ -12,8 +12,27 @@
#include <libft.h>
#include <cub3d.h>
+#include <stdlib.h>
+#include <stdint.h>
-void
- ft_save_to_bmp(void)
+static int8_t
+ ft_convert_image_to_bmp(void *img, t_cub *cl)
{
+ int32_t filelen;
+ uint8_t *bmp;
+
+ (void)img;
+ 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)
+ return (0);
+}
+
+int8_t
+ ft_save_to_bmp(void *img, t_cub *cl)
+{
+ if (ft_convert_image_to_bmp(img, cl) < 0)
+ return (-1);
+ return (0);
}