Change DecodeBitmap to use unsigned ints

Why would an image decoder ever return a _negative_ image
width/height?
This commit is contained in:
Clownacy 2020-01-26 23:59:04 +00:00
parent 4f7bd116f6
commit 2ef48bea8a
3 changed files with 7 additions and 7 deletions

View file

@ -8,9 +8,9 @@
#define STBI_NO_LINEAR #define STBI_NO_LINEAR
#include "stb_image.h" #include "stb_image.h"
unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, int *width, int *height) 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, width, height, NULL, 3); return stbi_load_from_memory(in_buffer, in_buffer_size, (int*)width, (int*)height, NULL, 3);
} }
void FreeBitmap(unsigned char *buffer) void FreeBitmap(unsigned char *buffer)

View file

@ -2,5 +2,5 @@
#include <stddef.h> #include <stddef.h>
unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, int *width, int *height); unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, unsigned int *width, unsigned int *height);
void FreeBitmap(unsigned char *buffer); void FreeBitmap(unsigned char *buffer);

View file

@ -223,7 +223,7 @@ BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no)
if (data == NULL) if (data == NULL)
return FALSE; return FALSE;
int width, height; unsigned int width, height;
unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height); unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
if (image_buffer == NULL) if (image_buffer == NULL)
@ -291,7 +291,7 @@ BOOL MakeSurface_File(const char *name, SurfaceID surf_no)
return FALSE; return FALSE;
} }
int width, height; unsigned int width, height;
unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height); unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
free(data); free(data);
@ -339,7 +339,7 @@ BOOL ReloadBitmap_Resource(const char *name, SurfaceID surf_no)
if (data == NULL) if (data == NULL)
return FALSE; return FALSE;
int width, height; unsigned int width, height;
unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height); unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
if (!ScaleAndUploadSurface(image_buffer, width, height, surf_no)) if (!ScaleAndUploadSurface(image_buffer, width, height, surf_no))
@ -387,7 +387,7 @@ BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no)
return FALSE; return FALSE;
} }
int width, height; unsigned int width, height;
unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height); unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
free(data); free(data);