Skip to content

Support reading the gamma table

John Doe requested to merge vicsanrope/ksanecore:master into master

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

  1. There are no set defaults
  2. 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.

Worst looking example I found example

Edited by John Doe

Merge request reports