I've been experimenting with using the get_histo_range(from,to) function to set exposure in a time lapse script. The main problem I'm having is the resolution of the histogram. The function returns the percent of the total samples in the range instead of just the total samples. The offending instruction is the last line in shot_histogram.c
return (rng*100)/tot;
It should just be
return rng;
You could then remove the "tot" variable completely, which makes the routine more efficient
You can get the total (tot) easily in Lua with:
tot=get_histo_range(0,1023)
Of course, this will break all current scripts that use get_histo_range. Considering the improvement, I think that it would be worth it. Old scripts could be modified to take advantage of the increased resolution, or be changed to:
x=(get_histo_range(from,to)*100)/get_histo_range(0,1023)
If you want to avoid breaking old scripts, one way would be to test for "histo_to" less than zero as a flag to return rng instead of return rng*100/tot. Here's what could be done without breaking old scripts, but my vote is for just changing to : return rng
int shot_histogram_get_range(int histo_from, int histo_to)
// Examines the histogram, and returns the percentage of pixels that
// have luminance between histo_from and histo_to
{
int x, tot, rng ;
tot=0;
rng=0;
//New Code 1
int frng;
frng=histo_to; //<0 flags full rng return
if(histo_to<0)
{
histo_to=-histo_to;
}
//End New Code 1
if(!shot_histogram_isenabled()) // TODO we could return an error somehow
return 0;
for (x = 0 ; x < SHOT_HISTOGRAM_SAMPLES; x ++ )
{
tot += shot_histogram[x];
if (x>=histo_from && x <= histo_to)
{
rng += shot_histogram[x];
}
}
//New Code 2
if(frng<0)
{
return rng;
}
//End New Code 2
return (rng*100)/tot;
}