Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

tinydng

> 编程语言
Open source

Header-only Tiny DNG/TIFF loader and writer in C++

185 stars0 likes4 views
WebsiteGitHub

About

Header-only Tiny DNG/TIFF loader and writer in C++

Tiny DNG Loader and Writer library

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)

Features

Loading

  • 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)

    • Composite image decode through the normal tinydng_decode_* APIs
    • Layers, layer channels, masks, blend modes, groups and tagged blocks
    • RAW, RLE(PackBits), ZIP and ZIP-with-prediction channel data
    • 1, 8, 16 and 32 bit depths
    • Image resources and JPEG thumbnail resources
    • Embedded smart objects (PSD/PSB/TIFF/DNG/JPEG/PNG payloads)
  • Region 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

    • Apple ProRAW (Lossless JPEG 12bit)
      • Lossless JPEG 12bit
      • Semantic map (8bit Standard JPEG)
    • Decode Canon RAW (CR2)
      • RAW
      • mRAW
      • sRAW
    • DNG quick header check (tinydng_is_dng / tinydng_is_dng_memory)

Writing

  • DNG and TIFF
    • Single-strip or tiled output
    • Lossless JPEG, LZW, PackBits compression
    • Streaming writer (writes tile/strip payloads incrementally)
  • PSD / PSB
    • Composite image + layers
    • RAW or RLE(PackBits) output
    • 8, 16 and 32 bit depths
    • Optional ICC profile resource

Supported DNG files

  • Sigma sd Quattro H (uncompressed RGB 12bit)
  • iPhone DNG
  • Apple ProRAW (Lossless JPEG 12bit + Semantic map)
  • Black magic DNG (CinemaDNG lossy compression is not supported)
  • Canon CR2 (experimental, RAW only)
  • Magic lantern DNG (uncompressed + lossless JPEG)
  • 8-bit TIFF (LZW compressed)
  • 16-bit uncompressed TIFF
  • 32-bit uncompressed TIFF
  • OpCodeList GainMap

Build

bash
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).

Compile-time options

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

Usage

Quick format check

c
#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;
}

Loading DNG

…

Decoding pixels

c
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);
}

Writing DNG

…

Writing PSD/PSB

c
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);
}

WebAssembly demo

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:

bash
emcmake cmake -S web -B web/build -DCMAKE_BUILD_TYPE=Release
cmake --build web/build
python3 -m http.server 8000

Open .

Testing

bash
cd build && cmake .. && make -j$(nproc)
ctest

Test 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

Fuzzing

  • fuzzer - LLVM libFuzzer harnesses for v3.

Deprecated APIs

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.

Examples

See examples/ for remaining examples. The deprecated v1 C++ examples have been moved to attic/examples/.

Python binding (Experimental)

Python bindings exist but currently use the deprecated v1 API. Contributions to port them to v3 are welcome.

$ python -m pip install tinydng

Resource

  • Developing a RAW photo file 'by hand' - Part 1 http://www.odelama.com/photo/Developing-a-RAW-Photo-by-hand/
  • Developing a RAW photo file 'by hand' - Part 2 http://www.odelama.com/photo/Developing-a-RAW-Photo-by-hand/Developing-a-RAW-Photo-by-hand_Part-2/
  • Understanding What is stored in a Canon RAW .CR2 file, How and Why http://lclevy.free.fr/cr2/

License

TinyDNG is licensed under MIT license.

TinyDNG uses the following third party libraries.

  • liblj92(Lossless JPEG library) : (c) Andrew Baldwin 2014. MIT license. https://bitbucket.org/baldand/mlrawviewer.git
  • stb_image : Public domain image loader.
  • miniz : Copyright 2013-2014 RAD Game Tools and Valve Software. Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC MIT license. See miniz.LICENSE

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言