From 6a0005746978070c86dcac7681db8389c98fd172 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 21 Apr 2020 23:57:07 +0100 Subject: [PATCH] Do not stream bitmaps Again - Wii U SD card IO is terrible, so load the whole file at once instead. --- src/Bitmap.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Bitmap.cpp b/src/Bitmap.cpp index f38ded4c..10947328 100644 --- a/src/Bitmap.cpp +++ b/src/Bitmap.cpp @@ -6,8 +6,11 @@ #define STB_IMAGE_STATIC #define STBI_ONLY_BMP #define STBI_NO_LINEAR +#define STBI_NO_STDIO #include "../external/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); @@ -15,7 +18,14 @@ 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) { - return stbi_load(path, (int*)width, (int*)height, NULL, 3); + size_t file_size; + unsigned char *file_buffer = LoadFileToMemory(path, &file_size); + + unsigned char *pixel_buffer = stbi_load_from_memory(file_buffer, file_size, (int*)width, (int*)height, NULL, 3); + + free(file_buffer); + + return pixel_buffer; } void FreeBitmap(unsigned char *buffer)