Back to Dechifro's Home Page

Decoding raw digital photos in Linux

Live free or die / DCRAW / New Hampshire
en Esperanto
em Português
auf Deutsch
на русском
па-беларуску

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. Almost 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, with 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 and maintain 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 (pronounced "dee-see-raw"), and it's become a standard tool within and without the Open Source world. It's small (about 10,500 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.

I can be reached by sending e-mail to dechifro dot org with the username "dechifro".

News and Interviews

Essay for Digital Outback Photo, 25 April 2003
Article in News.com, 21 April 2005
Interview with Digital Photography Review, 27 April 2005
Dcraw mentioned in Editors Guild magazine, July/August 2005
Interview with Thorsten Schnebeck, 10 June 2006
Interview with Ladinamo, 16 June 2006

My Code

Unless otherwise noted in the source code, these programs are free for all uses, although I would like to receive credit for them. Donations are welcome too, if you're making money from my code.

Note to Linux distributors: The only executable files that should be installed by a dcraw package are "dcraw", "clean_crw", and maybe "fuji_green", "fujiturn", and "fujiturn16". My shell scripts are dangerous and should only be installed in a "doc" directory without execute permission.

For hackers only:

Internationalization

To build and install multilingual dcraw in Linux, download the latest tarball from this directory and run the "install" script. The currently supported languages are Esperanto, Russian, French, Italian, German, Portuguese, Spanish, Dutch, Polish, Hungarian, Czech, Swedish, Catalan, Danish, Romanian, Japanese, and Chinese (both Traditional and Simplified).

To build a unilingual, self-contained DCRAW.EXE for DOS/Windows, use a source file from this directory instead.

To add another language, send me translations of this manpage and this message table in UTF-8 encoding. Translate only from my original English and Esperanto texts -- other languages may contain factual errors invisible to me.

Do not translate "Cannot do X" as "It is impossible to do X". Dcraw is not perfect, so if it cannot do something, that does not mean that the task is impossible. Computers must never use the pronoun "I", so write "dcraw cannot do X".

When in doubt, translate everything. I proofread these texts before releasing them, and it's much easier for me to correct over-translation than under-translation.

Dcraw decodes raw photos, not raw files. No digital camera generates raw files in normal usage, there's always a header with useful metadata. (For abnormal usage, see CHDK and DIAG RAW below)

"raw" is an English word, not an acronym or file format. "raw photo" should be translated with the same adjective that you would use for "crude oil" or "raw materials".

There are dozens of raw photo formats: CRW, CR2, MRW, NEF, RAF, etc. "RAW Format" does not exist; it is an illusion created by dcraw's ability to read all raw formats.

Other Raw Photo Decoders

Dcraw has made it far easier for developers to support a wide range of digital cameras in their applications. They can call dcraw from a graphical interface, paste pieces of dcraw.c into their code, or just use dcraw.c as the documentation that camera makers refuse to provide:

Frequently Asked Questions

I don't have a C compiler. Could you send me an executable?
Sergio Namias has built some current Windows EXE files here. Dcraw has also been ported to Amiga, MorphOS, BeOS, OS/2, and RISC OS.

Why does dcraw say "Out of memory" in Windows Vista?
Ostensibly to stop memory leaks, Microsoft decided that programs using the old MS-DOS API, including anything compiled with DJGPP, shall be confined to 32MB of memory. This limitation can be removed by some combination of service packs and registry hacks, or you can compile dcraw to use the newer Win32 API. Thomas Nicely (of Pentium FDIV fame) has a page describing the problem and various workarounds.

How can I read the EXIF data (shutter speed, aperture, etc.)?
Phil Harvey's ExifTool provides a unified Perl-based EXIF reader (and editor!) for all cameras and file formats. "dcraw -i -v" is much faster, but provides less information.

How can I read NEF files from Nikon scanners?
Dcraw only supports cameras. Try this simple program for scanners.

How can I read Nikon Dust Off images (NDF files)?
Use this program.

Do you have any specifications describing raw photo formats?
Yes, but they tend to omit important details, like how to decompress the raw image or decrypt private metadata. See the TIFF spec, the TIFF/EP spec, the Adobe DNG spec, the CIFF (CRW) spec, and the X3F spec.

Where can I get an assortment of raw photos to test my software?
For the latest cameras, I get samples from Photography Blog. A "Full Review" at Imaging Resource usually includes a few raw shots. www.rawsamples.ch is no longer updated, but it has samples from older cameras. For $800, I sell a complete test suite on six DVDs containing every camera supported by dcraw, and provide web-based updates for $300/year.

I'm designing a digital camera. How do I convert its raw photos into something that dcraw and Adobe Photoshop can open?
Download LibTIFF v3.8.2 and apply this patch. Then use this C program as a template for converting your photos to valid Adobe DNG files.

Why are dcraw output images larger than camera JPEGs?
Any algorithm that combines each pixel with its neighbors is going to have problems near the edges. C code is cheap, so dcraw applies a different algorithm to edge pixels. Hardware logic is expensive, so cameras crop off the edge pixels after processing.

I shot a raw photo with no light. Why does it appear all noisy, when it should be solid black?
No matter how dark an image is, dcraw's auto-exposure stretches it so that one percent of its pixels appear white. The "-W" option avoids this behavior.

I bracket plus/minus two stops, but all five shots look almost the same in dcraw. Why?
See the previous question.

Why is 16-bit output dark / unreadable?
If you want pretty pictures straight out of dcraw, stay with 8-bit output. 16-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.

What does the "-f" (four color RGB) option do?
If you see patterns like this or this in your output images, first try "dcraw -a". If these patterns persist, use "dcraw -f" to get rid of them.

Could you please add an option for TIFF / FITS / PNG / BMP / JPEG output?
In versions 8.25 and later, "dcraw -T" writes TIFF output with metadata. To write other formats:
dcraw -c crw_0001.crw | pnmtofits > crw_0001.fits
dcraw -c crw_0001.crw | pnmtopng > crw_0001.png
dcraw -c crw_0001.crw | ppmtobmp > crw_0001.bmp
dcraw -c crw_0001.crw | cjpeg > crw_0001.jpeg
I used the Netpbm toolkit in these examples. ImageMagick also does command-line format conversions. Both are free.

Why don't you implement dcraw as a library?
I have decided that dcraw shall be a command-line program written in C, and that any further abstraction layers must be added around this core, not inside it.

Library code is ugly because it cannot use global variables. Libraries are more difficult to modify, build, install, and test than standalone programs, and so are inappropriate for file formats that change every day.

There's a simpler way to make dcraw modular and thread-safe: Run it as a separate process. Eric Raymond explains this technique here.

Why are there false colors along edges 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.
Dcraw currently gives a choice of four methods: Bilinear, Variable Number of Gradients (VNG), Patterned Pixel Grouping (PPG), and Adaptive Homogeneity-Directed (AHD).

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. Much processing is needed to enhance color while suppressing noise.

How do I get my camera to take raw photos?
For Canon PowerShots that don't output CRW or CR2, you need the CHDK hack.
For some Nikon Coolpix cameras, you need to enable a special "DIAG RAW" mode.
For Casio cameras, see Maurice Delaney's website or read this discussion on dpreview.
For the Minolta DiMAGE G400, G500, G530, or G600, go here (in Russian) or here (in English).
For the Minolta DiMAGE Z2 and Nikon Coolpix 2100/3100/3700, go here.
For SMaL cameras, see the camerahacking Forum.
For Agfa and Samsung cameras, go here.

For other cameras, refer to the User's Manual.

Does dcraw work with my camera?
Most likely, yes. If your camera is not on the Supported list, try dcraw anyway. If it doesn't work perfectly, don't just sit quietly waiting for my next version. Ask me if I need any raw photos, or go ahead and post a photo to your website and e-mail me the URL. If you don't have a website, use YouSendIt, RapidShare, Sendshack, ShareFile, sendspace, or Megaupload.

Before choosing a photo to send, read the next question:

Why does dcraw output have a green tint and weak color?
Because dcraw doesn't have a color matrix for your camera model, it outputs raw color instead of sRGB. To fix this, I need a photo of a Wolf Faust, ColorChecker, CMP, or other calibrated color chart. Follow this checklist:

Supported Cameras