shithub: cstory

Download patch

ref: f127010848d7f03ad527cf0c24fba4d931c723c8
parent: 30dda63671f5f546e7218b0c391888e70ebd7ded
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Jan 27 10:07:08 EST 2020

Use stb_image's file API

Streams data, instead of reading the whole file into memory.

--- 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* 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)
--