title: Extracted thumbnail from DNG image using DCRaw
body: <p>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.</p>
  
  <p>I took a photo with my Camera and the preview looks like this:
  <img src="https://i.stack.imgur.com/gpNdZ.jpg" alt="enter image description here"></p>
  
  <p>Here is how I call DCRAW:</p>
  
  <pre><code> 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);
  </code></pre>
  
  <p>The result ppm file looks like this:
  <img src="https://i.stack.imgur.com/jmDok.jpg" alt="enter image description here"></p>
  
  <p>I tried inverting the thumbnail using this code:</p>
  
  <pre><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;
  }
  </code></pre>
  
  <p>This gave me the thumbnail like so:</p>
  
  <p><img src="https://i.stack.imgur.com/AN85e.jpg" alt="enter image description here"></p>
  
  <p>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.</p>
  
  <p>How can I invert the thumbnail generated by DCRaw to give the correct colors much like the first image.</p>
  
  <p>Note: my camera is a Lumia 1020 with DNG output.</p>
  
  <p>EDIT: The original DNG file can be downloaded from <a href="http://1drv.ms/1Pi3b2c" rel="nofollow noreferrer">Here</a></p>