6 Replies Latest reply on Jan 14, 2009 2:10 PM by (Roger_Howard)

    extract jpeg showing all edits from DNG file

      We need to programmatically extract from a DNG file a jpeg thumbnail and a jpeg preview image of optional long dimension, usually 512 or 1024 pixels, short dimension scaled to maintain aspect ratio.

      How do we get this image from a DNG file using the DNG SDK?

      We tried using some sample source code in the SDK to write a TIFF, and then resized that to the desired JPGs but the TIFF did not have all the edits the user had performed. Specifically, the user had warmed the image considerably, but tiff definitely lacked these edits.

      The embedded jpeg preview shows the edits, and is useable for a thumbnail, but it is too small to use for the preview. When we scale it up, it softens considerably.

      Does anybody have any ideas on how to code the SDK to extract the full-size image to tiff or jpg format with all the edits? We can use Imagemagick to rescale to our desired sizes.
        • 1. Re: extract jpeg showing all edits from DNG file
          Level 1
          Look at the sample code and find the code that iterates the IFDs in the DNG.

          Look for the biggest IFD that is marked as a JPEG compressed preview image. The SDK does not include a standard JPEG compression/decompression library. You can either provide your own, decompress, and write out a JPEG using your library, OR just write out a JPEG header and then dump out the JFIF stream.

          Also, it would probably be a good idea to read through the DNG and TIFF/EP specs.

          Keep in mind that not all DNG images include big preview images: extracting a JPEG won't work for all DNG files. DNGs generated on-camera tend to have smaller preview images, or lack one altogether (except for the thumbnail). The DNG converter has a number of preview options that you should use as test cases if you are developing a general solution.

          If you are unable to write code like this, then I suggest trying out exiftool.
          • 2. Re: extract jpeg showing all edits from DNG file
            Level 1
            Is there a way of writing code to get the SDK to output a TIFF that has all the edits? We can then use ImageMagick to convert the tiff to a jpg.
            In our first attempt, using the sample code as a guide, we set up the image and then called WriteTiFF:
            writer.WriteTIFF (host, stream2, *finalImage.Get (), finalImage->Planes () >= 3 ? piRGB : piBlackIsZero,
            negative.Get (),
            &render.FinalSpace ()
            but the tiff image converted to jpeg did not seem to have all the edits applied, specifically some colour changes were missing.
            Is there a more we need to do to get the SDK to output a tiff that corresponds to the jpeg thumbnail?
            • 3. Re: extract jpeg showing all edits from DNG file
              Level 1
              Extract != Render.

              The answer is probably "no" using the SDK. I don't know how the images in the files you are working with were created, but the rendering engine in the SDK is just a reference engine. It doesn't include the algorithms and source to ACR and Photoshop. The DNG spec outlines a few rendering-related tags that can be inserted into the XMP metadata, but these won't allow you to exactly reproduce the results from Adobe's algorithms, although they may help you get closer if they are present.
              • 4. Re: extract jpeg showing all edits from DNG file
                Level 1
                Thanks for the info.
                We build digital asset management software, and one of our clients is storing photos using our software. The photos come from any number of types of camera as raw files or as DNG files; I am not sure of their workflow.
                If the file to store is a raw file, our code runs Adobe_DNG_Converter.exe to generate a DNG; we then process the DNG using DNG_SDK to get some basic info such as dimensions and then we get and store a thumbnail and a larger preview image to display on the GUI.
                This larger preview image is the sticking point. If we use the embedded preview, it is not large enough and looks blurred when it scales up to a preview size. If we use the tiff generated by the DNG_SDK, the result does not contain all the edits.
                I am not sure how we will proceed if a preview representing the current state of the image is not readily available.
                Thanks again for your help.
                • 5. Re: extract jpeg showing all edits from DNG file
                  Level 1
                  The DNG converter can produce full size previews. I haven't tried this from the command line, but it seems like you should be able to set up your settings in the UI and then run the command line.

                  Your best bet would be to get them to use full size or the medium size (since full size is now a lot bigger than most monitors) preview as part of their workflow. If they take DAM seriously, they shouldn't mind adding or changing this step to have much better previews available.
                  • 6. Re: extract jpeg showing all edits from DNG file
                    Level 1
                    Graeme - if you're using Adobe DNG Converter to generate DNGs with full-size previews, these previews (which are JPEGs and can be easily extracted with exiftool or otherwise) will reflect the latest edits the user made.

                    If the embedded preview after the RAW->DNG conversion is *not* reflecting the users latest edits, then two things come to mind:

                    1. the RAW file you fed to DNG converter was not edited in an Adobe product, in which case the edits won't translate and be recognized by the DNG Converter
                    2. if the RAW file *was* edited in an Adobe product prior to passing to DNG Converter, then perhaps the .xmp sidecar file has been lost - this is where the edits are stored prior to DNG conversion.

                    If the problem is that edits to the DNG (after your conversion) are not being reflected in the DNG's embedded preview, then most likely the users editor (Adobe Camera RAW or Lightroom) is not configured to always update the embedded preview when edits are made - this is off by default as it does slow down the editing process.

                    Assuming your customer has an all-Adobe workflow for their RAW files, then I'd suggest:

                    1. Make sure you preserve the .xmp sidecar files during upload (prior to DNG Conversion), as these are where all edit instructions are stored.
                    2. Once your users have a DNG, then make sure their ACR or Lightroom are configured to always update the preview *or* make sure they have a procedure in place to manually update the preview when they are ready.

                    The other option I can think of is to pass even DNGs back through the DNG Converter whenever you can - you can use DNG Converter (I believe) to update previews so they reflect the most recent edits.

                    As others have said, the DNG SDK does *not* provide all of the image rendering capabilities of DNG Converter, ACR, or Lightroom, so it is not possible to *generate* an accurate preview using the DNG SDK alone.