Package: tinydng
Tiny DNG Loader and Writer libraryHeader-only simple&limited DNG(Digital NeGative, TIFF format + extension) loader and writer in C++11.Currently TinyDNG only supports lossless RAW DNG and limited lossless JPEG DNG(no lossy compression support).TinyDNG can also be used as an TIFF RGB image loader(8bit, 16bit and 32bit are supported).TinyDNG loader module is being fuzz tested using LLVMFuzzer, and is enoughly secure(and no C++ exception and assert/abort code exists).(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)FeaturesLoadingRAW DNG dataLossless JPEGLossless JPEG decoding is supported based on liblj92 lib:https://bitbucket.org/baldand/mlrawviewer.gitZIP-compressed DNGUse miniz or zlibJPEGSupport JPEG image(e.g. thumbnail) throughstb_image.h.TIFF8bit uncompressed8bit LZW compressed(no preditor, horizontal diff predictor)ExperimentalApple ProRAW(Lossless JPEG 12bit)Lossless JPEG 12bitSemantic map(8bit Standard JPEG)Decode Canon RAW(CR2)RAWmRAWsRAWDecode Nikon RAW(NEF)TODOReading custom TIFF tags.Read DNG data from memory.WritingDNG and TIFFLosslessJPEG compressionSupported DNG filesHere is the list of supported DNG files.Sigma sd Quattro HUncompressed RGB 12bit image.iPhone DNGApple ProRAWLossless JPEG 12bitSemantic mapBlack magic DNGCinemaDNG(lossy compression) isnot supported.Canon CR2(experimental)Since CR2 format is also based on TIFF format :http://lclevy.free.fr/cr2/RAW only(mRAW and sRAW are not supported)Magic lantern DNGUncompressedlossless JPEG(http://www.magiclantern.fm/forum/index.php?topic=18443.0)8-bit TIFF imageLZW compressed 8-bit image.16-bit uncompressed TIFF image32-bit uncompressed TIFF imageOpCodeListGainMapUsageLoading DNG#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"intmain(intargc,char**argv){std::stringinput_filename="colorchart.dng";if(argc>1){input_filename=std::string(argv[1]);}std::stringwarn,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.boolret=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_ti=0;i<images.size();i++){consttinydng::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;}}returnEXIT_SUCCESS;}Writing DNG(and TIFF)Seeexamples/dngwriterandhttps://github.com/storyboardcreativity/zraw-decoderfor more details.#include<cassert>#include<cstdio>#include<cstdlib>#include<iostream>#define TINY_DNG_WRITER_IMPLEMENTATION#include"tiny_dng_writer.h"staticvoidCreateRGBImage(tinydngwriter::DNGImage*dng_image,constunsignedshortbasecol){unsignedintimage_width=512;unsignedintimage_height=512;dng_image->SetSubfileType(false,false,false);dng_image->SetImageWidth(image_width);dng_image->SetImageLength(image_height);dng_image->SetRowsPerStrip(image_height);// SetSamplesPerPixel must be called before SetBitsPerSample()dng_image->SetSamplesPerPixel(3);uint16_tbps[3]={16,16,16};dng_image->SetBitsPerSample(3,bps);dng_image->SetPlanarConfig(tinydngwriter::PLANARCONFIG_CONTIG);dng_image->SetCompression(tinydngwriter::COMPRESSION_NONE);dng_image->SetPhotometric(tinydngwriter::PHOTOMETRIC_RGB);dng_image->SetXResolution(1.0);dng_image->SetYResolution(1.2);// fractioal testdng_image->SetResolutionUnit(tinydngwriter::RESUNIT_NONE);dng_image->SetImageDescription("bora");std::vector<unsignedshort>buf;buf.resize(image_width*image_height*3);for(size_ty=0;y<image_height;y++){for(size_tx=0;x<image_width;x++){buf[3*(y*image_width+x)+0]=static_cast<unsignedshort>(x%512);buf[3*(y*image_width+x)+1]=static_cast<unsignedshort>(y%512);buf[3*(y*image_width+x)+2]=basecol;}}dng_image->SetImageData(reinterpret_cast<unsignedchar*>(buf.data()),buf.size()*sizeof(unsignedshort));}intmain(intargc,char**argv){std::stringoutput_filename="output.dng";if(argc<1){std::cout<<argv[0]<<" <output.dng>"<<std::endl;}if(argc>1){output_filename=std::string(argv[1]);}// TinyDNGWriter supports both BigEndian and LittleEndian TIFF.// Default = BigEndian.boolbig_endian=false;if(argc>2){big_endian=bool(atoi(argv[2]));}{// DNGWriter supports multiple DNG images.// First create DNG image data, then pass it to DNGWriter with AddImage API.tinydngwriter::DNGImagedng_image0;dng_image0.SetBigEndian(big_endian);tinydngwriter::DNGImagedng_image1;dng_image1.SetBigEndian(big_endian);CreateRGBImage(&dng_image0,12000);CreateRGBImage(&dng_image1,42000);tinydngwriter::DNGWriterdng_writer(big_endian);boolret=dng_writer.AddImage(&dng_image0);assert(ret);ret=dng_writer.AddImage(&dng_image1);assert(ret);std::stringerr;ret=dng_writer.WriteToFile(output_filename.c_str(),&err);if(!err.empty()){std::cerr<<err;}if(!ret){returnEXIT_FAILURE;}std::cout<<"Wrote : "<<output_filename<<std::endl;}returnEXIT_SUCCESS;}CustomizationsTINY_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_LOADER_DEBUG: Enable debug printf(developer only!)TINY_DNG_LOADER_NO_STB_IMAGE_INCLUDE: Do not includestb_image.hinside oftiny_dng_loader.h.TINY_DNG_LOADER_NO_STDIO: Disable printf, cout/cerr.Examplesexamples/custom_fieldsWrite a DNG with custom TIFF field.examples/viewerSimple viewer example with simple debayering.examples/tiff_viewerSimple TIFF viewer example(assume TIFF RGB image stored in DNG).examples/fptiff2exr32bit float(SAMPLEFORMAT_IEEEFP) grayscale or RGB image to EXR converter.examples/dng2exrSimple DNG to OpenEXR converter.examples/dngwriterSimple DNG writer example.https://github.com/storyboardcreativity/zraw-decoderPython binding(Experimental)$ python -m pip install tinydngWindows(including ARM), Linux(including aarch64) and macOS are supported.Seeexperimental/pythonfor exsample python code.Command line tools(Experimental)When TinyDNG is installed from pip, CLI commandtinydngis available.$ tinydng input.dngFuzzing testfuzzerFuzzing test.ResourceHere is the list of great articles on how to decode RAW file and how to develop RAW image.Developing a RAW photo file 'by hand' - Part 1http://www.odelama.com/photo/Developing-a-RAW-Photo-by-hand/Developing a RAW photo file 'by hand' - Part 2http://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 Whyhttp://lclevy.free.fr/cr2/TODOMove to C++11.Drop C++03 support.Parse semantic map tags in Apple ProRAW.Add DNG header load only modeParse more DNG headersParse more custom DNG(TIFF) tagslossy DNGImprove DNG writerSupport compression(LJPEG)Support Big TIFF(4GB+)Decode Nikon RAW(NEF)Improve Canon RAW decodingOptimimze lossless JPEG decodingDelayed load of tiled image.LicenseTinyDNG 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.gitstb_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. Seeminiz.LICENSE