A little digging around showed that Microsoft, in their wisdom, have changed the behavior of the .Net 2 Picturebox control. Previously, under both XP and Vista, if the Picturebox control came across a file that it couldn't decode, but could extract a thumbnail from, it would display the thumbnail. Entirely logical and useful behavior, and what CornerFix depended on. That has changed in Windows 7 - all you get now is that Picturebox throws an exception, and displays a little cross icon.
I posted a query on the .Net part of the MSDN forum, and of course got the helpful suggestion (from a Microsoft employee) that as this was "a Windows 7 problem", I should post on the general Windows 7 forum. Very useful. Let's do anything we can to avoid actually solving the problem.
So given that Microsoft weren't going to offer any work-around, I got to thinking about how to solve this one myself. My first thought was to generate a JPEG from the thumbnail image data in the DNG file. A bit of work showed that while that was possible, it was going to be pretty messy. However, a better thought occurred to me. A DNG file is actually just a TIFF with additional tags, and a sub-IFD structure. In fact, what a DNG consists of is a single IFD which contains the thumbnail as well as the main image in raw form as a sub-IFD. Now the thumbnail is actually a perfectly valid TIFF image, it's just tagged via the kcNewSubFileType tag as "1" to show its a thumnail. In fact, the TIFF/EP spec requires that "In TIFF/EP files, the 0th IFD should be an image that can be read by a baseline TIFF 6.0 reader." So to get a valid TIFF file, which Picturebox can display, all that's required is to extract the thumbnail in the 0th IFD, and relabel it as the main image.
So, that's what I did. Now CornerFix uses Adobe's DNG SDK, so in theory I could have used that, but a quick look showed that the SDK isn't designed to extract thumbnails. In fact, it pretty much ignores them. So I decided to code a completely separate thumbnail extractor in C++, on the basis that it would be useful as a standalone product.
Because TIFF is a complex format, it turned out to be a more complex piece of code than I'd hoped, but I got it done, and its now part of CornerFix V1.1.0.0, which shipped a few days ago.
For those interested in using it, its just a single C++ file - tiffThumb.cpp - and its associated tiffThumb.h file, with no dependencies on anything else. The API is simple - it takes a file name, and return a memory buffer with the TIFF thumbnail file in it. I've tested it on both Windows and OS X. The documentation is in the tiffThumb.h file.
The file can be downloaded as part of the CornerFix source code, here.
Add a comment