/tinydngloader

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

Primary LanguageC

Tiny DNG Loader

Build Status

Header-only simple&limited DNG(Digital NeGative, TIFF format + extension) loader in C++03.

Currently TinyDNGLoader only supports lossless RAW DNG and limited lossless JPEG DNG.

TinyDNGLoader can also be used as an TIFF RGB image loader(8bit, 16bit and 32bit are supported).

(NOTE: TinyDNGLoader 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

  • RAW DNG data
  • Lossless JPEG
  • ZIP-compressed DNG
    • Use miniz or zlib
  • JPEG
    • Support JPEG image(e.g. thumbnail) through stb_image.h.
  • TIFF
    • 8bit uncompressed
    • 8bit LZW compressed(no preditor, horizontal diff predictor)
  • Experimental
    • Decode Canon RAW(CR2)
      • RAW
      • mRAW
      • sRAW
    • Decode Nikon RAW(NEF)
      • TODO
    • Reading custom TIFF tags.
  • Read DNG data from memory.

Supported DNG files

Here is the list of supported DNG files.

  • Sigma sd Quattro H
    • Uncompressed RGB 12bit image.
  • iPhone DNG
  • Black magic DNG
    • CinemaDNG(lossy compression) is not supported.
  • Canon CR2(experimental)
  • Magic lantern DNG
  • 8-bit TIFF image
    • LZW compressed 8-bit image.
  • 16-bit uncompressed TIFF image
  • 32-bit uncompressed TIFF image

Usage

#include <cstdio>
#include <cstdlib>
#include <iostream>

// Define TINY_DNG_LOADER_IMPLEMENTATION and STB_IMAGE_IMPLEMENTATION in only one *.cc
#define TINY_DNG_LOADER_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION

// Enable ZIP compression(through miniz library)
// Please don't forget copying&adding `miniz.c` and `miniz.h` to your project.
// #define TINY_DNG_LOADER_ENABLE_ZIP

// Uncomment these two lines if you want to use system provided zlib library, not miniz
// #define TINY_DNG_LOADER_USE_SYSTEM_ZLIB
// #include <zlib.h>
#include "tiny_dng_loader.h"

int main(int argc, char **argv) {
  std::string input_filename = "colorchart.dng";

  if (argc > 1) {
    input_filename = std::string(argv[1]);
  }

  std::string warn, err;
  std::vector<tinydng::DNGImage> images;

  // List of custom field infos. This is optional and can be empty.
  std::vector<tinydng::FieldInfo> custom_field_lists;

  // Loads all images(IFD) in the DNG file to `images` array.
  // You can use `LoadDNGFromMemory` API to load DNG image from a memory.
  bool ret = tinydng::LoadDNG(input_filename.c_str(), custom_field_lists, &images, &warn, &err);


  if (!warn.empty()) {
    std::cout << "Warn: " << warn << std::endl;
  }

  if (!err.empty()) {
    std::cerr << "Err: " << err << std::endl;
  }

  if (ret) {
    for (size_t i = 0; i < images.size(); i++) {
      const tinydng::DNGImage &image = images[i];
;
      std::cout << "width = " << image.width << std::endl;
      std::cout << "height = " << image.height << std::endl;
      std::cout << "bits per piexl = " << image.bits_per_sample << std::endl;
      std::cout << "bits per piexl(original) = " << image.bits_per_sample_original << std::endl;
      std::cout << "samples per pixel = " << image.samples_per_pixel << std::endl;

    }
  }

  return EXIT_SUCCESS;
}

Customizations

  • TINY_DNG_LOADER_USE_THREAD : Enable threaded loading(requires C++11)
  • TINY_DNG_LOADER_ENABLE_ZIP : Enable decoding AdobeDeflate image(Currently, tiled RGB image only).
    • TINY_DNG_LOADER_USE_SYSTEM_ZLIB : Use system's zlib library instead of miniz.
  • TINY_DNG_NO_EXCEPTION : disable C++ exception(abort the program when got an assertion)
  • TINY_DNG_LOADER_DEBUG : Enable debug printf(developer only!)

Examples

Resource

Here is the list of great articles on how to decode RAW file and how to develop RAW image.

TODO

  • Parse more DNG headers
  • Parse more custom DNG(TIFF) tags
  • lossy DNG
  • Improve DNG writer
    • Support compression
  • Support Big TIFF(4GB+)
  • Decode Nikon RAW(NEF)
  • Improve Canon RAW decoding
  • Optimimze lossless JPEG decoding
  • Delayed load of tiled image.

License

TinyDNGLoader is licensed under MIT license.

TinyDNGLoader 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.
  • lzw.hpp : Author: Guilherme R. Lampert. Public domain LZW decoder.
  • miniz : Copyright 2013-2014 RAD Game Tools and Valve Software. Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC MIT license. See miniz.LICENSE