1 person found this helpful
Well, you can directly manipulate the stage 1 image if you want. In that case I'd look at the CornerFix source code. But that's complicated.
An easier route if you're just creating a DNG file rather than manipulating existing data would be to (a) create a dng_host, (b) create a dng_memory_stream with your data, (c) create a dng_image with (d) its associated ifd, then (e) read the memory stream into the ifd using ifd.ReadImage.
Following is the code I put together based on Sandy's comments. I'm a bit sketchy on most of it, but it 'almost' compiles. I'm a bit stuck with the raw_ifd part - I don't think I'm getting the idea about the dng_image. I'm also unclear about defining the thumbnail - blank is fine with me.
dng_error_code dng_createsim (const char *filename)
int sz=10; // size of image
dng_memory_block * mem_block = host.Allocate(sz*sz);
for (int i=0;i<sz;i++)
for (int j=0;j<sz;j++)
In general, the process is to create the IFD, read the data into the image via the IFD, then assign the image as the Stage 1 image of a negative. Then after you have gone through the process of building a stage 2 and stage 3 image, you have a DNG image (in the shape of the dng_negative). Usually you build the thumbnail by rendering the negative image via a dng_render object to a dng_image_preview, which is then passed to dng_image_writer.WriteDNG which it includes it into the dng file. A DNG isn't valid without a thumbnail.
There aren't that many sample programs out there.
Take a look at elphel_dng.c from Dave Coffin. It uses libTIFF.
On the CinemaDNG prerelease forum, there is raw2dng sample code, also using LibTIFF.
one can extract the image buffer from dng_negative *negative..
// Returns the raw image data.
const dng_image & RawImage () const
From another post on this forum, the raw data can be extracted.
it's done with a dng_const_tile_buffer, where you give the dng_image as parameter in its constructur, and then you can get the pixels with dng_const_tile_buffer::ConstPixel.
The ifd header can be created separately.
However, how does one force dng_host to use a certain compression method ? dng_host does not seem to deal with compression flags internally.