mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
removing xpm support bc frick xpm
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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<uint8_t> pixels = parseXpmData(data, w, h);
|
||||
std::shared_ptr<Texture> texture = std::make_shared<Texture>();
|
||||
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> texture = std::make_shared<Texture>();
|
||||
texture->create(reinterpret_cast<uint8_t*>(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());
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/core/render_core.h>
|
||||
#include <filesystem>
|
||||
|
||||
#ifndef MLX_NO_XPM
|
||||
#include <X11/xpm.h>
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void* mlx_init()
|
||||
@@ -140,18 +136,6 @@ extern "C"
|
||||
return static_cast<mlx::core::Application*>(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::core::Application*>(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::core::Application*>(mlx)->newXpmTexture(xpm_data, width, height);
|
||||
}
|
||||
#endif
|
||||
|
||||
int mlx_pixel_put(void* mlx, void* win, int x, int y, int color)
|
||||
{
|
||||
static_cast<mlx::core::Application*>(mlx)->pixelPut(win, x, y, color);
|
||||
|
||||
@@ -6,13 +6,15 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <utils/xpm_reader.h>
|
||||
#include <core/errors.h>
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
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<std::string> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
34
test/main.c
34
test/main.c
@@ -6,39 +6,13 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdio.h>
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user