Header-only Tiny DNG/TIFF loader and writer in C++
Pure C11 DNG/TIFF/PSD loader and writer. Single public header (tinydng.h).
TinyDNG supports lossless RAW DNG, lossless JPEG, ZIP/Deflate, LZW, PackBits compression, tiled and multi-strip layouts, multi-threaded decode, PSD/PSB composite and layer decode, and streaming write to file or memory.
TinyDNG can also be used as a TIFF RGB image loader (8, 16 and 32 bit).
(NOTE: TinyDNG just loads DNG data as is, thus you'll need your own RAW processing code(e.g. debayer) to get a developed image as shown the above)
RAW DNG data
Lossless JPEG (streaming decode, no full-segment materialization)
Baseline/progressive JPEG (via stb_image)
ZIP-compressed DNG (via vendored miniz)
LZW compressed TIFF
PackBits compressed TIFF
PSD / PSB (Adobe Photoshop)
tinydng_decode_* APIsRegion decode (decode only a sub-region of an image)
Multi-threaded segment decode (POSIX / Win32 threads)
Custom TIFF field extraction
EXIF, CFA pattern, raw metadata, gainmaps, opcodes
Read from file, memory buffer, or memory-mapped I/O
BigTIFF (64-bit offsets)
Experimental
tinydng_is_dng / tinydng_is_dng_memory)mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)This builds the tinydng static library and test executables. No external
dependencies beyond a C11 compiler and pthreads (optional).
Define these to customize the build:
| Macro | Effect |
|---|---|
TINYDNG_NO_ZIP |
Compile out ZIP/Deflate support |
TINYDNG_NO_BASELINE_JPEG |
Compile out baseline/progressive JPEG support |
TINYDNG_NO_PSD |
Compile out PSD/PSB support |
TINYDNG_DISABLE_THREADS |
Build without multi-threaded decode |
#include "tinydng.h"
int main(void) {
tinydng_error err;
if (tinydng_is_dng("photo.dng", &err) == TINYDNG_OK) {
printf("valid DNG/TIFF\n");
}
return 0;
}…tinydng_pixels px;
tinydng_error derr;
if (tinydng_decode_image(ctx, doc, 0, NULL, &px, &derr) == TINYDNG_OK) {
/* px.data contains decoded pixels; px.width, px.height, px.samples_per_pixel,
px.bits_per_sample describe the buffer. */
tinydng_pixels_free(ctx, &px);
}…tinydng_psd_write_doc doc;
tinydng_psd_write_options opts;
memset(&doc, 0, sizeof(doc));
doc.width = width;
doc.height = height;
doc.depth = 16;
doc.color_mode = TINYDNG_PSD_RGB;
doc.channel_count = 3;
doc.composite = rgb16_interleaved;
doc.composite_size = (size_t)width * height * 3 * 2;
memset(&opts, 0, sizeof(opts));
opts.compression = TINYDNG_PSD_COMP_RLE;
if (tinydng_psd_write_file(ctx, "out.psd", &doc, &opts, &err) != TINYDNG_OK) {
fprintf(stderr, "%s\n", err.message);
}The maintained browser build lives in web. It uses the v3 pure C API to decode DNG/TIFF files in WebAssembly and includes a metadata/raw-development demo with a WebGL2 tiled GPU path. Build it with an Emscripten environment:
emcmake cmake -S web -B web/build -DCMAKE_BUILD_TYPE=Release
cmake --build web/build
python3 -m http.server 8000Open .
cd build && cmake .. && make -j$(nproc)
ctestTest executables:
| Target | Description |
|---|---|
test_dng_v3 |
Smoke test (load + decode a DNG file) |
test_v3_roundtrip |
Write + re-read round-trip |
test_v3_decode |
Decode parity across formats |
test_v3_metadata |
Metadata parsing (EXIF, CFA, raw info, gainmaps) |
test_v3_security |
Fuzz-derived regression tests |
test_v3_mt |
Multi-threaded decode determinism |
test_v3_psd |
PSD/PSB writer-reader round trips |
test_v3_streamwrite |
Streaming tiled writer |
The v1 C++ API (tiny_dng_loader.h, tiny_dng_writer.h) and the v2 C API
(tiny_dng_v2.h) are deprecated and have been moved to attic/. The v3 pure
C11 API in tinydng.h is the supported version. The lossless JPEG codec
(tiny_dng_ljpeg92_v2.h/c) is still used internally by v3 and is not
deprecated.
See examples/ for remaining examples. The deprecated v1 C++ examples
have been moved to attic/examples/.
Python bindings exist but currently use the deprecated v1 API. Contributions to port them to v3 are welcome.
$ python -m pip install tinydngTinyDNG is licensed under MIT license.
TinyDNG uses the following third party libraries.
miniz.LICENSENo open issues yet, or sync has not completed.