simple, easy to read, minimal and portable library to decode Canon RAW 2 files
Python Shell Batchfile
Latest commit e6233b0 Feb 16, 2017 @lclevy T7i, 77D and M6
T7i, 77D and M6
Permalink
Failed to load latest commit information.
docs
python unknown tags script Jul 8, 2016
.depend
.gitattributes DNG info script and output Nov 23, 2014
.gitignore
FILES.txt
cr2_database.sh
dng_info.sh DNG info script and output Nov 23, 2014
libcraw2.svg python stuff and camera updates Jul 7, 2016
readme.md
unknow_tags.sh
winsdk.bat cr2_database with 7D2 samples Nov 8, 2014

readme.md

The CRaw2 framework

A C and Python framework for Canon Raw v2 hacking

version 0.7, dec 2014

Origin

Because I was curious about how my holidays pictures are written to the memory card by my Canon camera, I started to write the Canon Raw v2 specification, based on others' work.

But is was not enough to 'open' this proprietary format, the next obvious step is to write code that can be used by others to play with CR2 file content. Python is easy to write and elegant to read, and C is efficient, let's use the best mix of them!

Design

The CRaw2 framework is composed of 3 parts: the libcraw2 library written in C, craw2tool a CLI tool and PyCRaw2 a Python extension.

Libcraw2 has two kind of interfaces:

  • an C API, mainly used by crawtool, to offer CR2 data handling in a Camera agnostic way
  • an Python extension, PyCraw2 a simpler API which goal is to offer all required functions to render RAW data into a 16bits RGB image, either from RAW (RGGB) or sraw/mraw (YCbCr) data.

Features

Using craw2tool or PyCraw2:

  • Access to TIFF tags, in a generic way to handle unknown tags
  • Jpeg lossless decompression and re-compression* of main image
  • Access to low level jpeg properties (bits depth, wide, high, components number, HSF, VSF, slices)
  • Unslicing and re-slicing*
  • RGGB and YCbCr data statistics
  • Automatic computation of RGGB top/left and bottom/right borders (before interpolation)
  • YCbCr data can be exported and imported in packed form (4:2:2 or 4:1:1 subsamping) or interpolated (4:4:4)
  • 16 bits TIFF export for RGGB data
  • 16 bits TIFF export and import for YCbCr data (unofficial TIFF extension, I know)

*not from PyCraw2, only libcraw2 API

In few words: educational, camera agnostic and lossless access to RGGB and YCbCr data

Using PyCraw2, we have additionallly:

  • Access to 'As Shot' white balance ratios
  • Naive interpolation (you can add better methods)
  • YCbCr data to RGB conversion

95% of camera specific values are outside of the code, in dng_info.txt. Only two libcraw2 functions are camera specific.

As a summary, the PyCRaw2 goal is to allow RAW to RGB rendering using only Python and NumPy.

What CRaw2 is not

  • a user friendly RAW to Jpeg rendering tool: use the excellent DCraw or Camera Raw. CRaw2 is limited to Canon CR2 files.
  • a tool to display or hack TIFF tags: use the standard ExifTool. But CRaw2 can be used to analyze unknow TIFF tags.

Bonus

  • cr2_database.txt, camera specific Jpeg properties, autogenerated and as CSV format
  • dng_info.txt, camera specific RGB rendering values, autogenerated, from DNG converted pictures
  • an experimental Python tool to render RGGB and YCbCr pictures to RGB (aka PyCRaw2 demo).
  • Python only code tool to extract Thumbnails pictures of CR2 files (thumbails.py) or get TIFF tags content
  • 2 PDF posters: to visually explain the CR2 file format, and Jpeg lossless decompression / unslicing

Availability

  • compiled for Windows 7 x64, Linux x64
  • for Python 2.7
  • as code source

CRaw2 is written by Laurent Clévy (@lorenzo2472) and released under GPLv2 license