From 3d9113997f30de42066727e81d0cd24c51335b65 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 14 Dec 2019 10:20:12 +0200 Subject: [PATCH] genesys: Switch remaining legacy curve uses to physical curves --- backend/genesys/genesys.cpp | 40 ++----- backend/genesys/gl841.cpp | 41 ++++--- backend/genesys/low.h | 7 +- backend/genesys/motor.cpp | 12 ++ backend/genesys/motor.h | 2 + backend/genesys/tables_motor.cpp | 129 +++------------------- testsuite/backend/genesys/tests_motor.cpp | 84 ++++++-------- 7 files changed, 94 insertions(+), 221 deletions(-) diff --git a/backend/genesys/genesys.cpp b/backend/genesys/genesys.cpp index ab1fb2624..dcb220506 100644 --- a/backend/genesys/genesys.cpp +++ b/backend/genesys/genesys.cpp @@ -406,49 +406,27 @@ MotorSlopeTable sanei_genesys_generate_slope_table(unsigned max_steps, unsigned * * @param dev Device struct * @param slope_table Table to write to - * @param max_step Size of slope_table in steps - * @param use_steps Maximum number of steps to use for acceleration * @param step_type Generate table for this step_type. 0=>full, 1=>half, * 2=>quarter * @param exposure_time Minimum exposure time of a scan line * @param yres Resolution of a scan line * @param used_steps Final number of steps is stored here * @param final_exposure Final step time is stored here - * @return Time for acceleration + * @return Motor slope table * @note all times in pixel time */ -MotorSlopeTable sanei_genesys_create_slope_table3(const Genesys_Motor& motor, - unsigned max_steps, - unsigned use_steps, - StepType step_type, - int exposure_time, +MotorSlopeTable sanei_genesys_create_slope_table3(AsicType asic_type, const Genesys_Motor& motor, + StepType step_type, int exposure_time, unsigned yres) { - unsigned int vtarget; - unsigned int vend; - unsigned int vstart; + unsigned target_speed_w = (exposure_time * yres) / motor.base_ydpi; - DBG(DBG_proc, "%s: step_type = %d, exposure_time = %d, yres = %d\n", __func__, - static_cast(step_type), exposure_time, yres); + const auto& slope = motor.get_slope(step_type); - /* final speed */ - vtarget = (exposure_time * yres) / motor.base_ydpi; - - const auto& slope = motor.get_slope(step_type).legacy(); - - unsigned u_step_type = static_cast(step_type); - vstart = slope.maximum_start_speed; - vend = slope.maximum_speed; - - vtarget = std::min(vtarget >> u_step_type, 65535u); - vstart = std::min(vstart >> u_step_type, 65535u); - vend = std::min(vend >> u_step_type, 65535u); - - auto table = sanei_genesys_generate_slope_table(max_steps, use_steps, vtarget, vstart, vend, - slope.minimum_steps << u_step_type, slope.g); + auto table = create_slope_table(slope.physical(), target_speed_w, step_type, 1, 1, + get_slope_table_max_size(asic_type)); table.final_exposure = (table.final_exposure * motor.base_ydpi) / yres; - return table; } @@ -524,8 +502,8 @@ SANE_Int sanei_genesys_exposure_time2(Genesys_Device * dev, float ydpi, StepType step_type, int endpixel, int exposure_by_led) { int exposure_by_ccd = endpixel + 32; - int exposure_by_motor = static_cast((dev->motor.get_slope(step_type).legacy().maximum_speed * - dev->motor.base_ydpi) / ydpi); + unsigned max_speed_motor_w = dev->motor.get_slope(step_type).physical().max_speed_w; + int exposure_by_motor = static_cast((max_speed_motor_w * dev->motor.base_ydpi) / ydpi); int exposure = exposure_by_ccd; diff --git a/backend/genesys/gl841.cpp b/backend/genesys/gl841.cpp index edcc6fdd1..59889b7ff 100644 --- a/backend/genesys/gl841.cpp +++ b/backend/genesys/gl841.cpp @@ -863,8 +863,9 @@ static void gl841_init_motor_regs(Genesys_Device* dev, const Genesys_Sensor& sen fast_exposure = dev->motor.get_slope(StepType::FULL).legacy().maximum_start_speed; } - auto fast_table = sanei_genesys_create_slope_table3(dev->motor, 256, 256, StepType::FULL, - fast_exposure, dev->motor.base_ydpi / 4); + auto fast_table = sanei_genesys_create_slope_table3(dev->model->asic_type, dev->motor, + StepType::FULL, fast_exposure, + dev->motor.base_ydpi / 4); feedl = feed_steps - fast_table.steps_count * 2; use_fast_fed = 1; @@ -1021,36 +1022,32 @@ static void gl841_init_motor_regs_scan(Genesys_Device* dev, const Genesys_Sensor allowed to use. */ - auto slow_table = sanei_genesys_create_slope_table3(dev->motor, 256, 256, scan_step_type, - scan_exposure_time, scan_yres); + auto slow_table = sanei_genesys_create_slope_table3(dev->model->asic_type, dev->motor, + scan_step_type, scan_exposure_time, + scan_yres); - auto back_table = sanei_genesys_create_slope_table3(dev->motor, 256, 256, scan_step_type, - 0, scan_yres); + auto back_table = sanei_genesys_create_slope_table3(dev->model->asic_type, dev->motor, + scan_step_type, 0, scan_yres); if (feed_steps < (slow_table.steps_count >> static_cast(scan_step_type))) { /*TODO: what should we do here?? go back to exposure calculation?*/ feed_steps = slow_table.steps_count >> static_cast(scan_step_type); } - unsigned max_fast_slope_steps = 0; // BUG: this should be 256 for the following conditional - // to make sense - if (feed_steps > max_fast_slope_steps * 2 - - (slow_table.steps_count >> static_cast(scan_step_type))) - { - max_fast_slope_steps = 256; - } else { - // we need to shorten fast_slope_steps here. - max_fast_slope_steps = (feed_steps - - (slow_table.steps_count >> static_cast(scan_step_type))) / 2; - } - - DBG(DBG_info, "%s: Maximum allowed slope steps for fast slope: %d\n", __func__, - max_fast_slope_steps); - - auto fast_table = sanei_genesys_create_slope_table3(dev->motor, 256, max_fast_slope_steps, + auto fast_table = sanei_genesys_create_slope_table3(dev->model->asic_type, dev->motor, StepType::FULL, fast_exposure, dev->motor.base_ydpi / 4); + unsigned max_fast_slope_steps_count = 1; + if (feed_steps > (slow_table.steps_count >> static_cast(scan_step_type)) + 2) { + max_fast_slope_steps_count = (feed_steps - + (slow_table.steps_count >> static_cast(scan_step_type))) / 2; + } + + if (fast_table.steps_count > max_fast_slope_steps_count) { + fast_table.slice_steps(max_fast_slope_steps_count); + } + /* fast fed special cases handling */ if (dev->model->gpio_id == GpioId::XP300 || dev->model->gpio_id == GpioId::DP685) diff --git a/backend/genesys/low.h b/backend/genesys/low.h index a3287a3b3..6bdfc006b 100644 --- a/backend/genesys/low.h +++ b/backend/genesys/low.h @@ -326,11 +326,8 @@ MotorSlopeTable sanei_genesys_generate_slope_table(unsigned max_steps, std::uint16_t vstart, std::uint16_t vend, unsigned steps, double g); -MotorSlopeTable sanei_genesys_create_slope_table3(const Genesys_Motor& motor, - unsigned max_steps, - unsigned use_steps, - StepType step_type, - int exposure_time, +MotorSlopeTable sanei_genesys_create_slope_table3(AsicType asic_type, const Genesys_Motor& motor, + StepType step_type, int exposure_time, unsigned yres); void sanei_genesys_create_default_gamma_table(Genesys_Device* dev, diff --git a/backend/genesys/motor.cpp b/backend/genesys/motor.cpp index dec419170..79e8130ed 100644 --- a/backend/genesys/motor.cpp +++ b/backend/genesys/motor.cpp @@ -80,6 +80,18 @@ MotorSlope MotorSlope::create_from_steps(unsigned initial_w, unsigned max_w, return slope; } +void MotorSlopeTable::slice_steps(unsigned count) +{ + if (count >= table.size() || count > steps_count) { + throw SaneException("Excepssive steps count"); + } + unsigned old_step = table[steps_count - 1]; + unsigned new_step = table[count - 1]; + steps_count = count; + + final_exposure = final_exposure * (static_cast(new_step) / old_step); +} + unsigned get_slope_table_max_size(AsicType asic_type) { switch (asic_type) { diff --git a/backend/genesys/motor.h b/backend/genesys/motor.h index 61e6461d2..5304b3fa2 100644 --- a/backend/genesys/motor.h +++ b/backend/genesys/motor.h @@ -155,6 +155,8 @@ struct MotorSlopeTable // table.back() adjusted to the scan dpi unsigned final_exposure = 0; + + void slice_steps(unsigned count); }; unsigned get_slope_table_max_size(AsicType asic_type); diff --git a/backend/genesys/tables_motor.cpp b/backend/genesys/tables_motor.cpp index e36643d07..aff31f9cc 100644 --- a/backend/genesys/tables_motor.cpp +++ b/backend/genesys/tables_motor.cpp @@ -53,27 +53,12 @@ void genesys_init_motor_tables() { s_motors.init(); - MotorSlopeLegacy slope; - Genesys_Motor motor; motor.id = MotorId::UMAX; motor.base_ydpi = 1200; motor.optical_ydpi = 2400; - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 11000; - slope.maximum_speed = 3000; - slope.minimum_steps = 128; - slope.g = 1.0; - motor.slopes.push_back(slope); - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 11000; - slope.maximum_speed = 3000; - slope.minimum_steps = 128; - slope.g = 1.0; - motor.slopes.push_back(slope); - + motor.slopes.push_back(MotorSlope::create_from_steps(11000, 3000, 128)); + motor.slopes.push_back(MotorSlope::create_from_steps(11000, 3000, 128)); s_motors->push_back(std::move(motor)); @@ -90,21 +75,8 @@ void genesys_init_motor_tables() motor.id = MotorId::ST24; motor.base_ydpi = 2400; motor.optical_ydpi = 2400; - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 2289; - slope.maximum_speed = 2100; - slope.minimum_steps = 128; - slope.g = 0.3f; - motor.slopes.push_back(slope); - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 2289; - slope.maximum_speed = 2100; - slope.minimum_steps = 128; - slope.g = 0.3f; - motor.slopes.push_back(slope); - + motor.slopes.push_back(MotorSlope::create_from_steps(2289, 2100, 128)); + motor.slopes.push_back(MotorSlope::create_from_steps(2289, 2100, 128)); s_motors->push_back(std::move(motor)); @@ -139,21 +111,8 @@ void genesys_init_motor_tables() motor.id = MotorId::CANON_LIDE_35; motor.base_ydpi = 1200; motor.optical_ydpi = 2400; - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 3500; - slope.maximum_speed = 1300; - slope.minimum_steps = 60; - slope.g = 0.8f; - motor.slopes.push_back(slope); - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 3500; - slope.maximum_speed = 1400; - slope.minimum_steps = 60; - slope.g = 0.8f; - motor.slopes.push_back(slope); - + motor.slopes.push_back(MotorSlope::create_from_steps(3500, 1300, 60)); + motor.slopes.push_back(MotorSlope::create_from_steps(3500, 1400, 60)); s_motors->push_back(std::move(motor)); @@ -170,22 +129,9 @@ void genesys_init_motor_tables() motor.id = MotorId::XP300; motor.base_ydpi = 300; motor.optical_ydpi = 600; - - slope = MotorSlopeLegacy(); // works best with GPIO10, GPIO14 off - slope.maximum_start_speed = 3700; - slope.maximum_speed = 3700; - slope.minimum_steps = 2; - slope.g = 0.8f; - motor.slopes.push_back(slope); - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 11000; - slope.maximum_speed = 11000; - slope.minimum_steps = 2; - slope.g = 0.8f; - motor.slopes.push_back(slope); - + motor.slopes.push_back(MotorSlope::create_from_steps(3700, 3700, 2)); + motor.slopes.push_back(MotorSlope::create_from_steps(11000, 11000, 2)); s_motors->push_back(std::move(motor)); @@ -193,21 +139,8 @@ void genesys_init_motor_tables() motor.id = MotorId::DP665; motor.base_ydpi = 750; motor.optical_ydpi = 1500; - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 3000; - slope.maximum_speed = 2500; - slope.minimum_steps = 10; - slope.g = 0.8f; - motor.slopes.push_back(slope); - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 11000; - slope.maximum_speed = 11000; - slope.minimum_steps = 2; - slope.g = 0.8f; - motor.slopes.push_back(slope); - + motor.slopes.push_back(MotorSlope::create_from_steps(3000, 2500, 10)); + motor.slopes.push_back(MotorSlope::create_from_steps(11000, 11000, 2)); s_motors->push_back(std::move(motor)); @@ -215,20 +148,8 @@ void genesys_init_motor_tables() motor.id = MotorId::ROADWARRIOR; motor.base_ydpi = 750; motor.optical_ydpi = 1500; - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 3000; - slope.maximum_speed = 2600; - slope.minimum_steps = 10; - slope.g = 0.8f; - motor.slopes.push_back(slope); - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 11000; - slope.maximum_speed = 11000; - slope.minimum_steps = 2; - slope.g = 0.8f; - motor.slopes.push_back(slope); + motor.slopes.push_back(MotorSlope::create_from_steps(3000, 2600, 10)); + motor.slopes.push_back(MotorSlope::create_from_steps(11000, 11000, 2)); s_motors->push_back(std::move(motor)); @@ -236,21 +157,8 @@ void genesys_init_motor_tables() motor.id = MotorId::DSMOBILE_600; motor.base_ydpi = 750; motor.optical_ydpi = 1500; - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 6666; - slope.maximum_speed = 3700; - slope.minimum_steps = 8; - slope.g = 0.8f; - motor.slopes.push_back(slope); - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 6666; - slope.maximum_speed = 3700; - slope.minimum_steps = 8; - slope.g = 0.8f; - motor.slopes.push_back(slope); - + motor.slopes.push_back(MotorSlope::create_from_steps(6666, 3700, 8)); + motor.slopes.push_back(MotorSlope::create_from_steps(6666, 3700, 8)); s_motors->push_back(std::move(motor)); @@ -410,14 +318,7 @@ void genesys_init_motor_tables() motor.id = MotorId::CANON_LIDE_80; motor.base_ydpi = 2400; motor.optical_ydpi = 4800; // 9600 - - slope = MotorSlopeLegacy(); - slope.maximum_start_speed = 9560; - slope.maximum_speed = 1912; - slope.minimum_steps = 31; - slope.g = 0.8f; - motor.slopes.push_back(slope); - + motor.slopes.push_back(MotorSlope::create_from_steps(9560, 1912, 31)); s_motors->push_back(std::move(motor)); } diff --git a/testsuite/backend/genesys/tests_motor.cpp b/testsuite/backend/genesys/tests_motor.cpp index 35285aa46..e8a2a4b9e 100644 --- a/testsuite/backend/genesys/tests_motor.cpp +++ b/testsuite/backend/genesys/tests_motor.cpp @@ -33,35 +33,18 @@ namespace genesys { void test_create_slope_table3() { - MotorSlopeLegacy slope; + auto asic_type = AsicType::GL841; + auto max_table_size = get_slope_table_max_size(asic_type); Genesys_Motor motor; motor.id = MotorId::CANON_LIDE_200; motor.base_ydpi = 1200; motor.optical_ydpi = 6400; + motor.slopes.push_back(MotorSlope::create_from_steps(10000, 1000, 20)); + motor.slopes.push_back(MotorSlope::create_from_steps(10000, 1000, 20)); + motor.slopes.push_back(MotorSlope::create_from_steps(10000, 1000, 16)); - slope = MotorSlopeLegacy(); // full step - slope.maximum_start_speed = 10000; - slope.maximum_speed = 1000; - slope.minimum_steps = 20; - slope.g = 0.80; - motor.slopes.push_back(slope); - - slope = MotorSlopeLegacy(); // half step - slope.maximum_start_speed = 10000; - slope.maximum_speed = 1000; - slope.minimum_steps = 20; - slope.g = 0.80; - motor.slopes.push_back(slope); - - slope = MotorSlopeLegacy(); // quarter step 0.75*2712 - slope.maximum_start_speed = 10000; - slope.maximum_speed = 1000; - slope.minimum_steps = 16; - slope.g = 0.80f; - motor.slopes.push_back(slope); - - auto table = sanei_genesys_create_slope_table3(motor, 20, 20, StepType::FULL, 10000, + auto table = sanei_genesys_create_slope_table3(asic_type, motor, StepType::FULL, 10000, motor.base_ydpi); ASSERT_EQ(table.pixeltime_sum, 10000u); @@ -69,26 +52,27 @@ void test_create_slope_table3() ASSERT_EQ(table.final_exposure, 10000u); std::vector expected_steps = { - 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, - 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, + 10000, }; + expected_steps.resize(max_table_size, 10000); ASSERT_EQ(table.table, expected_steps); - table = sanei_genesys_create_slope_table3(motor, 20, 20, StepType::FULL, 2000, motor.base_ydpi); + table = sanei_genesys_create_slope_table3(asic_type, motor, StepType::FULL, 2000, + motor.base_ydpi); - ASSERT_EQ(table.pixeltime_sum, 98183u); - ASSERT_EQ(table.steps_count, 18u); - ASSERT_EQ(table.final_exposure, 1766u); + ASSERT_EQ(table.pixeltime_sum, 33830u); + ASSERT_EQ(table.steps_count, 7u); + ASSERT_EQ(table.final_exposure, 2000u); expected_steps = { - 10000, 9146, 8513, 7944, 7412, 6906, 6421, 5951, 5494, 5049, - 4614, 4187, 3768, 3356, 2950, 2550, 2156, 1766, 1766, 1766, + 10000, 10000, 4099, 3028, 2511, 2192, 2000 }; + expected_steps.resize(max_table_size, 2000); ASSERT_EQ(table.table, expected_steps); - table = sanei_genesys_create_slope_table3(motor, 20, 20, StepType::HALF, 10000, + table = sanei_genesys_create_slope_table3(asic_type, motor, StepType::HALF, 10000, motor.base_ydpi); ASSERT_EQ(table.pixeltime_sum, 5000u); @@ -96,27 +80,28 @@ void test_create_slope_table3() ASSERT_EQ(table.final_exposure, 5000u); expected_steps = { - 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, - 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, + 5000, }; + expected_steps.resize(max_table_size, 5000); + ASSERT_EQ(table.table, expected_steps); - table = sanei_genesys_create_slope_table3(motor, 20, 20, StepType::HALF, 2000, + table = sanei_genesys_create_slope_table3(asic_type, motor, StepType::HALF, 2000, motor.base_ydpi); - ASSERT_EQ(table.pixeltime_sum, 72131u); - ASSERT_EQ(table.steps_count, 20u); - ASSERT_EQ(table.final_exposure, 2575u); + ASSERT_EQ(table.pixeltime_sum, 16914u); + ASSERT_EQ(table.steps_count, 7u); + ASSERT_EQ(table.final_exposure, 1000u); expected_steps = { - 5000, 4759, 4581, 4421, 4272, 4129, 3993, 3861, 3732, 3607, - 3485, 3365, 3247, 3131, 3017, 2904, 2793, 2684, 2575, 2575, + 5000, 5000, 2049, 1514, 1255, 1096, 1000 }; + expected_steps.resize(max_table_size, 1000); ASSERT_EQ(table.table, expected_steps); - table = sanei_genesys_create_slope_table3(motor, 20, 20, StepType::QUARTER, 10000, + table = sanei_genesys_create_slope_table3(asic_type, motor, StepType::QUARTER, 10000, motor.base_ydpi); ASSERT_EQ(table.pixeltime_sum, 2500u); @@ -124,23 +109,24 @@ void test_create_slope_table3() ASSERT_EQ(table.final_exposure, 2500u); expected_steps = { - 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, - 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, + 2500, }; + expected_steps.resize(max_table_size, 2500); + ASSERT_EQ(table.table, expected_steps); - table = sanei_genesys_create_slope_table3(motor, 20, 20, StepType::QUARTER, 2000, + table = sanei_genesys_create_slope_table3(asic_type, motor, StepType::QUARTER, 2000, motor.base_ydpi); - ASSERT_EQ(table.pixeltime_sum, 40503u); - ASSERT_EQ(table.steps_count, 20u); - ASSERT_EQ(table.final_exposure, 1674u); + ASSERT_EQ(table.pixeltime_sum, 7680u); + ASSERT_EQ(table.steps_count, 6u); + ASSERT_EQ(table.final_exposure, 500u); expected_steps = { - 2500, 2418, 2357, 2303, 2252, 2203, 2157, 2112, 2068, 2025, - 1983, 1943, 1902, 1863, 1824, 1786, 1748, 1711, 1674, 1674, + 2500, 2500, 932, 683, 565, 500 }; + expected_steps.resize(max_table_size, 500); ASSERT_EQ(table.table, expected_steps); }