RAW file processor



Refinery reads RAW photograph files as input and provides usable RGB (or other format) data, which is suitable for combining with other imaging libraries.


  1. Download the source: git clone git://
  2. Install CMake and Boost: sudo apt-get install libboost-dev cmake
  3. Change into the source directory and type cmake -D CMAKE_BUILD_TYPE=Release .
  4. make (to change options, install and run ccmake).
  5. sudo make install

This will install headers, a shared library, and the raw2ppm program.

If you also have SWIG 2.0 and Python development headers installed, then Python bindings will be built and installed. With these, you can combine refinery with the Python Imaging Library (PIL) for image-processing power.

You may also install Exiv2 and run cmake with -D LICENCE_GPL=ON to compile Exiv2 support. Where the built-in DcrawExifData doesn't work, Exiv2 might.


This is a library, not a program. You can use -I/path/to/refinery and -lrefinery to compile programs.

One program, raw2ppm, accompanies this code. Call it with raw2ppm [RAWFILE] outfile.ppm. It converts a RAW file to a PPM and is intended as an example, not an everyday tool. You can link refinery with other libraries (such as a JPEG-writing one) to create more powerful tools.


Use -I/path/to/refinery and -lrefinery to compile programs. You can include <refinery/refinery.h> for some basic tools, or just include the particular files you need.

Use util/ as an example. There's also util/licensed/gpl/ which shows how to use Python to extend classes and take advantage of PIL.

Raw decoding entails a series of steps; here's a typical chain:

  1. Unpack the Exif data (use DcrawExifData or Exiv2ExifData).
  2. Unpack the raw data (use ImageReader). Unless you're using a Foveon camera, you now have a grayscale Image.
  3. Scale it to fill its data-type (for instance, scaling 12-bit to 16-bit) (use ScaleColorsFilter).
  4. Interpolate the missing colors (use Interpolator). Now you have multi-color Image.
  5. Convert from the camera colorspace to sRGB (use ConvertToRgbFilter).
  6. Gamma-correct the image (use Histogram, GammaCurve and GammaFilter).
  7. Flip and rotate the image if needed (nothing in refinery for this right now).
  8. Save the image (use ImageWriter).

Depending on your intents, you might want to add more steps. That's okay, since the image data is easy to copy from Image::pixels().


This code is public domain, except for anything that links to Exiv2, which is GPL.

 All Classes Functions Variables Typedefs Enumerations Enumerator