richgel999/fpng logo

richgel999/fpng

Free

Super fast C++ .PNG writer/reader

FreeFree tier
Type
Open Source
Company
richgel999

About richgel999/fpng

fpng is a high-performance C++ library for reading and writing PNG images, specifically optimized for 24-bit (RGB) and 32-bit (RGBA) images. It is a single source file with no external dependencies, making it easy to integrate into any C++ project. The encoder uses Length-Limited Prefix Codes to achieve compression speeds 12-19x faster than stb_image_write.h while producing files 5-11% smaller on average. The decoder is 2.5-3x faster than stb_image.h and libpng when reading fpng-compressed PNGs. The library is fully compliant with the PNG standard and has been validated against libpng, wuffs, lodepng, stb_image, and pngcheck. It supports both 1-pass (fastest) and 2-pass (better compression) encoding modes. fpng is open source under an MIT-like license and can be built with Visual Studio or CMake on Windows, Linux, and macOS.

Key Features

Extremely fast PNG compression (12-19x faster than stb_image_write.h) with good compression ratios
High-speed PNG decompression (2.5-3x faster than stb_image.h) on fpng-compressed files
Single C++ source file with zero external dependencies
Full PNG standard compliance; validated with libpng, wuffs, lodepng, stb_image, pngcheck
Supports 1-pass and 2-pass encoding modes for speed vs. compression trade-off
Optimized decoder exploiting Length-Limited Prefix Codes
Cross-platform build support via CMake and Visual Studio SLN

Pros & Cons

Pros
  • Exceptional compression and decompression speed compared to popular libraries
  • Single-file, dependency-free integration
  • Open source and freely available
  • Produces standard PNG files readable by any PNG decoder
  • Actively maintained with benchmarks demonstrating clear performance advantages
Cons
  • Compression ratio typically lower than lodepng and libpng (less compact files)
  • Only supports 24/32bpp images; no grayscale, 8-bit palette, or other color types
  • Benchmarks primarily on x86/x64 with SSE optimizations; performance on other architectures may vary
  • Small community compared to larger libraries like libpng

Best For

Real-time or high-throughput PNG saving in games and graphics applicationsTexture compression pipelines where fast encode/decode is criticalEmbedded or resource-constrained environments needing a lightweight PNG libraryBulk image conversion tools requiring high performanceApplications that read PNGs written by fpng for maximum decoding speed

FAQ

What image formats does fpng support?
fpng supports 24-bit (RGB) and 32-bit (RGBA) PNG images. It does not support grayscale, indexed color, or other color types.
How does fpng compare to other PNG libraries?
fpng is 12-19x faster at compression than stb_image_write.h and ~23x faster than libpng, with slightly smaller file sizes. Decompression is 2.5-3x faster than stb_image.h and libpng on fpng-compressed images, and about 10% faster than Wuffs.
Is fpng compatible with existing PNG decoders?
Yes, files written by fpng conform to the PNG standard and can be read by libpng, wuffs, lodepng, stb_image, pngcheck, and any other standard PNG decoder.
What platforms and compilers are supported?
fpng can be built with Visual Studio 2019/2022 on Windows and with CMake on Linux, macOS, and other Unix-like systems. SSE optimizations are available on x86/x64.