From f127010848d7f03ad527cf0c24fba4d931c723c8 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 27 Jan 2020 15:07:08 +0000 Subject: [PATCH] Use stb_image's file API Streams data, instead of reading the whole file into memory. --- src/Bitmap.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/Bitmap.cpp b/src/Bitmap.cpp index 954f4dd3..25465184 100644 --- a/src/Bitmap.cpp +++ b/src/Bitmap.cpp @@ -4,12 +4,9 @@ #define STB_IMAGE_IMPLEMENTATION #define STBI_ONLY_BMP -#define STBI_NO_STDIO #define STBI_NO_LINEAR #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) { 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 *image_buffer = NULL; - - size_t size; - unsigned char *data = LoadFileToMemory(path, &size); - - if (data != NULL) - { - image_buffer = DecodeBitmap(data, size, width, height); - - free(data); - } - - return image_buffer; + return stbi_load(path, (int*)width, (int*)height, NULL, 3); } void FreeBitmap(unsigned char *buffer)