Added DecodeBitmapFromFile
This commit is contained in:
parent
2ef48bea8a
commit
1cffacb72e
3 changed files with 22 additions and 25 deletions
|
@ -8,11 +8,30 @@
|
|||
#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)
|
||||
{
|
||||
stbi_image_free(buffer);
|
||||
|
|
|
@ -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);
|
||||
|
|
27
src/Draw.cpp
27
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,19 +281,8 @@ BOOL MakeSurface_File(const char *name, SurfaceID surf_no)
|
|||
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)
|
||||
{
|
||||
|
@ -378,19 +366,8 @@ BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no)
|
|||
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)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue