kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Improve gain calibration on GL843
rodzic
8d3369f68e
commit
af0f8e7e46
|
@ -3574,7 +3574,6 @@ gl843_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor
|
||||||
int total_size;
|
int total_size;
|
||||||
int i, j, channels;
|
int i, j, channels;
|
||||||
SANE_Status status = SANE_STATUS_GOOD;
|
SANE_Status status = SANE_STATUS_GOOD;
|
||||||
int max[3];
|
|
||||||
float coeff;
|
float coeff;
|
||||||
int val, lines;
|
int val, lines;
|
||||||
int resolution;
|
int resolution;
|
||||||
|
@ -3671,7 +3670,7 @@ gl843_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor
|
||||||
/* average value on each channel */
|
/* average value on each channel */
|
||||||
for (j = 0; j < channels; j++)
|
for (j = 0; j < channels; j++)
|
||||||
{
|
{
|
||||||
max[j] = 0;
|
std::vector<uint16_t> values;
|
||||||
// FIXME: start from the second line because the first line often has artifacts. Probably
|
// FIXME: start from the second line because the first line often has artifacts. Probably
|
||||||
// caused by unclean cleanup of previous scans
|
// caused by unclean cleanup of previous scans
|
||||||
for (i = pixels/4 + pixels; i < (pixels*3/4) + pixels; i++)
|
for (i = pixels/4 + pixels; i < (pixels*3/4) + pixels; i++)
|
||||||
|
@ -3695,9 +3694,16 @@ gl843_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor
|
||||||
val = line[i * channels + j];
|
val = line[i * channels + j];
|
||||||
}
|
}
|
||||||
|
|
||||||
max[j] += val;
|
values.push_back(val);
|
||||||
}
|
}
|
||||||
max[j] = max[j] / (pixels/2);
|
|
||||||
|
// pick target value at 95th percentile of all values. There may be a lot of black values
|
||||||
|
// in transparency scans for example
|
||||||
|
std::sort(values.begin(), values.end());
|
||||||
|
uint16_t target_value = values[unsigned((values.size() - 1) * 0.95)];
|
||||||
|
if (bpp == 16) {
|
||||||
|
target_value /= 256;
|
||||||
|
}
|
||||||
|
|
||||||
/* the flow of data through the frontend ADC is as follows (see e.g. VM8192 datasheet)
|
/* the flow of data through the frontend ADC is as follows (see e.g. VM8192 datasheet)
|
||||||
input
|
input
|
||||||
|
@ -3718,7 +3724,7 @@ gl843_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor
|
||||||
|
|
||||||
{PGA} = 283 * (1 - {output} / {target output})
|
{PGA} = 283 * (1 - {output} / {target output})
|
||||||
*/
|
*/
|
||||||
float gain = ((float) max[j] / (calib_sensor.gain_white_ref*coeff));
|
float gain = ((float) target_value / (calib_sensor.gain_white_ref*coeff));
|
||||||
int code = 283 * (1 - gain);
|
int code = 283 * (1 - gain);
|
||||||
if (code > 255)
|
if (code > 255)
|
||||||
code = 255;
|
code = 255;
|
||||||
|
@ -3726,8 +3732,8 @@ gl843_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor
|
||||||
code = 0;
|
code = 0;
|
||||||
dev->frontend.set_gain(j, code);
|
dev->frontend.set_gain(j, code);
|
||||||
|
|
||||||
DBG(DBG_proc, "%s: channel %d, max=%d, gain = %f, setting:%d\n", __func__, j, max[j], gain,
|
DBG(DBG_proc, "%s: channel %d, max=%d, gain = %f, setting:%d\n", __func__, j, target_value,
|
||||||
code);
|
gain, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev->model->is_cis) {
|
if (dev->model->is_cis) {
|
||||||
|
|
Ładowanie…
Reference in New Issue