Skip to content

Library

YadeWira edited this page Jun 13, 2026 · 2 revisions

libpackPNG

packPNG ships as a static library with a small C API, so other programs can embed the codec. Verified byte-exact on Linux and Windows.

Build

make lib       # → libpackpng.a  + packpng.h   (Linux)
make lib-win   # → libpackpng-win.a + packpng.h (Windows, mingw)

Both are self-contained fat archives (packPNG + packJPG + kanzi + preflate merged). The consumer links only system libraries.

API (packpng.h)

typedef enum {
    PACKPNG_TCIP = 0, /* default: preflate + WebP-lossless */
    PACKPNG_TVCP = 1, /* fast:    kanzi + zstd            */
    PACKPNG_TMCP = 2, /* archival: preflate + kanzi-TPAQX */
    PACKPNG_TPCL = 3  /* legacy:  preflate + LZMA2        */
} packpng_backend;

int  packpng_compress_file(const char* in_path, const char* out_path, packpng_backend backend);
int  packpng_decompress_file(const char* in_path, const char* out_dir); /* auto-detects magic */
const char* packpng_last_error(void);
const char* packpng_version(void);

Both return 0 on success, nonzero on error (message via packpng_last_error). JNG/MNG inputs ignore backend and use their format codec.

Example

#include "packpng.h"
#include <stdio.h>
int main(void) {
    if (packpng_compress_file("image.png", "image.ppg", PACKPNG_TCIP))
        { printf("error: %s\n", packpng_last_error()); return 1; }
    packpng_decompress_file("image.ppg", "out/");   /* → out/image.png, byte-exact */
    return 0;
}

Link line

# Linux
gcc app.c libpackpng.a -lzstd -llzma -lz -lpthread -ldl -lm -lstdc++ -o app

# Windows (mingw)
x86_64-w64-mingw32-gcc app.c libpackpng-win.a -L vendor/mingw-deps/lib \
    -lzstd -llzma -lz -lws2_32 -luserenv -lbcrypt -lntdll -static -lstdc++ -o app.exe

Clone this wiki locally