diff --git a/README.md b/README.md index 5992bff..bfbe9c8 100644 --- a/README.md +++ b/README.md @@ -5,36 +5,45 @@ stb single-file public domain (or MIT licensed) libraries for C/C++ +Noteworthy: + +* image loader: stb_image.h +* image writer: stb_image_write.h +* image resizer: stb_image_resize.h> +* font text rasterizer: stb_truetype.h +* typesafe containers: stb_ds.h + Most libraries by stb, except: stb_dxt by Fabian "ryg" Giesen, stb_image_resize by Jorge L. "VinoBS" Rodriguez, and stb_sprintf by Jeff Roberts. library | lastest version | category | LoC | description --------------------- | ---- | -------- | --- | -------------------------------- -**[stb_vorbis.c](stb_vorbis.c)** | 1.17 | audio | 5486 | decode ogg vorbis files from file/memory to float/16-bit signed output -**[stb_image.h](stb_image.h)** | 2.22 | graphics | 7547 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC -**[stb_truetype.h](stb_truetype.h)** | 1.21 | graphics | 4882 | parse, decode, and rasterize characters from truetype fonts -**[stb_image_write.h](stb_image_write.h)** | 1.13 | graphics | 1617 | image writing to disk: PNG, TGA, BMP +**[stb_vorbis.c](stb_vorbis.c)** | 1.17 | audio | 5502 | decode ogg vorbis files from file/memory to float/16-bit signed output +**[stb_image.h](stb_image.h)** | 2.23 | graphics | 7559 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC +**[stb_truetype.h](stb_truetype.h)** | 1.22 | graphics | 4888 | parse, decode, and rasterize characters from truetype fonts +**[stb_image_write.h](stb_image_write.h)** | 1.13 | graphics | 1619 | image writing to disk: PNG, TGA, BMP **[stb_image_resize.h](stb_image_resize.h)** | 0.96 | graphics | 2630 | resize images larger/smaller with good quality **[stb_rect_pack.h](stb_rect_pack.h)** | 1.00 | graphics | 628 | simple 2D rectangle packer with decent quality -**[stb_ds.h](stb_ds.h)** | 0.5 | utility | 1691 | typesafe dynamic array and hash tables for C, will compile in C++ +**[stb_ds.h](stb_ds.h)** | 0.6 | utility | 1699 | typesafe dynamic array and hash tables for C, will compile in C++ **[stb_sprintf.h](stb_sprintf.h)** | 1.06 | utility | 1860 | fast sprintf, snprintf for C/C++ **[stretchy_buffer.h](stretchy_buffer.h)** | 1.03 | utility | 262 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++ **[stb_textedit.h](stb_textedit.h)** | 1.13 | user interface | 1404 | guts of a text editor for games etc implementing them from scratch **[stb_voxel_render.h](stb_voxel_render.h)** | 0.88 | 3D graphics | 3806 | Minecraft-esque voxel rendering "engine" with many more features **[stb_dxt.h](stb_dxt.h)** | 1.08b | 3D graphics | 728 | Fabian "ryg" Giesen's real-time DXT compressor -**[stb_perlin.h](stb_perlin.h)** | 0.4 | 3D graphics | 366 | revised Perlin noise (3D input, 1D output) +**[stb_perlin.h](stb_perlin.h)** | 0.4 | 3D graphics | 427 | revised Perlin noise (3D input, 1D output) **[stb_easy_font.h](stb_easy_font.h)** | 1.0 | 3D graphics | 303 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc **[stb_tilemap_editor.h](stb_tilemap_editor.h)** | 0.41 | game dev | 4161 | embeddable tilemap editor **[stb_herringbone_wa...](stb_herringbone_wang_tile.h)** | 0.7 | game dev | 1221 | herringbone Wang tile map generator -**[stb_c_lexer.h](stb_c_lexer.h)** | 0.10 | parsing | 964 | simplify writing parsers for C-like languages +**[stb_c_lexer.h](stb_c_lexer.h)** | 0.11 | parsing | 966 | simplify writing parsers for C-like languages **[stb_divide.h](stb_divide.h)** | 0.92 | math | 421 | more useful 32-bit modulus e.g. "euclidean divide" **[stb_connected_comp...](stb_connected_components.h)** | 0.96 | misc | 1049 | incrementally compute reachability on grids -**[stb.h](stb.h)** | 2.34 | misc | 14453 | helper functions for C, mostly redundant in C++; basically author's personal stuff +**[stb.h](stb.h)** | 2.35 | misc | 14453 | helper functions for C, mostly redundant in C++; basically author's personal stuff **[stb_leakcheck.h](stb_leakcheck.h)** | 0.5 | misc | 190 | quick-and-dirty malloc/free leak-checking +**[stb_include.h](stb_include.h)** | 0.01 | misc | 288 | implement recursive #include support, particularly for GLSL -Total libraries: 21 -Total lines of C code: 55669 +Total libraries: 22 +Total lines of C code: 56064 FAQ diff --git a/stb.h b/stb.h index e218b9f..a853d08 100644 --- a/stb.h +++ b/stb.h @@ -1,4 +1,4 @@ -/* stb.h - v2.34 - Sean's Tool Box -- public domain -- http://nothings.org/stb.h +/* stb.h - v2.35 - Sean's Tool Box -- public domain -- http://nothings.org/stb.h no warranty is offered or implied; use this code at your own risk This is a single header file with a bunch of useful utilities @@ -25,6 +25,7 @@ Version History + 2.35 fix clang-cl issues with swprintf 2.34 fix warnings 2.33 more fixes to random numbers 2.32 stb_intcmprev, stb_uidict, fix random numbers on Linux @@ -7150,6 +7151,7 @@ static void stb__dirtree_scandir(char *path, time_t last_time, stb_dirtree *acti // @TODO: do this concatenation without using swprintf to avoid this mess: #if (defined(_MSC_VER) && _MSC_VER < 1400) // || (defined(__clang__)) // confusingly, Windows Kits\10 needs to go down this path?!? + // except now it doesn't, I don't know what changed if (has_slash) swprintf(full_path, L"%s*", stb__from_utf8(path)); else diff --git a/stb_c_lexer.h b/stb_c_lexer.h index c340e2c..8352e27 100644 --- a/stb_c_lexer.h +++ b/stb_c_lexer.h @@ -1,4 +1,4 @@ -// stb_c_lexer.h - v0.10 - public domain Sean Barrett 2013 +// stb_c_lexer.h - v0.11 - public domain Sean Barrett 2013 // lexer for making little C-like languages with recursive-descent parsers // // This file provides both the interface and the implementation. @@ -10,6 +10,7 @@ // suffixes on integer constants are not handled (you can override this). // // History: +// 0.11 fix clang static analysis warning // 0.10 fix warnings // 0.09 hex floats, no-stdlib fixes // 0.08 fix bad pointer comparison diff --git a/stb_ds.h b/stb_ds.h index debeab0..951a02b 100644 --- a/stb_ds.h +++ b/stb_ds.h @@ -1,4 +1,4 @@ -/* stb_ds.h - v0.5 - public domain data structures - Sean Barrett 2019 +/* stb_ds.h - v0.6 - public domain data structures - Sean Barrett 2019 This is a single-header-file library that provides easy-to-use dynamic arrays and hash tables for C (also works in C++). diff --git a/stb_image.h b/stb_image.h index 17403e5..196dfd5 100644 --- a/stb_image.h +++ b/stb_image.h @@ -1,4 +1,4 @@ -/* stb_image - v2.22 - public domain image loader - http://nothings.org/stb +/* stb_image - v2.23 - public domain image loader - http://nothings.org/stb no warranty implied; use at your own risk Do this: @@ -48,6 +48,7 @@ LICENSE RECENT REVISION HISTORY: + 2.23 (2019-08-11) fix clang static analysis warning 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 diff --git a/stb_image_write.h b/stb_image_write.h index 082eb69..a9bf66c 100644 --- a/stb_image_write.h +++ b/stb_image_write.h @@ -1,4 +1,4 @@ -/* stb_image_write - v1.13 - public domain - http://nothings.org/stb/stb_image_write.h +/* stb_image_write - v1.13 - 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 @@ -868,7 +868,7 @@ STBIWDEF unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, i unsigned int bitbuf=0; int i,j, bitcount=0; unsigned char *out = NULL; - unsigned char ***hash_table = (unsigned char***) STBIW_MALLOC(stbiw__ZHASH * sizeof(char**)); + unsigned char ***hash_table = (unsigned char***) STBIW_MALLOC(stbiw__ZHASH * sizeof(unsigned char**)); if (hash_table == NULL) return NULL; if (quality < 5) quality = 5; @@ -1530,6 +1530,8 @@ STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const #endif // STB_IMAGE_WRITE_IMPLEMENTATION /* Revision history + 1.11 (2019-08-11) + 1.10 (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs 1.09 (2018-02-11) diff --git a/stb_truetype.h b/stb_truetype.h index aefa2a0..4a3ad33 100644 --- a/stb_truetype.h +++ b/stb_truetype.h @@ -1,5 +1,5 @@ -// stb_truetype.h - v1.21 - public domain -// authored from 2009-2016 by Sean Barrett / RAD Game Tools +// stb_truetype.h - v1.22 - public domain +// authored from 2009-2019 by Sean Barrett / RAD Game Tools // // This library processes TrueType files: // parse files @@ -50,6 +50,7 @@ // // VERSION HISTORY // +// 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined // 1.21 (2019-02-25) fix warning // 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() // 1.19 (2018-02-11) GPOS kerning, STBTT_fmod @@ -2541,8 +2542,7 @@ STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int g1, int if (info->gpos) xAdvance += stbtt__GetGlyphGPOSInfoAdvance(info, g1, g2); - - if (info->kern) + else if (info->kern) xAdvance += stbtt__GetGlyphKernInfoAdvance(info, g1, g2); return xAdvance; diff --git a/tests/stb.dsp b/tests/stb.dsp index 273e494..ece606e 100644 --- a/tests/stb.dsp +++ b/tests/stb.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /G6 /MT /W3 /GX /Z7 /O2 /Ob2 /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "GRID_TEST" /FD /c +# ADD CPP /nologo /G6 /MT /W3 /GX /Z7 /O2 /Ob2 /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "VORBIS_TEST" /FD /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe @@ -66,7 +66,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MTd /W3 /GX /Zi /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "DS_TEST" /FR /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /GX /Zi /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "VORBIS_TEST" /FR /FD /GZ /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" diff --git a/tools/README.header.md b/tools/README.header.md index 41e55f1..65dc95e 100644 --- a/tools/README.header.md +++ b/tools/README.header.md @@ -3,6 +3,14 @@ stb single-file public domain (or MIT licensed) libraries for C/C++ +Noteworthy: + +* image loader: stb_image.h +* image writer: stb_image_write.h +* image resizer: stb_image_resize.h> +* font text rasterizer: stb_truetype.h +* typesafe containers: stb_ds.h + Most libraries by stb, except: stb_dxt by Fabian "ryg" Giesen, stb_image_resize by Jorge L. "VinoBS" Rodriguez, and stb_sprintf by Jeff Roberts. diff --git a/tools/README.list b/tools/README.list index 85e8bf3..ef1fc6a 100644 --- a/tools/README.list +++ b/tools/README.list @@ -19,3 +19,4 @@ stb_divide.h | math | more useful 32-bit modulus e.g. stb_connected_components.h | misc | incrementally compute reachability on grids stb.h | misc | helper functions for C, mostly redundant in C++; basically author's personal stuff stb_leakcheck.h | misc | quick-and-dirty malloc/free leak-checking +stb_include.h | misc | implement recursive #include support, particularly for GLSL diff --git a/tools/build_matrix.c b/tools/build_matrix.c new file mode 100644 index 0000000..fab6b38 --- /dev/null +++ b/tools/build_matrix.c @@ -0,0 +1,132 @@ +#define STB_DEFINE +#include "stb.h" + +// true if no error +int run_command(char *batch_file, char *command) +{ + char buffer[4096]; + if (batch_file[0]) { + sprintf(buffer, "%s && %s", batch_file, command); + return system(buffer) == 0; + } else { + return system(command) == 0; + } +} + +typedef struct +{ + char *compiler_name; + char *batchfile; + char *objdir; + char *compiler; + char *args; + char *link; +} compiler_info; + +compiler_info *compilers; +char *shared_args; +char *shared_link; + +typedef struct +{ + char *filelist; +} project_info; + +project_info *projects; + +enum { NONE, IN_COMPILERS, IN_ARGS, IN_PROJECTS, IN_LINK }; + +int main(int argc, char **argv) +{ + int state = NONE; + int i,j,n; + char **line; + if (argc != 2) stb_fatal("Usage: stb_build_matrix {build-file}\n"); + line = stb_stringfile(argv[1], &n); + if (line == 0) stb_fatal("Couldn't open file '%s'\n", argv[1]); + + for (i=0; i < n; ++i) { + char *p = stb_trimwhite(line[i]); + if (p[0] == 0) continue; + else if (p[0] == '#') continue; + else if (0 == stricmp(p, "[compilers]")) { state = IN_COMPILERS; } + else if (0 == stricmp(p, "[args]" )) { state = IN_ARGS ; shared_args = NULL; } + else if (0 == stricmp(p, "[projects]" )) { state = IN_PROJECTS ; } + else if (0 == stricmp(p, "[link]" )) { state = IN_LINK ; shared_link = NULL; } + else { + switch (state) { + case NONE: stb_fatal("Invalid text outside section at line %d.", i+1); + case IN_COMPILERS: { + char buffer[4096]; + int count; + compiler_info ci; + char **tokens = stb_tokens_stripwhite(p, ",", &count), *batch; + if (count > 3) stb_fatal("Expecting name and batch file name at line %d.", i+1); + batch = (count==1 ? tokens[0] : tokens[1]); + if (strlen(batch)) + sprintf(buffer, "c:\\%s.bat", batch); + else + strcpy(buffer, ""); + ci.compiler_name = strdup(tokens[0]); + ci.batchfile = strdup(buffer); + ci.compiler = count==3 ? strdup(tokens[2]) : "cl"; + if (0==strnicmp(batch, "vcvars_", 7)) + ci.objdir = strdup(stb_sprintf("%s_%d", batch+7, i)); + else + ci.objdir = strdup(stb_sprintf("%s_%d", batch, i)); + ci.args = shared_args; + ci.link = shared_link; + stb_arr_push(compilers, ci); + break; + } + case IN_ARGS: { + stb_arr_push(shared_args, ' '); + for (j=0; p[j] != 0; ++j) + stb_arr_push(shared_args, p[j]); + break; + } + case IN_LINK: { + stb_arr_push(shared_link, ' '); + for (j=0; p[j] != 0; ++j) + stb_arr_push(shared_link, p[j]); + break; + } + case IN_PROJECTS: { + project_info pi; + pi.filelist = strdup(p); + stb_arr_push(projects, pi); + break; + } + } + } + } + + _mkdir("obj"); + for (j=0; j < stb_arr_len(compilers); ++j) { + char command[4096]; + for (i=0; i < stb_arr_len(projects); ++i) { + int r; + _mkdir(stb_sprintf("obj/%s", compilers[j].objdir)); + if (stb_suffix(compilers[j].compiler, "cl")) + sprintf(command, "%s %.*s %s /link %.*s", + compilers[j].compiler, + stb_arr_len(compilers[j].args), compilers[j].args, + projects[i].filelist, + stb_arr_len(compilers[j].link), compilers[j].link); + else + sprintf(command, "%s %.*s %s %.*s", + compilers[j].compiler, + stb_arr_len(compilers[j].args), compilers[j].args, + projects[i].filelist, + stb_arr_len(compilers[j].link), compilers[j].link); + r = run_command(compilers[j].batchfile, command); + stbprint("{%c== Compiler %s == Building %s}\n", r ? '$' : '!', compilers[j].compiler_name, projects[i].filelist); + system("if EXIST *.obj del /q *.obj"); + system("if EXIST *.o del /q *.o"); + if (!r) + return 1; + } + } + + return 0; +}