From 66022c08fba6fd2e11348b72bc79307fa7011975 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Thu, 6 Apr 2023 15:30:01 +0200 Subject: [PATCH] removing xpm support bc frick xpm --- includes/mlx.h | 7 +------ src/core/application.cpp | 23 +---------------------- src/core/application.h | 6 +----- src/core/bridge.cpp | 18 +----------------- src/utils/xpm_reader.cpp | 35 +++++++++++++++++++++++++++++------ test/main.c | 34 +--------------------------------- 6 files changed, 34 insertions(+), 89 deletions(-) diff --git a/includes/mlx.h b/includes/mlx.h index 6ccd485..3d89c00 100644 --- a/includes/mlx.h +++ b/includes/mlx.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */ -/* Updated: 2023/04/04 20:30:48 by maldavid ### ########.fr */ +/* Updated: 2023/04/06 15:27:07 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,11 +43,6 @@ void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height); void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height); void* mlx_bmp_file_to_image(void* mlx, char* filename, int* width, int* height); -#ifndef MLX_NO_XPM - void* mlx_xpm_file_to_image(void* mlx, char* filename, int* width, int* height); - void* mlx_xpm_to_image(void* mlx, char** xpm_data, int* width, int* height); -#endif - int mlx_clear_window(void* mlx, void* win); int mlx_destroy_window(void* mlx, void* win); diff --git a/src/core/application.cpp b/src/core/application.cpp index bd5440f..192239b 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */ -/* Updated: 2023/04/05 13:42:39 by maldavid ### ########.fr */ +/* Updated: 2023/04/06 15:27:21 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -63,27 +63,6 @@ namespace mlx::core return map; } - void* Application::newXpmTexture(char** data, int* w, int* h) - { - std::vector pixels = parseXpmData(data, w, h); - std::shared_ptr texture = std::make_shared(); - texture->create(pixels.data(), *w, *h, VK_FORMAT_R8G8B8A8_UNORM); - TextureID id = _texture_lib.addTextureToLibrary(texture); - _texture_ids.push_back(id); - return &_texture_ids.back(); - } - - void* Application::newXpmTexture(std::string filename, int* w, int* h) - { - /* - std::shared_ptr texture = std::make_shared(); - texture->create(reinterpret_cast(xpm_image.data), *w, *h, VK_FORMAT_R8G8B8A8_UNORM); - TextureID id = _texture_lib.addTextureToLibrary(texture); - _texture_ids.push_back(id); - return &_texture_ids.back(); - */ - } - void Application::destroyTexture(void* ptr) { vkDeviceWaitIdle(Render_Core::get().getDevice().get()); diff --git a/src/core/application.h b/src/core/application.h index aad77e6..6fcd529 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */ -/* Updated: 2023/04/04 20:53:21 by maldavid ### ########.fr */ +/* Updated: 2023/04/06 15:27:32 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,10 +49,6 @@ namespace mlx::core inline void pixelPut(void* win_ptr, int x, int y, int color) const noexcept; void* newTexture(int w, int h); - #ifndef MLX_NO_XPM - void* newXpmTexture(std::string filename, int* w, int* h); - void* newXpmTexture(char** data, int* w, int* h); - #endif void* newStbTexture(char* file, int* w, int* h); // stb textures are format managed by stb image (png, jpg, bpm, ...) char* mapTexture(void* img_ptr, int* bits_per_pixel, int* size_line, int* endian); inline void texturePut(void* win_ptr, void* img, int x, int y); diff --git a/src/core/bridge.cpp b/src/core/bridge.cpp index e93f5fe..07d799d 100644 --- a/src/core/bridge.cpp +++ b/src/core/bridge.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */ -/* Updated: 2023/04/04 21:02:29 by maldavid ### ########.fr */ +/* Updated: 2023/04/06 15:27:54 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,10 +16,6 @@ #include #include -#ifndef MLX_NO_XPM - #include -#endif - extern "C" { void* mlx_init() @@ -140,18 +136,6 @@ extern "C" return static_cast(mlx)->newStbTexture(filename, width, height); } -#ifndef MLX_NO_XPM - void* mlx_xpm_file_to_image(void* mlx, char* filename, int* width, int* height) - { - return static_cast(mlx)->newXpmTexture(std::string(filename), width, height); - } - - void* mlx_xpm_to_image(void* mlx, char** xpm_data, int* width, int* height) - { - return static_cast(mlx)->newXpmTexture(xpm_data, width, height); - } -#endif - int mlx_pixel_put(void* mlx, void* win, int x, int y, int color) { static_cast(mlx)->pixelPut(win, x, y, color); diff --git a/src/utils/xpm_reader.cpp b/src/utils/xpm_reader.cpp index 0041945..021c05b 100644 --- a/src/utils/xpm_reader.cpp +++ b/src/utils/xpm_reader.cpp @@ -6,13 +6,15 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/05 13:37:21 by maldavid #+# #+# */ -/* Updated: 2023/04/05 13:53:30 by maldavid ### ########.fr */ +/* Updated: 2023/04/06 15:20:14 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include +#include +#include namespace mlx { @@ -29,12 +31,19 @@ namespace mlx return {}; } - uint32_t width; - uint32_t height; - uint32_t ncolors; - uint32_t cpp; // chars per pixels + int32_t width = -1; + int32_t height = -1; + int32_t ncolors = -1; + int32_t cpp = -1; // chars per pixels + // + std::stringstream stream; - if(std::sscanf(data[0], "%d %d %d %d", &width, &height, &ncolors, &cpp) != 4) + stream.str(data[0]); + stream >> width; + stream >> height; + stream >> ncolors; + stream >> cpp; + if(width == -1 || height == -1 || ncolors == -1 || cpp == -1 || !stream.eof()) { core::error::report(e_kind::error, "Xpm reader : invalid pixmap description"); return {}; @@ -42,5 +51,19 @@ namespace mlx *w = width; *h = height; + + stream.clear(); + std::vector colors; + colors.reserve(ncolors); + std::cout << ncolors << std::endl; + for(int32_t i = 1; i < ncolors; ++i) + { + std::cout << (bool)(i < ncolors) << std::endl; + stream.str(data[i]); + std::string c; + stream >> c; + + std::cout << ncolors << " " << i << " " << c << std::endl; + } } } diff --git a/test/main.c b/test/main.c index 4c59a8b..b8770de 100644 --- a/test/main.c +++ b/test/main.c @@ -6,39 +6,13 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */ -/* Updated: 2023/04/05 13:03:09 by maldavid ### ########.fr */ +/* Updated: 2023/04/06 15:26:57 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "../includes/mlx.h" -static char* exemple_xpm[] = { -"24 20 3 1", -" c None", -". c #3A32E4", -"+ c #E43232", -" ", -" .. ", -" .... ", -" ......++++++++ ", -" .........+++++++ ", -" ..........+++++++ ", -" ............++++++ ", -" .............++++++ ", -" ..............++++ ", -" +.............+++ ", -" ++.............++ ", -" +++.............+ ", -" +++++............. ", -" ++++++.............. ", -" ++++++++............ ", -" +++++++++........... ", -" +++++++++......... ", -" ++++++++++....... ", -" ++++++++++..... ", -" +++++++++ ... "}; - typedef struct s_mlx { void *mlx; @@ -59,13 +33,11 @@ int update(t_mlx *mlx) mlx_pixel_put(mlx->mlx, mlx->win, 399 - j, j, 0xFF0000FF); j++; } - /* i++; if (i == 5000) mlx_clear_window(mlx->mlx, mlx->win); if (i > 10000) mlx_loop_end(mlx->mlx); - */ return (0); } @@ -99,7 +71,6 @@ int main(void) int w; int h; void *img; - void *pic; mlx.mlx = mlx_init(); mlx.win = mlx_new_window(mlx.mlx, 400, 400, "My window"); @@ -108,12 +79,9 @@ int main(void) mlx_put_image_to_window(mlx.mlx, mlx.win, mlx.logo, 200, 200); img = create_image(&mlx); mlx_put_image_to_window(mlx.mlx, mlx.win, img, 200, 20); - pic = mlx_xpm_to_image(mlx.mlx, exemple_xpm, &w, &h); - mlx_put_image_to_window(mlx.mlx, mlx.win, pic, 100, 20); mlx_loop_hook(mlx.mlx, update, &mlx); mlx_loop(mlx.mlx); mlx_destroy_image(mlx.mlx, img); - mlx_destroy_image(mlx.mlx, pic); mlx_destroy_image(mlx.mlx, mlx.logo); mlx_destroy_window(mlx.mlx, mlx.win); mlx_destroy_display(mlx.mlx);