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
Provenance
- Commit
00c2545- Tree
8895536- Author
Sean Barrett <sean@nothings.org>- Committer
Sean Barrett <sean@nothings.org>- Parent 1
8fe4809- Parent 2
9e76bb5
4 files changed+81 added−26 removed
modified:tools/README.footer.md+10 added-5 removed
2 unmodified lines34567878910111213141516171815192017212223242526272829303127323334353669 unmodified lines2 unmodified lines---
#### What's the license?
These libraries are in the public domain (or the equivalent where that is notpossible). You can do anything you want with them. You have no legal obligationThese libraries are in the public domain. You can do anything youwant with them. You have no legal obligationto do anything else, although I appreciate attribution.
They are also licensed under the MIT open source license, if you have lawyerswho are unhappy with public domain. Every source file includes an explicitdual-license for you to choose from.
#### <a name="other_libs"></a> Are there other single-file public-domain/open source libraries with minimal dependencies out there?
[Yes.](https://github.com/nothings/single_file_libs)
#### If I wrap an stb library in a new library, does the new library have to be public domain?#### If I wrap an stb library in a new library, does the new library have to be public domain/MIT?
No.No, because it's public domain you can freely relicense it to whatever license your newlibrary wants to be.
#### Some of these libraries seem redundant to existing open source libraries. Are they better somehow?
Generally they're only better in that they're easier to integrate,easier to use, and easier to release (single file; good API; noattribution requirement). They may be less featureful, slower,and/or use more memory. If you're already using an equivalentlibrary, there's probably no good reason to switch.
###### Can I link directly to the table of stb libraries?#### Can I link directly to the table of stb libraries?
You can use [this URL](https://github.com/nothings/stb#stb_libs) to link directly to that list.
#### Why do you list "lines of code"? It's a terrible metric.69 unmodified linesmodified:tools/README.header.md+1 added-1 removed
1234456783 unmodified linesstb===
single-file public domain libraries for C/C++ <a name="stb_libs"></a>single-file public domain (or MIT licensed) libraries for C/C++ <a name="stb_libs"></a>
Most libraries by stb, except: stb_dxt by Fabian "ryg" Giesen, stb_image_resizeby Jorge L. "VinoBS" Rodriguez, and stb_sprintf by Jeff Roberts.
3 unmodified linesmodified:README.md+20 added-15 removed
1 unmodified line2 3 stb4 ===5 6-single-file public domain libraries for C/C++ <a name="stb_libs"></a>6+single-file public domain (or MIT licensed) libraries for C/C++ <a name="stb_libs"></a>7 8 Most libraries by stb, except: stb_dxt by Fabian "ryg" Giesen, stb_image_resize9 by Jorge L. "VinoBS" Rodriguez, and stb_sprintf by Jeff Roberts.10 3 unmodified lines14 **[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 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 graphics | 3792 | Minecraft-esque voxel rendering "engine" with many more features24-**[stb_dxt.h](stb_dxt.h)** | 1.05 | 3D graphics | 686 | Fabian "ryg" Giesen's real-time DXT compressor25-**[stb_perlin.h](stb_perlin.h)** | 0.2 | 3D graphics | 222 | revised Perlin noise (3D input, 1D output)22+**[stb_textedit.h](stb_textedit.h)** | 1.11 | user 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 graphics | 3803 | Minecraft-esque voxel rendering "engine" with many more features24+**[stb_dxt.h](stb_dxt.h)** | 1.06 | 3D graphics | 687 | Fabian "ryg" Giesen's real-time DXT compressor25+**[stb_perlin.h](stb_perlin.h)** | 0.3 | 3D graphics | 316 | revised Perlin noise (3D input, 1D output)26 **[stb_easy_font.h](stb_easy_font.h)** | 1.0 | 3D graphics | 303 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc27 **[stb_tilemap_editor.h](stb_tilemap_editor.h)** | 0.38 | game dev | 4172 | embeddable tilemap editor28 **[stb_herringbone_wa...](stb_herringbone_wang_tile.h)** | 0.6 | game 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-checking34 35 Total libraries: 20 36-Total lines of C code: 5091636+Total lines of C code: 5117737 38 39 FAQ40 ---41 42 #### What's the license?43 44-These libraries are in the public domain (or the equivalent where that is not45-possible). You can do anything you want with them. You have no legal obligation44+These libraries are in the public domain. You can do anything you45+want with them. You have no legal obligation46 to do anything else, although I appreciate attribution.47 48+They are also licensed under the MIT open source license, if you have lawyers49+who are unhappy with public domain. Every source file includes an explicit50+dual-license for you to choose from.51+52 #### <a name="other_libs"></a> Are there other single-file public-domain/open source libraries with minimal dependencies out there?53 54 [Yes.](https://github.com/nothings/single_file_libs)55 52-#### 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?57 54-No.58+No, because it's public domain you can freely relicense it to whatever license your new59+library wants to be.60 61 #### Some of these libraries seem redundant to existing open source libraries. Are they better somehow?62 63 Generally they're only better in that they're easier to integrate,1 unmodified line65 attribution requirement). They may be less featureful, slower,66 and/or use more memory. If you're already using an equivalent67 library, there's probably no good reason to switch.68 64-###### Can I link directly to the table of stb libraries?69+#### Can I link directly to the table of stb libraries?70 71 You can use [this URL](https://github.com/nothings/stb#stb_libs) to link directly to that list.72 73 #### Why do you list "lines of code"? It's a terrible metric.69 unmodified linesmodified:stb_image.h+50 added-5 removed
1690 unmodified lines1691 int spec_end;1692 int succ_high;1693 int succ_low;1694 int eob_run;1695+ int jfif;1696+ int app14;1697 int rgb;1698 1699 int scan_n, order[4];1700 int restart_interval, todo;1140 unmodified lines2841 L -= n;2842 }2843 return L==0;2844 }2845+2846 // 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;2856+2857+ 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+ }2884+2885+ stbi__skip(z->s, L);2886 return 1;2887 }2888+2889 return stbi__err("unknown marker","Corrupt JPEG");2890 }2891 2892 // after we see SOS152 unmodified lines3045 3046 static 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 lines3518 } stbi__resample;3519 3520 static 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 safe3524 3525 // validate req_comp3526 if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error");3 unmodified lines3530 3531 // determine actual number of components to generate3532 n = req_comp ? req_comp : z->s->img_n;3533 3534+ is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14 == 0 && !z->jfif));3535+3491- 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 lines3592 }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 lines3610 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