proyecto-carga-electrica/main/utils.c
2025-10-30 00:55:27 -06:00

33 lines
817 B
C

#define STB_IMAGE_IMPLEMENTATION
#include <skr/skr.h>
#include <stb_image.h>
unsigned char* m_skr_load_image_from_file(const char* path, int* width,
int* height, int* channels) {
stbi_set_flip_vertically_on_load(1);
int w = 0, h = 0, ch = 0;
unsigned char* data = stbi_load(path, &w, &h, &ch, 0);
if (!data) {
const char* reason = stbi_failure_reason();
m_skr_last_error_set("stb_image failed to load %s: %s", path,
reason ? reason : "unknown error");
return NULL;
}
if (width)
*width = w;
if (height)
*height = h;
if (channels)
*channels = ch;
m_skr_last_error_clear();
return data;
}
void m_skr_free_image(unsigned char* image_data) {
if (image_data)
stbi_image_free(image_data);
m_skr_last_error_clear();
}