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

Overview

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
    new library 
    opened by nothings 46
  • 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
    4 enhancement help wanted 1 stb_vorbis 
    opened by nothings 25
  • 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

    opened by benwiley4000 20
  • 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

    2 bug 1 stb_image 
    opened by SpartanJ 20
  • 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.

    1 stb_image 
    opened by randy408 19
  • 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.

    1 stb_image_write 
    opened by guillaumechereau 17
  • 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.

    new library 
    opened by powerc9000 16
  • 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

    1 stb_image 
    opened by ghost 16
  • 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.

    2 bug 1 stb_image 
    opened by giordi91 16
  • 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.

    2 bug 1 stb library w/no tag 
    opened by BSVino 16
  • stb_ds.h fails unit tests gcc 11.3.0

    stb_ds.h fails unit tests gcc 11.3.0

    I tired running the unit test after getting unexpected results when compiling with address sanitizer. It failed one test. main.c

    #define STB_DS_IMPLEMENTATION
    #define STBDS_UNIT_TESTS
    #include "stb_ds.h"
    
    int main(int argc, char const *argv[])
    {
        stbds_unit_tests();
        return 0;
    }
    

    gcc main.c

    a.out: src/stb_ds.h:1847: stbds_unit_tests: Assertion `hmgets(map3, s.key).d == i*5' failed.

    I expected a piece in my game to move to its valid location, but it did not. I suspect it was a failed call to hmgeti(game->valid_actions, *action) != -1. The bug manifests itself in several ways. If i compile with no -fsanitize=address it appears to work. I checked the hashmap by iterating over it and it did have my entry but when using hmgeti it does not find it.

    Relevant structures.

    typedef struct Position {
        int q;
        int r;
        int s;
    } Position;
    
    typedef struct Action {
        char piece;
        Position source;
        Position destination;
    } Action;
    
    typedef struct ActionHashMapEntry {
        Action key;
    } ActionHashMapEntry;
    
    #define COLUMNS 127
    #define ROWS 127
    #define LAYERS 7
    #define SPACES (COLUMNS * ROWS * LAYERS)
    
    typedef struct Game {
        Position positions[PIECES];
        char board[SPACES];
        int current_turn;
        int pieces_in_play;
        Action *history;
        ActionHashMapEntry *valid_actions;
    } Game;
    

    I Create a hashmap of ActionHashMapEntrys.

    Game game = {0}; // Init game.valid_actions to NULL
    

    I insert and query for ActionHashMapEntrys

    Action action = {piece, piece_position, adjacent_position};
    hmputs(game->valid_actions, (ActionHashMapEntry){action});
    
    hmgeti(game->valid_actions, *action) != -1;
    

    I free and resuse the hashmap.

    hmfree(game.valid_actions);
    
    for(int i = 1; i < PIECES; ++i)
    {
        game_generate_moves_for_piece(&game, i);
    }
    

    I never pass the pointer to the hashmap directly it is always referenced by the Game structure.

    opened by Vaxeral 15
  • stb_image_write.h: UBSAN, left shift of negative value

    stb_image_write.h: UBSAN, left shift of negative value

    Hello! UBSan complains about a left shift of negative value:

    stb_image_write.h:1263:14: runtime error: left shift of negative value -402661120
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior stb_image_write.h:1263:14
    
    opened by BlackMATov 0
  • I updated stale code in STB_C_LEX_ISWHITE

    I updated stale code in STB_C_LEX_ISWHITE

    It looks like some stale code was left in the ifdef for STB_C_LEX_ISWHITE. The changes worked for me with this definition of isWhite in the file I'm using the library from:

    #define STB_C_LEXER_IMPLEMENTATION
    int myWhite(char *c){
        return (*c == ' ' || *c == '\t' || *c == '\f');
    }
    #define STB_C_LEX_ISWHITE(x) myWhite(x)
    #include "stb_c_lexer.h"
    
    opened by jeng 0
  • stb_image.h stbi_load

    stb_image.h stbi_load

    The filepath can't used in Windows UTF-8 I found that there is a function stbiw_fopen used to open utf-8 filepath ,but in stbi_load it only use stbi_fopen to load file.

    opened by Bendancom 0
  • stb_image.h  security issue : heap-based buffer over-read in stbi__tga_load

    stb_image.h security issue : heap-based buffer over-read in stbi__tga_load

    Hi, I would like to know if there will be update for stb_image.h due to the security issue it has ?

    Reference :

    https://vuldb.com/?id.212812

    https://groups.google.com/g/linux.debian.bugs.dist/c/ijJm5r8SWyk

    stb_image.h (aka the stb image loader) 2.23 has a heap-based buffer over-read in stbi__tga_load, leading to Information Disclosure or Denial of Service.

    If yes, do we know when ?

    opened by stavBodik 5
  • stb_truetype: Add missing `return` keyword

    stb_truetype: Add missing `return` keyword

    Hi stb maintainers! Here's one more pull request: in stb_truetype.h, stbtt__cid_get_glyph_subrs() creates a null stbtt__buf on an invalid format or glyph as if to return an error, but discards the result. This pull request adds the keyword to return it.

    Thanks!

    opened by NeilBickford-NV 0
  • Failed to run make under tests

    Failed to run make under tests

    Describe the bug can not make tests

    To Reproduce Steps to reproduce the behavior:

    1. Go to tests
    2. run 'make' on ubuntu 20.04
    3. Scroll down to '....'
    4. See error
    cc -I.. -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -DSTB_DIVIDE_TEST ../stb_vorbis.c test_c_compilation.c test_c_lexer.c test_dxt.c test_easyfont.c test_image.c test_image_write.c test_perlin.c test_sprintf.c test_truetype.c test_voxel.c -lm
    cc -I.. -Wno-write-strings -DSTB_DIVIDE_TEST -std=c++0x test_cpp_compilation.cpp -lm -lstdc++
    /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
    (.text+0x24): undefined reference to `main'
    collect2: error: ld returned 1 exit status
    make: *** [Makefile:10: all] Error 1
    

    Expected behavior should build tests without errors

    Screenshots If applicable, add screenshots to help explain your problem.

    opened by laoshaw 6
