Back to Dave Coffin's Home Page

Raw Digital Photo Decoding in Linux

Not affiliated with Canon, Nikon, Kodak, or any other company named herein.

Welcome! If you are wondering how to connect your digital camera and download images to a Linux PC, go to the gPhoto homepage. My software is for processing those images after downloading them.

If you're downloading JPEG files, you don't need my software at all. The image has already been processed inside the camera. All digital cameras made since 1997 produce JPEG images, so why would you want to do it any other way?

Well, despite the convenience and ubiquity of JPEG, there are some disadvantages. JPEG is a lossy format -- to fit a big image into a small file, a lot of information is thrown away. That's why midrange and high-end digital cameras offer an alternative: Raw, unprocessed CCD data files, for which the camera manufacturer provides special decoding software.

Of course this software is for Windows and Macintosh only, and there's no source code. So it's useless to users of other operating systems, programmers hoping to design a better interpolation algorithm, and historians not yet born in an era when the only Windows machines will be in museums.

So here is my mission: Write an ANSI C program that decodes any raw image from any digital camera on any computer running any operating system.

That program is called dcraw.c, and it's become a standard tool within and without the Open Source world. It's small (about 3000 lines), portable (standard C libraries only), free (both "gratis" and "libre"), and when used skillfully, produces better-quality output than the tools provided by the camera vendor.

Here's my resume. I do freelance consulting related to dcraw, and I'm also available for full-time work in BIOS engineering or UNIX system administration.

I can be reached by sending e-mail to cybercom dot net with the username "dcoffin".

Free Software

There are no restrictions on this code, although I would like to receive credit for it. Donations are welcome, especially if you're using my code commercially.

Commercial Software

The following image viewers use dcraw or pieces of dcraw.c to decode raw digital camera images:

Frequently Asked Questions

I don't have a C compiler. Could you send me an executable?
No, but Francisco Montilla provides up-to-date Mac OS and Windows executables on his website

If you're familiar with the DOS command line but don't know C, you can install this free C compiler for Windows and compile dcraw.c quite easily.

How can I read the EXIF data (shutter speed, aperture, etc.)?
For JPEG files, Matthias Wandel wrote an excellent utility called "jhead". For Canon CRW files, try this tool by Sven Riedel. Also Peter Galbavy's website and mailing list have a lot of information about CRW format.

Why is 48-bit output dark, flattened, or unreadable?
If you want pretty pictures straight out of dcraw, stay with 24-bit output. 48-bit linear output is the best raw material for professional image editors such as PhotoShop and CinePaint, but it's no good for most image viewers.

Could you write the output in my favorite image format?
I chose PPM for its simplicity and wide support among image viewers. There are hundreds of other tools for manipulating and converting images, so that dcraw doesn't have to do everything.

Why don't your images look the same as Canon's?
Such differences nearly always relate to brightness, gamma, and white balance, which can all be set on the command line. See this posting on rec.photo.digital.

Why are my Fuji images rotated 45 degrees?
Because the filter array on the "Fuji Super CCD" chip is turned that way. Fuji claims that this increases the resolution, so I suppose that the resolution of any non-Fuji camera can be increased by tilting it 45 degrees!

Anyway, I recommend the following commands for best results:

dcraw -c dscf0000.raf | fujiturn | pnmscale 0.70710678 > dscf0000.ppm

Download the source code for "fujiturn" here.

Why are there false colors along boundaries within the image?
Because of interpolation. This is a hard problem, easily defined:
  1. Take a three-color RGB image. At each pixel, set two color values to zero.
  2. Reconstruct the original three-color image as best you can from the remaining one color per pixel.
This research paper by Ting Chen provides a thorough critique of various color-interpolation algorithms available today. Raw Photo Decoder 4.0 uses the Variable Number Gradients Method. Earlier versions used bilinear interpolation with hue-smoothing.

Other methods are described in the research of Rajeev Ramanath

The Foveon X3 Capture chip requires a different kind of interpolation. Unlike CCD arrays, it captures three colors at every pixel location. But the colors are not well separated, so the raw data looks very gray. Enhancing the color without also enhancing noise is very difficult.

Does dcraw work with my camera?
Most likely, yes. The following cameras are supported:

History

It started in February 1997, when I bought a Canon PowerShot 600. Decoding the raw data was more difficult than I had expected, knowing nothing about filter arrays, colorspace conversion, etc. But in August 1997, I found a decent interpolation technique, and finally was able to create images comparable in quality to Canon's.

Word slowly spread, and people asked me to do other cameras, sending me sample images to decode. I added support for the PowerShot A5 in May 1999 and the PowerShot A50 and Pro70 in May 2000.

In late September 2001, after months of effort, I finally figured out the lossless compression algorithm used by the PowerShots Pro90, G1, G2, S30, S40, and EOS D30/D60 cameras.

I solved the Canon EOS-1D on Jan 28, 2002 and the Nikon compressed NEF format on March 24, 2002. Olympus ORF format is not compressed, so it's much easier to decode.

On November 19, 2002, I was laid off. During that month, I added nineteen Kodak cameras, the PowerShot G3/S45, the Canon EOS-1DS, the Fuji S2, and the Minolta DiMAGE 7. In early December, I replaced the whole color-interpolation system, yielding sharper images for all cameras.

On December 10, I attacked the Sigma SD9. I solved the compression algorithm on December 31, then spent another six weeks constructing a Foveon-specific interpolation routine to enhance color and reduce noise.

Misc. Stuff

A detailed description of the PowerShot 600 written in 1997.

renum A bash script to rename all files in the current directory, numbered by date of last modification. For example,

	renum rover 56

will rename the files to "rover-0056.jpg", "rover-0057.jpg", "rover-0058.jpg"...

lcfile A Python script to rename files and directories to lowercase.

Patches for XV 3.10a

XV is still my favorite image viewer, even though its last official release was in 1994. In case you're still using this antique, here are some useful patches for it:

To install them, unpack the xv-3.10a distribution. From the parent (not the xv-3.10a subdirectory) do:

cat patch1 patch2 | patch -p0