Skip to content
Myr

Merge branch 'rgb-detect' of https://github.com/jeremysawicki/stb into working

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parents 8fe4809, 9e76bb5 · Browse files · 4 files+81 added−26 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+81 added−26 removed

  • other:+81 added−26 removed

4 files+81 added−26 removed

modified:tools/README.footer.md+10 added-5 removed
modified:tools/README.header.md+1 added-1 removed
modified:README.md+20 added-15 removed
1 unmodified line
23stb4===56single-file public domain libraries for C/C++ <a name="stb_libs"></a>6single-file public domain (or MIT licensed) libraries for C/C++ <a name="stb_libs"></a>78Most libraries by stb, except: stb_dxt by Fabian "ryg" Giesen, stb_image_resize9by Jorge L. "VinoBS" Rodriguez, and stb_sprintf by Jeff Roberts.10
3 unmodified lines
14**[stb_vorbis.c](stb_vorbis.c)** | 1.10 | audio | 5447 | decode ogg vorbis files from file/memory to float/16-bit signed output15**[stb_image.h](stb_image.h)** | 2.14 | graphics | 7049 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC16**[stb_truetype.h](stb_truetype.h)** | 1.15 | graphics | 4061 | parse, decode, and rasterize characters from truetype fonts17**[stb_image_write.h](stb_image_write.h)** | 1.05 | graphics | 1092 | image writing to disk: PNG, TGA, BMP18**[stb_image_resize.h](stb_image_resize.h)** | 0.92 | graphics | 2620 | resize images larger/smaller with good quality19**[stb_rect_pack.h](stb_rect_pack.h)** | 0.10 | graphics | 623 | simple 2D rectangle packer with decent quality20**[stb_sprintf.h](stb_sprintf.h)** | 1.02 | utility | 1134 | fast sprintf, snprintf for C/C++18**[stb_image_resize.h](stb_image_resize.h)** | 0.93 | graphics | 2625 | resize images larger/smaller with good quality19**[stb_rect_pack.h](stb_rect_pack.h)** | 0.11 | graphics | 635 | simple 2D rectangle packer with decent quality20**[stb_sprintf.h](stb_sprintf.h)** | 1.02 | utility | 1202 | fast sprintf, snprintf for C/C++21**[stretchy_buffer.h](stretchy_buffer.h)** | 1.02 | utility | 257 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++22**[stb_textedit.h](stb_textedit.h)** | 1.10 | user&nbsp;interface | 1370 | guts of a text editor for games etc implementing them from scratch23**[stb_voxel_render.h](stb_voxel_render.h)** | 0.84 | 3D&nbsp;graphics | 3792 | Minecraft-esque voxel rendering "engine" with many more features24**[stb_dxt.h](stb_dxt.h)** | 1.05 | 3D&nbsp;graphics | 686 | Fabian "ryg" Giesen's real-time DXT compressor25**[stb_perlin.h](stb_perlin.h)** | 0.2 | 3D&nbsp;graphics | 222 | revised Perlin noise (3D input, 1D output)22**[stb_textedit.h](stb_textedit.h)** | 1.11 | user&nbsp;interface | 1393 | guts of a text editor for games etc implementing them from scratch23**[stb_voxel_render.h](stb_voxel_render.h)** | 0.85 | 3D&nbsp;graphics | 3803 | Minecraft-esque voxel rendering "engine" with many more features24**[stb_dxt.h](stb_dxt.h)** | 1.06 | 3D&nbsp;graphics | 687 | Fabian "ryg" Giesen's real-time DXT compressor25**[stb_perlin.h](stb_perlin.h)** | 0.3 | 3D&nbsp;graphics | 316 | revised Perlin noise (3D input, 1D output)26**[stb_easy_font.h](stb_easy_font.h)** | 1.0 | 3D&nbsp;graphics | 303 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc27**[stb_tilemap_editor.h](stb_tilemap_editor.h)** | 0.38 | game&nbsp;dev | 4172 | embeddable tilemap editor28**[stb_herringbone_wa...](stb_herringbone_wang_tile.h)** | 0.6 | game&nbsp;dev | 1220 | herringbone Wang tile map generator29**[stb_c_lexer.h](stb_c_lexer.h)** | 0.09 | parsing | 962 | simplify writing parsers for C-like languages30**[stb_divide.h](stb_divide.h)** | 0.91 | math | 419 | more useful 32-bit modulus e.g. "euclidean divide"31**[stb_connected_comp...](stb_connected_components.h)** | 0.95 | misc | 1045 | incrementally compute reachability on grids32**[stb.h](stb.h)** | 2.28 | misc | 14277 | helper functions for C, mostly redundant in C++; basically author's personal stuff32**[stb.h](stb.h)** | 2.29 | misc | 14324 | helper functions for C, mostly redundant in C++; basically author's personal stuff33**[stb_leakcheck.h](stb_leakcheck.h)** | 0.3 | misc | 165 | quick-and-dirty malloc/free leak-checking3435Total libraries: 20 36Total lines of C code: 5091636Total lines of C code: 51177373839FAQ40---4142#### What's the license?4344These libraries are in the public domain (or the equivalent where that is not45possible). You can do anything you want with them. You have no legal obligation44These libraries are in the public domain. You can do anything you45want with them. You have no legal obligation46to do anything else, although I appreciate attribution.4748They are also licensed under the MIT open source license, if you have lawyers49who are unhappy with public domain. Every source file includes an explicit50dual-license for you to choose from.5152#### <a name="other_libs"></a> Are there other single-file public-domain/open source libraries with minimal dependencies out there?5354[Yes.](https://github.com/nothings/single_file_libs)5552#### If I wrap an stb library in a new library, does the new library have to be public domain?56#### If I wrap an stb library in a new library, does the new library have to be public domain/MIT?5754No.58No, because it's public domain you can freely relicense it to whatever license your new59library wants to be.6061#### Some of these libraries seem redundant to existing open source libraries. Are they better somehow?6263Generally they're only better in that they're easier to integrate,
1 unmodified line
65attribution requirement). They may be less featureful, slower,66and/or use more memory. If you're already using an equivalent67library, there's probably no good reason to switch.6864###### Can I link directly to the table of stb libraries?69#### Can I link directly to the table of stb libraries?7071You can use [this URL](https://github.com/nothings/stb#stb_libs) to link directly to that list.7273#### Why do you list "lines of code"? It's a terrible metric.
69 unmodified lines
modified:stb_image.h+50 added-5 removed
1690 unmodified lines
1691 int spec_end;1692 int succ_high;1693 int succ_low;1694 int eob_run;1695 int jfif;1696 int app14;1697 int rgb;16981699 int scan_n, order[4];1700 int restart_interval, todo;
1140 unmodified lines
2841 L -= n;2842 }2843 return L==0;2844 }28452846 // check for comment block or APP blocks2847 if ((m >= 0xE0 && m <= 0xEF) || m == 0xFE) {2845 stbi__skip(z->s, stbi__get16be(z->s)-2);2848 L = stbi__get16be(z->s);2849 if (L < 2) {2850 if (m == 0xFE)2851 return stbi__err("bad COM len","Corrupt JPEG");2852 else2853 return stbi__err("bad APP len","Corrupt JPEG");2854 }2855 L -= 2;28562857 if (m == 0xE0 && L >= 5) { // JFIF APP0 segment2858 static const unsigned char tag[5] = {'J','F','I','F','\0'};2859 int ok = 1;2860 int i;2861 for (i=0; i < 5; ++i)2862 if (stbi__get8(z->s) != tag[i])2863 ok = 0;2864 L -= 5;2865 if (ok) {2866 z->jfif = 1;2867 }2868 } else if (m == 0xEE && L >= 12) { // Adobe APP14 segment2869 static const unsigned char tag[6] = {'A','d','o','b','e','\0'};2870 int ok = 1;2871 int i;2872 for (i=0; i < 6; ++i)2873 if (stbi__get8(z->s) != tag[i])2874 ok = 0;2875 L -= 6;2876 if (ok) {2877 stbi__get8(z->s); // version2878 stbi__get16be(z->s); // flags02879 stbi__get16be(z->s); // flags12880 z->app14 = stbi__get8(z->s); // color transform2881 L -= 6;2882 }2883 }28842885 stbi__skip(z->s, L);2886 return 1;2887 }28882889 return stbi__err("unknown marker","Corrupt JPEG");2890}28912892// after we see SOS
152 unmodified lines
30453046static int stbi__decode_jpeg_header(stbi__jpeg *z, int scan)3047{3048 int m;3049 z->jfif = 0;3050 z->app14 = -1;3051 z->marker = STBI__MARKER_none; // initialize cached marker to empty3052 m = stbi__get_marker(z);3053 if (!stbi__SOI(m)) return stbi__err("no SOI","Corrupt JPEG");3054 if (scan == STBI__SCAN_type) return 1;
463 unmodified lines
3518} stbi__resample;35193520static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp)3521{3479 int n, decode_n;3522 int n, decode_n, is_rgb;3523 z->s->img_n = 0; // make stbi__cleanup_jpeg safe35243525 // validate req_comp3526 if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error");
3 unmodified lines
35303531 // determine actual number of components to generate3532 n = req_comp ? req_comp : z->s->img_n;35333534 is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14 == 0 && !z->jfif));35353491 if (z->s->img_n == 3 && n < 3 && z->rgb != 3)3536 if (z->s->img_n == 3 && n < 3 && !is_rgb)3537 decode_n = 1;3538 else3539 decode_n = z->s->img_n;3540
51 unmodified lines
3592 }3593 if (n >= 3) {3594 stbi_uc *y = coutput[0];3595 if (z->s->img_n == 3) {3551 if (z->rgb == 3) {3596 if (is_rgb) {3597 for (i=0; i < z->s->img_x; ++i) {3598 out[0] = y[i];3599 out[1] = coutput[1][i];3600 out[2] = coutput[2][i];
9 unmodified lines
3610 out[3] = 255; // not used if n==33611 out += n;3612 }3613 } else {3569 if (z->rgb == 3) {3614 if (is_rgb) {3615 if (n == 1)3616 for (i=0; i < z->s->img_x; ++i)3617 *out++ = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]);3618 else {
3479 unmodified lines