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. 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.c,
and it's become a standard tool within and without the
Open Source world. It's small (about 6000 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".
My Code
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.
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.
-
dcraw.c -- decodes raw photos, extracts
thumbnails, and displays metadata
Supports 202 cameras at last count.
Compile with "gcc -o dcraw -O4 dcraw.c -lm -ljpeg -llcms"
or "gcc -o dcraw -O4 dcraw.c -lm -DNO_JPEG -DNO_LCMS".
Run with no arguments to see a usage message.
Don't complain that 16-bit output is too dark -- read the FAQ!
-
rawphoto.c -- basic plugin for GIMP 1.2 & 2.0
After installing "dcraw",
do "gimptool --install rawphoto.c".
My plugin provides a simple dialog box for loading raw
files into the Gimp.
Pawel Jochym
,
Udi Fuchs
, and
Joseph Heled
have written much nicer plugins, with live preview, histograms,
and color curves.
-
.badpixels -- my camera's "hot pixels"
This file tells dcraw which pixels have died and when,
so that it can interpolate around them.
-
dcraw.1 -- UNIX manpage for dcraw
Contains details and helpful hints not found elsewhere.
-
dcwrap -- example wrapper script
This is what I use with my PowerShot G2.
-
dcraw.c,v -- complete unabridged RCS file
This file contains the entire history of dcraw.c since its
conception on February 23, 1997. If you don't have the RCS toolkit,
download it here.
-
parse.c -- read image data structures
This program displays CIFF and TIFF data structures in a very
cryptic format.
-
clean_crw.c -- clean Canon CRW files
Recovered or undeleted CRW files often have junk appended
to them that makes them unreadable. This program safely cleans
CRW files.
-
fixdates.c -- set time on Canon CRW files
This program has been superseded by "dcraw -z".
-
fujiturn.c -- rotate Fuji Super CCD images
An alternative to dcraw's built-in Fuji rotation.
-
fuji_green.c -- convert Fuji green pixels to PGM
A side benefit of the Fuji Super CCD design is that its green
pixels make nice black-and-white images.
For hackers only:
- decompress.c
is a simple reference decompressor for CRW files.
- pgm.c
converts the decompressed data into an 8-bit grayscale image.
- sony_clear.c
decrypts SRF files from the Sony DSC-F828.
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?
- No, but Francisco Montilla provides Mac OS and Windows executables
on his website.
And Benjamin Lebsanft has volunteered to maintain
Windows executables optimized for specific CPUs.
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.)?
-
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.
- 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.
- Why is 16-bit output dark / flattened / 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.
- Could you please add an option for TIFF / FITS / PNG / BMP / JPEG output?
- No. Dcraw writes PPM only. To convert to other formats:
dcraw -c crw_0001.crw | pnmtotiff -truecolor > crw_0001.tiff
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.
- What does the "-f" option do? What's "four-color RGB"?
- If you see patterns like this
in your output images, use the "-f" option. Otherwise, don't.
- Why are there false colors along edges 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.
Dcraw currently gives a choice of three methods: Bilinear, Variable
Number of Gradients (VNG), 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 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, 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 other cameras, refer to the User's Manual.
- Does dcraw work with my camera?
- Most likely, yes. The cameras listed below are supported.
If your camera is not on the list, try dcraw anyway. If it
doesn't work, post a raw image to a website and e-mail me the
URL. If you don't have a website, use
Dropload or
YouSendIt.
Ideally, your sample image should show a standard white card
or color chart in direct sunlight, with other colors in the
background.
- Adobe Digital Negative (DNG)
- AVT F-145C
- AVT F-201C
- AVT F-510C
- AVT F-810C
- Canon PowerShot 600
- Canon PowerShot A5
- Canon PowerShot A5 Zoom
- Canon PowerShot A50
- Canon PowerShot Pro70
- Canon PowerShot Pro90 IS
- Canon PowerShot G1
- Canon PowerShot G2
- Canon PowerShot G3
- Canon PowerShot G5
- Canon PowerShot G6
- Canon PowerShot S30
- Canon PowerShot S40
- Canon PowerShot S45
- Canon PowerShot S50
- Canon PowerShot S60
- Canon PowerShot S70
- Canon PowerShot Pro1
- Canon EOS D30
- Canon EOS D60
- Canon EOS 5D
- Canon EOS 10D
- Canon EOS 20D
- Canon EOS 300D
- Canon EOS 350D
- Canon EOS Digital Rebel
- Canon EOS Digital Rebel XT
- Canon EOS Kiss Digital
- Canon EOS D2000C
- Canon EOS-1D
- Canon EOS-1DS
- Canon EOS-1D Mark II
- Canon EOS-1D Mark II N
- Canon EOS-1Ds Mark II
- Casio QV-2000UX
- Casio QV-3000EX
- Casio QV-3500EX
- Casio QV-4000
- Casio QV-5700
- Casio QV-R51
- Casio QV-R61
- Casio EX-S100
- Casio EX-Z50
- Casio EX-Z55
- Casio Exlim Pro 505
- Casio Exlim Pro 600
- Casio Exlim Pro 700
- Contax N Digital
- Creative PC-CAM 600
- Epson R-D1
- Foculus 531C
- Fuji FinePix E550
- Fuji FinePix F700
- Fuji FinePix F710
- Fuji FinePix F800
- Fuji FinePix F810
- Fuji FinePix S2Pro
- Fuji FinePix S3Pro
- Fuji FinePix S20Pro
- Fuji FinePix S5000
- Fuji FinePix S5100/S5500
- Fuji FinePix S5200
- Fuji FinePix S7000
- Fuji FinePix S9000/S9500
- Imacon Ixpress 16-megapixel
- Imacon Ixpress 22-megapixel
- ISG 2020x1520
- Kodak DC20 (see Oliver Hartman's page)
- Kodak DC25 (see Jun-ichiro Itoh's page)
- Kodak DC40
- Kodak DC50
- Kodak DC120 (also try kdc2tiff)
- Kodak DCS315C
- Kodak DCS330C
- Kodak DCS420
- Kodak DCS460
- Kodak DCS460A
- Kodak DCS520C
- Kodak DCS560C
- Kodak DCS620C
- Kodak DCS620X
- Kodak DCS660C
- Kodak DCS660M
- Kodak DCS720X
- Kodak DCS760C
- Kodak DCS760M
- Kodak EOSDCS1
- Kodak EOSDCS3B
- Kodak NC2000F
- Kodak ProBack
- Kodak PB645C
- Kodak PB645H
- Kodak PB645M
- Kodak DCS Pro 14n
- Kodak DCS Pro 14nx
- Kodak DCS Pro SLR/c
- Kodak DCS Pro SLR/n
- Kodak P850
- Kodak P880
- Kodak KAI-0340
- Konica KD-400Z
- Konica KD-510Z
- Leaf Aptus 17
- Leaf Valeo 11
- Leaf Valeo 22
- Leaf Volare
- Leica Digilux 2
- Logitech Fotoman Pixtura
- Minolta RD175
- Minolta DiMAGE 5
- Minolta DiMAGE 7
- Minolta DiMAGE 7i
- Minolta DiMAGE 7Hi
- Minolta DiMAGE A1
- Minolta DiMAGE A2
- Minolta DiMAGE A200
- Minolta DiMAGE G400
- Minolta DiMAGE G500
- Minolta DiMAGE G600
- Minolta DiMAGE Z2
- Minolta Alpha/Dynax/Maxxum 5D
- Minolta Alpha/Dynax/Maxxum 7D
- Nikon D1
- Nikon D1H
- Nikon D1X
- Nikon D100
- Nikon D2H
- Nikon D2Hs
- Nikon D2X
- Nikon D200
- Nikon D50
- Nikon D70
- Nikon D70s
- Nikon E700 ("DIAG RAW" hack)
- Nikon E800 ("DIAG RAW" hack)
- Nikon E880 ("DIAG RAW" hack)
- Nikon E900 ("DIAG RAW" hack)
- Nikon E950 ("DIAG RAW" hack)
- Nikon E990 ("DIAG RAW" hack)
- Nikon E995 ("DIAG RAW" hack)
- Nikon E2100 ("DIAG RAW" hack)
- Nikon E2500 ("DIAG RAW" hack)
- Nikon E3700 ("DIAG RAW" hack)
- Nikon E4300 ("DIAG RAW" hack)
- Nikon E4500 ("DIAG RAW" hack)
- Nikon E5000
- Nikon E5400
- Nikon E5700
- Nikon E8400
- Nikon E8700
- Nikon E8800
- Olympus C3030Z
- Olympus C5050Z
- Olympus C5060WZ
- Olympus C7070WZ
- Olympus C70Z,C7000Z
- Olympus C740UZ
- Olympus C770UZ
- Olympus C8080WZ
- Olympus E-1
- Olympus E-10
- Olympus E-20
- Olympus E-300
- Olympus E-500
- Olympus SP500UZ
- Panasonic DMC-FZ30
- Panasonic DMC-LC1
- Panasonic DMC-LX1
- Pentax *ist D
- Pentax *ist DL
- Pentax *ist DS
- Pentax Optio S
- Pentax Optio S4
- Pentax Optio 33WR
- Phase One LightPhase
- Phase One H 10
- Phase One H 20
- Phase One H 25
- Phase One P 20
- Phase One P 25
- Phase One P 30
- Phase One P 45
- Pixelink A782
- Polaroid x530
- Rollei d530flex
- RoverShot 3320af
- Sarnoff 4096x5440
- Sigma SD9
- Sigma SD10
- Sinar 3072x2048
- Sinar STI format
- SMaL Ultra-Pocket 3
- SMaL Ultra-Pocket 4
- SMaL Ultra-Pocket 5
- Sony DSC-F828
- Sony DSC-R1
- Sony DSC-V3
- STV680 VGA
Patches
These are patches for software that is either no longer maintained,
or maintained by authors who don't like my patches.
-
Super-patch for John Bradley's
XV image viewer
-
Provides a better Smooth24() function,
prevents segfaults when saving a color-adjusted image in PostScript
format, and adds PNG support, raw photo decoding, non-destructive
deletion, and simulated color-blindness.
-
Byte order patch for the
coreutils
"od" command
-
"od" cannot display multi-byte integers or floats correctly if
they are stored in the opposite byte order of your CPU. With
this patch, "od -I" is little-endian on all CPUs and "od -M"
is big-endian everywhere.
-
Off-by-one patch for the
coreutils
"tail" command
-
"tail -n +3" skips the first two lines of input, and "tail -c +2k"
skips the first 2047 bytes. This patch adds a "-z" option telling
"tail" to skip the exact number of lines or bytes specified.
-
Acceleration patch for the
FlightGear flight simulator
-
Time acceleration makes long simulated flights less tedious.
Without this patch, FlightGear doesn't speed up the clock to
match the accelerated aircraft, causing some instruments to
malfunction, and allowing small planes to outrace the sun.