Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


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

Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402 (1 ratings)
Rated 5.0 out of 5
Subscribe to updates I use stb

Statistics on stb

Number of watchers on Github 6918
Number of open issues 54
Average time to close an issue 9 days
Main language C
Average time to merge a PR about 1 month
Open pull requests 118+
Closed pull requests 45+
Last commit over 1 year ago
Repo Created over 5 years ago
Repo Last Updated over 1 year ago
Size 3.94 MB
Homepage https://twitter.c...
Organization / Authornothings
Page Updated
Do you use stb? Leave a review!
View open issues (54)
View stb activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating stb for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)
What people are saying about stb Leave a review
Consists of small helpful one header libraries which get the job done!


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.

library lastest version category LoC description
stb_vorbis.c 1.14 audio 5462 decode ogg vorbis files from file/memory to float/16-bit signed output
stb_image.h 2.19 graphics 7462 image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC
stb_truetype.h 1.19 graphics 4853 parse, decode, and rasterize characters from truetype fonts
stb_image_write.h 1.09 graphics 1568 image writing to disk: PNG, TGA, BMP
stb_image_resize.h 0.95 graphics 2627 resize images larger/smaller with good quality
stb_rect_pack.h 0.11 graphics 624 simple 2D rectangle packer with decent quality
stb_sprintf.h 1.05 utility 1833 fast sprintf, snprintf for C/C++
stretchy_buffer.h 1.03 utility 262 typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++
stb_textedit.h 1.12 user interface 1404 guts of a text editor for games etc implementing them from scratch
stb_voxel_render.h 0.85 3D graphics 3803 Minecraft-esque voxel rendering engine with many more features
stb_dxt.h 1.08b 3D graphics 728 Fabian ryg Giesen's real-time DXT compressor
stb_perlin.h 0.3 3D graphics 316 revised Perlin noise (3D input, 1D output)
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 0.38 game dev 4172 embeddable tilemap editor
stb_herringbone_wa... 0.6 game dev 1220 herringbone Wang tile map generator
stb_c_lexer.h 0.09 parsing 962 simplify writing parsers for C-like languages
stb_divide.h 0.91 math 419 more useful 32-bit modulus e.g. euclidean divide
stb_connected_comp... 0.95 misc 1045 incrementally compute reachability on grids
stb.h 2.31 misc 14405 helper functions for C, mostly redundant in C++; basically author's personal stuff
stb_leakcheck.h 0.4 misc 186 quick-and-dirty malloc/free leak-checking

Total libraries: 20
Total lines of C code: 53654


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?


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

If people submit them, I generally add them, but the goal of stb_image is less for applications like image viewer apps (which need to support every type of image under the sun) and more for things like games which can choose what images to use, so I may decline to add them if they're too rare or if the size of implementation vs. apparent benefit is too low.

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


Why public domain?

I prefer it over GPL, LGPL, BSD, zlib, etc. for many reasons. Some of them are listed here:

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.

stb open issues Ask a question     (View All Issues)
  • almost 3 years stbi_write_bmp: support for writing 32b rgba
  • about 3 years Static analysis warnings in stb_image.h
  • about 3 years Create the first release version
  • about 3 years stb_vorbis: C undefined behaviour in ilog()
  • about 3 years stb_truetype: Ubuntu.ttf bitmap errors
  • about 3 years SIGSEGV on stb_sdict_set()
  • about 3 years stb_truetype: Can't load Inconsolata.otf
  • about 3 years Minor - possible loss of data warnings (false positives)
  • over 3 years stb_image: Incorrect number of components for PNG with tRNS chunk
  • over 3 years stb_textedit.h: override is_word_boundary
  • over 3 years stb_textedit.h crash bug in stb_textedit_discard_redo()
  • over 3 years stb_image.h: stbi__hdr_load heap overflow
  • over 3 years stb_image.h: stbi__hdr_load heap overflow
  • over 3 years stb_image.h: stbi__psd_load heap overflow
  • over 3 years stb_image.h: stbi__psd_load heap overflow
  • over 3 years stb_image.h: stbi__bmp_load heap overflow
  • over 3 years stb_image.h: stbi__compute_huffman_codes stack overflow
  • over 3 years stb_image.h: stbi__reduce_png heap overflow
  • over 3 years stb_image.h: stbi__fill_gif_background heap overflow
  • over 3 years stb_image is it thread safe?
  • over 3 years stb_leakcheck_free in stb_leakcheck.h doesn't actually free memory, bug?
  • over 3 years stb_image_write monochrome bmp support
  • over 3 years stb.h: stb_filewrite of 64MB files
  • over 3 years stb_image_write.h: Implement flipping (e.g. stbiw_set_flip_vertically_on_write)
  • over 3 years stb_perlin - interest in fractal brownian noise and/or SIMD enhancement?
  • over 3 years Optimized stb_vorbis::ilog
  • over 3 years 1/2/4-bit monochrome PNGs loading incorrectly
  • over 3 years stb_truetype: Weird kerning
  • over 3 years Note: shared libraries that use stb_image.h fail on Ubuntu 16.04 with "/usr/bin/ld: a.out: hidden symbol `__cpu_model' in /usr/lib/gcc/x86_64-linux-gnu/5/libgcc.a(cpuinfo.o) is referenced by DSO"
  • over 3 years Request: add JPEG saving to stb_image
