finds.dev← search

// the find

miloyip/svpng

★ 766 · C++ · BSD-3-Clause · updated Jan 2022

Minimalistic C function for saving RGB/RGBA image as uncompressed PNG.

A single 32-line C function that writes RGB or RGBA pixel data to an uncompressed PNG file. No dependencies, just drop `svpng.inc` into your project and call one function. Useful for debugging renderers, raytracer output, or any C/C++ code that needs to dump image data without pulling in libpng.

The implementation is genuinely small — 32 lines of ANSI C that correctly handle PNG chunk structure, Adler-32 checksums, and the zlib/deflate framing without compression. The macro customization points (SVPNG_OUTPUT, SVPNG_PUT) are a clean way to redirect output to a vector or ostream without changing the core logic. From Milo Yip, who wrote RapidJSON and has a track record of writing correct, readable C. The header-only include pattern makes integration a two-line affair.

Uncompressed PNG means files can be 5-10x larger than what libpng would produce — fine for debug dumps, wrong for anything shipping to users. No error handling: if fputc fails mid-write you get a silently corrupt file. Abandoned since 2022 with no 16-bit, grayscale, or indexed color support, so the scope ceiling is low. The width limit (<16383) is undocumented in the header and will silently produce a malformed PNG if exceeded.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →