skip to main content

dcraw C Code, Outlined and Annotated, except the outline and annotations have been moved to a separate, non-indexed page to accommodate a bit of Google insanity

Understanding what the dcraw C code does will give you a better understanding of raw processing, and might even open a door to making better pictures.

Written around 2010. Minor Update in March 2015.

Why on earth would you want to read an article on dcraw C code?

Maybe you want to make your own modifications to the dcraw source code. If you've never looked at the code, an outline gives you a head start.

But what if you are code- and command-line-phobic ? I'm no coding guru. If the things I learned modifying the dcraw C code weren't incredibly interesting (at least to me, maybe to you, too), I would have given up long before I ever made my first successful code compilation.

If you are completely code-phobic, then skip over the C code and just read the annotations. You spend a lot of time in your digital darkroom rendering raw files — wouldn't you like to know what's going on under the hood?

Some highlights to entice you to dive in:

Other dcraw resources

This article assumes that you already know what dcraw is and how to use it. If not, the very best explanation of how to use dcraw to develop your raw images is Guillermo Luijk's DCRAW TUTORIAL.

An excellent set of articles on the whys and wherefores of dcraw can be found on Dave Coffin's dcraw website, Decoding raw digital photos in Linux. And see the dcraw manpage for how to use the dcraw command line options.

The single best explanation of the inner workings of dcraw code that I could find is lclevy's "Understanding What is stored in a Canon RAW .CR2 file, How and Why" (much of what the article discusses is relevant to all camera raw files, not just Canon raw files). I've noted in the documentation below places where I drew heavily upon lclevy's hints about how dcraw works.

This article provides an annotated outline of the overall flow and functions of the dcraw C code sections. I don't explain things like dcraw's extensive use of arrays and pointers or C code bit math. Nor do I explain how to set up a development environment for compiling C code into an executable.

Annotated dcraw C Code A word about Google, or why the rest of this page has been moved to a non-indexed part of my website

Google is the tail that wags the dog, the "dog" being the internet, of course.

When Google first made its appearance as a boolean search engine, I loved it. Over time, Google has monetized itself. No surprise — if it's free, you are the product.

Google used to serve up user search histories as a product to be sold to advertisers for money. This was expected and more or less acceptable, at least to me.

Today Google is intent on training its users to be "better products", siloing user information and search results for the benefit of paying advertisers, with no regard for user privacy. I don't want to be trained to be a better product and I do value privacy, so I opted out and closed all my Google accounts.

Before closing my accounts I used Webmaster Tools to check on what Google had to say about my Nine Degrees Below website. To my horror, I found that Google thought my website was about "col" and "row", which are two dcraw c code variables. Apparently Google counts the number of times unique words appear on a website (so much for Google's purportedly intelligent algorithms that figure out what a website is really about) and I had allowed Google to index some pages that included dcraw's c code.

I can't figure out any way to convince Google that my website is about color management rather than about "col" and "row", other than removing the dcraw c code to pages that aren't indexed. So I did. The remainder of this article has been moved to dcraw C Code, Outlined and Annotated.