stb open pull requests (View All Pulls)
  • stbi__bmp_load() might not return correct Channel
  • Slightly modify the public domain license
  • Added functions for iterating over the kerning values
  • Fixed typo
  • Initial 16 bit per channel PNG support
  • ttf: Correct direct use of fabs()
  • fix compile warning
  • stb_textedit: better support for keying while holding mouse drag button
  • Fix the calculation of the input image shift when using subpixel regions
  • typo in shader
  • Added a reset macro to allow the buffer to be reused
  • Fix typo in stbi__parse_uncompressed_block
  • Added PoissonGenerator.h
  • Allocate large structures on the heap, not stack
  • Fix a few warnings when building std_vorbis using Xcode 7.2.1
  • stb_vorbis: Fixed PS4/FreeBSD missing malloc.h
  • stb_textedit: Add support for custom move word left/right handlers
  • Add DG_dynarr.h to
  • Added sts_net / sts_mixer to other libraries list
  • Minor fixes.
  • stb_textedit/stb_text_locate_coord:
  • Perlin performance improvements and fractal noise
  • add jsonxx
  • Added flipping functionality for stb_image_write.h
  • updated description of yocto/GL libraries in other_libs
  • Add ccVector.h to
  • add direct links to files
  • added doctest to the list with single header libraries
  • stb.h: Fix arguments given to `swprintf` in `stb__dirtree_scandir`
  • Added Genann (neural networks)
  • Fix crash if out of memory in stb_image.h
  • image-write: fix monochrome bitmap writing from 8-bit-buffers
  • Update link for LIL
  • stb_image_resize: Fix crash when resizing large images (signed integer overflow)
  • Fix segfault on loading malformed HDR image
  • Update stb_c_lexer.h
  • add PAM reading to stb_image.h
  • Fix error on FreeBSD "#error malloc.h has been replaced by stdlib.h"
  • stb_c_lexer.h: C99 hex float literals and several fixes when not using CRT.
  • Fix GCC misleading-indentation warnings.
  • Fix several bugs.
  • Fix link to tinyobjloader-c
  • stb_vorbis: Fix handling of negative numbers in ilog.
  • Added labrat to the tests section
  • Fix duplicate symbols when lib is included statically more than once
  • stb_voxel_render: Added block_selector
  • Shouldn't this be 6?
  • Fixed 'printf' : unknown type field character
  • CFF and Type 2 charstream parsing in stb_truetype
  • stb_textedit.h: fix LINESTART when cursor is at end of buffer + simplifications/optimisations
  • Improved .HDR file compatability. Warnings fixes for VS2015
  • stb_dxt: 3Dc support
  • stretchy_buffer: Add sb_reserve feature
  • stb_image.h: large structures on the stack
  • stb_vorbis: Rename Point to stbv__point
  • Error control in stb_vorbis_open_memory.
  • allow for all 16 bits
  • stb_printf.h: Reuse code for assigning lead sign.
  • Fix the check for a percent character
  • The Si prefixes for mega, giga and tera are upper case
  • Fix "#ifndef STBI_WRITE_NO_STDIO" scope for stbi_write_hdr()
  • Return all_rects_packed status from stbrp_pack_rects.
  • Fix scope for stbi_load(), stbi_load_16() & stbi_loadf() when STBI_NO_STDIO
  • Add stbi_load_16() variants to load from callbacks or memory
  • stb_sprintf: avoid GCC 6 misleading-indentation warnings
  • Add support for BC4
  • Robustify stbi__sse2_available in stb_image.h
  • fix: Build on MinGW32
  • Fixing void * compile error for C++
  • stb_sprintf: Improve ASan workaround
  • stb_dxt: Add STB_DXT_STATIC option
  • stb_image: Fix STBI_NO_STDIO
  • stb_dxt: Add STBD_ABS, STBD_FABS and STBD_MEMSET macros
  • stb_truetype: fontdata can be const in stbtt_PackFontRange[s]()
  • stb_image_write.h: JPEG writing support based on jo_jpeg.cpp
  • Add I/O callback support to stb_vorbis
  • Fixes unpremultiply truncation bug.
  • Fix VS2015 warnings
  • Fix #430
  • Using secure CRT calls to avoid MSVC compile errors
  • stb_truetype: Silence compilation warnings of winding_lengths
  • Add functions with wchar_t to stb_image.h and stb_image_write.h
  • remove duplicated `pr = 0`
  • Feature/gif frames
  • Fix warning on unused stbi__sse2_available when skipping JPEG support.
  • Avoid warning about unused stbi__float_postprocess
  • stbi_is_16
  • stb_truetype.h: Fixes
  • Fix tests compilation
  • CFF/Type2 fixes
  • Fix implicit-fallthrough warning
  • Add a function to create a copy of a stretchy buffer
  • Use stbi__mad4sizes_valid() only if STBI_NO_LINEAR or STBI_NO_HDR are defined
  • stb_image: support for 1-bit BMP
  • place const tables to protected .rdata section
  • Remove argument from STBD_MEMSET macro
  • Fix compile errors on clang++
  • Add basic GPOS kerning
  • avoid GCC7 implicit-fallthrough warning
  • stb_image_write: allow forcing PNG filter and compression
  • Correct function signature in stbi_write_jpg usage documentation.
  • stb_sprintf.h: Don't compare uninitialized value when using zero.
  • stb_image_write.h: PNG: allow setting zlib compr. level and custom compress function
  • Disabled Clang pedantic warning (equality comparison with extraneous …
  • Fix syntactic errors when compiling stb_image_write statically
  • stb_image_write: fix png compression level typos
  • stb_image_write: Fix error when saving PNG with the stbi__flip_vertically_on_write flag on.
  • fix stb_vorbis.c
  • Perlin, added seed, fixed fractal wrapping, performance increase
  • stb_truetype: fix unused variable warning when asserts are disabled.
  • stb_dxt: fix constant color check
  • Re added unicode filename support for stb_image and stb_image_write w…
  • fixed 'unreferenced formal parameter' warnings in stb_image
  • stb_reck_pack: Removed unused assigned variables warnings
  • Misc. comment typos
  • stb_truetype: Added comment about stbtt_FindGlyphIndex() return value.
  • Fix overflow in stbi_write_hdr_core()
stb questions on Stackoverflow (View All Questions)
  • Connection between iPhone and STB (Set Top Box) Programming
  • Rendering text using bindings to STB in LWJGL 3
  • Is there any universal way to detect if android device is TV dongle or STB?
  • Format of packets of H264 video for raw\raw\udp STB
  • stb image loading library returning white textures
  • Integartion of stb tester with appium
  • Why Screen Navigation is not showing the next screen with this->show on STB
  • Create SQL query to fetch Total STB count and Total Out of sync STB Count for DVR in oms not in Enab
  • Restrict android app not to run on STB/ Android Tv
  • Couldn't load shared library 'gdx-stb-truetype' for target: Linux, 32-bit
  • Stream Video From Mobile to STB using LAN in Android application
  • How to check if Android device is an STB
  • TV and STB programming
  • How to write a C# app to change the channel on my Satellite STB via USB connected IR transmitter
  • android STB use external keyborad
  • Android/Google TV STB or multimedia centre with HLS support
  • Can you create a custom driver for STB?
stb list of languages used
More projects by nothings View all
Other projects in C