Compiling and using dcraw for Mac OS X users

A new camera almost always means a new RAW format and the wait begins until the various RAW converters get updated. I came across a forum post about a preliminary dcraw version that supports the Fuji X100 RAW format.


I never heard of dcraw before and learned that its a command line utility written in the C language by David Coffin. The authors intention is to provide a tool for RAW file conversion that is still usable even when current operating systems have disappeared.

David Coffin publishes the entire C source code of dcraw and anyone who knows how to compile it can make the tool run on his computer system. I also found several links to already compiled dcraw versions but I use a Mac and found only outdated OS X versions. Therefore I decided to try it myself. Fortunately it is not that difficult.

Compiling and using command line tools seems to be such a basic everyday stuff for programmers that there's almost no information on how to actually do it. Even more so for Mac OS X. But don't fret what follows is a detailed step by step guide on compiling and basic use of dcraw for OS X users. No one should be afraid of compiling dcraw.

Compiling dcraw for Mac OS X

The source code can be found at David Coffin's website Look for the dcraw.c link.

Select the entire code and copy it to the clipboard.

Open TextEdit and switch it to plain Text using
Format > Make Plain Text.

Paste the dcraw source code into the TextEdit Window and save it as dcraw.c in a folder named dcraw on the desktop.

Open Terminal.app which can be found in Applications/Utilities.

To change to the dcraw folder on the desktop type
cd desktop/dcraw followed by Return.

OS X is based on UNIX and comes with the free Gnu C Compiler (gcc).
Copy the next line and paste it into the Terminal window
gcc -o dcraw -O4 dcraw.c -lm -DNO_JPEG -DNO_LCMS

Hit Return to compile the dcraw.c file
Ignore the warning. The computer thinks for a moment and then the compiled dcraw file can be found in the dcraw folder on the desktop.


Now execute
open $home/bin
and move the just compiled dcraw file into the bin folder. You have to authenticate this step with your administrator password. Copying the dcraw file to the usually invisible bin folder insures that OS X can find the new dcraw executable from anywhere in the system.

Here's a screenshot of all the terminal action so far


Using dcraw with OS X Terminal.app

Copy a RAW photo into the dcraw folder on the desktop.


dcraw only needs the file name for a basic RAW conversion. The command line
dcraw rawfile.rw2
results in a rawfile.ppm file that can be opened in Photoshop. PPM stands for Portable Pixel Map and is an open source image format.

The RAW conversion process can be controlled by a dash followed by letters or letters and numbers.

dcraw
Executing dcraw without anything else displays a list of all available options.
Those control options have to be placed between the dcraw command and the file name.

dcraw -i -v rawfile.rw2
Identifies the file and shows the Metadata.


dcraw -T rawfile.rw2
Produces a TIFF file.


dcraw -a -T rawfile.rw2
Produces a TIFF file with auto white balance.


dcraw -a -b 5.0 -T rawfile.rw2
Produces a TIFF file with brightness 5.0 instead of 1.0


dcraw -a -T -6 rawfile.rw2
Produces a 16 bit TIFF file with auto white balance.

This should give you enough knowledge to start experimenting with dcraw. A more detailed UNIX manpage for dcraw can be found on David Coffin's website. You should also have some basic understanding about the data in a RAW file. Have fun.
I'm a big fan of such tools and I'm happy to now have dcraw in my toolbox.