Create 16bit gamma corrected image from raw image

Hi

I'm trying to extract 16bit TIF from raw image ( gamma corrected - not linear ) and only get a very noisy / false-colored image !?
I'm certainly doing something wrong when setting up LibRaw instance...

Any hint appriciated !

Here is my pseudo code ( error handling stripped ) to extract the raw image and create a GraphicsMagick image of the created image data :

    LibRaw rawProcessor;
    rawProcessor.imgdata.params.use_camera_wb  = 1;
    rawProcessor.imgdata.params.output_tiff    = 1;
    rawProcessor.imgdata.params.output_bps     = 16;
    rawProcessor.imgdata.params.output_color   = 0; // 0 = raw
    rawProcessor.imgdata.params.gamm[0]        = 1;
    rawProcessor.imgdata.params.gamm[1]        = 1;
    rawProcessor.imgdata.params.highlight      = 0; // 0 = clip
    rawProcessor.imgdata.params.no_auto_bright = 1;
    rawProcessor.imgdata.params.user_qual      = 3; // 3 = AHD
 
    rawProcessor.open_file( inPath );
    rawProcessor.unpack();
    rawProcessor.dcraw_process();
 
    libraw_processed_image_t *image = rawProcessor.dcraw_make_mem_image(&ret);
 
    Magick::Blob blob( image->data, image->data_size );
    Magick::Image img( blob, Magick::Geometry(image->width,image->height), rawProcessor.imgdata.params.output_bps, "RGB" );
    img.magick("TIF");
    // img.gamma( 2.2 ); this does not seem to fix the problem
    img.write(outPath.toStdString().c_str());
 
    LibRaw::dcraw_clear_mem(image);
    rawProcessor.recycle();

The following results in proper looking tif image when using settings to extract 8 bit image !?

    LibRaw rawProcessor;
    rawProcessor.imgdata.params.use_camera_wb  = 1;
    rawProcessor.imgdata.params.output_tiff    = 1;
    rawProcessor.imgdata.params.output_bps     = 8;
    rawProcessor.imgdata.params.output_color   = 1; // 1 = sRGB
    rawProcessor.imgdata.params.highlight      = 0; // 0 = clip
    rawProcessor.imgdata.params.no_auto_bright = 1;
    rawProcessor.imgdata.params.user_qual      = 3; // 3 = AHD
 
    rawProcessor.open_file( inPath );
    rawProcessor.unpack();
    rawProcessor.dcraw_process();
 
    libraw_processed_image_t *image = rawProcessor.dcraw_make_mem_image(&ret);
 
    Magick::Blob blob( image->data, image->data_size );
    Magick::Image img( blob, Magick::Geometry(image->width,image->height), rawProcessor.imgdata.params.output_bps, "RGB" );
    img.magick("TIF");
    img.write(outPath.toStdString().c_str());
 
    LibRaw::dcraw_clear_mem(image);
    rawProcessor.recycle();

Forums: 

1) no_auto_bright will do not

1) no_auto_bright will do not do any auto-brigten, so for 10-bit images (for example) you'll get 0...1023 data range whilt 16-bit data range is 0..64k. Most likely you need some data scaling

2) gamm[0]=gamm[1] = 1.0 is NOT 'gamma corrected' image. It is gamma=1.0 with slope (linear part) 1.0

-- Alex Tutubalin @LibRaw LLC

But what about the totally

But what about the totally wrong colors ?
If it is just scaling, I would assume that the output which utilizes only fraction of the full data-width ( i.e. only 10 of 16 bits ) has "correct" colors but is way to dark.

My output just looks mostly like gray pixel dust with false colored spots !?
I'll try to attach a picture...

See a downscaled version of

See a downscaled version of the output here.
This used to be a picture of a beach incl. bright sun light.

You can download the RAW here

You can download the RAW here.

The output of the following command looks ok.

dcraw_emu -w -6 -T 01.cr2

Find a thumbnail of the output here

Seems like I don't use the correct options on LibRaw or GraphicsMagick is causing the problem.

dcraw_emu.exe -4 -T -w -o 0

dcraw_emu.exe -4 -T -w -o 0 looks OK too.
-4: equal to gamm[0]=gamm[1] = no_auto_bright = 1; output_bps=16
-w - use camera WB
-o 0 - RAW color

-- Alex Tutubalin @LibRaw LLC