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 goal: Write an ANSI C program that decodes any
raw image from any digital camera on any computer running any
operating system. And give it away for free.
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.
Disassembling the Nikon Coolpix firmware, some Russian hackers
recently discovered an secret "DIAG RAW" mode that lets the
CP995, CP2500, CP4300, and CP4500 cameras save raw photos.
dcraw.c now decodes these photos.
Read their website in Russian,
or this discussion in English.
Casio digital cameras have a similar feature.
See Maurice Delaney's page for details.
Here's my resume.
No matter how my career turns out, this code remains free for
all uses:
-
Convert raw photos to PPM.
Supports 63 cameras at last count. Please don't tell me
that 48-bit output is too dark -- use 24-bit output instead.
Compile with "gcc -o dcraw -O3 dcraw.c -lm".
Run with no arguments to see a usage message.
For more detailed instructions, install
this UNIX man page.
-
Lossless JPEG Decoder
Adapted from ftp://ftp.cs.cornell.edu/pub/multimed/ljpg.tar.Z.
Required for the Canon EOS-1D and some Kodak cameras.
Untar and run "make". The resulting "dcraw"
executable decodes all camera formats.
-
GIMP plugin to load raw photos
This plugin won't work by itself -- you need to do
"gimptool --install rawphoto.c" and install
"dcraw" in your executable path.
-
Complete unabridged RCS file
In case you want to learn more about the history of dcraw.c.
-
Parse image data structures
This program displays CIFF and TIFF data structures in a very
cryptic format. For Canon images, it will also extract the JPEG
thumbnail. Compile with "gcc parse.c".
-
Decompress raw CCD data to standard output.
Simple reference decompressor for Canon images.
Here's a simple program to convert that
raw data to an 8-bit grayscale image.
Frequently Asked Questions
- I don't have a C compiler. Could you send me an executable?
- OK, but I have to charge for this service. The fee is $20
for a Linux-x86 or Solaris-SPARC binary, $35 for a Windows EXE
file, or $50 for a Windows EXE with EOS-1D support.
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.
- Why is 48-bit output dark (or unreadable)?
- Because I don't attempt to adjust the brightness.
If you have a 48-bit image viewer (like
PhotoShop 6.0 or
Film Gimp),
correcting the brightness is easy.
If you have a 24-bit image viewer
(XV,
GIMP,
and most others), you must choose 24-bit output!
- 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.c doesn't have to do everything.
- How can I read the EXIF data (exposure settings, etc.)?
- For JPEG files, Matthias Wandel wrote
an excellent utility called "jhead".
Peter Galbavy is working on an EXIF parser for CRW files.
When he has some usable code, expect to find it on
his web site and mailing list.
- 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 S2 images rotated 45 degrees?
- Because the filter array on the "Fuji Super CCD" chip is rotated
45 degrees. Rotating the image back to a normal orientation would
lose detail, so I leave it as is.
- Why are there false colors along boundaries within the image?
- Because of interpolation. This is a hard problem, easily defined:
- Take a three-color RGB image. At each pixel, set two color
values to zero.
- 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.c work with my camera?
- Most likely, yes. The following cameras are supported:
- Canon PowerShot 600
- Canon PowerShot A5
- Canon PowerShot A50
- Canon PowerShot Pro70
- Canon PowerShot Pro90 IS
- Canon PowerShot G1
- Canon PowerShot G2
- Canon PowerShot G3
- Canon PowerShot S30
- Canon PowerShot S40
- Canon PowerShot S45
- Canon PowerShot S50
- Canon EOS D30
- Canon EOS D60
- Canon EOS 10D
- Canon EOS-1D (needs ljpeg_decode)
- Canon EOS-1DS (needs ljpeg_decode)
- Canon EOS D2000C (needs ljpeg_decode)
- Nikon D1
- Nikon D1H
- Nikon D1X
- Nikon D100
- Nikon E950 ("DIAG RAW" hack)
- Nikon E990 ("DIAG RAW" hack)
- Nikon E995 ("DIAG RAW" hack)
- Nikon E2500 ("DIAG RAW" hack)
- Nikon E4300 ("DIAG RAW" hack)
- Nikon E4500 ("DIAG RAW" hack)
- Nikon E5000
- Nikon E5700
- Casio QV-3000EX
- Casio QV-3500EX
- Casio QV-4000
- Casio QV-5700
- Olympus E-10
- Olympus E-20
- Olympus C5050Z
- Minolta DiMAGE 5 (untested)
- Minolta DiMAGE 7 (untested)
- Minolta DiMAGE 7i
- Fuji FinePixS2Pro
- Kodak DCS315C
- Kodak DCS330C
- Kodak DCS420
- Kodak DCS460
- Kodak DCS460A
- Kodak EOSDCS3B
- Kodak EOSDCS1
- Kodak DCS520C (needs ljpeg_decode)
- Kodak DCS560C (needs ljpeg_decode)
- Kodak DCS620C (needs ljpeg_decode)
- Kodak DCS620X (needs ljpeg_decode)
- Kodak DCS660C (needs ljpeg_decode)
- Kodak DCS660M (needs ljpeg_decode)
- Kodak DCS720X
- Kodak DCS760C
- Kodak DCS760M
- Kodak ProBack
- Kodak PB645C
- Kodak PB645H
- Kodak PB645M
- Kodak DCS Pro 14n
- Sigma SD9
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
-
Smooth patch
Using XV to expand an image from 832x608 to 832x624 blurs it badly.
This patch does the interpolation correctly, and twice as fast.
This bug report explains the fix
-
PostScript free() patch
Prevents a segmentation fault when saving a color-adjusted image
in PostScript format.
-
JPEGlib patch
Changes a couple of JPEG library defaults.
-
My XV super-patch
Adds PNG support, raw photo decoding, non-destructive deletion,
simulated color-blindness, plus all of the above patches.
The author can be reached at
dcoffin@shore.net.