From 256a90e29d777de3b2865627b3f8030ef7635857 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sun, 10 May 2020 22:27:59 +0300 Subject: [PATCH] genesys: Simplify coarse_gain_calibration() on gl646 --- backend/genesys/gl646.cpp | 46 ++++++++++----------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/backend/genesys/gl646.cpp b/backend/genesys/gl646.cpp index 620d872f5..f08f46404 100644 --- a/backend/genesys/gl646.cpp +++ b/backend/genesys/gl646.cpp @@ -2521,8 +2521,6 @@ void CommandSetGl646::coarse_gain_calibration(Genesys_Device* dev, const Genesys DBG_HELPER(dbg); (void) dpi; - unsigned val, maximum, idx; - unsigned count, pass; float average[3]; char title[32]; @@ -2581,27 +2579,11 @@ void CommandSetGl646::coarse_gain_calibration(Genesys_Device* dev, const Genesys dev->frontend.set_gain(1, 1); dev->frontend.set_gain(2, 1); - if (channels > 1) - { - average[0] = 0; - average[1] = 0; - average[2] = 0; - idx = 0; - } - else - { - average[0] = 255; - average[1] = 255; - average[2] = 255; - switch (dev->settings.color_filter) { - case ColorFilter::RED: idx = 0; break; - case ColorFilter::GREEN: idx = 1; break; - case ColorFilter::BLUE: idx = 2; break; - default: idx = 0; break; // should not happen - } - average[idx] = 0; - } - pass = 0; + average[0] = 0; + average[1] = 0; + average[2] = 0; + + unsigned pass = 0; std::vector line; @@ -2625,15 +2607,14 @@ void CommandSetGl646::coarse_gain_calibration(Genesys_Device* dev, const Genesys /* average high level for each channel and compute gain to reach the target code we only use the central half of the CCD data */ - for (unsigned k = idx; k < idx + channels; k++) { + for (unsigned k = 0; k < channels; k++) { /* we find the maximum white value, so we can deduce a threshold to average white values */ - maximum = 0; + unsigned maximum = 0; for (unsigned i = 0; i < lines; i++) { for (unsigned j = 0; j < pixels; j++) { - val = line[i * channels * pixels + j + k]; - if (val > maximum) - maximum = val; + unsigned val = line[i * channels * pixels + j + k]; + maximum = std::max(maximum, val); } } @@ -2642,11 +2623,11 @@ void CommandSetGl646::coarse_gain_calibration(Genesys_Device* dev, const Genesys /* computes white average */ average[k] = 0; - count = 0; + unsigned count = 0; for (unsigned i = 0; i < lines; i++) { for (unsigned j = 0; j < pixels; j++) { /* averaging only white points allow us not to care about dark margins */ - val = line[i * channels * pixels + j + k]; + unsigned val = line[i * channels * pixels + j + k]; if (val > maximum) { average[k] += val; @@ -2665,11 +2646,6 @@ void CommandSetGl646::coarse_gain_calibration(Genesys_Device* dev, const Genesys } } - if (channels < 3) { - dev->frontend.set_gain(1, dev->frontend.get_gain(0)); - dev->frontend.set_gain(2, dev->frontend.get_gain(0)); - } - DBG(DBG_info, "%s: gains=(%d,%d,%d)\n", __func__, dev->frontend.get_gain(0), dev->frontend.get_gain(1),