Use stb_image's file API

Streams data, instead of reading the whole file into memory.
This commit is contained in:
Clownacy 2020-01-27 15:07:08 +00:00
parent 30dda63671
commit f127010848

View file

@ -4,12 +4,9 @@
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#define STBI_ONLY_BMP #define STBI_ONLY_BMP
#define STBI_NO_STDIO
#define STBI_NO_LINEAR #define STBI_NO_LINEAR
#include "stb_image.h" #include "stb_image.h"
#include "File.h"
unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, unsigned int *width, unsigned int *height) unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, unsigned int *width, unsigned int *height)
{ {
return stbi_load_from_memory(in_buffer, in_buffer_size, (int*)width, (int*)height, NULL, 3); return stbi_load_from_memory(in_buffer, in_buffer_size, (int*)width, (int*)height, NULL, 3);
@ -17,19 +14,7 @@ unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_siz
unsigned char* DecodeBitmapFromFile(const char *path, unsigned int *width, unsigned int *height) unsigned char* DecodeBitmapFromFile(const char *path, unsigned int *width, unsigned int *height)
{ {
unsigned char *image_buffer = NULL; return stbi_load(path, (int*)width, (int*)height, NULL, 3);
size_t size;
unsigned char *data = LoadFileToMemory(path, &size);
if (data != NULL)
{
image_buffer = DecodeBitmap(data, size, width, height);
free(data);
}
return image_buffer;
} }
void FreeBitmap(unsigned char *buffer) void FreeBitmap(unsigned char *buffer)