Gamma correction in Libraw

For the life of me, I cannot clarify my mind about how gamma correction/expansion is managed in libraw/dcraw and in general in a color management chain. Or maybe, I have an idea that has to be confirmed/rejected.

I assume human eyes introduce a gamma compression of about 0.45 and that this is canceled out by the viewer who observe an lcd screen with the same law.

When a raw file is opened everything is linear. DcRaw by default seems to gamma compress by 0.45 only if the output file is going to be saved in 8 bit format. If the 16 bit option is given than the file is no gamma corrected.

I don't understand where inverse gamma is applied, to return in a linear realm ( the gamma monitor should be canceled out by the profiling software).

What puzzles me is that taking the raw values (in linear realm, no call of gamma_curve()) and putting them on the screen using the wxwidgets graphic library, the result is too dark indicating that somewhere the library compensates with a 2.2 gamma ... but there 's no evidence of that in the documentation!

My take is that every graphic viewer/library always inserts a 2.2 gamma expansion when dealing with 8 bit files. if the file is 16 bit encoded then the viewer should not include gamma correction.... but the embedded profile seems to include a 2.2 gamma coefficent.... how is this dealt?

Then there is another "unclear" point: in convert_to_rgb() I see another call to gamma_curve(). I don't understand what it does and, speaking of this method, it is unclear how it works : Mode=2 seems to be the normal mode which gamma expands/contracts the curve[] table. But what about mode 0 and mode 1?

Thank you very much for your help!!



The data values in image[]

The data values in image[] (and raw_image) array are in linear space

The gamma correction applied only on output (dcraw_make_mem_image(), dcraw_ppm_tiff_writer() calls)
convert_to_rgb() only fills the curve[] with gamma_curve() call and rgb maximum calculated on convert-to-rgb stage.

If you need linear output in dcraw_make_mem_image()/ppm_tiff_writer, set output_params.gamm[0] and [1] to 1.0

-- Alex Tutubalin

Please think of this: the

Please think of this: the scene you are shooting linear. Monitor gamma is applied for inverse companding of the image that has a high gamma. The resulting image on the monitor after inverse companding is close to linear, just as it is in the real world.

Iliah Borg