ref: 1cffacb72e5adb4a2903c99adc7baea8b84bf4da
parent: 2ef48bea8aad4d2e2d7450eff71b0adb6bb2ac44
author: Clownacy <Clownacy@users.noreply.github.com>
date: Sun Jan 26 19:30:54 EST 2020
Added DecodeBitmapFromFile
--- a/src/Bitmap.cpp
+++ b/src/Bitmap.cpp
@@ -8,9 +8,28 @@
#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);
+}
+
+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;
}
void FreeBitmap(unsigned char *buffer)
--- a/src/Bitmap.h
+++ b/src/Bitmap.h
@@ -3,4 +3,5 @@
#include <stddef.h>
unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, unsigned int *width, unsigned int *height);
+unsigned char* DecodeBitmapFromFile(const char *path, unsigned int *width, unsigned int *height);
void FreeBitmap(unsigned char *buffer);
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -13,7 +13,6 @@
#include "Bitmap.h"
#include "CommonDefines.h"
#include "Ending.h"
-#include "File.h"
#include "Font.h"
#include "Generic.h"
#include "Main.h"
@@ -282,20 +281,9 @@
return FALSE;
}
- size_t size;
- unsigned char *data = LoadFileToMemory(path, &size);
-
- if (data == NULL)
- {
- PrintBitmapError(path, 1);
- return FALSE;
- }
-
unsigned int width, height;
- unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
+ unsigned char *image_buffer = DecodeBitmapFromFile(path, &width, &height);
- free(data);
-
if (image_buffer == NULL)
{
PrintBitmapError(path, 1);
@@ -378,19 +366,8 @@
return FALSE;
}
- size_t size;
- unsigned char *data = LoadFileToMemory(path, &size);
-
- if (data == NULL)
- {
- PrintBitmapError(path, 1);
- return FALSE;
- }
-
unsigned int width, height;
- unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
-
- free(data);
+ unsigned char *image_buffer = DecodeBitmapFromFile(path, &width, &height);
if (image_buffer == NULL)
{
--
⑨