Abseil Common Libraries (C++)

Abseil - C++ Common Libraries The repository contains the Abseil C++ library code. Abseil is an open-source collection of C++ code (compliant to C++11

Abseil 11.5k Jan 8, 2023
Basic Development Environment - a set of foundational C++ libraries used at Bloomberg.

BDE Libraries This repository contains the BDE libraries, currently BSL (Basic Standard Library), BDL (Basic Development Library), BAL (Basic Applicat

Bloomberg 1.4k Dec 29, 2022
C++14 evented IO libraries for high performance networking and media based applications

LibSourcey C++ Networking Evolved LibSourcey is a collection of cross platform C++14 modules and classes that provide developers with an arsenal for r

Sourcey 1.3k Dec 21, 2022
stb single-file public domain libraries for C/C++

stb single-file public domain (or MIT licensed) libraries for C/C++ Noteworthy: image loader: stb_image.h image writer: stb_image_write.h image resize

Sean Barrett 20.7k Dec 30, 2022
Single header lib for JPEG encoding. Public domain. C99. stb style.

tiny_jpeg.h A header-only public domain implementation of Baseline JPEG compression. Features: stb-style header only library. Does not do dynamic allo

Sergio Gonzalez 213 Jan 1, 2023
Single header lib for JPEG encoding. Public domain. C99. stb style.

tiny_jpeg.h A header-only public domain implementation of Baseline JPEG compression. Features: stb-style header only library. Does not do dynamic allo

Sergio Gonzalez 212 Dec 14, 2022
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

Chris 19 Nov 5, 2022
A single file, public domain C implementation of aSchroeder reverb.

Introduction This is a reverb implementation based on Freeverb, a public domain reverb written by Jezar at Dreampoint in 2000. The library is written

Philip Bennefall 55 Nov 27, 2022
Single file public domain networking library

zed_net zed_net is a single file, public domain library that provides a simple wrapper around BSD sockets (Winsock 2.2 on Windows), intended primary f

Ian T. Jacobsen 52 Jan 1, 2023
A collection of public domain/unlicense single-file cryptography

simple-crypto A collection of single-file public domain/unlicense cryptographic functions in different programming languages. Feel free to copy-paste

null 4 Sep 24, 2022
linalg.h is a single header, public domain, short vector math library for C++

linalg.h linalg.h is a single header, public domain, short vector math library for C++. It is inspired by the syntax of popular shading and compute la

Sterling Orsten 758 Jan 7, 2023
The MHS Filesystem- A very simple linked-list based file system designed for recoverability and low data redundancy. Public domain filesystem (Version 1)

MHS Filesystem The MHS filesystem. Features: can be modified to work with any size of disk or sector, even non powers of two! Allocation bitmap stored

DMHSW 8 Sep 17, 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

null 5 Aug 22, 2022
Public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C

rpmalloc - General Purpose Memory Allocator This library provides a public domain cross platform lock free thread caching 16-byte aligned memory alloc

Mattias Jansson 1.7k Dec 28, 2022
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

Jakub Šebek 29 Dec 15, 2022
⛳ Simple, extensible, header-only C++17 argument parser released into the public domain.

⛳ flags Simple, extensible, header-only C++17 argument parser released into the public domain. why requirements api get get (with default value) posit

sailormoon 207 Dec 11, 2022
Rpmalloc - Public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C

rpmalloc - General Purpose Memory Allocator This library provides a public domain cross platform lock free thread caching 16-byte aligned memory alloc

Mattias Jansson 1.7k Jan 5, 2023
This is a minimal state immediate mode graphical user interface toolkit written in ANSI C and licensed under public domain

This is a minimal state immediate mode graphical user interface toolkit written in ANSI C and licensed under public domain. It was designed as a simple embeddable user interface for application and does not have any dependencies, a default render backend or OS window and input handling but instead provides a very modular library approach by using simple input state for input and draw commands describing primitive shapes as output.

Micha Mettke 13.5k Jan 8, 2023
super duper simple gui for C, wrapping imgui and stb

super duper simle gui for C, wrapping imgui and stb You can use it as a static library with cmake. See the example directory for a complete example. E

Rasmus 11 May 19, 2022
A collection of single-file C libraries. (generic containers, random number generation, argument parsing and other functionalities)

cauldron A collection of single-file C libraries and tools with the goal to be portable and modifiable. Libraries library description arena-allocator.

Camel Coder 40 Dec 29, 2022