   [1]Back to Dave Coffin's Home Page

                    Raw Digital Photo Decoding in Linux

   Not affiliated with [2]Canon, [3]Nikon, [4]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 [5]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 [6]dcraw.c, and it's become a standard tool
   within and without the Open Source world. It's small (under 4000
   lines), portable (standard C libraries only), free (both "gratis"
   and "libre"), and when used skillfully, produces [7]better-quality
   output than the tools provided by the camera vendor.

   [8]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.
     * [9]dcraw.c -- Convert raw photos to PPM
       Supports 112 cameras at last count. Compile with "gcc -o dcraw
       -O3 dcraw.c -lm -ljpeg". Run with no arguments to see a usage
       message. Don't complain that 48-bpp output is too dark -- read
       the FAQ!
     * [10]rawphoto.c -- my plugin for GIMP 1.2
       [11]rawphoto.c -- my plugin for GIMP 2.0
       [12]Pawel Jochym's GIMP 2.0 plugin with live preview
       After installing "dcraw", do "gimptool --install rawphoto.c".
       Now the GIMP can load raw photos without creating a PPM file.
       For programmers, rawphoto.c shows how to create a graphical
       interface to dcraw without modifying it.
     * [13].badpixels -- my camera's "hot pixels"
       This file tells dcraw which pixels have died and when, so that
       it can interpolate around them.
     * [14]dcraw.1 -- UNIX manpage for dcraw
       Contains details and helpful hints not found elsewhere.
     * [15]dcwrap -- example wrapper script
       This is what I use with my PowerShot G2.
     * [16]dcraw.c,v -- complete unabridged RCS file
       In case you want to learn more about the history of dcraw.c.
       If you don't have the RCS toolkit, [17]download it here.
     * [18]parse.c -- read image data structures
       This program displays CIFF and TIFF data structures in a very
       cryptic format. It also extracts the thumbnail, if the image
       has one. Compile with "gcc parse.c".
     * [19]fixdates.c -- set time on CRW files
       Sets the time on CRW files to show when the photo was taken,
       assuming that the camera's clock was set to Universal Time.

   For hackers only:
     * [20]decompress.c is a simple reference decompressor for CRW
       files.
     * [21]pgm.c converts the decompressed data into an 8-bit
       grayscale image.
     * [22]sony_clear.c decrypts SRF files from the Sony DSC-F828.

  Commercial Software

   The following image viewers use dcraw or pieces of dcraw.c to
   decode raw digital camera images:
     * [23]Adobe Photoshop
     * [24]Bibble by Eric Hyman
     * [25]BreezeBrowser by Chris Breeze
     * [26]Conceiva Lightbox
     * [27]cPicture by Jürgen Eidt
     * [28]dcRAW-X by Bryan Chang
     * [29]dpMagic by Mikhail Stolpner
     * [30]GraphicConverter by Thorsten Lemke
     * [31]IrfanView by Irfan Skiljan
     * [32]IRIS image processor for astronomers
     * [33]Lightbox by Josh Anon
     * [34]Photo Companion by Jeff Moore
     * [35]PhotoReviewer by Ben Haller
     * [36]PolyView by Polybytes
     * [37]PowerShovel-II by Luc Minnebo
     * [38]RawDrop by Frank Siegert
     * [39]SilverFast DCPro by LaserSoft Imaging
     * [40]VueScan by Ed Hamrick

  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 [41]on his website. And Benjamin
          Lebsanft has volunteered to maintain [42]Windows executables
          optimized for specific CPUs.

          If you're familiar with the DOS command line but don't know
          C, you can install this [43]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 [44]an excellent
          utility called "jhead". For Canon CRW files, try [45]this
          tool by Sven Riedel. Also [46]Peter Galbavy's website and
          mailing list have a lot of information about CRW format.

   Do you have any specifications describing raw photo formats?
          No. If such documents exist, the camera companies keep them
          under lock and key. Dcraw.c is the best documentation you
          can get without resorting to burglary.

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

   Could you please add an option for TIFF / 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 | 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 [49]Netpbm toolkit in these examples.
          [50]ImageMagick also does command-line format conversions.
          Both are free.

   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 [51]this posting on rec.photo.digital.

   What does the "-f" option do? What's "four-color RGB"?
          If you see [52]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:

         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.

          [53]This research paper by Ting Chen compares various
          color-interpolation algorithms. Dcraw uses his favorite, the
          Variable Number of Gradients Method, with Bilinear as an
          option for quick test images.

          Other methods are described in [54]the research of Rajeev
          Ramanath and at [55]http://dsplab.ece.cornell.edu/.

          [56]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.

   Why are my Fuji images rotated 45 degrees?
          Interpolation artifacts are more noticeable along orthogonal
          edges than diagonal ones. Thus Fuji decided to rotate the
          pixel array 45 degrees, to favor orthogonal edges. You must
          rotate dcraw's output back to normal. Some detail is lost,
          but the final result shows very few artifacts.

          I recommend the following commands for best results:

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

          [57]Download the source code for "fujiturn" here.

   How do I get my camera to take raw photos?
          For some Nikon Coolpix cameras, you need to enable a
          [58]special "DIAG RAW" mode.

          For Casio cameras, see [59]Maurice Delaney's website or read
          [60]this discussion on dpreview.

          For the Minolta DiMAGE G400 and G500, [61]go here.

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

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

          + 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 S30
          + Canon PowerShot S40
          + Canon PowerShot S45
          + Canon PowerShot S50
          + Canon PowerShot Pro1
          + Canon EOS D30
          + Canon EOS D60
          + Canon EOS 10D
          + Canon EOS 300D
          + Canon EOS DIGITAL REBEL
          + Canon EOS Kiss Digital
          + Canon EOS D2000C
          + Canon EOS-1D
          + Canon EOS-1DS
          + Canon EOS-1D Mark II
          + Casio QV-2000UX
          + Casio QV-3000EX
          + Casio QV-3500EX
          + Casio QV-4000
          + Casio QV-5700
          + Casio Exlim Pro 600
          + Contax N DIGITAL
          + Creative PC-CAM 600
          + Creo Leaf Valeo 22
          + Fuji FinePix S2Pro
          + Fuji FinePix S5000
          + Fuji FinePix S7000
          + Fuji FinePix F700
          + Imacon Ixpress
          + Kodak DC20 (see [62]Oliver Hartman's page)
          + Kodak DC25 (see [63]Jun-ichiro Itoh's page)
          + Kodak DC40 (aka "Logitech Fotoman Pixtura")
          + Kodak DC50
          + Kodak DC120 (also try [64]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
          + Leica Digilux 2
          + Minolta DiMAGE 5
          + Minolta DiMAGE 7
          + Minolta DiMAGE 7i
          + Minolta DiMAGE A1
          + Minolta DiMAGE A2
          + Minolta DiMAGE G500
          + Nikon D1
          + Nikon D1H
          + Nikon D1X
          + Nikon D100
          + Nikon D2H
          + Nikon D70
          + 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 E4300 ("DIAG RAW" hack)
          + Nikon E4500 ("DIAG RAW" hack)
          + Nikon E5000
          + Nikon E5400
          + Nikon E5700
          + Nikon E8700
          + Olympus C5050Z
          + Olympus C5060WZ
          + Olympus C8080WZ
          + Olympus E-1
          + Olympus E-10
          + Olympus E-20
          + Panasonic DMC-LC1
          + Pentax *ist D
          + Pentax Optio S
          + Pentax Optio S4
          + Phase One LightPhase
          + Phase One H10
          + Phase One H20
          + Phase One H25
          + Rollei d530flex
          + Sigma SD9
          + Sigma SD10
          + Sinar 12582980-byte
          + Sony DSC-F828

  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

   [65]A detailed description of the PowerShot 600 written in 1997.

   [66]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"...

   [67]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 [68]xv-3.10a distribution. From the
   parent (not the xv-3.10a subdirectory) do:

   cat patch1 patch2 | patch -p0
     * [69]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. [70]This bug report explains the
       fix
     * [71]PostScript free() patch Prevents a segmentation fault when
       saving a color-adjusted image in PostScript format.
     * [72]JPEGlib patch Changes a couple of JPEG library defaults.
     * [73]My XV super-patch Adds PNG support, raw photo decoding,
       non-destructive deletion, simulated color-blindness, plus all
       of the above patches.
     _________________________________________________________________

Reference

   1. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/index.html
   2. http://www.canon.com/
   3. http://www.nikon.com/
   4. http://www.kodak.com/
   5. http://gphoto.sourceforge.net/
   6. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/dcraw.c
   7. http://www.insflug.org/raw/
   8. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/resume.html
   9. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/dcraw.c
  10. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/old/rawphoto.c
  11. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/rawphoto.c
  12. http://ptj.rozeta.com.pl/Soft/RawPhoto
  13. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/.badpixels
  14. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/dcraw.1
  15. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/dcwrap
  16. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/RCS/dcraw.c,v
  17. http://www.cs.purdue.edu/homes/trinkle/RCS/
  18. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/parse.c
  19. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/fixdates.c
  20. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/decompress.c
  21. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/pgm.c
  22. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/sony_clear.c
  23. http://www.adobe.com/products/photoshop/cameraraw.html
  24. http://www.bibblelabs.com/
  25. http://www.breezesys.com/
  26. http://www.conceiva.com/
  27. http://cpicture.de/en/t_raw.html
  28. http://frostyplace.com/dcraw/
  29. http://www.dpmagic.com/
  30. http://www.lemkesoft.com/
  31. http://www.irfanview.com/
  32. http://www.astrosurf.com/buil/us/iris/iris.htm
  33. http://www.lightboxsoftware.com/
  34. http://www.wildcape.com/
  35. http://www.sticksoftware.com/software/PhotoReviewer.html
  36. http://www.polybytes.com/
  37. http://lens.liteserv.com/download/powershovel2.php
  38. http://www.wizards.de/rawdrop
  39. http://www.silverfast.com/
  40. http://www.hamrick.com/
  41. http://www.insflug.org/raw/
  42. http://home.arcor.de/benjamin_lebsanft/
  43. http://www.delorie.com/djgpp/
  44. http://www.sentex.net/~mwandel/jhead/
  45. http://neuemuenze.heim1.tu-clausthal.de/~sven/crwinfo/
  46. http://www.wonderland.org/crw/
  47. http://www.adobe.com/products/photoshop/main.html
  48. http://cinepaint.sourceforge.net/
  49. http://netpbm.sourceforge.net/
  50. http://www.imagemagick.org/
  51. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/rpd_rico
  52. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/screendoor.png
  53. http://www-ise.stanford.edu/~tingchen/
  54. http://www4.ncsu.edu:8030/~rramana/research.html
  55. http://dsplab.ece.cornell.edu/
  56. http://www.dpreview.com/news/0202/02021101foveonx3.asp
  57. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/fujiturn.c
  58. http://e2500.narod.ru/raw_format_e.htm
  59. http://www.inweb.ch/foto/rawformat.html
  60. http://forums.dpreview.com/forums/read.asp?forum=1015&message=4961779
  61. http://myfototest.narod.ru/
  62. http://www.planet-interkom.de/oliver.hartmann/dc20secr.htm
  63. http://www.itojun.org/diary/19961113/index.eng.html
  64. http://kdc2tiff.sourceforge.net/
  65. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/secrets.html
  66. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/renum
  67. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/lcfile
  68. http://trilon.com/xv/index.html
  69. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/xv_smooth.patch
  70. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/xv-bug.txt
  71. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/xv_ps_save.patch
  72. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/xv_jpeg.patch
  73. file://localhost/home/sbrabec/STABLE/dcraw/www.cybercom.net/~dcoffin/dcraw/xv_png_crw.patch
