Skip to content

vmaxer/tinypng

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tinypng

tinypng is a tiny, header-only PNG writer in a single tinypng.h file, written in C23.

It has no dependencies: no libpng and no zlib. Image data is emitted as DEFLATE "stored" (uncompressed) blocks wrapped in a zlib stream, so the output is a valid, standard PNG that any image viewer can open. The required CRC-32 and Adler-32 checks are computed inline.

The resulting files are larger than compressed PNGs, but the code is small and easy to drop into any project.

Usage

Include the header anywhere for the declaration. In exactly one translation unit, define TINYPNG_IMPLEMENTATION before the include:

#define TINYPNG_IMPLEMENTATION
#include "tinypng.h"

bool write_png(FILE *fp, const uint32_t *pixels, uint32_t width, uint32_t height);

Pixels are 32-bit RGBA in memory order (byte 0 = R, byte 1 = G, byte 2 = B, byte 3 = A). write_png returns true on success.

Example

main.c writes a 64x64 RGBA gradient to output.png:

gcc -std=c23 -Wall -Wextra -O2 -o tinypng main.c
./tinypng

Requirements

  • A C compiler that supports C23.

General info

  • License: The Unlicense (public domain). See the LICENSE file.
  • Version: 1.0.0

About

Header-only, dependency-free PNG writer (C23)

Topics

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors