stb single-file public domain libraries for C/C++

stb

single-file public domain (or MIT licensed) libraries for C/C++

Noteworthy:

Most libraries by stb, except: stb_dxt by Fabian "ryg" Giesen, stb_image_resize by Jorge L. "VinoBS" Rodriguez, and stb_sprintf by Jeff Roberts.

library lastest version category LoC description
stb_vorbis.c 1.20 audio 5563 decode ogg vorbis files from file/memory to float/16-bit signed output
stb_image.h 2.26 graphics 7762 image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC
stb_truetype.h 1.24 graphics 5011 parse, decode, and rasterize characters from truetype fonts
stb_image_write.h 1.15 graphics 1690 image writing to disk: PNG, TGA, BMP
stb_image_resize.h 0.96 graphics 2631 resize images larger/smaller with good quality
stb_rect_pack.h 1.00 graphics 628 simple 2D rectangle packer with decent quality
stb_ds.h 0.65 utility 1880 typesafe dynamic array and hash tables for C, will compile in C++
stb_sprintf.h 1.09 utility 1879 fast sprintf, snprintf for C/C++
stretchy_buffer.h 1.04 utility 263 typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++
stb_textedit.h 1.13 user interface 1404 guts of a text editor for games etc implementing them from scratch
stb_voxel_render.h 0.89 3D graphics 3807 Minecraft-esque voxel rendering "engine" with many more features
stb_dxt.h 1.10 3D graphics 753 Fabian "ryg" Giesen's real-time DXT compressor
stb_perlin.h 0.5 3D graphics 428 revised Perlin noise (3D input, 1D output)
stb_easy_font.h 1.1 3D graphics 305 quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc
stb_tilemap_editor.h 0.41 game dev 4161 embeddable tilemap editor
stb_herringbone_wa... 0.7 game dev 1221 herringbone Wang tile map generator
stb_c_lexer.h 0.11 parsing 966 simplify writing parsers for C-like languages
stb_divide.h 0.93 math 430 more useful 32-bit modulus e.g. "euclidean divide"
stb_connected_comp... 0.96 misc 1049 incrementally compute reachability on grids
stb.h 2.37 misc 14454 helper functions for C, mostly redundant in C++; basically author's personal stuff
stb_leakcheck.h 0.6 misc 194 quick-and-dirty malloc/free leak-checking
stb_include.h 0.02 misc 295 implement recursive #include support, particularly for GLSL

Total libraries: 22 Total lines of C code: 56774

FAQ

What's the license?

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.

If I wrap an stb library in a new library, does the new library have to be public domain/MIT?

No, because it's public domain you can freely relicense it to whatever license your new library wants to be.

What's the deal with SSE support in GCC-based compilers?

stb_image will either use SSE2 (if you compile with -msse2) or will not use any SIMD at all, rather than trying to detect the processor at runtime and handle it correctly. As I understand it, the approved path in GCC for runtime-detection require you to use multiple source files, one for each CPU configuration. Because stb_image is a header-file library that compiles in only one source file, there's no approved way to build both an SSE-enabled and a non-SSE-enabled variation.

While we've tried to work around it, we've had multiple issues over the years due to specific versions of gcc breaking what we're doing, so we've given up on it. See https://github.com/nothings/stb/issues/280 and https://github.com/nothings/stb/issues/410 for examples.

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; no 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?

You can use this URL to link directly to that list.

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 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?

No, they are just the initials for my name, Sean T. Barrett. This was not chosen out of egomania, but as a moderately sane way of namespacing the filenames and source function names.

Will you add more image types to stb_image.h?

No. As stb_image use has grown, it has become more important for us to focus on security of the codebase. Adding new image formats increases the amount of code we need to secure, so it is no longer worth adding new formats.

Do you have any advice on how to create my own single-file library?

Yes. https://github.com/nothings/stb/blob/master/docs/stb_howto.txt

Why public domain?

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?

Primarily, because I use C, not C++. But it does also make it easier for other people to use them from other languages.

Why not C99? stdint.h, declare-anywhere, etc.

I still use MSVC 6 (1998) as my IDE because it has better human factors for me than later versions of MSVC.

Comments
  • Requested libraries

    Requested libraries

    THIS THREAD IS FOR REQUESTING LIBRARIES, NOT FOR ADDITIONS TO OTHER_LIBS.

    Over the years, people have suggested the following ideas for stb libraries. Here are your options for these libraries, where appropriate.

    • ~~lexer~~
    • ~~image resizer~~
    • matrix library -- stb_vec.h is the beginnings of one
    • zip file handler -- consider miniz
    • flac audio decoder
    • adpcm audio decoder
    • Opus audio decoder -- why there is no stb_opus
    • crypto library -- consider TweetNaCl
    • wide-line rendering -- I have a bad version of this coming, need to think about good version
    • triangle-soup raycaster
    • key/value store
    • json parser -- consider one of the 4+ JSON parsers here
    • http -- consider one of the server or client libraries here
    • plotting & graphing -- I need to finish up stb_plot.h
    • unicode text shaping -- (Harfbuzz et al) my best guess from researching is that this isn't sufficiently documented in official Unicode documents (and other English documents) to write it purely from specs; needs language-specific expertise for each supported language
    • software-rendered photoshop layer & filter effects
    • pdb parsing/processing -- the "specification" is primarily source code, so this has the same problem as Opus above
    • C preprocessor -- consider fcpp; also, I actually need this for a C-with-statically-typed-NULL-checking tool I've been working on on-and-off, so I might do it
    • PhysFS-esque pak-file-esque handler with pluggable back-ends
    • JPEG RGBA file format
    • regex matching using stb's boyer-moore-esque SGREP algorithm
    • FFT -- consider KISS FFT
    • arbitrary precision math
    • portable networking
    • portable threading -- consider mts
    • SVD
    • speech synthesizer
    • fbx/obj/blender 3d-model loader -- consider https://github.com/syoyo/tinyobjloader
    • non-linear least squares and general solver, a la http://ceres-solver.org/
    • HAMT or other sophisticated data structure
    • mp3 decoder useful once the patents expire soon-ish
    • html paser/renderer
  • support for seeking in stb_vorbis.c  (payment)

    support for seeking in stb_vorbis.c (payment)

    Someone has currently declared their intent to pursue this. Historically, multiple people have looked at this and given up, though, so it may re-open.

    stb_vorbis is this single-file C library for decoding ogg vorbis files: https://github.com/nothings/stb/blob/master/stb_vorbis.c

    stb_vorbis doesn't have correctly-working seek functionality (e.g. being able to say 'start playback from sample number 31415926').

    The payment for a correct implementation of this feature is 5000 USD. (It may go down again in a few months as the current amount is the sum of several individuals who may drop out if it doesn't get done soon enough.) Please let me know if you are working on it to make sure we don't end up with two people doing it at the same time, as only one correct implementation will be paid out.

    Requirements:

    • seeking must be sample-accurate
    • reasonably efficient (binary search, interpolation search, etc)
    • cannot generate an off-line index or scan the whole file at start
    • changes must be placed in the public domain
    • you can start with the existing non-working implementation of seek (see below) or start from scratch
    • you'll need to learn about both the ogg specification and the vorbis specification to do this (see the link below for some insight why)
    • I (@nothings) am available to provide guidance about what the existing code is doing (aka write better comments)

    Current status in the code:

    • there is a 2007 implementation of seeking in the code which doesn't work. I no longer remember the details of how it doesn't work. I wrote this document about the frustrations of trying to do a performance-optimal implementation: http://nothings.org/stb_vorbis/ogg_seek.txt but at this point I will accept some suboptimality.
    • the "pushdata" API supports an approximate seeking; this is satisfactory for the pushdata API but not for the normal ("pulldata") API. you can just ignore the pushdata case
  • Crash with Floating Point Exception (Code 8) on bitmap load

    Crash with Floating Point Exception (Code 8) on bitmap load

    I've run into a floating point exception (code 8) trying to stbi_load a bitmap image, which loads if I save the image as a png or jpeg. I was able to run the program fine on my Linux distro (Ubuntu 17.04) but not on macOS Sierra.

    This is the image: https://drive.google.com/file/d/0B1z6l9DJ0EySbExqTFpkM0FkWk0/view?usp=sharing

  • SSE2 jpeg decoding segfaults in mingw 32 bit builds

    SSE2 jpeg decoding segfaults in mingw 32 bit builds

    Hi Sean!

    I received a bug report on one of my libraries that relies on stb_image to do the image decoding. It took me a while to understand what was happening since i couldn't reproduce it, until the user mentioned that it was building for 32bits with mingw32 ( and i was building 64 bit builds ).

    It seems that the jpeg SSE2 decoder is failing strangely, since if i build with VC works just fine. Here's an image of the callstack when fails: fail.

    Here's a project to test the issue.

    I've also tested to cross-compile the project from linux and it also happens. I must say that i know nothing about SSE2 so i really can't help much with the bug. And AFAIK it's a 32bit mingw only problem, no problems so far in 32 or 64 bit builds in linux, and if i remember correctly, no problems in os x neither.

    Edit: I tried compiling with "-msse -msse2" enabled but didn't help.

    Regards

  • stb_image: add png fuzz target

    stb_image: add png fuzz target

    This adds a fuzz target, dictionary and iphone png's for fuzzing the png reader. My plan is to eventually integrate with OSS-Fuzz which would continuously fuzz the code in stb_image.h.

  • stb_image and stb_image_write: allow to use zlib for png compression

    stb_image and stb_image_write: allow to use zlib for png compression

    I noticed that the zlib compression in stb_image_write was rather poor compared to what the actual zlib library would do. For example saving an rgba image filled with the gray color (128,128,128,255) prodices a png of size 42KB. When I use zlib to compress the data instead of stb algorithm, I get 6.4KB.

    Many projects already use zlib, so I think having the option to use it would be nice, if that is not too much work.

  • Error compiling stb.h in visual studio

    Error compiling stb.h in visual studio

    Hello I am having problems compiling stb.h Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019 for x64 stb.h version 2.30 Here are my includes just in case one of them is the problem

    #define STB_DEFINE
    #include "stb.h"
    #include "sdl/include/SDL.h"
    #define STB_IMAGE_IMPLEMENTATION
    #include "stb_image.h"
    #include <stdint.h>
    #include <cmath>
    #include "platform.h"
    
    #include <limits> 
    

    compile script

    
    cl -Od -Zo -Z7 ..\seville\win32_main.cpp -Fmwin32_main.map /link  -incremental:no -opt:ref user32.lib gdi32.lib winmm.lib opengl32.lib ..\seville\sdl\lib\x64\sdl2.lib
    

    here are the errors I get

    Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019 for x64
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    win32_main.cpp
    c:\users\computer\games\seville\stb.h(3365): warning C4311: 'type cast': pointer truncation from 'void *' to 'unsigned int'
    c:\users\computer\games\seville\stb.h(3414): warning C4311: 'type cast': pointer truncation from 'unsigned char *' to 'int'
    c:\users\computer\games\seville\stb.h(3740): warning C4311: 'type cast': pointer truncation from 'char *' to 'int'
    c:\users\computer\games\seville\stb.h(3759): warning C4311: 'type cast': pointer truncation from 'char *' to 'int'
    c:\users\computer\games\seville\stb.h(3767): warning C4311: 'type cast': pointer truncation from 'char *' to 'int'
    c:\users\computer\games\seville\stb.h(6528): warning C4312: 'type cast': conversion from 'unsigned int' to 'void *' of greater size
    c:\users\computer\games\seville\stb.h(6530): warning C4312: 'type cast': conversion from 'unsigned int' to 'void *' of greater size
    c:\users\computer\games\seville\stb.h(6963): error C2665: 'swprintf': none of the 2 overloads could convert all the argument types
    C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\corecrt_wstdio.h(1820): note: could be 'int swprintf(wchar_t *const ,const wchar_t *const ,...) throw()'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\corecrt_wstdio.h(1463): note: or       'int swprintf(wchar_t *const ,const ::size_t,const wchar_t *const ,...)'
    c:\users\computer\games\seville\stb.h(6963): note: while trying to match the argument list '(stb__wchar [1024], int, const wchar_t [4], stb__wchar *)'
    c:\users\computer\games\seville\stb.h(6965): error C2665: 'swprintf': none of the 2 overloads could convert all the argument types
    C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\corecrt_wstdio.h(1820): note: could be 'int swprintf(wchar_t *const ,const wchar_t *const ,...) throw()'
    C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\corecrt_wstdio.h(1463): note: or       'int swprintf(wchar_t *const ,const ::size_t,const wchar_t *const ,...)'
    c:\users\computer\games\seville\stb.h(6965): note: while trying to match the argument list '(stb__wchar [1024], int, const wchar_t [5], stb__wchar *)'
    c:\users\computer\games\seville\stb.h(6983): error C2664: 'intptr_t _wfindfirst64(const wchar_t *,_wfinddata64_t *)': cannot convert argument 1 from 'stb__wchar [1024]' to 'const wchar_t *'
    c:\users\computer\games\seville\stb.h(6983): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    c:\users\computer\games\seville\stb.h(6990): error C2664: 'char *stb__to_utf8(stb__wchar *)': cannot convert argument 1 from 'wchar_t [260]' to 'stb__wchar *'
    c:\users\computer\games\seville\stb.h(6990): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    c:\users\computer\games\seville\stb.h(7007): error C2664: 'char *stb__to_utf8(stb__wchar *)': cannot convert argument 1 from 'wchar_t [260]' to 'stb__wchar *'
    c:\users\computer\games\seville\stb.h(7007): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    c:\users\computer\games\seville\stb.h(7045): warning C4477: 'printf' : format string '%08x' requires an argument of type 'unsigned int', but variadic argument 2 has type 'time_t'
    c:\users\computer\games\seville\stb.h(7045): note: consider using '%llx' in the format string
    c:\users\computer\games\seville\stb.h(7045): note: consider using '%Ix' in the format string
    c:\users\computer\games\seville\stb.h(7045): note: consider using '%I64x' in the format string
    c:\users\computer\games\seville\stb.h(7045): warning C4477: 'printf' : format string '%08x' requires an argument of type 'unsigned int', but variadic argument 3 has type '__time64_t'
    c:\users\computer\games\seville\stb.h(7045): note: consider using '%llx' in the format string
    c:\users\computer\games\seville\stb.h(7045): note: consider using '%Ix' in the format string
    c:\users\computer\games\seville\stb.h(7045): note: consider using '%I64x' in the format string
    c:\users\computer\games\seville\stb.h(7634): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint32'
    c:\users\computer\games\seville\stb.h(7641): warning C4311: 'type cast': pointer truncation from 'stb_ps *' to 'int'
    c:\users\computer\games\seville\stb.h(7653): warning C4311: 'type cast': pointer truncation from 'stb_ps *' to 'int'
    c:\users\computer\games\seville\stb.h(7680): warning C4311: 'type cast': pointer truncation from 'stb_ps *' to 'int'
    c:\users\computer\games\seville\stb.h(7681): warning C4311: 'type cast': pointer truncation from 'void *' to 'int'
    c:\users\computer\games\seville\stb.h(7722): warning C4311: 'type cast': pointer truncation from 'void *' to 'int'
    c:\users\computer\games\seville\stb.h(7726): warning C4311: 'type cast': pointer truncation from 'stb_ps *' to 'int'
    c:\users\computer\games\seville\stb.h(7775): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint32'
    c:\users\computer\games\seville\stb.h(7779): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint32'
    c:\users\computer\games\seville\stb.h(7806): warning C4311: 'type cast': pointer truncation from 'void *' to 'int'
    c:\users\computer\games\seville\stb.h(7808): warning C4311: 'type cast': pointer truncation from 'stb_ps *' to 'int'
    c:\users\computer\games\seville\stb.h(7867): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint32'
    c:\users\computer\games\seville\stb.h(7889): warning C4311: 'type cast': pointer truncation from 'stb_ps *' to 'int'
    c:\users\computer\games\seville\stb.h(7922): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint32'
    c:\users\computer\games\seville\stb.h(7943): warning C4311: 'type cast': pointer truncation from 'stb_ps *' to 'int'
    c:\users\computer\games\seville\stb.h(7969): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint32'
    c:\users\computer\games\seville\stb.h(7981): warning C4311: 'type cast': pointer truncation from 'stb_ps *' to 'int'
    c:\users\computer\games\seville\stb.h(8003): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint32'
    c:\users\computer\games\seville\stb.h(8017): warning C4311: 'type cast': pointer truncation from 'stb_ps *' to 'int'
    c:\users\computer\games\seville\stb.h(8039): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint32'
    c:\users\computer\games\seville\stb.h(8050): warning C4311: 'type cast': pointer truncation from 'stb_ps *' to 'int'
    c:\users\computer\games\seville\stb.h(8074): warning C4311: 'type cast': pointer truncation from 'stb_ps *' to 'int'
    c:\users\computer\games\seville\stb.h(9121): warning C4838: conversion from 'int' to 'stb_int16' requires a narrowing conversion
    c:\users\computer\games\seville\stb.h(9121): warning C4838: conversion from 'int' to 'stb_uint16' requires a narrowing conversion
    c:\users\computer\games\seville\stb.h(9834): warning C4311: 'type cast': pointer truncation from 'char *' to 'int'
    c:\users\computer\games\seville\stb.h(9865): warning C4311: 'type cast': pointer truncation from 'char *' to 'int'
    c:\users\computer\games\seville\stb.h(9866): warning C4311: 'type cast': pointer truncation from 'char *' to 'int'
    c:\users\computer\games\seville\stb.h(10623): warning C4838: conversion from 'stb_uint' to 'stb_uchar' requires a narrowing conversion
    c:\users\computer\games\seville\stb.h(12373): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint32'
    c:\users\computer\games\seville\stb.h(12373): warning C4312: 'type cast': conversion from 'stb_uint32' to 'stb__span **' of greater size
    c:\users\computer\games\seville\stb.h(12392): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint32'
    c:\users\computer\games\seville\stb.h(12392): warning C4312: 'type cast': conversion from 'stb_uint32' to 'stb__span *' of greater size
    c:\users\computer\games\seville\stb.h(12473): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint32'
    c:\users\computer\games\seville\stb.h(12551): warning C4312: 'type cast': conversion from 'int' to 'char *' of greater size
    c:\users\computer\games\seville\stb.h(12628): warning C4312: 'type cast': conversion from 'int' to 'void *' of greater size
    c:\users\computer\games\seville\stb.h(12648): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint'
    c:\users\computer\games\seville\stb.h(12661): warning C4311: 'type cast': pointer truncation from 'void *' to 'stb_uint'
    

    Thanks for any help or insight you can give.

  • stb_image can't load these png files (but they view OK in any other app)

    stb_image can't load these png files (but they view OK in any other app)

    I saved some png files on OSX. Via the screen capture, but also via resaving the file in Apple's Preview.app. And now the files don't load properly in stb_image.

    stb_fail1 stb_fail2 stb_fail3

  • stb_image is it thread safe?

    stb_image is it thread safe?

    Hi, I am using stb_image to load texture for my game engine, all works nice and dandy but I am getting what I believe being race conditions inside stbi_load and I would like to know If that function is thread safe. What I am doing is really simple:

    auto data= stbi_load(path,&m_width, &m_height, 0, 0);

    This is at the start of my own Texture::load, that class is allocated on the heap right before calling the load, so no race condition can happen there ,the first line in load() is the stbi_load function you see. From time to time, an assertion from stbi_load (or any nested func call), is being triggered. The assertion is the following:

    Assertion failed: z->size[b] == s, file E:\WORK_IN_PROGRESS\C\libs\Simple-OpenGL-Image-Library\src\stb_image_aug.c, line 1750

    Which looking at the current version i have (to be honest the stb_image i am using came from SOIL, but i have bypassed it completely and called stb_image directly):

    `__forceinline static int zhuffman_decode(zbuf *a, zhuffman *z) { int b,s,k; if (a->num_bits < 16) fill_bits(a); b = z->fast[a->code_buffer & ZFAST_MASK]; if (b < 0xffff) { s = z->size[b]; a->code_buffer >>= s; a->num_bits -= s; return z->value[b]; }

    // not resolved by fast table, so compute it the slow way // use jpeg approach, which requires MSbits at top k = bit_reverse(a->code_buffer, 16); for (s=ZFAST_BITS+1; ; ++s) if (k < z->maxcode[s]) break; if (s == 16) return -1; // invalid code! // code size is s, so: b = (k >> (16-s)) - z->firstcode[s] + z->firstsymbol[s]; assert(z->size[b] == s); a->code_buffer >>= s; a->num_bits -= s; return z->value[b]; }`

    Now anyone know what could be triggering this? If I move just the stbi_func call inside a lock everything works perfectly, so I would be curious to know whats going on and how to prevent the assertion, having texture loading inside a lock is less than ideal and would rather avoid it.

  • Fix the calculation of the input image shift when using subpixel regions

    Fix the calculation of the input image shift when using subpixel regions

    Includes some more tests which had incorrect results before, but work fine with the included fixes. The test does a subpixel region that slides from [0, 0.5] to [0.5, 1] for both upsampling and downsampling. I think that should cover all of the uses of the subpixel stuff. I'm not bothering with s < 0 or t > 1 because I don't think we ever intended to support that in the first place. At the very least, non-subpixel stuff is unaffected because s0 = t0 = 0 means in_shift = 0.

  • stb_vorbis.c fails to compile because of __forceinline (windows cross-compile)

    stb_vorbis.c fails to compile because of __forceinline (windows cross-compile)

    I'm compiling my application in a Debian x64 box, using an Windows cross-compilation toolchain.

    The error message is:

    In file included from ../retroluxury/src/rl_sound.c:25:0:
    ../retroluxury/src/stb_vorbis.c:941:1: error: multiple storage classes in declaration specifiers
     static __forceinline uint32 crc32_update(uint32 crc, uint8 byte)
     ^
    

    followed by four more identical errors at lines 1558, 2042, and 2599.

    __forceinline default definition has extern in it, as the error message shows when I add #define __forceinline to std_vorbis.c:

    In file included from ../retroluxury/src/rl_sound.c:25:0:
    ../retroluxury/src/stb_vorbis.c:565:0: warning: "__forceinline" redefined [enabled by default]
     #define __forceinline
     ^
    In file included from /opt/mingw64/x86_64-w64-mingw32/include/crtdefs.h:10:0,
                     from /opt/mingw64/x86_64-w64-mingw32/include/stdint.h:28,
                     from /opt/mingw64/lib/gcc/x86_64-w64-mingw32/4.9.0/include/stdint.h:9,
                     from ../retroluxury/src/rl_sound.h:6,
                     from ../retroluxury/src/rl_sound.c:1:
    /opt/mingw64/x86_64-w64-mingw32/include/_mingw.h:263:0: note: this is the location of the previous definition
     #define __forceinline extern __inline__ __attribute__((__always_inline__,__gnu_inline__))
     ^
    

    and it clashes with the functions declarations which are static.

    I'm not sure how to fix this without redefining __forceinline in std_vorbis.c.

  • Assertion failed while loading 32bit BMP

    Assertion failed while loading 32bit BMP

    The following gets written to the console after calling stbi_load: Assertion failed: info.offset == s->callback_already_read + (int) (s->img_buffer - s->img_buffer_original) stb_image.h, line 5397

    Here is the BMP that triggers the error example_bmp.zip.

  • Please add support for XYZE Radiance .hdr files

    Please add support for XYZE Radiance .hdr files

    Is your feature request related to a problem? Please describe. Radiance .hdr does not support negative values. Thus, any out-of-gamut colors get clipped in the normal RGBE format. Meaning, the range of colors that can be displayed with normal .hdr files is limited to the sRGB gamut (in a typical context like reading .hdr files as textures in a non-color-managed context). There's also the XYZE variation of .hdr. XYZE saves values in the XYZ color space instead which encompasses all visible colors.

    Describe the solution you'd like Support reading/writing of XYZE files. Treat them like normal linear sRGB images. When writing, convert from the input values from linear sRGB to XYZ. When reading, convert from XYZ to linear sRGB. It is a simple matrix transform. Thus, effectively, negative values are allowed to the degree necessary to cover the colors perceivable by humans.

    Describe alternatives you've considered Alternative solutions: Treat the XYZE values as raw without any conversion, but let the calling application know/set that the .hdr file is a XYZE file so the application can do its own conversion. Yet another solution if the assumption of the data being linear sRGB is not desired: Provide a reading/writing function for .hdr files that allows to specify the chromacity and white coordinates, which then can be used to generate the correct conversion matrix. This way any arbitrary RGB color space could be assumed.

    Additional context That's about it I think.

  • Provide type definitions for Symbian OS/EPOC, #1321

    Provide type definitions for Symbian OS/EPOC, #1321

    The Symbian S60v1 SDK does not provide stdint.h. This additional preprocessor definition ensures that the required types are provided so that stb_image.h also compiles on this legacy system.

    This modification is intended for use with the N-Gage SDK.-project.

    No additional credit required.

  • Make stdint.h optional, allow to provide own type definitions

    Make stdint.h optional, allow to provide own type definitions

    Is your feature request related to a problem? Please describe. I'm actively developing a game for a legacy system. The compiler does not provide stdint.h, which seems to be a requirement for stb_image.h.

    Describe the solution you'd like It would be great if the library would offer the possibility to use own type definitions.

  • stb_truetype: allow user defined STBTT_DEF

    stb_truetype: allow user defined STBTT_DEF

    Allow users to define their own STBTT_DEF. Other headers such as stb_image.h and stb_image_write.h have a similar mechanism. I ran into a "STBTT_DEF redefined" compiler warning and figured that stb_truetype.h does not check if STBTT_DEF is defined.

  • Segmentation fault when loading certain JPG files with clang

    Segmentation fault when loading certain JPG files with clang

    Hello, I have an issue, I don't know if it's me who doesn't get how things should works or if it's a bug.

    When I compile my code with clang++ I get a segmentation fault if I use this JPG file (works well if I use png files) : https://user-images.githubusercontent.com/63962731/162726250-a5341182-9621-4f14-8a84-9ef99d05a51d.jpg If I compile with g++ I get no error. Note that I have g++ 11.2.0 and clang++ 13.0.0 and I use Windows

    Steps to reproduce the behavior:

    1. Here is my code :
    #include <stdio.h>
    #define STB_IMAGE_IMPLEMENTATION
    #include "stb_image.h"
    int main(void) 
    {
        int width, height, channels;
        unsigned char *img = stbi_load("test.jpg", &width, &height, &channels, 0);
        if(img == NULL) {
            printf("Error in loading the image\n");
            exit(1);
        }
        printf("Loaded image with a width of %dpx, a height of %dpx and %d channels\n", width, height, channels);
    }
    
    1. Compile using clang++ file.cpp
    2. Execute using ./a.exe
    3. Here is my backtrace if you want to know :
    Thread 1 received signal SIGSEGV, Segmentation fault.
    0x008417d8 in stbi__err(char const*) ()
    (gdb) bt
    #0  0x008417d8 in stbi__err(char const*) ()
    #1  0x00847849 in stbi__check_png_header(stbi__context*) ()
    #2  0x00843db4 in stbi__png_test(stbi__context*) ()
    #3  0x00843833 in stbi__load_main(stbi__context*, int*, int*, int*, int, stbi__result_info*, int) ()
    #4  0x0084190e in stbi__load_and_postprocess_8bit(stbi__context*, int*, int*, int*, int) ()
    #5  0x00841849 in stbi_load_from_file ()
    #6  0x00841770 in stbi_load ()
    #7  0x0084368a in main ()
    

    I also receive a Segmentation fault with clang if the file doesn't exist, whereas with g++ I prints me Error in loading the image as it should be. Here is the backtrace for this :

    Thread 1 received signal SIGSEGV, Segmentation fault.
    0x003717d8 in stbi__err(char const*) ()
    (gdb) bt
    #0  0x003717d8 in stbi__err(char const*) ()
    #1  0x00371737 in stbi_load ()
    #2  0x0037368a in main ()
    
Related tags
Several single-file, cross-platform, public domain libraries for C/C++ that I use for learning / testing

HTC Several single-file, cross-platform, public domain libraries for C/C++ that I use for learning / testing (Not meant for production code). This is

May 6, 2022
Public domain, header-only file to simplify the C programmer's life in their interaction with strings

SCL_String Public domain, header-only file to simplify the C programmer's life in their interaction with strings NOTE: This library is still under con

May 5, 2022
Jittey - A public domain text editor written in C and Win32
Jittey  - A public domain text editor written in C and Win32

Jittey (Jacob's Terrific Text Editor) is a single-file basic text editor written in pure C and Win32, there is no real reason to use it, but it

Feb 22, 2022
POCO C++ Libraries are powerful cross-platform C++ libraries for building network
POCO C++ Libraries are powerful cross-platform C++ libraries for building network

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.

May 19, 2022
A single file, single function, header to make notifications on the PS4 easier

Notifi Synopsis Adds a single function notifi(). It functions like printf however the first arg is the image to use (NULL and any invalid input should

Mar 24, 2022
Collection of cross-platform single-header C libraries for doing a lot of stuff! (Still WIP)

ice_libs Collection of cross-platform single-header C libraries for doing a lot of stuff! (Still WIP) Brief ice_libs is collection of Single-Header C

May 19, 2022
Just another "Won't Fix" Windows Privilege Escalation from User to Domain Admin.
Just another

RemotePotato0 Just another "Won't Fix" Windows Privilege Escalation from User to Domain Admin. RemotePotato0 is an exploit that allows you to escalate

May 11, 2022
A static C++ library for the generation of discrete functions on a box-shaped domain
A static C++ library for the generation of discrete functions on a box-shaped domain

A static C++ library for the generation of discrete functions on a box-shaped domain. This is especially suited for the discretization of signed distance fields.

May 17, 2022
1337.club public open source paste for CSGO

1337.club 1337.club public open source paste for CSGO Discord: https://discord.gg/nmDZ8Rwxvk How-To: Download the git client, found here: https://git-

Mar 26, 2022
All of my code from exploiting Apex Legends released to the public.

apex-cheating I'm releasing all my source and tools to do with Apex Legends today because idk man. UC-Apex-Remastered An Apex Legends cheat based off

Apr 22, 2022
Displays Lat & Long on the terminal from a public API.
Displays Lat & Long on the terminal from a public API.

iss-term Displays Latidude & Longitude on the terminal from a public API, by using lib curl Libraries used libcurl to install Before you do anything,

Nov 16, 2021
Public repository for the HPPS course
Public repository for the HPPS course

Syllabus and Material for High Performance Programming and Systems (HPPS) Welcome to the course website for HPPS! While assignment handin is still on

Apr 2, 2022
This is a public repository which contains various topic wise coding problems on Ds and Algo

This repo will be partcipating in the Hacktoberfest 2021. Readme Credit goes to @Saumya ?? ?? All Noobs and pro PR's Are Welcome ?? ?? This repository

Feb 21, 2022
Public repository for Beerbox project.

Beerbox v1.0 - Public Repository This is a public repository for an "IoT Project"-course project called Beerbox. Difference between the private and pu

Dec 23, 2021
Rp-pppoe - Public repository for RP-PPPoE PPPoE client and server software

RP-PPPoE - a PPPoE client, relay and server for Linux RP-PPPoE is a PPPoE client, relay and server for Linux. It can run completely in user-mode or us

Apr 24, 2022
Wgeo, or "wi-fi geolocator", is a cross-platform C/C++ library for wifi-based device geolocation, utilising public wireless access point location databases

wgeo Wgeo, or "wi-fi geolocator", is a cross-platform C/C++ library for wifi-based device geolocation, utilising public wireless access point location

Jan 30, 2022
A simple Z-Machine implementation in a single C file. Now with online multiplayer! :)

This is an implementation of Infocom's Z-Machine. The Z-Machine is a virtual machine that's something like a high-level CPU. To keep their games portable and easier to write, Infocom's games all use this fake processor and ship with a platform-specific Z-Machine "emulator" ... so a game could run wherever someone had implemented the Z-Machine.

May 13, 2022
A single-file GLTF loader with no dependencies.

mvImporter Basic Usage #define MV_IMPORTER_IMPLEMENTATION #include "mvImporter.h" int main() { mvGLTFModel gltfmodel = mvLoadGLTF("C/dev/Resource

Apr 26, 2022
A high performance, shared memory, lock free, cross platform, single file, no dependencies, C++11 key-value store
A high performance, shared memory, lock free, cross platform, single file, no dependencies, C++11 key-value store

SimDB A high performance, shared memory, lock free, cross platform, single file, no dependencies, C++11 key-value store. SimDB is part of LAVA (Live A

May 13, 2022