summaryrefslogtreecommitdiffhomepage
path: root/src/external/stb_image.h
diff options
context:
space:
mode:
authorRay <[email protected]>2019-04-23 16:01:18 +0200
committerRay <[email protected]>2019-04-23 16:01:18 +0200
commit372d77957fdc73991dca3f406c71a2c9a24b9e03 (patch)
tree66a973cb01758f7cf9ad6eca57d739a0a0cd4769 /src/external/stb_image.h
parent958bf43eac6a71815c2815000b54e40d46e6c419 (diff)
downloadraylib-372d77957fdc73991dca3f406c71a2c9a24b9e03.tar.gz
raylib-372d77957fdc73991dca3f406c71a2c9a24b9e03.zip
Update STB libraries to latest version
Diffstat (limited to 'src/external/stb_image.h')
-rw-r--r--src/external/stb_image.h44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/external/stb_image.h b/src/external/stb_image.h
index 5a6c863f..a6202a31 100644
--- a/src/external/stb_image.h
+++ b/src/external/stb_image.h
@@ -1,4 +1,4 @@
-/* stb_image - v2.20 - public domain image loader - http://nothings.org/stb
+/* stb_image - v2.22 - public domain image loader - http://nothings.org/stb
no warranty implied; use at your own risk
Do this:
@@ -48,6 +48,8 @@ LICENSE
RECENT REVISION HISTORY:
+ 2.22 (2019-03-04) gif fixes, fix warnings
+ 2.21 (2019-02-25) fix typo in comment
2.20 (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs
2.19 (2018-02-11) fix warning
2.18 (2018-01-30) fix warnings
@@ -168,7 +170,7 @@ RECENT REVISION HISTORY:
// If compiling for Windows and you wish to use Unicode filenames, compile
// with
// #define STBI_WINDOWS_UTF8
-// and pass utf8-encoded filenames. Call stbiw_convert_wchar_to_utf8 to convert
+// and pass utf8-encoded filenames. Call stbi_convert_wchar_to_utf8 to convert
// Windows wchar_t filenames to utf8.
//
// ===========================================================================
@@ -338,11 +340,13 @@ typedef unsigned short stbi_us;
extern "C" {
#endif
+#ifndef STBIDEF
#ifdef STB_IMAGE_STATIC
#define STBIDEF static
#else
#define STBIDEF extern
#endif
+#endif
//////////////////////////////////////////////////////////////////////////////
//
@@ -1181,7 +1185,7 @@ STBI_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input)
{
- return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, bufferlen, NULL, NULL);
+ return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL, NULL);
}
#endif
@@ -3658,7 +3662,7 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp
int k;
unsigned int i,j;
stbi_uc *output;
- stbi_uc *coutput[4];
+ stbi_uc *coutput[4] = { NULL, NULL, NULL, NULL };
stbi__resample res_comp[4];
@@ -6411,18 +6415,22 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
// on first frame, any non-written pixels get the background colour (non-transparent)
first_frame = 0;
if (g->out == 0) {
- if (!stbi__gif_header(s, g, comp,0)) return 0; // stbi__g_failure_reason set by stbi__gif_header
- g->out = (stbi_uc *) stbi__malloc(4 * g->w * g->h);
- g->background = (stbi_uc *) stbi__malloc(4 * g->w * g->h);
- g->history = (stbi_uc *) stbi__malloc(g->w * g->h);
- if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");
+ if (!stbi__gif_header(s, g, comp,0)) return 0; // stbi__g_failure_reason set by stbi__gif_header
+ if (!stbi__mad3sizes_valid(4, g->w, g->h, 0))
+ return stbi__errpuc("too large", "GIF image is too large");
+ pcount = g->w * g->h;
+ g->out = (stbi_uc *) stbi__malloc(4 * pcount);
+ g->background = (stbi_uc *) stbi__malloc(4 * pcount);
+ g->history = (stbi_uc *) stbi__malloc(pcount);
+ if (!g->out || !g->background || !g->history)
+ return stbi__errpuc("outofmem", "Out of memory");
// image is treated as "transparent" at the start - ie, nothing overwrites the current background;
// background colour is only used for pixels that are not rendered first frame, after that "background"
// color refers to the color that was there the previous frame.
- memset( g->out, 0x00, 4 * g->w * g->h );
- memset( g->background, 0x00, 4 * g->w * g->h ); // state of the background (starts transparent)
- memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame
+ memset(g->out, 0x00, 4 * pcount);
+ memset(g->background, 0x00, 4 * pcount); // state of the background (starts transparent)
+ memset(g->history, 0x00, pcount); // pixels that were affected previous frame
first_frame = 1;
} else {
// second frame - how do we dispoase of the previous one?
@@ -6483,6 +6491,13 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
g->cur_x = g->start_x;
g->cur_y = g->start_y;
+ // if the width of the specified rectangle is 0, that means
+ // we may not see *any* pixels or the image is malformed;
+ // to make sure this is caught, move the current y down to
+ // max_y (which is what out_gif_code checks).
+ if (w == 0)
+ g->cur_y = g->max_y;
+
g->lflags = stbi__get8(s);
if (g->lflags & 0x40) {
@@ -6502,7 +6517,7 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
return stbi__errpuc("missing color table", "Corrupt GIF");
o = stbi__process_gif_raster(s, g);
- if (o == NULL) return NULL;
+ if (!o) return NULL;
// if this was the first frame,
pcount = g->w * g->h;
@@ -6642,6 +6657,9 @@ static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req
// can be done for multiple frames.
if (req_comp && req_comp != 4)
u = stbi__convert_format(u, 4, req_comp, g.w, g.h);
+ } else if (g.out) {
+ // if there was an error and we allocated an image buffer, free it!
+ STBI_FREE(g.out);
}
// free buffers needed for multiple frame loading;