This is a comparison between libspng and the reference implementation libpng.

Additionally stb_image and lodepng are also compared in terms of features and performance.

Lines of code

libspng is 2.8 kLOC while libpng is ~10 kLOC without the encoder or 18 kLOC in total.


libspng does not have a configuration header, you only have to include spng.c/spng.h in your project.


The API is a lot simpler, decoding a PNG file takes 6 function calls, there are no row pointers or callback functions involved.

Error handling

All functions return zero on success and non-zero on error. libpng uses setjmp() for error handling, this makes it difficult to use from other languages such as C++.


libspng has a clear way to request a specific output format, with libpng the output format depends on whether you set alpha filler bits, it also has weird defaults such as not converting 16-bit PNG's to host endianness unless png_set_swap() is called.


Feature libspng libpng stb_image lodepng
Decode to RGBA8/16
Decode from stream
Gamma correction
Fuzzed by OSS-Fuzz[1]
Progressive read WIP
Doesn't require zlib
Encoding WIP
Animated PNG WIP [2]
Apple CgBI
  1. OSS-Fuzz improves code reliability with continuous, large-scale fuzz testing.

  2. Third-party patch is available.


Decode time on x86 (lower is better)

results matching ""

    No results matching ""