update stb lib

This commit is contained in:
Sak32009 2024-08-18 11:05:49 +02:00
parent 31e500f4e3
commit f4d9f23ac6
6 changed files with 12180 additions and 3993 deletions

View File

@ -23,6 +23,7 @@
#define STBI_ONLY_JPEG
#if defined(__WINDOWS__)
#define STBI_WINDOWS_UTF8
#define STBIW_WINDOWS_UTF8
#endif
#include "stb/stb_image.h"
@ -31,7 +32,7 @@
#include "stb/stb_image_write.h"
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb/stb_image_resize.h"
#include "stb/stb_image_resize2.h"
struct File_Data {
std::string name{};
@ -883,13 +884,13 @@ std::string Local_Storage::load_image_resized(std::string const& image_path, std
PRINT_DEBUG("stbi_load('%s') -> %s", image_path.c_str(), (img == nullptr ? stbi_failure_reason() : "loaded"));
if (img != nullptr) {
std::vector<char> out_resized(resized_img_size);
stbir_resize_uint8(img, width, height, 0, (unsigned char*)&out_resized[0], resolution, resolution, 0, 4);
stbir_resize_uint8_linear(img, width, height, 0, (unsigned char*)&out_resized[0], resolution, resolution, 0, STBIR_RGBA);
resized_image = std::string((char*)&out_resized[0], out_resized.size());
stbi_image_free(img);
}
} else if (image_data.length() > 0) {
std::vector<char> out_resized(resized_img_size);
stbir_resize_uint8((unsigned char*)image_data.c_str(), 184, 184, 0, (unsigned char*)&out_resized[0], resolution, resolution, 0, 4);
stbir_resize_uint8_linear((unsigned char*)image_data.c_str(), 184, 184, 0, (unsigned char*)&out_resized[0], resolution, resolution, 0, STBIR_RGBA);
resized_image = std::string((char*)&out_resized[0], out_resized.size());
}

View File

@ -1,3 +1,9 @@
============================================================================ INFO
https://github.com/nothings/stb
VERSION: https://github.com/nothings/stb/tree/f75e8d1cad7d90d72ef7a4661f1b994ef78b4e31
============================================================================ LICENSE MIT / PUBLIC DOMAIN
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

10572
libs/stb/stb_image_resize2.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* stb_image_write - v1.15 - public domain - http://nothings.org/stb
/* stb_image_write - v1.16 - public domain - http://nothings.org/stb
writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015
no warranty implied; use at your own risk
@ -140,6 +140,7 @@ CREDITS:
Ivan Tikhonov
github:ignotion
Adam Schackart
Andrew Kensler
LICENSE
@ -166,9 +167,9 @@ LICENSE
#endif
#ifndef STB_IMAGE_WRITE_STATIC // C++ forbids static forward declarations
extern int stbi_write_tga_with_rle;
extern int stbi_write_png_compression_level;
extern int stbi_write_force_png_filter;
STBIWDEF int stbi_write_tga_with_rle;
STBIWDEF int stbi_write_png_compression_level;
STBIWDEF int stbi_write_force_png_filter;
#endif
#ifndef STBI_WRITE_NO_STDIO
@ -178,7 +179,7 @@ STBIWDEF int stbi_write_tga(char const* filename, int w, int h, int comp, const
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
#ifdef STBI_WINDOWS_UTF8
#ifdef STBIW_WINDOWS_UTF8
STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);
#endif
#endif
@ -285,7 +286,7 @@ static void stbi__stdio_write(void* context, void* data, int size)
fwrite(data,1,size,(FILE*) context);
}
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
#if defined(_WIN32) && defined(STBIW_WINDOWS_UTF8)
#ifdef __cplusplus
#define STBIW_EXTERN extern "C"
#else
@ -303,16 +304,16 @@ STBIWDEF int stbiw_convert_wchar_to_utf8(char* buffer, size_t bufferlen, const w
static FILE *stbiw__fopen(char const *filename, char const *mode)
{
FILE *f;
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
#if defined(_WIN32) && defined(STBIW_WINDOWS_UTF8)
wchar_t wMode[64];
wchar_t wFilename[1024];
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)))
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)/sizeof(*wFilename)))
return 0;
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)))
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)/sizeof(*wMode)))
return 0;
#if _MSC_VER >= 1400
#if defined(_MSC_VER) && _MSC_VER >= 1400
if (0 != _wfopen_s(&f, wFilename, wMode))
f = 0;
#else
@ -397,7 +398,7 @@ static void stbiw__putc(stbi__write_context* s, unsigned char c)
static void stbiw__write1(stbi__write_context *s, unsigned char a)
{
if (s->buf_used + 1 > sizeof(s->buffer))
if ((size_t)s->buf_used + 1 > sizeof(s->buffer))
stbiw__write_flush(s);
s->buffer[s->buf_used++] = a;
}
@ -405,7 +406,7 @@ static void stbiw__write1(stbi__write_context* s, unsigned char a)
static void stbiw__write3(stbi__write_context *s, unsigned char a, unsigned char b, unsigned char c)
{
int n;
if (s->buf_used + 3 > sizeof(s->buffer))
if ((size_t)s->buf_used + 3 > sizeof(s->buffer))
stbiw__write_flush(s);
n = s->buf_used;
s->buf_used = n+3;
@ -460,8 +461,7 @@ static void stbiw__write_pixels(stbi__write_context* s, int rgb_dir, int vdir, i
if (vdir < 0) {
j_end = -1; j = y-1;
}
else {
} else {
j_end = y; j = 0;
}
@ -479,8 +479,7 @@ static int stbiw__outfile(stbi__write_context* s, int rgb_dir, int vdir, int x,
{
if (y < 0 || x < 0) {
return 0;
}
else {
} else {
va_list v;
va_start(v, fmt);
stbiw__writefv(s, fmt, v);
@ -492,11 +491,22 @@ static int stbiw__outfile(stbi__write_context* s, int rgb_dir, int vdir, int x,
static int stbi_write_bmp_core(stbi__write_context *s, int x, int y, int comp, const void *data)
{
if (comp != 4) {
// write RGB bitmap
int pad = (-x*3) & 3;
return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *) data,0,pad,
"11 4 22 4" "4 44 22 444444",
'B', 'M', 14+40+(x*3+pad)*y, 0,0, 14+40, // file header
40, x,y, 1,24, 0,0,0,0,0,0); // bitmap header
} else {
// RGBA bitmaps need a v4 header
// use BI_BITFIELDS mode with 32bpp and alpha mask
// (straight BI_RGB with alpha mask doesn't work in most readers)
return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *)data,1,0,
"11 4 22 4" "4 44 22 444444 4444 4 444 444 444 444",
'B', 'M', 14+108+x*y*4, 0, 0, 14+108, // file header
108, x,y, 1,32, 3,0,0,0,0,0, 0xff0000,0xff00,0xff,0xff000000u, 0, 0,0,0, 0,0,0, 0,0,0, 0,0,0); // bitmap V4 header
}
}
STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data)
@ -514,8 +524,7 @@ STBIWDEF int stbi_write_bmp(char const* filename, int x, int y, int comp, const
int r = stbi_write_bmp_core(&s, x, y, comp, data);
stbi__end_write_file(&s);
return r;
}
else
} else
return 0;
}
#endif //!STBI_WRITE_NO_STDIO
@ -532,8 +541,7 @@ static int stbi_write_tga_core(stbi__write_context* s, int x, int y, int comp, v
if (!stbi_write_tga_with_rle) {
return stbiw__outfile(s, -1, -1, x, y, comp, 0, (void *) data, has_alpha, 0,
"111 221 2222 11", 0, 0, format, 0, 0, 0, 0, 0, x, y, (colorbytes + has_alpha) * 8, has_alpha * 8);
}
else {
} else {
int i,j,k;
int jend, jdir;
@ -543,8 +551,7 @@ static int stbi_write_tga_core(stbi__write_context* s, int x, int y, int comp, v
j = 0;
jend = y;
jdir = 1;
}
else {
} else {
j = y-1;
jend = -1;
jdir = -1;
@ -567,19 +574,16 @@ static int stbi_write_tga_core(stbi__write_context* s, int x, int y, int comp, v
if (memcmp(prev, row + k * comp, comp)) {
prev += comp;
++len;
}
else {
} else {
--len;
break;
}
}
}
else {
} else {
for (k = i + 2; k < x && len < 128; ++k) {
if (!memcmp(begin, row + k * comp, comp)) {
++len;
}
else {
} else {
break;
}
}
@ -592,8 +596,7 @@ static int stbi_write_tga_core(stbi__write_context* s, int x, int y, int comp, v
for (k = 0; k < len; ++k) {
stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin + k * comp);
}
}
else {
} else {
unsigned char header = STBIW_UCHAR(len - 129);
stbiw__write1(s, header);
stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin);
@ -620,8 +623,7 @@ STBIWDEF int stbi_write_tga(char const* filename, int x, int y, int comp, const
int r = stbi_write_tga_core(&s, x, y, comp, (void *) data);
stbi__end_write_file(&s);
return r;
}
else
} else
return 0;
}
#endif
@ -632,6 +634,8 @@ STBIWDEF int stbi_write_tga(char const* filename, int x, int y, int comp, const
#define stbiw__max(a, b) ((a) > (b) ? (a) : (b))
#ifndef STBI_WRITE_NO_STDIO
static void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
{
int exponent;
@ -639,8 +643,7 @@ static void stbiw__linear_to_rgbe(unsigned char* rgbe, float* linear)
if (maxcomp < 1e-32f) {
rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0;
}
else {
} else {
float normalize = (float) frexp(maxcomp, &exponent) * 256.0f/maxcomp;
rgbe[0] = (unsigned char)(linear[0] * normalize);
@ -692,8 +695,7 @@ static void stbiw__write_hdr_scanline(stbi__write_context* s, int width, int nco
stbiw__linear_to_rgbe(rgbe, linear);
s->func(s->context, rgbe, 4);
}
}
else {
} else {
int c,r;
/* encode into scratch buffer */
for (x=0; x < width; x++) {
@ -768,7 +770,7 @@ 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";
s->func(s->context, header, sizeof(header)-1);
#ifdef __STDC_WANT_SECURE_LIB__
#ifdef __STDC_LIB_EXT1__
len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
#else
len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
@ -789,7 +791,6 @@ STBIWDEF int stbi_write_hdr_to_func(stbi_write_func* func, void* context, int x,
return stbi_write_hdr_core(&s, x, y, comp, (float *) data);
}
#ifndef STBI_WRITE_NO_STDIO
STBIWDEF int stbi_write_hdr(char const *filename, int x, int y, int comp, const float *data)
{
stbi__write_context s = { 0 };
@ -797,8 +798,7 @@ STBIWDEF int stbi_write_hdr(char const* filename, int x, int y, int comp, const
int r = stbi_write_hdr_core(&s, x, y, comp, (float *) data);
stbi__end_write_file(&s);
return r;
}
else
} else
return 0;
}
#endif // STBI_WRITE_NO_STDIO
@ -964,8 +964,7 @@ STBIWDEF unsigned char* stbi_zlib_compress(unsigned char* data, int data_len, in
stbiw__zlib_add(stbiw__zlib_bitrev(j,5),5);
if (disteb[j]) stbiw__zlib_add(d - distc[j], disteb[j]);
i += best;
}
else {
} else {
stbiw__zlib_huffb(data[i]);
++i;
}
@ -982,6 +981,23 @@ STBIWDEF unsigned char* stbi_zlib_compress(unsigned char* data, int data_len, in
(void) stbiw__sbfree(hash_table[i]);
STBIW_FREE(hash_table);
// store uncompressed instead if compression was worse
if (stbiw__sbn(out) > data_len + 2 + ((data_len+32766)/32767)*5) {
stbiw__sbn(out) = 2; // truncate to DEFLATE 32K window and FLEVEL = 1
for (j = 0; j < data_len;) {
int blocklen = data_len - j;
if (blocklen > 32767) blocklen = 32767;
stbiw__sbpush(out, data_len - j == blocklen); // BFINAL = ?, BTYPE = 0 -- no compression
stbiw__sbpush(out, STBIW_UCHAR(blocklen)); // LEN
stbiw__sbpush(out, STBIW_UCHAR(blocklen >> 8));
stbiw__sbpush(out, STBIW_UCHAR(~blocklen)); // NLEN
stbiw__sbpush(out, STBIW_UCHAR(~blocklen >> 8));
memcpy(out+stbiw__sbn(out), data+j, blocklen);
stbiw__sbn(out) += blocklen;
j += blocklen;
}
}
{
// compute adler32 on input
unsigned int s1=1, s2=0;
@ -1132,8 +1148,7 @@ STBIWDEF unsigned char* stbi_write_png_to_mem(const unsigned char* pixels, int s
if (force_filter > -1) {
filter_type = force_filter;
stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, force_filter, line_buffer);
}
else { // Estimate the best filter by running through all of them:
} else { // Estimate the best filter by running through all of them:
int best_filter = 0, best_filter_val = 0x7fffffff, est, i;
for (filter_type = 0; filter_type < 5; filter_type++) {
stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, filter_type, line_buffer);
@ -1341,8 +1356,7 @@ static int stbiw__jpg_processDU(stbi__write_context* s, int* bitBuf, int* bitCnt
diff = DU[0] - DC;
if (diff == 0) {
stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTDC[0]);
}
else {
} else {
unsigned short bits[2];
stbiw__jpg_calcBits(diff, bits);
stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTDC[bits[1]]);
@ -1554,8 +1568,7 @@ static int stbi_write_jpg_core(stbi__write_context* s, int width, int height, in
}
}
}
}
else {
} else {
for(y = 0; y < height; y += 8) {
for(x = 0; x < width; x += 8) {
float Y[64], U[64], V[64];
@ -1607,8 +1620,7 @@ STBIWDEF int stbi_write_jpg(char const* filename, int x, int y, int comp, const
int r = stbi_write_jpg_core(&s, x, y, comp, data, quality);
stbi__end_write_file(&s);
return r;
}
else
} else
return 0;
}
#endif
@ -1616,6 +1628,10 @@ STBIWDEF int stbi_write_jpg(char const* filename, int x, int y, int comp, const
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
/* Revision history
1.16 (2021-07-11)
make Deflate code emit uncompressed blocks when it would otherwise expand
support writing BMPs with alpha channel
1.15 (2020-07-13) unknown
1.14 (2020-02-02) updated JPEG writer to downsample chroma channels
1.13
1.12