Support reading the gamma table
This calculates the brightness, contrast, and gamma values from the gamma table returned from SANE.
The code/math was derived from the code for generating the gamma table.
It approximates the values rather well (graph below)
Importantly, this fixes Skanpage Bug 461120 (caused by no default values here)
Though, a minimal bugfix is this: bugfix.patch
Bug comment
The bug was also experienced by me, when using the SANE epson2 backend (sane-airscan has no gamma option and thus works fine), if skanpage has no saved options the scanner works fine, but when saving options, the brightness, contrast, and gamma values that are saved are invalid (looking at the code, they are never set to any defaults!). When restarting skanpage, the gamma table is generated from the invalid values.Testing details
I wrote this to test the calculations: testingCode.patch
And graphed the results with
for file in *.dat; do gnuplot -p -e "set title '$file'; set xrange [0:255]; set yrange [0:255]; plot '$file' using 1:2 with lines title 'Old', '$file' using 1:3 with lines title 'New'"; done
The calculated brightness and contrast withing ±2 when gamma is below 200, at 300 the worst example I tested is 6. The gamma also has error when it is high (±18 at 200, ±26 at 300).
The results are (I think) good enough since the are only calculated when
- There are no set defaults
- The gamma table changes by itself
Normally a value is set, and when re-reading the option, the table doesn't change, so no recalculations.