Update STB libraries to latest version

This commit is contained in:
Ray
2019-04-23 16:01:18 +02:00
parent 958bf43eac
commit 372d77957f
6 changed files with 68 additions and 53 deletions

View File

@@ -10,7 +10,7 @@
// In addition to the comment block above each function declaration, the API // In addition to the comment block above each function declaration, the API
// has informal documentation here: // has informal documentation here:
// //
// http://github.prideout.net/shapes/ // https://prideout.net/shapes
// //
// For our purposes, a "mesh" is a list of points and a list of triangles; the // For our purposes, a "mesh" is a list of points and a list of triangles; the
// former is a flattened list of three-tuples (32-bit floats) and the latter is // former is a flattened list of three-tuples (32-bit floats) and the latter is

View File

@@ -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 no warranty implied; use at your own risk
Do this: Do this:
@@ -48,6 +48,8 @@ LICENSE
RECENT REVISION HISTORY: 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.20 (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs
2.19 (2018-02-11) fix warning 2.19 (2018-02-11) fix warning
2.18 (2018-01-30) fix warnings 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 // If compiling for Windows and you wish to use Unicode filenames, compile
// with // with
// #define STBI_WINDOWS_UTF8 // #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. // Windows wchar_t filenames to utf8.
// //
// =========================================================================== // ===========================================================================
@@ -338,11 +340,13 @@ typedef unsigned short stbi_us;
extern "C" { extern "C" {
#endif #endif
#ifndef STBIDEF
#ifdef STB_IMAGE_STATIC #ifdef STB_IMAGE_STATIC
#define STBIDEF static #define STBIDEF static
#else #else
#define STBIDEF extern #define STBIDEF extern
#endif #endif
#endif
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
@@ -1181,7 +1185,7 @@ STBI_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8) #if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input) 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 #endif
@@ -3658,7 +3662,7 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp
int k; int k;
unsigned int i,j; unsigned int i,j;
stbi_uc *output; stbi_uc *output;
stbi_uc *coutput[4]; stbi_uc *coutput[4] = { NULL, NULL, NULL, NULL };
stbi__resample res_comp[4]; 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) // on first frame, any non-written pixels get the background colour (non-transparent)
first_frame = 0; first_frame = 0;
if (g->out == 0) { if (g->out == 0) {
if (!stbi__gif_header(s, g, comp,0)) return 0; // stbi__g_failure_reason set by stbi__gif_header 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); if (!stbi__mad3sizes_valid(4, g->w, g->h, 0))
g->background = (stbi_uc *) stbi__malloc(4 * g->w * g->h); return stbi__errpuc("too large", "GIF image is too large");
g->history = (stbi_uc *) stbi__malloc(g->w * g->h); pcount = g->w * g->h;
if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory"); 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; // 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" // 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. // color refers to the color that was there the previous frame.
memset( g->out, 0x00, 4 * g->w * g->h ); memset(g->out, 0x00, 4 * pcount);
memset( g->background, 0x00, 4 * g->w * g->h ); // state of the background (starts transparent) memset(g->background, 0x00, 4 * pcount); // state of the background (starts transparent)
memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame memset(g->history, 0x00, pcount); // pixels that were affected previous frame
first_frame = 1; first_frame = 1;
} else { } else {
// second frame - how do we dispoase of the previous one? // 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_x = g->start_x;
g->cur_y = g->start_y; 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); g->lflags = stbi__get8(s);
if (g->lflags & 0x40) { 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"); return stbi__errpuc("missing color table", "Corrupt GIF");
o = stbi__process_gif_raster(s, g); o = stbi__process_gif_raster(s, g);
if (o == NULL) return NULL; if (!o) return NULL;
// if this was the first frame, // if this was the first frame,
pcount = g->w * g->h; 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. // can be done for multiple frames.
if (req_comp && req_comp != 4) if (req_comp && req_comp != 4)
u = stbi__convert_format(u, 4, req_comp, g.w, g.h); 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; // free buffers needed for multiple frame loading;

View File

@@ -1,4 +1,4 @@
/* stb_image_resize - v0.95 - public domain image resizing /* stb_image_resize - v0.96 - public domain image resizing
by Jorge L Rodriguez (@VinoBS) - 2014 by Jorge L Rodriguez (@VinoBS) - 2014
http://github.com/nothings/stb http://github.com/nothings/stb
@@ -159,6 +159,7 @@
Nathan Reed: warning fixes Nathan Reed: warning fixes
REVISIONS REVISIONS
0.96 (2019-03-04) fixed warnings
0.95 (2017-07-23) fixed warnings 0.95 (2017-07-23) fixed warnings
0.94 (2017-03-18) fixed warnings 0.94 (2017-03-18) fixed warnings
0.93 (2017-03-03) fixed bug with certain combinations of heights 0.93 (2017-03-03) fixed bug with certain combinations of heights
@@ -193,6 +194,7 @@ typedef uint16_t stbir_uint16;
typedef uint32_t stbir_uint32; typedef uint32_t stbir_uint32;
#endif #endif
#ifndef STBIRDEF
#ifdef STB_IMAGE_RESIZE_STATIC #ifdef STB_IMAGE_RESIZE_STATIC
#define STBIRDEF static #define STBIRDEF static
#else #else
@@ -202,7 +204,7 @@ typedef uint32_t stbir_uint32;
#define STBIRDEF extern #define STBIRDEF extern
#endif #endif
#endif #endif
#endif
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
@@ -2324,8 +2326,9 @@ static int stbir__resize_allocated(stbir__info *info,
if (alpha_channel < 0) if (alpha_channel < 0)
flags |= STBIR_FLAG_ALPHA_USES_COLORSPACE | STBIR_FLAG_ALPHA_PREMULTIPLIED; flags |= STBIR_FLAG_ALPHA_USES_COLORSPACE | STBIR_FLAG_ALPHA_PREMULTIPLIED;
if (!(flags&STBIR_FLAG_ALPHA_USES_COLORSPACE) || !(flags&STBIR_FLAG_ALPHA_PREMULTIPLIED)) if (!(flags&STBIR_FLAG_ALPHA_USES_COLORSPACE) || !(flags&STBIR_FLAG_ALPHA_PREMULTIPLIED)) {
STBIR_ASSERT(alpha_channel >= 0 && alpha_channel < info->channels); STBIR_ASSERT(alpha_channel >= 0 && alpha_channel < info->channels);
}
if (alpha_channel >= info->channels) if (alpha_channel >= info->channels)
return 0; return 0;

View File

@@ -1,4 +1,4 @@
/* stb_image_write - v1.10 - public domain - http://nothings.org/stb/stb_image_write.h /* stb_image_write - v1.13 - public domain - http://nothings.org/stb/stb_image_write.h
writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015 writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015
no warranty implied; use at your own risk no warranty implied; use at your own risk
@@ -299,7 +299,7 @@ STBIW_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned in
STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input) STBIWDEF int stbiw_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 #endif
@@ -393,7 +393,7 @@ static void stbiw__putc(stbi__write_context *s, unsigned char c)
static void stbiw__write3(stbi__write_context *s, unsigned char a, unsigned char b, unsigned char c) static void stbiw__write3(stbi__write_context *s, unsigned char a, unsigned char b, unsigned char c)
{ {
unsigned char arr[3]; unsigned char arr[3];
arr[0] = a, arr[1] = b, arr[2] = c; arr[0] = a; arr[1] = b; arr[2] = c;
s->func(s->context, arr, 3); s->func(s->context, arr, 3);
} }
@@ -441,10 +441,11 @@ static void stbiw__write_pixels(stbi__write_context *s, int rgb_dir, int vdir, i
if (stbi__flip_vertically_on_write) if (stbi__flip_vertically_on_write)
vdir *= -1; vdir *= -1;
if (vdir < 0) if (vdir < 0) {
j_end = -1, j = y-1; j_end = -1; j = y-1;
else } else {
j_end = y, j = 0; j_end = y; j = 0;
}
for (; j != j_end; j += vdir) { for (; j != j_end; j += vdir) {
for (i=0; i < x; ++i) { for (i=0; i < x; ++i) {
@@ -736,8 +737,8 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f
char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n"; char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n";
s->func(s->context, header, sizeof(header)-1); s->func(s->context, header, sizeof(header)-1);
#ifdef STBI_MSC_SECURE_CRT #ifdef __STDC_WANT_SECURE_LIB__
len = sprintf_s(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
#else #else
len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
#endif #endif
@@ -895,7 +896,7 @@ STBIWDEF unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, i
for (j=0; j < n; ++j) { for (j=0; j < n; ++j) {
if (hlist[j]-data > i-32768) { // if entry lies within window if (hlist[j]-data > i-32768) { // if entry lies within window
int d = stbiw__zlib_countm(hlist[j], data+i, data_len-i); int d = stbiw__zlib_countm(hlist[j], data+i, data_len-i);
if (d >= best) best=d,bestloc=hlist[j]; if (d >= best) { best=d; bestloc=hlist[j]; }
} }
} }
// when hash table entry is too long, delete half the entries // when hash table entry is too long, delete half the entries
@@ -954,8 +955,8 @@ STBIWDEF unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, i
int blocklen = (int) (data_len % 5552); int blocklen = (int) (data_len % 5552);
j=0; j=0;
while (j < data_len) { while (j < data_len) {
for (i=0; i < blocklen; ++i) s1 += data[j+i], s2 += s1; for (i=0; i < blocklen; ++i) { s1 += data[j+i]; s2 += s1; }
s1 %= 65521, s2 %= 65521; s1 %= 65521; s2 %= 65521;
j += blocklen; j += blocklen;
blocklen = 5552; blocklen = 5552;
} }
@@ -1476,17 +1477,13 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in
for(x = 0; x < width; x += 8) { for(x = 0; x < width; x += 8) {
float YDU[64], UDU[64], VDU[64]; float YDU[64], UDU[64], VDU[64];
for(row = y, pos = 0; row < y+8; ++row) { for(row = y, pos = 0; row < y+8; ++row) {
int p; // row >= height => use last input row
if(row < height) { int clamped_row = (row < height) ? row : height - 1;
p = (stbi__flip_vertically_on_write ? (height-1-row) : row)*width*comp; int base_p = (stbi__flip_vertically_on_write ? (height-1-clamped_row) : clamped_row)*width*comp;
} else {
// row >= height => use last input row (=> first if flipping)
p = stbi__flip_vertically_on_write ? 0 : ((height-1)*width*comp);
}
for(col = x; col < x+8; ++col, ++pos) { for(col = x; col < x+8; ++col, ++pos) {
float r, g, b; float r, g, b;
// if col >= width => use pixel from last input column // if col >= width => use pixel from last input column
p += ((col < width) ? col : (width-1))*comp; int p = base_p + ((col < width) ? col : (width-1))*comp;
r = imageData[p+0]; r = imageData[p+0];
g = imageData[p+ofsG]; g = imageData[p+ofsG];

View File

@@ -1,4 +1,4 @@
// stb_rect_pack.h - v0.99 - public domain - rectangle packing // stb_rect_pack.h - v1.00 - public domain - rectangle packing
// Sean Barrett 2014 // Sean Barrett 2014
// //
// Useful for e.g. packing rectangular textures into an atlas. // Useful for e.g. packing rectangular textures into an atlas.
@@ -31,9 +31,11 @@
// //
// Bugfixes / warning fixes // Bugfixes / warning fixes
// Jeremy Jaussaud // Jeremy Jaussaud
// Fabian Giesen
// //
// Version history: // Version history:
// //
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
// 0.99 (2019-02-07) warning fixes // 0.99 (2019-02-07) warning fixes
// 0.11 (2017-03-03) return packing success/fail result // 0.11 (2017-03-03) return packing success/fail result
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings // 0.10 (2016-10-25) remove cast-away-const to avoid warnings
@@ -348,6 +350,13 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
width -= width % c->align; width -= width % c->align;
STBRP_ASSERT(width % c->align == 0); STBRP_ASSERT(width % c->align == 0);
// if it can't possibly fit, bail immediately
if (width > c->width || height > c->height) {
fr.prev_link = NULL;
fr.x = fr.y = 0;
return fr;
}
node = c->active_head; node = c->active_head;
prev = &c->active_head; prev = &c->active_head;
while (node->x + width <= c->width) { while (node->x + width <= c->width) {
@@ -411,7 +420,7 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
} }
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos); STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste); y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
if (y + height < c->height) { if (y + height <= c->height) {
if (y <= best_y) { if (y <= best_y) {
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) { if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
best_x = xpos; best_x = xpos;

View File

@@ -1,4 +1,4 @@
// stb_truetype.h - v1.20 - public domain // stb_truetype.h - v1.21 - public domain
// authored from 2009-2016 by Sean Barrett / RAD Game Tools // authored from 2009-2016 by Sean Barrett / RAD Game Tools
// //
// This library processes TrueType files: // This library processes TrueType files:
@@ -49,6 +49,7 @@
// //
// VERSION HISTORY // VERSION HISTORY
// //
// 1.21 (2019-02-25) fix warning
// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() // 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics()
// 1.19 (2018-02-11) GPOS kerning, STBTT_fmod // 1.19 (2018-02-11) GPOS kerning, STBTT_fmod
// 1.18 (2018-01-29) add missing function // 1.18 (2018-01-29) add missing function
@@ -243,19 +244,6 @@
// recommend it. // recommend it.
// //
// //
// SOURCE STATISTICS (based on v0.6c, 2050 LOC)
//
// Documentation & header file 520 LOC \___ 660 LOC documentation
// Sample code 140 LOC /
// Truetype parsing 620 LOC ---- 620 LOC TrueType
// Software rasterization 240 LOC \
// Curve tessellation 120 LOC \__ 550 LOC Bitmap creation
// Bitmap management 100 LOC /
// Baked bitmap interface 70 LOC /
// Font name matching & access 150 LOC ---- 150
// C runtime library abstraction 60 LOC ---- 60
//
//
// PERFORMANCE MEASUREMENTS FOR 1.06: // PERFORMANCE MEASUREMENTS FOR 1.06:
// //
// 32-bit 64-bit // 32-bit 64-bit