diff --git a/README.md b/README.md index 4197a8c..5bd0d12 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ stb === -single-file public domain libraries for C/C++ +single-file public domain (or MIT licensed) libraries for C/C++ Most libraries by stb, except: stb_dxt by Fabian "ryg" Giesen, stb_image_resize by Jorge L. "VinoBS" Rodriguez, and stb_sprintf by Jeff Roberts. @@ -15,25 +15,25 @@ library | lastest version | category | LoC | description **[stb_image.h](stb_image.h)** | 2.14 | graphics | 7049 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC **[stb_truetype.h](stb_truetype.h)** | 1.15 | graphics | 4061 | parse, decode, and rasterize characters from truetype fonts **[stb_image_write.h](stb_image_write.h)** | 1.05 | graphics | 1092 | image writing to disk: PNG, TGA, BMP -**[stb_image_resize.h](stb_image_resize.h)** | 0.92 | graphics | 2620 | resize images larger/smaller with good quality -**[stb_rect_pack.h](stb_rect_pack.h)** | 0.10 | graphics | 623 | simple 2D rectangle packer with decent quality -**[stb_sprintf.h](stb_sprintf.h)** | 1.02 | utility | 1134 | fast sprintf, snprintf for C/C++ +**[stb_image_resize.h](stb_image_resize.h)** | 0.93 | graphics | 2625 | resize images larger/smaller with good quality +**[stb_rect_pack.h](stb_rect_pack.h)** | 0.11 | graphics | 635 | simple 2D rectangle packer with decent quality +**[stb_sprintf.h](stb_sprintf.h)** | 1.02 | utility | 1202 | fast sprintf, snprintf for C/C++ **[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++ -**[stb_textedit.h](stb_textedit.h)** | 1.10 | user interface | 1370 | guts of a text editor for games etc implementing them from scratch -**[stb_voxel_render.h](stb_voxel_render.h)** | 0.84 | 3D graphics | 3792 | Minecraft-esque voxel rendering "engine" with many more features -**[stb_dxt.h](stb_dxt.h)** | 1.05 | 3D graphics | 686 | Fabian "ryg" Giesen's real-time DXT compressor -**[stb_perlin.h](stb_perlin.h)** | 0.2 | 3D graphics | 222 | revised Perlin noise (3D input, 1D output) +**[stb_textedit.h](stb_textedit.h)** | 1.11 | user interface | 1393 | guts of a text editor for games etc implementing them from scratch +**[stb_voxel_render.h](stb_voxel_render.h)** | 0.85 | 3D graphics | 3803 | Minecraft-esque voxel rendering "engine" with many more features +**[stb_dxt.h](stb_dxt.h)** | 1.06 | 3D graphics | 687 | Fabian "ryg" Giesen's real-time DXT compressor +**[stb_perlin.h](stb_perlin.h)** | 0.3 | 3D graphics | 316 | revised Perlin noise (3D input, 1D output) **[stb_easy_font.h](stb_easy_font.h)** | 1.0 | 3D graphics | 303 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc **[stb_tilemap_editor.h](stb_tilemap_editor.h)** | 0.38 | game dev | 4172 | embeddable tilemap editor **[stb_herringbone_wa...](stb_herringbone_wang_tile.h)** | 0.6 | game dev | 1220 | herringbone Wang tile map generator **[stb_c_lexer.h](stb_c_lexer.h)** | 0.09 | parsing | 962 | simplify writing parsers for C-like languages **[stb_divide.h](stb_divide.h)** | 0.91 | math | 419 | more useful 32-bit modulus e.g. "euclidean divide" **[stb_connected_comp...](stb_connected_components.h)** | 0.95 | misc | 1045 | incrementally compute reachability on grids -**[stb.h](stb.h)** | 2.28 | misc | 14277 | helper functions for C, mostly redundant in C++; basically author's personal stuff +**[stb.h](stb.h)** | 2.29 | misc | 14324 | helper functions for C, mostly redundant in C++; basically author's personal stuff **[stb_leakcheck.h](stb_leakcheck.h)** | 0.3 | misc | 165 | quick-and-dirty malloc/free leak-checking Total libraries: 20 -Total lines of C code: 50916 +Total lines of C code: 51177 FAQ @@ -41,17 +41,22 @@ FAQ #### What's the license? -These libraries are in the public domain (or the equivalent where that is not -possible). You can do anything you want with them. You have no legal obligation +These libraries are in the public domain. You can do anything you +want with them. You have no legal obligation to do anything else, although I appreciate attribution. +They are also licensed under the MIT open source license, if you have lawyers +who are unhappy with public domain. Every source file includes an explicit +dual-license for you to choose from. + #### 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 new +library wants to be. #### Some of these libraries seem redundant to existing open source libraries. Are they better somehow? @@ -61,7 +66,7 @@ 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. -###### 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. diff --git a/stb_image.h b/stb_image.h index 1d7843c..bd83c14 100644 --- a/stb_image.h +++ b/stb_image.h @@ -1692,6 +1692,8 @@ typedef struct int succ_high; int succ_low; int eob_run; + int jfif; + int app14; int rgb; int scan_n, order[4]; @@ -2840,11 +2842,50 @@ static int stbi__process_marker(stbi__jpeg *z, int m) } return L==0; } + // check for comment block or APP blocks if ((m >= 0xE0 && m <= 0xEF) || m == 0xFE) { - stbi__skip(z->s, stbi__get16be(z->s)-2); + L = stbi__get16be(z->s); + if (L < 2) { + if (m == 0xFE) + return stbi__err("bad COM len","Corrupt JPEG"); + else + return stbi__err("bad APP len","Corrupt JPEG"); + } + L -= 2; + + if (m == 0xE0 && L >= 5) { // JFIF APP0 segment + static const unsigned char tag[5] = {'J','F','I','F','\0'}; + int ok = 1; + int i; + for (i=0; i < 5; ++i) + if (stbi__get8(z->s) != tag[i]) + ok = 0; + L -= 5; + if (ok) { + z->jfif = 1; + } + } else if (m == 0xEE && L >= 12) { // Adobe APP14 segment + static const unsigned char tag[6] = {'A','d','o','b','e','\0'}; + int ok = 1; + int i; + for (i=0; i < 6; ++i) + if (stbi__get8(z->s) != tag[i]) + ok = 0; + L -= 6; + if (ok) { + stbi__get8(z->s); // version + stbi__get16be(z->s); // flags0 + stbi__get16be(z->s); // flags1 + z->app14 = stbi__get8(z->s); // color transform + L -= 6; + } + } + + stbi__skip(z->s, L); return 1; } + return stbi__err("unknown marker","Corrupt JPEG"); } @@ -3005,6 +3046,8 @@ static int stbi__process_frame_header(stbi__jpeg *z, int scan) static int stbi__decode_jpeg_header(stbi__jpeg *z, int scan) { int m; + z->jfif = 0; + z->app14 = -1; z->marker = STBI__MARKER_none; // initialize cached marker to empty m = stbi__get_marker(z); if (!stbi__SOI(m)) return stbi__err("no SOI","Corrupt JPEG"); @@ -3476,7 +3519,7 @@ typedef struct static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp) { - int n, decode_n; + int n, decode_n, is_rgb; z->s->img_n = 0; // make stbi__cleanup_jpeg safe // validate req_comp @@ -3488,7 +3531,9 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp // determine actual number of components to generate n = req_comp ? req_comp : z->s->img_n; - if (z->s->img_n == 3 && n < 3 && z->rgb != 3) + is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14 == 0 && !z->jfif)); + + if (z->s->img_n == 3 && n < 3 && !is_rgb) decode_n = 1; else decode_n = z->s->img_n; @@ -3548,7 +3593,7 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp if (n >= 3) { stbi_uc *y = coutput[0]; if (z->s->img_n == 3) { - if (z->rgb == 3) { + if (is_rgb) { for (i=0; i < z->s->img_x; ++i) { out[0] = y[i]; out[1] = coutput[1][i]; @@ -3566,7 +3611,7 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp out += n; } } else { - if (z->rgb == 3) { + if (is_rgb) { if (n == 1) for (i=0; i < z->s->img_x; ++i) *out++ = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]); diff --git a/tools/README.footer.md b/tools/README.footer.md index e670b7f..b492e0a 100644 --- a/tools/README.footer.md +++ b/tools/README.footer.md @@ -4,17 +4,22 @@ FAQ #### What's the license? -These libraries are in the public domain (or the equivalent where that is not -possible). You can do anything you want with them. You have no legal obligation +These libraries are in the public domain. You can do anything you +want with them. You have no legal obligation to do anything else, although I appreciate attribution. +They are also licensed under the MIT open source license, if you have lawyers +who are unhappy with public domain. Every source file includes an explicit +dual-license for you to choose from. + #### 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 new +library wants to be. #### Some of these libraries seem redundant to existing open source libraries. Are they better somehow? @@ -24,7 +29,7 @@ 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. -###### 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. diff --git a/tools/README.header.md b/tools/README.header.md index 847fe62..41e55f1 100644 --- a/tools/README.header.md +++ b/tools/README.header.md @@ -1,7 +1,7 @@ stb === -single-file public domain libraries for C/C++ +single-file public domain (or MIT licensed) libraries for C/C++ Most libraries by stb, except: stb_dxt by Fabian "ryg" Giesen, stb_image_resize by Jorge L. "VinoBS" Rodriguez, and stb_sprintf by Jeff Roberts.