Extracted thumbnail from DNG image using DCRaw

841 Views Asked by At

I am using DCRaw as a command line utility to extract thumbnails from DNG images. The thumbnail colors are way off and inverting them will not help.

I took a photo with my Camera and the preview looks like this: enter image description here

Here is how I call DCRAW:

 Settings oSettings = Settings.GetInstance();
 var startInfo = new ProcessStartInfo(dcRawPath)
 {
    Arguments = "-e \"" + sInputFileName + "\"",
    UseShellExecute = true,
    RedirectStandardOutput = false,
    WindowStyle = ProcessWindowStyle.Hidden,
    CreateNoWindow = true,
    WorkingDirectory = RootDirectory
 };
 var process = Process.Start(startInfo);

The result ppm file looks like this: enter image description here

I tried inverting the thumbnail using this code:

static readonly ColorMatrix _inverseColorMatrix = new ColorMatrix(new[]
{
   new float[] {-1, 0, 0, 0, 0},
   new float[] {0, -1, 0, 0, 0},
   new float[] {0, 0, -1, 0, 0},
   new float[] {0, 0, 0, 1, 0},
   new float[] {1, 1, 1, 0, 1}
});

public static Bitmap InverseImage(Bitmap source)
{
   var newBitmap = new Bitmap(source.Width, source.Height);
   using (var g = Graphics.FromImage(newBitmap))
   {
      var attributes = new ImageAttributes();
      attributes.SetColorMatrix(_inverseColorMatrix);
      g.DrawImage(source, new Rectangle(0, 0, source.Width, source.Height),
                            0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);
   }

   return newBitmap;
}

This gave me the thumbnail like so:

enter image description here

I got the same result using Photoshop which means that the code is inverting the image correctly but it seems that this is not the way to parse DNG thumbnails.

How can I invert the thumbnail generated by DCRaw to give the correct colors much like the first image.

Note: my camera is a Lumia 1020 with DNG output.

EDIT: The original DNG file can be downloaded from Here

0

There are 0 best solutions below