working on xpm support

This commit is contained in:
2023-04-06 12:56:36 +02:00
parent 27000b6163
commit fbe97415cf
6 changed files with 83 additions and 74 deletions

46
src/utils/xpm_reader.cpp git.filemode.normal_file
View File

@@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* xpm_reader.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#include <utils/xpm_reader.h>
#include <core/errors.h>
#include <cstdio>
namespace mlx
{
std::vector<uint8_t> parseXpmFile(std::filesystem::path file, int* w, int* h)
{
return {};
}
std::vector<uint8_t> parseXpmData(char** data, int* w, int* h)
{
if(data == nullptr)
{
core::error::report(e_kind::error, "Xpm reader : null data");
return {};
}
uint32_t width;
uint32_t height;
uint32_t ncolors;
uint32_t cpp; // chars per pixels
if(std::sscanf(data[0], "%d %d %d %d", &width, &height, &ncolors, &cpp) != 4)
{
core::error::report(e_kind::error, "Xpm reader : invalid pixmap description");
return {};
}
*w = width;
*h = height;
}
}

26
src/utils/xpm_reader.h git.filemode.normal_file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* xpm_reader.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/05 13:25:55 by maldavid #+# #+# */
/* Updated: 2023/04/05 13:35:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_XPM_READER__
#define __MLX_XPM_READER__
#include <filesystem>
#include <cstdint>
#include <vector>
namespace mlx
{
std::vector<uint8_t> parseXpmData(char** data, int* w, int* h);
std::vector<uint8_t> parseXpmFile(std::filesystem::path file, int* w, int* h);
}
#endif