From 7a0b46075ca5fcd46fc6b161f84c13e4cb7d8cf4 Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 17:07:57 -0500 Subject: [PATCH 01/50] Fix stbte_create_map declaration --- stb_tilemap_editor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index ed56a10..e751980 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -339,7 +339,7 @@ enum // creation // -extern stbte_tilemap *stbte_create(int map_x, int map_y, int map_layers, int spacing_x, int spacing_y, int max_tiles); +extern stbte_tilemap *stbte_create_map(int map_x, int map_y, int map_layers, int spacing_x, int spacing_y, int max_tiles); // create an editable tilemap // map_x : dimensions of map horizontally (user can change this in editor), <= STBTE_MAX_TILEMAP_X // map_y : dimensions of map vertically (user can change this in editor) <= STBTE_MAX_TILEMAP_Y From f82fbb2e36bcacc781561e6034813f808df1648f Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 17:55:03 -0500 Subject: [PATCH 02/50] stbte: layername button grows/shrinks Layer name buttons grow to fill box --- stb_tilemap_editor.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index e751980..0a8339b 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -938,6 +938,7 @@ struct stbte_tilemap int tileinfo_dirty; stbte__layer layerinfo[STBTE_MAX_LAYERS]; int has_layer_names; + int layername_width; int layer_scroll; int propmode; int solo_layer; @@ -1016,6 +1017,7 @@ stbte_tilemap *stbte_create_map(int map_x, int map_y, int map_layers, int spacin tm->layer_scroll = 0; tm->propmode = 0; tm->has_layer_names = 0; + tm->layername_width = 0; tm->undo_available_valid = 0; for (i=0; i < tm->num_layers; ++i) { @@ -1088,12 +1090,16 @@ void stbte_define_tile(stbte_tilemap *tm, unsigned short id, unsigned int layerm tm->tileinfo_dirty = 1; } +static int stbte__text_width(const char *str); + void stbte_set_layername(stbte_tilemap *tm, int layer, const char *layername) { STBTE_ASSERT(layer >= 0 && layer < tm->num_layers); if (layer >= 0 && layer < tm->num_layers) { tm->layerinfo[layer].name = layername; tm->has_layer_names = 1; + int width = stbte__text_width(layername); + tm->layername_width = (width > tm->layername_width ? width : tm->layername_width); } } @@ -3385,7 +3391,9 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) int i, y, n; int x1 = x0+w; int y1 = y0+h; - int xoff = tm->has_layer_names ? 50 : 20; + int side = stbte__ui.panel[STBTE__layer].side; + int xoff = tm->has_layer_names ? stbte__region[side].width - 42 : 20; + xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10); static char *propmodes[3] = { "default", "always", "never" }; From 87faf06b5d195462a2c9b66ecc86b69febd908a2 Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 18:06:40 -0500 Subject: [PATCH 03/50] stbte: update documentation/version 0.31 Changed REVISION HISTORY, TODO, CREDITS, and README --- README.md | 5 +---- stb_tilemap_editor.h | 7 +++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8918d86..ad57108 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ library | lastest version | category | description **stb_textedit.h** | 1.5 | UI | guts of a text editor for games etc implementing them from scratch **stb_dxt.h** | 1.04 | 3D graphics | Fabian "ryg" Giesen's real-time DXT compressor **stb_perlin.h** | 0.2 | 3D graphics | revised Perlin noise (3D input, 1D output) -**stb_tilemap_editor.h** | 0.30 | games | embeddable tilemap editor +**stb_tilemap_editor.h** | 0.31 | games | embeddable tilemap editor **stb_herringbone_wang_tile.h** | 0.6 | games | herringbone Wang tile map generator **stb_c_lexer.h** | 0.06 | parsing | simplify writing parsers for C-like languages **stb_divide.h** | 0.91 | math | more useful 32-bit modulus e.g. "euclidean divide" @@ -82,6 +82,3 @@ for other people to use them from other languages. I still use MSVC 6 (1998) as my IDE because it has better human factors for me than later versions of MSVC. - - - diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index 0a8339b..bfa0d11 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -1,4 +1,4 @@ -// stb_tilemap_editor.h - v0.30 - Sean Barrett - http://nothings.org/stb +// stb_tilemap_editor.h - v0.31 - Sean Barrett - http://nothings.org/stb // placed in the public domain - not copyrighted - first released 2014-09 // // Embeddable tilemap editor for C/C++ @@ -275,6 +275,9 @@ // either approach allows cut&pasting between levels.) // // REVISION HISTORY +// 0.31 layername button changes +// - layername buttons grow with the layer panel +// - fix stbte_create_map being declared as stbte_create // 0.30 properties release // - properties panel for editing user-defined "object" properties // - can link each tile to one other tile @@ -296,11 +299,11 @@ // Support STBTE_HITTEST_TILE above // ?Cancel drags by clicking other button? - may be fixed // Finish support for toolbar at side -// Layer name buttons grow to fill box // // CREDITS // // Written by Sean Barrett, September & October 2014. +// Contributions from Josh Huelsman, January 2015. // // LICENSE // From ba38019c9585af63fd9759879f11f764cfb26210 Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 18:46:57 -0500 Subject: [PATCH 04/50] stbte: fix layername button growing for both sides --- stb_tilemap_editor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index bfa0d11..ade6783 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -3394,7 +3394,7 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) int i, y, n; int x1 = x0+w; int y1 = y0+h; - int side = stbte__ui.panel[STBTE__layer].side; + int side = stbte__ui.panel[STBTE__panel_layers].side; int xoff = tm->has_layer_names ? stbte__region[side].width - 42 : 20; xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10); static char *propmodes[3] = { From e62a54ee0bdf88aa5c42b71790d58b95e6203b99 Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 18:58:59 -0500 Subject: [PATCH 05/50] stbte: fix number rendering when no layernames set --- stb_tilemap_editor.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index ade6783..ac9eaf2 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -3394,9 +3394,14 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) int i, y, n; int x1 = x0+w; int y1 = y0+h; - int side = stbte__ui.panel[STBTE__panel_layers].side; - int xoff = tm->has_layer_names ? stbte__region[side].width - 42 : 20; - xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10); + int xoff = 20; + + if (tm->has_layer_names) { + int side = stbte__ui.panel[STBTE__panel_layers].side; + xoff = tm->has_layer_names ? stbte__region[side].width - 42 : 20; + xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10); + } + static char *propmodes[3] = { "default", "always", "never" }; From 6cc48214ac02181d3c771ad3dd47abd647b2517e Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 21:17:24 -0500 Subject: [PATCH 06/50] stbte: removed redundant conditional --- stb_tilemap_editor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index ac9eaf2..21dabcf 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -3398,7 +3398,7 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) if (tm->has_layer_names) { int side = stbte__ui.panel[STBTE__panel_layers].side; - xoff = tm->has_layer_names ? stbte__region[side].width - 42 : 20; + xoff = stbte__region[side].width - 42; xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10); } From 3f418bfe6e4db5dd93fe93b35b55c7af7b4a745c Mon Sep 17 00:00:00 2001 From: joshhuelsman Date: Fri, 30 Jan 2015 21:59:01 -0500 Subject: [PATCH 07/50] stbte: fix; prop button now draws 't' in default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit prop button didn’t draw the ’t’ when the panel is expanded --- stb_tilemap_editor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index 21dabcf..cc6a398 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -3443,7 +3443,7 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) n = stbte__text_width("prop:")+2; stbte__draw_text(x0,y+2, "prop:", w, STBTE__TEXTCOLOR(STBTE__cpanel)); i = w - n - 4; - if (i > 45) i = 45; + if (i > 50) i = 50; if (stbte__button(STBTE__clayer_button, propmodes[tm->propmode], x0+n,y,0,i, STBTE__ID(STBTE__layer,256), 0,0)) tm->propmode = (tm->propmode+1)%3; #endif From 198ee828caf8ebf8b5051361785ffd709850ac87 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 Mar 2015 14:58:38 -0700 Subject: [PATCH 08/50] Allow to replace memmove function with custom implementation --- stb_textedit.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/stb_textedit.h b/stb_textedit.h index 32e90e6..3682d97 100644 --- a/stb_textedit.h +++ b/stb_textedit.h @@ -358,7 +358,10 @@ typedef struct // included just the "header" portion #ifdef STB_TEXTEDIT_IMPLEMENTATION -#include // memmove +#ifndef STBTE_memmove +#include +#define STBTE_memmove memmove +#endif ///////////////////////////////////////////////////////////////////////////// @@ -1038,13 +1041,13 @@ static void stb_textedit_discard_undo(StbUndoState *state) int n = state->undo_rec[0].insert_length, i; // delete n characters from all other records state->undo_char_point = state->undo_char_point - (short) n; // vsnet05 - memmove(state->undo_char, state->undo_char + n, (size_t) (state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE))); + STBTE_memmove(state->undo_char, state->undo_char + n, (size_t) (state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE))); for (i=0; i < state->undo_point; ++i) if (state->undo_rec[i].char_storage >= 0) state->undo_rec[i].char_storage = state->undo_rec[i].char_storage - (short) n; // vsnet05 // @OPTIMIZE: get rid of char_storage and infer it } --state->undo_point; - memmove(state->undo_rec, state->undo_rec+1, (size_t) (state->undo_point*sizeof(state->undo_rec[0]))); + STBTE_memmove(state->undo_rec, state->undo_rec+1, (size_t) (state->undo_point*sizeof(state->undo_rec[0]))); } } @@ -1062,13 +1065,13 @@ static void stb_textedit_discard_redo(StbUndoState *state) int n = state->undo_rec[k].insert_length, i; // delete n characters from all other records state->redo_char_point = state->redo_char_point + (short) n; // vsnet05 - memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE))); + STBTE_memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE))); for (i=state->redo_point; i < k; ++i) if (state->undo_rec[i].char_storage >= 0) state->undo_rec[i].char_storage = state->undo_rec[i].char_storage + (short) n; // vsnet05 } ++state->redo_point; - memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0]))); + STBTE_memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0]))); } } From 8bfd635220544916a93020686e88186eb681ed63 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 Mar 2015 15:01:53 -0700 Subject: [PATCH 09/50] Allow to replace qsort function with custom implementation --- stb_rect_pack.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stb_rect_pack.h b/stb_rect_pack.h index dcc9d88..8c73a30 100644 --- a/stb_rect_pack.h +++ b/stb_rect_pack.h @@ -169,7 +169,10 @@ struct stbrp_context // #ifdef STB_RECT_PACK_IMPLEMENTATION +#ifndef STBRP_sort #include +#define STBRP_sort qsort +#endif #ifndef STBRP_ASSERT #include @@ -524,7 +527,7 @@ STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int n } // sort according to heuristic - qsort(rects, num_rects, sizeof(rects[0]), rect_height_compare); + STBRP_sort(rects, num_rects, sizeof(rects[0]), rect_height_compare); for (i=0; i < num_rects; ++i) { stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h); @@ -537,7 +540,7 @@ STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int n } // unsort - qsort(rects, num_rects, sizeof(rects[0]), rect_original_order); + STBRP_sort(rects, num_rects, sizeof(rects[0]), rect_original_order); // set was_packed flags for (i=0; i < num_rects; ++i) From 80744251282f86faa0e0812fe796a34af5799d8c Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 01:56:56 -0700 Subject: [PATCH 10/50] standalone public-domain rationale document --- docs/why_public_domain.md | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 docs/why_public_domain.md diff --git a/docs/why_public_domain.md b/docs/why_public_domain.md new file mode 100644 index 0000000..141e4b6 --- /dev/null +++ b/docs/why_public_domain.md @@ -0,0 +1,49 @@ +My collected rationales for placing these libraries +in the public domain: + +1. Public domain vs. viral licenses + +Why is this library public domain? +Because more people will use it. Because it's not viral, people are +not obligated to give back, so you could argue that it hurts the +development of it, and then because it doesn't develop as well it's +not as good, and then because it's not as good, in the long run +maybe fewer people will use it. I have total respect for that +opinion, but I just don't believe it myself for most software. + +2. Public domain vs. attribution-required licenses + +The primary difference between public domain and, say, a Creative Commons +commercial / non-share-alike / attribution license is solely the +requirement for attribution. (Similarly the BSD license and such.) +While I would *appreciate* acknowledgement and attribution, I believe +that it is foolish to place a legal encumberment (i.e. a license) on +the software *solely* to get attribution. + +In other words, I'm arguing that PD is superior to the BSD license and +the Creative Commons 'Attribution' license. If the license offers +anything besides attribution -- as does, e.g., CC NonCommercial-ShareAlike, +or the GPL -- that's a separate discussion. + +3. Other aspects of BSD-style licenses besides attribution + +Permissive licenses like zlib and BSD license are perfectly reasonable +in their requirements, but they are very wordy and +have only two benefits over public domain: legally-mandated +attribution and liability-control. I do not believe these +are worth the excessive verbosity and user-unfriendliness +these licenses induce, especially in the single-file +case where those licenses tend to be at the top of +the file, the first thing you see. + +To the specific points, I have had no trouble receiving +attribution for my libraries; liability in the face of +no explicit disclaimer of liability is an open question, +but one I have a lot of difficulty imagining there being +any actual doubt about in court. Sometimes I explicitly +note in my libraries that I make no guarantees about them +being fit for purpose, but it's pretty absurd to do this; +as a whole, it comes across as "here is a library to decode +vorbis audio files, but it may not actually work and if +you have problems it's not my fault, but also please +report bugs so I can fix them". \ No newline at end of file From 2f17f1a93b9ee14f6f096f0b10070233b73417e0 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 01:58:25 -0700 Subject: [PATCH 11/50] Update why_public_domain.md --- docs/why_public_domain.md | 72 +++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/docs/why_public_domain.md b/docs/why_public_domain.md index 141e4b6..5b6df6f 100644 --- a/docs/why_public_domain.md +++ b/docs/why_public_domain.md @@ -3,47 +3,47 @@ in the public domain: 1. Public domain vs. viral licenses -Why is this library public domain? -Because more people will use it. Because it's not viral, people are -not obligated to give back, so you could argue that it hurts the -development of it, and then because it doesn't develop as well it's -not as good, and then because it's not as good, in the long run -maybe fewer people will use it. I have total respect for that -opinion, but I just don't believe it myself for most software. + Why is this library public domain? + Because more people will use it. Because it's not viral, people are + not obligated to give back, so you could argue that it hurts the + development of it, and then because it doesn't develop as well it's + not as good, and then because it's not as good, in the long run + maybe fewer people will use it. I have total respect for that + opinion, but I just don't believe it myself for most software. 2. Public domain vs. attribution-required licenses -The primary difference between public domain and, say, a Creative Commons -commercial / non-share-alike / attribution license is solely the -requirement for attribution. (Similarly the BSD license and such.) -While I would *appreciate* acknowledgement and attribution, I believe -that it is foolish to place a legal encumberment (i.e. a license) on -the software *solely* to get attribution. + The primary difference between public domain and, say, a Creative Commons + commercial / non-share-alike / attribution license is solely the + requirement for attribution. (Similarly the BSD license and such.) + While I would *appreciate* acknowledgement and attribution, I believe + that it is foolish to place a legal encumberment (i.e. a license) on + the software *solely* to get attribution. -In other words, I'm arguing that PD is superior to the BSD license and -the Creative Commons 'Attribution' license. If the license offers -anything besides attribution -- as does, e.g., CC NonCommercial-ShareAlike, -or the GPL -- that's a separate discussion. + In other words, I'm arguing that PD is superior to the BSD license and + the Creative Commons 'Attribution' license. If the license offers + anything besides attribution -- as does, e.g., CC NonCommercial-ShareAlike, + or the GPL -- that's a separate discussion. 3. Other aspects of BSD-style licenses besides attribution -Permissive licenses like zlib and BSD license are perfectly reasonable -in their requirements, but they are very wordy and -have only two benefits over public domain: legally-mandated -attribution and liability-control. I do not believe these -are worth the excessive verbosity and user-unfriendliness -these licenses induce, especially in the single-file -case where those licenses tend to be at the top of -the file, the first thing you see. + Permissive licenses like zlib and BSD license are perfectly reasonable + in their requirements, but they are very wordy and + have only two benefits over public domain: legally-mandated + attribution and liability-control. I do not believe these + are worth the excessive verbosity and user-unfriendliness + these licenses induce, especially in the single-file + case where those licenses tend to be at the top of + the file, the first thing you see. -To the specific points, I have had no trouble receiving -attribution for my libraries; liability in the face of -no explicit disclaimer of liability is an open question, -but one I have a lot of difficulty imagining there being -any actual doubt about in court. Sometimes I explicitly -note in my libraries that I make no guarantees about them -being fit for purpose, but it's pretty absurd to do this; -as a whole, it comes across as "here is a library to decode -vorbis audio files, but it may not actually work and if -you have problems it's not my fault, but also please -report bugs so I can fix them". \ No newline at end of file + To the specific points, I have had no trouble receiving + attribution for my libraries; liability in the face of + no explicit disclaimer of liability is an open question, + but one I have a lot of difficulty imagining there being + any actual doubt about in court. Sometimes I explicitly + note in my libraries that I make no guarantees about them + being fit for purpose, but it's pretty absurd to do this; + as a whole, it comes across as "here is a library to decode + vorbis audio files, but it may not actually work and if + you have problems it's not my fault, but also please + report bugs so I can fix them"--so dumb! From 31461003c7d89fa6a814d5d741477719c84a5fa7 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 02:00:59 -0700 Subject: [PATCH 12/50] Update why_public_domain.md --- docs/why_public_domain.md | 65 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/docs/why_public_domain.md b/docs/why_public_domain.md index 5b6df6f..902e766 100644 --- a/docs/why_public_domain.md +++ b/docs/why_public_domain.md @@ -47,3 +47,68 @@ in the public domain: vorbis audio files, but it may not actually work and if you have problems it's not my fault, but also please report bugs so I can fix them"--so dumb! + +4. discussion from stb_howto.txt on what YOU should do for YOUR libs + +EASY-TO-COMPLY LICENSE + +I make my libraries public domain. You don't have to. +But my goal in releasing stb-style libraries is to +reduce friction for potential users as much as +possible. That means: + + a. easy to build (what this file is mostly about) + b. easy to invoke (which requires good API design) + c. easy to deploy (which is about licensing) + +I choose to place all my libraries in the public +domain, abjuring copyright, rather than license +the libraries. This has some benefits and some +drawbacks. + +Any license which is "viral" to modifications +causes worries for lawyers, even if their programmers +aren't modifying it. + +Any license which requires crediting in documentation +adds friction which can add up. Valve used to have +a page with a list of all of these on their web site, +and it was insane, and obviously nobody ever looked +at it so why would you care whether your credit appeared +there? + +Permissive licenses like zlib and BSD license are +perfectly reasonable, but they are very wordy and +have only two benefits over public domain: legally-mandated +attribution and liability-control. I do not believe these +are worth the excessive verbosity and user-unfriendliness +these licenses induce, especially in the single-file +case where those licenses tend to be at the top of +the file, the first thing you see. (To the specific +points, I have had no trouble receiving attribution +for my libraries; liability in the face of no explicit +disclaimer of liability is an open question.) + +However, public domain has frictions of its own, because +public domain declarations aren't necessary recognized +in the USA and some other locations. For that reason, +I recommend a declaration along these lines: + +// This software is in the public domain. Where that dedication is not +// recognized, you are granted a perpetual, irrevocable license to copy +// and modify this file as you see fit. + +I typically place this declaration at the end of the initial +comment block of the file and just say 'public domain' +at the top. + +I have had people say they couldn't use one of my +libraries because it was only "public domain" and didn't +have the additional fallback clause, who asked if +I could dual-license it under a traditional license. + +My answer: they can create a derivative work by +modifying one character, and then license that however +they like. (Indeed, *adding* the zlib or BSD license +would be such a modification!) Unfortunately, their +lawyers reportedly didn't like that answer. :( From d44e52d3638b8dd3eaaa7958c5352976f4ffaa12 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 02:03:22 -0700 Subject: [PATCH 13/50] Update why_public_domain.md --- docs/why_public_domain.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/why_public_domain.md b/docs/why_public_domain.md index 902e766..661ba1f 100644 --- a/docs/why_public_domain.md +++ b/docs/why_public_domain.md @@ -50,16 +50,18 @@ in the public domain: 4. discussion from stb_howto.txt on what YOU should do for YOUR libs -EASY-TO-COMPLY LICENSE +```EASY-TO-COMPLY LICENSE I make my libraries public domain. You don't have to. But my goal in releasing stb-style libraries is to reduce friction for potential users as much as possible. That means: - a. easy to build (what this file is mostly about) - b. easy to invoke (which requires good API design) - c. easy to deploy (which is about licensing) + a. easy to build (what this file is mostly about) + + b. easy to invoke (which requires good API design) + + c. easy to deploy (which is about licensing) I choose to place all my libraries in the public domain, abjuring copyright, rather than license @@ -112,3 +114,4 @@ modifying one character, and then license that however they like. (Indeed, *adding* the zlib or BSD license would be such a modification!) Unfortunately, their lawyers reportedly didn't like that answer. :( +``` From 8fece213ee9a00f6037852a0fd50e4fcb02897f0 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 02:04:44 -0700 Subject: [PATCH 14/50] Update why_public_domain.md --- docs/why_public_domain.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/why_public_domain.md b/docs/why_public_domain.md index 661ba1f..9c7c77b 100644 --- a/docs/why_public_domain.md +++ b/docs/why_public_domain.md @@ -50,7 +50,8 @@ in the public domain: 4. discussion from stb_howto.txt on what YOU should do for YOUR libs -```EASY-TO-COMPLY LICENSE +``` +EASY-TO-COMPLY LICENSE I make my libraries public domain. You don't have to. But my goal in releasing stb-style libraries is to From 0a3b6adb32ad1f65aa8fb3cea7f3acb474d9b6e6 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 02:05:18 -0700 Subject: [PATCH 15/50] Update why_public_domain.md --- docs/why_public_domain.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/why_public_domain.md b/docs/why_public_domain.md index 9c7c77b..2962e7d 100644 --- a/docs/why_public_domain.md +++ b/docs/why_public_domain.md @@ -59,9 +59,7 @@ reduce friction for potential users as much as possible. That means: a. easy to build (what this file is mostly about) - b. easy to invoke (which requires good API design) - c. easy to deploy (which is about licensing) I choose to place all my libraries in the public From 8f4958e1f0e85cd6274cb37f2789f039d2512c9b Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 02:05:54 -0700 Subject: [PATCH 16/50] Update why_public_domain.md --- docs/why_public_domain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/why_public_domain.md b/docs/why_public_domain.md index 2962e7d..8636921 100644 --- a/docs/why_public_domain.md +++ b/docs/why_public_domain.md @@ -48,7 +48,7 @@ in the public domain: you have problems it's not my fault, but also please report bugs so I can fix them"--so dumb! -4. discussion from stb_howto.txt on what YOU should do for YOUR libs +4. full discussion from stb_howto.txt on what YOU should do for YOUR libs ``` EASY-TO-COMPLY LICENSE From ede1ebdaa966f98fadc67bfbb2f9b35a8adf1f09 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 03:03:11 -0700 Subject: [PATCH 17/50] add "lines of code" to README.md --- README.md | 51 +++++++++++++++++++++++++----------------- tools/README.footer.md | 11 +++++++++ tools/README.header.md | 4 ++-- tools/make_readme.c | 11 +++++---- 4 files changed, 49 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index eec9e98..8c0b594 100644 --- a/README.md +++ b/README.md @@ -3,26 +3,26 @@ stb single-file public domain libraries for C/C++ -library | lastest version | category | description ---------------------- | ---- | -------- | -------------------------------- -**stb_vorbis.c** | 1.04 | audio | decode ogg vorbis files from file/memory to float/16-bit signed output -**stb_image.h** | 2.03 | graphics | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC -**stb_truetype.h** | 1.03 | graphics | parse, decode, and rasterize characters from truetype fonts -**stb_image_write.h** | 0.98 | graphics | image writing to disk: PNG, TGA, BMP -**stb_image_resize.h** | 0.90 | graphics | resize images larger/smaller with good quality -**stb_rect_pack.h** | 0.05 | graphics | simple 2D rectangle packer with decent quality -**stretchy_buffer.h** | 1.01 | utility | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++ -**stb_textedit.h** | 1.5 | UI | guts of a text editor for games etc implementing them from scratch -**stb_voxel_render.h** | 0.80 | 3D graphics | Minecraft-esque voxel rendering "engine" with many more features -**stb_dxt.h** | 1.04 | 3D graphics | Fabian "ryg" Giesen's real-time DXT compressor -**stb_perlin.h** | 0.2 | 3D graphics | revised Perlin noise (3D input, 1D output) -**stb_easy_font.h** | 0.5 | 3D graphics | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc -**stb_tilemap_editor.h** | 0.30 | game development | embeddable tilemap editor -**stb_herringbone_wang_tile.h** | 0.6 | game development | herringbone Wang tile map generator -**stb_c_lexer.h** | 0.06 | parsing | simplify writing parsers for C-like languages -**stb_divide.h** | 0.91 | math | more useful 32-bit modulus e.g. "euclidean divide" -**stb.h** | 2.24 | misc | helper functions for C, mostly redundant in C++; basically author's personal stuff -**stb_leakcheck.h** | 0.1 | misc | quick-and-dirty malloc/free leak-checking +library | lastest version | Lines Of Code | category | description +--------------------- | ---- | --------------| -------- | -------------------------------- +**stb_vorbis.c** | 1.04 | audio | 5443 | decode ogg vorbis files from file/memory to float/16-bit signed output +**stb_image.h** | 2.03 | graphics | 6426 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC +**stb_truetype.h** | 1.03 | graphics | 2629 | parse, decode, and rasterize characters from truetype fonts +**stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP +**stb_image_resize.h** | 0.90 | graphics | 2585 | resize images larger/smaller with good quality +**stb_rect_pack.h** | 0.05 | graphics | 546 | simple 2D rectangle packer with decent quality +**stretchy_buffer.h** | 1.01 | utility | 209 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++ +**stb_textedit.h** | 1.5 | UI | 1284 | guts of a text editor for games etc implementing them from scratch +**stb_voxel_render.h** | 0.80 | 3D graphics | 3644 | Minecraft-esque voxel rendering "engine" with many more features +**stb_dxt.h** | 1.04 | 3D graphics | 624 | Fabian "ryg" Giesen's real-time DXT compressor +**stb_perlin.h** | 0.2 | 3D graphics | 175 | revised Perlin noise (3D input, 1D output) +**stb_easy_font.h** | 0.5 | 3D graphics | 220 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc +**stb_tilemap_editor.h** | 0.30 | game development | 4097 | embeddable tilemap editor +**stb_herringbone_wang_tile.h** | 0.6 | game development | 1217 | herringbone Wang tile map generator +**stb_c_lexer.h** | 0.06 | parsing | 809 | simplify writing parsers for C-like languages +**stb_divide.h** | 0.91 | math | 373 | more useful 32-bit modulus e.g. "euclidean divide" +**stb.h** | 2.24 | misc | 14086 | helper functions for C, mostly redundant in C++; basically author's personal stuff +**stb_leakcheck.h** | 0.1 | misc | 117 | quick-and-dirty malloc/free leak-checking FAQ --- @@ -45,6 +45,17 @@ attribution requirement). They may be less featureful, slower, and/or use more memory. If you're already using an equivalent library, there's probably no good reason to switch. +#### Why do you list "lines of code"? It's a terrible metric. + +Just to give you some idea of the internal complexity of the library, +to help you manage your expectations, or to let you know what you're +getting into. While not all the libraries are written in the same +style, they're certainly similar styles, and so comparisons between +the libraries are probably still meaningful. + +Note though that the lines do include both the implementation, the +part that corresponds to a header file, and the documentation. + #### Why single-file headers? Windows doesn't have standard directories where libraries diff --git a/tools/README.footer.md b/tools/README.footer.md index 24925a3..b97ee47 100644 --- a/tools/README.footer.md +++ b/tools/README.footer.md @@ -20,6 +20,17 @@ attribution requirement). They may be less featureful, slower, and/or use more memory. If you're already using an equivalent library, there's probably no good reason to switch. +#### Why do you list "lines of code"? It's a terrible metric. + +Just to give you some idea of the internal complexity of the library, +to help you manage your expectations, or to let you know what you're +getting into. While not all the libraries are written in the same +style, they're certainly similar styles, and so comparisons between +the libraries are probably still meaningful. + +Note though that the lines do include both the implementation, the +part that corresponds to a header file, and the documentation. + #### Why single-file headers? Windows doesn't have standard directories where libraries diff --git a/tools/README.header.md b/tools/README.header.md index 66871d2..41135cf 100644 --- a/tools/README.header.md +++ b/tools/README.header.md @@ -3,5 +3,5 @@ stb single-file public domain libraries for C/C++ -library | lastest version | category | description ---------------------- | ---- | -------- | -------------------------------- +library | lastest version | Lines Of Code | category | description +--------------------- | ---- | --------------| -------- | -------------------------------- diff --git a/tools/make_readme.c b/tools/make_readme.c index cdc0b85..c562e82 100644 --- a/tools/make_readme.c +++ b/tools/make_readme.c @@ -15,12 +15,10 @@ int main(int argc, char **argv) for (i=0; i < listlen; ++i) { int num,j; char **tokens = stb_tokens_stripwhite(list[i], "|", &num); // stb_tokens -- tokenize string into malloced array of strings - FILE *g = fopen(stb_sprintf("../%s", tokens[0]), "rb"); // stb_sprintf -- sprintf to a static temp buffer (not threadsafe or secure) - char buffer[256], *s1, *s2; - fread(buffer, 1, 256, g); - fclose(g); - buffer[255] = 0; - s1 = strchr(buffer, '-'); + int num_lines; + char **lines = stb_stringfile(stb_sprintf("../%s", tokens[0]), &num_lines); + char *s1, *s2; + s1 = strchr(lines[0], '-'); if (!s1) stb_fatal("Couldn't find '-' before version number in %s", tokens[0]); // stb_fatal -- print error message & exit s2 = strchr(s1+2, '-'); if (!s2) stb_fatal("Couldn't find '-' after version number in %s", tokens[0]); // stb_fatal -- print error message & exit @@ -33,6 +31,7 @@ int main(int argc, char **argv) s2 = stb_dupreplace(s1, " ", " "); // stb_dupreplace -- search & replace string and malloc result fprintf(f, " | %s", s2); free(s2); + fprintf(f, " | %d", num_lines); for (j=2; j < num; ++j) fprintf(f, " | %s", tokens[j]); fprintf(f, "\n"); From 3c2090565db9c91b560349a35eb8642d815d87b4 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 03:04:32 -0700 Subject: [PATCH 18/50] fix reversed column headers --- README.md | 4 ++-- tools/README.header.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8c0b594..356c499 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ stb single-file public domain libraries for C/C++ -library | lastest version | Lines Of Code | category | description ---------------------- | ---- | --------------| -------- | -------------------------------- +library | lastest version | category | Lines Of Code | description +--------------------- | ---- | -------- | ------------- | -------------------------------- **stb_vorbis.c** | 1.04 | audio | 5443 | decode ogg vorbis files from file/memory to float/16-bit signed output **stb_image.h** | 2.03 | graphics | 6426 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC **stb_truetype.h** | 1.03 | graphics | 2629 | parse, decode, and rasterize characters from truetype fonts diff --git a/tools/README.header.md b/tools/README.header.md index 41135cf..47678ea 100644 --- a/tools/README.header.md +++ b/tools/README.header.md @@ -3,5 +3,5 @@ stb single-file public domain libraries for C/C++ -library | lastest version | Lines Of Code | category | description ---------------------- | ---- | --------------| -------- | -------------------------------- +library | lastest version | category | Lines Of Code | description +--------------------- | ---- | -------- | ------------- | -------------------------------- From c1ad6b09def878d275d4ee52af61ed1d5af375fc Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 03:09:01 -0700 Subject: [PATCH 19/50] make table more readable by shrinking some columns horizontally --- README.md | 4 ++-- tools/README.list | 4 ++-- tools/make_readme.c | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 356c499..e32f9cb 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ library | lastest version | category | Lines Of Code | description **stb_dxt.h** | 1.04 | 3D graphics | 624 | Fabian "ryg" Giesen's real-time DXT compressor **stb_perlin.h** | 0.2 | 3D graphics | 175 | revised Perlin noise (3D input, 1D output) **stb_easy_font.h** | 0.5 | 3D graphics | 220 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc -**stb_tilemap_editor.h** | 0.30 | game development | 4097 | embeddable tilemap editor -**stb_herringbone_wang_tile.h** | 0.6 | game development | 1217 | herringbone Wang tile map generator +**stb_tilemap_editor.h** | 0.30 | game dev | 4097 | embeddable tilemap editor +**stb_herringbone_wa...** | 0.6 | game dev | 1217 | herringbone Wang tile map generator **stb_c_lexer.h** | 0.06 | parsing | 809 | simplify writing parsers for C-like languages **stb_divide.h** | 0.91 | math | 373 | more useful 32-bit modulus e.g. "euclidean divide" **stb.h** | 2.24 | misc | 14086 | helper functions for C, mostly redundant in C++; basically author's personal stuff diff --git a/tools/README.list b/tools/README.list index 70f6ff7..8cf1f5f 100644 --- a/tools/README.list +++ b/tools/README.list @@ -10,8 +10,8 @@ stb_voxel_render.h | 3D graphics | Minecraft-esque voxel rendering stb_dxt.h | 3D graphics | Fabian "ryg" Giesen's real-time DXT compressor stb_perlin.h | 3D graphics | revised Perlin noise (3D input, 1D output) stb_easy_font.h | 3D graphics | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc -stb_tilemap_editor.h | game development | embeddable tilemap editor -stb_herringbone_wang_tile.h | game development | herringbone Wang tile map generator +stb_tilemap_editor.h | game dev | embeddable tilemap editor +stb_herringbone_wang_tile.h | game dev | herringbone Wang tile map generator stb_c_lexer.h | parsing | simplify writing parsers for C-like languages stb_divide.h | math | more useful 32-bit modulus e.g. "euclidean divide" stb.h | misc | helper functions for C, mostly redundant in C++; basically author's personal stuff diff --git a/tools/make_readme.c b/tools/make_readme.c index c562e82..eb949a6 100644 --- a/tools/make_readme.c +++ b/tools/make_readme.c @@ -17,7 +17,7 @@ int main(int argc, char **argv) char **tokens = stb_tokens_stripwhite(list[i], "|", &num); // stb_tokens -- tokenize string into malloced array of strings int num_lines; char **lines = stb_stringfile(stb_sprintf("../%s", tokens[0]), &num_lines); - char *s1, *s2; + char *s1, *s2,*s3; s1 = strchr(lines[0], '-'); if (!s1) stb_fatal("Couldn't find '-' before version number in %s", tokens[0]); // stb_fatal -- print error message & exit s2 = strchr(s1+2, '-'); @@ -26,7 +26,17 @@ int main(int argc, char **argv) s1 += 1; s1 = stb_trimwhite(s1); // stb_trimwhite -- advance pointer to after whitespace & delete trailing whitespace if (*s1 == 'v') ++s1; - fprintf(f, "**%s** | %s", tokens[0], s1); + s3 = tokens[0]; + stb_trimwhite(s3); + if (strlen(s3) < 21) { + fprintf(f, "**%s** | %s", tokens[0], s1); + } else { + char buffer[256]; + strncpy(buffer, s3, 18); + buffer[18] = 0; + strcat(buffer, "..."); + fprintf(f, "**%s** | %s", buffer, s1); + } s1 = stb_trimwhite(tokens[1]); // stb_trimwhite -- advance pointer to after whitespace & delete trailing whitespace s2 = stb_dupreplace(s1, " ", " "); // stb_dupreplace -- search & replace string and malloc result fprintf(f, " | %s", s2); From 3db3e566968a207eac6c67fbad5e07c74259bc98 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 03:10:36 -0700 Subject: [PATCH 20/50] consistent capitalization --- README.md | 2 +- tools/README.header.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e32f9cb..79ecce6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ stb single-file public domain libraries for C/C++ -library | lastest version | category | Lines Of Code | description +library | lastest version | category | lines of code | description --------------------- | ---- | -------- | ------------- | -------------------------------- **stb_vorbis.c** | 1.04 | audio | 5443 | decode ogg vorbis files from file/memory to float/16-bit signed output **stb_image.h** | 2.03 | graphics | 6426 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC diff --git a/tools/README.header.md b/tools/README.header.md index 47678ea..f85c985 100644 --- a/tools/README.header.md +++ b/tools/README.header.md @@ -3,5 +3,5 @@ stb single-file public domain libraries for C/C++ -library | lastest version | category | Lines Of Code | description +library | lastest version | category | lines of code | description --------------------- | ---- | -------- | ------------- | -------------------------------- From 977cce8cc75075c74141033ca8b588010eca207e Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 03:13:45 -0700 Subject: [PATCH 21/50] expand explanation of why single file --- README.md | 9 +++++++++ tools/README.footer.md | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 79ecce6..9bfebee 100644 --- a/README.md +++ b/README.md @@ -63,12 +63,21 @@ live. That makes deploying libraries in Windows a lot more painful than open source developers on Unix-derivates generally realize. (It also makes library dependencies a lot worse in Windows.) +There's also a common problem in Windows where a library was built +against a different version of the runtime library, which causes +link conflicts and confusion. Shipping the libs as headers means +you normally just compile them straight into your project without +making libraries, thus sidestepping that problem. + Making them a single file makes it very easy to just drop them into a project that needs them. (Of course you can still put them in a proper shared library tree if you want.) +Why not two files, one a header and one an implementation? The difference between 10 files and 9 files is not a big deal, but the difference between 2 files and 1 file is a big deal. +You don't need to zip or tar the files up, you don't have to +remember to attach *two* files, etc. #### Why "stb"? Is this something to do with Set-Top Boxes? diff --git a/tools/README.footer.md b/tools/README.footer.md index b97ee47..a3dc19f 100644 --- a/tools/README.footer.md +++ b/tools/README.footer.md @@ -38,12 +38,21 @@ live. That makes deploying libraries in Windows a lot more painful than open source developers on Unix-derivates generally realize. (It also makes library dependencies a lot worse in Windows.) +There's also a common problem in Windows where a library was built +against a different version of the runtime library, which causes +link conflicts and confusion. Shipping the libs as headers means +you normally just compile them straight into your project without +making libraries, thus sidestepping that problem. + Making them a single file makes it very easy to just drop them into a project that needs them. (Of course you can still put them in a proper shared library tree if you want.) +Why not two files, one a header and one an implementation? The difference between 10 files and 9 files is not a big deal, but the difference between 2 files and 1 file is a big deal. +You don't need to zip or tar the files up, you don't have to +remember to attach *two* files, etc. #### Why "stb"? Is this something to do with Set-Top Boxes? From dda1519da8f3d87d7e09bc9f104fe66595902bb7 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 03:19:54 -0700 Subject: [PATCH 22/50] shrink font for LoC to layout table better --- README.md | 40 ++++++++++++++++++++-------------------- tools/README.header.md | 4 ++-- tools/make_readme.c | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 9bfebee..ca8d5bd 100644 --- a/README.md +++ b/README.md @@ -3,26 +3,26 @@ stb single-file public domain libraries for C/C++ -library | lastest version | category | lines of code | description ---------------------- | ---- | -------- | ------------- | -------------------------------- -**stb_vorbis.c** | 1.04 | audio | 5443 | decode ogg vorbis files from file/memory to float/16-bit signed output -**stb_image.h** | 2.03 | graphics | 6426 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC -**stb_truetype.h** | 1.03 | graphics | 2629 | parse, decode, and rasterize characters from truetype fonts -**stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP -**stb_image_resize.h** | 0.90 | graphics | 2585 | resize images larger/smaller with good quality -**stb_rect_pack.h** | 0.05 | graphics | 546 | simple 2D rectangle packer with decent quality -**stretchy_buffer.h** | 1.01 | utility | 209 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++ -**stb_textedit.h** | 1.5 | UI | 1284 | guts of a text editor for games etc implementing them from scratch -**stb_voxel_render.h** | 0.80 | 3D graphics | 3644 | Minecraft-esque voxel rendering "engine" with many more features -**stb_dxt.h** | 1.04 | 3D graphics | 624 | Fabian "ryg" Giesen's real-time DXT compressor -**stb_perlin.h** | 0.2 | 3D graphics | 175 | revised Perlin noise (3D input, 1D output) -**stb_easy_font.h** | 0.5 | 3D graphics | 220 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc -**stb_tilemap_editor.h** | 0.30 | game dev | 4097 | embeddable tilemap editor -**stb_herringbone_wa...** | 0.6 | game dev | 1217 | herringbone Wang tile map generator -**stb_c_lexer.h** | 0.06 | parsing | 809 | simplify writing parsers for C-like languages -**stb_divide.h** | 0.91 | math | 373 | more useful 32-bit modulus e.g. "euclidean divide" -**stb.h** | 2.24 | misc | 14086 | helper functions for C, mostly redundant in C++; basically author's personal stuff -**stb_leakcheck.h** | 0.1 | misc | 117 | quick-and-dirty malloc/free leak-checking +library | lastest version | category | lines of code | description +--------------------- | ---- | -------- | ----------------------------- | -------------------------------- +**stb_vorbis.c** | 1.04 | audio | 5443 | decode ogg vorbis files from file/memory to float/16-bit signed output +**stb_image.h** | 2.03 | graphics | 6426 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC +**stb_truetype.h** | 1.03 | graphics | 2629 | parse, decode, and rasterize characters from truetype fonts +**stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP +**stb_image_resize.h** | 0.90 | graphics | 2585 | resize images larger/smaller with good quality +**stb_rect_pack.h** | 0.05 | graphics | 546 | simple 2D rectangle packer with decent quality +**stretchy_buffer.h** | 1.01 | utility | 209 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++ +**stb_textedit.h** | 1.5 | UI | 1284 | guts of a text editor for games etc implementing them from scratch +**stb_voxel_render.h** | 0.80 | 3D graphics | 3644 | Minecraft-esque voxel rendering "engine" with many more features +**stb_dxt.h** | 1.04 | 3D graphics | 624 | Fabian "ryg" Giesen's real-time DXT compressor +**stb_perlin.h** | 0.2 | 3D graphics | 175 | revised Perlin noise (3D input, 1D output) +**stb_easy_font.h** | 0.5 | 3D graphics | 220 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc +**stb_tilemap_editor.h** | 0.30 | game dev | 4097 | embeddable tilemap editor +**stb_herringbone_wa...** | 0.6 | game dev | 1217 | herringbone Wang tile map generator +**stb_c_lexer.h** | 0.06 | parsing | 809 | simplify writing parsers for C-like languages +**stb_divide.h** | 0.91 | math | 373 | more useful 32-bit modulus e.g. "euclidean divide" +**stb.h** | 2.24 | misc | 14086 | helper functions for C, mostly redundant in C++; basically author's personal stuff +**stb_leakcheck.h** | 0.1 | misc | 117 | quick-and-dirty malloc/free leak-checking FAQ --- diff --git a/tools/README.header.md b/tools/README.header.md index f85c985..a5a6fb7 100644 --- a/tools/README.header.md +++ b/tools/README.header.md @@ -3,5 +3,5 @@ stb single-file public domain libraries for C/C++ -library | lastest version | category | lines of code | description ---------------------- | ---- | -------- | ------------- | -------------------------------- +library | lastest version | category | lines of code | description +--------------------- | ---- | -------- | ----------------------------- | -------------------------------- diff --git a/tools/make_readme.c b/tools/make_readme.c index eb949a6..2fa593f 100644 --- a/tools/make_readme.c +++ b/tools/make_readme.c @@ -41,7 +41,7 @@ int main(int argc, char **argv) s2 = stb_dupreplace(s1, " ", " "); // stb_dupreplace -- search & replace string and malloc result fprintf(f, " | %s", s2); free(s2); - fprintf(f, " | %d", num_lines); + fprintf(f, " | %d", num_lines); for (j=2; j < num; ++j) fprintf(f, " | %s", tokens[j]); fprintf(f, "\n"); From f982f5ae1e0f723762c5bf0bc10a04843a5aa848 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 03:25:12 -0700 Subject: [PATCH 23/50] restore lines-of-code to original size --- README.md | 40 ++++++++++++++++++++-------------------- tools/README.header.md | 4 ++-- tools/make_readme.c | 2 +- tools/make_readme.dsp | 4 ++++ 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index ca8d5bd..5e2e637 100644 --- a/README.md +++ b/README.md @@ -3,26 +3,26 @@ stb single-file public domain libraries for C/C++ -library | lastest version | category | lines of code | description ---------------------- | ---- | -------- | ----------------------------- | -------------------------------- -**stb_vorbis.c** | 1.04 | audio | 5443 | decode ogg vorbis files from file/memory to float/16-bit signed output -**stb_image.h** | 2.03 | graphics | 6426 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC -**stb_truetype.h** | 1.03 | graphics | 2629 | parse, decode, and rasterize characters from truetype fonts -**stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP -**stb_image_resize.h** | 0.90 | graphics | 2585 | resize images larger/smaller with good quality -**stb_rect_pack.h** | 0.05 | graphics | 546 | simple 2D rectangle packer with decent quality -**stretchy_buffer.h** | 1.01 | utility | 209 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++ -**stb_textedit.h** | 1.5 | UI | 1284 | guts of a text editor for games etc implementing them from scratch -**stb_voxel_render.h** | 0.80 | 3D graphics | 3644 | Minecraft-esque voxel rendering "engine" with many more features -**stb_dxt.h** | 1.04 | 3D graphics | 624 | Fabian "ryg" Giesen's real-time DXT compressor -**stb_perlin.h** | 0.2 | 3D graphics | 175 | revised Perlin noise (3D input, 1D output) -**stb_easy_font.h** | 0.5 | 3D graphics | 220 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc -**stb_tilemap_editor.h** | 0.30 | game dev | 4097 | embeddable tilemap editor -**stb_herringbone_wa...** | 0.6 | game dev | 1217 | herringbone Wang tile map generator -**stb_c_lexer.h** | 0.06 | parsing | 809 | simplify writing parsers for C-like languages -**stb_divide.h** | 0.91 | math | 373 | more useful 32-bit modulus e.g. "euclidean divide" -**stb.h** | 2.24 | misc | 14086 | helper functions for C, mostly redundant in C++; basically author's personal stuff -**stb_leakcheck.h** | 0.1 | misc | 117 | quick-and-dirty malloc/free leak-checking +library | lastest version | category | LoC | description +--------------------- | ---- | -------- | --- | -------------------------------- +**stb_vorbis.c** | 1.04 | audio | 5443 | decode ogg vorbis files from file/memory to float/16-bit signed output +**stb_image.h** | 2.03 | graphics | 6426 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC +**stb_truetype.h** | 1.03 | graphics | 2629 | parse, decode, and rasterize characters from truetype fonts +**stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP +**stb_image_resize.h** | 0.90 | graphics | 2585 | resize images larger/smaller with good quality +**stb_rect_pack.h** | 0.05 | graphics | 546 | simple 2D rectangle packer with decent quality +**stretchy_buffer.h** | 1.01 | utility | 209 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++ +**stb_textedit.h** | 1.5 | UI | 1284 | guts of a text editor for games etc implementing them from scratch +**stb_voxel_render.h** | 0.80 | 3D graphics | 3644 | Minecraft-esque voxel rendering "engine" with many more features +**stb_dxt.h** | 1.04 | 3D graphics | 624 | Fabian "ryg" Giesen's real-time DXT compressor +**stb_perlin.h** | 0.2 | 3D graphics | 175 | revised Perlin noise (3D input, 1D output) +**stb_easy_font.h** | 0.5 | 3D graphics | 220 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc +**stb_tilemap_editor.h** | 0.30 | game dev | 4097 | embeddable tilemap editor +**stb_herringbone_wa...** | 0.6 | game dev | 1217 | herringbone Wang tile map generator +**stb_c_lexer.h** | 0.06 | parsing | 809 | simplify writing parsers for C-like languages +**stb_divide.h** | 0.91 | math | 373 | more useful 32-bit modulus e.g. "euclidean divide" +**stb.h** | 2.24 | misc | 14086 | helper functions for C, mostly redundant in C++; basically author's personal stuff +**stb_leakcheck.h** | 0.1 | misc | 117 | quick-and-dirty malloc/free leak-checking FAQ --- diff --git a/tools/README.header.md b/tools/README.header.md index a5a6fb7..f30e631 100644 --- a/tools/README.header.md +++ b/tools/README.header.md @@ -3,5 +3,5 @@ stb single-file public domain libraries for C/C++ -library | lastest version | category | lines of code | description ---------------------- | ---- | -------- | ----------------------------- | -------------------------------- +library | lastest version | category | LoC | description +--------------------- | ---- | -------- | --- | -------------------------------- diff --git a/tools/make_readme.c b/tools/make_readme.c index 2fa593f..eb949a6 100644 --- a/tools/make_readme.c +++ b/tools/make_readme.c @@ -41,7 +41,7 @@ int main(int argc, char **argv) s2 = stb_dupreplace(s1, " ", " "); // stb_dupreplace -- search & replace string and malloc result fprintf(f, " | %s", s2); free(s2); - fprintf(f, " | %d", num_lines); + fprintf(f, " | %d", num_lines); for (j=2; j < num; ++j) fprintf(f, " | %s", tokens[j]); fprintf(f, "\n"); diff --git a/tools/make_readme.dsp b/tools/make_readme.dsp index e5969ae..232dd86 100644 --- a/tools/make_readme.dsp +++ b/tools/make_readme.dsp @@ -87,6 +87,10 @@ SOURCE=.\make_readme.c # End Source File # Begin Source File +SOURCE=.\README.header.md +# End Source File +# Begin Source File + SOURCE=.\README.list # End Source File # End Target From e105a19be99fc28088a78618be59a4b0ced5b304 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 03:33:54 -0700 Subject: [PATCH 24/50] add summary statistics --- README.md | 4 ++++ tools/make_readme.c | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e2e637..164d72f 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,10 @@ library | lastest version | category | LoC | description **stb.h** | 2.24 | misc | 14086 | helper functions for C, mostly redundant in C++; basically author's personal stuff **stb_leakcheck.h** | 0.1 | misc | 117 | quick-and-dirty malloc/free leak-checking +Total libraries: 18 +Total lines of C code: 45214 + + FAQ --- diff --git a/tools/make_readme.c b/tools/make_readme.c index eb949a6..03c9060 100644 --- a/tools/make_readme.c +++ b/tools/make_readme.c @@ -4,7 +4,7 @@ int main(int argc, char **argv) { int i; - int hlen, flen, listlen; + int hlen, flen, listlen, total_lines = 0; char *header = stb_file("README.header.md", &hlen); // stb_file - read file into malloc()ed buffer char *footer = stb_file("README.footer.md", &flen); // stb_file - read file into malloc()ed buffer char **list = stb_stringfile("README.list", &listlen); // stb_stringfile - read file lines into malloced array of strings @@ -42,11 +42,16 @@ int main(int argc, char **argv) fprintf(f, " | %s", s2); free(s2); fprintf(f, " | %d", num_lines); + total_lines += num_lines; for (j=2; j < num; ++j) fprintf(f, " | %s", tokens[j]); fprintf(f, "\n"); } + fprintf(f, "\n"); + fprintf(f, "Total libraries: %d \n", listlen); + fprintf(f, "Total lines of C code: %d\n\n", total_lines); + fwrite(footer, 1, flen, f); fclose(f); From cbcbaff851d2406f086d29f90d8bda3f5e9b5189 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 03:38:40 -0700 Subject: [PATCH 25/50] replace public-domain rationale with link to longer public domain rationale document --- README.md | 9 +++------ tools/README.footer.md | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 164d72f..893cfdb 100644 --- a/README.md +++ b/README.md @@ -107,12 +107,9 @@ Yes. https://github.com/nothings/stb/blob/master/docs/stb_howto.txt #### Why public domain? -Because more people will use it. Because it's not viral, people -are not obligated to give back, so you could argue that it hurts -the *development* of it, and then because it doesn't develop as -well it's not as good, and then because it's not as good, in the -long run maybe fewer people will use it. I have total respect for -that opinion, but I just don't believe it myself for most software. +I prefer it over GPL, LGPL, BSD, zlib, etc. for many reasons. +Some of them are listed here: +https://github.com/nothings/stb/blob/master/docs/why_public_domain.md #### Why C? diff --git a/tools/README.footer.md b/tools/README.footer.md index a3dc19f..aa07eeb 100644 --- a/tools/README.footer.md +++ b/tools/README.footer.md @@ -78,12 +78,9 @@ Yes. https://github.com/nothings/stb/blob/master/docs/stb_howto.txt #### Why public domain? -Because more people will use it. Because it's not viral, people -are not obligated to give back, so you could argue that it hurts -the *development* of it, and then because it doesn't develop as -well it's not as good, and then because it's not as good, in the -long run maybe fewer people will use it. I have total respect for -that opinion, but I just don't believe it myself for most software. +I prefer it over GPL, LGPL, BSD, zlib, etc. for many reasons. +Some of them are listed here: +https://github.com/nothings/stb/blob/master/docs/why_public_domain.md #### Why C? From 3f17b24d9062f30973f217d3799691ddedc4b04c Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 03:53:26 -0700 Subject: [PATCH 26/50] make sure all libs compile as C++ --- stb_leakcheck.h | 4 +- stretchy_buffer.h | 5 +- tests/stb.dsp | 4 ++ tests/stb_cpp.cpp | 1 - tests/test_cpp_compilation.cpp | 104 ++++++++++++++++++++++++++++++++- 5 files changed, 112 insertions(+), 6 deletions(-) diff --git a/stb_leakcheck.h b/stb_leakcheck.h index d309da5..a75df7c 100644 --- a/stb_leakcheck.h +++ b/stb_leakcheck.h @@ -1,4 +1,4 @@ -// stb_leakcheck.h - v0.1 - quick & dirty malloc leak-checking - public domain +// stb_leakcheck.h - v0.2 - quick & dirty malloc leak-checking - public domain #ifdef STB_LEAKCHECK_IMPLEMENTATION #undef STB_LEAKCHECK_IMPLEMENTATION // don't implenment more than once @@ -27,7 +27,7 @@ static stb_leakcheck_malloc_info *mi_head; void *stb_leakcheck_malloc(size_t sz, char *file, int line) { - stb_leakcheck_malloc_info *mi = malloc(sz + sizeof(*mi)); + stb_leakcheck_malloc_info *mi = (stb_leakcheck_malloc_info *) malloc(sz + sizeof(*mi)); if (mi == NULL) return mi; mi->file = file; mi->line = line; diff --git a/stretchy_buffer.h b/stretchy_buffer.h index 967e076..a89be09 100644 --- a/stretchy_buffer.h +++ b/stretchy_buffer.h @@ -1,7 +1,8 @@ -// stretchy_buffer.h - v1.01 - public domain - nothings.org/stb +// stretchy_buffer.h - v1.02 - public domain - nothings.org/stb // a vector<>-like dynamic array for C // // version history: +// 1.02 - compiles as C++, but untested // 1.01 - added a "common uses" documentation section // 1.0 - fixed bug in the version I posted prematurely // 0.9 - rewrite to try to avoid strict-aliasing optimization @@ -193,7 +194,7 @@ static void * stb__sbgrowf(void *arr, int increment, int itemsize) int dbl_cur = arr ? 2*stb__sbm(arr) : 0; int min_needed = stb_sb_count(arr) + increment; int m = dbl_cur > min_needed ? dbl_cur : min_needed; - int *p = realloc(arr ? stb__sbraw(arr) : 0, itemsize * m + sizeof(int)*2); + int *p = (int *) realloc(arr ? stb__sbraw(arr) : 0, itemsize * m + sizeof(int)*2); if (p) { if (!arr) p[1] = 0; diff --git a/tests/stb.dsp b/tests/stb.dsp index b86c6d2..c29cb4c 100644 --- a/tests/stb.dsp +++ b/tests/stb.dsp @@ -150,6 +150,10 @@ SOURCE=..\stb_vorbis.c # End Source File # Begin Source File +SOURCE=..\stb_voxel_render.h +# End Source File +# Begin Source File + SOURCE=..\stretchy_buffer.h # End Source File # Begin Source File diff --git a/tests/stb_cpp.cpp b/tests/stb_cpp.cpp index 94a7310..57f2cfa 100644 --- a/tests/stb_cpp.cpp +++ b/tests/stb_cpp.cpp @@ -80,4 +80,3 @@ int main(int argc, char **argv) } return 0; } - \ No newline at end of file diff --git a/tests/test_cpp_compilation.cpp b/tests/test_cpp_compilation.cpp index 59b7969..97bd2c2 100644 --- a/tests/test_cpp_compilation.cpp +++ b/tests/test_cpp_compilation.cpp @@ -8,7 +8,6 @@ #define STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION #define STB_RECT_PACK_IMPLEMENTATION #define STB_VOXEL_RENDER_IMPLEMENTATION -#define STBVOX_CONFIG_MODE 1 #define STBI_MALLOC my_malloc #define STBI_FREE my_free @@ -27,9 +26,112 @@ void my_free(void *) { } #include "stb_c_lexer.h" #include "stb_divide.h" #include "stb_herringbone_wang_tile.h" + +#define STBVOX_CONFIG_MODE 1 #include "stb_voxel_render.h" #define STBTE_DRAW_RECT(x0,y0,x1,y1,color) do ; while(0) #define STBTE_DRAW_TILE(x,y,id,highlight,data) do ; while(0) #define STB_TILEMAP_EDITOR_IMPLEMENTATION #include "stb_tilemap_editor.h" + +#include "stb_easy_font.h" + +#define STB_LEAKCHECK_IMPLEMENTATION +#include "stb_leakcheck.h" + +#define STB_IMAGE_RESIZE_IMPLEMENTATION +#include "stb_image_resize.h" + +#include "stretchy_buffer.h" + + + +//////////////////////////////////////////////////////////// +// +// text edit + +#include +#include // memmove +#include // isspace + +#define STB_TEXTEDIT_CHARTYPE char +#define STB_TEXTEDIT_STRING text_control + +// get the base type +#include "stb_textedit.h" + +// define our editor structure +typedef struct +{ + char *string; + int stringlen; + STB_TexteditState state; +} text_control; + +// define the functions we need +void layout_func(StbTexteditRow *row, STB_TEXTEDIT_STRING *str, int start_i) +{ + int remaining_chars = str->stringlen - start_i; + row->num_chars = remaining_chars > 20 ? 20 : remaining_chars; // should do real word wrap here + row->x0 = 0; + row->x1 = 20; // need to account for actual size of characters + row->baseline_y_delta = 1.25; + row->ymin = -1; + row->ymax = 0; +} + +int delete_chars(STB_TEXTEDIT_STRING *str, int pos, int num) +{ + memmove(&str->string[pos], &str->string[pos+num], str->stringlen - (pos+num)); + str->stringlen -= num; + return 1; // always succeeds +} + +int insert_chars(STB_TEXTEDIT_STRING *str, int pos, STB_TEXTEDIT_CHARTYPE *newtext, int num) +{ + str->string = (char *) realloc(str->string, str->stringlen + num); + memmove(&str->string[pos+num], &str->string[pos], str->stringlen - pos); + memcpy(&str->string[pos], newtext, num); + str->stringlen += num; + return 1; // always succeeds +} + +// define all the #defines needed + +#define KEYDOWN_BIT 0x80000000 + +#define STB_TEXTEDIT_STRINGLEN(tc) ((tc)->stringlen) +#define STB_TEXTEDIT_LAYOUTROW layout_func +#define STB_TEXTEDIT_GETWIDTH(tc,n,i) (1) // quick hack for monospaced +#define STB_TEXTEDIT_KEYTOTEXT(key) (((key) & KEYDOWN_BIT) ? 0 : (key)) +#define STB_TEXTEDIT_GETCHAR(tc,i) ((tc)->string[i]) +#define STB_TEXTEDIT_NEWLINE '\n' +#define STB_TEXTEDIT_IS_SPACE(ch) isspace(ch) +#define STB_TEXTEDIT_DELETECHARS delete_chars +#define STB_TEXTEDIT_INSERTCHARS insert_chars + +#define STB_TEXTEDIT_K_SHIFT 0x40000000 +#define STB_TEXTEDIT_K_CONTROL 0x20000000 +#define STB_TEXTEDIT_K_LEFT (KEYDOWN_BIT | 1) // actually use VK_LEFT, SDLK_LEFT, etc +#define STB_TEXTEDIT_K_RIGHT (KEYDOWN_BIT | 2) // VK_RIGHT +#define STB_TEXTEDIT_K_UP (KEYDOWN_BIT | 3) // VK_UP +#define STB_TEXTEDIT_K_DOWN (KEYDOWN_BIT | 4) // VK_DOWN +#define STB_TEXTEDIT_K_LINESTART (KEYDOWN_BIT | 5) // VK_HOME +#define STB_TEXTEDIT_K_LINEEND (KEYDOWN_BIT | 6) // VK_END +#define STB_TEXTEDIT_K_TEXTSTART (STB_TEXTEDIT_K_LINESTART | STB_TEXTEDIT_K_CONTROL) +#define STB_TEXTEDIT_K_TEXTEND (STB_TEXTEDIT_K_LINEEND | STB_TEXTEDIT_K_CONTROL) +#define STB_TEXTEDIT_K_DELETE (KEYDOWN_BIT | 7) // VK_DELETE +#define STB_TEXTEDIT_K_BACKSPACE (KEYDOWN_BIT | 8) // VK_BACKSPACE +#define STB_TEXTEDIT_K_UNDO (KEYDOWN_BIT | STB_TEXTEDIT_K_CONTROL | 'z') +#define STB_TEXTEDIT_K_REDO (KEYDOWN_BIT | STB_TEXTEDIT_K_CONTROL | 'y') +#define STB_TEXTEDIT_K_INSERT (KEYDOWN_BIT | 9) // VK_INSERT +#define STB_TEXTEDIT_K_WORDLEFT (STB_TEXTEDIT_K_LEFT | STB_TEXTEDIT_K_CONTROL) +#define STB_TEXTEDIT_K_WORDRIGHT (STB_TEXTEDIT_K_RIGHT | STB_TEXTEDIT_K_CONTROL) +#define STB_TEXTEDIT_K_PGUP (KEYDOWN_BIT | 10) // VK_PGUP -- not implemented +#define STB_TEXTEDIT_K_PGDOWN (KEYDOWN_BIT | 11) // VK_PGDOWN -- not implemented + +#define STB_TEXTEDIT_IMPLEMENTATION +#include "stb_textedit.h" + + From 0d7f3bb60b68c606eb4b75cf1d2bfc8b750f6d88 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Apr 2015 03:53:57 -0700 Subject: [PATCH 27/50] update version numbers for minor libraries that have been made C++-compatible --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 893cfdb..b967c81 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ library | lastest version | category | LoC | description **stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP **stb_image_resize.h** | 0.90 | graphics | 2585 | resize images larger/smaller with good quality **stb_rect_pack.h** | 0.05 | graphics | 546 | simple 2D rectangle packer with decent quality -**stretchy_buffer.h** | 1.01 | utility | 209 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++ +**stretchy_buffer.h** | 1.02 | utility | 210 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++ **stb_textedit.h** | 1.5 | UI | 1284 | guts of a text editor for games etc implementing them from scratch **stb_voxel_render.h** | 0.80 | 3D graphics | 3644 | Minecraft-esque voxel rendering "engine" with many more features **stb_dxt.h** | 1.04 | 3D graphics | 624 | Fabian "ryg" Giesen's real-time DXT compressor @@ -22,10 +22,10 @@ library | lastest version | category | LoC | description **stb_c_lexer.h** | 0.06 | parsing | 809 | simplify writing parsers for C-like languages **stb_divide.h** | 0.91 | math | 373 | more useful 32-bit modulus e.g. "euclidean divide" **stb.h** | 2.24 | misc | 14086 | helper functions for C, mostly redundant in C++; basically author's personal stuff -**stb_leakcheck.h** | 0.1 | misc | 117 | quick-and-dirty malloc/free leak-checking +**stb_leakcheck.h** | 0.2 | misc | 117 | quick-and-dirty malloc/free leak-checking Total libraries: 18 -Total lines of C code: 45214 +Total lines of C code: 45215 FAQ From 63550ae9edefffece9b4b50cdb47353b5d9ee534 Mon Sep 17 00:00:00 2001 From: Peter LaValle Date: Tue, 14 Apr 2015 13:03:05 +0100 Subject: [PATCH 28/50] Update stb_truetype.h trivial typo --- stb_truetype.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_truetype.h b/stb_truetype.h index 26aba20..011c077 100644 --- a/stb_truetype.h +++ b/stb_truetype.h @@ -239,7 +239,7 @@ GLuint ftex; void my_stbtt_initfont(void) { fread(ttf_buffer, 1, 1<<20, fopen("c:/windows/fonts/times.ttf", "rb")); - stbtt_BakeFontBitmap(data,0, 32.0, temp_bitmap,512,512, 32,96, cdata); // no guarantee this fits! + stbtt_BakeFontBitmap(ttf_buffer,0, 32.0, temp_bitmap,512,512, 32,96, cdata); // no guarantee this fits! // can free ttf_buffer at this point glGenTextures(1, &ftex); glBindTexture(GL_TEXTURE_2D, ftex); From 53011a3d96761196a09ef74ac872fdb8bf9cbd91 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:10:02 -0700 Subject: [PATCH 29/50] fix declaration of stbte_create_map --- stb_tilemap_editor.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index ed56a10..41d02fe 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -275,6 +275,8 @@ // either approach allows cut&pasting between levels.) // // REVISION HISTORY +// 0.31 bugfixes +// - fix declaration of stbte_create_map // 0.30 properties release // - properties panel for editing user-defined "object" properties // - can link each tile to one other tile @@ -339,7 +341,7 @@ enum // creation // -extern stbte_tilemap *stbte_create(int map_x, int map_y, int map_layers, int spacing_x, int spacing_y, int max_tiles); +extern stbte_tilemap *stbte_create_map(int map_x, int map_y, int map_layers, int spacing_x, int spacing_y, int max_tiles); // create an editable tilemap // map_x : dimensions of map horizontally (user can change this in editor), <= STBTE_MAX_TILEMAP_X // map_y : dimensions of map vertically (user can change this in editor) <= STBTE_MAX_TILEMAP_Y @@ -352,7 +354,7 @@ extern stbte_tilemap *stbte_create(int map_x, int map_y, int map_layers, int spa extern void stbte_define_tile(stbte_tilemap *tm, unsigned short id, unsigned int layermask, const char * category); // call this repeatedly for each tile to install the tile definitions into the editable tilemap -// tm : tilemap created by stbte_create +// tm : tilemap created by stbte_create_map // id : unique identifier for each tile, 0 <= id < 32768 // layermask : bitmask of which layers tile is allowed on: 1 = layer 0, 255 = layers 0..7 // (note that onscreen, the editor numbers the layers from 1 not 0) From 6cb8c1b624a15f4266c16ef2898b63a1db6a963f Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:17:44 -0700 Subject: [PATCH 30/50] make compile as C --- stb_tilemap_editor.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index 80c6275..3cb9471 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -1,4 +1,4 @@ -// stb_tilemap_editor.h - v0.31 - Sean Barrett - http://nothings.org/stb +// stb_tilemap_editor.h - v0.35 - Sean Barrett - http://nothings.org/stb // placed in the public domain - not copyrighted - first released 2014-09 // // Embeddable tilemap editor for C/C++ @@ -275,7 +275,7 @@ // either approach allows cut&pasting between levels.) // // REVISION HISTORY -// 0.31 layername button changes +// 0.35 layername button changes // - layername buttons grow with the layer panel // - fix stbte_create_map being declared as stbte_create // - fix declaration of stbte_create_map @@ -1100,9 +1100,10 @@ void stbte_set_layername(stbte_tilemap *tm, int layer, const char *layername) { STBTE_ASSERT(layer >= 0 && layer < tm->num_layers); if (layer >= 0 && layer < tm->num_layers) { + int width; tm->layerinfo[layer].name = layername; tm->has_layer_names = 1; - int width = stbte__text_width(layername); + width = stbte__text_width(layername); tm->layername_width = (width > tm->layername_width ? width : tm->layername_width); } } @@ -3392,6 +3393,10 @@ static void stbte__info(stbte_tilemap *tm, int x0, int y0, int w, int h) static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) { + static char *propmodes[3] = { + "default", "always", "never" + }; + int num_rows; int i, y, n; int x1 = x0+w; int y1 = y0+h; @@ -3403,10 +3408,6 @@ static void stbte__layers(stbte_tilemap *tm, int x0, int y0, int w, int h) xoff = (xoff < tm->layername_width + 10 ? xoff : tm->layername_width + 10); } - static char *propmodes[3] = { - "default", "always", "never" - }; - int num_rows; x0 += 2; y0 += 5; if (!tm->has_layer_names) { From 9d4da3f7ccf1fd7cee0c74720bcf875b0300f24d Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:18:48 -0700 Subject: [PATCH 31/50] update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b967c81..a2dde61 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ library | lastest version | category | LoC | description **stb_dxt.h** | 1.04 | 3D graphics | 624 | Fabian "ryg" Giesen's real-time DXT compressor **stb_perlin.h** | 0.2 | 3D graphics | 175 | revised Perlin noise (3D input, 1D output) **stb_easy_font.h** | 0.5 | 3D graphics | 220 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc -**stb_tilemap_editor.h** | 0.30 | game dev | 4097 | embeddable tilemap editor +**stb_tilemap_editor.h** | 0.35 | game dev | 4115 | embeddable tilemap editor **stb_herringbone_wa...** | 0.6 | game dev | 1217 | herringbone Wang tile map generator **stb_c_lexer.h** | 0.06 | parsing | 809 | simplify writing parsers for C-like languages **stb_divide.h** | 0.91 | math | 373 | more useful 32-bit modulus e.g. "euclidean divide" @@ -25,7 +25,7 @@ library | lastest version | category | LoC | description **stb_leakcheck.h** | 0.2 | misc | 117 | quick-and-dirty malloc/free leak-checking Total libraries: 18 -Total lines of C code: 45215 +Total lines of C code: 45233 FAQ From a51c2d4ab02d1e835850f70a1f154f318d26e03f Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:21:59 -0700 Subject: [PATCH 32/50] update version number etc --- stb_truetype.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stb_truetype.h b/stb_truetype.h index 011c077..812691d 100644 --- a/stb_truetype.h +++ b/stb_truetype.h @@ -1,4 +1,4 @@ -// stb_truetype.h - v1.03 - public domain +// stb_truetype.h - v1.04 - public domain // authored from 2009-2014 by Sean Barrett / RAD Game Tools // // This library processes TrueType files: @@ -38,12 +38,14 @@ // Cap Petschulat // Omar Cornut // github:aloucks +// Peter LaValle // // Misc other: // Ryan Gordon // // VERSION HISTORY // +// 1.04 (2015-04-15) typo in example // 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes // 1.02 (2014-12-10) fix various warnings & compile issues w/ stb_rect_pack, C++ // 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match From 457679209b7dc2214637ddbb7b893039bc4a3398 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:22:19 -0700 Subject: [PATCH 33/50] update truetype version # --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a2dde61..efb63df 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ library | lastest version | category | LoC | description --------------------- | ---- | -------- | --- | -------------------------------- **stb_vorbis.c** | 1.04 | audio | 5443 | decode ogg vorbis files from file/memory to float/16-bit signed output **stb_image.h** | 2.03 | graphics | 6426 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC -**stb_truetype.h** | 1.03 | graphics | 2629 | parse, decode, and rasterize characters from truetype fonts +**stb_truetype.h** | 1.04 | graphics | 2631 | parse, decode, and rasterize characters from truetype fonts **stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP **stb_image_resize.h** | 0.90 | graphics | 2585 | resize images larger/smaller with good quality **stb_rect_pack.h** | 0.05 | graphics | 546 | simple 2D rectangle packer with decent quality @@ -25,7 +25,7 @@ library | lastest version | category | LoC | description **stb_leakcheck.h** | 0.2 | misc | 117 | quick-and-dirty malloc/free leak-checking Total libraries: 18 -Total lines of C code: 45233 +Total lines of C code: 45235 FAQ From d710ada2f9d6f7ffcc9ee21a379c41482bbeae5e Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:31:12 -0700 Subject: [PATCH 34/50] try to re-enable SSE2 support by default on mingw 64-bit --- README.md | 4 ++-- stb_image.h | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index efb63df..051b0ee 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ single-file public domain libraries for C/C++ library | lastest version | category | LoC | description --------------------- | ---- | -------- | --- | -------------------------------- **stb_vorbis.c** | 1.04 | audio | 5443 | decode ogg vorbis files from file/memory to float/16-bit signed output -**stb_image.h** | 2.03 | graphics | 6426 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC +**stb_image.h** | 2.04 | graphics | 6433 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC **stb_truetype.h** | 1.04 | graphics | 2631 | parse, decode, and rasterize characters from truetype fonts **stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP **stb_image_resize.h** | 0.90 | graphics | 2585 | resize images larger/smaller with good quality @@ -25,7 +25,7 @@ library | lastest version | category | LoC | description **stb_leakcheck.h** | 0.2 | misc | 117 | quick-and-dirty malloc/free leak-checking Total libraries: 18 -Total lines of C code: 45235 +Total lines of C code: 45242 FAQ diff --git a/stb_image.h b/stb_image.h index c00f346..01d74d3 100644 --- a/stb_image.h +++ b/stb_image.h @@ -1,4 +1,4 @@ -/* stb_image - v2.03 - public domain image loader - http://nothings.org/stb_image.h +/* stb_image - v2.04 - public domain image loader - http://nothings.org/stb_image.h no warranty implied; use at your own risk Do this: @@ -143,6 +143,7 @@ Latest revision history: + 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit 2.03 (2015-04-12) additional corruption checking stbi_set_flip_vertically_on_load fix NEON support; fix mingw support @@ -633,11 +634,14 @@ typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1]; #endif // x86/x64 detection -#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) +#if defined(__x86_64__) || defined(_M_X64) +#define STBI__X64_TARGET +#elif defined(__i386) || defined(_M_IX86) #define STBI__X86_TARGET #endif -#if defined(__GNUC__) && defined(STBI__X86_TARGET) && !defined(__SSE2__) && !defined(STBI_NO_SIMD) +#if defined(__GNUC__) && (defined(STBI__X86_TARGET) || defined(STBI__X64_TARGET)) && !defined(__SSE2__) && !defined(STBI_NO_SIMD) +// NOTE: not clear do we actually need this for the 64-bit path? // gcc doesn't support sse2 intrinsics unless you compile with -msse2, // (but compiling with -msse2 allows the compiler to use SSE2 everywhere; // this is just broken and gcc are jerks for not fixing it properly @@ -646,6 +650,8 @@ typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1]; #endif #if defined(__MINGW32__) && defined(STBI__X86_TARGET) && !defined(STBI_MINGW_ENABLE_SSE2) && !defined(STBI_NO_SIMD) +// Note that __MINGW32__ doesn't actually mean 32-bit, so we have to avoid STBI__X64_TARGET +// // 32-bit MinGW wants ESP to be 16-byte aligned, but this is not in the // Windows ABI and VC++ as well as Windows DLLs don't maintain that invariant. // As a result, enabling SSE2 on 32-bit MinGW is dangerous when not @@ -6287,6 +6293,7 @@ STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int /* revision history: + 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit 2.03 (2015-04-12) extra corruption checking (mmozeiko) stbi_set_flip_vertically_on_load (nguillemot) fix NEON support; fix mingw support From b92b225f61a35c90bf7a202d5cc8b88afdb620ae Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:35:55 -0700 Subject: [PATCH 35/50] note that README is auto-generated so submitters don't need to change it --- README.md | 2 ++ tools/make_readme.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 051b0ee..ee58e19 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ + + stb === diff --git a/tools/make_readme.c b/tools/make_readme.c index 03c9060..224f289 100644 --- a/tools/make_readme.c +++ b/tools/make_readme.c @@ -10,6 +10,8 @@ int main(int argc, char **argv) char **list = stb_stringfile("README.list", &listlen); // stb_stringfile - read file lines into malloced array of strings FILE *f = fopen("../README.md", "wb"); + + fprintf(f, "\n\n"); fwrite(header, 1, hlen, f); for (i=0; i < listlen; ++i) { From 1acf56b8fb9e087e46c89b21873c9be3b73073cd Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:40:15 -0700 Subject: [PATCH 36/50] tweak credits --- stb_tilemap_editor.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/stb_tilemap_editor.h b/stb_tilemap_editor.h index 3cb9471..bd22a4d 100644 --- a/stb_tilemap_editor.h +++ b/stb_tilemap_editor.h @@ -303,8 +303,13 @@ // // CREDITS // -// Written by Sean Barrett, September & October 2014. -// Contributions from Josh Huelsman, January 2015. +// +// Main editor & features +// Sean Barrett +// Additional features: +// Josh Huelsman +// Bugfixes: +// [this could be you!] // // LICENSE // From 9487a59c14a798022d0b8aa787c9757b6cd5ef83 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:52:25 -0700 Subject: [PATCH 37/50] STB_TEXTEDIT_memmove --- stb_textedit.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/stb_textedit.h b/stb_textedit.h index 3682d97..1f78048 100644 --- a/stb_textedit.h +++ b/stb_textedit.h @@ -1,4 +1,4 @@ -// stb_textedit.h - v1.5 - public domain - Sean Barrett +// stb_textedit.h - v1.6 - public domain - Sean Barrett // Development of this library was sponsored by RAD Game Tools // // This C header file implements the guts of a multi-line text-editing @@ -24,12 +24,14 @@ // // DEPENDENCIES // -// Uses the C runtime function 'memmove'. Uses no other functions. -// Performs no runtime allocations. +// Uses the C runtime function 'memmove', which you can override +// by defining STB_TEXTEDIT_memmove before the implementation. +// Uses no other functions. Performs no runtime allocations. // // // VERSION HISTORY // +// 1.6 (2015-04-15) allow STB_TEXTEDIT_memmove // 1.5 (2014-09-10) add support for secondary keys for OS X // 1.4 (2014-08-17) fix signed/unsigned warnings // 1.3 (2014-06-19) fix mouse clicking to round to nearest char boundary @@ -45,6 +47,7 @@ // Ulf Winklemann: move-by-word in 1.1 // Scott Graham: mouse selection bugfix in 1.3 // Fabian Giesen: secondary key inputs in 1.5 +// Martins Mozeiko: STB_TEXTEDIT_memmove // // USAGE // @@ -358,9 +361,9 @@ typedef struct // included just the "header" portion #ifdef STB_TEXTEDIT_IMPLEMENTATION -#ifndef STBTE_memmove +#ifndef STB_TEXTEDIT_memmove #include -#define STBTE_memmove memmove +#define STB_TEXTEDIT_memmove memmove #endif @@ -1041,13 +1044,13 @@ static void stb_textedit_discard_undo(StbUndoState *state) int n = state->undo_rec[0].insert_length, i; // delete n characters from all other records state->undo_char_point = state->undo_char_point - (short) n; // vsnet05 - STBTE_memmove(state->undo_char, state->undo_char + n, (size_t) (state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE))); + STB_TEXTEDIT_memmove(state->undo_char, state->undo_char + n, (size_t) (state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE))); for (i=0; i < state->undo_point; ++i) if (state->undo_rec[i].char_storage >= 0) state->undo_rec[i].char_storage = state->undo_rec[i].char_storage - (short) n; // vsnet05 // @OPTIMIZE: get rid of char_storage and infer it } --state->undo_point; - STBTE_memmove(state->undo_rec, state->undo_rec+1, (size_t) (state->undo_point*sizeof(state->undo_rec[0]))); + STB_TEXTEDIT_memmove(state->undo_rec, state->undo_rec+1, (size_t) (state->undo_point*sizeof(state->undo_rec[0]))); } } @@ -1065,13 +1068,13 @@ static void stb_textedit_discard_redo(StbUndoState *state) int n = state->undo_rec[k].insert_length, i; // delete n characters from all other records state->redo_char_point = state->redo_char_point + (short) n; // vsnet05 - STBTE_memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE))); + STB_TEXTEDIT_memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE))); for (i=state->redo_point; i < k; ++i) if (state->undo_rec[i].char_storage >= 0) state->undo_rec[i].char_storage = state->undo_rec[i].char_storage + (short) n; // vsnet05 } ++state->redo_point; - STBTE_memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0]))); + STB_TEXTEDIT_memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0]))); } } From e927c3a07aa3533486b0bbc3510b08192c15c6eb Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:58:00 -0700 Subject: [PATCH 38/50] rename to STBRP_SORT for STBRP_ASSERT consistency; version number, credits --- stb_rect_pack.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/stb_rect_pack.h b/stb_rect_pack.h index 8c73a30..63a5b15 100644 --- a/stb_rect_pack.h +++ b/stb_rect_pack.h @@ -1,4 +1,4 @@ -// stb_rect_pack.h - v0.05 - public domain - rectangle packing +// stb_rect_pack.h - v0.06 - public domain - rectangle packing // Sean Barrett 2014 // // Useful for e.g. packing rectangular textures into an atlas. @@ -13,6 +13,7 @@ // More docs to come. // // No memory allocations; uses qsort() and assert() from stdlib. +// Can override those by defining STBRP_SORT and STBRP_ASSERT. // // This library currently uses the Skyline Bottom-Left algorithm. // @@ -20,8 +21,18 @@ // implement them to the same API, but with a different init // function. // +// Credits +// +// Library +// Sean Barrett +// Minor features +// Martins Mozeiko +// Bugfixes / warning fixes +// [your name could be here] +// // Version history: // +// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort // 0.05: added STBRP_ASSERT to allow replacing assert // 0.04: fixed minor bug in STBRP_LARGE_RECTS support // 0.01: initial release @@ -169,9 +180,9 @@ struct stbrp_context // #ifdef STB_RECT_PACK_IMPLEMENTATION -#ifndef STBRP_sort +#ifndef STBRP_SORT #include -#define STBRP_sort qsort +#define STBRP_SORT qsort #endif #ifndef STBRP_ASSERT @@ -527,7 +538,7 @@ STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int n } // sort according to heuristic - STBRP_sort(rects, num_rects, sizeof(rects[0]), rect_height_compare); + STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare); for (i=0; i < num_rects; ++i) { stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h); @@ -540,7 +551,7 @@ STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int n } // unsort - STBRP_sort(rects, num_rects, sizeof(rects[0]), rect_original_order); + STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order); // set was_packed flags for (i=0; i < num_rects; ++i) From 294340b25d8b0cc2ec74ea03a445da49c67db30a Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 02:59:17 -0700 Subject: [PATCH 39/50] update version numbers --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ee58e19..b771b9b 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,14 @@ library | lastest version | category | LoC | description **stb_truetype.h** | 1.04 | graphics | 2631 | parse, decode, and rasterize characters from truetype fonts **stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP **stb_image_resize.h** | 0.90 | graphics | 2585 | resize images larger/smaller with good quality -**stb_rect_pack.h** | 0.05 | graphics | 546 | simple 2D rectangle packer with decent quality +**stb_rect_pack.h** | 0.06 | graphics | 560 | simple 2D rectangle packer with decent quality **stretchy_buffer.h** | 1.02 | utility | 210 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++ -**stb_textedit.h** | 1.5 | UI | 1284 | guts of a text editor for games etc implementing them from scratch +**stb_textedit.h** | 1.6 | UI | 1290 | guts of a text editor for games etc implementing them from scratch **stb_voxel_render.h** | 0.80 | 3D graphics | 3644 | Minecraft-esque voxel rendering "engine" with many more features **stb_dxt.h** | 1.04 | 3D graphics | 624 | Fabian "ryg" Giesen's real-time DXT compressor **stb_perlin.h** | 0.2 | 3D graphics | 175 | revised Perlin noise (3D input, 1D output) **stb_easy_font.h** | 0.5 | 3D graphics | 220 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc -**stb_tilemap_editor.h** | 0.35 | game dev | 4115 | embeddable tilemap editor +**stb_tilemap_editor.h** | 0.35 | game dev | 4120 | embeddable tilemap editor **stb_herringbone_wa...** | 0.6 | game dev | 1217 | herringbone Wang tile map generator **stb_c_lexer.h** | 0.06 | parsing | 809 | simplify writing parsers for C-like languages **stb_divide.h** | 0.91 | math | 373 | more useful 32-bit modulus e.g. "euclidean divide" @@ -27,7 +27,7 @@ library | lastest version | category | LoC | description **stb_leakcheck.h** | 0.2 | misc | 117 | quick-and-dirty malloc/free leak-checking Total libraries: 18 -Total lines of C code: 45242 +Total lines of C code: 45267 FAQ From e4be8fae2c3688094fbc6e4721fdab5495712234 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 15 Apr 2015 16:06:46 -0700 Subject: [PATCH 40/50] fix misplaced STBTT_DEF definition --- stb_truetype.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/stb_truetype.h b/stb_truetype.h index 812691d..ae60212 100644 --- a/stb_truetype.h +++ b/stb_truetype.h @@ -1,4 +1,4 @@ -// stb_truetype.h - v1.04 - public domain +// stb_truetype.h - v1.05 - public domain // authored from 2009-2014 by Sean Barrett / RAD Game Tools // // This library processes TrueType files: @@ -45,6 +45,7 @@ // // VERSION HISTORY // +// 1.05 (2015-04-15) fix misplaced definitions for STBTT_STATIC // 1.04 (2015-04-15) typo in example // 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes // 1.02 (2014-12-10) fix various warnings & compile issues w/ stb_rect_pack, C++ @@ -387,12 +388,6 @@ int main(int arg, char **argv) typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1]; typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1]; - #ifdef STBTT_STATIC - #define STBTT_DEF static - #else - #define STBTT_DEF extern - #endif - // #define your own STBTT_sort() to override this to avoid qsort #ifndef STBTT_sort #include @@ -445,6 +440,12 @@ int main(int arg, char **argv) #ifndef __STB_INCLUDE_STB_TRUETYPE_H__ #define __STB_INCLUDE_STB_TRUETYPE_H__ +#ifdef STBTT_STATIC +#define STBTT_DEF static +#else +#define STBTT_DEF extern +#endif + #ifdef __cplusplus extern "C" { #endif From fda335609f25d717d84f1e08026d5cb728764bd9 Mon Sep 17 00:00:00 2001 From: Nicolas Guillemot Date: Sat, 18 Apr 2015 20:39:46 -0700 Subject: [PATCH 41/50] don't redefine __forceinline with mingw mingw redefines __forceinline (though I don't think this applies to all versions of mingw.) Therefore, don't redefine it if mingw has already defined it. --- stb_vorbis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_vorbis.c b/stb_vorbis.c index ef346fc..4920eb6 100644 --- a/stb_vorbis.c +++ b/stb_vorbis.c @@ -553,7 +553,7 @@ enum STBVorbisError #define NULL 0 #endif -#ifndef _MSC_VER +#if !defined(_MSC_VER) && !(defined(__MINGW32__) && defined(__forceinline)) #if __GNUC__ #define __forceinline inline #else From 1894bede3f88007b78aca6130af7ff556e8929c5 Mon Sep 17 00:00:00 2001 From: Nicolas Guillemot Date: Sat, 18 Apr 2015 21:23:34 -0700 Subject: [PATCH 42/50] fix signed/unsignted compare warning --- stb_image.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_image.h b/stb_image.h index 01d74d3..d3ee077 100644 --- a/stb_image.h +++ b/stb_image.h @@ -1646,7 +1646,7 @@ stbi_inline static int stbi__extend_receive(stbi__jpeg *j, int n) sgn = (stbi__int32)j->code_buffer >> 31; // sign bit is always in MSB k = stbi_lrot(j->code_buffer, n); - STBI_ASSERT(n >= 0 && n < sizeof(stbi__bmask)/sizeof(*stbi__bmask)); + STBI_ASSERT(n >= 0 && n < (int) (sizeof(stbi__bmask)/sizeof(*stbi__bmask))); j->code_buffer = k & ~stbi__bmask[n]; k &= stbi__bmask[n]; j->code_bits -= n; From f224bc2cdbbcf603a2d36e275a277a1969635aee Mon Sep 17 00:00:00 2001 From: Fabian Giesen Date: Sun, 19 Apr 2015 01:49:16 -0700 Subject: [PATCH 43/50] stb_image: Progressive AC decoding - fix ZRL code. The original AC decoding logic handled ZRL (runs of 16 zeros) incorrectly. The problem is that the original flow set r=16 and skipped the final coeff write when s=0. This is not actually correct. The problem is the intervening "refinement" bits. With the original logic, even once we decrement r to 0, we keep reading more refinement bits for subsequent coefficients until we find the next currently-unsent AC in the current scan. That is, it works as if it was trying to place 17 new AC values, and only bails at the last minute from actually setting that 17th value. This is wrong. Once we've found the 16th previously-unsent AC, we need to stop reading refinement bits, otherwise we get out of sync with the bit stream (which expects us to read a huffman code next). The easiest fix is to just do what the JPEG standard implicitly assumes anyway: treat ZRL as a run of 15 zeros followed by an explicit magnitude-zero AC coeff. (That is, leave s=0 and actually write s). So this is what this fix does. --- stb_image.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/stb_image.h b/stb_image.h index 01d74d3..67936f1 100644 --- a/stb_image.h +++ b/stb_image.h @@ -1852,8 +1852,8 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__ if (r) j->eob_run += stbi__jpeg_get_bits(j, r); r = 64; // force end of block - } else - r = 16; // r=15 is the code for 16 0s + } + // r=15 s=0 already does the right thing (write 16 0s) } else { if (s != 1) return stbi__err("bad huffman code", "Corrupt JPEG"); // sign bit @@ -1865,7 +1865,7 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__ // advance by r while (k <= j->spec_end) { - short *p = &data[stbi__jpeg_dezigzag[k]]; + short *p = &data[stbi__jpeg_dezigzag[k++]]; if (*p != 0) { if (stbi__jpeg_get_bit(j)) if ((*p & bit)==0) { @@ -1874,15 +1874,12 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__ else *p -= bit; } - ++k; } else { if (r == 0) { - if (s) - data[stbi__jpeg_dezigzag[k++]] = (short) s; + *p = (short) s; break; } --r; - ++k; } } } while (k <= j->spec_end); From ac5e25ae01b82018adca7fbcf8e5e58dbc322e07 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Sun, 19 Apr 2015 04:15:33 -0700 Subject: [PATCH 44/50] bump stb_image to version 2.05, tweak docs --- stb_image.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/stb_image.h b/stb_image.h index 67936f1..cb0c5e9 100644 --- a/stb_image.h +++ b/stb_image.h @@ -1,4 +1,4 @@ -/* stb_image - v2.04 - public domain image loader - http://nothings.org/stb_image.h +/* stb_image - v2.05 - public domain image loader - http://nothings.org/stb_image.h no warranty implied; use at your own risk Do this: @@ -143,6 +143,7 @@ Latest revision history: + 2.05 (2015-04-19) fix bug in progressive JPEG handling 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit 2.03 (2015-04-12) additional corruption checking stbi_set_flip_vertically_on_load @@ -160,8 +161,6 @@ 1.47 (2014-12-14) 1/2/4-bit PNG support (both grayscale and paletted) optimize PNG fix bug in interlaced PNG with user-specified channel count - 1.46 (2014-08-26) fix broken tRNS chunk in non-paletted PNG - 1.45 (2014-08-16) workaround MSVC-ARM internal compiler error by wrapping malloc See end of file for full revision history. @@ -1852,8 +1851,11 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__ if (r) j->eob_run += stbi__jpeg_get_bits(j, r); r = 64; // force end of block + } else { + // r=15 s=0 should write 16 0s, so we just do + // a run of 15 0s and then write s (which is 0), + // so we don't have to do anything special here } - // r=15 s=0 already does the right thing (write 16 0s) } else { if (s != 1) return stbi__err("bad huffman code", "Corrupt JPEG"); // sign bit @@ -6290,6 +6292,7 @@ STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int /* revision history: + 2.05 (2015-04-19) fix bug in progressive JPEG handling 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit 2.03 (2015-04-12) extra corruption checking (mmozeiko) stbi_set_flip_vertically_on_load (nguillemot) From b4b196af1c02acef15b8e1b9fd205b30393f1a37 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Sun, 19 Apr 2015 04:16:11 -0700 Subject: [PATCH 45/50] update version numbers --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b771b9b..0ce5e0b 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ single-file public domain libraries for C/C++ library | lastest version | category | LoC | description --------------------- | ---- | -------- | --- | -------------------------------- **stb_vorbis.c** | 1.04 | audio | 5443 | decode ogg vorbis files from file/memory to float/16-bit signed output -**stb_image.h** | 2.04 | graphics | 6433 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC -**stb_truetype.h** | 1.04 | graphics | 2631 | parse, decode, and rasterize characters from truetype fonts +**stb_image.h** | 2.05 | graphics | 6433 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC +**stb_truetype.h** | 1.05 | graphics | 2632 | parse, decode, and rasterize characters from truetype fonts **stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP **stb_image_resize.h** | 0.90 | graphics | 2585 | resize images larger/smaller with good quality **stb_rect_pack.h** | 0.06 | graphics | 560 | simple 2D rectangle packer with decent quality @@ -27,7 +27,7 @@ library | lastest version | category | LoC | description **stb_leakcheck.h** | 0.2 | misc | 117 | quick-and-dirty malloc/free leak-checking Total libraries: 18 -Total lines of C code: 45267 +Total lines of C code: 45268 FAQ From 947bdcd02716b6bb9f365710b23493ae1564f990 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Sun, 19 Apr 2015 04:19:55 -0700 Subject: [PATCH 46/50] update version numbers & docs --- README.md | 4 ++-- stb_image.h | 4 ++-- stb_vorbis.c | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0ce5e0b..7929edc 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ single-file public domain libraries for C/C++ library | lastest version | category | LoC | description --------------------- | ---- | -------- | --- | -------------------------------- -**stb_vorbis.c** | 1.04 | audio | 5443 | decode ogg vorbis files from file/memory to float/16-bit signed output +**stb_vorbis.c** | 1.05 | audio | 5445 | decode ogg vorbis files from file/memory to float/16-bit signed output **stb_image.h** | 2.05 | graphics | 6433 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC **stb_truetype.h** | 1.05 | graphics | 2632 | parse, decode, and rasterize characters from truetype fonts **stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP @@ -27,7 +27,7 @@ library | lastest version | category | LoC | description **stb_leakcheck.h** | 0.2 | misc | 117 | quick-and-dirty malloc/free leak-checking Total libraries: 18 -Total lines of C code: 45268 +Total lines of C code: 45270 FAQ diff --git a/stb_image.h b/stb_image.h index 140a150..79f076d 100644 --- a/stb_image.h +++ b/stb_image.h @@ -143,7 +143,7 @@ Latest revision history: - 2.05 (2015-04-19) fix bug in progressive JPEG handling + 2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit 2.03 (2015-04-12) additional corruption checking stbi_set_flip_vertically_on_load @@ -6292,7 +6292,7 @@ STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int /* revision history: - 2.05 (2015-04-19) fix bug in progressive JPEG handling + 2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit 2.03 (2015-04-12) extra corruption checking (mmozeiko) stbi_set_flip_vertically_on_load (nguillemot) diff --git a/stb_vorbis.c b/stb_vorbis.c index 4920eb6..4d0f048 100644 --- a/stb_vorbis.c +++ b/stb_vorbis.c @@ -1,4 +1,4 @@ -// Ogg Vorbis audio decoder - v1.04 - public domain +// Ogg Vorbis audio decoder - v1.05 - public domain // http://nothings.org/stb_vorbis/ // // Written by Sean Barrett in 2007, last updated in 2014 @@ -24,12 +24,13 @@ // Casey Muratori John Bolton Gargaj // Laurent Gomila Marc LeBlanc Ronny Chevalier // Bernhard Wodo Evan Balster "alxprd"@github -// Tom Beaumont Ingo Leitgeb +// Tom Beaumont Ingo Leitgeb Nicolas Guillemot // (If you reported a bug but do not appear in this list, it is because // someone else reported the bug before you. There were too many of you to // list them all because I was lax about updating for a long time, sorry.) // // Partial history: +// 1.05 - 2015/04/19 - don't define __forceinline if it's redundant // 1.04 - 2014/08/27 - fix missing const-correct case in API // 1.03 - 2014/08/07 - warning fixes // 1.02 - 2014/07/09 - declare qsort comparison as explicitly _cdecl in Windows @@ -5397,6 +5398,7 @@ int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, in #endif // STB_VORBIS_NO_PULLDATA_API /* Version history + 1.05 - 2015/04/19 - don't define __forceinline if it's redundant 1.04 - 2014/08/27 - fix missing const-correct case in API 1.03 - 2014/08/07 - Warning fixes 1.02 - 2014/07/09 - Declare qsort compare function _cdecl on windows From aa89970d6be59d6cc0f18f49f392b3f58f145c7d Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Thu, 28 May 2015 22:11:45 -0700 Subject: [PATCH 47/50] stb_image.h: fix *comp value when loading PSDs stb_voxel_render.h: fix STBVOX_CONFIG_OPTIMIZED_VHEIGHT --- README.md | 6 +++--- stb_image.h | 16 ++++++++++------ stb_voxel_render.h | 6 +++--- tests/stb.dsp | 2 +- tests/test_vorbis.c | 3 +-- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 7929edc..3fe7ee5 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,14 @@ single-file public domain libraries for C/C++ library | lastest version | category | LoC | description --------------------- | ---- | -------- | --- | -------------------------------- **stb_vorbis.c** | 1.05 | audio | 5445 | decode ogg vorbis files from file/memory to float/16-bit signed output -**stb_image.h** | 2.05 | graphics | 6433 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC +**stb_image.h** | 2.06 | graphics | 6437 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC **stb_truetype.h** | 1.05 | graphics | 2632 | parse, decode, and rasterize characters from truetype fonts **stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP **stb_image_resize.h** | 0.90 | graphics | 2585 | resize images larger/smaller with good quality **stb_rect_pack.h** | 0.06 | graphics | 560 | simple 2D rectangle packer with decent quality **stretchy_buffer.h** | 1.02 | utility | 210 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++ **stb_textedit.h** | 1.6 | UI | 1290 | guts of a text editor for games etc implementing them from scratch -**stb_voxel_render.h** | 0.80 | 3D graphics | 3644 | Minecraft-esque voxel rendering "engine" with many more features +**stb_voxel_render.h** | 0.81 | 3D graphics | 3644 | Minecraft-esque voxel rendering "engine" with many more features **stb_dxt.h** | 1.04 | 3D graphics | 624 | Fabian "ryg" Giesen's real-time DXT compressor **stb_perlin.h** | 0.2 | 3D graphics | 175 | revised Perlin noise (3D input, 1D output) **stb_easy_font.h** | 0.5 | 3D graphics | 220 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc @@ -27,7 +27,7 @@ library | lastest version | category | LoC | description **stb_leakcheck.h** | 0.2 | misc | 117 | quick-and-dirty malloc/free leak-checking Total libraries: 18 -Total lines of C code: 45270 +Total lines of C code: 45274 FAQ diff --git a/stb_image.h b/stb_image.h index 79f076d..d0fa9c2 100644 --- a/stb_image.h +++ b/stb_image.h @@ -1,4 +1,4 @@ -/* stb_image - v2.05 - public domain image loader - http://nothings.org/stb_image.h +/* stb_image - v2.06 - public domain image loader - http://nothings.org/stb_image.h no warranty implied; use at your own risk Do this: @@ -143,6 +143,7 @@ Latest revision history: + 2.06 (2015-04-19) fix bug where PSD returns wrong '*comp' value 2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit 2.03 (2015-04-12) additional corruption checking @@ -5139,7 +5140,8 @@ static stbi_uc *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int p = out+channel; if (channel >= channelCount) { // Fill this channel with default data. - for (i = 0; i < pixelCount; i++) *p = (channel == 3 ? 255 : 0), p += 4; + for (i = 0; i < pixelCount; i++, p += 4) + *p = (channel == 3 ? 255 : 0); } else { // Read the RLE data. count = 0; @@ -5185,11 +5187,12 @@ static stbi_uc *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int p = out + channel; if (channel > channelCount) { // Fill this channel with default data. - for (i = 0; i < pixelCount; i++) *p = channel == 3 ? 255 : 0, p += 4; + for (i = 0; i < pixelCount; i++, p += 4) + *p = channel == 3 ? 255 : 0; } else { // Read the data. - for (i = 0; i < pixelCount; i++) - *p = stbi__get8(s), p += 4; + for (i = 0; i < pixelCount; i++, p += 4) + *p = stbi__get8(s); } } } @@ -5199,7 +5202,7 @@ static stbi_uc *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int if (out == NULL) return out; // stbi__convert_format frees input on failure } - if (comp) *comp = channelCount; + if (comp) *comp = 4; *y = h; *x = w; @@ -6292,6 +6295,7 @@ STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int /* revision history: + 2.06 (2015-04-19) fix bug where PSD returns wrong '*comp' value 2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning 2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit 2.03 (2015-04-12) extra corruption checking (mmozeiko) diff --git a/stb_voxel_render.h b/stb_voxel_render.h index 576926e..d7dcbc7 100644 --- a/stb_voxel_render.h +++ b/stb_voxel_render.h @@ -1,4 +1,4 @@ -// stb_voxel_render.h - v0.80 - Sean Barrett, 2015 - public domain +// stb_voxel_render.h - v0.81 - Sean Barrett, 2015 - public domain // // This library helps render large-scale "voxel" worlds for games, // in this case, one with blocks that can have textures and that @@ -169,6 +169,7 @@ // // VERSION HISTORY // +// 0.81 (2015-05-28) fix broken STBVOX_CONFIG_OPTIMIZED_VHEIGHT // 0.80 (2015-04-11) fix broken STBVOX_CONFIG_ROTATION_IN_LIGHTING refactoring // change STBVOX_MAKE_LIGHTING to STBVOX_MAKE_LIGHTING_EXT so // that header defs don't need to see config vars @@ -2734,7 +2735,6 @@ void stbvox_make_mesh_for_face(stbvox_mesh_maker *mm, stbvox_rotate rot, int fac } } -#ifndef STBVOX_CONFIG_OPTIMIZED_VHEIGHT // get opposite-facing normal & texgen for opposite face, used to map up-facing vheight data to down-facing data static unsigned char stbvox_reverse_face[STBVF_count] = { @@ -2744,7 +2744,7 @@ static unsigned char stbvox_reverse_face[STBVF_count] = 0, 0, 0, 0, STBVF_ne_d, STBVF_ne_d, STBVF_nd, STBVF_nu }; - +#ifndef STBVOX_CONFIG_OPTIMIZED_VHEIGHT // render non-planar quads by splitting into two triangles, rendering each as a degenerate quad static void stbvox_make_12_split_mesh_for_face(stbvox_mesh_maker *mm, stbvox_rotate rot, int face, int v_off, stbvox_pos pos, stbvox_mesh_vertex vertbase, stbvox_mesh_vertex *face_coord, unsigned char mesh, unsigned char *ht) { diff --git a/tests/stb.dsp b/tests/stb.dsp index c29cb4c..621f5a4 100644 --- a/tests/stb.dsp +++ b/tests/stb.dsp @@ -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 "TT_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/tests/test_vorbis.c b/tests/test_vorbis.c index a9a9f26..5841381 100644 --- a/tests/test_vorbis.c +++ b/tests/test_vorbis.c @@ -8,11 +8,10 @@ extern void stb_vorbis_dumpmem(void); int main(int argc, char **argv) { size_t memlen; - unsigned char *mem = stb_fileu("c:/x/01.ogg", &memlen); + unsigned char *mem = stb_fileu("c:/x/theme_03.ogg", &memlen); int chan, samplerate; short *output; int samples = stb_vorbis_decode_memory(mem, memlen, &chan, &samplerate, &output); - stb_vorbis_dumpmem(); return 0; } #endif From 3787e1c143715ccedd14e552c6ec7c895773f662 Mon Sep 17 00:00:00 2001 From: Michael Sartain Date: Tue, 9 Jun 2015 16:52:39 -0700 Subject: [PATCH 48/50] Fix relative path check for non-Windows platforms in stb_fullpath. --- stb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb.h b/stb.h index d78c465..671ffcd 100644 --- a/stb.h +++ b/stb.h @@ -5255,7 +5255,7 @@ int stb_fullpath(char *abs, int abs_size, char *rel) #ifdef _MSC_VER return _fullpath(abs, rel, abs_size) != NULL; #else - if (abs[0] == '/' || abs[0] == '~') { + if (rel[0] == '/' || rel[0] == '~') { if ((int) strlen(rel) >= abs_size) return 0; strcpy(abs,rel); From 20b04f4aa90836d087396e6e5b1540935df8b47f Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Jul 2015 18:23:12 -0700 Subject: [PATCH 49/50] stb_truetype version 1.06 - switch from qsort() to built-in quicksort (about 2x as fast a sort, ~10% faster overall) - use pool allocator for active-edge allocations (~10% faster overall) - use new rasterizer (about 30% faster, ~10% faster overall) --- stb_truetype.h | 560 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 513 insertions(+), 47 deletions(-) diff --git a/stb_truetype.h b/stb_truetype.h index ae60212..663aef4 100644 --- a/stb_truetype.h +++ b/stb_truetype.h @@ -1,4 +1,4 @@ -// stb_truetype.h - v1.05 - public domain +// stb_truetype.h - v1.06 - public domain // authored from 2009-2014 by Sean Barrett / RAD Game Tools // // This library processes TrueType files: @@ -45,6 +45,9 @@ // // VERSION HISTORY // +// 1.06 (2015-07-14) performance improvements (~35% faster on x86 and x64 on test machine) +// also more precise AA rasterizer, except if shapes overlap +// remove need for STBTT_sort // 1.05 (2015-04-15) fix misplaced definitions for STBTT_STATIC // 1.04 (2015-04-15) typo in example // 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes @@ -120,6 +123,15 @@ // stbtt_GetFontVMetrics() // stbtt_GetCodepointKernAdvance() // +// Starting with version 1.06, the rasterizer was replaced with a new, +// faster and generally-more-precise rasterizer. The new rasterizer more +// accurately measures pixel coverage for anti-aliasing, except in the case +// where multiple shapes overlap, in which case it overestimates the AA pixel +// coverage. Thus, anti-aliasing of intersecting shapes may look wrong. If +// this turns out to be a problem, you can re-enable the old rasterizer with +// #define STBTT_RASTERIZER_VERSION 1 +// which will incur about a 15% speed hit. +// // ADDITIONAL DOCUMENTATION // // Immediately after this block comment are a series of sample programs. @@ -219,7 +231,15 @@ // Baked bitmap interface 70 LOC / // Font name matching & access 150 LOC ---- 150 // C runtime library abstraction 60 LOC ---- 60 - +// +// +// PERFORMANCE MEASUREMENTS FOR 1.06: +// +// 32-bit 64-bit +// Previous release: 8.83 s 7.68 s +// Pool allocations: 7.72 s 6.34 s +// Inline sort : 6.54 s 5.65 s +// New rasterizer : 5.63 s 5.00 s ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// @@ -330,7 +350,7 @@ int main(int arg, char **argv) stbtt_fontinfo font; int i,j,ascent,baseline,ch=0; float scale, xpos=2; // leave a little padding in case the character extends left - char *text = "Heljo World!"; + char *text = "Heljo World!"; // intentionally misspelled to show 'lj' brokenness fread(buffer, 1, 1000000, fopen("c:/windows/fonts/arialbd.ttf", "rb")); stbtt_InitFont(&font, buffer, 0); @@ -388,12 +408,6 @@ int main(int arg, char **argv) typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1]; typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1]; - // #define your own STBTT_sort() to override this to avoid qsort - #ifndef STBTT_sort - #include - #define STBTT_sort(data,num_items,item_size,compare_func) qsort(data,num_items,item_size,compare_func) - #endif - // #define your own STBTT_ifloor/STBTT_iceil() to avoid math.h #ifndef STBTT_ifloor #include @@ -902,6 +916,10 @@ enum { // languageID for STBTT_PLATFORM_ID_MAC typedef int stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERSAMPLE-1)) == 0 ? 1 : -1]; +#ifndef STBTT_RASTERIZER_VERSION +#define STBTT_RASTERIZER_VERSION 2 +#endif + ////////////////////////////////////////////////////////////////////////// // // accessors to parse data from file @@ -1550,42 +1568,129 @@ STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codep stbtt_GetCodepointBitmapBoxSubpixel(font, codepoint, scale_x, scale_y,0.0f,0.0f, ix0,iy0,ix1,iy1); } +////////////////////////////////////////////////////////////////////////////// +// +// Rasterizer + +typedef struct stbtt__hheap_chunk +{ + struct stbtt__hheap_chunk *next; +} stbtt__hheap_chunk; + +typedef struct stbtt__hheap +{ + struct stbtt__hheap_chunk *head; + void *first_free; + int num_remaining_in_head_chunk; +} stbtt__hheap; + +static void *stbtt__hheap_alloc(stbtt__hheap *hh, size_t size, void *userdata) +{ + if (hh->first_free) { + void *p = hh->first_free; + hh->first_free = * (void **) p; + return p; + } else { + if (hh->num_remaining_in_head_chunk == 0) { + int count = (size < 32 ? 2000 : size < 128 ? 800 : 100); + stbtt__hheap_chunk *c = (stbtt__hheap_chunk *) STBTT_malloc(sizeof(stbtt__hheap_chunk) + size * count, userdata); + if (c == NULL) + return NULL; + c->next = hh->head; + hh->head = c; + hh->num_remaining_in_head_chunk = count; + } + --hh->num_remaining_in_head_chunk; + return (char *) (hh->head) + size * hh->num_remaining_in_head_chunk; + } +} + +static void stbtt__hheap_free(stbtt__hheap *hh, void *p) +{ + *(void **) p = hh->first_free; + hh->first_free = p; +} + +static void stbtt__hheap_cleanup(stbtt__hheap *hh, void *userdata) +{ + stbtt__hheap_chunk *c = hh->head; + while (c) { + stbtt__hheap_chunk *n = c->next; + STBTT_free(c, userdata); + c = n; + } +} + typedef struct stbtt__edge { float x0,y0, x1,y1; int invert; } stbtt__edge; + typedef struct stbtt__active_edge { + struct stbtt__active_edge *next; + #if STBTT_RASTERIZER_VERSION==1 int x,dx; float ey; - struct stbtt__active_edge *next; - int valid; + int direction; + #elif STBTT_RASTERIZER_VERSION==2 + float fx,fdx,fdy; + float direction; + float sy; + float ey; + #else + #error "Unrecognized value of STBTT_RASTERIZER_VERSION" + #endif } stbtt__active_edge; -#define FIXSHIFT 10 -#define FIX (1 << FIXSHIFT) -#define FIXMASK (FIX-1) +#if STBTT_RASTERIZER_VERSION == 1 +#define STBTT_FIXSHIFT 10 +#define STBTT_FIX (1 << STBTT_FIXSHIFT) +#define STBTT_FIXMASK (STBTT_FIX-1) -static stbtt__active_edge *new_active(stbtt__edge *e, int off_x, float start_point, void *userdata) +static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata) { - stbtt__active_edge *z = (stbtt__active_edge *) STBTT_malloc(sizeof(*z), userdata); // @TODO: make a pool of these!!! + stbtt__active_edge *z = (stbtt__active_edge *) stbtt__hheap_alloc(hh, sizeof(*z), userdata); float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0); - STBTT_assert(e->y0 <= start_point); if (!z) return z; - // round dx down to avoid going too far + + // round dx down to avoid overshooting if (dxdy < 0) - z->dx = -STBTT_ifloor(FIX * -dxdy); + z->dx = -STBTT_ifloor(STBTT_FIX * -dxdy); else - z->dx = STBTT_ifloor(FIX * dxdy); - z->x = STBTT_ifloor(FIX * (e->x0 + dxdy * (start_point - e->y0))); - z->x -= off_x * FIX; + z->dx = STBTT_ifloor(STBTT_FIX * dxdy); + + z->x = STBTT_ifloor(STBTT_FIX * e->x0 + z->dx * (start_point - e->y0)); // use z->dx so when we offset later it's by the same amount + z->x -= off_x * STBTT_FIX; + z->ey = e->y1; z->next = 0; - z->valid = e->invert ? 1 : -1; + z->direction = e->invert ? 1 : -1; return z; } +#elif STBTT_RASTERIZER_VERSION == 2 +static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata) +{ + stbtt__active_edge *z = (stbtt__active_edge *) stbtt__hheap_alloc(hh, sizeof(*z), userdata); + float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0); + //STBTT_assert(e->y0 <= start_point); + if (!z) return z; + z->fdx = dxdy; + z->fdy = (1/dxdy); + z->fx = e->x0 + dxdy * (start_point - e->y0); + z->fx -= off_x; + z->direction = e->invert ? 1.0f : -1.0f; + z->sy = e->y0; + z->ey = e->y1; + z->next = 0; + return z; +} +#else +#error "Unrecognized value of STBTT_RASTERIZER_VERSION" +#endif +#if STBTT_RASTERIZER_VERSION == 1 // note: this routine clips fills that extend off the edges... ideally this // wouldn't happen, but it could happen if the truetype glyph bounding boxes // are wrong, or if the user supplies a too-small bitmap @@ -1597,26 +1702,26 @@ static void stbtt__fill_active_edges(unsigned char *scanline, int len, stbtt__ac while (e) { if (w == 0) { // if we're currently at zero, we need to record the edge start point - x0 = e->x; w += e->valid; + x0 = e->x; w += e->direction; } else { - int x1 = e->x; w += e->valid; + int x1 = e->x; w += e->direction; // if we went to zero, we need to draw if (w == 0) { - int i = x0 >> FIXSHIFT; - int j = x1 >> FIXSHIFT; + int i = x0 >> STBTT_FIXSHIFT; + int j = x1 >> STBTT_FIXSHIFT; if (i < len && j >= 0) { if (i == j) { // x0,x1 are the same pixel, so compute combined coverage - scanline[i] = scanline[i] + (stbtt_uint8) ((x1 - x0) * max_weight >> FIXSHIFT); + scanline[i] = scanline[i] + (stbtt_uint8) ((x1 - x0) * max_weight >> STBTT_FIXSHIFT); } else { if (i >= 0) // add antialiasing for x0 - scanline[i] = scanline[i] + (stbtt_uint8) (((FIX - (x0 & FIXMASK)) * max_weight) >> FIXSHIFT); + scanline[i] = scanline[i] + (stbtt_uint8) (((STBTT_FIX - (x0 & STBTT_FIXMASK)) * max_weight) >> STBTT_FIXSHIFT); else i = -1; // clip if (j < len) // add antialiasing for x1 - scanline[j] = scanline[j] + (stbtt_uint8) (((x1 & FIXMASK) * max_weight) >> FIXSHIFT); + scanline[j] = scanline[j] + (stbtt_uint8) (((x1 & STBTT_FIXMASK) * max_weight) >> STBTT_FIXSHIFT); else j = len; // clip @@ -1633,6 +1738,7 @@ static void stbtt__fill_active_edges(unsigned char *scanline, int len, stbtt__ac static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata) { + stbtt__hheap hh = { 0 }; stbtt__active_edge *active = NULL; int y,j=0; int max_weight = (255 / vsubsample); // weight per vertical scanline @@ -1660,9 +1766,9 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, stbtt__active_edge * z = *step; if (z->ey <= scan_y) { *step = z->next; // delete from list - STBTT_assert(z->valid); - z->valid = 0; - STBTT_free(z, userdata); + STBTT_assert(z->direction); + z->direction = 0; + stbtt__hheap_free(&hh, z); } else { z->x += z->dx; // advance to position for current scanline step = &((*step)->next); // advance through list @@ -1691,7 +1797,7 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, // insert all edges that start before the center of this scanline -- omit ones that also end on this scanline while (e->y0 <= scan_y) { if (e->y1 > scan_y) { - stbtt__active_edge *z = new_active(e, off_x, scan_y, userdata); + stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y, userdata); // find insertion point if (active == NULL) active = z; @@ -1722,24 +1828,377 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, ++j; } - while (active) { - stbtt__active_edge *z = active; - active = active->next; - STBTT_free(z, userdata); - } + stbtt__hheap_cleanup(&hh, userdata); if (scanline != scanline_data) STBTT_free(scanline, userdata); } -static int stbtt__edge_compare(const void *p, const void *q) -{ - stbtt__edge *a = (stbtt__edge *) p; - stbtt__edge *b = (stbtt__edge *) q; +#elif STBTT_RASTERIZER_VERSION == 2 - if (a->y0 < b->y0) return -1; - if (a->y0 > b->y0) return 1; - return 0; +// the edge passed in here does not cross the vertical line at x or the vertical line at x+1 +// (i.e. it has already been clipped to those) +static void stbtt__handle_clipped_edge(float *scanline, int x, stbtt__active_edge *e, float x0, float y0, float x1, float y1) +{ + if (y0 == y1) return; + assert(y0 < y1); + assert(e->sy <= e->ey); + if (y0 > e->ey) return; + if (y1 < e->sy) return; + if (y0 < e->sy) { + x0 += (x1-x0) * (e->sy - y0) / (y1-y0); + y0 = e->sy; + } + if (y1 > e->ey) { + x1 += (x1-x0) * (e->ey - y1) / (y1-y0); + y1 = e->ey; + } + + if (x0 == x) + assert(x1 <= x+1); + else if (x0 == x+1) + assert(x1 >= x); + else if (x0 <= x) + assert(x1 <= x); + else if (x0 >= x+1) + assert(x1 >= x+1); + else + assert(x1 >= x && x1 <= x+1); + + if (x0 <= x && x1 <= x) + scanline[x] += e->direction * (y1-y0); + else if (x0 >= x+1 && x1 >= x+1) + ; + else { + assert(x0 >= x && x0 <= x+1 && x1 >= x && x1 <= x+1); + scanline[x] += e->direction * (y1-y0) * (1-((x0-x)+(x1-x))/2); // coverage = 1 - average x position + } +} + +static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill, int len, stbtt__active_edge *e, float y_top) +{ + float y_bottom = y_top+1; + + while (e) { + // brute force every pixel + + // compute intersection points with top & bottom + assert(e->ey >= y_top); + + if (e->fdx == 0) { + float x0 = e->fx; + if (x0 < len) { + if (x0 >= 0) { + stbtt__handle_clipped_edge(scanline,(int) x0,e, x0,y_top, x0,y_bottom); + stbtt__handle_clipped_edge(scanline_fill-1,(int) x0+1,e, x0,y_top, x0,y_bottom); + } else { + stbtt__handle_clipped_edge(scanline_fill-1,0,e, x0,y_top, x0,y_bottom); + } + } + } else { + float x0 = e->fx; + float dx = e->fdx; + float xb = x0 + dx; + float x_top, x_bottom; + float y0,y1; + float dy = e->fdy; + assert(e->sy <= y_bottom && e->ey >= y_top); + + // compute endpoints of line segment clipped to this scanline (if the + // line segment starts on this scanline. x0 is the intersection of the + // line with y_top, but that may be off the line segment. + if (e->sy > y_top) { + x_top = x0 + dx * (e->sy - y_top); + y0 = e->sy; + } else { + x_top = x0; + y0 = y_top; + } + if (e->ey < y_bottom) { + x_bottom = x0 + dx * (e->ey - y_top); + y1 = e->ey; + } else { + x_bottom = xb; + y1 = y_bottom; + } + + if (x_top >= 0 && x_bottom >= 0 && x_top < len && x_bottom < len) { + // from here on, we don't have to range check x values + + if ((int) x_top == (int) x_bottom) { + float height; + // simple case, only spans one pixel + int x = (int) x_top; + height = y1 - y0; + assert(x >= 0 && x < len); + scanline[x] += e->direction * (1-((x_top - x) + (x_bottom-x))/2) * height; + scanline_fill[x] += e->direction * height; // everything right of this pixel is filled + } else { + int x,x1,x2; + float y_crossing, step, sign, area; + // covers 2+ pixels + if (x_top > x_bottom) { + // flip scanline vertically; signed area is the same + float t; + y0 = y_bottom - (y0 - y_top); + y1 = y_bottom - (y1 - y_top); + t = y0, y0 = y1, y1 = t; + t = x_bottom, x_bottom = x_top, x_top = t; + dx = -dx; + dy = -dy; + t = x0, x0 = xb, xb = t; + } + + x1 = (int) x_top; + x2 = (int) x_bottom; + // compute intersection with y axis at x1+1 + y_crossing = (x1+1 - x0) * dy + y_top; + + sign = e->direction; + // area of the rectangle covered from y0..y_crossing + area = sign * (y_crossing-y0); + // area of the triangle (x_top,y0), (x+1,y0), (x+1,y_crossing) + scanline[x1] += area * (1-((x_top - x1)+(x1+1-x1))/2); + + step = sign * dy; + for (x = x1+1; x < x2; ++x) { + scanline[x] += area + step/2; + area += step; + } + y_crossing += dy * (x2 - (x1+1)); + + assert(fabs(area) <= 1.01f); + + scanline[x2] += area + sign * (1-((x2-x2)+(x_bottom-x2))/2) * (y1-y_crossing); + + scanline_fill[x2] += sign * (y1-y0); + } + } else { + // if edge goes outside of box we're drawing, we require + // clipping logic. since this does not match the intended use + // of this library, we use a different, very slow brute + // force implementation + int x; + for (x=0; x < len; ++x) { + // cases: + // + // there can be up to two intersections with the pixel. any intersection + // with left or right edges can be handled by splitting into two (or three) + // regions. intersections with top & bottom do not necessitate case-wise logic. + float y0,y1; + float y_cur = y_top, x_cur = x0; + // x = e->x + e->dx * (y-y_top) + // (y-y_top) = (x - e->x) / e->dx + // y = (x - e->x) / e->dx + y_top + y0 = (x - x0) / dx + y_top; + y1 = (x+1 - x0) / dx + y_top; + + if (y0 < y1) { + if (y0 > y_top && y0 < y_bottom) { + stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, (float) x,y0); + y_cur = y0; + x_cur = (float) x; + } + if (y1 >= y_cur && y1 < y_bottom) { + stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, (float) x+1,y1); + y_cur = y1; + x_cur = (float) x+1; + } + } else { + if (y1 >= y_cur && y1 < y_bottom) { + stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, (float) x+1,y1); + y_cur = y1; + x_cur = (float) x+1; + } + if (y0 > y_top && y0 < y_bottom) { + stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, (float) x,y0); + y_cur = y0; + x_cur = (float) x; + } + } + stbtt__handle_clipped_edge(scanline,x,e, x_cur,y_cur, xb,y_bottom); + } + } + } + e = e->next; + } +} + +// directly AA rasterize edges w/o supersampling +static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata) +{ + stbtt__hheap hh = { 0 }; + stbtt__active_edge *active = NULL; + int y,j=0, i; + float scanline_data[129], *scanline, *scanline2; + + if (result->w > 64) + scanline = (float *) STBTT_malloc((result->w*2+1) * sizeof(float), userdata); + else + scanline = scanline_data; + + scanline2 = scanline + result->w; + + y = off_y; + e[n].y0 = (float) (off_y + result->h) + 1; + + while (j < result->h) { + // find center of pixel for this scanline + float scan_y_top = y + 0.0f; + float scan_y_bottom = y + 1.0f; + stbtt__active_edge **step = &active; + + STBTT_memset(scanline , 0, result->w*sizeof(scanline[0])); + STBTT_memset(scanline2, 0, (result->w+1)*sizeof(scanline[0])); + + // update all active edges; + // remove all active edges that terminate before the top of this scanline + while (*step) { + stbtt__active_edge * z = *step; + if (z->ey <= scan_y_top) { + *step = z->next; // delete from list + STBTT_assert(z->direction); + z->direction = 0; + stbtt__hheap_free(&hh, z); + } else { + step = &((*step)->next); // advance through list + } + } + + // insert all edges that start before the bottom of this scanline + while (e->y0 <= scan_y_bottom) { + stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata); + assert(z->ey >= scan_y_top); + // insert at front + z->next = active; + active = z; + ++e; + } + + // now process all active edges + if (active) + stbtt__fill_active_edges_new(scanline, scanline2+1, result->w, active, scan_y_top); + + { + float sum = 0; + for (i=0; i < result->w; ++i) { + float k; + int m; + sum += scanline2[i]; + k = scanline[i] + sum; + k = (float) fabs(k)*255 + 0.5f; + m = (int) k; + if (m > 255) m = 255; + result->pixels[j*result->stride + i] = (unsigned char) m; + } + } + // advance all the edges + step = &active; + while (*step) { + stbtt__active_edge *z = *step; + z->fx += z->fdx; // advance to position for current scanline + step = &((*step)->next); // advance through list + } + + ++y; + ++j; + } + + stbtt__hheap_cleanup(&hh, userdata); + + if (scanline != scanline_data) + STBTT_free(scanline, userdata); +} +#else +#error "Unrecognized value of STBTT_RASTERIZER_VERSION" +#endif + +#define STBTT__COMPARE(a,b) ((a)->y0 < (b)->y0) + +static void stbtt__sort_edges_ins_sort(stbtt__edge *p, int n) +{ + int i,j; + for (i=1; i < n; ++i) { + stbtt__edge t = p[i], *a = &t; + j = i; + while (j > 0) { + stbtt__edge *b = &p[j-1]; + int c = STBTT__COMPARE(a,b); + if (!c) break; + p[j] = p[j-1]; + --j; + } + if (i != j) + p[j] = t; + } +} + +static void stbtt__sort_edges_quicksort(stbtt__edge *p, int n) +{ + /* threshhold for transitioning to insertion sort */ + while (n > 12) { + stbtt__edge t; + int c01,c12,c,m,i,j; + + /* compute median of three */ + m = n >> 1; + c01 = STBTT__COMPARE(&p[0],&p[m]); + c12 = STBTT__COMPARE(&p[m],&p[n-1]); + /* if 0 >= mid >= end, or 0 < mid < end, then use mid */ + if (c01 != c12) { + /* otherwise, we'll need to swap something else to middle */ + int z; + c = STBTT__COMPARE(&p[0],&p[n-1]); + /* 0>mid && midn => n; 0 0 */ + /* 0n: 0>n => 0; 0 n */ + z = (c == c12) ? 0 : n-1; + t = p[z]; + p[z] = p[m]; + p[m] = t; + } + /* now p[m] is the median-of-three */ + /* swap it to the beginning so it won't move around */ + t = p[0]; + p[0] = p[m]; + p[m] = t; + + /* partition loop */ + i=1; + j=n-1; + for(;;) { + /* handling of equality is crucial here */ + /* for sentinels & efficiency with duplicates */ + for (;;++i) { + if (!STBTT__COMPARE(&p[i], &p[0])) break; + } + for (;;--j) { + if (!STBTT__COMPARE(&p[0], &p[j])) break; + } + /* make sure we haven't crossed */ + if (i >= j) break; + t = p[i]; + p[i] = p[j]; + p[j] = t; + + ++i; + --j; + } + /* recurse on smaller side, iterate on larger */ + if (j < (n-i)) { + stbtt__sort_edges_quicksort(p,j); + p = p+i; + n = n-i; + } else { + stbtt__sort_edges_quicksort(p+i, n-i); + n = j; + } + } +} + +static void stbtt__sort_edges(stbtt__edge *p, int n) +{ + stbtt__sort_edges_quicksort(p, n); + stbtt__sort_edges_ins_sort(p, n); } typedef struct @@ -1752,7 +2211,13 @@ static void stbtt__rasterize(stbtt__bitmap *result, stbtt__point *pts, int *wcou float y_scale_inv = invert ? -scale_y : scale_y; stbtt__edge *e; int n,i,j,k,m; +#if STBTT_RASTERIZER_VERSION == 1 int vsubsample = result->h < 8 ? 15 : 5; +#elif STBTT_RASTERIZER_VERSION == 2 + int vsubsample = 1; +#else + #error "Unrecognized value of STBTT_RASTERIZER_VERSION" +#endif // vsubsample should divide 255 evenly; otherwise we won't reach full opacity // now we have to blow out the windings into explicit edge lists @@ -1789,7 +2254,8 @@ static void stbtt__rasterize(stbtt__bitmap *result, stbtt__point *pts, int *wcou } // now sort the edges by their highest point (should snap to integer, and then by x) - STBTT_sort(e, n, sizeof(e[0]), stbtt__edge_compare); + //STBTT_sort(e, n, sizeof(e[0]), stbtt__edge_compare); + stbtt__sort_edges(e, n); // now, traverse the scanlines and find the intersections on each scanline, use xor winding rule stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y, userdata); From 93fb3720284ad368bb3ee97faed093b507cc2450 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Tue, 14 Jul 2015 18:23:46 -0700 Subject: [PATCH 50/50] update stb_truetype version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3fe7ee5..6694d03 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ library | lastest version | category | LoC | description --------------------- | ---- | -------- | --- | -------------------------------- **stb_vorbis.c** | 1.05 | audio | 5445 | decode ogg vorbis files from file/memory to float/16-bit signed output **stb_image.h** | 2.06 | graphics | 6437 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC -**stb_truetype.h** | 1.05 | graphics | 2632 | parse, decode, and rasterize characters from truetype fonts +**stb_truetype.h** | 1.06 | graphics | 2632 | parse, decode, and rasterize characters from truetype fonts **stb_image_write.h** | 0.98 | graphics | 730 | image writing to disk: PNG, TGA, BMP **stb_image_resize.h** | 0.90 | graphics | 2585 | resize images larger/smaller with good quality **stb_rect_pack.h** | 0.06 | graphics | 560 | simple 2D rectangle packer with decent quality