5 Replies Latest reply on Mar 22, 2014 6:58 PM by zcream

    Newbie - getting started



      Hopefully someone can help me here.  I'm looking to place either simulated or camera raw output (and here I mean a matrix of 8 or 10 bit values without debayering) into a RAW format so that I can experiment with the debayering, white balance, colour profiles, linearization or LUTs that I need to shift my camera output into a useable image.  I was thinking about using the Adobe DNG format - but I'm struggling to understand where to start with this.


      What I'd like to do to start with is simply create a DNG file with, say, a 10x10 image size, 8 bit data with a ramp profile: e.g.

      0 20 40 60 80 100 120 140 160 180

      0 20 40 60 80 100 120 140 160 180




      0 20 40 60 80 100 120 140 160 180


      I've been looking at using the dng_validate example and creating a new function:




      dng_error_code dng_createsim (const char *filenameOut)






      After several attempts at this, I've sort of guessed that I need to access the data buffer in negative->Stage1Image(), but I've not succeeded in this.


      Thanks for any help.



        • 1. Re: Newbie - getting started
          sandy_mc Level 3

          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.





          1 person found this helpful
          • 2. Re: Newbie - getting started
            simonprince Level 1

            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_allocator alloc(gDefaultDNGMemoryAllocator);

            dng_host host;

            dng_memory_block * mem_block = host.Allocate(sz*sz);


            dng_memory_stream mem_stream(alloc);



            for (int i=0;i<sz;i++)


              for (int j=0;j<sz;j++)




            //dng_rect rect(sz,sz);


            dng_image Rimage();

            dng_ifd rawifd;


            dng_negative *negative=host.Make_dng_negative();

            dng_image_preview thumbnail;


            dng_file_stream streamout(


            dng_image_writer writer;



            return dng_error_none;


            • 3. Re: Newbie - getting started
              sandy_mc Level 3



              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.



              • 4. Re: Newbie - getting started
                Lars Borg

                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.

                • 5. Re: Newbie - getting started

                  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.