Gamma curve and increasing the exposure

I am really stumped on this problem, and couldn't find the answer anywhere.

After I manually process the raw stuff, I am getting nice colors and everything. I apply a gamma curve of 2.2 and all is fine. I build and store my gamma curve in an array with this function (it's just a hack):

//gamma is a double of 2.2
    for(i=0;i<65535;i++)
    {
        double i_double=i;
 
        resulting_gamma=pow(i_double/(double)channels_max,1.0f/gamma);
        color_curve[i]=resulting_gamma*255;
    }

Channels max is the maximum color of any channel.
This function works well, as it places all the values of any given sRGB in a 0 to 1f range.

The problem is when I want the increase the exposure, and I multiply all the pixels (just after the WB step) with a certain value. While the pixels will have a new value, they will still be in the same range of 0-1f like before, and nothing will change. So I guess that instead of using channels_max I should use something else. But to what value should I change it, if not to the max value?

I could also apply the exposure AFTER the gamma curve, but then I guess some of the details might be lost? In all the places where I read it, the exposure compensation should be done before the gamma curve.

Thanks for reading!

Forums: 

I think I sort of got it to work

Well, after some tests and thinking, it downed to me that I should just adjust the gamma curve, there is no point in multiplying everything with a constant multiplyer.

So my function is now like this, and it works (but not exactly how it does in RawTherapee)

void do_color_curve()
{
    int i;
    double resulting_gamma;
    double max_color=original_exposure_max_channels*(1.0f/exposure);
 
    for(i=0;i<65535;i++)
    {
        double i_double=i;
 
        resulting_gamma=pow(i_double/(double)max_color,1.0f/gamma);
        if(resulting_gamma>1)resulting_gamma=1;
        color_curve[i]=resulting_gamma*255;
    }
}

Yes, this will effectively

Yes, this will effectively map [0...max_value/exposure] to full output range.

-- Alex Tutubalin @LibRaw LLC