Workaround for Buggy DNG Handling in macOS

Mar 04, 2018

Yesterday I released a new version of my video post processing tool Colorcast. Among other things this new version includes support for Cinema DNG. Cinema DNG is an industry standard to store RAW video. Sometimes there are tools that convert the vendor RAW format of the camera to Cinema DNG and other times Cinema DNG is directly produced in camera, examples for this is the Blackmagic Cinema Camera lineup and the DJI X5R camera that can be mounted on a DJI Osmo or under a DJI Inspire drone.

During development of that feature, I had to deal with a number of bugs in Apple's implementation of DNG. There are configurations of DNG files that simply to not render correctly in Finder, QuickLook, Preview and even Photos. The reason for that is a lack of correctly handling those configurations in the underlying Apple API. I wasn't able to pinpoint the number of bugs exactly, but I think there are basically 2 main issues:

  1. Problem with handling bitdepths other than 14 bit RAW
  2. Problem with tiled RAW buffers

Buggy Tiling

The first problem causes 10 or 12 bit images to draw very dark. 12 bit 2 stops and 10 bit 4 stops darker as normal. The second problem just produces weird drawing issues, I can't really explain. The solution however is quite simple. You need to convert the RAW buffers to 14 bit and untile it. Sounds easier than done. You basically need to decode the whole DNG image yourself, convert the RAW buffers, convert some metadata like linearization tables and write out a new DNG image. And that is exactly what I have done. Around 2000 lines of code, just to get the images properly displayed. I hope that with macOS 10.14 Apple comes around and fixes those issues (Radars: 37538394, 31032063, 30754552).

Nevertheless, I found this conversion method so useful, I also created a small batch conversion application called DNGDoctor and put it into the Mac App Store. Check it out. And if you have a graphics application that deals with DNG images, and like to ship this fix in your app, just let me know.