diff --git a/backend/genesys.cc b/backend/genesys.cc index 4cc0f6620..e3830de3e 100644 --- a/backend/genesys.cc +++ b/backend/genesys.cc @@ -98,11 +98,18 @@ static SANE_String_Const cis_color_filter_list[] = { }; static SANE_String_Const source_list[] = { - SANE_I18N (FLATBED), - SANE_I18N (TRANSPARENCY_ADAPTER), + SANE_I18N (STR_FLATBED), + SANE_I18N (STR_TRANSPARENCY_ADAPTER), 0 }; +static const char* source_list_infrared[] = { + SANE_I18N(STR_FLATBED), + SANE_I18N(STR_TRANSPARENCY_ADAPTER), + SANE_I18N(STR_TRANSPARENCY_ADAPTER_INFRARED), + 0 +}; + static SANE_Range swdespeck_range = { 1, 9, @@ -184,14 +191,13 @@ const Genesys_Sensor& sanei_genesys_find_sensor_any(Genesys_Device* dev) } const Genesys_Sensor& sanei_genesys_find_sensor(Genesys_Device* dev, int dpi, - int scan_method) + ScanMethod scan_method) { - bool is_transparency = scan_method == SCAN_METHOD_TRANSPARENCY; for (const auto& sensor : *s_sensors) { if (dev->model->ccd_type == sensor.sensor_id && (sensor.min_resolution == -1 || dpi >= sensor.min_resolution) && (sensor.max_resolution == -1 || dpi <= sensor.max_resolution) && - sensor.is_transparency == is_transparency) { + sensor.method == scan_method) { return sensor; } } @@ -199,14 +205,13 @@ const Genesys_Sensor& sanei_genesys_find_sensor(Genesys_Device* dev, int dpi, } Genesys_Sensor& sanei_genesys_find_sensor_for_write(Genesys_Device* dev, int dpi, - int scan_method) + ScanMethod scan_method) { - bool is_transparency = scan_method == SCAN_METHOD_TRANSPARENCY; for (auto& sensor : *s_sensors) { if (dev->model->ccd_type == sensor.sensor_id && (sensor.min_resolution == -1 || dpi >= sensor.min_resolution) && (sensor.max_resolution == -1 || dpi <= sensor.max_resolution) && - sensor.is_transparency == is_transparency) { + sensor.method == scan_method) { return sensor; } } @@ -918,7 +923,7 @@ sanei_genesys_exposure_time (Genesys_Device * dev, Genesys_Register_Set * reg, } } } - return dev->settings.exposure_time; + return 11000; } @@ -959,7 +964,8 @@ genesys_send_offset_and_shading (Genesys_Device * dev, const Genesys_Sensor& sen /* TODO invert the test so only the 2 models behaving like that are * tested instead of adding all the others */ /* many scanners send coefficient for lineart/gray like in color mode */ - if (dev->settings.scan_mode < 2 + if ((dev->settings.scan_mode == ScanColorMode::LINEART || + dev->settings.scan_mode == ScanColorMode::HALFTONE) && dev->model->ccd_type != CCD_PLUSTEK3800 && dev->model->ccd_type != CCD_KVSS080 && dev->model->ccd_type != CCD_G4050 @@ -1028,10 +1034,14 @@ sanei_genesys_init_shading_data (Genesys_Device * dev, const Genesys_Sensor& sen DBG(DBG_proc, "%s (pixels_per_line = %d)\n", __func__, pixels_per_line); - if (dev->settings.scan_mode >= 2) /* 3 pass or single pass color */ - channels = 3; - else - channels = 1; + // BUG: GRAY shouldn't probably be in the if condition below. Discovered when refactoring + if (dev->settings.scan_mode == ScanColorMode::GRAY || + dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) + { + channels = 3; + } else { + channels = 1; + } // 16 bit black, 16 bit white std::vector shading_data(pixels_per_line * 4 * channels, 0); @@ -1353,7 +1363,7 @@ genesys_average_white (Genesys_Device * dev, Genesys_Sensor& sensor, int channel range = size / 50; - if (dev->settings.scan_method == SCAN_METHOD_TRANSPARENCY) /* transparency mode */ + if (dev->settings.scan_method == ScanMethod::TRANSPARENCY) /* transparency mode */ gain_white_ref = sensor.fau_gain_white_ref * 256; else gain_white_ref = sensor.gain_white_ref * 256; @@ -1404,7 +1414,7 @@ genesys_average_black (Genesys_Device * dev, int channel, sum = 0; - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) { data += (channel * 2); pixel_step = 3 * 2; @@ -1441,12 +1451,12 @@ static SANE_Status genesys_coarse_calibration(Genesys_Device * dev, Genesys_Sens uint16_t white[12], dark[12]; int i, j; - DBG(DBG_info, "%s (scan_mode = %d)\n", __func__, dev->settings.scan_mode); + DBG(DBG_info, "%s (scan_mode = %d)\n", __func__, static_cast(dev->settings.scan_mode)); black_pixels = sensor.black_pixels * dev->settings.xres / sensor.optical_res; - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; else channels = 1; @@ -1489,7 +1499,7 @@ static SANE_Status genesys_coarse_calibration(Genesys_Device * dev, Genesys_Sens double applied_multi; double gain_white_ref; - if (dev->settings.scan_method == SCAN_METHOD_TRANSPARENCY) /* Transparency */ + if (dev->settings.scan_method == ScanMethod::TRANSPARENCY) /* Transparency */ gain_white_ref = sensor.fau_gain_white_ref * 256; else gain_white_ref = sensor.gain_white_ref * 256; @@ -1633,7 +1643,7 @@ static SANE_Status genesys_coarse_calibration(Genesys_Device * dev, Genesys_Sens DBG(DBG_error, "%s: Failed to end scan: %s\n", __func__, sane_strstatus(status)); return status; } - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) { for (j = 0; j < 3; j++) { @@ -1659,7 +1669,7 @@ static SANE_Status genesys_coarse_calibration(Genesys_Device * dev, Genesys_Sens if (i == 3) { - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) { /* todo: huh? */ dev->dark[0] = @@ -1673,7 +1683,7 @@ static SANE_Status genesys_coarse_calibration(Genesys_Device * dev, Genesys_Sens { switch (dev->settings.color_filter) { - case 0: + case ColorFilter::RED: default: dev->dark[0] = (uint16_t) (1.6925 * dark[i * 3 + 0] + @@ -1681,14 +1691,14 @@ static SANE_Status genesys_coarse_calibration(Genesys_Device * dev, Genesys_Sens dev->dark[1] = dev->dark[2] = dev->dark[0]; break; - case 1: + case ColorFilter::GREEN: dev->dark[1] = (uint16_t) (1.4013 * dark[i * 3 + 1] + (1.3147 - 1.0) * 256); dev->dark[0] = dev->dark[2] = dev->dark[1]; break; - case 2: + case ColorFilter::BLUE: dev->dark[2] = (uint16_t) (1.2931 * dark[i * 3 + 2] + (1.1558 - 1.0) * 256); @@ -1788,13 +1798,13 @@ genesys_dark_shading_calibration(Genesys_Device * dev, const Genesys_Sensor& sen * because they have a calibration sheet with a sufficient black strip */ if (dev->model->is_sheetfed == SANE_FALSE) { - dev->model->cmd_set->set_lamp_power(dev, sensor, &dev->calib_reg, SANE_FALSE); - dev->model->cmd_set->set_motor_power(&dev->calib_reg, motor); + sanei_genesys_set_lamp_power(dev, sensor, dev->calib_reg, false); + sanei_genesys_set_motor_power(dev->calib_reg, motor); } else { - dev->model->cmd_set->set_lamp_power(dev, sensor, &dev->calib_reg, SANE_TRUE); - dev->model->cmd_set->set_motor_power(&dev->calib_reg, motor); + sanei_genesys_set_lamp_power(dev, sensor, dev->calib_reg, true); + sanei_genesys_set_motor_power(dev->calib_reg, motor); } status = @@ -1982,9 +1992,9 @@ genesys_white_shading_calibration (Genesys_Device * dev, const Genesys_Sensor& s motor=SANE_FALSE; } - /* turn on motor and lamp power */ - dev->model->cmd_set->set_lamp_power(dev, sensor, &dev->calib_reg, SANE_TRUE); - dev->model->cmd_set->set_motor_power(&dev->calib_reg, motor); + // turn on motor and lamp power + sanei_genesys_set_lamp_power(dev, sensor, dev->calib_reg, true); + sanei_genesys_set_motor_power(dev->calib_reg, motor); /* if needed, go back before doing next scan */ if (dev->model->flags & GENESYS_FLAG_SHADING_REPARK) @@ -1995,7 +2005,7 @@ genesys_white_shading_calibration (Genesys_Device * dev, const Genesys_Sensor& s status = (dev->model->cmd_set->rewind ? dev->model->cmd_set->rewind (dev) : dev->model->cmd_set->slow_back_home (dev, SANE_TRUE)); - if (dev->settings.scan_method == SCAN_METHOD_TRANSPARENCY) + if (dev->settings.scan_method == ScanMethod::TRANSPARENCY) { dev->model->cmd_set->move_to_ta(dev); } @@ -2117,9 +2127,9 @@ genesys_dark_white_shading_calibration(Genesys_Device * dev, const Genesys_Senso motor=SANE_FALSE; } - /* turn on motor and lamp power */ - dev->model->cmd_set->set_lamp_power(dev, sensor, &dev->calib_reg, SANE_TRUE); - dev->model->cmd_set->set_motor_power(&dev->calib_reg, motor); + // turn on motor and lamp power + sanei_genesys_set_lamp_power(dev, sensor, dev->calib_reg, true); + sanei_genesys_set_motor_power(dev->calib_reg, motor); status = dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg); @@ -3172,7 +3182,7 @@ genesys_flatbed_calibration(Genesys_Device * dev, Genesys_Sensor& sensor) /* do offset calibration if needed */ if (dev->model->flags & GENESYS_FLAG_OFFSET_CALIBRATION) { - status = dev->model->cmd_set->offset_calibration (dev, sensor); + status = dev->model->cmd_set->offset_calibration(dev, sensor, dev->calib_reg); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: offset calibration failed: %s\n", __func__, sane_strstatus(status)); @@ -3180,7 +3190,7 @@ genesys_flatbed_calibration(Genesys_Device * dev, Genesys_Sensor& sensor) } /* since all the registers are set up correctly, just use them */ - status = dev->model->cmd_set->coarse_gain_calibration(dev, sensor, yres); + status = dev->model->cmd_set->coarse_gain_calibration(dev, sensor, dev->calib_reg, yres); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: coarse gain calibration: %s\n", __func__, sane_strstatus(status)); @@ -3192,7 +3202,7 @@ genesys_flatbed_calibration(Genesys_Device * dev, Genesys_Sensor& sensor) /* since we have 2 gain calibration proc, skip second if first one was used. */ { - status = dev->model->cmd_set->init_regs_for_coarse_calibration(dev, sensor); + status = dev->model->cmd_set->init_regs_for_coarse_calibration(dev, sensor, dev->calib_reg); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to send calibration registers: %s\n", __func__, @@ -3213,7 +3223,7 @@ genesys_flatbed_calibration(Genesys_Device * dev, Genesys_Sensor& sensor) if (dev->model->is_cis) { /* the afe now sends valid data for doing led calibration */ - status = dev->model->cmd_set->led_calibration(dev, sensor); + status = dev->model->cmd_set->led_calibration(dev, sensor, dev->calib_reg); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: led calibration failed: %s\n", __func__, sane_strstatus(status)); @@ -3223,7 +3233,7 @@ genesys_flatbed_calibration(Genesys_Device * dev, Genesys_Sensor& sensor) /* calibrate afe again to match new exposure */ if (dev->model->flags & GENESYS_FLAG_OFFSET_CALIBRATION) { - status = dev->model->cmd_set->offset_calibration (dev, sensor); + status = dev->model->cmd_set->offset_calibration(dev, sensor, dev->calib_reg); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: offset calibration failed: %s\n", __func__, sane_strstatus(status)); @@ -3232,7 +3242,7 @@ genesys_flatbed_calibration(Genesys_Device * dev, Genesys_Sensor& sensor) /* since all the registers are set up correctly, just use them */ - status = dev->model->cmd_set->coarse_gain_calibration (dev, sensor, yres); + status = dev->model->cmd_set->coarse_gain_calibration(dev, sensor, dev->calib_reg, yres); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: coarse gain calibration: %s\n", __func__, sane_strstatus(status)); @@ -3243,8 +3253,8 @@ genesys_flatbed_calibration(Genesys_Device * dev, Genesys_Sensor& sensor) /* since we have 2 gain calibration proc, skip second if first one was used. */ { - status = - dev->model->cmd_set->init_regs_for_coarse_calibration(dev, sensor); + status = dev->model->cmd_set->init_regs_for_coarse_calibration(dev, sensor, + dev->calib_reg); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to send calibration registers: %s\n", __func__, @@ -3281,7 +3291,7 @@ genesys_flatbed_calibration(Genesys_Device * dev, Genesys_Sensor& sensor) } /* shading calibration */ - status = dev->model->cmd_set->init_regs_for_shading(dev, sensor); + status = dev->model->cmd_set->init_regs_for_shading(dev, sensor, dev->calib_reg); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to send shading registers: %s\n", __func__, @@ -3393,7 +3403,7 @@ static SANE_Status genesys_sheetfed_calibration(Genesys_Device * dev, Genesys_Se if (dev->model->is_cis) { - status = dev->model->cmd_set->led_calibration(dev, sensor); + status = dev->model->cmd_set->led_calibration(dev, sensor, dev->calib_reg); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: led calibration failed: %s\n", __func__, sane_strstatus(status)); @@ -3404,7 +3414,7 @@ static SANE_Status genesys_sheetfed_calibration(Genesys_Device * dev, Genesys_Se /* calibrate afe */ if (dev->model->flags & GENESYS_FLAG_OFFSET_CALIBRATION) { - status = dev->model->cmd_set->offset_calibration (dev, sensor); + status = dev->model->cmd_set->offset_calibration(dev, sensor, dev->calib_reg); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: offset calibration failed: %s\n", __func__, sane_strstatus(status)); @@ -3413,7 +3423,7 @@ static SANE_Status genesys_sheetfed_calibration(Genesys_Device * dev, Genesys_Se /* since all the registers are set up correctly, just use them */ - status = dev->model->cmd_set->coarse_gain_calibration (dev, sensor, xres); + status = dev->model->cmd_set->coarse_gain_calibration(dev, sensor, dev->calib_reg, xres); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: coarse gain calibration: %s\n", __func__, sane_strstatus(status)); @@ -3424,8 +3434,7 @@ static SANE_Status genesys_sheetfed_calibration(Genesys_Device * dev, Genesys_Se /* since we have 2 gain calibration proc, skip second if first one was used. */ { - status = - dev->model->cmd_set->init_regs_for_coarse_calibration(dev, sensor); + status = dev->model->cmd_set->init_regs_for_coarse_calibration(dev, sensor, dev->calib_reg); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to send calibration registers: %s\n", __func__, @@ -3454,7 +3463,7 @@ static SANE_Status genesys_sheetfed_calibration(Genesys_Device * dev, Genesys_Se return status; } - status = dev->model->cmd_set->init_regs_for_shading(dev, sensor); + status = dev->model->cmd_set->init_regs_for_shading(dev, sensor, dev->calib_reg); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to do set up registers for shading calibration: %s\n", @@ -3482,7 +3491,7 @@ static SANE_Status genesys_sheetfed_calibration(Genesys_Device * dev, Genesys_Se return status; } - status = dev->model->cmd_set->init_regs_for_shading(dev, sensor); + status = dev->model->cmd_set->init_regs_for_shading(dev, sensor, dev->calib_reg); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to do set up registers for shading calibration: %s\n", __func__, @@ -3759,7 +3768,7 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) /* wait for lamp warmup : until a warmup for TRANSPARENCY is designed, skip * it when scanning from XPA. */ if (!(dev->model->flags & GENESYS_FLAG_SKIP_WARMUP) - && (dev->settings.scan_method == SCAN_METHOD_FLATBED)) + && (dev->settings.scan_method == ScanMethod::FLATBED)) { RIE (genesys_warmup_lamp (dev)); } @@ -3807,7 +3816,7 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) } /* move to calibration area for transparency adapter */ - if ((dev->settings.scan_method == SCAN_METHOD_TRANSPARENCY) + if ((dev->settings.scan_method == ScanMethod::TRANSPARENCY) && dev->model->cmd_set->move_to_ta != NULL) { status=dev->model->cmd_set->move_to_ta(dev); @@ -3897,7 +3906,7 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) /* no lamp during scan */ if(lamp_off == SANE_TRUE) { - dev->model->cmd_set->set_lamp_power(dev, sensor, &dev->reg, SANE_FALSE); + sanei_genesys_set_lamp_power(dev, sensor, dev->reg, false); } /* GL124 is using SHDAREA, so we have to wait for scan to be set up before @@ -4144,7 +4153,7 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s int depth,i,n,k; depth = dev->settings.depth; - if (dev->settings.scan_mode == SCAN_MODE_LINEART && dev->settings.dynamic_lineart==SANE_FALSE) + if (dev->settings.scan_mode == ScanColorMode::LINEART && dev->settings.dynamic_lineart==SANE_FALSE) depth = 1; /* fill buffer if needed */ @@ -4164,70 +4173,47 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s count = 0; while (count < size) { - if(dev->settings.double_xres==SANE_TRUE) - { - /* copy only even pixel */ - work_buffer_dst[count] = dev->oe_buffer.get_read_pos()[dev->cur]; - /* update counter and pointer */ - count++; - dev->cur++; - } - else - { - if(depth==1) - { - while (dev->cur < dev->len && count < size) - { - for(n=0;nsegnb;n++) - { - work_buffer_dst[count+n] = 0; - } - /* interleaving is at bit level */ - for(i=0;i<8;i++) - { - k=count+(i*dev->segnb)/8; - for(n=0;nsegnb;n++) - { - work_buffer_dst[k] = work_buffer_dst[k] << 1; - if((dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->dist*dev->order[n]])&(128>>i)) - { - work_buffer_dst[k] |= 1; - } - } + if (depth==1) { + while (dev->cur < dev->len && count < size) { + for (n=0; nsegnb; n++) { + work_buffer_dst[count+n] = 0; + } + /* interleaving is at bit level */ + for (i=0;i<8;i++) { + k=count+(i*dev->segnb)/8; + for (n=0;nsegnb;n++) { + work_buffer_dst[k] = work_buffer_dst[k] << 1; + if ((dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->dist*dev->order[n]])&(128>>i)) { + work_buffer_dst[k] |= 1; } + } + } - /* update counter and pointer */ - count += dev->segnb; - dev->cur++; - } + /* update counter and pointer */ + count += dev->segnb; + dev->cur++; + } + } + if (depth==8) { + while (dev->cur < dev->len && count < size) { + for (n=0;nsegnb;n++) { + work_buffer_dst[count+n] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->dist*dev->order[n]]; } - if(depth==8) - { - while (dev->cur < dev->len && count < size) - { - for(n=0;nsegnb;n++) - { - work_buffer_dst[count+n] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->dist*dev->order[n]]; - } - /* update counter and pointer */ - count += dev->segnb; - dev->cur++; - } - } - if(depth==16) - { - while (dev->cur < dev->len && count < size) - { - for(n=0;nsegnb;n++) - { - work_buffer_dst[count+n*2] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->dist*dev->order[n]]; - work_buffer_dst[count+n*2+1] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->dist*dev->order[n] + 1]; - } - /* update counter and pointer */ - count += dev->segnb*2; - dev->cur+=2; - } + /* update counter and pointer */ + count += dev->segnb; + dev->cur++; + } + } + if (depth==16) { + while (dev->cur < dev->len && count < size) { + for (n=0;nsegnb;n++) { + work_buffer_dst[count+n*2] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->dist*dev->order[n]]; + work_buffer_dst[count+n*2+1] = dev->oe_buffer.get_read_pos()[dev->cur + dev->skip + dev->dist*dev->order[n] + 1]; } + /* update counter and pointer */ + count += dev->segnb*2; + dev->cur+=2; + } } /* go to next line if needed */ @@ -4851,53 +4837,46 @@ max_string_size (const SANE_String_Const strings[]) static SANE_Status calc_parameters (Genesys_Scanner * s) { - SANE_String mode, source, color_filter; SANE_Status status = SANE_STATUS_GOOD; - SANE_Int depth = 0, resolution = 0; double tl_x = 0, tl_y = 0, br_x = 0, br_y = 0; - mode = s->val[OPT_MODE].s; - source = s->val[OPT_SOURCE].s; - color_filter = s->val[OPT_COLOR_FILTER].s; - depth = s->val[OPT_BIT_DEPTH].w; - resolution = s->val[OPT_RESOLUTION].w; - tl_x = SANE_UNFIX (s->val[OPT_TL_X].w); - tl_y = SANE_UNFIX (s->val[OPT_TL_Y].w); - br_x = SANE_UNFIX (s->val[OPT_BR_X].w); - br_y = SANE_UNFIX (s->val[OPT_BR_Y].w); + tl_x = SANE_UNFIX(s->pos_top_left_x); + tl_y = SANE_UNFIX(s->pos_top_left_y); + br_x = SANE_UNFIX(s->pos_bottom_right_x); + br_y = SANE_UNFIX(s->pos_bottom_right_y); s->params.last_frame = SANE_TRUE; /* only single pass scanning supported */ - if (strcmp (mode, SANE_VALUE_SCAN_MODE_GRAY) == 0 - || strcmp (mode, SANE_VALUE_SCAN_MODE_LINEART) == 0) - s->params.format = SANE_FRAME_GRAY; - else /* Color */ - s->params.format = SANE_FRAME_RGB; + if (s->mode == SANE_VALUE_SCAN_MODE_GRAY || s->mode == SANE_VALUE_SCAN_MODE_LINEART) { + s->params.format = SANE_FRAME_GRAY; + } else { + s->params.format = SANE_FRAME_RGB; + } - if (strcmp (mode, SANE_VALUE_SCAN_MODE_LINEART) == 0) - s->params.depth = 1; - else - s->params.depth = depth; - s->dev->settings.depth = depth; + if (s->mode == SANE_VALUE_SCAN_MODE_LINEART) { + s->params.depth = 1; + } else { + s->params.depth = s->bit_depth; + } + + s->dev->settings.depth = s->bit_depth; /* interpolation */ - s->dev->settings.disable_interpolation = - s->val[OPT_DISABLE_INTERPOLATION].w == SANE_TRUE; + s->dev->settings.disable_interpolation = s->disable_interpolation; // FIXME: use correct sensor const auto& sensor = sanei_genesys_find_sensor_any(s->dev); - /* hardware settings */ - if (resolution > sensor.optical_res && - s->dev->settings.disable_interpolation) - s->dev->settings.xres = sensor.optical_res; - else - s->dev->settings.xres = resolution; - s->dev->settings.yres = resolution; + // hardware settings + if (s->resolution > sensor.optical_res && s->dev->settings.disable_interpolation) { + s->dev->settings.xres = sensor.optical_res; + } else { + s->dev->settings.xres = s->resolution; + } + s->dev->settings.yres = s->resolution; - s->params.lines = ((br_y - tl_y) * s->dev->settings.yres) / MM_PER_INCH; - s->params.pixels_per_line = - ((br_x - tl_x) * resolution) / MM_PER_INCH; + s->params.lines = ((br_y - tl_y) * s->dev->settings.yres) / MM_PER_INCH; + s->params.pixels_per_line = ((br_x - tl_x) * s->resolution) / MM_PER_INCH; /* we need an even pixels number * TODO invert test logic or generalize behaviour across all ASICs */ @@ -4940,80 +4919,80 @@ calc_parameters (Genesys_Scanner * s) s->params.pixels_per_line = 8 * s->params.bytes_per_line; } - if (s->params.format == SANE_FRAME_RGB) - s->params.bytes_per_line *= 3; + if (s->params.format == SANE_FRAME_RGB) { + s->params.bytes_per_line *= 3; + } - if (strcmp (mode, SANE_VALUE_SCAN_MODE_COLOR) == 0) - s->dev->settings.scan_mode = SCAN_MODE_COLOR; - else if (strcmp (mode, SANE_VALUE_SCAN_MODE_GRAY) == 0) - s->dev->settings.scan_mode = SCAN_MODE_GRAY; - else if (strcmp (mode, SANE_TITLE_HALFTONE) == 0) - s->dev->settings.scan_mode = SCAN_MODE_HALFTONE; - else /* Lineart */ - s->dev->settings.scan_mode = SCAN_MODE_LINEART; + if (s->mode == SANE_VALUE_SCAN_MODE_COLOR) { + s->dev->settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + } else if (s->mode == SANE_VALUE_SCAN_MODE_GRAY) { + s->dev->settings.scan_mode = ScanColorMode::GRAY; + } else if (s->mode == SANE_TITLE_HALFTONE) { + s->dev->settings.scan_mode = ScanColorMode::HALFTONE; + } else { /* Lineart */ + s->dev->settings.scan_mode = ScanColorMode::LINEART; + } - /* TODO: change and check */ - if (strcmp (source, FLATBED) == 0) - s->dev->settings.scan_method = SCAN_METHOD_FLATBED; - else /* transparency */ - s->dev->settings.scan_method = SCAN_METHOD_TRANSPARENCY; + if (s->source == STR_FLATBED) { + s->dev->settings.scan_method = ScanMethod::FLATBED; + } else if (s->source == STR_TRANSPARENCY_ADAPTER) { + s->dev->settings.scan_method = ScanMethod::TRANSPARENCY; + } else if (s->source == STR_TRANSPARENCY_ADAPTER_INFRARED) { + s->dev->settings.scan_method = ScanMethod::TRANSPARENCY_INFRARED; + } s->dev->settings.lines = s->params.lines; s->dev->settings.pixels = s->params.pixels_per_line; s->dev->settings.tl_x = tl_x; s->dev->settings.tl_y = tl_y; - /* threshold setting */ - s->dev->settings.threshold = 2.55 * (SANE_UNFIX (s->val[OPT_THRESHOLD].w)); + // threshold setting + s->dev->settings.threshold = 2.55 * (SANE_UNFIX(s->threshold)); - /* color filter */ - if (strcmp (color_filter, "Red") == 0) - s->dev->settings.color_filter = 0; - else if (strcmp (color_filter, "Green") == 0) - s->dev->settings.color_filter = 1; - else if (strcmp (color_filter, "Blue") == 0) - s->dev->settings.color_filter = 2; - else - s->dev->settings.color_filter = 3; + // color filter + if (s->color_filter == "Red") { + s->dev->settings.color_filter = ColorFilter::RED; + } else if (s->color_filter == "Green") { + s->dev->settings.color_filter = ColorFilter::GREEN; + } else if (s->color_filter == "Blue") { + s->dev->settings.color_filter = ColorFilter::BLUE; + } else { + s->dev->settings.color_filter = ColorFilter::NONE; + } - /* true gray */ - if (strcmp (color_filter, "None") == 0) - s->dev->settings.true_gray = 1; - else - s->dev->settings.true_gray = 0; + // true gray + if (s->color_filter == "None") { + s->dev->settings.true_gray = 1; + } else { + s->dev->settings.true_gray = 0; + } /* dynamic lineart */ s->dev->settings.dynamic_lineart = SANE_FALSE; s->dev->settings.threshold_curve=0; - if(s->val[OPT_DISABLE_DYNAMIC_LINEART].w ==SANE_FALSE - &&s->dev->settings.scan_mode == SCAN_MODE_LINEART) - { - s->dev->settings.dynamic_lineart = SANE_TRUE; - } + if (!s->disable_dynamic_lineart && s->dev->settings.scan_mode == ScanColorMode::LINEART) { + s->dev->settings.dynamic_lineart = SANE_TRUE; + } /* hardware lineart works only when we don't have interleave data * for GL847 scanners, ie up to 600 DPI, then we have to rely on * dynamic_lineart */ if(s->dev->settings.xres > 600 && s->dev->model->asic_type==GENESYS_GL847 - && s->dev->settings.scan_mode == SCAN_MODE_LINEART) + && s->dev->settings.scan_mode == ScanColorMode::LINEART) { s->dev->settings.dynamic_lineart = SANE_TRUE; } - /* threshold curve for dynamic rasterization */ - s->dev->settings.threshold_curve=s->val[OPT_THRESHOLD_CURVE].w; + // threshold curve for dynamic rasterization + s->dev->settings.threshold_curve = s->threshold_curve; /* some digital processing requires the whole picture to be buffered */ /* no digital processing takes place when doing preview, or when bit depth is * higher than 8 bits */ - if ((s->val[OPT_SWDESPECK].b - || s->val[OPT_SWCROP].b - || s->val[OPT_SWDESKEW].b - || s->val[OPT_SWDEROTATE].b - ||(SANE_UNFIX(s->val[OPT_SWSKIP].w)>0)) - && (!s->val[OPT_PREVIEW].b) - && (s->val[OPT_BIT_DEPTH].w <= 8)) + if ((s->swdespeck || s->swcrop || s->swdeskew || s->swderotate ||(SANE_UNFIX(s->swskip)>0)) + && (!s->preview) + && (s->bit_depth <= 8)) { s->dev->buffer_image=SANE_TRUE; } @@ -5023,10 +5002,10 @@ calc_parameters (Genesys_Scanner * s) } /* brigthness and contrast only for for 8 bit scans */ - if(s->val[OPT_BIT_DEPTH].w <= 8) + if(s->bit_depth <= 8) { - s->dev->settings.contrast=(s->val[OPT_CONTRAST].w*127)/100; - s->dev->settings.brightness=(s->val[OPT_BRIGHTNESS].w*127)/100; + s->dev->settings.contrast = (s->contrast * 127) / 100; + s->dev->settings.brightness = (s->brightness * 127) / 100; } else { @@ -5035,7 +5014,7 @@ calc_parameters (Genesys_Scanner * s) } /* cache expiration time */ - s->dev->settings.expiration_time=s->val[OPT_EXPIRATION_TIME].w; + s->dev->settings.expiration_time = s->expiration_time; return status; } @@ -5091,8 +5070,6 @@ init_gamma_vector_option (Genesys_Scanner * scanner, int option) scanner->opt[option].size = 256 * sizeof (SANE_Word); scanner->opt[option].constraint.range = &u16_range; } - /* default value is NULL */ - scanner->val[option].wa = NULL; } /** @@ -5224,7 +5201,6 @@ init_options (Genesys_Scanner * s) DBGSTART; memset (s->opt, 0, sizeof (s->opt)); - memset (s->val, 0, sizeof (s->val)); for (option = 0; option < NUM_OPTIONS; ++option) { @@ -5236,7 +5212,6 @@ init_options (Genesys_Scanner * s) s->opt[OPT_NUM_OPTS].desc = SANE_DESC_NUM_OPTIONS; s->opt[OPT_NUM_OPTS].type = SANE_TYPE_INT; s->opt[OPT_NUM_OPTS].cap = SANE_CAP_SOFT_DETECT; - s->val[OPT_NUM_OPTS].w = NUM_OPTIONS; /* "Mode" group: */ s->opt[OPT_MODE_GROUP].title = SANE_I18N ("Scan Mode"); @@ -5254,7 +5229,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST; s->opt[OPT_MODE].size = max_string_size (mode_list); s->opt[OPT_MODE].constraint.string_list = mode_list; - s->val[OPT_MODE].s = strdup (SANE_VALUE_SCAN_MODE_GRAY); + s->mode = SANE_VALUE_SCAN_MODE_GRAY; /* scan source */ s->opt[OPT_SOURCE].name = SANE_NAME_SCAN_SOURCE; @@ -5264,10 +5239,14 @@ init_options (Genesys_Scanner * s) s->opt[OPT_SOURCE].constraint_type = SANE_CONSTRAINT_STRING_LIST; s->opt[OPT_SOURCE].size = max_string_size (source_list); s->opt[OPT_SOURCE].constraint.string_list = source_list; - s->val[OPT_SOURCE].s = strdup (FLATBED); + s->source = STR_FLATBED; if (model->flags & GENESYS_FLAG_HAS_UTA) { - ENABLE (OPT_SOURCE); + ENABLE (OPT_SOURCE); + if (model->flags & GENESYS_FLAG_HAS_UTA_INFRARED) { + s->opt[OPT_SOURCE].size = max_string_size(source_list_infrared); + s->opt[OPT_SOURCE].constraint.string_list = source_list_infrared; + } } else { @@ -5281,7 +5260,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_PREVIEW].type = SANE_TYPE_BOOL; s->opt[OPT_PREVIEW].unit = SANE_UNIT_NONE; s->opt[OPT_PREVIEW].constraint_type = SANE_CONSTRAINT_NONE; - s->val[OPT_PREVIEW].w = SANE_FALSE; + s->preview = false; /* bit depth */ s->opt[OPT_BIT_DEPTH].name = SANE_NAME_BIT_DEPTH; @@ -5293,7 +5272,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_BIT_DEPTH].constraint.word_list = 0; s->opt[OPT_BIT_DEPTH].constraint.word_list = s->bpp_list; create_bpp_list (s, model->bpp_gray_values); - s->val[OPT_BIT_DEPTH].w = 8; + s->bit_depth = 8; if (s->opt[OPT_BIT_DEPTH].constraint.word_list[0] < 2) DISABLE (OPT_BIT_DEPTH); @@ -5319,7 +5298,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_RESOLUTION].unit = SANE_UNIT_DPI; s->opt[OPT_RESOLUTION].constraint_type = SANE_CONSTRAINT_WORD_LIST; s->opt[OPT_RESOLUTION].constraint.word_list = dpi_list; - s->val[OPT_RESOLUTION].w = min_dpi; + s->resolution = min_dpi; /* "Geometry" group: */ s->opt[OPT_GEOMETRY_GROUP].title = SANE_I18N ("Geometry"); @@ -5349,7 +5328,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_TL_X].unit = SANE_UNIT_MM; s->opt[OPT_TL_X].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_TL_X].constraint.range = x_range; - s->val[OPT_TL_X].w = 0; + s->pos_top_left_x = 0; /* top-left y */ s->opt[OPT_TL_Y].name = SANE_NAME_SCAN_TL_Y; @@ -5359,7 +5338,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_TL_Y].unit = SANE_UNIT_MM; s->opt[OPT_TL_Y].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_TL_Y].constraint.range = y_range; - s->val[OPT_TL_Y].w = 0; + s->pos_top_left_y = 0; /* bottom-right x */ s->opt[OPT_BR_X].name = SANE_NAME_SCAN_BR_X; @@ -5369,7 +5348,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_BR_X].unit = SANE_UNIT_MM; s->opt[OPT_BR_X].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_BR_X].constraint.range = x_range; - s->val[OPT_BR_X].w = x_range->max; + s->pos_bottom_right_x = x_range->max; /* bottom-right y */ s->opt[OPT_BR_Y].name = SANE_NAME_SCAN_BR_Y; @@ -5379,7 +5358,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_BR_Y].unit = SANE_UNIT_MM; s->opt[OPT_BR_Y].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_BR_Y].constraint.range = y_range; - s->val[OPT_BR_Y].w = y_range->max; + s->pos_bottom_right_y = y_range->max; /* "Enhancement" group: */ s->opt[OPT_ENHANCEMENT_GROUP].title = SANE_I18N ("Enhancement"); @@ -5395,7 +5374,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_CUSTOM_GAMMA].desc = SANE_DESC_CUSTOM_GAMMA; s->opt[OPT_CUSTOM_GAMMA].type = SANE_TYPE_BOOL; s->opt[OPT_CUSTOM_GAMMA].cap |= SANE_CAP_ADVANCED; - s->val[OPT_CUSTOM_GAMMA].b = SANE_FALSE; + s->custom_gamma = false; /* grayscale gamma vector */ s->opt[OPT_GAMMA_VECTOR].name = SANE_NAME_GAMMA_VECTOR; @@ -5441,7 +5420,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_SWDESKEW].desc = "Request backend to rotate skewed pages digitally"; s->opt[OPT_SWDESKEW].type = SANE_TYPE_BOOL; s->opt[OPT_SWDESKEW].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; - s->val[OPT_SWDESKEW].b = SANE_FALSE; + s->swdeskew = false; /* software deskew */ s->opt[OPT_SWDESPECK].name = "swdespeck"; @@ -5449,7 +5428,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_SWDESPECK].desc = "Request backend to remove lone dots digitally"; s->opt[OPT_SWDESPECK].type = SANE_TYPE_BOOL; s->opt[OPT_SWDESPECK].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; - s->val[OPT_SWDESPECK].b = SANE_FALSE; + s->swdespeck = false; /* software despeckle radius */ s->opt[OPT_DESPECK].name = "despeck"; @@ -5460,7 +5439,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_DESPECK].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_DESPECK].constraint.range = &swdespeck_range; s->opt[OPT_DESPECK].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED | SANE_CAP_INACTIVE; - s->val[OPT_DESPECK].w = 1; + s->despeck = 1; /* crop by software */ s->opt[OPT_SWCROP].name = "swcrop"; @@ -5469,7 +5448,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_SWCROP].type = SANE_TYPE_BOOL; s->opt[OPT_SWCROP].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; s->opt[OPT_SWCROP].unit = SANE_UNIT_NONE; - s->val[OPT_SWCROP].b = SANE_FALSE; + s->swcrop = false; /* Software blank page skip */ s->opt[OPT_SWSKIP].name = "swskip"; @@ -5480,8 +5459,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_SWSKIP].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_SWSKIP].constraint.range = &(percentage_range); s->opt[OPT_SWSKIP].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; - /* disable by default */ - s->val[OPT_SWSKIP].w = 0; + s->swskip = 0; // disable by default /* Software Derotate */ s->opt[OPT_SWDEROTATE].name = "swderotate"; @@ -5490,7 +5468,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_SWDEROTATE].type = SANE_TYPE_BOOL; s->opt[OPT_SWDEROTATE].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED; s->opt[OPT_SWDEROTATE].unit = SANE_UNIT_NONE; - s->val[OPT_SWDEROTATE].b = SANE_FALSE; + s->swderotate = false; /* Software brightness */ s->opt[OPT_BRIGHTNESS].name = SANE_NAME_BRIGHTNESS; @@ -5501,8 +5479,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_BRIGHTNESS].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_BRIGHTNESS].constraint.range = &(enhance_range); s->opt[OPT_BRIGHTNESS].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; - /* disable by default */ - s->val[OPT_BRIGHTNESS].w = 0; + s->brightness = 0; // disable by default /* Sowftware contrast */ s->opt[OPT_CONTRAST].name = SANE_NAME_CONTRAST; @@ -5513,8 +5490,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_CONTRAST].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_CONTRAST].constraint.range = &(enhance_range); s->opt[OPT_CONTRAST].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; - /* disable by default */ - s->val[OPT_CONTRAST].w = 0; + s->contrast = 0; // disable by default /* "Extras" group: */ s->opt[OPT_EXTRAS_GROUP].title = SANE_I18N ("Extras"); @@ -5532,7 +5508,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_THRESHOLD].unit = SANE_UNIT_PERCENT; s->opt[OPT_THRESHOLD].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_THRESHOLD].constraint.range = &percentage_range; - s->val[OPT_THRESHOLD].w = SANE_FIX (50); + s->threshold = SANE_FIX(50); /* BW threshold curve */ s->opt[OPT_THRESHOLD_CURVE].name = "threshold-curve"; @@ -5542,7 +5518,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_THRESHOLD_CURVE].unit = SANE_UNIT_NONE; s->opt[OPT_THRESHOLD_CURVE].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_THRESHOLD_CURVE].constraint.range = &threshold_curve_range; - s->val[OPT_THRESHOLD_CURVE].w = 50; + s->threshold_curve = 50; /* dynamic linart */ s->opt[OPT_DISABLE_DYNAMIC_LINEART].name = "disable-dynamic-lineart"; @@ -5552,7 +5528,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_DISABLE_DYNAMIC_LINEART].type = SANE_TYPE_BOOL; s->opt[OPT_DISABLE_DYNAMIC_LINEART].unit = SANE_UNIT_NONE; s->opt[OPT_DISABLE_DYNAMIC_LINEART].constraint_type = SANE_CONSTRAINT_NONE; - s->val[OPT_DISABLE_DYNAMIC_LINEART].w = SANE_FALSE; + s->disable_dynamic_lineart = false; /* fastmod is required for hw lineart to work */ if ((s->dev->model->asic_type == GENESYS_GL646) @@ -5572,7 +5548,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_DISABLE_INTERPOLATION].type = SANE_TYPE_BOOL; s->opt[OPT_DISABLE_INTERPOLATION].unit = SANE_UNIT_NONE; s->opt[OPT_DISABLE_INTERPOLATION].constraint_type = SANE_CONSTRAINT_NONE; - s->val[OPT_DISABLE_INTERPOLATION].w = SANE_FALSE; + s->disable_interpolation = false; /* color filter */ s->opt[OPT_COLOR_FILTER].name = "color-filter"; @@ -5587,14 +5563,14 @@ init_options (Genesys_Scanner * s) { s->opt[OPT_COLOR_FILTER].size = max_string_size (color_filter_list); s->opt[OPT_COLOR_FILTER].constraint.string_list = color_filter_list; - s->val[OPT_COLOR_FILTER].s = strdup (s->opt[OPT_COLOR_FILTER].constraint.string_list[1]); + s->color_filter = s->opt[OPT_COLOR_FILTER].constraint.string_list[1]; } else { s->opt[OPT_COLOR_FILTER].size = max_string_size (cis_color_filter_list); s->opt[OPT_COLOR_FILTER].constraint.string_list = cis_color_filter_list; /* default to "None" ie true gray */ - s->val[OPT_COLOR_FILTER].s = strdup (s->opt[OPT_COLOR_FILTER].constraint.string_list[3]); + s->color_filter = s->opt[OPT_COLOR_FILTER].constraint.string_list[3]; } /* no support for color filter for cis+gl646 scanners */ @@ -5612,7 +5588,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_CALIBRATION_FILE].size = PATH_MAX; s->opt[OPT_CALIBRATION_FILE].cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED; s->opt[OPT_CALIBRATION_FILE].constraint_type = SANE_CONSTRAINT_NONE; - s->val[OPT_CALIBRATION_FILE].s = NULL; + s->calibration_file.clear(); /* disable option if ran as root */ #ifdef HAVE_GETUID if(geteuid()==0) @@ -5630,7 +5606,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_EXPIRATION_TIME].unit = SANE_UNIT_NONE; s->opt[OPT_EXPIRATION_TIME].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_EXPIRATION_TIME].constraint.range = &expiration_range; - s->val[OPT_EXPIRATION_TIME].w = 60; /* 60 minutes by default */ + s->expiration_time = 60; // 60 minutes by default /* Powersave time (turn lamp off) */ s->opt[OPT_LAMP_OFF_TIME].name = "lamp-off-time"; @@ -5643,7 +5619,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_LAMP_OFF_TIME].unit = SANE_UNIT_NONE; s->opt[OPT_LAMP_OFF_TIME].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_LAMP_OFF_TIME].constraint.range = &time_range; - s->val[OPT_LAMP_OFF_TIME].w = 15; /* 15 minutes */ + s->lamp_off_time = 15; // 15 minutes /* turn lamp off during scan */ s->opt[OPT_LAMP_OFF].name = "lamp-off-scan"; @@ -5652,7 +5628,7 @@ init_options (Genesys_Scanner * s) s->opt[OPT_LAMP_OFF].type = SANE_TYPE_BOOL; s->opt[OPT_LAMP_OFF].unit = SANE_UNIT_NONE; s->opt[OPT_LAMP_OFF].constraint_type = SANE_CONSTRAINT_NONE; - s->val[OPT_LAMP_OFF].w = SANE_FALSE; + s->lamp_off = false; s->opt[OPT_SENSOR_GROUP].title = SANE_TITLE_SENSORS; s->opt[OPT_SENSOR_GROUP].desc = SANE_DESC_SENSORS; @@ -5671,8 +5647,6 @@ init_options (Genesys_Scanner * s) SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; else s->opt[OPT_SCAN_SW].cap = SANE_CAP_INACTIVE; - s->val[OPT_SCAN_SW].b = 0; - s->last_val[OPT_SCAN_SW].b = 0; /* SANE_NAME_FILE is not for buttons */ s->opt[OPT_FILE_SW].name = "file"; @@ -5685,8 +5659,6 @@ init_options (Genesys_Scanner * s) SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; else s->opt[OPT_FILE_SW].cap = SANE_CAP_INACTIVE; - s->val[OPT_FILE_SW].b = 0; - s->last_val[OPT_FILE_SW].b = 0; s->opt[OPT_EMAIL_SW].name = SANE_NAME_EMAIL; s->opt[OPT_EMAIL_SW].title = SANE_TITLE_EMAIL; @@ -5698,8 +5670,6 @@ init_options (Genesys_Scanner * s) SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; else s->opt[OPT_EMAIL_SW].cap = SANE_CAP_INACTIVE; - s->val[OPT_EMAIL_SW].b = 0; - s->last_val[OPT_EMAIL_SW].b = 0; s->opt[OPT_COPY_SW].name = SANE_NAME_COPY; s->opt[OPT_COPY_SW].title = SANE_TITLE_COPY; @@ -5711,8 +5681,6 @@ init_options (Genesys_Scanner * s) SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; else s->opt[OPT_COPY_SW].cap = SANE_CAP_INACTIVE; - s->val[OPT_COPY_SW].b = 0; - s->last_val[OPT_COPY_SW].b = 0; s->opt[OPT_PAGE_LOADED_SW].name = SANE_NAME_PAGE_LOADED; s->opt[OPT_PAGE_LOADED_SW].title = SANE_TITLE_PAGE_LOADED; @@ -5724,8 +5692,6 @@ init_options (Genesys_Scanner * s) SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; else s->opt[OPT_PAGE_LOADED_SW].cap = SANE_CAP_INACTIVE; - s->val[OPT_PAGE_LOADED_SW].b = 0; - s->last_val[OPT_PAGE_LOADED_SW].b = 0; /* OCR button */ s->opt[OPT_OCR_SW].name = "ocr"; @@ -5738,8 +5704,6 @@ init_options (Genesys_Scanner * s) SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; else s->opt[OPT_OCR_SW].cap = SANE_CAP_INACTIVE; - s->val[OPT_OCR_SW].b = 0; - s->last_val[OPT_OCR_SW].b = 0; /* power button */ s->opt[OPT_POWER_SW].name = "power"; @@ -5752,8 +5716,6 @@ init_options (Genesys_Scanner * s) SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; else s->opt[OPT_POWER_SW].cap = SANE_CAP_INACTIVE; - s->val[OPT_POWER_SW].b = 0; - s->last_val[OPT_POWER_SW].b = 0; /* extra button */ s->opt[OPT_EXTRA_SW].name = "extra"; @@ -5766,8 +5728,6 @@ init_options (Genesys_Scanner * s) SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; else s->opt[OPT_EXTRA_SW].cap = SANE_CAP_INACTIVE; - s->val[OPT_EXTRA_SW].b = 0; - s->last_val[OPT_EXTRA_SW].b = 0; /* calibration needed */ s->opt[OPT_NEED_CALIBRATION_SW].name = "need-calibration"; @@ -5780,8 +5740,6 @@ init_options (Genesys_Scanner * s) SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED; else s->opt[OPT_NEED_CALIBRATION_SW].cap = SANE_CAP_INACTIVE; - s->val[OPT_NEED_CALIBRATION_SW].b = 0; - s->last_val[OPT_NEED_CALIBRATION_SW].b = 0; /* button group */ s->opt[OPT_BUTTON_GROUP].title = SANE_I18N ("Buttons"); @@ -5804,8 +5762,6 @@ init_options (Genesys_Scanner * s) SANE_CAP_AUTOMATIC; else s->opt[OPT_CALIBRATE].cap = SANE_CAP_INACTIVE; - s->val[OPT_CALIBRATE].b = 0; - s->last_val[OPT_CALIBRATE].b = 0; /* clear calibration cache button */ s->opt[OPT_CLEAR_CALIBRATION].name = "clear-calibration"; @@ -5817,8 +5773,6 @@ init_options (Genesys_Scanner * s) s->opt[OPT_CLEAR_CALIBRATION].constraint_type = SANE_CONSTRAINT_NONE; s->opt[OPT_CLEAR_CALIBRATION].cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED; - s->val[OPT_CLEAR_CALIBRATION].b = 0; - s->last_val[OPT_CLEAR_CALIBRATION].b = 0; /* force calibration cache button */ s->opt[OPT_FORCE_CALIBRATION].name = "force-calibration"; @@ -5830,8 +5784,6 @@ init_options (Genesys_Scanner * s) s->opt[OPT_FORCE_CALIBRATION].constraint_type = SANE_CONSTRAINT_NONE; s->opt[OPT_FORCE_CALIBRATION].cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED; - s->val[OPT_FORCE_CALIBRATION].b = 0; - s->last_val[OPT_FORCE_CALIBRATION].b = 0; RIE (calc_parameters (s)); @@ -6492,7 +6444,7 @@ sane_open_impl(SANE_String_Const devicename, SANE_Handle * handle) if (s->dev->force_calibration == 0) { tmpstr=calibration_filename(s->dev); - s->val[OPT_CALIBRATION_FILE].s = strdup (tmpstr); + s->calibration_file = tmpstr; s->dev->calib_file = tmpstr; DBG(DBG_info, "%s: Calibration filename set to:\n", __func__); DBG(DBG_info, "%s: >%s<\n", __func__, s->dev->calib_file.c_str()); @@ -6574,9 +6526,6 @@ sane_close_impl(SANE_Handle handle) /* for an handful of bytes .. */ free ((void *)(size_t)s->opt[OPT_RESOLUTION].constraint.word_list); - free (s->val[OPT_SOURCE].s); - free (s->val[OPT_MODE].s); - free (s->val[OPT_COLOR_FILTER].s); free ((void *)(size_t)s->opt[OPT_TL_X].constraint.range); free ((void *)(size_t)s->opt[OPT_TL_Y].constraint.range); @@ -6636,7 +6585,6 @@ static SANE_Status get_option_value (Genesys_Scanner * s, int option, void *val) { unsigned int i; - SANE_Word tmp; SANE_Word* table = nullptr; std::vector gamma_table; unsigned option_size = 0; @@ -6649,64 +6597,99 @@ get_option_value (Genesys_Scanner * s, int option, void *val) { /* geometry */ case OPT_TL_X: + *reinterpret_cast(val) = s->pos_top_left_x; + break; case OPT_TL_Y: + *reinterpret_cast(val) = s->pos_top_left_y; + break; case OPT_BR_X: + *reinterpret_cast(val) = s->pos_bottom_right_x; + break; case OPT_BR_Y: - *(SANE_Word *) val = s->val[option].w; - /* switch coordinate to keep them coherent */ - if (s->val[OPT_TL_X].w >= s->val[OPT_BR_X].w) - { - tmp=s->val[OPT_BR_X].w; - s->val[OPT_BR_X].w=s->val[OPT_TL_X].w; - s->val[OPT_TL_X].w=tmp; - } - if (s->val[OPT_TL_Y].w >= s->val[OPT_BR_Y].w) - { - tmp=s->val[OPT_BR_Y].w; - s->val[OPT_BR_Y].w=s->val[OPT_TL_Y].w; - s->val[OPT_TL_Y].w=tmp; - } - break; + *reinterpret_cast(val) = s->pos_bottom_right_y; + break; /* word options: */ case OPT_NUM_OPTS: + *reinterpret_cast(val) = NUM_OPTIONS; + break; case OPT_RESOLUTION: + *reinterpret_cast(val) = s->resolution; + break; case OPT_BIT_DEPTH: + *reinterpret_cast(val) = s->bit_depth; + break; case OPT_PREVIEW: + *reinterpret_cast(val) = s->preview; + break; case OPT_THRESHOLD: + *reinterpret_cast(val) = s->threshold; + break; case OPT_THRESHOLD_CURVE: + *reinterpret_cast(val) = s->threshold_curve; + break; case OPT_DISABLE_DYNAMIC_LINEART: + *reinterpret_cast(val) = s->disable_dynamic_lineart; + break; case OPT_DISABLE_INTERPOLATION: + *reinterpret_cast(val) = s->disable_interpolation; + break; case OPT_LAMP_OFF: + *reinterpret_cast(val) = s->lamp_off; + break; case OPT_LAMP_OFF_TIME: + *reinterpret_cast(val) = s->lamp_off_time; + break; case OPT_SWDESKEW: + *reinterpret_cast(val) = s->swdeskew; + break; case OPT_SWCROP: + *reinterpret_cast(val) = s->swcrop; + break; case OPT_SWDESPECK: + *reinterpret_cast(val) = s->swdespeck; + break; case OPT_SWDEROTATE: + *reinterpret_cast(val) = s->swderotate; + break; case OPT_SWSKIP: + *reinterpret_cast(val) = s->swskip; + break; case OPT_DESPECK: + *reinterpret_cast(val) = s->despeck; + break; case OPT_CONTRAST: + *reinterpret_cast(val) = s->contrast; + break; case OPT_BRIGHTNESS: + *reinterpret_cast(val) = s->brightness; + break; case OPT_EXPIRATION_TIME: - *(SANE_Word *) val = s->val[option].w; - break; + *reinterpret_cast(val) = s->expiration_time; + break; case OPT_CUSTOM_GAMMA: - *(SANE_Word *) val = s->val[option].w; - break; + *reinterpret_cast(val) = s->custom_gamma; + break; /* string options: */ case OPT_MODE: + std::strcpy(reinterpret_cast(val), s->mode.c_str()); + break; case OPT_COLOR_FILTER: + std::strcpy(reinterpret_cast(val), s->color_filter.c_str()); + break; case OPT_CALIBRATION_FILE: + std::strcpy(reinterpret_cast(val), s->calibration_file.c_str()); + break; case OPT_SOURCE: - strcpy((char*) val, s->val[option].s); - break; + std::strcpy(reinterpret_cast(val), s->source.c_str()); + break; /* word array options */ case OPT_GAMMA_VECTOR: table = (SANE_Word *) val; - if (strcmp (s->val[OPT_COLOR_FILTER].s, "Red") == 0) { + if (s->color_filter == "Red") { gamma_table = get_gamma_table(s->dev, sensor, GENESYS_RED); - } else if (strcmp (s->val[OPT_COLOR_FILTER].s, "Blue") == 0) { + } else if (s->color_filter == "Blue") { gamma_table = get_gamma_table(s->dev, sensor, GENESYS_BLUE); } else { gamma_table = get_gamma_table(s->dev, sensor, GENESYS_GREEN); @@ -6762,8 +6745,7 @@ get_option_value (Genesys_Scanner * s, int option, void *val) case OPT_POWER_SW: case OPT_EXTRA_SW: RIE (s->dev->model->cmd_set->update_hardware_sensors (s)); - *(SANE_Bool *) val = s->val[option].b; - s->last_val[option].b = *(SANE_Bool *) val; + *(SANE_Bool *) val = s->buttons[genesys_option_to_button(option)].read(); break; case OPT_NEED_CALIBRATION_SW: /* scanner needs calibration for current mode unless a matching @@ -6787,7 +6769,7 @@ get_option_value (Genesys_Scanner * s, int option, void *val) /** @brief set calibration file value * Set calibration file value. Load new cache values from file if it exists, * else creates the file*/ -static SANE_Status set_calibration_value (Genesys_Scanner * s, int option, void *val) +static SANE_Status set_calibration_value(Genesys_Scanner* s, const char* val) { SANE_Status status=SANE_STATUS_GOOD; Genesys_Device *dev=s->dev; @@ -6796,7 +6778,7 @@ static SANE_Status set_calibration_value (Genesys_Scanner * s, int option, void /* try to load file */ std::string prev_calib_file = dev->calib_file; - dev->calib_file = (char*) val; + dev->calib_file = val; status=sanei_genesys_read_calibration (dev); /* file exists but is invalid, so fall back to previous cache file @@ -6808,11 +6790,8 @@ static SANE_Status set_calibration_value (Genesys_Scanner * s, int option, void return status; } - /* now we can set file name value */ - if (s->val[option].s) - free (s->val[option].s); - s->val[option].s = strdup((char*) val); - dev->calib_file = (char*) val; + s->calibration_file = val; + dev->calib_file = val; DBG(DBG_info, "%s: Calibration filename set to:\n", __func__); DBG(DBG_info, "%s: >%s<\n", __func__, s->dev->calib_file.c_str()); @@ -6837,48 +6816,109 @@ set_option_value (Genesys_Scanner * s, int option, void *val, switch (option) { case OPT_TL_X: + s->pos_top_left_x = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_TL_Y: + s->pos_top_left_y = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_BR_X: + s->pos_bottom_right_x = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_BR_Y: - s->val[option].w = *(SANE_Word *) val; - RIE (calc_parameters (s)); - *myinfo |= SANE_INFO_RELOAD_PARAMS; - break; + s->pos_bottom_right_y = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_RESOLUTION: + s->resolution = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_THRESHOLD: + s->threshold = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_THRESHOLD_CURVE: + s->threshold_curve = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_DISABLE_DYNAMIC_LINEART: + s->disable_dynamic_lineart = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_SWCROP: + s->swcrop = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_SWDESKEW: + s->swdeskew = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_DESPECK: + s->despeck = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_SWDEROTATE: + s->swderotate = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_SWSKIP: + s->swskip = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_DISABLE_INTERPOLATION: + s->disable_interpolation = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_LAMP_OFF: + s->lamp_off = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_PREVIEW: + s->preview = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_BRIGHTNESS: + s->brightness = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_CONTRAST: - s->val[option].w = *(SANE_Word *) val; - RIE (calc_parameters (s)); - *myinfo |= SANE_INFO_RELOAD_PARAMS; - break; + s->contrast = *reinterpret_cast(val); + RIE (calc_parameters(s)); + *myinfo |= SANE_INFO_RELOAD_PARAMS; + break; case OPT_SWDESPECK: - s->val[option].w = *(SANE_Word *) val; - if (s->val[OPT_SWDESPECK].b == SANE_TRUE) - { - ENABLE(OPT_DESPECK); - } - else - { - DISABLE(OPT_DESPECK); + s->swdespeck = *reinterpret_cast(val); + if (s->swdespeck) { + ENABLE(OPT_DESPECK); + } else { + DISABLE(OPT_DESPECK); } RIE (calc_parameters (s)); *myinfo |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS; break; /* software enhancement functions only apply to 8 or 1 bits data */ case OPT_BIT_DEPTH: - s->val[option].w = *(SANE_Word *) val; - if(s->val[OPT_BIT_DEPTH].w>8) + s->bit_depth = *reinterpret_cast(val); + if(s->bit_depth>8) { DISABLE(OPT_SWDESKEW); DISABLE(OPT_SWDESPECK); @@ -6904,14 +6944,11 @@ set_option_value (Genesys_Scanner * s, int option, void *val, *myinfo |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS; break; case OPT_SOURCE: - if (strcmp (s->val[option].s, (char*) val) != 0) - { /* something changed */ - if (s->val[option].s) - free (s->val[option].s); - s->val[option].s = strdup((char*) val); + if (s->source != reinterpret_cast(val)) { + s->source = reinterpret_cast(val); - /* change geometry constraint to the new source value */ - if (strcmp (s->val[option].s, FLATBED) == 0) + // change geometry constraint to the new source value + if (s->source == STR_FLATBED) { x_range=create_range(s->dev->model->x_size); y_range=create_range(s->dev->model->y_size); @@ -6930,24 +6967,22 @@ set_option_value (Genesys_Scanner * s, int option, void *val, free((void *)(size_t)s->opt[OPT_TL_X].constraint.range); free((void *)(size_t)s->opt[OPT_TL_Y].constraint.range); s->opt[OPT_TL_X].constraint.range = x_range; - s->val[OPT_TL_X].w = 0; + s->pos_top_left_x = 0; s->opt[OPT_TL_Y].constraint.range = y_range; - s->val[OPT_TL_Y].w = 0; + s->pos_top_left_y = 0; s->opt[OPT_BR_X].constraint.range = x_range; - s->val[OPT_BR_Y].w = y_range->max; + s->pos_bottom_right_x = x_range->max; s->opt[OPT_BR_Y].constraint.range = y_range; - s->val[OPT_BR_X].w = x_range->max; + s->pos_bottom_right_y = y_range->max; /* signals reload */ *myinfo |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS; } break; case OPT_MODE: - if (s->val[option].s) - free (s->val[option].s); - s->val[option].s = strdup((char*) val); + s->mode = reinterpret_cast(val); - if (strcmp (s->val[option].s, SANE_VALUE_SCAN_MODE_LINEART) == 0) + if (s->mode == SANE_VALUE_SCAN_MODE_LINEART) { ENABLE (OPT_THRESHOLD); ENABLE (OPT_THRESHOLD_CURVE); @@ -6963,7 +6998,7 @@ set_option_value (Genesys_Scanner * s, int option, void *val, DISABLE (OPT_THRESHOLD); DISABLE (OPT_THRESHOLD_CURVE); DISABLE (OPT_DISABLE_DYNAMIC_LINEART); - if (strcmp (s->val[option].s, SANE_VALUE_SCAN_MODE_GRAY) == 0) + if (s->mode == SANE_VALUE_SCAN_MODE_GRAY) { if (s->dev->model->asic_type != GENESYS_GL646 || !s->dev->model->is_cis) { @@ -6984,9 +7019,9 @@ set_option_value (Genesys_Scanner * s, int option, void *val, RIE (calc_parameters (s)); /* if custom gamma, toggle gamma table options according to the mode */ - if (s->val[OPT_CUSTOM_GAMMA].b == SANE_TRUE) + if (s->custom_gamma) { - if (strcmp (s->val[option].s, SANE_VALUE_SCAN_MODE_COLOR) == 0) + if (s->mode == SANE_VALUE_SCAN_MODE_COLOR) { DISABLE (OPT_GAMMA_VECTOR); ENABLE (OPT_GAMMA_VECTOR_R); @@ -7005,32 +7040,33 @@ set_option_value (Genesys_Scanner * s, int option, void *val, *myinfo |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS; break; case OPT_COLOR_FILTER: - if (s->val[option].s) - free (s->val[option].s); - s->val[option].s = strdup((char*) val); + s->color_filter = reinterpret_cast(val); RIE (calc_parameters (s)); break; case OPT_CALIBRATION_FILE: if (s->dev->force_calibration == 0) - RIE(set_calibration_value (s, option, val)); + RIE(set_calibration_value(s, reinterpret_cast(val))); break; case OPT_LAMP_OFF_TIME: + if (*reinterpret_cast(val) != s->lamp_off_time) { + s->lamp_off_time = *reinterpret_cast(val); + RIE(s->dev->model->cmd_set->set_powersaving(s->dev, s->lamp_off_time)); + } + break; case OPT_EXPIRATION_TIME: - if (*(SANE_Word *) val != s->val[option].w) - { - s->val[option].w = *(SANE_Word *) val; - RIE (s->dev->model->cmd_set-> - set_powersaving (s->dev, s->val[option].w)); + if (*reinterpret_cast(val) != s->expiration_time) { + s->expiration_time = *reinterpret_cast(val); + // BUG: this is most likely not intended behavior, found out during refactor + RIE(s->dev->model->cmd_set->set_powersaving(s->dev, s->expiration_time)); } - break; + break; case OPT_CUSTOM_GAMMA: *myinfo |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS; - s->val[OPT_CUSTOM_GAMMA].b = *(SANE_Bool *) val; + s->custom_gamma = *reinterpret_cast(val); - if (s->val[OPT_CUSTOM_GAMMA].b == SANE_TRUE) - { - if (strcmp (s->val[OPT_MODE].s, SANE_VALUE_SCAN_MODE_COLOR) == 0) + if (s->custom_gamma) { + if (s->mode == SANE_VALUE_SCAN_MODE_COLOR) { DISABLE (OPT_GAMMA_VECTOR); ENABLE (OPT_GAMMA_VECTOR_R); @@ -7247,7 +7283,7 @@ SANE_Status sane_get_parameters_impl(SANE_Handle handle, SANE_Parameters* params */ if (s->dev->model->is_sheetfed == SANE_TRUE && s->dev->buffer_image == SANE_FALSE - && s->val[OPT_BR_Y].w == s->opt[OPT_BR_Y].constraint.range->max) + && s->pos_bottom_right_y == s->opt[OPT_BR_Y].constraint.range->max) { params->lines = -1; } @@ -7273,12 +7309,12 @@ SANE_Status sane_start_impl(SANE_Handle handle) DBGSTART; - if (s->val[OPT_TL_X].w >= s->val[OPT_BR_X].w) + if (s->pos_top_left_x >= s->pos_bottom_right_x) { DBG(DBG_error0, "%s: top left x >= bottom right x --- exiting\n", __func__); return SANE_STATUS_INVAL; } - if (s->val[OPT_TL_Y].w >= s->val[OPT_BR_Y].w) + if (s->pos_top_left_y >= s->pos_bottom_right_y) { DBG(DBG_error0, "%s: top left y >= bottom right y --- exiting\n", __func__); return SANE_STATUS_INVAL; @@ -7288,7 +7324,7 @@ SANE_Status sane_start_impl(SANE_Handle handle) parameters will be overwritten below, but that's OK. */ RIE (calc_parameters (s)); - RIE (genesys_start_scan (s->dev, s->val[OPT_LAMP_OFF].w)); + RIE(genesys_start_scan(s->dev, s->lamp_off)); s->scanning = SANE_TRUE; @@ -7311,11 +7347,10 @@ SANE_Status sane_start_impl(SANE_Handle handle) /* check if we need to skip this page, sheetfed scanners * can go to next doc while flatbed ones can't */ - if (s->val[OPT_SWSKIP].w && IS_ACTIVE(OPT_SWSKIP)) - { + if (s->swskip > 0 && IS_ACTIVE(OPT_SWSKIP)) { status = sanei_magic_isBlank(&s->params, s->dev->img_buffer.data(), - SANE_UNFIX(s->val[OPT_SWSKIP].w)); + SANE_UNFIX(s->swskip)); if(status == SANE_STATUS_NO_DOCS) { if (s->dev->model->is_sheetfed == SANE_TRUE) @@ -7327,30 +7362,22 @@ SANE_Status sane_start_impl(SANE_Handle handle) } } - /* deskew image if required */ - if(s->val[OPT_SWDESKEW].b == SANE_TRUE) - { + if (s->swdeskew) { const auto& sensor = sanei_genesys_find_sensor(s->dev, s->dev->settings.xres, s->dev->settings.scan_method); RIE(genesys_deskew(s, sensor)); } - /* despeck image if required */ - if(s->val[OPT_SWDESPECK].b == SANE_TRUE) - { - RIE(genesys_despeck(s)); + if (s->swdespeck) { + RIE(genesys_despeck(s)); } - /* crop image if required */ - if(s->val[OPT_SWCROP].b == SANE_TRUE) - { - RIE(genesys_crop(s)); + if(s->swcrop) { + RIE(genesys_crop(s)); } - /* de-rotate image if required */ - if(s->val[OPT_SWDEROTATE].b == SANE_TRUE) - { - RIE(genesys_derotate(s)); + if(s->swderotate) { + RIE(genesys_derotate(s)); } } @@ -7633,3 +7660,18 @@ sane_get_select_fd(SANE_Handle handle, SANE_Int * fd) return sane_get_select_fd_impl(handle, fd); }); } + +GenesysButtonName genesys_option_to_button(int option) +{ + switch (option) { + case OPT_SCAN_SW: return BUTTON_SCAN_SW; + case OPT_FILE_SW: return BUTTON_FILE_SW; + case OPT_EMAIL_SW: return BUTTON_EMAIL_SW; + case OPT_COPY_SW: return BUTTON_COPY_SW; + case OPT_PAGE_LOADED_SW: return BUTTON_PAGE_LOADED_SW; + case OPT_OCR_SW: return BUTTON_OCR_SW; + case OPT_POWER_SW: return BUTTON_POWER_SW; + case OPT_EXTRA_SW: return BUTTON_EXTRA_SW; + default: throw std::runtime_error("Unknown option to convert to button index"); + } +} diff --git a/backend/genesys.h b/backend/genesys.h index fc01d863e..0f13eadf5 100644 --- a/backend/genesys.h +++ b/backend/genesys.h @@ -52,6 +52,7 @@ #endif #include "genesys_low.h" +#include #ifndef PATH_MAX # define PATH_MAX 1024 @@ -73,8 +74,9 @@ /* Maximum time for lamp warm-up */ #define WARMUP_TIME 65 -#define FLATBED "Flatbed" -#define TRANSPARENCY_ADAPTER "Transparency Adapter" +#define STR_FLATBED "Flatbed" +#define STR_TRANSPARENCY_ADAPTER "Transparency Adapter" +#define STR_TRANSPARENCY_ADAPTER_INFRARED "Transparency Adapter Infrared" #ifndef SANE_I18N #define SANE_I18N(text) text @@ -145,6 +147,45 @@ enum Genesys_Option NUM_OPTIONS }; +enum GenesysButtonName : unsigned { + BUTTON_SCAN_SW = 0, + BUTTON_FILE_SW, + BUTTON_EMAIL_SW, + BUTTON_COPY_SW, + BUTTON_PAGE_LOADED_SW, + BUTTON_OCR_SW, + BUTTON_POWER_SW, + BUTTON_EXTRA_SW, + NUM_BUTTONS +}; + +GenesysButtonName genesys_option_to_button(int option); + +class GenesysButton { +public: + void write(bool value) + { + if (value == value_) { + return; + } + values_to_read_.push(value); + value_ = value; + } + + bool read() + { + if (values_to_read_.empty()) { + return value_; + } + bool ret = values_to_read_.front(); + values_to_read_.pop(); + return ret; + } + +private: + bool value_ = false; + std::queue values_to_read_; +}; /** Scanner object. Should have better be called Session than Scanner */ @@ -164,10 +205,39 @@ struct Genesys_Scanner SANE_Bool scanning; // Option descriptors SANE_Option_Descriptor opt[NUM_OPTIONS]; + // Option values - Option_Value val[NUM_OPTIONS]; - // Option values as read by the frontend. used for sensors. - Option_Value last_val[NUM_OPTIONS]; + SANE_Word bit_depth = 0; + SANE_Word resolution = 0; + bool preview = false; + SANE_Word threshold = 0; + SANE_Word threshold_curve = 0; + bool disable_dynamic_lineart = false; + bool disable_interpolation = false; + bool lamp_off = false; + SANE_Word lamp_off_time = 0; + bool swdeskew = false; + bool swcrop = false; + bool swdespeck = false; + bool swderotate = false; + SANE_Word swskip = 0; + SANE_Word despeck = 0; + SANE_Word contrast = 0; + SANE_Word brightness = 0; + SANE_Word expiration_time = 0; + bool custom_gamma = false; + + SANE_Word pos_top_left_y = 0; + SANE_Word pos_top_left_x = 0; + SANE_Word pos_bottom_right_y = 0; + SANE_Word pos_bottom_right_x = 0; + + std::string mode, source, color_filter; + + std::string calibration_file; + // Button states + GenesysButton buttons[NUM_BUTTONS]; + // SANE Parameters SANE_Parameters params = {}; SANE_Int bpp_list[5] = {}; diff --git a/backend/genesys_conv.cc b/backend/genesys_conv.cc index 3a4180ed0..db87dd941 100644 --- a/backend/genesys_conv.cc +++ b/backend/genesys_conv.cc @@ -428,7 +428,7 @@ genesys_despeck(Genesys_Scanner *s) { if(sanei_magic_despeck(&s->params, s->dev->img_buffer.data(), - s->val[OPT_DESPECK].w)!=SANE_STATUS_GOOD) + s->despeck)!=SANE_STATUS_GOOD) { DBG (DBG_error, "%s: bad despeck, bailing\n",__func__); } @@ -443,13 +443,12 @@ genesys_derotate (Genesys_Scanner * s) { SANE_Status status; int angle = 0; - int resolution = s->val[OPT_RESOLUTION].w; DBGSTART; status = sanei_magic_findTurn (&s->params, s->dev->img_buffer.data(), - resolution, - resolution, + s->resolution, + s->resolution, &angle); if (status) diff --git a/backend/genesys_devices.cc b/backend/genesys_devices.cc index 8ae18e0a0..b2a10a2ca 100644 --- a/backend/genesys_devices.cc +++ b/backend/genesys_devices.cc @@ -1357,12 +1357,12 @@ void genesys_init_sensor_tables() int min_resolution; int max_resolution; int exposure; - int is_transparency; + ScanMethod method; GenesysRegisterSettingSet extra_custom_regs; }; CustomSensorSettings custom_settings[] = { - { -1, 600, 8016, false, { + { -1, 600, 8016, ScanMethod::FLATBED, { { 0x74, 0x00 }, { 0x75, 0x01 }, { 0x76, 0xff }, { 0x77, 0x03 }, { 0x78, 0xff }, { 0x79, 0xff }, { 0x7a, 0x03 }, { 0x7b, 0xff }, { 0x7c, 0xff }, @@ -1390,7 +1390,7 @@ void genesys_init_sensor_tables() { 0x5a, 0x40 }, } }, - { 1200, 1200, 56064, false, { + { 1200, 1200, 56064, ScanMethod::FLATBED, { { 0x74, 0x0f }, { 0x75, 0xff }, { 0x76, 0xff }, { 0x77, 0x00 }, { 0x78, 0x01 }, { 0x79, 0xff }, { 0x7a, 0x00 }, { 0x7b, 0x01 }, { 0x7c, 0xff }, @@ -1418,7 +1418,7 @@ void genesys_init_sensor_tables() { 0x5a, 0x40 }, } }, - { 2400, 2400, 56064, false, { + { 2400, 2400, 56064, ScanMethod::FLATBED, { { 0x74, 0x0f }, { 0x75, 0xff }, { 0x76, 0xff }, { 0x77, 0x00 }, { 0x78, 0x00 }, { 0x79, 0x00 }, { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x00 }, @@ -1446,7 +1446,7 @@ void genesys_init_sensor_tables() { 0x5a, 0x40 }, } }, - { 4800, 4800, 42752, false, { + { 4800, 4800, 42752, ScanMethod::FLATBED, { { 0x74, 0x0f }, { 0x75, 0xff }, { 0x76, 0xff }, { 0x77, 0x00 }, { 0x78, 0x00 }, { 0x79, 0x00 }, { 0x7a, 0x00 }, { 0x7b, 0x00 }, { 0x7c, 0x00 }, @@ -1474,7 +1474,7 @@ void genesys_init_sensor_tables() { 0x5a, 0x40 }, } }, - { -1, -1, 15624, true, { + { -1, -1, 15624, ScanMethod::TRANSPARENCY, { { 0x74, 0x00 }, { 0x75, 0x1c }, { 0x76, 0x7f }, { 0x77, 0x03 }, { 0x78, 0xff }, { 0x79, 0xff }, { 0x7a, 0x03 }, { 0x7b, 0xff }, { 0x7c, 0xff }, @@ -1510,7 +1510,7 @@ void genesys_init_sensor_tables() sensor.min_resolution = setting.min_resolution; sensor.max_resolution = setting.max_resolution; sensor.exposure_lperiod = setting.exposure; - sensor.is_transparency = setting.is_transparency; + sensor.method = setting.method; sensor.custom_regs = base_custom_regs; sensor.custom_regs.merge(setting.extra_custom_regs); s_sensors->push_back(sensor); @@ -1626,13 +1626,13 @@ void genesys_init_sensor_tables() int min_resolution; int max_resolution; int exposure; - int is_transparency; + ScanMethod method; GenesysRegisterSettingSet extra_custom_regs; GenesysRegisterSettingSet custom_fe_regs; }; CustomSensorSettings custom_settings[] = { - { -1, 1200, 0x5dc0, false, { + { -1, 1200, 0x5dc0, ScanMethod::FLATBED, { { 0x74, 0x03 }, { 0x75, 0xf0 }, { 0x76, 0xf0 }, { 0x77, 0x03 }, { 0x78, 0xfe }, { 0x79, 0x00 }, { 0x7a, 0x00 }, { 0x7b, 0x92 }, { 0x7c, 0x49 }, @@ -1661,7 +1661,7 @@ void genesys_init_sensor_tables() }, {}, }, - { -1, 1200, 0x5dc0, true, { + { -1, 1200, 0x5dc0, ScanMethod::TRANSPARENCY, { { 0x74, 0x03 }, { 0x75, 0xf0 }, { 0x76, 0xf0 }, { 0x77, 0x03 }, { 0x78, 0xfe }, { 0x79, 0x00 }, { 0x7a, 0x00 }, { 0x7b, 0x92 }, { 0x7c, 0x49 }, @@ -1690,7 +1690,7 @@ void genesys_init_sensor_tables() }, {}, }, - { 2400, 2400, 0x5dc0, true, { + { 2400, 2400, 0x5dc0, ScanMethod::TRANSPARENCY, { { 0x74, 0x03 }, { 0x75, 0xfe }, { 0x76, 0x00 }, { 0x77, 0x03 }, { 0x78, 0xfe }, { 0x79, 0x00 }, { 0x7a, 0x00 }, { 0x7b, 0x92 }, { 0x7c, 0x49 }, @@ -1719,7 +1719,7 @@ void genesys_init_sensor_tables() }, {}, }, - { 4800, 4800, 0x5dc0, true, { + { 4800, 4800, 0x5dc0, ScanMethod::TRANSPARENCY, { { 0x74, 0x03 }, { 0x75, 0xff }, { 0x76, 0xff }, { 0x77, 0x03 }, { 0x78, 0xff }, { 0x79, 0xff }, { 0x7a, 0x00 }, { 0x7b, 0x92 }, { 0x7c, 0x49 }, @@ -1758,7 +1758,7 @@ void genesys_init_sensor_tables() { sensor.min_resolution = setting.min_resolution; sensor.max_resolution = setting.max_resolution; - sensor.is_transparency = setting.is_transparency; + sensor.method = setting.method; sensor.exposure_lperiod = setting.exposure; sensor.custom_regs = base_custom_regs; sensor.custom_regs.merge(setting.extra_custom_regs); diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index 90fd2d359..ce763649f 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -687,7 +687,7 @@ gl124_init_motor_regs_scan (Genesys_Device * dev, unsigned int scan_lines, unsigned int scan_dummy, unsigned int feed_steps, - int scan_mode, + ScanColorMode scan_mode, unsigned int flags) { SANE_Status status; @@ -705,7 +705,8 @@ gl124_init_motor_regs_scan (Genesys_Device * dev, DBGSTART; DBG(DBG_info, "%s : scan_exposure_time=%d, scan_yres=%g, scan_step_type=%d, scan_lines=%d, " "scan_dummy=%d, feed_steps=%d, scan_mode=%d, flags=%x\n", __func__, scan_exposure_time, - scan_yres, scan_step_type, scan_lines, scan_dummy, feed_steps, scan_mode, flags); + scan_yres, scan_step_type, scan_lines, scan_dummy, feed_steps, + static_cast(scan_mode), flags); /* we never use fast fed since we do manual feed for the scans */ use_fast_fed=0; @@ -713,7 +714,7 @@ gl124_init_motor_regs_scan (Genesys_Device * dev, /* enforce motor minimal scan speed * @TODO extend motor struct for this value */ - if (scan_mode == SCAN_MODE_COLOR) + if (scan_mode == ScanColorMode::COLOR_SINGLE_PASS) { min_speed = 900; } @@ -759,7 +760,6 @@ gl124_init_motor_regs_scan (Genesys_Device * dev, /* compute register 02 value */ uint8_t r02 = REG02_NOTHOME; - r02 |= REG02_MTRPWR; if (use_fast_fed) { r02 |= REG02_FASTFED; @@ -777,6 +777,7 @@ gl124_init_motor_regs_scan (Genesys_Device * dev, } reg->set8(REG02, r02); + sanei_genesys_set_motor_power(*reg, true); /* SCANFED */ sanei_genesys_set_double(reg,REG_SCANFED,4); @@ -801,7 +802,7 @@ gl124_init_motor_regs_scan (Genesys_Device * dev, fast_dpi=yres; /* - if (scan_mode != SCAN_MODE_COLOR) + if (scan_mode != ScanColorMode::COLOR_SINGLE_PASS) { fast_dpi*=3; } @@ -990,7 +991,7 @@ gl124_init_optical_regs_scan (Genesys_Device * dev, int channels, int depth, SANE_Bool half_ccd, - int color_filter, + ColorFilter color_filter, int flags) { unsigned int words_per_line, segcnt; @@ -1065,10 +1066,7 @@ gl124_init_optical_regs_scan (Genesys_Device * dev, DBG (DBG_io, "%s: enabling AVEENB\n", __func__); } - if (flags & OPTICAL_FLAG_DISABLE_LAMP) - r->value &= ~REG03_LAMPPWR; - else - r->value |= REG03_LAMPPWR; + sanei_genesys_set_lamp_power(dev, sensor, *reg, !(flags & OPTICAL_FLAG_DISABLE_LAMP)); /* BW threshold */ RIE (sanei_genesys_write_register (dev, REG114, dev->settings.threshold)); @@ -1096,15 +1094,17 @@ gl124_init_optical_regs_scan (Genesys_Device * dev, { switch (color_filter) { - case 0: - r->value |= 0x10; /* red filter */ - break; - case 2: - r->value |= 0x30; /* blue filter */ - break; - default: - r->value |= 0x20; /* green filter */ - break; + case ColorFilter::RED: + r->value |= 0x10; + break; + case ColorFilter::BLUE: + r->value |= 0x30; + break; + case ColorFilter::GREEN: + r->value |= 0x20; + break; + default: + break; // should not happen } } @@ -1252,24 +1252,12 @@ gl124_init_optical_regs_scan (Genesys_Device * dev, * * this function sets up the scanner to scan in normal or single line mode */ -static -SANE_Status -gl124_init_scan_regs (Genesys_Device * dev, - const Genesys_Sensor& sensor, - Genesys_Register_Set * reg, - float xres, /*dpi */ - float yres, /*dpi */ - float startx, /*optical_res, from dummy_pixel+1 */ - float starty, /*base_ydpi, from home! */ - float pixels, - float lines, - unsigned int depth, - unsigned int channels, - __sane_unused__ int scan_method, - int scan_mode, - int color_filter, - unsigned int flags) +static SANE_Status +gl124_init_scan_regs(Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Register_Set* reg, + SetupParams& params) { + params.assert_valid(); + int used_res; int start, used_pixels; int bytes_per_line; @@ -1286,20 +1274,13 @@ gl124_init_scan_regs (Genesys_Device * dev, size_t requested_buffer_size, read_buffer_size; SANE_Bool half_ccd; /* false: full CCD res is used, true, half max CCD res is used */ - int optical_res; + unsigned optical_res; SANE_Status status; - DBG(DBG_info, - "%s:\n" - "Resolution : %gDPI/%gDPI\n" - "Lines : %g\n" - "PPL : %g\n" - "Startpos : %g/%g\n" - "Depth/Channels: %u/%u\n" - "Flags : %x\n\n", - __func__, xres, yres, lines, pixels, startx, starty, depth, channels, flags); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, params); - half_ccd=compute_half_ccd(sensor, xres); + half_ccd=compute_half_ccd(sensor, params.xres); /* optical_res */ optical_res = sensor.optical_res; @@ -1309,13 +1290,13 @@ gl124_init_scan_regs (Genesys_Device * dev, /* stagger */ if ((!half_ccd) && (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE)) - stagger = (4 * yres) / dev->motor.base_ydpi; + stagger = (4 * params.yres) / dev->motor.base_ydpi; else stagger = 0; DBG (DBG_info, "gl124_init_scan_regs : stagger=%d lines\n", stagger); /** @brief compute used resolution */ - if (flags & SCAN_FLAG_USE_OPTICAL_RES) + if (params.flags & SCAN_FLAG_USE_OPTICAL_RES) { used_res = optical_res; } @@ -1323,10 +1304,10 @@ gl124_init_scan_regs (Genesys_Device * dev, { /* resolution is choosen from a fixed list and can be used directly, * unless we have ydpi higher than sensor's maximum one */ - if(xres>optical_res) + if(params.xres>optical_res) used_res=optical_res; else - used_res = xres; + used_res = params.xres; } /* compute scan parameters values */ @@ -1334,17 +1315,17 @@ gl124_init_scan_regs (Genesys_Device * dev, /* use detected left margin and fixed value */ /* start */ /* add x coordinates */ - start = startx; + start = params.startx; if (stagger > 0) start |= 1; /* compute correct pixels number */ - used_pixels = (pixels * optical_res) / xres; + used_pixels = (params.pixels * optical_res) / params.xres; DBG (DBG_info, "%s: used_pixels=%d\n", __func__, used_pixels); /* round up pixels number if needed */ - if (used_pixels * xres < pixels * optical_res) + if (used_pixels * params.xres < params.pixels * optical_res) used_pixels++; /* we want even number of pixels here */ @@ -1354,12 +1335,12 @@ gl124_init_scan_regs (Genesys_Device * dev, /* slope_dpi */ /* cis color scan is effectively a gray scan with 3 gray lines per color line and a FILTER of 0 */ if (dev->model->is_cis) - slope_dpi = yres * channels; + slope_dpi = params.yres * params.channels; else - slope_dpi = yres; + slope_dpi = params.yres; /* scan_step_type */ - if(flags & SCAN_FLAG_FEEDING) + if(params.flags & SCAN_FLAG_FEEDING) { scan_step_type=0; exposure_time=MOVE_EXPOSURE; @@ -1376,22 +1357,21 @@ gl124_init_scan_regs (Genesys_Device * dev, /*** optical parameters ***/ /* in case of dynamic lineart, we use an internal 8 bit gray scan * to generate 1 lineart data */ - if ((flags & SCAN_FLAG_DYNAMIC_LINEART) && (scan_mode == SCAN_MODE_LINEART)) - { - depth = 8; + if (params.flags & SCAN_FLAG_DYNAMIC_LINEART) { + params.depth = 8; } /* we enable true gray for cis scanners only, and just when doing * scan since color calibration is OK for this mode */ oflags = 0; - if (flags & SCAN_FLAG_DISABLE_SHADING) + if (params.flags & SCAN_FLAG_DISABLE_SHADING) oflags |= OPTICAL_FLAG_DISABLE_SHADING; - if (flags & SCAN_FLAG_DISABLE_GAMMA) + if (params.flags & SCAN_FLAG_DISABLE_GAMMA) oflags |= OPTICAL_FLAG_DISABLE_GAMMA; - if (flags & SCAN_FLAG_DISABLE_LAMP) + if (params.flags & SCAN_FLAG_DISABLE_LAMP) oflags |= OPTICAL_FLAG_DISABLE_LAMP; - if (flags & SCAN_FLAG_CALIBRATION) + if (params.flags & SCAN_FLAG_CALIBRATION) oflags |= OPTICAL_FLAG_DISABLE_DOUBLE; if (dev->model->is_cis && dev->settings.true_gray) @@ -1407,10 +1387,10 @@ gl124_init_scan_regs (Genesys_Device * dev, used_res, start, used_pixels, - channels, - depth, + params.channels, + params.depth, half_ccd, - color_filter, + params.color_filter, oflags); if (status != SANE_STATUS_GOOD) return status; @@ -1418,19 +1398,19 @@ gl124_init_scan_regs (Genesys_Device * dev, /*** motor parameters ***/ /* max_shift */ - max_shift=sanei_genesys_compute_max_shift(dev,channels,yres,flags); + max_shift=sanei_genesys_compute_max_shift(dev,params.channels,params.yres,params.flags); /* lines to scan */ - lincnt = lines + max_shift + stagger; + lincnt = params.lines + max_shift + stagger; /* add tl_y to base movement */ - move = starty; + move = params.starty; DBG(DBG_info, "%s: move=%d steps\n", __func__, move); mflags=0; - if(flags & SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE) + if(params.flags & SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE) mflags|=MOTOR_FLAG_DISABLE_BUFFER_FULL_MOVE; - if(flags & SCAN_FLAG_FEEDING) + if(params.flags & SCAN_FLAG_FEEDING) mflags|=MOTOR_FLAG_FEED; status = gl124_init_motor_regs_scan (dev, sensor, @@ -1438,10 +1418,10 @@ gl124_init_scan_regs (Genesys_Device * dev, exposure_time, slope_dpi, scan_step_type, - dev->model->is_cis ? lincnt * channels : lincnt, + dev->model->is_cis ? lincnt * params.channels : lincnt, dummy, move, - scan_mode, + params.scan_mode, mflags); if (status != SANE_STATUS_GOOD) return status; @@ -1450,7 +1430,7 @@ gl124_init_scan_regs (Genesys_Device * dev, /* words_per_line */ bytes_per_line = (used_pixels * used_res) / optical_res; - bytes_per_line = (bytes_per_line * channels * depth) / 8; + bytes_per_line = (bytes_per_line * params.channels * params.depth) / 8; /* since we don't have sheetfed scanners to handle, * use huge read buffer */ @@ -1459,7 +1439,7 @@ gl124_init_scan_regs (Genesys_Device * dev, read_buffer_size = 2 * requested_buffer_size + - ((max_shift + stagger) * used_pixels * channels * depth) / 8; + ((max_shift + stagger) * used_pixels * params.channels * params.depth) / 8; dev->read_buffer.clear(); dev->read_buffer.alloc(read_buffer_size); @@ -1471,7 +1451,7 @@ gl124_init_scan_regs (Genesys_Device * dev, dev->shrink_buffer.alloc(requested_buffer_size); dev->out_buffer.clear(); - dev->out_buffer.alloc((8 * dev->settings.pixels * channels * depth) / 8); + dev->out_buffer.alloc((8 * dev->settings.pixels * params.channels * params.depth) / 8); dev->read_bytes_left = bytes_per_line * lincnt; @@ -1479,27 +1459,28 @@ gl124_init_scan_regs (Genesys_Device * dev, dev->read_active = SANE_TRUE; + dev->current_setup.params = params; dev->current_setup.pixels = (used_pixels * used_res) / optical_res; DBG(DBG_info, "%s: current_setup.pixels=%d\n", __func__, dev->current_setup.pixels); dev->current_setup.lines = lincnt; - dev->current_setup.depth = depth; - dev->current_setup.channels = channels; + dev->current_setup.depth = params.depth; + dev->current_setup.channels = params.channels; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = used_res; - dev->current_setup.yres = yres; + dev->current_setup.yres = params.yres; dev->current_setup.ccd_size_divisor = half_ccd ? 2 : 1; dev->current_setup.stagger = stagger; dev->current_setup.max_shift = max_shift + stagger; dev->total_bytes_read = 0; - if (depth == 1) + if (params.depth == 1) dev->total_bytes_to_read = ((dev->settings.pixels * dev->settings.lines) / 8 + (((dev->settings.pixels * dev->settings.lines) % 8) ? 1 : 0)) * - channels; + params.channels; else dev->total_bytes_to_read = - dev->settings.pixels * dev->settings.lines * channels * (depth / 8); + dev->settings.pixels * dev->settings.lines * params.channels * (params.depth / 8); DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); @@ -1514,12 +1495,6 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso int depth; int start; - float xres; /*dpi */ - float yres; /*dpi */ - float startx; /*optical_res, from dummy_pixel+1 */ - float pixels; - float lines; - int used_res; int used_pixels; unsigned int lincnt; @@ -1531,27 +1506,18 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso int optical_res; - DBG(DBG_info, - "%s:\n" - "Resolution: %ux%uDPI\n" - "Lines : %u\n" - "PPL : %u\n" - "Startpos : %.3f/%.3f\n" - "Scan mode : %d\n\n", - __func__, - dev->settings.xres, - dev->settings.yres, dev->settings.lines, dev->settings.pixels, - dev->settings.tl_x, dev->settings.tl_y, dev->settings.scan_mode); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, dev->settings); /* channels */ - if (dev->settings.scan_mode == 4) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; else channels = 1; /* depth */ depth = dev->settings.depth; - if (dev->settings.scan_mode == 0) + if (dev->settings.scan_mode == ScanColorMode::LINEART) depth = 1; /* start */ @@ -1559,30 +1525,30 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso start += dev->settings.tl_x; start = (start * sensor.optical_res) / MM_PER_INCH; + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = start; + params.starty = 0; // not used + params.pixels = dev->settings.pixels; + params.lines = dev->settings.lines; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = 0; - xres = dev->settings.xres; - yres = dev->settings.yres; - startx = start; - pixels = dev->settings.pixels; - lines = dev->settings.lines; + half_ccd=compute_half_ccd(sensor, params.xres); - half_ccd=compute_half_ccd(sensor, xres); - - DBG(DBG_info, - "%s:\n" - "Resolution : %gDPI/%gDPI\n" - "Lines : %g\n" - "PPL : %g\n" - "Startpos : %g\n" - "Half ccd : %d\n" - "Depth/Channels: %u/%u\n\n", - __func__, xres, yres, lines, pixels, startx, depth, half_ccd, channels); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, params); /* optical_res */ optical_res = sensor.optical_res; - if(xres<=optical_res) - used_res = xres; + if (params.xres <= (unsigned) optical_res) + used_res = params.xres; else used_res=optical_res; @@ -1591,15 +1557,15 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso /* use detected left margin and fixed value */ /* compute correct pixels number */ - used_pixels = (pixels * optical_res) / xres; + used_pixels = (params.pixels * optical_res) / params.xres; DBG (DBG_info, "%s: used_pixels=%d\n", __func__, used_pixels); /* exposure */ - exposure_time = gl124_compute_exposure (dev, xres, half_ccd); + exposure_time = gl124_compute_exposure (dev, params.xres, half_ccd); DBG (DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); /* max_shift */ - max_shift=sanei_genesys_compute_max_shift(dev,channels,yres,0); + max_shift=sanei_genesys_compute_max_shift(dev, params.channels, params.yres, 0); /* compute hw dpi for sensor */ dpihw=sanei_genesys_compute_dpihw(dev, sensor,used_res); @@ -1609,22 +1575,23 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso /* stagger */ if ((!half_ccd) && (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE)) - stagger = (4 * yres) / dev->motor.base_ydpi; + stagger = (4 * params.yres) / dev->motor.base_ydpi; else stagger = 0; DBG (DBG_info, "%s: stagger=%d lines\n", __func__, stagger); /* lincnt */ - lincnt = lines + max_shift + stagger; + lincnt = params.lines + max_shift + stagger; + dev->current_setup.params = params; dev->current_setup.pixels = (used_pixels * used_res) / optical_res; DBG (DBG_info, "%s: current_setup.pixels=%d\n", __func__, dev->current_setup.pixels); dev->current_setup.lines = lincnt; - dev->current_setup.depth = depth; - dev->current_setup.channels = channels; + dev->current_setup.depth = params.depth; + dev->current_setup.channels = params.channels; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = used_res; - dev->current_setup.yres = yres; + dev->current_setup.yres = params.yres; dev->current_setup.ccd_size_divisor = half_ccd ? 2 : 1; dev->current_setup.stagger = stagger; dev->current_setup.max_shift = max_shift + stagger; @@ -1633,52 +1600,6 @@ gl124_calculate_current_setup (Genesys_Device * dev, const Genesys_Sensor& senso return SANE_STATUS_GOOD; } -static void -gl124_set_motor_power (Genesys_Register_Set * regs, SANE_Bool set) -{ - - DBG(DBG_proc, "%s\n", __func__); - - if (set) - { - sanei_genesys_set_reg_from_set (regs, REG02, - sanei_genesys_read_reg_from_set (regs, - REG02) - | REG02_MTRPWR); - } - else - { - sanei_genesys_set_reg_from_set (regs, REG02, - sanei_genesys_read_reg_from_set (regs, - REG02) - & ~REG02_MTRPWR); - } -} - -static void -gl124_set_lamp_power (Genesys_Device * dev, const Genesys_Sensor& sensor, - Genesys_Register_Set * regs, SANE_Bool set) -{ - (void) sensor; - if (dev == NULL || regs==NULL) - return; - - if (set) - { - sanei_genesys_set_reg_from_set (regs, 0x03, - sanei_genesys_read_reg_from_set (regs, - 0x03) - | REG03_LAMPPWR); - } - else - { - sanei_genesys_set_reg_from_set (regs, 0x03, - sanei_genesys_read_reg_from_set (regs, - 0x03) - & ~REG03_LAMPPWR); - } -} - /** * for fast power saving methods only, like disabling certain amplifiers * @param dev device to use @@ -2046,22 +1967,24 @@ gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) const auto& sensor = sanei_genesys_find_sensor_any(dev); - status = gl124_init_scan_regs (dev, sensor, - &local_reg, - resolution, - resolution, - 100, - 30000, - 100, - 100, - 8, - 1, - dev->settings.scan_method, - SCAN_MODE_GRAY, - 0, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 100; + params.starty = 30000; + params.pixels = 100; + params.lines = 100; + params.depth = 8; + params.channels = 1; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::GRAY; + params.color_filter = ColorFilter::RED; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl124_init_scan_regs(dev, sensor, &local_reg, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to set up registers: %s\n", __func__, sane_strstatus(status)); @@ -2151,24 +2074,26 @@ gl124_feed (Genesys_Device * dev, unsigned int steps, int reverse) resolution=sanei_genesys_get_lowest_ydpi(dev); const auto& sensor = sanei_genesys_find_sensor(dev, resolution); - status = gl124_init_scan_regs (dev, sensor, - &local_reg, - resolution, - resolution, - 0, - steps, - 100, - 3, - 8, - 3, - dev->settings.scan_method, - SCAN_MODE_COLOR, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_FEEDING | - SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 0; + params.starty = steps; + params.pixels = 100; + params.lines = 3; + params.depth = 8; + params.channels = 3; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_FEEDING | + SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl124_init_scan_regs(dev, sensor, &local_reg, params); + if (status != SANE_STATUS_GOOD) { DBG (DBG_error, "%s: failed to set up registers: %s\n", __func__, sane_strstatus (status)); @@ -2248,23 +2173,25 @@ gl124_search_start_position (Genesys_Device * dev) // whith employ different sensors with potentially different settings. auto& sensor = sanei_genesys_find_sensor_for_write(dev, dpi); - status = gl124_init_scan_regs (dev, sensor, - &local_reg, - dpi, - dpi, - 0, - 0, /*we should give a small offset here~60 steps */ - 600, - dev->model->search_lines, - 8, - 1, - dev->settings.scan_method, - SCAN_MODE_GRAY, - 1, /*green */ - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_IGNORE_LINE_DISTANCE | - SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE); + SetupParams params; + params.xres = dpi; + params.yres = dpi; + params.startx = 0; + params.starty = 0; /*we should give a small offset here~60 steps */ + params.pixels = 600; + params.lines = dev->model->search_lines; + params.depth = 8; + params.channels = 1; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::GRAY; + params.color_filter = ColorFilter::GREEN; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_IGNORE_LINE_DISTANCE | + SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE; + + status = gl124_init_scan_regs(dev, sensor, &local_reg, params); + if (status!=SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to init scan registers: %s\n", __func__, sane_strstatus(status)); @@ -2335,50 +2262,54 @@ gl124_search_start_position (Genesys_Device * dev) * sets up register for coarse gain calibration * todo: check it for scanners using it */ static SANE_Status -gl124_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl124_init_regs_for_coarse_calibration(Genesys_Device* dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status; uint8_t channels; uint8_t cksel; DBGSTART; - cksel = (dev->calib_reg.find_reg(0x18).value & REG18_CKSEL) + 1; /* clock speed = 1..4 clocks */ + cksel = (regs.find_reg(0x18).value & REG18_CKSEL) + 1; /* clock speed = 1..4 clocks */ /* set line size */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ - channels = 3; - else - channels = 1; + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) { + channels = 3; + } else { + channels = 1; + } + + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = 0; + params.starty = 0; + params.pixels = sensor.optical_res / cksel; + params.lines = 20; + params.depth = 16; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_FEEDING | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl124_init_scan_regs(dev, sensor, ®s, params); - status = gl124_init_scan_regs (dev, sensor, - &dev->calib_reg, - dev->settings.xres, - dev->settings.yres, - 0, - 0, - sensor.optical_res / cksel, - 20, - 16, - channels, - dev->settings.scan_method, - dev->settings.scan_mode, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_FEEDING | - SCAN_FLAG_IGNORE_LINE_DISTANCE); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus(status)); return status; } - gl124_set_motor_power(&dev->calib_reg, SANE_FALSE); + sanei_genesys_set_motor_power(regs, false); DBG(DBG_info, "%s: optical sensor res: %d dpi, actual res: %d\n", __func__, sensor.optical_res / cksel, dev->settings.xres); - status = dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg); + status = dev->model->cmd_set->bulk_write_register(dev, regs); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to bulk write registers: %s\n", __func__, sane_strstatus(status)); @@ -2393,7 +2324,8 @@ gl124_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sens /* init registers for shading calibration */ /* shading calibration is done at dpihw */ static SANE_Status -gl124_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor) +gl124_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status; int move, resolution, dpihw, factor; @@ -2401,7 +2333,7 @@ gl124_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor) DBGSTART; /* initial calibration reg values */ - dev->calib_reg = dev->reg; + regs = dev->reg; dev->calib_channels = 3; dev->calib_lines = dev->model->shading_lines; @@ -2432,24 +2364,26 @@ gl124_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor) } DBG (DBG_io, "%s: move=%d steps\n", __func__, move); - status = gl124_init_scan_regs (dev, sensor, - &dev->calib_reg, - resolution, - resolution, - 0, - move, - dev->calib_pixels, - dev->calib_lines, - 16, - dev->calib_channels, - dev->settings.scan_method, - SCAN_MODE_COLOR, - 0, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); - gl124_set_motor_power(&dev->calib_reg, SANE_FALSE); + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 0; + params.starty = move; + params.pixels = dev->calib_pixels; + params.lines = dev->calib_lines; + params.depth = 16; + params.channels = dev->calib_channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = ColorFilter::RED; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl124_init_scan_regs(dev, sensor, ®s, params); + + sanei_genesys_set_motor_power(regs, false); if (status != SANE_STATUS_GOOD) { @@ -2460,7 +2394,7 @@ gl124_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor) dev->scanhead_position_in_steps += dev->calib_lines + move; - status = dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg); + status = dev->model->cmd_set->bulk_write_register(dev, regs); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, @@ -2488,15 +2422,8 @@ gl124_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) SANE_Status status; - DBG(DBG_info, "%s:\nResolution: %ux%uDPI\n" - "Lines : %u\npixels : %u\nStartpos : %.3f/%.3f\nScan mode : %d\n\n", __func__, - dev->settings.xres, - dev->settings.yres, - dev->settings.lines, - dev->settings.pixels, - dev->settings.tl_x, - dev->settings.tl_y, - dev->settings.scan_mode); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, dev->settings); /* wait for motor to stop first */ status = sanei_genesys_get_status (dev, &val); @@ -2540,14 +2467,14 @@ gl124_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) RIE (gl124_slow_back_home (dev, SANE_TRUE)); /* channels */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; else channels = 1; /* depth */ depth = dev->settings.depth; - if (dev->settings.scan_mode == SCAN_MODE_LINEART) + if (dev->settings.scan_mode == ScanColorMode::LINEART) depth = 1; /* y (motor) distance to move to reach scanned area */ @@ -2581,26 +2508,27 @@ gl124_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) flags = 0; /* enable emulated lineart from gray data */ - if(dev->settings.scan_mode == SCAN_MODE_LINEART + if(dev->settings.scan_mode == ScanColorMode::LINEART && dev->settings.dynamic_lineart) { flags |= SCAN_FLAG_DYNAMIC_LINEART; } - status = gl124_init_scan_regs (dev, sensor, - &dev->reg, - dev->settings.xres, - dev->settings.yres, - start, - move, - dev->settings.pixels, - dev->settings.lines, - depth, - channels, - dev->settings.scan_method, - dev->settings.scan_mode, - dev->settings.color_filter, - flags); + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = start; + params.starty = move; + params.pixels = dev->settings.pixels; + params.lines = dev->settings.lines; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = flags; + + status = gl124_init_scan_regs(dev, sensor, &dev->reg, params); if (status != SANE_STATUS_GOOD) return status; @@ -2742,7 +2670,8 @@ gl124_send_shading_data (Genesys_Device * dev, const Genesys_Sensor& sensor, * @return SANE_STATUS_GOOD on success, else the error code */ static SANE_Status -move_to_calibration_area (Genesys_Device * dev, const Genesys_Sensor& sensor) +move_to_calibration_area (Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { int pixels; int size; @@ -2753,26 +2682,27 @@ move_to_calibration_area (Genesys_Device * dev, const Genesys_Sensor& sensor) pixels = (sensor.sensor_pixels*600)/sensor.optical_res; /* initial calibration reg values */ - dev->calib_reg = dev->reg; + regs = dev->reg; + + SetupParams params; + params.xres = 600; + params.yres = 600; + params.startx = 0; + params.starty = 0; + params.pixels = pixels; + params.lines = 1; + params.depth = 8; + params.channels = 3; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl124_init_scan_regs(dev, sensor, ®s, params); - /* set up for the calibration scan */ - status = gl124_init_scan_regs (dev, sensor, - &dev->calib_reg, - 600, - 600, - 0, - 0, - pixels, - 1, - 8, - 3, - dev->settings.scan_method, - SCAN_MODE_COLOR, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus (status)); @@ -2783,10 +2713,10 @@ move_to_calibration_area (Genesys_Device * dev, const Genesys_Sensor& sensor) std::vector line(size); /* write registers and scan data */ - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG (DBG_info, "%s: starting line reading\n", __func__); - RIE(gl124_begin_scan (dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl124_begin_scan (dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, line.data(), size)); /* stop scanning */ @@ -2807,7 +2737,7 @@ move_to_calibration_area (Genesys_Device * dev, const Genesys_Sensor& sensor) -needs working coarse/gain */ static SANE_Status -gl124_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) +gl124_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor, Genesys_Register_Set& regs) { int num_pixels; int total_size; @@ -2826,7 +2756,7 @@ gl124_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) DBGSTART; /* move to calibration area */ - move_to_calibration_area(dev, sensor); + move_to_calibration_area(dev, sensor, regs); /* offset calibration is always done in 16 bit depth color mode */ channels = 3; @@ -2845,26 +2775,27 @@ gl124_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) num_pixels = (sensor.sensor_pixels*resolution)/sensor.optical_res; /* initial calibration reg values */ - dev->calib_reg = dev->reg; + regs = dev->reg; + + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 0; + params.starty = 0; + params.pixels = num_pixels; + params.lines = 1; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl124_init_scan_regs(dev, sensor, ®s, params); - /* set up for the calibration scan */ - status = gl124_init_scan_regs (dev, sensor, - &dev->calib_reg, - resolution, - resolution, - 0, - 0, - num_pixels, - 1, - depth, - channels, - dev->settings.scan_method, - SCAN_MODE_COLOR, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus (status)); @@ -2883,19 +2814,19 @@ gl124_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) turn = 0; /* no move during led calibration */ - gl124_set_motor_power (&dev->calib_reg, SANE_FALSE); + sanei_genesys_set_motor_power(regs, false); do { /* set up exposure */ - sanei_genesys_set_triple(&dev->calib_reg,REG_EXPR,exp[0]); - sanei_genesys_set_triple(&dev->calib_reg,REG_EXPG,exp[1]); - sanei_genesys_set_triple(&dev->calib_reg,REG_EXPB,exp[2]); + sanei_genesys_set_triple(®s,REG_EXPR,exp[0]); + sanei_genesys_set_triple(®s,REG_EXPG,exp[1]); + sanei_genesys_set_triple(®s,REG_EXPB,exp[2]); /* write registers and scan data */ - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting line reading\n", __func__); - RIE(gl124_begin_scan (dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl124_begin_scan (dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner (dev, line.data(), total_size)); /* stop scanning */ @@ -3001,7 +2932,8 @@ dark_average (uint8_t * data, unsigned int pixels, unsigned int lines, static SANE_Status -gl124_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) +gl124_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status = SANE_STATUS_GOOD; uint8_t reg0a; @@ -3030,29 +2962,31 @@ gl124_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) black_pixels = (sensor.black_pixels * resolution) / sensor.optical_res; DBG(DBG_io2, "%s: black_pixels=%d\n", __func__, black_pixels); - status = gl124_init_scan_regs (dev, sensor, - &dev->calib_reg, - resolution, - resolution, - 0, - 0, - pixels, - lines, - bpp, - channels, - dev->settings.scan_method, - SCAN_MODE_COLOR, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 0; + params.starty = 0; + params.pixels = pixels; + params.lines = lines; + params.depth = bpp; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl124_init_scan_regs(dev, sensor, ®s, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus(status)); return status; } - gl124_set_motor_power (&dev->calib_reg, SANE_FALSE); + sanei_genesys_set_motor_power(regs, false); /* allocate memory for scans */ total_size = pixels * channels * lines * (bpp/8); /* colors * bytes_per_color * scan lines */ @@ -3072,9 +3006,9 @@ gl124_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) dev->frontend.set_offset(2, bottom); RIE(gl124_set_fe(dev, sensor, AFE_SET)); - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting first line reading\n", __func__); - RIE(gl124_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl124_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, first_line.data(), total_size)); if (DBG_LEVEL >= DBG_data) { @@ -3092,9 +3026,9 @@ gl124_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) dev->frontend.set_offset(1, top); dev->frontend.set_offset(2, top); RIE(gl124_set_fe(dev, sensor, AFE_SET)); - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting second line reading\n", __func__); - RIE(gl124_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl124_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner (dev, second_line.data(), total_size)); topavg = dark_average(second_line.data(), pixels, lines, channels, black_pixels); @@ -3112,9 +3046,9 @@ gl124_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) /* scan with no move */ RIE(gl124_set_fe(dev, sensor, AFE_SET)); - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting second line reading\n", __func__); - RIE(gl124_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl124_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, second_line.data(), total_size)); if (DBG_LEVEL >= DBG_data) @@ -3159,7 +3093,8 @@ gl124_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) be done with shading. */ static SANE_Status -gl124_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor, int dpi) +gl124_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs, int dpi) { int pixels; int total_size; @@ -3201,24 +3136,26 @@ gl124_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso bpp=8; pixels = (sensor.sensor_pixels * resolution) / sensor.optical_res; - status = gl124_init_scan_regs (dev, sensor, - &dev->calib_reg, - resolution, - resolution, - 0, - 0, - pixels, - lines, - bpp, - channels, - dev->settings.scan_method, - SCAN_MODE_COLOR, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); - gl124_set_motor_power(&dev->calib_reg, SANE_FALSE); + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 0; + params.starty = 0; + params.pixels = pixels; + params.lines = lines; + params.depth = bpp; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl124_init_scan_regs(dev, sensor, ®s, params); + + sanei_genesys_set_motor_power(regs, false); if (status != SANE_STATUS_GOOD) { @@ -3226,14 +3163,14 @@ gl124_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso return status; } - RIE (dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE (dev->model->cmd_set->bulk_write_register(dev, regs)); total_size = pixels * channels * (16/bpp) * lines; std::vector line(total_size); RIE(gl124_set_fe(dev, sensor, AFE_SET)); - RIE(gl124_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl124_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, line.data(), total_size)); if (DBG_LEVEL >= DBG_data) @@ -3328,23 +3265,25 @@ gl124_init_regs_for_warmup (Genesys_Device * dev, *channels=3; *reg = dev->reg; - status = gl124_init_scan_regs (dev, sensor, - reg, - sensor.optical_res, - dev->motor.base_ydpi, - sensor.sensor_pixels/4, - 0, - sensor.sensor_pixels/2, - 1, - 8, - *channels, - dev->settings.scan_method, - SCAN_MODE_COLOR, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + + SetupParams params; + params.xres = sensor.optical_res; + params.yres = dev->motor.base_ydpi; + params.startx = sensor.sensor_pixels / 4; + params.starty = 0; + params.pixels = sensor.sensor_pixels / 2; + params.lines = 1; + params.depth = 8; + params.channels = *channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl124_init_scan_regs(dev, sensor, reg, params); if (status != SANE_STATUS_GOOD) { @@ -3356,7 +3295,7 @@ gl124_init_regs_for_warmup (Genesys_Device * dev, *total_size = num_pixels * 3 * 1; /* colors * bytes_per_color * scan lines */ - gl124_set_motor_power (reg, SANE_FALSE); + sanei_genesys_set_motor_power(*reg, false); RIE (dev->model->cmd_set->bulk_write_register(dev, *reg)); DBGCOMPLETED; @@ -3574,27 +3513,18 @@ gl124_update_hardware_sensors (Genesys_Scanner * s) if((s->dev->model->gpo_type == GPO_CANONLIDE110) ||(s->dev->model->gpo_type == GPO_CANONLIDE120)) { - if (s->val[OPT_SCAN_SW].b == s->last_val[OPT_SCAN_SW].b) - s->val[OPT_SCAN_SW].b = (val & 0x01) == 0; - if (s->val[OPT_FILE_SW].b == s->last_val[OPT_FILE_SW].b) - s->val[OPT_FILE_SW].b = (val & 0x08) == 0; - if (s->val[OPT_EMAIL_SW].b == s->last_val[OPT_EMAIL_SW].b) - s->val[OPT_EMAIL_SW].b = (val & 0x04) == 0; - if (s->val[OPT_COPY_SW].b == s->last_val[OPT_COPY_SW].b) - s->val[OPT_COPY_SW].b = (val & 0x02) == 0; + s->buttons[BUTTON_SCAN_SW].write((val & 0x01) == 0); + s->buttons[BUTTON_FILE_SW].write((val & 0x08) == 0); + s->buttons[BUTTON_EMAIL_SW].write((val & 0x04) == 0); + s->buttons[BUTTON_COPY_SW].write((val & 0x02) == 0); } else { /* LiDE 210 case */ - if (s->val[OPT_EXTRA_SW].b == s->last_val[OPT_EXTRA_SW].b) - s->val[OPT_EXTRA_SW].b = (val & 0x01) == 0; - if (s->val[OPT_SCAN_SW].b == s->last_val[OPT_SCAN_SW].b) - s->val[OPT_SCAN_SW].b = (val & 0x02) == 0; - if (s->val[OPT_COPY_SW].b == s->last_val[OPT_COPY_SW].b) - s->val[OPT_COPY_SW].b = (val & 0x04) == 0; - if (s->val[OPT_EMAIL_SW].b == s->last_val[OPT_EMAIL_SW].b) - s->val[OPT_EMAIL_SW].b = (val & 0x08) == 0; - if (s->val[OPT_FILE_SW].b == s->last_val[OPT_FILE_SW].b) - s->val[OPT_FILE_SW].b = (val & 0x10) == 0; + s->buttons[BUTTON_EXTRA_SW].write((val & 0x01) == 0); + s->buttons[BUTTON_SCAN_SW].write((val & 0x02) == 0); + s->buttons[BUTTON_COPY_SW].write((val & 0x04) == 0); + s->buttons[BUTTON_EMAIL_SW].write((val & 0x08) == 0); + s->buttons[BUTTON_FILE_SW].write((val & 0x10) == 0); } return status; } @@ -3622,9 +3552,6 @@ static Genesys_Command_Set gl124_cmd_set = { gl124_set_powersaving, gl124_save_power, - gl124_set_motor_power, - gl124_set_lamp_power, - gl124_begin_scan, gl124_end_scan, @@ -3655,8 +3582,7 @@ static Genesys_Command_Set gl124_cmd_set = { NULL, gl124_send_shading_data, gl124_calculate_current_setup, - gl124_boot, - gl124_init_scan_regs + gl124_boot }; SANE_Status diff --git a/backend/genesys_gl124.h b/backend/genesys_gl124.h index 128869735..751321d87 100644 --- a/backend/genesys_gl124.h +++ b/backend/genesys_gl124.h @@ -463,20 +463,8 @@ static Motor_Profile motors[]={ }; static -SANE_Status gl124_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, - Genesys_Register_Set * reg, - float xres, /*dpi */ - float yres, /*dpi */ - float startx, /*optical_res, from dummy_pixel+1 */ - float starty, /*base_ydpi, from home! */ - float pixels, - float lines, - unsigned int depth, - unsigned int channels, - int scan_method, - int scan_mode, - int color_filter, - unsigned int flags); +SANE_Status gl124_init_scan_regs(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set * reg, SetupParams& params); static SANE_Status gl124_start_action (Genesys_Device * dev); static SANE_Status diff --git a/backend/genesys_gl646.cc b/backend/genesys_gl646.cc index 08ba99d0a..c563324e5 100644 --- a/backend/genesys_gl646.cc +++ b/backend/genesys_gl646.cc @@ -222,7 +222,7 @@ gl646_stop_motor (Genesys_Device * dev) * @return the closest resolution for the sensor and mode */ static int -get_lowest_resolution(int sensor_id, SANE_Bool color) +get_lowest_resolution(int sensor_id, unsigned channels) { int i, nb; int dpi; @@ -234,7 +234,7 @@ get_lowest_resolution(int sensor_id, SANE_Bool color) { /* computes distance and keep mode if it is closer than previous */ if (sensor_id == sensor_master[i].sensor - && sensor_master[i].color == color) + && sensor_master[i].channels == channels) { if (sensor_master[i].dpi < dpi) { @@ -255,7 +255,7 @@ get_lowest_resolution(int sensor_id, SANE_Bool color) * @return the closest resolution for the sensor and mode */ static int -get_closest_resolution (int sensor_id, int required, SANE_Bool color) +get_closest_resolution(int sensor_id, int required, unsigned channels) { int i, nb; int dist, dpi; @@ -269,14 +269,14 @@ get_closest_resolution (int sensor_id, int required, SANE_Bool color) /* exit on perfect match */ if (sensor_id == sensor_master[i].sensor && sensor_master[i].dpi == required - && sensor_master[i].color == color) + && sensor_master[i].channels == channels) { DBG(DBG_info, "%s: match found for %d\n", __func__, required); return required; } /* computes distance and keep mode if it is closer than previous */ if (sensor_id == sensor_master[i].sensor - && sensor_master[i].color == color) + && sensor_master[i].channels == channels) { if (abs (sensor_master[i].dpi - required) < dist) { @@ -298,8 +298,7 @@ get_closest_resolution (int sensor_id, int required, SANE_Bool color) * @param color true is color mode * @return SANE_TRUE if half ccd is used */ -static SANE_Bool -is_half_ccd (int sensor_id, int required, SANE_Bool color) +static SANE_Bool is_half_ccd(int sensor_id, int required, unsigned channels) { int i, nb; @@ -310,7 +309,7 @@ is_half_ccd (int sensor_id, int required, SANE_Bool color) /* exit on perfect match */ if (sensor_id == sensor_master[i].sensor && sensor_master[i].dpi == required - && sensor_master[i].color == color) + && sensor_master[i].channels == channels) { DBG(DBG_io, "%s: match found for %d (half_ccd=%d)\n", __func__, required, sensor_master[i].half_ccd); @@ -329,8 +328,7 @@ is_half_ccd (int sensor_id, int required, SANE_Bool color) * @param color true is color mode * @return cksel value for mode */ -static int -get_cksel (int sensor_id, int required, SANE_Bool color) +static int get_cksel(int sensor_id, int required, unsigned channels) { int i, nb; @@ -341,7 +339,7 @@ get_cksel (int sensor_id, int required, SANE_Bool color) /* exit on perfect match */ if (sensor_id == sensor_master[i].sensor && sensor_master[i].dpi == required - && sensor_master[i].color == color) + && sensor_master[i].channels == channels) { DBG(DBG_io, "%s: match found for %d (cksel=%d)\n", __func__, required, sensor_master[i].cksel); @@ -360,16 +358,8 @@ get_cksel (int sensor_id, int required, SANE_Bool color) * the device. * @param dev pointer to a struct describing the device * @param regs register set to fill - * @param scan_settings scan's settings * @param slope_table1 first motor table to fill * @param slope_table2 second motor table to fill - * @param resolution dpi of the scan - * @param move distance to move (at scan's dpi) before scan - * @param linecnt number of lines to scan at scan's dpi - * @param startx start of scan area on CCD at CCD's optical resolution - * @param endx end of scan area on CCD at CCD's optical resolution - * @param color SANE_TRUE is color scan - * @param depth 1, 8 or 16 bits data sample * @return SANE_STATUS_GOOD if registers could be set, SANE_STATUS_INVAL if * conditions can't be met. * @note No harcoded SENSOR or MOTOR 'names' should be present and @@ -380,16 +370,46 @@ static SANE_Status gl646_setup_registers (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Register_Set * regs, - Genesys_Settings scan_settings, + SetupParams& params, uint16_t * slope_table1, uint16_t * slope_table2, - SANE_Int resolution, - uint32_t move, - uint32_t linecnt, - uint16_t startx, - uint16_t endx, SANE_Bool color, - SANE_Int depth) + bool xcorrection) { + int resolution = params.xres; + uint32_t move = params.starty; + uint32_t linecnt = params.lines; + + uint32_t startx = 0; + /* pixels are allways given at full CCD optical resolution */ + /* use detected left margin and fixed value */ + if (xcorrection == SANE_TRUE) { + if (sensor.CCD_start_xoffset > 0) { + startx = sensor.CCD_start_xoffset; + } else { + startx = sensor.dummy_pixel; + } + } else { + // startx cannot be below dummy pixel value + startx = sensor.dummy_pixel; + } + + /* add x coordinates : expressed in sensor max dpi */ + startx += params.startx; + + /* stagger works with odd start cordinates */ + if (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE) { + startx |= 1; + } + + uint32_t pixels = (params.pixels * sensor.optical_res) / params.xres; + /* special requirement for 400 dpi on 1200 dpi sensors */ + if (params.xres == 400) + { + pixels = (pixels / 6) * 6; + } + /* TODO check for pixel width overflow */ + uint32_t endx = startx + pixels; + SANE_Status status = SANE_STATUS_GOOD; int i, nb; Sensor_Master *sensor_mst = NULL; @@ -400,7 +420,7 @@ gl646_setup_registers (Genesys_Device * dev, unsigned int bpp; /**> bytes per pixel */ uint32_t z1, z2; uint16_t ex, sx; - int channels = 1, stagger, words_per_line, max_shift; + int stagger, words_per_line, max_shift; size_t requested_buffer_size; size_t read_buffer_size; SANE_Bool half_ccd = SANE_FALSE; @@ -428,7 +448,7 @@ gl646_setup_registers (Genesys_Device * dev, { if (dev->model->ccd_type == sensor_master[i].sensor && sensor_master[i].dpi == xresolution - && sensor_master[i].color == color) + && sensor_master[i].channels == params.channels) { sensor_mst = &sensor_master[i]; } @@ -436,8 +456,8 @@ gl646_setup_registers (Genesys_Device * dev, } if (sensor_mst == NULL) { - DBG(DBG_error, "%s: unable to find settings for sensor %d at %d dpi color=%d\n", __func__, - dev->model->ccd_type, xresolution, color); + DBG(DBG_error, "%s: unable to find settings for sensor %d at %d dpi channels=%d\n", __func__, + dev->model->ccd_type, xresolution, params.channels); return SANE_STATUS_INVAL; } @@ -448,8 +468,8 @@ gl646_setup_registers (Genesys_Device * dev, while (i < nb) { if (dev->model->motor_type == motor_master[i].motor - && motor_master[i].dpi == resolution - && motor_master[i].color == color) + && motor_master[i].dpi == resolution + && motor_master[i].channels == params.channels) { motor = &motor_master[i]; } @@ -458,7 +478,7 @@ gl646_setup_registers (Genesys_Device * dev, if (motor == NULL) { DBG(DBG_error, "%s: unable to find settings for motor %d at %d dpi, color=%d\n", __func__, - dev->model->motor_type, resolution, color); + dev->model->motor_type, resolution, params.channels); return SANE_STATUS_INVAL; } @@ -543,11 +563,6 @@ gl646_setup_registers (Genesys_Device * dev, motor->steps2, motor->g2, &used2, &vfinal); - if (color == SANE_TRUE) - channels = 3; - else - channels = 1; - /* R01 */ /* now setup other registers for final scan (ie with shading enabled) */ /* watch dog + shading + scan enable */ @@ -575,7 +590,7 @@ gl646_setup_registers (Genesys_Device * dev, dev->reg.find_reg(0x02).value |= REG02_ACDCDIS; /* setup motor power and direction */ - regs->find_reg(0x02).value |= REG02_MTRPWR; + sanei_genesys_set_motor_power(*regs, true); regs->find_reg(0x02).value &= ~REG02_MTRREV; /* fastfed enabled (2 motor slope tables) */ @@ -618,14 +633,14 @@ gl646_setup_registers (Genesys_Device * dev, /* select XPA */ regs->find_reg(0x03).value &= ~REG03_XPASEL; - if (scan_settings.scan_method == SCAN_METHOD_TRANSPARENCY) - { + if (params.flags & SCAN_FLAG_USE_XPA) { regs->find_reg(0x03).value |= REG03_XPASEL; } + regs->state.is_xpa_on = params.flags & SCAN_FLAG_USE_XPA; /* R04 */ /* monochrome / color scan */ - switch (depth) + switch (params.depth) { case 1: regs->find_reg(0x04).value &= ~REG04_BITSET; @@ -664,7 +679,7 @@ gl646_setup_registers (Genesys_Device * dev, regs->find_reg(0x05).value &= ~REG05_GMMENB; /* true CIS gray if needed */ - if (dev->model->is_cis == SANE_TRUE && color == SANE_FALSE + if (dev->model->is_cis == SANE_TRUE && params.channels == 1 && dev->settings.true_gray) { regs->find_reg(0x05).value |= REG05_LEDADD; @@ -686,7 +701,7 @@ gl646_setup_registers (Genesys_Device * dev, { /* reset count of dummy lines to zero */ regs->find_reg(0x1e).value &= ~REG1E_LINESEL; - if (scan_settings.xres >= 1200) + if (params.xres >= 1200) { /* there must be one dummy line */ regs->find_reg(0x1e).value |= 1 & REG1E_LINESEL; @@ -708,21 +723,20 @@ gl646_setup_registers (Genesys_Device * dev, regs->find_reg(0x24).value = motor->steps1; /* scanned area height must be enlarged by max color shift needed */ - max_shift=sanei_genesys_compute_max_shift(dev,channels,scan_settings.yres,0); + max_shift=sanei_genesys_compute_max_shift(dev,params.channels, params.yres, 0); /* we adjust linecnt according to real motor dpi */ - linecnt = (linecnt * motor->ydpi) / scan_settings.yres + max_shift; + linecnt = (linecnt * motor->ydpi) / params.yres + max_shift; /* at QUATER_STEP lines are 'staggered' and need correction */ stagger = 0; if ((!half_ccd) && (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE)) { /* for HP3670, stagger happens only at >=1200 dpi */ - if ((dev->model->motor_type != MOTOR_HP3670 - && dev->model->motor_type != MOTOR_HP2400) - || scan_settings.yres >= sensor.optical_res) + if ((dev->model->motor_type != MOTOR_HP3670 && dev->model->motor_type != MOTOR_HP2400) + || params.yres >= (unsigned) sensor.optical_res) { - stagger = (4 * scan_settings.yres) / dev->motor.base_ydpi; + stagger = (4 * params.yres) / dev->motor.base_ydpi; } } linecnt += stagger; @@ -735,7 +749,7 @@ gl646_setup_registers (Genesys_Device * dev, if (dev->model->is_cis == SANE_TRUE) { sanei_genesys_set_triple(regs, REG_LINCNT, linecnt * 3); - linecnt *= channels; + linecnt *= params.channels; } else { @@ -757,8 +771,8 @@ gl646_setup_registers (Genesys_Device * dev, /* words_per_line must be computed according to the scan's resolution */ /* in fact, words_per_line _gives_ the actual scan resolution */ words_per_line = (((endx - startx) * sensor_mst->xdpi) / sensor.optical_res); - bpp=depth/8; - if (depth == 1) + bpp=params.depth/8; + if (params.depth == 1) { words_per_line = (words_per_line+7)/8 ; bpp=1; @@ -768,7 +782,7 @@ gl646_setup_registers (Genesys_Device * dev, words_per_line *= bpp; } dev->bpl = words_per_line; - words_per_line *= channels; + words_per_line *= params.channels; dev->wpl = words_per_line; DBG(DBG_info, "%s: wpl=%d\n", __func__, words_per_line); @@ -907,7 +921,7 @@ gl646_setup_registers (Genesys_Device * dev, sensor_mst->exposure, slope_table1, motor->steps1, - move, motor->fwdbwd, &z1, &z2); + move, motor->fwdbwd, &z1, &z2); /* no z1/z2 for sheetfed scanners */ if (dev->model->is_sheetfed == SANE_TRUE) @@ -934,7 +948,7 @@ gl646_setup_registers (Genesys_Device * dev, requested_buffer_size = 8 * words_per_line; read_buffer_size = 2 * requested_buffer_size + - ((max_shift + stagger) * scan_settings.pixels * channels * depth) / 8; + ((max_shift + stagger) * params.pixels * params.channels * params.depth) / 8; dev->read_buffer.clear(); dev->read_buffer.alloc(read_buffer_size); @@ -946,7 +960,7 @@ gl646_setup_registers (Genesys_Device * dev, dev->shrink_buffer.alloc(requested_buffer_size); dev->out_buffer.clear(); - dev->out_buffer.alloc(8 * scan_settings.pixels * channels * bpp); + dev->out_buffer.alloc(8 * params.pixels * params.channels * bpp); /* scan bytes to read */ dev->read_bytes_left = words_per_line * linecnt; @@ -954,11 +968,12 @@ gl646_setup_registers (Genesys_Device * dev, DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left); dev->read_active = SANE_TRUE; + dev->current_setup.params = params; dev->current_setup.pixels = ((endx - startx) * sensor_mst->xdpi) / sensor.optical_res; dev->current_setup.lines = linecnt; - dev->current_setup.depth = depth; - dev->current_setup.channels = channels; + dev->current_setup.depth = params.depth; + dev->current_setup.channels = params.channels; dev->current_setup.exposure_time = sensor_mst->exposure; dev->current_setup.xres = sensor_mst->xdpi; dev->current_setup.yres = motor->ydpi; @@ -971,14 +986,30 @@ gl646_setup_registers (Genesys_Device * dev, * read_bytes_left is the number of bytes to read from the scanner */ dev->total_bytes_read = 0; - if (depth == 1) - dev->total_bytes_to_read = - ((scan_settings.pixels * scan_settings.lines) / 8 + - (((scan_settings.pixels * scan_settings.lines) % 8) ? 1 : 0)) * - channels; - else - dev->total_bytes_to_read = - scan_settings.pixels * scan_settings.lines * channels * bpp; + if (params.depth == 1) { + dev->total_bytes_to_read = ((params.pixels * params.lines) / 8 + + (((params.pixels * params.lines) % 8) ? 1 : 0)) * params.channels; + } else { + dev->total_bytes_to_read = params.pixels * params.lines * params.channels * bpp; + } + + /* select color filter based on settings */ + regs->find_reg(0x04).value &= ~REG04_FILTER; + if (params.channels == 1) { + switch (params.color_filter) { + case ColorFilter::RED: + regs->find_reg(0x04).value |= 0x04; + break; + case ColorFilter::GREEN: + regs->find_reg(0x04).value |= 0x08; + break; + case ColorFilter::BLUE: + regs->find_reg(0x04).value |= 0x0c; + break; + default: + break; + } + } DBG(DBG_proc, "%s: end\n", __func__); return SANE_STATUS_GOOD; @@ -1260,8 +1291,8 @@ gl646_init_regs (Genesys_Device * dev) dev->reg.find_reg(0x35).value = 0x01 /*0x00 */ ; /* set maximum word size per line, for buffer full control (10800) */ dev->reg.find_reg(0x36).value = 0x00 /*0x2a */ ; dev->reg.find_reg(0x37).value = 0x00 /*0x30 */ ; - dev->reg.find_reg(0x38).value = HIBYTE (dev->settings.exposure_time) /*0x2a */ ; /* line period (exposure time = 11000 pixels) */ - dev->reg.find_reg(0x39).value = LOBYTE (dev->settings.exposure_time) /*0xf8 */ ; + dev->reg.find_reg(0x38).value = 0x2a; // line period (exposure time = 11000 pixels) */ + dev->reg.find_reg(0x39).value = 0xf8; dev->reg.find_reg(0x3d).value = 0x00; /* set feed steps number of motor move */ dev->reg.find_reg(0x3e).value = 0x00; dev->reg.find_reg(0x3f).value = 0x01 /*0x00 */ ; @@ -1732,47 +1763,6 @@ gl646_public_set_fe (Genesys_Device * dev, const Genesys_Sensor& sensor, uint8_t return gl646_set_fe(dev, sensor, set, dev->settings.yres); } -static void -gl646_set_motor_power (Genesys_Register_Set * regs, SANE_Bool set) -{ - if (set) - { - sanei_genesys_set_reg_from_set (regs, 0x02, - sanei_genesys_read_reg_from_set (regs, - 0x02) | - REG02_MTRPWR); - } - else - { - sanei_genesys_set_reg_from_set (regs, 0x02, - sanei_genesys_read_reg_from_set (regs, - 0x02) & - ~REG02_MTRPWR); - } -} - -static void -gl646_set_lamp_power (Genesys_Device * dev, const Genesys_Sensor& sensor, - Genesys_Register_Set * regs, SANE_Bool set) -{ - (void) sensor; - if (dev) - { - if (set) - { - sanei_genesys_set_reg_from_set (regs, 0x03, - sanei_genesys_read_reg_from_set - (regs, 0x03) | REG03_LAMPPWR); - } - else - { - sanei_genesys_set_reg_from_set (regs, 0x03, - sanei_genesys_read_reg_from_set - (regs, 0x03) & ~REG03_LAMPPWR); - } - } -} - /** * enters or leaves power saving mode * limited to AFE for now. @@ -2502,20 +2492,19 @@ gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) } /* setup for a backward scan of 65535 steps, with no actual data reading */ - settings.scan_method = SCAN_METHOD_FLATBED; - settings.scan_mode = SCAN_MODE_COLOR; - settings.xres = get_lowest_resolution (dev->model->ccd_type, SANE_FALSE); + settings.scan_method = ScanMethod::FLATBED; + settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + settings.xres = get_lowest_resolution(dev->model->ccd_type, 1); settings.yres = settings.xres; settings.tl_x = 0; settings.tl_y = 0; settings.pixels = 600; settings.lines = 1; settings.depth = 8; - settings.color_filter = 0; + settings.color_filter = ColorFilter::RED; settings.disable_interpolation = 0; settings.threshold = 0; - settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; const auto& sensor = sanei_genesys_find_sensor(dev, settings.xres); @@ -2615,15 +2604,15 @@ gl646_search_start_position (Genesys_Device * dev) DBG(DBG_proc, "%s: start\n", __func__); /* we scan at 300 dpi */ - resolution = get_closest_resolution (dev->model->ccd_type, 300, SANE_FALSE); + resolution = get_closest_resolution(dev->model->ccd_type, 300, 1); // FIXME: the current approach of doing search only for one resolution does not work on scanners // whith employ different sensors with potentially different settings. auto& sensor = sanei_genesys_find_sensor_for_write(dev, resolution); /* fill settings for a gray level scan */ - settings.scan_method = SCAN_METHOD_FLATBED; - settings.scan_mode = SCAN_MODE_GRAY; + settings.scan_method = ScanMethod::FLATBED; + settings.scan_mode = ScanColorMode::GRAY; settings.xres = resolution; settings.yres = resolution; settings.tl_x = 0; @@ -2631,11 +2620,10 @@ gl646_search_start_position (Genesys_Device * dev) settings.pixels = 600; settings.lines = dev->model->search_lines; settings.depth = 8; - settings.color_filter = 0; + settings.color_filter = ColorFilter::RED; settings.disable_interpolation = 0; settings.threshold = 0; - settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; /* scan the desired area */ @@ -2696,9 +2684,11 @@ gl646_search_start_position (Genesys_Device * dev) * sets up register for coarse gain calibration */ static SANE_Status -gl646_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl646_init_regs_for_coarse_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { (void) sensor; + (void) regs; DBG(DBG_proc, "%s\n", __func__); DBG(DBG_proc, "%s: end\n", __func__); @@ -2722,8 +2712,10 @@ gl646_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sens * @return SANE_STATUS_GOOD if success, else error code */ static SANE_Status -gl646_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl646_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { + (void) regs; SANE_Status status = SANE_STATUS_GOOD; Genesys_Settings settings; /* 1: no half_ccd, 2: use half number of pixels */ @@ -2732,26 +2724,27 @@ gl646_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) DBG(DBG_proc, "%s: start\n", __func__); - /* when shading all (full width) line, we must adapt to half_ccd case */ + /* fill settings for scan : always a color scan */ + int channels = 3; + if (sensor.ccd_size_divisor > 1) { - /* walk the master mode list to find if half_ccd */ - if (is_half_ccd (dev->model->ccd_type, dev->settings.xres, SANE_TRUE) == - SANE_TRUE) + // when shading all (full width) line, we must adapt to half_ccd case + if (is_half_ccd(dev->model->ccd_type, dev->settings.xres, channels) == SANE_TRUE) { half_ccd = 2; } } - /* fill settings for scan : always a color scan */ settings.scan_method = dev->settings.scan_method; settings.scan_mode = dev->settings.scan_mode; if (dev->model->is_cis == SANE_FALSE) { - settings.scan_mode = SCAN_MODE_COLOR; + // FIXME: always a color scan, but why don't we set scan_mode to COLOR_SINGLE_PASS always? + settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; } settings.xres = sensor.optical_res / half_ccd; - cksel = get_cksel (dev->model->ccd_type, dev->settings.xres, SANE_TRUE); + cksel = get_cksel(dev->model->ccd_type, dev->settings.xres, channels); settings.xres = settings.xres / cksel; settings.yres = settings.xres; settings.tl_x = 0; @@ -2765,7 +2758,6 @@ gl646_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) settings.disable_interpolation = dev->settings.disable_interpolation; settings.threshold = dev->settings.threshold; - settings.exposure_time = dev->settings.exposure_time; settings.dynamic_lineart = SANE_FALSE; /* keep account of the movement for final scan move */ @@ -2788,7 +2780,7 @@ gl646_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) dev->reg.find_reg(0x02).value |= REG02_ACDCDIS; /* ease backtracking */ dev->reg.find_reg(0x02).value &= ~(REG02_FASTFED | REG02_AGOHOME); dev->reg.find_reg(0x05).value &= ~REG05_GMMENB; - gl646_set_motor_power(&dev->reg, SANE_FALSE); + sanei_genesys_set_motor_power(dev->reg, false); /* TODO another flag to setup regs ? */ /* enforce needed LINCNT, getting rid of extra lines for color reordering */ @@ -2829,7 +2821,7 @@ gl646_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) /* park head after calibration if needed */ if (dev->scanhead_position_in_steps > 0 - && dev->settings.scan_method == SCAN_METHOD_FLATBED) + && dev->settings.scan_method == ScanMethod::FLATBED) { RIE(gl646_slow_back_home (dev, SANE_TRUE)); dev->scanhead_position_in_steps = 0; @@ -2866,33 +2858,23 @@ setup_for_scan (Genesys_Device * dev, SANE_Bool ycorrection) { SANE_Status status = SANE_STATUS_GOOD; - SANE_Bool color; SANE_Int depth; int channels; - uint16_t startx = 0, endx, pixels; - int move = 0; - DBGSTART; - DBG(DBG_info, "%s settings:\nResolution: %ux%uDPI\n" - "Lines : %u\nPixels : %u\nStartpos : %.3f/%.3f\nScan mode : %d\nScan method: %s\n\n", - __func__, - settings.xres, settings.yres, settings.lines, settings.pixels, - settings.tl_x, settings.tl_y, settings.scan_mode, - settings.scan_method == SCAN_METHOD_FLATBED ? "flatbed" : "XPA"); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, dev->settings); - if (settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) { channels = 3; - color = SANE_TRUE; } else { channels = 1; - color = SANE_FALSE; } depth=settings.depth; - if (settings.scan_mode == SCAN_MODE_LINEART) + if (settings.scan_mode == ScanColorMode::LINEART) { if (settings.dynamic_lineart == SANE_TRUE) { @@ -2905,129 +2887,69 @@ setup_for_scan (Genesys_Device * dev, } } - /* compute distance to move */ - move = 0; - /* XXX STEF XXX MD5345 -> optical_ydpi, other base_ydpi => half/full step ? */ - if (split == SANE_FALSE) - { - if (dev->model->is_sheetfed == SANE_FALSE) - { - if (ycorrection == SANE_TRUE) - { - move = - (SANE_UNFIX (dev->model->y_offset) * - dev->motor.optical_ydpi) / MM_PER_INCH; + // compute distance to move + float move = 0; + // XXX STEF XXX MD5345 -> optical_ydpi, other base_ydpi => half/full step ? */ + if (split == SANE_FALSE) { + if (dev->model->is_sheetfed == SANE_FALSE) { + if (ycorrection == SANE_TRUE) { + move = SANE_UNFIX(dev->model->y_offset); } - /* add tl_y to base movement */ - move += (settings.tl_y * dev->motor.optical_ydpi) / MM_PER_INCH; - - } - else - { - move += (settings.tl_y * dev->motor.optical_ydpi) / MM_PER_INCH; + // add tl_y to base movement } + move += settings.tl_y; - DBG(DBG_info, "%s: move=%d steps\n", __func__, move); - - /* security check */ - if (move < 0) - { - DBG(DBG_error, "%s: overriding negative move value %d\n", __func__, move); - move = 0; + if (move < 0) { + DBG(DBG_error, "%s: overriding negative move value %f\n", __func__, move); + move = 0; } } - DBG(DBG_info, "%s: move=%d steps\n", __func__, move); + move = (move * dev->motor.optical_ydpi) / MM_PER_INCH; + DBG(DBG_info, "%s: move=%f steps\n", __func__, move); - /* pixels are allways given at full CCD optical resolution */ - /* use detected left margin and fixed value */ - if (xcorrection == SANE_TRUE) - { - if (sensor.CCD_start_xoffset > 0) - startx = sensor.CCD_start_xoffset; - else - startx = sensor.dummy_pixel; - if (settings.scan_method == SCAN_METHOD_FLATBED) - { - startx += - ((SANE_UNFIX (dev->model->x_offset) * sensor.optical_res) / - MM_PER_INCH); - } - else - { - startx += - ((SANE_UNFIX (dev->model->x_offset_ta) * - sensor.optical_res) / MM_PER_INCH); - } + float start = settings.tl_x; + if (xcorrection) { + if (settings.scan_method == ScanMethod::FLATBED) { + start += SANE_UNFIX(dev->model->x_offset); + } else { + start += SANE_UNFIX(dev->model->x_offset_ta); + } } - else - { - /* startx cannot be below dummy pixel value */ - startx = sensor.dummy_pixel; + start = (start * sensor.optical_res) / MM_PER_INCH; + + SetupParams params; + params.xres = settings.xres; + params.yres = settings.yres; + params.startx = start; + params.starty = move; + params.pixels = settings.pixels; + params.lines = settings.lines; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = settings.scan_mode; + params.color_filter = settings.color_filter; + params.flags = 0; + if (settings.scan_method == ScanMethod::TRANSPARENCY) { + params.flags |= SCAN_FLAG_USE_XPA; } - /* add x coordinates : expressed in sensor max dpi */ - startx += (settings.tl_x * sensor.optical_res) / MM_PER_INCH; - - /* stagger works with odd start cordinates */ - if (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE) - startx |= 1; - - pixels = (settings.pixels * sensor.optical_res) / settings.xres; - /* special requirement for 400 dpi on 1200 dpi sensors */ - if (settings.xres == 400) - { - pixels = (pixels / 6) * 6; - } - endx = startx + pixels; - - /* TODO check for pixel width overflow */ + uint16_t slope_table0[256] = {}; + uint16_t slope_table1[256] = {}; /* set up correct values for scan (gamma and shading enabled) */ - status = gl646_setup_registers (dev, sensor, - regs, - settings, - dev->slope_table0, - dev->slope_table1, - settings.xres, - move, - settings.lines, - startx, endx, color, - depth); + status = gl646_setup_registers(dev, sensor, regs, params, slope_table0, slope_table1, + xcorrection); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed setup registers: %s\n", __func__, sane_strstatus(status)); return status; } - /* now post-process values for register and options fine tuning */ - - /* select color filter based on settings */ - regs->find_reg(0x04).value &= ~REG04_FILTER; - if (channels == 1) - { - switch (settings.color_filter) - { - /* red */ - case 0: - regs->find_reg(0x04).value |= 0x04; - break; - /* green */ - case 1: - regs->find_reg(0x04).value |= 0x08; - break; - /* blue */ - case 2: - regs->find_reg(0x04).value |= 0x0c; - break; - default: - break; - } - } - /* send computed slope tables */ status = - gl646_send_slope_table (dev, 0, dev->slope_table0, + gl646_send_slope_table (dev, 0, slope_table0, sanei_genesys_read_reg_from_set (regs, 0x21)); if (status != SANE_STATUS_GOOD) { @@ -3036,7 +2958,7 @@ setup_for_scan (Genesys_Device * dev, } status = - gl646_send_slope_table (dev, 1, dev->slope_table1, + gl646_send_slope_table (dev, 1, slope_table1, sanei_genesys_read_reg_from_set (regs, 0x6b)); if (status != SANE_STATUS_GOOD) { @@ -3120,8 +3042,9 @@ gl646_send_gamma_table (Genesys_Device * dev, const Genesys_Sensor& sensor) * currently limited to the XP200 */ static SANE_Status -gl646_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) +gl646_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor, Genesys_Register_Set& regs) { + (void) regs; int total_size; unsigned int i, j; SANE_Status status = SANE_STATUS_GOOD; @@ -3143,25 +3066,20 @@ gl646_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) } /* get led calibration resolution */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) { - resolution = - get_closest_resolution (dev->model->ccd_type, sensor.optical_res, - SANE_TRUE); - settings.scan_mode = SCAN_MODE_COLOR; channels = 3; + settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; } else { - resolution = - get_closest_resolution (dev->model->ccd_type, sensor.optical_res, - SANE_FALSE); - settings.scan_mode = SCAN_MODE_GRAY; channels = 1; + settings.scan_mode = ScanColorMode::GRAY; } + resolution = get_closest_resolution(dev->model->ccd_type, sensor.optical_res, channels); /* offset calibration is always done in color mode */ - settings.scan_method = SCAN_METHOD_FLATBED; + settings.scan_method = ScanMethod::FLATBED; settings.xres = resolution; settings.yres = resolution; settings.tl_x = 0; @@ -3170,11 +3088,10 @@ gl646_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) (sensor.sensor_pixels * resolution) / sensor.optical_res; settings.lines = 1; settings.depth = 16; - settings.color_filter = 0; + settings.color_filter = ColorFilter::RED; settings.disable_interpolation = 0; settings.threshold = 0; - settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; /* colors * bytes_per_color * scan lines */ @@ -3332,16 +3249,14 @@ ad_fe_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) unsigned int bottom, black_pixels; DBG(DBG_proc, "%s: start\n", __func__); - resolution = - get_closest_resolution (dev->model->ccd_type, sensor.optical_res, - SANE_TRUE); channels = 3; + resolution = get_closest_resolution(dev->model->ccd_type, sensor.optical_res, channels); black_pixels = (sensor.black_pixels * resolution) / sensor.optical_res; DBG(DBG_io2, "%s: black_pixels=%d\n", __func__, black_pixels); - settings.scan_method = SCAN_METHOD_FLATBED; - settings.scan_mode = SCAN_MODE_COLOR; + settings.scan_method = ScanMethod::FLATBED; + settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; settings.xres = resolution; settings.yres = resolution; settings.tl_x = 0; @@ -3350,11 +3265,10 @@ ad_fe_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) (sensor.sensor_pixels * resolution) / sensor.optical_res; settings.lines = CALIBRATION_LINES; settings.depth = 8; - settings.color_filter = 0; + settings.color_filter = ColorFilter::RED; settings.disable_interpolation = 0; settings.threshold = 0; - settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; /* scan first line of data with no gain */ @@ -3430,8 +3344,10 @@ ad_fe_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) * @return SANE_STATUS_GOOD if success, else error code is failure */ static SANE_Status -gl646_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl646_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { + (void) regs; SANE_Status status = SANE_STATUS_GOOD; unsigned int channels; int pass = 0, avg; @@ -3450,25 +3366,18 @@ gl646_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) /* setup for a RGB scan, one full sensor's width line */ /* resolution is the one from the final scan */ - if (dev->settings.xres > sensor.optical_res) - { - resolution = - get_closest_resolution (dev->model->ccd_type, sensor.optical_res, - SANE_TRUE); + channels = 3; + if (dev->settings.xres > sensor.optical_res) { + resolution = get_closest_resolution(dev->model->ccd_type, sensor.optical_res, channels); + } else { + resolution = get_closest_resolution(dev->model->ccd_type, dev->settings.xres, channels); } - else - { - resolution = - get_closest_resolution (dev->model->ccd_type, dev->settings.xres, - SANE_TRUE); - } - channels = 3; black_pixels = (sensor.black_pixels * resolution) / sensor.optical_res; DBG(DBG_io2, "%s: black_pixels=%d\n", __func__, black_pixels); - settings.scan_method = SCAN_METHOD_FLATBED; - settings.scan_mode = SCAN_MODE_COLOR; + settings.scan_method = ScanMethod::FLATBED; + settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; settings.xres = resolution; settings.yres = resolution; settings.tl_x = 0; @@ -3477,11 +3386,10 @@ gl646_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) (sensor.sensor_pixels * resolution) / sensor.optical_res; settings.lines = CALIBRATION_LINES; settings.depth = 8; - settings.color_filter = 0; + settings.color_filter = ColorFilter::RED; settings.disable_interpolation = 0; settings.threshold = 0; - settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; /* scan first line of data with no gain, but with offset from @@ -3607,8 +3515,10 @@ gl646_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) * Alternative coarse gain calibration */ static SANE_Status -ad_fe_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor, int dpi) +ad_fe_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs, int dpi) { + (void) regs; unsigned int i, channels, val; unsigned int size, count, resolution, pass; SANE_Status status = SANE_STATUS_GOOD; @@ -3620,11 +3530,11 @@ ad_fe_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso /* setup for a RGB scan, one full sensor's width line */ /* resolution is the one from the final scan */ - resolution = get_closest_resolution (dev->model->ccd_type, dpi, SANE_TRUE); channels = 3; - settings.scan_mode = SCAN_MODE_COLOR; + resolution = get_closest_resolution(dev->model->ccd_type, dpi, channels); + settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; - settings.scan_method = SCAN_METHOD_FLATBED; + settings.scan_method = ScanMethod::FLATBED; settings.xres = resolution; settings.yres = resolution; settings.tl_x = 0; @@ -3633,11 +3543,10 @@ ad_fe_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso (sensor.sensor_pixels * resolution) / sensor.optical_res; settings.lines = CALIBRATION_LINES; settings.depth = 8; - settings.color_filter = 0; + settings.color_filter = ColorFilter::RED; settings.disable_interpolation = 0; settings.threshold = 0; - settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; size = channels * settings.pixels * settings.lines; @@ -3713,7 +3622,8 @@ ad_fe_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso * @param dpi resolutnio to calibrate at */ static SANE_Status -gl646_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor, int dpi) +gl646_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs, int dpi) { unsigned int i, j, k, channels, val, maximum, idx; unsigned int count, resolution, pass; @@ -3724,7 +3634,7 @@ gl646_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso if (dev->model->ccd_type == CIS_XP200) { - return ad_fe_coarse_gain_calibration (dev, sensor, sensor.optical_res); + return ad_fe_coarse_gain_calibration (dev, sensor, regs, sensor.optical_res); } DBGSTART; @@ -3733,23 +3643,18 @@ gl646_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso channels = 3; /* we are searching a sensor resolution */ - if (dpi > sensor.optical_res) - { - resolution = sensor.optical_res; - } - else - { - resolution = - get_closest_resolution (dev->model->ccd_type, dev->settings.xres, - SANE_TRUE); + if (dpi > sensor.optical_res) { + resolution = sensor.optical_res; + } else { + resolution = get_closest_resolution(dev->model->ccd_type, dev->settings.xres, channels); } settings.scan_method = dev->settings.scan_method; - settings.scan_mode = SCAN_MODE_COLOR; + settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; settings.xres = resolution; settings.yres = resolution; settings.tl_y = 0; - if (settings.scan_method == SCAN_METHOD_FLATBED) + if (settings.scan_method == ScanMethod::FLATBED) { settings.tl_x = 0; settings.pixels = (sensor.sensor_pixels * resolution) / sensor.optical_res; @@ -3761,11 +3666,10 @@ gl646_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso } settings.lines = CALIBRATION_LINES; settings.depth = 8; - settings.color_filter = 0; + settings.color_filter = ColorFilter::RED; settings.disable_interpolation = 0; settings.threshold = 0; - settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; /* start gain value */ @@ -3785,7 +3689,12 @@ gl646_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso average[0] = 255; average[1] = 255; average[2] = 255; - idx = dev->settings.color_filter; + 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; @@ -3894,11 +3803,11 @@ gl646_init_regs_for_warmup (Genesys_Device * dev, dev->frontend = dev->frontend_initial; - resolution = get_closest_resolution (dev->model->ccd_type, 300, SANE_FALSE); + resolution = get_closest_resolution(dev->model->ccd_type, 300, 1); /* set up for a half width 2 lines gray scan without moving */ - settings.scan_method = SCAN_METHOD_FLATBED; - settings.scan_mode = SCAN_MODE_GRAY; + settings.scan_method = ScanMethod::FLATBED; + settings.scan_mode = ScanColorMode::GRAY; settings.xres = resolution; settings.yres = resolution; settings.tl_x = 0; @@ -3907,11 +3816,10 @@ gl646_init_regs_for_warmup (Genesys_Device * dev, (sensor.sensor_pixels * resolution) / sensor.optical_res; settings.lines = 2; settings.depth = 8; - settings.color_filter = 0; + settings.color_filter = ColorFilter::RED; settings.disable_interpolation = 0; settings.threshold = 0; - settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; /* setup for scan */ @@ -3932,7 +3840,7 @@ gl646_init_regs_for_warmup (Genesys_Device * dev, *local_reg = dev->reg; /* turn off motor during this scan */ - gl646_set_motor_power (local_reg, SANE_FALSE); + sanei_genesys_set_motor_power(*local_reg, false); /* returned value to higher level warmup function */ *channels = 1; @@ -3964,21 +3872,19 @@ gl646_repark_head (Genesys_Device * dev) DBG(DBG_proc, "%s: start\n", __func__); - settings.scan_method = SCAN_METHOD_FLATBED; - settings.scan_mode = SCAN_MODE_COLOR; - settings.xres = - get_closest_resolution (dev->model->ccd_type, 75, SANE_FALSE); + settings.scan_method = ScanMethod::FLATBED; + settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + settings.xres = get_closest_resolution(dev->model->ccd_type, 75, 1); settings.yres = settings.xres; settings.tl_x = 0; settings.tl_y = 5; settings.pixels = 600; settings.lines = 4; settings.depth = 8; - settings.color_filter = 0; + settings.color_filter = ColorFilter::RED; settings.disable_interpolation = 0; settings.threshold = 0; - settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; const auto& sensor = sanei_genesys_find_sensor(dev, settings.xres); @@ -4071,26 +3977,10 @@ gl646_init (Genesys_Device * dev) dev->dark_average_data.clear(); dev->white_average_data.clear(); - dev->settings.color_filter = 1; /* green filter by default */ + dev->settings.color_filter = ColorFilter::GREEN; gettimeofday (&tv, NULL); dev->init_date = tv.tv_sec; - switch (dev->model->motor_type) - { - /* set to 11111 to spot bugs, sanei_genesys_exposure_time should - have obsoleted this field */ - case MOTOR_5345: - dev->settings.exposure_time = 11111; - break; - - case MOTOR_ST24: - dev->settings.exposure_time = 11000; - break; - default: - dev->settings.exposure_time = 11000; - break; - } - /* Set default values for registers */ gl646_init_regs (dev); @@ -4351,7 +4241,7 @@ simple_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, else bpp = 1; size *= bpp; - if (settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) size *= 3; data.clear(); data.resize(size); @@ -4384,8 +4274,7 @@ simple_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, if (move == SANE_FALSE) { - /* clear motor power flag if no move */ - dev->reg.find_reg(0x02).value &= ~REG02_MTRPWR; + sanei_genesys_set_motor_power(dev->reg, false); /* no automatic go home if no movement */ dev->reg.find_reg(0x02).value &= ~REG02_AGOHOME; @@ -4400,7 +4289,7 @@ simple_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, } /* no automatic go home when using XPA */ - if (settings.scan_method == SCAN_METHOD_TRANSPARENCY) + if (settings.scan_method == ScanMethod::TRANSPARENCY) { dev->reg.find_reg(0x02).value &= ~REG02_AGOHOME; } @@ -4451,7 +4340,7 @@ simple_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, /* in case of CIS scanner, we must reorder data */ if (dev->model->is_cis == SANE_TRUE - && settings.scan_mode == SCAN_MODE_COLOR) + && settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) { /* alloc one line sized working buffer */ std::vector buffer(settings.pixels * 3 * bpp); @@ -4521,13 +4410,13 @@ simple_move (Genesys_Device * dev, SANE_Int distance) DBG(DBG_proc, "%s: %d mm\n", __func__, distance); - int resolution = get_lowest_resolution (dev->model->ccd_type, SANE_TRUE); + int resolution = get_lowest_resolution(dev->model->ccd_type, 3); const auto& sensor = sanei_genesys_find_sensor(dev, resolution); /* TODO give a no AGOHOME flag */ - settings.scan_method = SCAN_METHOD_TRANSPARENCY; - settings.scan_mode = SCAN_MODE_COLOR; + settings.scan_method = ScanMethod::TRANSPARENCY; + settings.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; settings.xres = resolution; settings.yres = resolution; settings.tl_y = 0; @@ -4536,11 +4425,10 @@ simple_move (Genesys_Device * dev, SANE_Int distance) (sensor.sensor_pixels * settings.xres) / sensor.optical_res; settings.lines = (distance * settings.xres) / MM_PER_INCH; settings.depth = 8; - settings.color_filter = 0; + settings.color_filter = ColorFilter::RED; settings.disable_interpolation = 0; settings.threshold = 0; - settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; std::vector data; @@ -4556,7 +4444,7 @@ simple_move (Genesys_Device * dev, SANE_Int distance) /** * update the status of the required sensor in the scanner session - * the last_val fileds are used to make events 'sticky' + * the button fileds are used to make events 'sticky' */ static SANE_Status gl646_update_hardware_sensors (Genesys_Scanner * session) @@ -4576,109 +4464,90 @@ gl646_update_hardware_sensors (Genesys_Scanner * session) } DBG(DBG_io, "%s: GPIO=0x%02x\n", __func__, value); - /* scan button */ - if ((dev->model->buttons & GENESYS_HAS_SCAN_SW) - && session->val[OPT_SCAN_SW].b == session->last_val[OPT_SCAN_SW].b) - { - switch (dev->model->gpo_type) - { + // scan button + if (dev->model->buttons & GENESYS_HAS_SCAN_SW) { + switch (dev->model->gpo_type) { case GPO_XP200: - session->val[OPT_SCAN_SW].b = ((value & 0x02) != 0); - break; + session->buttons[BUTTON_SCAN_SW].write((value & 0x02) != 0); + break; case GPO_5345: - session->val[OPT_SCAN_SW].b = (value == 0x16); - break; + session->buttons[BUTTON_SCAN_SW].write(value == 0x16); + break; case GPO_HP2300: - session->val[OPT_SCAN_SW].b = (value == 0x6c); - break; + session->buttons[BUTTON_SCAN_SW].write(value == 0x6c); + break; case GPO_HP3670: case GPO_HP2400: - session->val[OPT_SCAN_SW].b = ((value & 0x20) == 0); - break; + session->buttons[BUTTON_SCAN_SW].write((value & 0x20) == 0); + break; default: - return SANE_STATUS_UNSUPPORTED; + return SANE_STATUS_UNSUPPORTED; } } - /* email button */ - if ((dev->model->buttons & GENESYS_HAS_EMAIL_SW) - && session->val[OPT_EMAIL_SW].b == session->last_val[OPT_EMAIL_SW].b) - { - switch (dev->model->gpo_type) - { + // email button + if (dev->model->buttons & GENESYS_HAS_EMAIL_SW) { + switch (dev->model->gpo_type) { case GPO_5345: - session->val[OPT_EMAIL_SW].b = (value == 0x12); - break; + session->buttons[BUTTON_EMAIL_SW].write(value == 0x12); + break; case GPO_HP3670: case GPO_HP2400: - session->val[OPT_EMAIL_SW].b = ((value & 0x08) == 0); - break; + session->buttons[BUTTON_EMAIL_SW].write((value & 0x08) == 0); + break; default: - return SANE_STATUS_UNSUPPORTED; + return SANE_STATUS_UNSUPPORTED; } } - /* copy button */ - if ((dev->model->buttons & GENESYS_HAS_COPY_SW) - && session->val[OPT_COPY_SW].b == session->last_val[OPT_COPY_SW].b) - { - switch (dev->model->gpo_type) - { + // copy button + if (dev->model->buttons & GENESYS_HAS_COPY_SW) { + switch (dev->model->gpo_type) { case GPO_5345: - session->val[OPT_COPY_SW].b = (value == 0x11); - break; + session->buttons[BUTTON_COPY_SW].write(value == 0x11); + break; case GPO_HP2300: - session->val[OPT_COPY_SW].b = (value == 0x5c); - break; + session->buttons[BUTTON_COPY_SW].write(value == 0x5c); + break; case GPO_HP3670: case GPO_HP2400: - session->val[OPT_COPY_SW].b = ((value & 0x10) == 0); - break; + session->buttons[BUTTON_COPY_SW].write((value & 0x10) == 0); + break; default: return SANE_STATUS_UNSUPPORTED; } } - /* power button */ - if ((dev->model->buttons & GENESYS_HAS_POWER_SW) - && session->val[OPT_POWER_SW].b == session->last_val[OPT_POWER_SW].b) - { - switch (dev->model->gpo_type) - { + // power button + if (dev->model->buttons & GENESYS_HAS_POWER_SW) { + switch (dev->model->gpo_type) { case GPO_5345: - session->val[OPT_POWER_SW].b = (value == 0x14); - break; + session->buttons[BUTTON_POWER_SW].write(value == 0x14); + break; default: - return SANE_STATUS_UNSUPPORTED; + return SANE_STATUS_UNSUPPORTED; } } - /* ocr button */ - if ((dev->model->buttons & GENESYS_HAS_OCR_SW) - && session->val[OPT_OCR_SW].b == session->last_val[OPT_OCR_SW].b) - { - switch (dev->model->gpo_type) - { + // ocr button + if (dev->model->buttons & GENESYS_HAS_OCR_SW) { + switch (dev->model->gpo_type) { case GPO_5345: - session->val[OPT_OCR_SW].b = (value == 0x13); - break; + session->buttons[BUTTON_OCR_SW].write(value == 0x13); + break; default: - return SANE_STATUS_UNSUPPORTED; + return SANE_STATUS_UNSUPPORTED; } } - /* document detection */ - if ((dev->model->buttons & GENESYS_HAS_PAGE_LOADED_SW) - && session->val[OPT_PAGE_LOADED_SW].b == - session->last_val[OPT_PAGE_LOADED_SW].b) - { - switch (dev->model->gpo_type) - { + // document detection + if (dev->model->buttons & GENESYS_HAS_PAGE_LOADED_SW) { + switch (dev->model->gpo_type) { case GPO_XP200: - session->val[OPT_PAGE_LOADED_SW].b = ((value & 0x04) != 0); - break; + session->buttons[BUTTON_PAGE_LOADED_SW].write((value & 0x04) != 0); + break; default: - return SANE_STATUS_UNSUPPORTED; + return SANE_STATUS_UNSUPPORTED; } } @@ -4804,7 +4673,7 @@ gl646_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sen /* build minimal current_setup for calibration cache use only, it will be better * computed when during setup for scan */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) { dev->current_setup.channels = 3; } @@ -4813,7 +4682,6 @@ gl646_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sen dev->current_setup.channels = 1; } dev->current_setup.xres = dev->settings.xres; - dev->current_setup.scan_method = dev->settings.scan_method; DBG(DBG_io, "%s: requested=(%d,%f), tested=(%d,%f)\n", __func__, dev->current_setup.channels, dev->current_setup.xres, cache->used_setup.channels, cache->used_setup.xres); @@ -4832,10 +4700,11 @@ gl646_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sen compatible = (dev->current_setup.channels == cache->used_setup.channels); } - if (dev->current_setup.scan_method != cache->used_setup.scan_method) + if (dev->current_setup.params.scan_method != cache->used_setup.params.scan_method) { - DBG(DBG_io, "%s: current method=%d, used=%d\n", __func__, dev->current_setup.scan_method, - cache->used_setup.scan_method); + DBG(DBG_io, "%s: current method=%d, used=%d\n", __func__, + static_cast(dev->current_setup.params.scan_method), + static_cast(cache->used_setup.params.scan_method)); compatible = 0; } if (!compatible) @@ -4876,7 +4745,7 @@ gl646_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor, SANE_Bool SANE_Status status = SANE_STATUS_GOOD; SANE_Bool half_ccd = SANE_FALSE; Genesys_Settings settings; - int res = get_closest_resolution (dev->model->ccd_type, 75, SANE_FALSE); + int res = get_closest_resolution(dev->model->ccd_type, 75, 1); unsigned int pass, count, found, x, y; char title[80]; @@ -4885,15 +4754,16 @@ gl646_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor, SANE_Bool if (sensor.ccd_size_divisor > 1) { /* walk the master mode list to find if half_ccd */ - if (is_half_ccd (dev->model->ccd_type, res, SANE_TRUE) == SANE_TRUE) + // FIXME: possibly wrong channel count for is_half_ccd + if (is_half_ccd (dev->model->ccd_type, res, 3) == SANE_TRUE) { half_ccd = SANE_TRUE; } } /* we set up for a lowest available resolution color grey scan, full width */ - settings.scan_method = SCAN_METHOD_FLATBED; - settings.scan_mode = SCAN_MODE_GRAY; + settings.scan_method = ScanMethod::FLATBED; + settings.scan_mode = ScanColorMode::GRAY; settings.xres = res; settings.yres = res; settings.tl_x = 0; @@ -4907,11 +4777,10 @@ gl646_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor, SANE_Bool /* 15 mm at at time */ settings.lines = (15 * settings.yres) / MM_PER_INCH; /* may become a parameter from genesys_devices.c */ settings.depth = 8; - settings.color_filter = 0; + settings.color_filter = ColorFilter::RED; settings.disable_interpolation = 0; settings.threshold = 0; - settings.exposure_time = 0; settings.dynamic_lineart = SANE_FALSE; /* signals if a strip of the given color has been found */ @@ -5050,8 +4919,6 @@ static Genesys_Command_Set gl646_cmd_set = { gl646_public_set_fe, gl646_set_powersaving, gl646_save_power, - gl646_set_motor_power, - gl646_set_lamp_power, gl646_begin_scan, gl646_end_scan, @@ -5083,7 +4950,6 @@ static Genesys_Command_Set gl646_cmd_set = { gl646_move_to_ta, NULL, NULL, - NULL, NULL }; diff --git a/backend/genesys_gl646.h b/backend/genesys_gl646.h index 0aa463cc6..766176a2d 100644 --- a/backend/genesys_gl646.h +++ b/backend/genesys_gl646.h @@ -212,15 +212,10 @@ setup_for_scan (Genesys_Device *device, static SANE_Status gl646_setup_registers (Genesys_Device * dev, const Genesys_Sensor& sensor, - Genesys_Register_Set * regs, - Genesys_Settings scan_settings, - uint16_t * slope_table1, - uint16_t * slope_table2, - SANE_Int resolution, - uint32_t move, - uint32_t linecnt, - uint16_t startx, - uint16_t endx, SANE_Bool color, SANE_Int depth); + Genesys_Register_Set * regs, SetupParams& params, + uint16_t * slope_table1, + uint16_t * slope_table2, + bool xcorrection); /** * Does a simple move of the given distance by doing a scan at lowest resolution @@ -286,7 +281,7 @@ typedef struct /* key */ SANE_Int motor; SANE_Int dpi; - SANE_Bool color; + unsigned channels; /* settings */ SANE_Int ydpi; /* real motor dpi, may be different from the resolution */ @@ -313,7 +308,7 @@ typedef struct /* key */ SANE_Int sensor; /**< sensor identifier */ SANE_Int dpi; /**< required dpi */ - SANE_Bool color; /**< SANE_TRUE if color scan */ + unsigned channels; // 3 channels if color scan, 1 channel for gray scan /* settings */ SANE_Int xdpi; /**< real sensor dpi, may be different from the required resolution */ @@ -355,85 +350,85 @@ static uint8_t xp200_gray[6]={0x05, 0x0a, 0x0f, 0xa0, 0x10, 0x10}; */ static Sensor_Master sensor_master[] = { /* HP3670 master settings */ - {CCD_HP3670, 75, SANE_TRUE , 75, 4879, 300, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, - {CCD_HP3670, 100, SANE_TRUE , 100, 4487, 400, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, - {CCD_HP3670, 150, SANE_TRUE , 150, 4879, 600, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, - {CCD_HP3670, 300, SANE_TRUE , 300, 4503, 1200, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, - {CCD_HP3670, 600, SANE_TRUE , 600, 10251, 1200, 2, 42, NULL, SANE_FALSE, 0x31, 0x43}, - {CCD_HP3670,1200, SANE_TRUE , 1200, 12750, 1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x43}, - {CCD_HP3670,2400, SANE_TRUE , 1200, 12750, 1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x43}, - {CCD_HP3670, 75, SANE_FALSE, 75, 4879, 300, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, - {CCD_HP3670, 100, SANE_FALSE, 100, 4487, 400, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, - {CCD_HP3670, 150, SANE_FALSE, 150, 4879, 600, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, - {CCD_HP3670, 300, SANE_FALSE, 300, 4503, 1200, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, - {CCD_HP3670, 600, SANE_FALSE, 600, 10251, 1200, 2, 42, NULL, SANE_FALSE, 0x31, 0x43}, - {CCD_HP3670,1200, SANE_FALSE, 1200, 12750, 1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x43}, - {CCD_HP3670,2400, SANE_FALSE, 1200, 12750, 1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x43}, + {CCD_HP3670, 75, 3, 75, 4879, 300, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, + {CCD_HP3670, 100, 3, 100, 4487, 400, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, + {CCD_HP3670, 150, 3, 150, 4879, 600, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, + {CCD_HP3670, 300, 3, 300, 4503, 1200, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, + {CCD_HP3670, 600, 3, 600, 10251, 1200, 2, 42, NULL, SANE_FALSE, 0x31, 0x43}, + {CCD_HP3670,1200, 3, 1200, 12750, 1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x43}, + {CCD_HP3670,2400, 3, 1200, 12750, 1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x43}, + {CCD_HP3670, 75, 1, 75, 4879, 300, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, + {CCD_HP3670, 100, 1, 100, 4487, 400, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, + {CCD_HP3670, 150, 1, 150, 4879, 600, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, + {CCD_HP3670, 300, 1, 300, 4503, 1200, 4, 42, NULL, SANE_FALSE, 0x33, 0x43}, + {CCD_HP3670, 600, 1, 600, 10251, 1200, 2, 42, NULL, SANE_FALSE, 0x31, 0x43}, + {CCD_HP3670,1200, 1, 1200, 12750, 1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x43}, + {CCD_HP3670,2400, 1, 1200, 12750, 1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x43}, /* HP 2400 master settings */ - {CCD_HP2400, 50, SANE_TRUE , 50, 7211, 200, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, - {CCD_HP2400, 100, SANE_TRUE , 100, 7211, 400, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, - {CCD_HP2400, 150, SANE_TRUE , 150, 7211, 600, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, - {CCD_HP2400, 300, SANE_TRUE , 300, 8751, 1200, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, - {CCD_HP2400, 600, SANE_TRUE , 600, 18760, 1200, 2, 42, NULL, SANE_FALSE, 0x31, 0x02}, - {CCD_HP2400,1200, SANE_TRUE , 1200, 21749, 1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x42}, - {CCD_HP2400, 50, SANE_FALSE, 50, 7211, 200, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, - {CCD_HP2400, 100, SANE_FALSE, 100, 7211, 400, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, - {CCD_HP2400, 150, SANE_FALSE, 150, 7211, 600, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, - {CCD_HP2400, 300, SANE_FALSE, 300, 8751, 1200, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, - {CCD_HP2400, 600, SANE_FALSE, 600, 18760, 1200, 2, 42, NULL, SANE_FALSE, 0x31, 0x02}, - {CCD_HP2400,1200, SANE_FALSE, 1200, 21749, 1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x42}, + {CCD_HP2400, 50, 3, 50, 7211, 200, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, + {CCD_HP2400, 100, 3, 100, 7211, 400, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, + {CCD_HP2400, 150, 3, 150, 7211, 600, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, + {CCD_HP2400, 300, 3, 300, 8751, 1200, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, + {CCD_HP2400, 600, 3, 600, 18760, 1200, 2, 42, NULL, SANE_FALSE, 0x31, 0x02}, + {CCD_HP2400,1200, 3, 1200, 21749, 1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x42}, + {CCD_HP2400, 50, 1, 50, 7211, 200, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, + {CCD_HP2400, 100, 1, 100, 7211, 400, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, + {CCD_HP2400, 150, 1, 150, 7211, 600, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, + {CCD_HP2400, 300, 1, 300, 8751, 1200, 4, 42, NULL, SANE_FALSE, 0x3f, 0x02}, + {CCD_HP2400, 600, 1, 600, 18760, 1200, 2, 42, NULL, SANE_FALSE, 0x31, 0x02}, + {CCD_HP2400,1200, 1, 1200, 21749, 1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x42}, /* XP 200 master settings */ - {CIS_XP200 , 75, SANE_TRUE , 75, 5700, 75, 1, 42, xp200_color, SANE_FALSE, 0x00, 0x11}, - {CIS_XP200 , 100, SANE_TRUE , 100, 5700, 100, 1, 42, xp200_color, SANE_FALSE, 0x00, 0x11}, - {CIS_XP200 , 200, SANE_TRUE , 200, 5700, 200, 1, 42, xp200_color, SANE_FALSE, 0x00, 0x11}, - {CIS_XP200 , 300, SANE_TRUE , 300, 9000, 300, 1, 42, xp200_color, SANE_FALSE, 0x00, 0x11}, - {CIS_XP200 , 600, SANE_TRUE , 600, 16000, 600, 1, 42, xp200_color, SANE_FALSE, 0x00, 0x11}, + {CIS_XP200 , 75, 3, 75, 5700, 75, 1, 42, xp200_color, SANE_FALSE, 0x00, 0x11}, + {CIS_XP200 , 100, 3, 100, 5700, 100, 1, 42, xp200_color, SANE_FALSE, 0x00, 0x11}, + {CIS_XP200 , 200, 3, 200, 5700, 200, 1, 42, xp200_color, SANE_FALSE, 0x00, 0x11}, + {CIS_XP200 , 300, 3, 300, 9000, 300, 1, 42, xp200_color, SANE_FALSE, 0x00, 0x11}, + {CIS_XP200 , 600, 3, 600, 16000, 600, 1, 42, xp200_color, SANE_FALSE, 0x00, 0x11}, - {CIS_XP200 , 75, SANE_FALSE, 75, 16000, 75, 1, 42, xp200_gray, SANE_FALSE, 0x00, 0x11}, - {CIS_XP200 , 100, SANE_FALSE, 100, 7800, 100, 1, 42, xp200_gray, SANE_FALSE, 0x00, 0x11}, - {CIS_XP200 , 200, SANE_FALSE, 200, 11000, 200, 1, 42, xp200_gray, SANE_FALSE, 0x00, 0x11}, - {CIS_XP200 , 300, SANE_FALSE, 300, 13000, 300, 1, 42, xp200_gray, SANE_FALSE, 0x00, 0x11}, - {CIS_XP200 , 600, SANE_FALSE, 600, 24000, 600, 1, 42, xp200_gray, SANE_FALSE, 0x00, 0x11}, + {CIS_XP200 , 75, 1, 75, 16000, 75, 1, 42, xp200_gray, SANE_FALSE, 0x00, 0x11}, + {CIS_XP200 , 100, 1, 100, 7800, 100, 1, 42, xp200_gray, SANE_FALSE, 0x00, 0x11}, + {CIS_XP200 , 200, 1, 200, 11000, 200, 1, 42, xp200_gray, SANE_FALSE, 0x00, 0x11}, + {CIS_XP200 , 300, 1, 300, 13000, 300, 1, 42, xp200_gray, SANE_FALSE, 0x00, 0x11}, + {CIS_XP200 , 600, 1, 600, 24000, 600, 1, 42, xp200_gray, SANE_FALSE, 0x00, 0x11}, /* HP 2300 master settings */ - {CCD_HP2300, 75, SANE_TRUE , 75, 4480, 150, 1, 42, NULL, SANE_TRUE , 0x20, 0x85}, - {CCD_HP2300, 150, SANE_TRUE , 150, 4350, 300, 1, 42, NULL, SANE_TRUE , 0x20, 0x85}, - {CCD_HP2300, 300, SANE_TRUE, 300, 4350, 600, 1, 42, NULL, SANE_TRUE , 0x20, 0x85}, - {CCD_HP2300, 600, SANE_TRUE , 600, 8700, 600, 1, 42, NULL, SANE_FALSE, 0x20, 0x05}, - {CCD_HP2300,1200, SANE_TRUE , 600, 8700, 600, 1, 42, NULL, SANE_FALSE, 0x20, 0x05}, - {CCD_HP2300, 75, SANE_FALSE, 75, 4480, 150, 1, 42, NULL, SANE_TRUE , 0x20, 0x85}, - {CCD_HP2300, 150, SANE_FALSE, 150, 4350, 300, 1, 42, NULL, SANE_TRUE , 0x20, 0x85}, - {CCD_HP2300, 300, SANE_FALSE, 300, 4350, 600, 1, 42, NULL, SANE_TRUE , 0x20, 0x85}, - {CCD_HP2300, 600, SANE_FALSE, 600, 8700, 600, 1, 42, NULL, SANE_FALSE, 0x20, 0x05}, - {CCD_HP2300,1200, SANE_FALSE, 600, 8700, 600, 1, 42, NULL, SANE_FALSE, 0x20, 0x05}, + {CCD_HP2300, 75, 3, 75, 4480, 150, 1, 42, NULL, SANE_TRUE , 0x20, 0x85}, + {CCD_HP2300, 150, 3, 150, 4350, 300, 1, 42, NULL, SANE_TRUE , 0x20, 0x85}, + {CCD_HP2300, 300, 3, 300, 4350, 600, 1, 42, NULL, SANE_TRUE , 0x20, 0x85}, + {CCD_HP2300, 600, 3, 600, 8700, 600, 1, 42, NULL, SANE_FALSE, 0x20, 0x05}, + {CCD_HP2300,1200, 3, 600, 8700, 600, 1, 42, NULL, SANE_FALSE, 0x20, 0x05}, + {CCD_HP2300, 75, 1, 75, 4480, 150, 1, 42, NULL, SANE_TRUE , 0x20, 0x85}, + {CCD_HP2300, 150, 1, 150, 4350, 300, 1, 42, NULL, SANE_TRUE , 0x20, 0x85}, + {CCD_HP2300, 300, 1, 300, 4350, 600, 1, 42, NULL, SANE_TRUE , 0x20, 0x85}, + {CCD_HP2300, 600, 1, 600, 8700, 600, 1, 42, NULL, SANE_FALSE, 0x20, 0x05}, + {CCD_HP2300,1200, 1, 600, 8700, 600, 1, 42, NULL, SANE_FALSE, 0x20, 0x05}, /* non half ccd 300 dpi settings - {CCD_HP2300, 300, SANE_TRUE , 300, 8700, 300, 1, 42, NULL, SANE_FALSE, 0x20, 0x05}, - {CCD_HP2300, 300, SANE_FALSE, 300, 8700, 300, 1, 42, NULL, SANE_FALSE, 0x20, 0x05}, + {CCD_HP2300, 300, 3, 300, 8700, 300, 1, 42, NULL, SANE_FALSE, 0x20, 0x05}, + {CCD_HP2300, 300, 1, 300, 8700, 300, 1, 42, NULL, SANE_FALSE, 0x20, 0x05}, */ /* MD5345/6471 master settings */ - {CCD_5345 , 50, SANE_TRUE , 50, 12000, 100, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 75, SANE_TRUE , 75, 11000, 150, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 100, SANE_TRUE , 100, 11000, 200, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 150, SANE_TRUE , 150, 11000, 300, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 200, SANE_TRUE , 200, 11000, 400, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 300, SANE_TRUE , 300, 11000, 600, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 400, SANE_TRUE , 400, 11000, 800, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 600, SANE_TRUE , 600, 11000,1200, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 ,1200, SANE_TRUE ,1200, 11000,1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x03}, - {CCD_5345 ,2400, SANE_TRUE ,1200, 11000,1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x03}, - {CCD_5345 , 50, SANE_FALSE, 50, 12000, 100, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 75, SANE_FALSE, 75, 11000, 150, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 100, SANE_FALSE, 100, 11000, 200, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 150, SANE_FALSE, 150, 11000, 300, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 200, SANE_FALSE, 200, 11000, 400, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 300, SANE_FALSE, 300, 11000, 600, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 400, SANE_FALSE, 400, 11000, 800, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 , 600, SANE_FALSE, 600, 11000,1200, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, - {CCD_5345 ,1200, SANE_FALSE,1200, 11000,1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x03}, - {CCD_5345 ,2400, SANE_FALSE,1200, 11000,1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x03}, + {CCD_5345 , 50, 3, 50, 12000, 100, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 75, 3, 75, 11000, 150, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 100, 3, 100, 11000, 200, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 150, 3, 150, 11000, 300, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 200, 3, 200, 11000, 400, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 300, 3, 300, 11000, 600, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 400, 3, 400, 11000, 800, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 600, 3, 600, 11000,1200, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 ,1200, 3, 1200, 11000,1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x03}, + {CCD_5345 ,2400, 3, 1200, 11000,1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x03}, + {CCD_5345 , 50, 1, 50, 12000, 100, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 75, 1, 75, 11000, 150, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 100, 1, 100, 11000, 200, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 150, 1, 150, 11000, 300, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 200, 1, 200, 11000, 400, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 300, 1, 300, 11000, 600, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 400, 1, 400, 11000, 800, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 , 600, 1, 600, 11000,1200, 1, 42, NULL, SANE_TRUE , 0x28, 0x03}, + {CCD_5345 ,1200, 1, 1200, 11000,1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x03}, + {CCD_5345 ,2400, 1, 1200, 11000,1200, 1, 42, NULL, SANE_FALSE, 0x30, 0x03}, }; @@ -443,88 +438,88 @@ static Sensor_Master sensor_master[] = { */ static Motor_Master motor_master[] = { /* HP3670 motor settings */ - {MOTOR_HP3670, 75, SANE_TRUE , 75, FULL_STEP, SANE_FALSE, SANE_TRUE , 1, 200, 3429, 305, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670, 100, SANE_TRUE , 100, HALF_STEP, SANE_FALSE, SANE_TRUE , 1, 143, 2905, 187, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670, 150, SANE_TRUE , 150, HALF_STEP, SANE_FALSE, SANE_TRUE , 1, 73, 3429, 305, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670, 300, SANE_TRUE , 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 1, 11, 1055, 563, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670, 600, SANE_TRUE , 600, FULL_STEP, SANE_FALSE, SANE_TRUE , 0, 3, 10687, 5126, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670,1200, SANE_TRUE ,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 0, 3, 15937, 6375, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670,2400, SANE_TRUE ,2400, HALF_STEP, SANE_FALSE, SANE_TRUE , 0, 3, 15937, 12750, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670, 75, SANE_FALSE, 75, FULL_STEP, SANE_FALSE, SANE_TRUE , 1, 200, 3429, 305, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670, 100, SANE_FALSE, 100, HALF_STEP, SANE_FALSE, SANE_TRUE , 1, 143, 2905, 187, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670, 150, SANE_FALSE, 150, HALF_STEP, SANE_FALSE, SANE_TRUE , 1, 73, 3429, 305, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670, 300, SANE_FALSE, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 1, 11, 1055, 563, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670, 600, SANE_FALSE, 600, FULL_STEP, SANE_FALSE, SANE_TRUE , 0, 3, 10687, 5126, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670,1200, SANE_FALSE,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 0, 3, 15937, 6375, 192, 3399, 337, 0.3, 0.4, 192}, - {MOTOR_HP3670,2400, SANE_TRUE ,2400, HALF_STEP, SANE_FALSE, SANE_TRUE , 0, 3, 15937, 12750, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670, 75, 3, 75, FULL_STEP, SANE_FALSE, SANE_TRUE , 1, 200, 3429, 305, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670, 100, 3, 100, HALF_STEP, SANE_FALSE, SANE_TRUE , 1, 143, 2905, 187, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670, 150, 3, 150, HALF_STEP, SANE_FALSE, SANE_TRUE , 1, 73, 3429, 305, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670, 300, 3, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 1, 11, 1055, 563, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670, 600, 3, 600, FULL_STEP, SANE_FALSE, SANE_TRUE , 0, 3, 10687, 5126, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670,1200, 3,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 0, 3, 15937, 6375, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670,2400, 3,2400, HALF_STEP, SANE_FALSE, SANE_TRUE , 0, 3, 15937, 12750, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670, 75, 1, 75, FULL_STEP, SANE_FALSE, SANE_TRUE , 1, 200, 3429, 305, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670, 100, 1, 100, HALF_STEP, SANE_FALSE, SANE_TRUE , 1, 143, 2905, 187, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670, 150, 1, 150, HALF_STEP, SANE_FALSE, SANE_TRUE , 1, 73, 3429, 305, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670, 300, 1, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 1, 11, 1055, 563, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670, 600, 1, 600, FULL_STEP, SANE_FALSE, SANE_TRUE , 0, 3, 10687, 5126, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670,1200, 1,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 0, 3, 15937, 6375, 192, 3399, 337, 0.3, 0.4, 192}, + {MOTOR_HP3670,2400, 3,2400, HALF_STEP, SANE_FALSE, SANE_TRUE , 0, 3, 15937, 12750, 192, 3399, 337, 0.3, 0.4, 192}, /* HP2400/G2410 motor settings base motor dpi = 600 */ - {MOTOR_HP2400, 50, SANE_TRUE , 50, FULL_STEP, SANE_FALSE, SANE_TRUE , 63, 120, 8736, 601, 192, 4905, 337, 0.30, 0.4, 192}, - {MOTOR_HP2400, 100, SANE_TRUE , 100, HALF_STEP, SANE_FALSE, SANE_TRUE, 63, 120, 8736, 601, 192, 4905, 337, 0.30, 0.4, 192}, - {MOTOR_HP2400, 150, SANE_TRUE , 150, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 67, 15902, 902, 192, 4905, 337, 0.30, 0.4, 192}, - {MOTOR_HP2400, 300, SANE_TRUE , 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 32, 16703, 2188, 192, 4905, 337, 0.30, 0.4, 192}, - {MOTOR_HP2400, 600, SANE_TRUE , 600, FULL_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 18761, 18761, 192, 4905, 627, 0.30, 0.4, 192}, - {MOTOR_HP2400,1200, SANE_TRUE ,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 43501, 43501, 192, 4905, 627, 0.30, 0.4, 192}, - {MOTOR_HP2400, 50, SANE_FALSE, 50, FULL_STEP, SANE_FALSE, SANE_TRUE , 63, 120, 8736, 601, 192, 4905, 337, 0.30, 0.4, 192}, - {MOTOR_HP2400, 100, SANE_FALSE, 100, HALF_STEP, SANE_FALSE, SANE_TRUE, 63, 120, 8736, 601, 192, 4905, 337, 0.30, 0.4, 192}, - {MOTOR_HP2400, 150, SANE_FALSE, 150, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 67, 15902, 902, 192, 4905, 337, 0.30, 0.4, 192}, - {MOTOR_HP2400, 300, SANE_FALSE, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 32, 16703, 2188, 192, 4905, 337, 0.30, 0.4, 192}, - {MOTOR_HP2400, 600, SANE_FALSE, 600, FULL_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 18761, 18761, 192, 4905, 337, 0.30, 0.4, 192}, - {MOTOR_HP2400,1200, SANE_FALSE,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 43501, 43501, 192, 4905, 337, 0.30, 0.4, 192}, + {MOTOR_HP2400, 50, 3, 50, FULL_STEP, SANE_FALSE, SANE_TRUE , 63, 120, 8736, 601, 192, 4905, 337, 0.30, 0.4, 192}, + {MOTOR_HP2400, 100, 3, 100, HALF_STEP, SANE_FALSE, SANE_TRUE, 63, 120, 8736, 601, 192, 4905, 337, 0.30, 0.4, 192}, + {MOTOR_HP2400, 150, 3, 150, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 67, 15902, 902, 192, 4905, 337, 0.30, 0.4, 192}, + {MOTOR_HP2400, 300, 3, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 32, 16703, 2188, 192, 4905, 337, 0.30, 0.4, 192}, + {MOTOR_HP2400, 600, 3, 600, FULL_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 18761, 18761, 192, 4905, 627, 0.30, 0.4, 192}, + {MOTOR_HP2400,1200, 3,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 43501, 43501, 192, 4905, 627, 0.30, 0.4, 192}, + {MOTOR_HP2400, 50, 1, 50, FULL_STEP, SANE_FALSE, SANE_TRUE , 63, 120, 8736, 601, 192, 4905, 337, 0.30, 0.4, 192}, + {MOTOR_HP2400, 100, 1, 100, HALF_STEP, SANE_FALSE, SANE_TRUE, 63, 120, 8736, 601, 192, 4905, 337, 0.30, 0.4, 192}, + {MOTOR_HP2400, 150, 1, 150, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 67, 15902, 902, 192, 4905, 337, 0.30, 0.4, 192}, + {MOTOR_HP2400, 300, 1, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 32, 16703, 2188, 192, 4905, 337, 0.30, 0.4, 192}, + {MOTOR_HP2400, 600, 1, 600, FULL_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 18761, 18761, 192, 4905, 337, 0.30, 0.4, 192}, + {MOTOR_HP2400,1200, 1,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 43501, 43501, 192, 4905, 337, 0.30, 0.4, 192}, /* XP 200 motor settings */ - {MOTOR_XP200, 75, SANE_TRUE, 75, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6000, 2136, 8, 12000, 1200, 0.3, 0.5, 1}, - {MOTOR_XP200, 100, SANE_TRUE, 100, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6000, 2850, 8, 12000, 1200, 0.3, 0.5, 1}, - {MOTOR_XP200, 200, SANE_TRUE, 200, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6999, 5700, 8, 12000, 1200, 0.3, 0.5, 1}, - {MOTOR_XP200, 250, SANE_TRUE, 250, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6999, 6999, 8, 12000, 1200, 0.3, 0.5, 1}, - {MOTOR_XP200, 300, SANE_TRUE, 300, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 13500, 13500, 8, 12000, 1200, 0.3, 0.5, 1}, - {MOTOR_XP200, 600, SANE_TRUE, 600, HALF_STEP, SANE_TRUE , SANE_TRUE, 0, 4, 31998, 31998, 2, 12000, 1200, 0.3, 0.5, 1}, - {MOTOR_XP200, 75, SANE_FALSE, 75, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6000, 2000, 8, 12000, 1200, 0.3, 0.5, 1}, - {MOTOR_XP200, 100, SANE_FALSE, 100, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6000, 1300, 8, 12000, 1200, 0.3, 0.5, 1}, - {MOTOR_XP200, 200, SANE_FALSE, 200, HALF_STEP, SANE_TRUE , SANE_TRUE, 0, 4, 6000, 3666, 8, 12000, 1200, 0.3, 0.5, 1}, - {MOTOR_XP200, 300, SANE_FALSE, 300, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6500, 6500, 8, 12000, 1200, 0.3, 0.5, 1}, - {MOTOR_XP200, 600, SANE_FALSE, 600, HALF_STEP, SANE_TRUE , SANE_TRUE, 0, 4, 24000, 24000, 2, 12000, 1200, 0.3, 0.5, 1}, + {MOTOR_XP200, 75, 3, 75, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6000, 2136, 8, 12000, 1200, 0.3, 0.5, 1}, + {MOTOR_XP200, 100, 3, 100, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6000, 2850, 8, 12000, 1200, 0.3, 0.5, 1}, + {MOTOR_XP200, 200, 3, 200, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6999, 5700, 8, 12000, 1200, 0.3, 0.5, 1}, + {MOTOR_XP200, 250, 3, 250, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6999, 6999, 8, 12000, 1200, 0.3, 0.5, 1}, + {MOTOR_XP200, 300, 3, 300, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 13500, 13500, 8, 12000, 1200, 0.3, 0.5, 1}, + {MOTOR_XP200, 600, 3, 600, HALF_STEP, SANE_TRUE , SANE_TRUE, 0, 4, 31998, 31998, 2, 12000, 1200, 0.3, 0.5, 1}, + {MOTOR_XP200, 75, 1, 75, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6000, 2000, 8, 12000, 1200, 0.3, 0.5, 1}, + {MOTOR_XP200, 100, 1, 100, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6000, 1300, 8, 12000, 1200, 0.3, 0.5, 1}, + {MOTOR_XP200, 200, 1, 200, HALF_STEP, SANE_TRUE , SANE_TRUE, 0, 4, 6000, 3666, 8, 12000, 1200, 0.3, 0.5, 1}, + {MOTOR_XP200, 300, 1, 300, HALF_STEP, SANE_TRUE , SANE_FALSE, 0, 4, 6500, 6500, 8, 12000, 1200, 0.3, 0.5, 1}, + {MOTOR_XP200, 600, 1, 600, HALF_STEP, SANE_TRUE , SANE_TRUE, 0, 4, 24000, 24000, 2, 12000, 1200, 0.3, 0.5, 1}, /* HP scanjet 2300c */ - {MOTOR_HP2300, 75, SANE_TRUE, 75, FULL_STEP, SANE_FALSE, SANE_TRUE , 63, 120, 8139, 560, 120, 4905, 337, 0.3, 0.4, 16}, - {MOTOR_HP2300, 150, SANE_TRUE, 150, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 67, 7903, 543, 120, 4905, 337, 0.3, 0.4, 16}, - {MOTOR_HP2300, 300, SANE_TRUE, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 2175, 1087, 120, 4905, 337, 0.3, 0.4, 16}, - {MOTOR_HP2300, 600, SANE_TRUE, 600, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 8700, 4350, 120, 4905, 337, 0.3, 0.4, 16}, - {MOTOR_HP2300,1200, SANE_TRUE,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 17400, 8700, 120, 4905, 337, 0.3, 0.4, 16}, - {MOTOR_HP2300, 75, SANE_FALSE, 75, FULL_STEP, SANE_FALSE, SANE_TRUE , 63, 120, 8139, 560, 120, 4905, 337, 0.3, 0.4, 16}, - {MOTOR_HP2300, 150, SANE_FALSE, 150, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 67, 7903, 543, 120, 4905, 337, 0.3, 0.4, 16}, - {MOTOR_HP2300, 300, SANE_FALSE, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 2175, 1087, 120, 4905, 337, 0.3, 0.4, 16}, - {MOTOR_HP2300, 600, SANE_FALSE, 600, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 8700, 4350, 120, 4905, 337, 0.3, 0.4, 16}, - {MOTOR_HP2300,1200, SANE_FALSE,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 17400, 8700, 120, 4905, 337, 0.3, 0.4, 16}, + {MOTOR_HP2300, 75, 3, 75, FULL_STEP, SANE_FALSE, SANE_TRUE , 63, 120, 8139, 560, 120, 4905, 337, 0.3, 0.4, 16}, + {MOTOR_HP2300, 150, 3, 150, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 67, 7903, 543, 120, 4905, 337, 0.3, 0.4, 16}, + {MOTOR_HP2300, 300, 3, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 2175, 1087, 120, 4905, 337, 0.3, 0.4, 16}, + {MOTOR_HP2300, 600, 3, 600, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 8700, 4350, 120, 4905, 337, 0.3, 0.4, 16}, + {MOTOR_HP2300,1200, 3,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 17400, 8700, 120, 4905, 337, 0.3, 0.4, 16}, + {MOTOR_HP2300, 75, 1, 75, FULL_STEP, SANE_FALSE, SANE_TRUE , 63, 120, 8139, 560, 120, 4905, 337, 0.3, 0.4, 16}, + {MOTOR_HP2300, 150, 1, 150, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 67, 7903, 543, 120, 4905, 337, 0.3, 0.4, 16}, + {MOTOR_HP2300, 300, 1, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 2175, 1087, 120, 4905, 337, 0.3, 0.4, 16}, + {MOTOR_HP2300, 600, 1, 600, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 8700, 4350, 120, 4905, 337, 0.3, 0.4, 16}, + {MOTOR_HP2300,1200, 1,1200, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 3, 17400, 8700, 120, 4905, 337, 0.3, 0.4, 16}, /* non half ccd settings for 300 dpi - {MOTOR_HP2300, 300, SANE_TRUE, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 44, 5386, 2175, 120, 4905, 337, 0.3, 0.4, 16}, - {MOTOR_HP2300, 300, SANE_FALSE, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 44, 5386, 2175, 120, 4905, 337, 0.3, 0.4, 16}, + {MOTOR_HP2300, 300, 3, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 44, 5386, 2175, 120, 4905, 337, 0.3, 0.4, 16}, + {MOTOR_HP2300, 300, 1, 300, HALF_STEP, SANE_FALSE, SANE_TRUE , 63, 44, 5386, 2175, 120, 4905, 337, 0.3, 0.4, 16}, */ /* MD5345/6471 motor settings */ /* vfinal=(exposure/(1200/dpi))/step_type */ - {MOTOR_5345, 50, SANE_TRUE , 50, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 250, 255, 2000, 300, 0.3, 0.4, 64}, - {MOTOR_5345, 75, SANE_TRUE , 75, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 343, 255, 2000, 300, 0.3, 0.4, 64}, - {MOTOR_5345, 100, SANE_TRUE , 100, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 458, 255, 2000, 300, 0.3, 0.4, 64}, - {MOTOR_5345, 150, SANE_TRUE , 150, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 687, 255, 2000, 300, 0.3, 0.4, 64}, - {MOTOR_5345, 200, SANE_TRUE , 200, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 916, 255, 2000, 300, 0.3, 0.4, 64}, - {MOTOR_5345, 300, SANE_TRUE, 300, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 1375, 255, 2000, 300, 0.3, 0.4, 64}, - {MOTOR_5345, 400, SANE_TRUE, 400, HALF_STEP , SANE_FALSE, SANE_TRUE , 0, 32, 2000, 1833, 255, 2000, 300, 0.3, 0.4, 32}, - {MOTOR_5345, 500, SANE_TRUE, 500, HALF_STEP , SANE_FALSE, SANE_TRUE , 0, 32, 2291, 2291, 255, 2000, 300, 0.3, 0.4, 32}, - {MOTOR_5345, 600, SANE_TRUE, 600, HALF_STEP , SANE_FALSE, SANE_TRUE , 0, 32, 2750, 2750, 255, 2000, 300, 0.3, 0.4, 32}, - {MOTOR_5345, 1200, SANE_TRUE ,1200, QUATER_STEP, SANE_FALSE, SANE_TRUE , 0, 16, 2750, 2750, 255, 2000, 300, 0.3, 0.4, 146}, - {MOTOR_5345, 2400, SANE_TRUE ,2400, QUATER_STEP, SANE_FALSE, SANE_TRUE , 0, 16, 5500, 5500, 255, 2000, 300, 0.3, 0.4, 146}, - {MOTOR_5345, 50, SANE_FALSE, 50, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 250, 255, 2000, 300, 0.3, 0.4, 64}, - {MOTOR_5345, 75, SANE_FALSE, 75, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 343, 255, 2000, 300, 0.3, 0.4, 64}, - {MOTOR_5345, 100, SANE_FALSE, 100, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 458, 255, 2000, 300, 0.3, 0.4, 64}, - {MOTOR_5345, 150, SANE_FALSE, 150, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 687, 255, 2000, 300, 0.3, 0.4, 64}, - {MOTOR_5345, 200, SANE_FALSE, 200, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 916, 255, 2000, 300, 0.3, 0.4, 64}, - {MOTOR_5345, 300, SANE_FALSE, 300, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 1375, 255, 2000, 300, 0.3, 0.4, 64}, - {MOTOR_5345, 400, SANE_FALSE, 400, HALF_STEP , SANE_FALSE, SANE_TRUE , 0, 32, 2000, 1833, 255, 2000, 300, 0.3, 0.4, 32}, - {MOTOR_5345, 500, SANE_FALSE, 500, HALF_STEP , SANE_FALSE, SANE_TRUE , 0, 32, 2291, 2291, 255, 2000, 300, 0.3, 0.4, 32}, - {MOTOR_5345, 600, SANE_FALSE, 600, HALF_STEP , SANE_FALSE, SANE_TRUE , 0, 32, 2750, 2750, 255, 2000, 300, 0.3, 0.4, 32}, - {MOTOR_5345, 1200, SANE_FALSE,1200, QUATER_STEP, SANE_FALSE, SANE_TRUE , 0, 16, 2750, 2750, 255, 2000, 300, 0.3, 0.4, 146}, - {MOTOR_5345, 2400, SANE_FALSE,2400, QUATER_STEP, SANE_FALSE, SANE_TRUE , 0, 16, 5500, 5500, 255, 2000, 300, 0.3, 0.4, 146}, /* 5500 guessed */ + {MOTOR_5345, 50, 3, 50, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 250, 255, 2000, 300, 0.3, 0.4, 64}, + {MOTOR_5345, 75, 3, 75, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 343, 255, 2000, 300, 0.3, 0.4, 64}, + {MOTOR_5345, 100, 3, 100, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 458, 255, 2000, 300, 0.3, 0.4, 64}, + {MOTOR_5345, 150, 3, 150, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 687, 255, 2000, 300, 0.3, 0.4, 64}, + {MOTOR_5345, 200, 3, 200, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 916, 255, 2000, 300, 0.3, 0.4, 64}, + {MOTOR_5345, 300, 3, 300, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 1375, 255, 2000, 300, 0.3, 0.4, 64}, + {MOTOR_5345, 400, 3, 400, HALF_STEP , SANE_FALSE, SANE_TRUE , 0, 32, 2000, 1833, 255, 2000, 300, 0.3, 0.4, 32}, + {MOTOR_5345, 500, 3, 500, HALF_STEP , SANE_FALSE, SANE_TRUE , 0, 32, 2291, 2291, 255, 2000, 300, 0.3, 0.4, 32}, + {MOTOR_5345, 600, 3, 600, HALF_STEP , SANE_FALSE, SANE_TRUE , 0, 32, 2750, 2750, 255, 2000, 300, 0.3, 0.4, 32}, + {MOTOR_5345, 1200, 3,1200, QUATER_STEP, SANE_FALSE, SANE_TRUE , 0, 16, 2750, 2750, 255, 2000, 300, 0.3, 0.4, 146}, + {MOTOR_5345, 2400, 3,2400, QUATER_STEP, SANE_FALSE, SANE_TRUE , 0, 16, 5500, 5500, 255, 2000, 300, 0.3, 0.4, 146}, + {MOTOR_5345, 50, 1, 50, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 250, 255, 2000, 300, 0.3, 0.4, 64}, + {MOTOR_5345, 75, 1, 75, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 343, 255, 2000, 300, 0.3, 0.4, 64}, + {MOTOR_5345, 100, 1, 100, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 458, 255, 2000, 300, 0.3, 0.4, 64}, + {MOTOR_5345, 150, 1, 150, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 687, 255, 2000, 300, 0.3, 0.4, 64}, + {MOTOR_5345, 200, 1, 200, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 916, 255, 2000, 300, 0.3, 0.4, 64}, + {MOTOR_5345, 300, 1, 300, HALF_STEP , SANE_FALSE, SANE_TRUE , 2, 255, 2500, 1375, 255, 2000, 300, 0.3, 0.4, 64}, + {MOTOR_5345, 400, 1, 400, HALF_STEP , SANE_FALSE, SANE_TRUE , 0, 32, 2000, 1833, 255, 2000, 300, 0.3, 0.4, 32}, + {MOTOR_5345, 500, 1, 500, HALF_STEP , SANE_FALSE, SANE_TRUE , 0, 32, 2291, 2291, 255, 2000, 300, 0.3, 0.4, 32}, + {MOTOR_5345, 600, 1, 600, HALF_STEP , SANE_FALSE, SANE_TRUE , 0, 32, 2750, 2750, 255, 2000, 300, 0.3, 0.4, 32}, + {MOTOR_5345, 1200, 1,1200, QUATER_STEP, SANE_FALSE, SANE_TRUE , 0, 16, 2750, 2750, 255, 2000, 300, 0.3, 0.4, 146}, + {MOTOR_5345, 2400, 1,2400, QUATER_STEP, SANE_FALSE, SANE_TRUE , 0, 16, 5500, 5500, 255, 2000, 300, 0.3, 0.4, 146}, /* 5500 guessed */ }; /** diff --git a/backend/genesys_gl841.cc b/backend/genesys_gl841.cc index ef22622a3..7ebfe482c 100644 --- a/backend/genesys_gl841.cc +++ b/backend/genesys_gl841.cc @@ -634,7 +634,7 @@ gl841_init_registers (Genesys_Device * dev) dev->reg.find_reg(0x02).value = 0x30 /*0x38 */ ; /* auto home, one-table-move, full step */ dev->reg.find_reg(0x02).value |= REG02_AGOHOME; - dev->reg.find_reg(0x02).value |= REG02_MTRPWR; + sanei_genesys_set_motor_power(dev->reg, true); dev->reg.find_reg(0x02).value |= REG02_FASTFED; dev->reg.find_reg(0x03).value = 0x1f /*0x17 */ ; /* lamp on */ @@ -1817,7 +1817,7 @@ gl841_init_optical_regs_scan(Genesys_Device * dev, int channels, int depth, SANE_Bool half_ccd, - int color_filter, + ColorFilter color_filter, int flags ) { @@ -1901,25 +1901,7 @@ gl841_init_optical_regs_scan(Genesys_Device * dev, */ r = sanei_genesys_get_address (reg, 0x03); r->value |= REG03_AVEENB; - if (flags & OPTICAL_FLAG_DISABLE_LAMP) - r->value &= ~REG03_LAMPPWR; - else - r->value |= REG03_LAMPPWR; - - /* exposure times */ - if (flags & OPTICAL_FLAG_DISABLE_LAMP) { - // 0x0101 is as off as possible - sanei_genesys_set_exposure(*reg, {0x0101, 0x0101, 0x0101}); - } else { - // EXP[R,G,B] only matter for CIS scanners - sanei_genesys_set_exposure(*reg, sanei_genesys_fixup_exposure(sensor.exposure)); - } - - r = sanei_genesys_get_address (reg, 0x19); - if (flags & OPTICAL_FLAG_DISABLE_LAMP) - r->value = 0xff; - else - r->value = 0x50; + sanei_genesys_set_lamp_power(dev, sensor, *reg, !(flags & OPTICAL_FLAG_DISABLE_LAMP)); /* BW threshold */ r = sanei_genesys_get_address (reg, 0x2e); @@ -1955,18 +1937,18 @@ gl841_init_optical_regs_scan(Genesys_Device * dev, { switch (color_filter) { - case 0: - r->value |= 0x14; /* red filter */ - break; - case 1: - r->value |= 0x18; /* green filter */ - break; - case 2: - r->value |= 0x1c; /* blue filter */ - break; - default: - r->value |= 0x10; /* no filter */ - break; + case ColorFilter::RED: + r->value |= 0x14; + break; + case ColorFilter::GREEN: + r->value |= 0x18; + break; + case ColorFilter::BLUE: + r->value |= 0x1c; + break; + default: + r->value |= 0x10; + break; } } else @@ -2156,20 +2138,11 @@ int scan_step_type=0; */ static SANE_Status -gl841_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, - Genesys_Register_Set * reg, - float xres,/*dpi*/ - float yres,/*dpi*/ - float startx,/*optical_res, from dummy_pixel+1*/ - float starty,/*base_ydpi, from home!*/ - float pixels, - float lines, - unsigned int depth, - unsigned int channels, - int color_filter, - unsigned int flags - ) +gl841_init_scan_regs(Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Register_Set * reg, + SetupParams& params) { + params.assert_valid(); + int used_res; int start, used_pixels; int bytes_per_line; @@ -2192,18 +2165,8 @@ gl841_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, SANE_Status status; unsigned int oflags; /**> optical flags */ - DBG(DBG_info, - "%s settings:\n" - "Resolution : %gDPI/%gDPI\n" - "Lines : %g\n" - "PPL : %g\n" - "Startpos : %g/%g\n" - "Depth/Channels: %u/%u\n" - "Flags : %x\n\n", - __func__, xres, yres, lines, pixels, - startx, starty, - depth, channels, - flags); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, params); /* results: @@ -2236,7 +2199,7 @@ independent of our calculated values: /* half_ccd */ /* we have 2 domains for ccd: xres below or above half ccd max dpi */ - if (sensor.get_ccd_size_divisor_for_dpi(xres) > 1) { + if (sensor.get_ccd_size_divisor_for_dpi(params.xres) > 1) { half_ccd = SANE_TRUE; } else { half_ccd = SANE_FALSE; @@ -2251,17 +2214,17 @@ independent of our calculated values: /* stagger */ if ((!half_ccd) && (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE)) - stagger = (4 * yres) / dev->motor.base_ydpi; + stagger = (4 * params.yres) / dev->motor.base_ydpi; else stagger = 0; DBG(DBG_info, "%s : stagger=%d lines\n", __func__, stagger); /* used_res */ - i = optical_res / xres; + i = optical_res / params.xres; /* gl841 supports 1/1 1/2 1/3 1/4 1/5 1/6 1/8 1/10 1/12 1/15 averaging */ - if (i < 2 || (flags & SCAN_FLAG_USE_OPTICAL_RES)) /* optical_res >= xres > optical_res/2 */ + if (i < 2 || (params.flags & SCAN_FLAG_USE_OPTICAL_RES)) /* optical_res >= xres > optical_res/2 */ used_res = optical_res; else if (i < 3) /* optical_res/2 >= xres > optical_res/3 */ used_res = optical_res/2; @@ -2287,7 +2250,7 @@ independent of our calculated values: /* use detected left margin and fixed value */ /* start */ /* add x coordinates */ - start = ((sensor.CCD_start_xoffset + startx) * used_res) / sensor.optical_res; + start = ((sensor.CCD_start_xoffset + params.startx) * used_res) / sensor.optical_res; /* needs to be aligned for used_res */ start = (start * optical_res) / used_res; @@ -2309,10 +2272,10 @@ independent of our calculated values: /* compute correct pixels number */ /* pixels */ - used_pixels = (pixels * optical_res) / xres; + used_pixels = (params.pixels * optical_res) / params.xres; /* round up pixels number if needed */ - if (used_pixels * xres < pixels * optical_res) + if (used_pixels * params.xres < params.pixels * optical_res) used_pixels++; /* dummy */ @@ -2346,13 +2309,13 @@ dummy \ scanned lines /* cis color scan is effectively a gray scan with 3 gray lines per color line and a FILTER of 0 */ if (dev->model->is_cis) - slope_dpi = yres*channels; + slope_dpi = params.yres* params.channels; else - slope_dpi = yres; + slope_dpi = params.yres; slope_dpi = slope_dpi * (1 + dummy); - scan_step_type = gl841_scan_step_type(dev, yres); + scan_step_type = gl841_scan_step_type(dev, params.yres); exposure_time = gl841_exposure_time(dev, sensor, slope_dpi, scan_step_type, @@ -2364,25 +2327,25 @@ dummy \ scanned lines /*** optical parameters ***/ /* in case of dynamic lineart, we use an internal 8 bit gray scan * to generate 1 lineart data */ - if(flags & SCAN_FLAG_DYNAMIC_LINEART) + if(params.flags & SCAN_FLAG_DYNAMIC_LINEART) { - depth=8; + params.depth=8; } oflags=0; - if (flags & SCAN_FLAG_DISABLE_SHADING) + if (params.flags & SCAN_FLAG_DISABLE_SHADING) { oflags |= OPTICAL_FLAG_DISABLE_SHADING; } - if ((flags & SCAN_FLAG_DISABLE_GAMMA) || (depth==16)) + if ((params.flags & SCAN_FLAG_DISABLE_GAMMA) || (params.depth==16)) { oflags |= OPTICAL_FLAG_DISABLE_GAMMA; } - if (flags & SCAN_FLAG_DISABLE_LAMP) + if (params.flags & SCAN_FLAG_DISABLE_LAMP) { oflags |= OPTICAL_FLAG_DISABLE_LAMP; } - if (flags & SCAN_FLAG_ENABLE_LEDADD) + if (params.flags & SCAN_FLAG_ENABLE_LEDADD) { oflags |= OPTICAL_FLAG_ENABLE_LEDADD; } @@ -2393,10 +2356,10 @@ dummy \ scanned lines used_res, start, used_pixels, - channels, - depth, + params.channels, + params.depth, half_ccd, - color_filter, + params.color_filter, oflags); if (status != SANE_STATUS_GOOD) { @@ -2406,13 +2369,13 @@ dummy \ scanned lines /*** motor parameters ***/ /* scanned area must be enlarged by max color shift needed */ - max_shift=sanei_genesys_compute_max_shift(dev,channels,yres,flags); + max_shift=sanei_genesys_compute_max_shift(dev, params.channels,params.yres,params.flags); /* lincnt */ - lincnt = lines + max_shift + stagger; + lincnt = params.lines + max_shift + stagger; /* add tl_y to base movement */ - move = starty; + move = params.starty; DBG(DBG_info, "%s: move=%d steps\n", __func__, move); /* subtract current head position */ @@ -2427,19 +2390,19 @@ dummy \ scanned lines /* move = ((move + dummy) / (dummy + 1)) * (dummy + 1); DBG(DBG_info, "%s: move=%d steps\n", __func__, move);*/ - if (flags & SCAN_FLAG_SINGLE_LINE) - status = gl841_init_motor_regs_off(reg, dev->model->is_cis?lincnt*channels:lincnt); + if (params.flags & SCAN_FLAG_SINGLE_LINE) + status = gl841_init_motor_regs_off(reg, dev->model->is_cis?lincnt* params.channels:lincnt); else status = gl841_init_motor_regs_scan(dev, sensor, reg, exposure_time, slope_dpi, scan_step_type, - dev->model->is_cis?lincnt*channels:lincnt, + dev->model->is_cis?lincnt* params.channels:lincnt, dummy, move, scan_power_mode, - (flags & SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE)? + (params.flags & SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE)? MOTOR_FLAG_DISABLE_BUFFER_FULL_MOVE:0 ); @@ -2451,7 +2414,7 @@ dummy \ scanned lines /* words_per_line */ bytes_per_line = (used_pixels * used_res) / optical_res; - bytes_per_line = (bytes_per_line * channels * depth) / 8; + bytes_per_line = (bytes_per_line * params.channels * params.depth) / 8; requested_buffer_size = 8 * bytes_per_line; /* we must use a round number of bytes_per_line */ @@ -2461,7 +2424,7 @@ dummy \ scanned lines read_buffer_size = 2 * requested_buffer_size + - ((max_shift + stagger) * used_pixels * channels * depth) / 8; + ((max_shift + stagger) * used_pixels * params.channels * params.depth) / 8; dev->read_buffer.clear(); dev->read_buffer.alloc(read_buffer_size); @@ -2473,21 +2436,21 @@ dummy \ scanned lines dev->shrink_buffer.alloc(requested_buffer_size); dev->out_buffer.clear(); - dev->out_buffer.alloc((8 * dev->settings.pixels * channels * depth) / 8); + dev->out_buffer.alloc((8 * dev->settings.pixels * params.channels * params.depth) / 8); dev->read_bytes_left = bytes_per_line * lincnt; DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left); dev->read_active = SANE_TRUE; - + dev->current_setup.params = params; dev->current_setup.pixels = (used_pixels * used_res)/optical_res; dev->current_setup.lines = lincnt; - dev->current_setup.depth = depth; - dev->current_setup.channels = channels; + dev->current_setup.depth = params.depth; + dev->current_setup.channels = params.channels; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = used_res; - dev->current_setup.yres = yres; + dev->current_setup.yres = params.yres; dev->current_setup.ccd_size_divisor = half_ccd ? 2 : 1; dev->current_setup.stagger = stagger; dev->current_setup.max_shift = max_shift + stagger; @@ -2508,14 +2471,14 @@ dummy \ scanned lines */ dev->total_bytes_read = 0; - if (depth == 1) + if (params.depth == 1) dev->total_bytes_to_read = ((dev->settings.pixels * dev->settings.lines) / 8 + (((dev->settings.pixels * dev->settings.lines)%8)?1:0) - ) * channels; + ) * params.channels; else dev->total_bytes_to_read = - dev->settings.pixels * dev->settings.lines * channels * (depth / 8); + dev->settings.pixels * dev->settings.lines * params.channels * (params.depth / 8); DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); /* END TODO */ @@ -2530,12 +2493,6 @@ static SANE_Status gl841_calculate_current_setup(Genesys_Device * dev, const Gen int depth; int start; - float xres;/*dpi*/ - float yres;/*dpi*/ - float startx;/*optical_res, from dummy_pixel+1*/ - float pixels; - float lines; - int used_res; int used_pixels; unsigned int lincnt; @@ -2552,26 +2509,18 @@ static SANE_Status gl841_calculate_current_setup(Genesys_Device * dev, const Gen SANE_Bool half_ccd; /* false: full CCD res is used, true, half max CCD res is used */ int optical_res; - DBG(DBG_info, - "%s:\n" - "Resolution: %uDPI\n" - "Lines : %u\n" - "PPL : %u\n" - "Startpos : %.3f/%.3f\n" - "Scan mode : %d\n\n", - __func__, - dev->settings.yres, dev->settings.lines, dev->settings.pixels, - dev->settings.tl_x, dev->settings.tl_y, dev->settings.scan_mode); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, dev->settings); /* channels */ - if (dev->settings.scan_mode == 4) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; else channels = 1; /* depth */ depth = dev->settings.depth; - if (dev->settings.scan_mode == 0) + if (dev->settings.scan_mode == ScanColorMode::LINEART) depth = 1; /* start */ @@ -2581,27 +2530,26 @@ static SANE_Status gl841_calculate_current_setup(Genesys_Device * dev, const Gen start = (start * sensor.optical_res) / MM_PER_INCH; + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = start; + params.starty = 0; // not used + params.pixels = dev->settings.pixels; + params.lines = dev->settings.lines; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = 0; - xres = dev->settings.xres;/*dpi*/ - yres = dev->settings.yres;/*dpi*/ - startx = start;/*optical_res, from dummy_pixel+1*/ - pixels = dev->settings.pixels; - lines = dev->settings.lines; - - DBG(DBG_info, - "%s:\n" - "Resolution : %gDPI/%gDPI\n" - "Lines : %g\n" - "PPL : %g\n" - "Startpos : %g\n" - "Depth/Channels: %u/%u\n\n", - __func__, xres, yres, lines, pixels, - startx, - depth, channels); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, params); /* half_ccd */ /* we have 2 domains for ccd: xres below or above half ccd max dpi */ - if (sensor.get_ccd_size_divisor_for_dpi(xres) > 1) { + if (sensor.get_ccd_size_divisor_for_dpi(params.xres) > 1) { half_ccd = SANE_TRUE; } else { half_ccd = SANE_FALSE; @@ -2616,13 +2564,13 @@ static SANE_Status gl841_calculate_current_setup(Genesys_Device * dev, const Gen /* stagger */ if ((!half_ccd) && (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE)) - stagger = (4 * yres) / dev->motor.base_ydpi; + stagger = (4 * params.yres) / dev->motor.base_ydpi; else stagger = 0; DBG(DBG_info, "%s: stagger=%d lines\n", __func__, stagger); /* used_res */ - i = optical_res / xres; + i = optical_res / params.xres; /* gl841 supports 1/1 1/2 1/3 1/4 1/5 1/6 1/8 1/10 1/12 1/15 averaging */ @@ -2650,30 +2598,24 @@ static SANE_Status gl841_calculate_current_setup(Genesys_Device * dev, const Gen /* compute scan parameters values */ /* pixels are allways given at half or full CCD optical resolution */ /* use detected left margin and fixed value */ -/* start */ - /* add x coordinates */ - start = - ((sensor.CCD_start_xoffset + startx) * used_res) / - sensor.optical_res; + start = ((sensor.CCD_start_xoffset + params.startx) * used_res) / sensor.optical_res; /* needs to be aligned for used_res */ start = (start * optical_res) / used_res; start += sensor.dummy_pixel + 1; - if (stagger > 0) + if (stagger > 0) { start |= 1; + } - /* compute correct pixels number */ -/* pixels */ - used_pixels = - (pixels * optical_res) / xres; + used_pixels = (params.pixels * optical_res) / params.xres; - /* round up pixels number if needed */ - if (used_pixels * xres < pixels * optical_res) - used_pixels++; + // round up pixels number if needed + if (used_pixels * params.xres < params.pixels * optical_res) { + used_pixels++; + } -/* dummy */ /* dummy lines: may not be usefull, for instance 250 dpi works with 0 or 1 dummy line. Maybe the dummy line adds correctness since the motor runs slower (higher dpi) @@ -2700,17 +2642,17 @@ dummy \ scanned lines */ dummy = 0; -/* slope_dpi */ /* cis color scan is effectively a gray scan with 3 gray lines per color line and a FILTER of 0 */ - if (dev->model->is_cis) - slope_dpi = yres*channels; - else - slope_dpi = yres; + if (dev->model->is_cis) { + slope_dpi = params.yres * params.channels; + } else { + slope_dpi = params.yres; + } slope_dpi = slope_dpi * (1 + dummy); - scan_step_type = gl841_scan_step_type(dev, yres); + scan_step_type = gl841_scan_step_type(dev, params.yres); exposure_time = gl841_exposure_time(dev, sensor, slope_dpi, scan_step_type, @@ -2720,18 +2662,18 @@ dummy \ scanned lines DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); /* scanned area must be enlarged by max color shift needed */ - max_shift=sanei_genesys_compute_max_shift(dev,channels,yres,0); + max_shift = sanei_genesys_compute_max_shift(dev, params.channels, params.yres, 0); - /* lincnt */ - lincnt = lines + max_shift + stagger; + lincnt = params.lines + max_shift + stagger; + dev->current_setup.params = params; dev->current_setup.pixels = (used_pixels * used_res)/optical_res; dev->current_setup.lines = lincnt; - dev->current_setup.depth = depth; - dev->current_setup.channels = channels; + dev->current_setup.depth = params.depth; + dev->current_setup.channels = params.channels; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = used_res; - dev->current_setup.yres = yres; + dev->current_setup.yres = params.yres; dev->current_setup.ccd_size_divisor = half_ccd ? 2 : 1; dev->current_setup.stagger = stagger; dev->current_setup.max_shift = max_shift + stagger; @@ -2740,65 +2682,6 @@ dummy \ scanned lines return SANE_STATUS_GOOD; } -static void -gl841_set_motor_power (Genesys_Register_Set * regs, SANE_Bool set) -{ - - DBG(DBG_proc, "%s\n", __func__); - - if (set) - { - sanei_genesys_set_reg_from_set (regs, 0x02, - sanei_genesys_read_reg_from_set (regs, - 0x02) | - REG02_MTRPWR); - } - else - { - sanei_genesys_set_reg_from_set (regs, 0x02, - sanei_genesys_read_reg_from_set (regs, - 0x02) & - ~REG02_MTRPWR); - } -} - -static void -gl841_set_lamp_power (Genesys_Device * dev, const Genesys_Sensor& sensor, - Genesys_Register_Set * regs, SANE_Bool set) -{ - (void) dev; - GenesysRegister* r; - int i; - - if (set) - { - sanei_genesys_set_reg_from_set (regs, 0x03, - sanei_genesys_read_reg_from_set (regs, - 0x03) | - REG03_LAMPPWR); - - sanei_genesys_set_exposure(*regs, - sanei_genesys_fixup_exposure(sensor.exposure)); - - r = sanei_genesys_get_address (regs, 0x19); - r->value = 0x50; - } - else - { - sanei_genesys_set_reg_from_set (regs, 0x03, - sanei_genesys_read_reg_from_set (regs, - 0x03) & - ~REG03_LAMPPWR); - - r = sanei_genesys_get_address (regs, 0x10); - for (i = 0; i < 6; i++, r++) { - r->value = 0x01;/* 0x0101 is as off as possible */ - } - r = sanei_genesys_get_address (regs, 0x19); - r->value = 0xff; - } -} - /*for fast power saving methods only, like disabling certain amplifiers*/ static SANE_Status gl841_save_power(Genesys_Device * dev, SANE_Bool enable) { @@ -3295,7 +3178,7 @@ gl841_detect_document_end (Genesys_Device * dev) DBG(DBG_proc, "%s: finished\n", __func__); return SANE_STATUS_GOOD; } - if (dev->settings.scan_mode == SCAN_MODE_COLOR && dev->model->is_cis) + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS && dev->model->is_cis) { scancnt/=3; } @@ -3646,21 +3529,25 @@ gl841_search_start_position (Genesys_Device * dev) // whith employ different sensors with potentially different settings. auto& sensor = sanei_genesys_find_sensor_for_write(dev, dpi); - status = gl841_init_scan_regs (dev, sensor, - &local_reg, - dpi, - dpi, - 0, - 0,/*we should give a small offset here~60 steps*/ - 600, - dev->model->search_lines, - 8, - 1, - 1,/*green*/ - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_IGNORE_LINE_DISTANCE | - SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE); + SetupParams params; + params.xres = dpi; + params.yres = dpi; + params.startx = 0; + params.starty = 0; /*we should give a small offset here~60 steps*/ + params.pixels = 600; + params.lines = dev->model->search_lines; + params.depth = 8; + params.channels = 1; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::GRAY; + params.color_filter = ColorFilter::GREEN; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_IGNORE_LINE_DISTANCE | + SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE; + + status = gl841_init_scan_regs(dev, sensor, &local_reg, params); + if(status!=SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to init scan registers: %s\n", __func__, sane_strstatus(status)); @@ -3732,7 +3619,8 @@ gl841_search_start_position (Genesys_Device * dev) * sets up register for coarse gain calibration * todo: check it for scanners using it */ static SANE_Status -gl841_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl841_init_regs_for_coarse_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status; uint8_t channels; @@ -3740,30 +3628,34 @@ gl841_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sens DBGSTART; - cksel = (dev->calib_reg.find_reg(0x18).value & REG18_CKSEL) + 1; /* clock speed = 1..4 clocks */ + cksel = (regs.find_reg(0x18).value & REG18_CKSEL) + 1; /* clock speed = 1..4 clocks */ /* set line size */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; - else + else { channels = 1; + } + + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = 0; + params.starty = 0; + params.pixels = sensor.optical_res / cksel; /* XXX STEF XXX !!! */ + params.lines = 20; + params.depth = 16; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl841_init_scan_regs(dev, sensor, ®s, params); - status = gl841_init_scan_regs (dev, sensor, - &dev->calib_reg, - dev->settings.xres, - dev->settings.yres, - 0, - 0, - sensor.optical_res / cksel, /* XXX STEF XXX !!! */ - 20, - 16, - channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE - ); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus(status)); @@ -3773,7 +3665,7 @@ gl841_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sens DBG(DBG_info, "%s: optical sensor res: %d dpi, actual res: %d\n", __func__, sensor.optical_res / cksel, dev->settings.xres); - status = sanei_genesys_bulk_write_register(dev, dev->calib_reg); + status = sanei_genesys_bulk_write_register(dev, regs); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to bulk write registers: %s\n", __func__, sane_strstatus(status)); @@ -3782,7 +3674,7 @@ gl841_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sens /* if (DBG_LEVEL >= DBG_info) - sanei_gl841_print_registers (dev->calib_reg);*/ + sanei_gl841_print_registers (regs);*/ DBGCOMPLETED; return SANE_STATUS_GOOD; @@ -3791,7 +3683,8 @@ gl841_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sens /* init registers for shading calibration */ static SANE_Status -gl841_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl841_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status; SANE_Int ydpi; @@ -3801,7 +3694,7 @@ gl841_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) DBG(DBG_proc, "%s: lines = %d\n", __func__, (int)(dev->calib_lines)); /* initial calibration reg values */ - dev->calib_reg = dev->reg; + regs = dev->reg; ydpi = dev->motor.base_ydpi; if (dev->model->motor_type == MOTOR_PLUSTEK_3600) /* TODO PLUSTEK_3600: 1200dpi not yet working, produces dark bar */ @@ -3826,22 +3719,27 @@ gl841_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) dev->calib_channels = 3; dev->calib_lines = dev->model->shading_lines; - status = gl841_init_scan_regs (dev, sensor, - &dev->calib_reg, - dev->settings.xres, - ydpi, - 0, - starty, - (sensor.sensor_pixels * dev->settings.xres) / sensor.optical_res, - dev->calib_lines, - 16, - dev->calib_channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_USE_OPTICAL_RES | - /*SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE |*/ - SCAN_FLAG_IGNORE_LINE_DISTANCE); + + SetupParams params; + params.xres = dev->settings.xres; + params.yres = ydpi; + params.startx = 0; + params.starty = starty; + params.pixels = (sensor.sensor_pixels * dev->settings.xres) / sensor.optical_res; + params.lines = dev->calib_lines; + params.depth = 16; + params.channels = dev->calib_channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_USE_OPTICAL_RES | + /*SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE |*/ + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl841_init_scan_regs(dev, sensor, ®s, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus(status)); @@ -3851,7 +3749,7 @@ gl841_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) dev->calib_pixels = dev->current_setup.pixels; dev->scanhead_position_in_steps += dev->calib_lines + starty; - status = sanei_genesys_bulk_write_register(dev, dev->calib_reg); + status = sanei_genesys_bulk_write_register(dev, regs); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to bulk write registers: %s\n", __func__, sane_strstatus(status)); @@ -3876,22 +3774,20 @@ gl841_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) SANE_Status status; - DBG(DBG_info, "%s:\nResolution: %uDPI\n" - "Lines : %u\nPPL : %u\nStartpos : %.3f/%.3f\nScan mode : %d\n\n", __func__, - dev->settings.yres, dev->settings.lines, dev->settings.pixels, dev->settings.tl_x, - dev->settings.tl_y, dev->settings.scan_mode); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, dev->settings); gl841_slow_back_home(dev,SANE_TRUE); /* channels */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; else channels = 1; /* depth */ depth = dev->settings.depth; - if (dev->settings.scan_mode == SCAN_MODE_LINEART) + if (dev->settings.scan_mode == ScanColorMode::LINEART) depth = 1; @@ -3948,7 +3844,7 @@ gl841_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) /* true gray (led add for cis scanners) */ if(dev->model->is_cis && dev->settings.true_gray - && dev->settings.scan_mode != SCAN_MODE_COLOR + && dev->settings.scan_mode != ScanColorMode::COLOR_SINGLE_PASS && dev->model->ccd_type != CIS_CANONLIDE80) { // on Lide 80 the LEDADD bit results in only red LED array being lit @@ -3957,24 +3853,27 @@ gl841_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) } /* enable emulated lineart from gray data */ - if(dev->settings.scan_mode == SCAN_MODE_LINEART + if(dev->settings.scan_mode == ScanColorMode::LINEART && dev->settings.dynamic_lineart) { flags |= SCAN_FLAG_DYNAMIC_LINEART; } - status = gl841_init_scan_regs (dev, sensor, - &dev->reg, - dev->settings.xres, - dev->settings.yres, - start, - move, - dev->settings.pixels, - dev->settings.lines, - depth, - channels, - dev->settings.color_filter, - flags); + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = start; + params.starty = move; + params.pixels = dev->settings.pixels; + params.lines = dev->settings.lines; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = flags; + + status = gl841_init_scan_regs(dev, sensor, &dev->reg, params); if (status != SANE_STATUS_GOOD) return status; @@ -4030,7 +3929,7 @@ gl841_send_gamma_table(Genesys_Device * dev, const Genesys_Sensor& sensor) -needs working coarse/gain */ static SANE_Status -gl841_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) +gl841_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor, Genesys_Register_Set& regs) { int num_pixels; int total_size; @@ -4068,23 +3967,25 @@ gl841_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) /* offset calibration is always done in color mode */ channels = 3; - status = gl841_init_scan_regs (dev, sensor, - &dev->calib_reg, - dev->settings.xres, - dev->settings.yres, - 0, - 0, - (sensor.sensor_pixels*dev->settings.xres) / sensor.optical_res, - 1, - 16, - channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE | - SCAN_FLAG_USE_OPTICAL_RES - ); + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = 0; + params.starty = 0; + params.pixels = (sensor.sensor_pixels*dev->settings.xres) / sensor.optical_res; + params.lines = 1; + params.depth = 16; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE | + SCAN_FLAG_USE_OPTICAL_RES; + + status = gl841_init_scan_regs(dev, sensor, ®s, params); if (status != SANE_STATUS_GOOD) { @@ -4092,7 +3993,7 @@ gl841_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) return status; } - RIE(sanei_genesys_bulk_write_register(dev, dev->calib_reg)); + RIE(sanei_genesys_bulk_write_register(dev, regs)); num_pixels = dev->current_setup.pixels; @@ -4123,7 +4024,7 @@ gl841_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) sensor.exposure.green = exp[1]; sensor.exposure.blue = exp[2]; - sanei_genesys_set_exposure(dev->calib_reg, sensor.exposure); + sanei_genesys_set_exposure(regs, sensor.exposure); RIE(sanei_genesys_write_register(dev, 0x10, (sensor.exposure.red >> 8) & 0xff)); RIE(sanei_genesys_write_register(dev, 0x11, sensor.exposure.red & 0xff)); RIE(sanei_genesys_write_register(dev, 0x12, (sensor.exposure.green >> 8) & 0xff)); @@ -4131,10 +4032,10 @@ gl841_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) RIE(sanei_genesys_write_register(dev, 0x14, (sensor.exposure.blue >> 8) & 0xff)); RIE(sanei_genesys_write_register(dev, 0x15, sensor.exposure.blue & 0xff)); - RIE(sanei_genesys_bulk_write_register(dev, dev->calib_reg)); + RIE(sanei_genesys_bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting line reading\n", __func__); - RIE(gl841_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl841_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, line.data(), total_size)); if (DBG_LEVEL >= DBG_data) { @@ -4250,7 +4151,8 @@ gl841_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) * We scan a line with no gain until average offset reaches the target */ static SANE_Status -ad_fe_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) +ad_fe_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status = SANE_STATUS_GOOD; int num_pixels; @@ -4271,22 +4173,25 @@ ad_fe_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) return status; } - status = gl841_init_scan_regs (dev, sensor, - &dev->calib_reg, - dev->settings.xres, - dev->settings.yres, - 0, - 0, - (sensor.sensor_pixels*dev->settings.xres) / sensor.optical_res, - 1, - 8, - 3, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE | - SCAN_FLAG_USE_OPTICAL_RES); + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = 0; + params.starty = 0; + params.pixels = (sensor.sensor_pixels*dev->settings.xres) / sensor.optical_res; + params.lines = 1; + params.depth = 8; + params.channels = 3; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE | + SCAN_FLAG_USE_OPTICAL_RES; + + status = gl841_init_scan_regs(dev, sensor, ®s, params); if (status != SANE_STATUS_GOOD) { @@ -4316,9 +4221,9 @@ ad_fe_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) /* scan line */ DBG(DBG_info, "%s: starting line reading\n", __func__); - sanei_genesys_bulk_write_register(dev, dev->calib_reg); + sanei_genesys_bulk_write_register(dev, regs); gl841_set_fe(dev, sensor, AFE_SET); - gl841_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE); + gl841_begin_scan(dev, sensor, ®s, SANE_TRUE); sanei_genesys_read_data_from_scanner(dev, line.data(), total_size); gl841_stop_action (dev); if (DBG_LEVEL >= DBG_data) { @@ -4369,7 +4274,8 @@ ad_fe_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) this function expects the slider to be where? */ static SANE_Status -gl841_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl841_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { int num_pixels; int total_size; @@ -4389,30 +4295,32 @@ gl841_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) /* Analog Device fronted have a different calibration */ if ((dev->reg.find_reg(0x04).value & REG04_FESET) == 0x02) { - return ad_fe_offset_calibration (dev, sensor); + return ad_fe_offset_calibration(dev, sensor, regs); } /* offset calibration is always done in color mode */ channels = 3; - status = gl841_init_scan_regs (dev, sensor, - &dev->calib_reg, - dev->settings.xres, - dev->settings.yres, - 0, - 0, - (sensor.sensor_pixels*dev->settings.xres) / sensor.optical_res, - 1, - 16, - channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE | - SCAN_FLAG_USE_OPTICAL_RES | - SCAN_FLAG_DISABLE_LAMP - ); + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = 0; + params.starty = 0; + params.pixels = (sensor.sensor_pixels*dev->settings.xres) / sensor.optical_res; + params.lines = 1; + params.depth = 16; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE | + SCAN_FLAG_USE_OPTICAL_RES | + SCAN_FLAG_DISABLE_LAMP; + + status = gl841_init_scan_regs(dev, sensor, ®s, params); if (status != SANE_STATUS_GOOD) { @@ -4459,7 +4367,7 @@ gl841_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) do { - RIE(sanei_genesys_bulk_write_register(dev, dev->calib_reg)); + RIE(sanei_genesys_bulk_write_register(dev, regs)); for (j=0; j < channels; j++) { off[j] = (offh[j]+offl[j])/2; @@ -4475,7 +4383,7 @@ gl841_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) } DBG(DBG_info, "%s: starting first line reading\n", __func__); - RIE(gl841_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl841_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner (dev, first_line.data(), total_size)); @@ -4588,8 +4496,8 @@ gl841_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) } DBG(DBG_info, "%s: starting second line reading\n", __func__); - RIE(sanei_genesys_bulk_write_register(dev, dev->calib_reg)); - RIE(gl841_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(sanei_genesys_bulk_write_register(dev, regs)); + RIE(gl841_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner (dev, second_line.data(), total_size)); if (DBG_LEVEL >= DBG_data) { @@ -4750,7 +4658,8 @@ gl841_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) be done with shading. */ static SANE_Status -gl841_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor, int dpi) +gl841_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs, int dpi) { int num_pixels; int total_size; @@ -4781,23 +4690,25 @@ gl841_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso /* coarse gain calibration is allways done in color mode */ channels = 3; - status = gl841_init_scan_regs (dev, sensor, - &dev->calib_reg, - dev->settings.xres, - dev->settings.yres, - 0, - 0, - (sensor.sensor_pixels*dev->settings.xres) / sensor.optical_res, - lines, - 16, - channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE | - SCAN_FLAG_USE_OPTICAL_RES - ); + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = 0; + params.starty = 0; + params.pixels = (sensor.sensor_pixels*dev->settings.xres) / sensor.optical_res; + params.lines = lines; + params.depth = 16; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE | + SCAN_FLAG_USE_OPTICAL_RES; + + status = gl841_init_scan_regs(dev, sensor, ®s, params); if (status != SANE_STATUS_GOOD) { @@ -4805,7 +4716,7 @@ gl841_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso return status; } - RIE(sanei_genesys_bulk_write_register(dev, dev->calib_reg)); + RIE(sanei_genesys_bulk_write_register(dev, regs)); num_pixels = dev->current_setup.pixels; @@ -4813,7 +4724,7 @@ gl841_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso std::vector line(total_size); - RIE(gl841_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl841_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, line.data(), total_size)); if (DBG_LEVEL >= DBG_data) @@ -4944,23 +4855,29 @@ gl841_init_regs_for_warmup (Genesys_Device * dev, dev->frontend.set_offset(1, 0x80); dev->frontend.set_offset(2, 0x80); - status = gl841_init_scan_regs (dev, sensor, - local_reg, - sensor.optical_res, - dev->settings.yres, - sensor.dummy_pixel, - 0, - num_pixels, - 1, - 16, - *channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE | - SCAN_FLAG_USE_OPTICAL_RES - ); + SetupParams params; + params.xres = sensor.optical_res; + params.yres = dev->settings.yres; + params.startx = sensor.dummy_pixel; + params.starty = 0; + params.pixels = num_pixels; + params.lines = 1; + params.depth = 16; + params.channels = *channels; + params.scan_method = dev->settings.scan_method; + if (*channels == 3) { + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + } else { + params.scan_mode = ScanColorMode::GRAY; + } + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE | + SCAN_FLAG_USE_OPTICAL_RES; + + status = gl841_init_scan_regs(dev, sensor, local_reg, params); if (status != SANE_STATUS_GOOD) { @@ -5086,7 +5003,7 @@ gl841_init (Genesys_Device * dev) dev->dark_average_data.clear(); dev->white_average_data.clear(); - dev->settings.color_filter = 0; + dev->settings.color_filter = ColorFilter::RED; /* ASIC reset */ RIE (sanei_genesys_write_register (dev, 0x0e, 0x01)); @@ -5141,34 +5058,37 @@ gl841_init (Genesys_Device * dev) } /* initial calibration reg values */ - dev->calib_reg = dev->reg; + Genesys_Register_Set& regs = dev->calib_reg; + regs = dev->reg; - status = gl841_init_scan_regs (dev, sensor, - &dev->calib_reg, - 300, - 300, - 0, - 0, - (16 * 300) / sensor.optical_res, - 1, - 16, - 3, - 0, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE | - SCAN_FLAG_USE_OPTICAL_RES - ); + SetupParams params; + params.xres = 300; + params.yres = 300; + params.startx = 0; + params.starty = 0; + params.pixels = (16 * 300) / sensor.optical_res; + params.lines = 1; + params.depth = 16; + params.channels = 3; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = ColorFilter::RED; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE | + SCAN_FLAG_USE_OPTICAL_RES; - RIE(sanei_genesys_bulk_write_register(dev, dev->calib_reg)); + status = gl841_init_scan_regs(dev, sensor, ®s, params); + + RIE(sanei_genesys_bulk_write_register(dev, regs)); size = dev->current_setup.pixels * 3 * 2 * 1; /* colors * bytes_per_color * scan lines */ std::vector line(size); DBG(DBG_info, "%s: starting dummy data reading\n", __func__); - RIE(gl841_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl841_begin_scan(dev, sensor, ®s, SANE_TRUE)); sanei_usb_set_timeout(1000);/* 1 second*/ @@ -5177,9 +5097,9 @@ gl841_init (Genesys_Device * dev) sanei_usb_set_timeout(30 * 1000);/* 30 seconds*/ - RIE (gl841_end_scan(dev, &dev->calib_reg, SANE_TRUE)); + RIE (gl841_end_scan(dev, ®s, SANE_TRUE)); - dev->calib_reg = dev->reg; + regs = dev->reg; /* Set powersaving (default = 15 minutes) */ RIE (gl841_set_powersaving (dev, 15)); @@ -5201,28 +5121,21 @@ gl841_update_hardware_sensors (Genesys_Scanner * s) if (s->dev->model->gpo_type == GPO_CANONLIDE35 || s->dev->model->gpo_type == GPO_CANONLIDE80) { - RIE(sanei_genesys_read_register(s->dev, REG6D, &val)); - - if (s->val[OPT_SCAN_SW].b == s->last_val[OPT_SCAN_SW].b) - s->val[OPT_SCAN_SW].b = (val & 0x01) == 0; - if (s->val[OPT_FILE_SW].b == s->last_val[OPT_FILE_SW].b) - s->val[OPT_FILE_SW].b = (val & 0x02) == 0; - if (s->val[OPT_EMAIL_SW].b == s->last_val[OPT_EMAIL_SW].b) - s->val[OPT_EMAIL_SW].b = (val & 0x04) == 0; - if (s->val[OPT_COPY_SW].b == s->last_val[OPT_COPY_SW].b) - s->val[OPT_COPY_SW].b = (val & 0x08) == 0; + RIE(sanei_genesys_read_register(s->dev, REG6D, &val)); + s->buttons[BUTTON_SCAN_SW].write((val & 0x01) == 0); + s->buttons[BUTTON_FILE_SW].write((val & 0x02) == 0); + s->buttons[BUTTON_EMAIL_SW].write((val & 0x04) == 0); + s->buttons[BUTTON_COPY_SW].write((val & 0x08) == 0); } if (s->dev->model->gpo_type == GPO_XP300 || s->dev->model->gpo_type == GPO_DP665 || s->dev->model->gpo_type == GPO_DP685) { - RIE(sanei_genesys_read_register(s->dev, REG6D, &val)); + RIE(sanei_genesys_read_register(s->dev, REG6D, &val)); - if (s->val[OPT_PAGE_LOADED_SW].b == s->last_val[OPT_PAGE_LOADED_SW].b) - s->val[OPT_PAGE_LOADED_SW].b = (val & 0x01) == 0; - if (s->val[OPT_SCAN_SW].b == s->last_val[OPT_SCAN_SW].b) - s->val[OPT_SCAN_SW].b = (val & 0x02) == 0; + s->buttons[BUTTON_PAGE_LOADED_SW].write((val & 0x01) == 0); + s->buttons[BUTTON_SCAN_SW].write((val & 0x02) == 0); } return status; @@ -5296,18 +5209,22 @@ gl841_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor, local_reg = dev->reg; - status = gl841_init_scan_regs (dev, sensor, - &local_reg, - dpi, - dpi, - 0, - 0, - pixels, - lines, - depth, - channels, - 0, - SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA); + SetupParams params; + params.xres = dpi; + params.yres = dpi; + params.startx = 0; + params.starty = 0; + params.pixels = pixels; + params.lines = lines; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::GRAY; + params.color_filter = ColorFilter::RED; + params.flags = SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA; + + status = gl841_init_scan_regs(dev, sensor, &local_reg, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup for scan: %s\n", __func__, sane_strstatus(status)); @@ -5648,9 +5565,6 @@ static Genesys_Command_Set gl841_cmd_set = { gl841_set_powersaving, gl841_save_power, - gl841_set_motor_power, - gl841_set_lamp_power, - gl841_begin_scan, gl841_end_scan, @@ -5680,7 +5594,6 @@ static Genesys_Command_Set gl841_cmd_set = { NULL, gl841_send_shading_data, gl841_calculate_current_setup, - NULL, NULL }; diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index 348b681d5..b7d809574 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -906,7 +906,7 @@ gl843_init_motor_regs_scan (Genesys_Device * dev, /* compute register 02 value */ r = sanei_genesys_get_address (reg, REG02); r->value = 0x00; - r->value |= REG02_MTRPWR; + sanei_genesys_set_motor_power(*reg, true); if (use_fast_fed) r->value |= REG02_FASTFED; @@ -1089,7 +1089,7 @@ gl843_init_optical_regs_scan (Genesys_Device * dev, int channels, int depth, unsigned ccd_size_divisor, - int color_filter, + ColorFilter color_filter, int flags) { unsigned int words_per_line; @@ -1177,13 +1177,13 @@ gl843_init_optical_regs_scan (Genesys_Device * dev, r = sanei_genesys_get_address (reg, REG03); if (dev->model->model_id == MODEL_CANON_CANOSCAN_8600F) r->value |= REG03_AVEENB; - else + else { r->value &= ~REG03_AVEENB; + } - if (flags & OPTICAL_FLAG_DISABLE_LAMP) - r->value &= ~REG03_LAMPPWR; - else - r->value |= REG03_LAMPPWR; + // FIXME: we probably don't need to set exposure to registers at this point. It was this way + // before a refactor. + sanei_genesys_set_lamp_power(dev, sensor, *reg, !(flags & OPTICAL_FLAG_DISABLE_LAMP)); /* select XPA */ r->value &= ~REG03_XPASEL; @@ -1191,6 +1191,7 @@ gl843_init_optical_regs_scan (Genesys_Device * dev, { r->value |= REG03_XPASEL; } + reg->state.is_xpa_on = flags & OPTICAL_FLAG_USE_XPA; /* BW threshold */ r = sanei_genesys_get_address (reg, REG2E); @@ -1220,15 +1221,17 @@ gl843_init_optical_regs_scan (Genesys_Device * dev, { switch (color_filter) { - case 0: - r->value |= 0x14; /* red filter */ - break; - case 2: - r->value |= 0x1c; /* blue filter */ - break; - default: - r->value |= 0x18; /* green filter */ - break; + case ColorFilter::RED: + r->value |= 0x14; + break; + case ColorFilter::BLUE: + r->value |= 0x1c; + break; + case ColorFilter::GREEN: + r->value |= 0x18; + break; + default: + break; // should not happen } } else @@ -1306,42 +1309,8 @@ gl843_init_optical_regs_scan (Genesys_Device * dev, return SANE_STATUS_GOOD; } -struct ScanSessionParams { - // resolution in x direction - float xres = -1; - // resolution in y direction - float yres = -1; - // start pixel in X direction, from dummy_pixel + 1 - float startx = -1; - // start pixel in Y direction, counted according to base_ydpi - float starty = -1; - // the number of pixels in X direction - float pixels = -1; - // the number of pixels in Y direction - float lines = -1; - // the depth of the scan in bits. Allowed are 1, 8, 16 - int depth = -1; - // the number of channels - int channels = -1; - - int scan_mode = -1; - - int color_filter = -1; - - int flags = -1; - - void assert_valid() const - { - if (xres < 0 || yres < 0 || startx < 0 || starty < 0 || pixels < 0 || lines < 0 || - depth < 0 || channels < 0 || scan_mode < 0 || color_filter < 0 || flags < 0) - { - throw std::runtime_error("ScanGenesysPhysicalParams are not valid"); - } - } -}; - struct ScanSession { - ScanSessionParams params; + SetupParams params; // whether the session setup has been computed via gl843_compute_session() bool computed = false; @@ -1469,16 +1438,8 @@ static SANE_Status gl843_init_scan_regs(Genesys_Device* dev, const Genesys_Senso SANE_Status status; - DBG(DBG_info, "%s:\n" - "Resolution : %gDPI/%gDPI\n" - "Lines : %g\n" - "PPL : %g\n" - "Startpos : %g/%g\n" - "Depth/Channels: %u/%u\n" - "Flags : %x\n\n", - __func__, session.params.xres, session.params.yres, session.params.lines, - session.params.pixels, session.params.startx, session.params.starty, - session.params.depth, session.params.channels, session.params.flags); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, session.params); DBG(DBG_info, "%s : stagger=%d lines\n", __func__, session.num_staggered_lines); @@ -1530,10 +1491,10 @@ static SANE_Status gl843_init_scan_regs(Genesys_Device* dev, const Genesys_Senso /*** optical parameters ***/ /* in case of dynamic lineart, we use an internal 8 bit gray scan * to generate 1 lineart data */ - if ((session.params.flags & SCAN_FLAG_DYNAMIC_LINEART) && (session.params.scan_mode == SCAN_MODE_LINEART)) - { - session.params.depth = 8; + if (session.params.flags & SCAN_FLAG_DYNAMIC_LINEART) { + session.params.depth = 8; } + /* no 16 bit gamma for this ASIC */ if (session.params.depth == 16) { @@ -1618,13 +1579,15 @@ static SANE_Status gl843_init_scan_regs(Genesys_Device* dev, const Genesys_Senso dev->shrink_buffer.alloc(requested_buffer_size); dev->out_buffer.clear(); - dev->out_buffer.alloc((8 * dev->settings.pixels * session.params.channels * session.params.depth) / 8); + dev->out_buffer.alloc((8 * session.params.pixels * session.params.channels * + session.params.depth) / 8); dev->read_bytes_left = session.output_line_bytes * session.output_line_count; DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left); dev->read_active = SANE_TRUE; + dev->current_setup.params = session.params; dev->current_setup.pixels = session.output_pixels; DBG(DBG_info, "%s: current_setup.pixels=%d\n", __func__, dev->current_setup.pixels); dev->current_setup.lines = session.output_line_count; @@ -1638,14 +1601,14 @@ static SANE_Status gl843_init_scan_regs(Genesys_Device* dev, const Genesys_Senso dev->current_setup.max_shift = session.max_color_shift_lines + session.num_staggered_lines; dev->total_bytes_read = 0; - if (session.params.depth == 1) - dev->total_bytes_to_read = - ((dev->settings.pixels * dev->settings.lines) / 8 + - (((dev->settings.pixels * dev->settings.lines) % 8) ? 1 : 0)) * - session.params.channels; - else - dev->total_bytes_to_read = - dev->settings.pixels * dev->settings.lines * session.params.channels * (session.params.depth / 8); + if (session.params.depth == 1) { + dev->total_bytes_to_read = ((session.params.pixels * session.params.lines) / 8 + + (((session.params.pixels * session.params.lines) % 8) ? 1 : 0)) * + session.params.channels; + } else { + dev->total_bytes_to_read = session.params.pixels * session.params.lines * + session.params.channels * (session.params.depth / 8); + } DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); @@ -1660,12 +1623,6 @@ gl843_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor int depth; int start; - float xres; /*dpi */ - float yres; /*dpi */ - float startx; /*optical_res, from dummy_pixel+1 */ - float pixels; - float lines; - int used_res; int used_pixels; unsigned int lincnt; @@ -1676,35 +1633,25 @@ gl843_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor int optical_res; - DBG(DBG_info, "%s settings:\n" - "Resolution: %ux%uDPI\n" - "Lines : %u\n" - "PPL : %u\n" - "Startpos : %.3f/%.3f\n" - "Scan mode : %d\n\n", __func__, - dev->settings.xres, - dev->settings.yres, dev->settings.lines, dev->settings.pixels, - dev->settings.tl_x, dev->settings.tl_y, dev->settings.scan_mode); - - xres = dev->settings.xres; - yres = dev->settings.yres; + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, dev->settings); /* we have 2 domains for ccd: xres below or above half ccd max dpi */ - unsigned ccd_size_divisor = sensor.get_ccd_size_divisor_for_dpi(xres); + unsigned ccd_size_divisor = sensor.get_ccd_size_divisor_for_dpi(dev->settings.xres); /* channels */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; else channels = 1; /* depth */ depth = dev->settings.depth; - if (dev->settings.scan_mode == SCAN_MODE_LINEART) + if (dev->settings.scan_mode == ScanColorMode::LINEART) depth = 1; /* start */ - if(dev->settings.scan_method==SCAN_METHOD_TRANSPARENCY) + if(dev->settings.scan_method==ScanMethod::TRANSPARENCY) start = SANE_UNFIX (dev->model->x_offset_ta); else start = SANE_UNFIX (dev->model->x_offset); @@ -1714,39 +1661,45 @@ gl843_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor start += dev->settings.tl_x; start = (start * sensor.optical_res) / MM_PER_INCH; - startx = start; - pixels = dev->settings.pixels; - lines = dev->settings.lines; + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = start; // not used + params.starty = 0; // not used + params.pixels = dev->settings.pixels; + params.lines = dev->settings.lines; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = 0; - DBG(DBG_info, "%s settings:\n" - "Resolution : %gDPI/%gDPI\n" - "Lines : %g\n" - "PPL : %g\n" - "Startpos : %g\n" - "Depth/Channels: %u/%u\n\n", - __func__, xres, yres, lines, pixels, startx, depth, channels); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, params); /* optical_res */ optical_res = sensor.optical_res / ccd_size_divisor; /* stagger */ if (ccd_size_divisor == 1 && (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE)) - stagger = (4 * yres) / dev->motor.base_ydpi; + stagger = (4 * params.yres) / dev->motor.base_ydpi; else stagger = 0; DBG(DBG_info, "%s: stagger=%d lines\n", __func__, stagger); - if(xres<=optical_res) - used_res = xres; - else - used_res=optical_res; + if (params.xres <= (unsigned) optical_res) { + used_res = params.xres; + } else { + used_res = optical_res; + } /* compute scan parameters values */ /* pixels are allways given at half or full CCD optical resolution */ /* use detected left margin and fixed value */ /* compute correct pixels number */ - used_pixels = (pixels * optical_res) / xres; + used_pixels = (params.pixels * optical_res) / params.xres; DBG(DBG_info, "%s: used_pixels=%d\n", __func__, used_pixels); /* exposure */ @@ -1757,7 +1710,7 @@ gl843_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor DBG(DBG_info, "%s : exposure=%d pixels\n", __func__, exposure); /* it seems base_dpi of the G4050 motor is changed above 600 dpi*/ - if (dev->model->motor_type == MOTOR_G4050 && yres>600) + if (dev->model->motor_type == MOTOR_G4050 && params.yres>600) { dev->ld_shift_r = (dev->model->ld_shift_r*3800)/dev->motor.base_ydpi; dev->ld_shift_g = (dev->model->ld_shift_g*3800)/dev->motor.base_ydpi; @@ -1771,19 +1724,20 @@ gl843_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor } /* scanned area must be enlarged by max color shift needed */ - max_shift=sanei_genesys_compute_max_shift(dev,channels,yres,0); + max_shift = sanei_genesys_compute_max_shift(dev, params.channels, params.yres, 0); /* lincnt */ - lincnt = lines + max_shift + stagger; + lincnt = params.lines + max_shift + stagger; + dev->current_setup.params = params; dev->current_setup.pixels = (used_pixels * used_res) / optical_res; DBG(DBG_info, "%s: current_setup.pixels=%d\n", __func__, dev->current_setup.pixels); dev->current_setup.lines = lincnt; - dev->current_setup.depth = depth; - dev->current_setup.channels = channels; + dev->current_setup.depth = params.depth; + dev->current_setup.channels = params.channels; dev->current_setup.exposure_time = exposure; dev->current_setup.xres = used_res; - dev->current_setup.yres = yres; + dev->current_setup.yres = params.yres; dev->current_setup.ccd_size_divisor = ccd_size_divisor; dev->current_setup.stagger = stagger; dev->current_setup.max_shift = max_shift + stagger; @@ -1792,54 +1746,6 @@ gl843_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor return SANE_STATUS_GOOD; } -static void -gl843_set_motor_power (Genesys_Register_Set * regs, SANE_Bool set) -{ - - DBG(DBG_proc, "%s\n", __func__); - - if (set) - { - sanei_genesys_set_reg_from_set (regs, REG02, - sanei_genesys_read_reg_from_set (regs, - REG02) - | REG02_MTRPWR); - } - else - { - sanei_genesys_set_reg_from_set (regs, REG02, - sanei_genesys_read_reg_from_set (regs, - REG02) - & ~REG02_MTRPWR); - } -} - -static void -gl843_set_lamp_power (Genesys_Device * dev, const Genesys_Sensor& sensor, - Genesys_Register_Set * regs, SANE_Bool set) -{ - uint8_t val; - - val = sanei_genesys_read_reg_from_set (regs, REG03); - if (set) - { - val |= REG03_LAMPPWR; - sanei_genesys_set_reg_from_set (regs, REG03, val); - - sanei_genesys_set_exposure(*regs, sensor.exposure); - } - else - { - val &= ~REG03_LAMPPWR; - sanei_genesys_set_reg_from_set (regs, REG03, val); - if (dev->model->model_id != MODEL_CANON_CANOSCAN_8600F) - { - // FIXME: datasheet says we shouldn't set exposure to zero - sanei_genesys_set_exposure(*regs, {0, 0, 0}); - } - } -} - /** * for fast power saving methods only, like disabling certain amplifiers * @param dev device to use @@ -2052,7 +1958,7 @@ gl843_detect_document_end (Genesys_Device * dev) { /* compute number of line read */ tmp = (int) dev->total_bytes_read; - if (depth == 1 || dev->settings.scan_mode == SCAN_MODE_LINEART) + if (depth == 1 || dev->settings.scan_mode == ScanColorMode::LINEART) flines = tmp * 8 / dev->settings.pixels / channels; else flines = tmp / (depth / 8) / dev->settings.pixels / channels; @@ -2087,7 +1993,7 @@ gl843_detect_document_end (Genesys_Device * dev) DBG(DBG_io, "%s: bytes_remain=%d\n", __func__, bytes_remain); /* remaining lines to read by frontend for the current scan */ - if (depth == 1 || dev->settings.scan_mode == SCAN_MODE_LINEART) + if (depth == 1 || dev->settings.scan_mode == ScanColorMode::LINEART) { flines = bytes_remain * 8 / dev->settings.pixels / channels; } @@ -2103,7 +2009,7 @@ gl843_detect_document_end (Genesys_Device * dev) * multiplied by bytes per line */ sublines = flines - lines; - if (depth == 1 || dev->settings.scan_mode == SCAN_MODE_LINEART) + if (depth == 1 || dev->settings.scan_mode == ScanColorMode::LINEART) sub_bytes = ((dev->settings.pixels * sublines) / 8 + (((dev->settings.pixels * sublines) % 8) ? 1 : 0)) * @@ -2142,50 +2048,8 @@ gl843_detect_document_end (Genesys_Device * dev) return SANE_STATUS_GOOD; } -/** @brief disable XPA slider motor - * toggle gpios to switch disble XPA slider motor - * @param dev device to set up - */ -static SANE_Status gl843_xpa_motor_off(Genesys_Device *dev) -{ - uint8_t val; - SANE_Status status=SANE_STATUS_GOOD; - - DBGSTART; - - if (dev->model->model_id == MODEL_CANON_CANOSCAN_8600F) { - RIE(sanei_genesys_read_register(dev, REG6C, &val)); - val |= REG6C_GPIO14; - val &= ~REG6C_GPIO10; - RIE(sanei_genesys_write_register(dev, REG6C, val)); - - RIE(sanei_genesys_read_register(dev, REGA6, &val)); - val &= ~REGA6_GPIO17; - RIE(sanei_genesys_write_register(dev, REGA6,val)); - } else { - /* unset GPOADF */ - RIE (sanei_genesys_read_register (dev, REG6B, &val)); - val &= ~REG6B_GPOADF; - RIE (sanei_genesys_write_register (dev, REG6B, val)); - - RIE (sanei_genesys_read_register (dev, REGA8, &val)); - val |= REGA8_GPO27; - RIE (sanei_genesys_write_register (dev, REGA8, val)); - - RIE (sanei_genesys_read_register (dev, REGA9, &val)); - val &= ~REGA9_GPO31; - RIE (sanei_genesys_write_register (dev, REGA9, val)); - } - DBGCOMPLETED; - return status; -} - - -/** @brief enable XPA slider motor - * toggle gpios to switch enable XPA slider motor - * @param dev device to set up - */ -static SANE_Status gl843_xpa_motor_on(Genesys_Device *dev) +// enables or disables XPA slider motor +static SANE_Status gl843_set_xpa_motor_power(Genesys_Device *dev, bool set) { uint8_t val; SANE_Status status=SANE_STATUS_GOOD; @@ -2193,38 +2057,72 @@ static SANE_Status gl843_xpa_motor_on(Genesys_Device *dev) DBGSTART; if (dev->model->model_id == MODEL_CANON_CANOSCAN_8600F) { - RIE(sanei_genesys_read_register(dev, REG6C, &val)); - val &= ~REG6C_GPIO14; - if (dev->current_setup.xres >= 2400) { - val |= REG6C_GPIO10; + + if (set) { + RIE(sanei_genesys_read_register(dev, REG6C, &val)); + val &= ~REG6C_GPIO14; + if (dev->current_setup.xres >= 2400) { + val |= REG6C_GPIO10; + } + RIE(sanei_genesys_write_register(dev, REG6C, val)); + + RIE(sanei_genesys_read_register(dev, REGA6, &val)); + val |= REGA6_GPIO17; + RIE(sanei_genesys_write_register(dev, REGA6,val)); + } else { + RIE(sanei_genesys_read_register(dev, REG6C, &val)); + val |= REG6C_GPIO14; + val &= ~REG6C_GPIO10; + RIE(sanei_genesys_write_register(dev, REG6C, val)); + + RIE(sanei_genesys_read_register(dev, REGA6, &val)); + val &= ~REGA6_GPIO17; + RIE(sanei_genesys_write_register(dev, REGA6,val)); } - RIE(sanei_genesys_write_register(dev, REG6C, val)); + DBGCOMPLETED; + return status; + } - RIE(sanei_genesys_read_register(dev, REGA6, &val)); - val |= REGA6_GPIO17; - RIE(sanei_genesys_write_register(dev, REGA6,val)); - } else { - /* set MULTFILM et GPOADF */ - RIE (sanei_genesys_read_register (dev, REG6B, &val)); - val |=REG6B_MULTFILM|REG6B_GPOADF; - RIE (sanei_genesys_write_register (dev, REG6B, val)); + if (dev->model->model_id == MODEL_HP_SCANJET_G4050) { - RIE (sanei_genesys_read_register (dev, REG6C, &val)); - val &= ~REG6C_GPIO15; - RIE (sanei_genesys_write_register (dev, REG6C, val)); + if (set) { + /* set MULTFILM et GPOADF */ + RIE (sanei_genesys_read_register (dev, REG6B, &val)); + val |=REG6B_MULTFILM|REG6B_GPOADF; + RIE (sanei_genesys_write_register (dev, REG6B, val)); - /* Motor power ? No move at all without this one */ - RIE (sanei_genesys_read_register (dev, REGA6, &val)); - val |= REGA6_GPIO20; - RIE (sanei_genesys_write_register(dev,REGA6,val)); + RIE (sanei_genesys_read_register (dev, REG6C, &val)); + val &= ~REG6C_GPIO15; + RIE (sanei_genesys_write_register (dev, REG6C, val)); - RIE (sanei_genesys_read_register (dev, REGA8, &val)); - val &= ~REGA8_GPO27; - RIE (sanei_genesys_write_register (dev, REGA8, val)); + /* Motor power ? No move at all without this one */ + RIE (sanei_genesys_read_register (dev, REGA6, &val)); + val |= REGA6_GPIO20; + RIE (sanei_genesys_write_register(dev,REGA6,val)); - RIE (sanei_genesys_read_register (dev, REGA9, &val)); - val |= REGA9_GPO32|REGA9_GPO31; - RIE (sanei_genesys_write_register (dev, REGA9, val)); + RIE (sanei_genesys_read_register (dev, REGA8, &val)); + val &= ~REGA8_GPO27; + RIE (sanei_genesys_write_register (dev, REGA8, val)); + + RIE (sanei_genesys_read_register (dev, REGA9, &val)); + val |= REGA9_GPO32|REGA9_GPO31; + RIE (sanei_genesys_write_register (dev, REGA9, val)); + } else { + /* unset GPOADF */ + RIE (sanei_genesys_read_register (dev, REG6B, &val)); + val &= ~REG6B_GPOADF; + RIE (sanei_genesys_write_register (dev, REG6B, val)); + + RIE (sanei_genesys_read_register (dev, REGA8, &val)); + val |= REGA8_GPO27; + RIE (sanei_genesys_write_register (dev, REGA8, val)); + + RIE (sanei_genesys_read_register (dev, REGA9, &val)); + val &= ~REGA9_GPO31; + RIE (sanei_genesys_write_register (dev, REGA9, val)); + } + DBGCOMPLETED; + return status; } DBGCOMPLETED; @@ -2237,32 +2135,42 @@ static SANE_Status gl843_xpa_motor_on(Genesys_Device *dev) * XPA light * @param dev device to set up */ -static SANE_Status gl843_xpa_lamp_on(Genesys_Device *dev) +static SANE_Status gl843_set_xpa_lamp_power(Genesys_Device *dev, bool set) { - uint8_t val; - SANE_Status status=SANE_STATUS_GOOD; + SANE_Status status = SANE_STATUS_GOOD; + uint8_t val = 0; + DBGSTART; - DBGSTART; + if (set) { + RIE(sanei_genesys_read_register(dev, REGA6, &val)); - /* REGA6 */ - RIE(sanei_genesys_read_register(dev, REGA6, &val)); + // cut regular lamp power + val &= ~(REGA6_GPIO24 | REGA6_GPIO23); - /* cut regular lamp power */ - val &= ~(REGA6_GPIO24|REGA6_GPIO23); + // set XPA lamp power + val |= REGA6_GPIO22 | REGA6_GPIO21 | REGA6_GPIO19; - /* set XPA lamp power */ - val |= REGA6_GPIO22 | REGA6_GPIO21 | REGA6_GPIO19; + RIE(sanei_genesys_write_register(dev, REGA6, val)); - RIE(sanei_genesys_write_register(dev, REGA6, val)); + RIE(sanei_genesys_read_register(dev, REGA7, &val)); + val|=REGA7_GPOE24; /* lamp 1 off GPOE 24 */ + val|=REGA7_GPOE23; /* lamp 2 off GPOE 23 */ + val|=REGA7_GPOE22; /* full XPA lamp power */ + RIE(sanei_genesys_write_register(dev, REGA7, val)); + } else { + RIE(sanei_genesys_read_register(dev, REGA6, &val)); - RIE(sanei_genesys_read_register(dev, REGA7, &val)); - val|=REGA7_GPOE24; /* lamp 1 off GPOE 24 */ - val|=REGA7_GPOE23; /* lamp 2 off GPOE 23 */ - val|=REGA7_GPOE22; /* full XPA lamp power */ - RIE(sanei_genesys_write_register(dev, REGA7, val)); + // switch on regular lamp + val |= REGA6_GPIO23; - DBGCOMPLETED; - return status; + // no XPA lamp power (2 bits for level: __11 ____) + val &= ~(REGA6_GPIO22 | REGA6_GPIO21); + + RIE(sanei_genesys_write_register(dev, REGA6, val)); + } + + DBGCOMPLETED; + return status; } /* Send the low-level scan command */ @@ -2271,7 +2179,7 @@ gl843_begin_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Re SANE_Bool start_motor) { SANE_Status status; - uint8_t val,r03; + uint8_t val; uint16_t dpiset, dpihw; DBGSTART; @@ -2307,31 +2215,23 @@ gl843_begin_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Re RIE (sanei_genesys_write_register (dev, REGA6, 0x44)); } - /* turn on XPA lamp if XPA is selected and lamp power on*/ - r03 = sanei_genesys_read_reg_from_set (reg, REG03); - if ((r03 & REG03_XPASEL) && (r03 & REG03_LAMPPWR)) - { - RIE(gl843_xpa_lamp_on(dev)); - } + if (reg->state.is_xpa_on && reg->state.is_lamp_on) { + RIE(gl843_set_xpa_lamp_power(dev, true)); + } - /* enable XPA lamp motor */ - if (r03 & REG03_XPASEL) - { - dev->needs_home_ta = SANE_TRUE; - RIE(gl843_xpa_motor_on(dev)); - } + if (reg->state.is_xpa_on) { + dev->needs_home_ta = SANE_TRUE; + RIE(gl843_set_xpa_motor_power(dev, true)); + } /* blinking led */ RIE (sanei_genesys_write_register (dev, REG7E, 0x01)); break; case GPO_CS8600F: - r03 = sanei_genesys_read_reg_from_set (reg, REG03); - /* enable XPA lamp motor */ - if (r03 & REG03_XPASEL) - { - dev->needs_home_ta = SANE_TRUE; - RIE(gl843_xpa_motor_on(dev)); - } + if (reg->state.is_xpa_on) { + dev->needs_home_ta = SANE_TRUE; + RIE(gl843_set_xpa_motor_power(dev, true)); + } break; case GPO_CS4400F: case GPO_CS8400F: @@ -2368,7 +2268,6 @@ gl843_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg, SANE_Bool check_stop) { SANE_Status status; - uint8_t val; DBG(DBG_proc, "%s (check_stop = %d)\n", __func__, check_stop); if (reg == NULL) @@ -2377,19 +2276,10 @@ gl843_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg, /* post scan gpio */ RIE(sanei_genesys_write_register(dev,0x7e,0x00)); - /* turn off XPA lamp if XPA is selected and lamp power on*/ - val = sanei_genesys_read_reg_from_set (reg, REG03); - if (val & (REG03_XPASEL|REG03_LAMPPWR)) - { - sanei_genesys_read_register (dev, REGA6, &val); - - /* switch on regular lamp */ - val |= 0x40; - - /* no XPA lamp power (2 bits for level: __11 ____) */ - val &= ~0x30; - - RIE (sanei_genesys_write_register (dev, REGA6, val)); + // turn off XPA lamp if needed + // BUG: the if condition below probably shouldn't be enabled when XPA is off + if (reg->state.is_xpa_on || reg->state.is_lamp_on) { + gl843_set_xpa_lamp_power(dev, false); } if (dev->model->is_sheetfed == SANE_TRUE) @@ -2440,7 +2330,7 @@ static SANE_Status gl843_park_xpa_lamp (Genesys_Device * dev) /* write to scanner and start action */ RIE (dev->model->cmd_set->bulk_write_register(dev, local_reg)); - RIE (gl843_xpa_motor_on(dev)); + RIE(gl843_set_xpa_motor_power(dev, true)); status = gl843_start_action (dev); if (status != SANE_STATUS_GOOD) { @@ -2470,8 +2360,8 @@ static SANE_Status gl843_park_xpa_lamp (Genesys_Device * dev) DBG(DBG_info, "%s: reached home position\n", __func__); DBG(DBG_proc, "%s: finished\n", __func__); - gl843_xpa_motor_off(dev); - dev->needs_home_ta = SANE_FALSE; + gl843_set_xpa_motor_power(dev, false); + dev->needs_home_ta = SANE_FALSE; return SANE_STATUS_GOOD; } @@ -2546,7 +2436,8 @@ gl843_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) session.params.lines = 100; session.params.depth = 8; session.params.channels = 1; - session.params.scan_mode = SCAN_MODE_LINEART; + session.params.scan_method = dev->settings.scan_method; + session.params.scan_mode = ScanColorMode::LINEART; session.params.color_filter = dev->settings.color_filter; session.params.flags = SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | @@ -2655,8 +2546,9 @@ gl843_search_start_position (Genesys_Device * dev) session.params.lines = dev->model->search_lines; session.params.depth = 8; session.params.channels = 1; - session.params.scan_mode = SCAN_MODE_GRAY; - session.params.color_filter = 1; // green + session.params.scan_method = dev->settings.scan_method; + session.params.scan_mode = ScanColorMode::GRAY; + session.params.color_filter = ColorFilter::GREEN; session.params.flags = SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | SCAN_FLAG_IGNORE_LINE_DISTANCE | @@ -2734,17 +2626,18 @@ gl843_search_start_position (Genesys_Device * dev) * sets up register for coarse gain calibration * todo: check it for scanners using it */ static SANE_Status -gl843_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl843_init_regs_for_coarse_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status; uint8_t channels; uint8_t cksel; DBGSTART; - cksel = (dev->calib_reg.find_reg(0x18).value & REG18_CKSEL) + 1; /* clock speed = 1..4 clocks */ + cksel = (regs.find_reg(0x18).value & REG18_CKSEL) + 1; /* clock speed = 1..4 clocks */ /* set line size */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; else channels = 1; @@ -2754,7 +2647,7 @@ gl843_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sens SCAN_FLAG_SINGLE_LINE | SCAN_FLAG_IGNORE_LINE_DISTANCE; - if (dev->settings.scan_method == SCAN_METHOD_TRANSPARENCY) { + if (dev->settings.scan_method == ScanMethod::TRANSPARENCY) { flags |= SCAN_FLAG_USE_XPA; } @@ -2767,24 +2660,25 @@ gl843_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sens session.params.lines = 20; session.params.depth = 16; session.params.channels = channels; + session.params.scan_method = dev->settings.scan_method; session.params.scan_mode = dev->settings.scan_mode; session.params.color_filter = dev->settings.color_filter; session.params.flags = flags; gl843_compute_session(dev, session, sensor); - status = gl843_init_scan_regs(dev, sensor, &dev->calib_reg, session); + status = gl843_init_scan_regs(dev, sensor, ®s, session); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus(status)); return status; } - gl843_set_motor_power (&dev->calib_reg, SANE_FALSE); + sanei_genesys_set_motor_power(regs, false); DBG(DBG_info, "%s: optical sensor res: %d dpi, actual res: %d\n", __func__, sensor.optical_res / cksel, dev->settings.xres); - status = dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg); + status = dev->model->cmd_set->bulk_write_register(dev, regs); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to bulk write registers: %s\n", __func__, sane_strstatus(status)); @@ -2826,8 +2720,9 @@ gl843_feed (Genesys_Device * dev, unsigned int steps) session.params.lines = 3; session.params.depth = 8; session.params.channels = 3; - session.params.scan_mode = SCAN_MODE_COLOR; - session.params.color_filter = 0; + session.params.scan_method = dev->settings.scan_method; + session.params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + session.params.color_filter = ColorFilter::RED; session.params.flags = SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | SCAN_FLAG_FEEDING | @@ -2884,7 +2779,8 @@ static SANE_Status gl843_move_to_ta (Genesys_Device * dev); /* init registers for shading calibration */ /* shading calibration is done at dpihw */ static SANE_Status -gl843_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl843_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status; int move, resolution, dpihw, factor; @@ -2893,10 +2789,10 @@ gl843_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) DBGSTART; /* initial calibration reg values */ - dev->calib_reg = dev->reg; + regs = dev->reg; dev->calib_channels = 3; - if (dev->settings.scan_method == SCAN_METHOD_TRANSPARENCY) + if (dev->settings.scan_method == ScanMethod::TRANSPARENCY) dev->calib_lines = dev->model->shading_ta_lines; else dev->calib_lines = dev->model->shading_lines; @@ -2907,7 +2803,7 @@ gl843_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) const auto& calib_sensor = sanei_genesys_find_sensor(dev, resolution, dev->settings.scan_method); - if (dev->settings.scan_method == SCAN_METHOD_TRANSPARENCY && + if (dev->settings.scan_method == ScanMethod::TRANSPARENCY && dev->model->model_id == MODEL_CANON_CANOSCAN_8600F && dev->settings.xres == 4800) { @@ -2935,7 +2831,7 @@ gl843_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE | SCAN_FLAG_IGNORE_LINE_DISTANCE; - if (dev->settings.scan_method == SCAN_METHOD_TRANSPARENCY) + if (dev->settings.scan_method == ScanMethod::TRANSPARENCY) { // FIXME: we should handle moving to TA in the caller, this function should only setup the // registers. @@ -2957,12 +2853,13 @@ gl843_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) session.params.lines = dev->calib_lines; session.params.depth = 16; session.params.channels = dev->calib_channels; + session.params.scan_method = dev->settings.scan_method; session.params.scan_mode = dev->settings.scan_mode; session.params.color_filter = dev->settings.color_filter; session.params.flags = flags; gl843_compute_session(dev, session, calib_sensor); - status = gl843_init_scan_regs(dev, calib_sensor, &dev->calib_reg, session); + status = gl843_init_scan_regs(dev, calib_sensor, ®s, session); // the pixel number may be updated to conform to scanner constraints dev->calib_pixels = dev->current_setup.pixels; @@ -2976,10 +2873,10 @@ gl843_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) dev->calib_total_bytes_to_read = dev->read_bytes_left; dev->scanhead_position_in_steps += dev->calib_lines + move; - sanei_genesys_get_double(&dev->calib_reg,REG_STRPIXEL,&strpixel); + sanei_genesys_get_double(®s,REG_STRPIXEL,&strpixel); DBG(DBG_info, "%s: STRPIXEL=%d\n", __func__, strpixel); - status = dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg); + status = dev->model->cmd_set->bulk_write_register(dev, regs); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to bulk write registers: %s\n", __func__, sane_strstatus(status)); @@ -3004,34 +2901,27 @@ gl843_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) SANE_Status status; - DBG(DBG_info, "%s settings:\nResolution: %ux%uDPI\n" - "Lines : %u\npixels : %u\nStartpos : %.3f/%.3f\nScan mode : %d\n\n", __func__, - dev->settings.xres, - dev->settings.yres, - dev->settings.lines, - dev->settings.pixels, - dev->settings.tl_x, - dev->settings.tl_y, - dev->settings.scan_mode); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, dev->settings); /* ensure head is parked in case of calibration */ gl843_slow_back_home (dev, SANE_TRUE); /* channels */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; else channels = 1; /* depth */ depth = dev->settings.depth; - if (dev->settings.scan_mode == SCAN_MODE_LINEART) + if (dev->settings.scan_mode == ScanColorMode::LINEART) depth = 1; move_dpi = dev->motor.base_ydpi; flags = 0; - if (dev->settings.scan_method == SCAN_METHOD_TRANSPARENCY) + if (dev->settings.scan_method == ScanMethod::TRANSPARENCY) { // FIXME: we should handle moving to TA in the caller, this function should only setup the // registers. @@ -3047,7 +2937,7 @@ gl843_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) DBG(DBG_info, "%s: move=%f steps\n", __func__, move); /* start */ - if(dev->settings.scan_method==SCAN_METHOD_TRANSPARENCY) + if(dev->settings.scan_method==ScanMethod::TRANSPARENCY) start = SANE_UNFIX (dev->model->x_offset_ta); else start = SANE_UNFIX (dev->model->x_offset); @@ -3057,7 +2947,7 @@ gl843_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) start = (start * sensor.optical_res) / MM_PER_INCH; /* enable emulated lineart from gray data */ - if(dev->settings.scan_mode == SCAN_MODE_LINEART + if(dev->settings.scan_mode == ScanColorMode::LINEART && dev->settings.dynamic_lineart) { flags |= SCAN_FLAG_DYNAMIC_LINEART; @@ -3072,6 +2962,7 @@ gl843_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) session.params.lines = dev->settings.lines; session.params.depth = depth; session.params.channels = channels; + session.params.scan_method = dev->settings.scan_method; session.params.scan_mode = dev->settings.scan_mode; session.params.color_filter = dev->settings.color_filter; session.params.flags = flags; @@ -3143,7 +3034,7 @@ gl843_send_gamma_table(Genesys_Device* dev, const Genesys_Sensor& sensor) -needs working coarse/gain */ static SANE_Status -gl843_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) +gl843_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor, Genesys_Register_Set& regs) { int num_pixels; int total_size; @@ -3171,7 +3062,7 @@ gl843_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) (calib_sensor.sensor_pixels * used_res) / calib_sensor.optical_res; /* initial calibration reg values */ - dev->calib_reg = dev->reg; + regs = dev->reg; ScanSession session; session.params.xres = used_res; @@ -3182,7 +3073,8 @@ gl843_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) session.params.lines = 1; session.params.depth = depth; session.params.channels = channels; - session.params.scan_mode = SCAN_MODE_COLOR; + session.params.scan_method = dev->settings.scan_method; + session.params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; session.params.color_filter = dev->settings.color_filter; session.params.flags = SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | @@ -3190,7 +3082,7 @@ gl843_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) SCAN_FLAG_IGNORE_LINE_DISTANCE; gl843_compute_session(dev, session, calib_sensor); - status = gl843_init_scan_regs(dev, calib_sensor, &dev->calib_reg, session); + status = gl843_init_scan_regs(dev, calib_sensor, ®s, session); if (status != SANE_STATUS_GOOD) { @@ -3198,7 +3090,7 @@ gl843_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) return status; } - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); total_size = dev->read_bytes_left; @@ -3225,14 +3117,14 @@ gl843_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) calib_sensor.exposure.green = expg; calib_sensor.exposure.blue = expb; - sanei_genesys_set_exposure(dev->calib_reg, calib_sensor.exposure); + sanei_genesys_set_exposure(regs, calib_sensor.exposure); - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting first line reading\n", __func__); - RIE (gl843_begin_scan(dev, calib_sensor, &dev->calib_reg, SANE_TRUE)); + RIE (gl843_begin_scan(dev, calib_sensor, ®s, SANE_TRUE)); RIE (sanei_genesys_read_data_from_scanner(dev, line.data(), total_size)); - RIE(gl843_stop_action_no_move(dev, &dev->calib_reg)); + RIE(gl843_stop_action_no_move(dev, ®s)); if (DBG_LEVEL >= DBG_data) { @@ -3362,7 +3254,8 @@ dark_average_channel (uint8_t * data, unsigned int pixels, unsigned int lines, * @param dev device to calibrate */ static SANE_Status -gl843_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) +gl843_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status = SANE_STATUS_GOOD; unsigned int channels, bpp; @@ -3389,7 +3282,7 @@ gl843_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) int start_pixel = 0; black_pixels = calib_sensor.black_pixels / factor; - if (dev->settings.scan_method == SCAN_METHOD_TRANSPARENCY && + if (dev->settings.scan_method == ScanMethod::TRANSPARENCY && dev->model->model_id == MODEL_CANON_CANOSCAN_8600F && dev->settings.xres == 4800) { @@ -3407,7 +3300,7 @@ gl843_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) SCAN_FLAG_SINGLE_LINE | SCAN_FLAG_IGNORE_LINE_DISTANCE; - if (dev->settings.scan_method == SCAN_METHOD_TRANSPARENCY) + if (dev->settings.scan_method == ScanMethod::TRANSPARENCY) { flags |= SCAN_FLAG_USE_XPA; } @@ -3421,8 +3314,9 @@ gl843_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) session.params.lines = lines; session.params.depth = bpp; session.params.channels = channels; - session.params.scan_mode = SCAN_MODE_COLOR; - session.params.color_filter = 0; + session.params.scan_method = dev->settings.scan_method; + session.params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + session.params.color_filter = ColorFilter::RED; session.params.flags = flags; gl843_compute_session(dev, session, calib_sensor); pixels = session.output_pixels; @@ -3432,13 +3326,13 @@ gl843_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) DBG(DBG_io, "%s: resolution =%d\n", __func__, resolution); DBG(DBG_io, "%s: pixels =%d\n", __func__, pixels); DBG(DBG_io, "%s: black_pixels=%d\n", __func__, black_pixels); - status = gl843_init_scan_regs(dev, calib_sensor, &dev->calib_reg, session); + status = gl843_init_scan_regs(dev, calib_sensor, ®s, session); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus(status)); return status; } - gl843_set_motor_power(&dev->calib_reg, SANE_FALSE); + sanei_genesys_set_motor_power(regs, false); /* allocate memory for scans */ total_size = dev->read_bytes_left; @@ -3456,11 +3350,11 @@ gl843_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) RIE(gl843_set_fe(dev, calib_sensor, AFE_SET)); /* scan with obttom AFE settings */ - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting first line reading\n", __func__); - RIE(gl843_begin_scan(dev, calib_sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl843_begin_scan(dev, calib_sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, first_line.data(), total_size)); - RIE(gl843_stop_action_no_move(dev, &dev->calib_reg)); + RIE(gl843_stop_action_no_move(dev, ®s)); if (DBG_LEVEL >= DBG_data) { @@ -3485,11 +3379,11 @@ gl843_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) RIE(gl843_set_fe(dev, calib_sensor, AFE_SET)); /* scan with top AFE values */ - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting second line reading\n", __func__); - RIE(gl843_begin_scan(dev, calib_sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl843_begin_scan(dev, calib_sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, second_line.data(), total_size)); - RIE(gl843_stop_action_no_move(dev, &dev->calib_reg)); + RIE(gl843_stop_action_no_move(dev, ®s)); for (i = 0; i < 3; i++) { @@ -3521,11 +3415,11 @@ gl843_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) RIE(gl843_set_fe(dev, calib_sensor, AFE_SET)); /* scan with no move */ - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting second line reading\n", __func__); - RIE(gl843_begin_scan(dev, calib_sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl843_begin_scan(dev, calib_sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, second_line.data(), total_size)); - RIE(gl843_stop_action_no_move(dev, &dev->calib_reg)); + RIE(gl843_stop_action_no_move(dev, ®s)); if (DBG_LEVEL >= DBG_data) { @@ -3591,7 +3485,8 @@ gl843_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) be done with shading. */ static SANE_Status -gl843_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor, int dpi) +gl843_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs, int dpi) { int pixels, factor, dpihw; int total_size; @@ -3636,7 +3531,7 @@ gl843_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso SCAN_FLAG_SINGLE_LINE | SCAN_FLAG_IGNORE_LINE_DISTANCE; - if (dev->settings.scan_method == SCAN_METHOD_TRANSPARENCY) + if (dev->settings.scan_method == ScanMethod::TRANSPARENCY) { flags |= SCAN_FLAG_USE_XPA; } @@ -3653,14 +3548,15 @@ gl843_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso session.params.lines = lines; session.params.depth = bpp; session.params.channels = channels; - session.params.scan_mode = SCAN_MODE_COLOR; + session.params.scan_method = dev->settings.scan_method; + session.params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; session.params.color_filter = dev->settings.color_filter; session.params.flags = flags; gl843_compute_session(dev, session, calib_sensor); pixels = session.output_pixels; - status = gl843_init_scan_regs(dev, calib_sensor, &dev->calib_reg, session); - gl843_set_motor_power(&dev->calib_reg, SANE_FALSE); + status = gl843_init_scan_regs(dev, calib_sensor, ®s, session); + sanei_genesys_set_motor_power(regs, false); if (status != SANE_STATUS_GOOD) { @@ -3668,16 +3564,16 @@ gl843_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso return status; } - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); total_size = dev->read_bytes_left; std::vector line(total_size); RIE(gl843_set_fe(dev, calib_sensor, AFE_SET)); - RIE(gl843_begin_scan(dev, calib_sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl843_begin_scan(dev, calib_sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner (dev, line.data(), total_size)); - RIE(gl843_stop_action_no_move(dev, &dev->calib_reg)); + RIE(gl843_stop_action_no_move(dev, ®s)); if (DBG_LEVEL >= DBG_data) sanei_genesys_write_pnm_file("gl843_coarse.pnm", line.data(), bpp, channels, pixels, lines); @@ -3813,7 +3709,8 @@ gl843_init_regs_for_warmup (Genesys_Device * dev, session.params.lines = 1; session.params.depth = 8; session.params.channels = *channels; - session.params.scan_mode = SCAN_MODE_COLOR; + session.params.scan_method = dev->settings.scan_method; + session.params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; session.params.color_filter = dev->settings.color_filter; session.params.flags = SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_GAMMA | @@ -3829,7 +3726,7 @@ gl843_init_regs_for_warmup (Genesys_Device * dev, return status; } - gl843_set_motor_power (reg, SANE_FALSE); + sanei_genesys_set_motor_power(*reg, false); RIE(dev->model->cmd_set->bulk_write_register(dev, *reg)); DBGCOMPLETED; @@ -4011,24 +3908,19 @@ gl843_update_hardware_sensors (Genesys_Scanner * s) switch (s->dev->model->gpo_type) { - case GPO_KVSS080: - if (s->val[OPT_SCAN_SW].b == s->last_val[OPT_SCAN_SW].b) - s->val[OPT_SCAN_SW].b = (val & 0x04) == 0; - break; - case GPO_G4050: - if (s->val[OPT_SCAN_SW].b == s->last_val[OPT_SCAN_SW].b) - s->val[OPT_SCAN_SW].b = (val & 0x01) == 0; - if (s->val[OPT_FILE_SW].b == s->last_val[OPT_FILE_SW].b) - s->val[OPT_FILE_SW].b = (val & 0x02) == 0; - if (s->val[OPT_EMAIL_SW].b == s->last_val[OPT_EMAIL_SW].b) - s->val[OPT_EMAIL_SW].b = (val & 0x04) == 0; - if (s->val[OPT_COPY_SW].b == s->last_val[OPT_COPY_SW].b) - s->val[OPT_COPY_SW].b = (val & 0x08) == 0; - break; - case GPO_CS4400F: - case GPO_CS8400F: - default: - break; + case GPO_KVSS080: + s->buttons[BUTTON_SCAN_SW].write((val & 0x04) == 0); + break; + case GPO_G4050: + s->buttons[BUTTON_SCAN_SW].write((val & 0x01) == 0); + s->buttons[BUTTON_FILE_SW].write((val & 0x02) == 0); + s->buttons[BUTTON_EMAIL_SW].write((val & 0x04) == 0); + s->buttons[BUTTON_COPY_SW].write((val & 0x08) == 0); + break; + case GPO_CS4400F: + case GPO_CS8400F: + default: + break; } return status; @@ -4118,8 +4010,9 @@ gl843_search_strip (Genesys_Device * dev, const Genesys_Sensor& sensor, session.params.lines = lines; session.params.depth = depth; session.params.channels = channels; - session.params.scan_mode = SCAN_MODE_GRAY; - session.params.color_filter = 0; + session.params.scan_method = dev->settings.scan_method; + session.params.scan_mode = ScanColorMode::GRAY; + session.params.color_filter = ColorFilter::RED; session.params.flags = SCAN_FLAG_DISABLE_SHADING | SCAN_FLAG_DISABLE_SHADING; gl843_compute_session(dev, session, calib_sensor); @@ -4449,9 +4342,6 @@ static Genesys_Command_Set gl843_cmd_set = { gl843_set_powersaving, gl843_save_power, - gl843_set_motor_power, - gl843_set_lamp_power, - gl843_begin_scan, gl843_end_scan, @@ -4481,8 +4371,7 @@ static Genesys_Command_Set gl843_cmd_set = { gl843_move_to_ta, gl843_send_shading_data, gl843_calculate_current_setup, - gl843_boot, - NULL + gl843_boot }; SANE_Status diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index 4c55a8730..750d0bfc3 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -428,7 +428,7 @@ gl846_init_registers (Genesys_Device * dev) */ static SANE_Status gl846_send_slope_table (Genesys_Device * dev, int table_nr, - uint16_t * slope_table, int steps) + uint16_t * slope_table, int steps) { SANE_Status status; int i; @@ -455,9 +455,9 @@ gl846_send_slope_table (Genesys_Device * dev, int table_nr, { sprintf (msg, "write slope %d (%d)=", table_nr, steps); for (i = 0; i < steps; i++) - { - sprintf (msg+strlen(msg), "%d", slope_table[i]); - } + { + sprintf (msg+strlen(msg), "%d", slope_table[i]); + } DBG (DBG_io, "%s: %s\n", __func__, msg); } @@ -504,14 +504,14 @@ gl846_set_adi_fe (Genesys_Device * dev, uint8_t set) if (status != SANE_STATUS_GOOD) { DBG (DBG_error, "%s: failed to write reg0: %s\n", __func__, - sane_strstatus (status)); + sane_strstatus (status)); return status; } status = sanei_genesys_fe_write_data(dev, 0x01, dev->frontend.regs.get_value(0x01)); if (status != SANE_STATUS_GOOD) { DBG (DBG_error, "%s: failed to write reg1: %s\n", __func__, - sane_strstatus (status)); + sane_strstatus (status)); return status; } @@ -519,23 +519,23 @@ gl846_set_adi_fe (Genesys_Device * dev, uint8_t set) { status = sanei_genesys_fe_write_data(dev, 0x02 + i, dev->frontend.get_gain(i)); if (status != SANE_STATUS_GOOD) - { - DBG (DBG_error, - "%s: failed to write gain %d: %s\n", __func__, i, - sane_strstatus (status)); - return status; - } + { + DBG (DBG_error, + "%s: failed to write gain %d: %s\n", __func__, i, + sane_strstatus (status)); + return status; + } } for (i = 0; i < 3; i++) { status = sanei_genesys_fe_write_data(dev, 0x05 + i, dev->frontend.get_offset(i)); if (status != SANE_STATUS_GOOD) - { - DBG (DBG_error, - "%s: failed to write offset %d: %s\n", __func__, i, - sane_strstatus (status)); - return status; - } + { + DBG (DBG_error, + "%s: failed to write offset %d: %s\n", __func__, i, + sane_strstatus (status)); + return status; + } } DBGCOMPLETED; @@ -589,12 +589,12 @@ gl846_init_motor_regs_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Register_Set * reg, unsigned int scan_exposure_time, - float scan_yres, - int scan_step_type, - unsigned int scan_lines, - unsigned int scan_dummy, - unsigned int feed_steps, - int scan_power_mode, + float scan_yres, + int scan_step_type, + unsigned int scan_lines, + unsigned int scan_dummy, + unsigned int feed_steps, + int scan_power_mode, unsigned int flags) { SANE_Status status; @@ -634,7 +634,7 @@ gl846_init_motor_regs_scan (Genesys_Device * dev, /* compute register 02 value */ r = sanei_genesys_get_address (reg, REG02); r->value = 0x00; - r->value |= REG02_MTRPWR; + sanei_genesys_set_motor_power(*reg, true); if (use_fast_fed) r->value |= REG02_FASTFED; @@ -780,10 +780,10 @@ gl846_init_motor_regs_scan (Genesys_Device * dev, r->value = min_restep; sanei_genesys_calculate_zmode2(use_fast_fed, - scan_exposure_time*ccdlmt*tgtime, - scan_table, - scan_steps*factor, - feedl, + scan_exposure_time*ccdlmt*tgtime, + scan_table, + scan_steps*factor, + feedl, min_restep*factor, &z1, &z2); @@ -845,14 +845,14 @@ gl846_init_motor_regs_scan (Genesys_Device * dev, static SANE_Status gl846_init_optical_regs_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, - Genesys_Register_Set * reg, - unsigned int exposure_time, - int used_res, - unsigned int start, - unsigned int pixels, - int channels, - int depth, - SANE_Bool half_ccd, int color_filter, int flags) + Genesys_Register_Set * reg, + unsigned int exposure_time, + int used_res, + unsigned int start, + unsigned int pixels, + int channels, + int depth, + SANE_Bool half_ccd, ColorFilter color_filter, int flags) { unsigned int words_per_line; unsigned int startx, endx, used_pixels; @@ -942,10 +942,7 @@ gl846_init_optical_regs_scan (Genesys_Device * dev, r = sanei_genesys_get_address (reg, REG03); r->value &= ~REG03_AVEENB; - if (flags & OPTICAL_FLAG_DISABLE_LAMP) - r->value &= ~REG03_LAMPPWR; - else - r->value |= REG03_LAMPPWR; + sanei_genesys_set_lamp_power(dev, sensor, *reg, !(flags & OPTICAL_FLAG_DISABLE_LAMP)); /* BW threshold */ r = sanei_genesys_get_address (reg, 0x2e); @@ -974,17 +971,19 @@ gl846_init_optical_regs_scan (Genesys_Device * dev, if (channels == 1) { switch (color_filter) - { - case 0: - r->value |= 0x24; /* red filter */ - break; - case 2: - r->value |= 0x2c; /* blue filter */ - break; - default: - r->value |= 0x28; /* green filter */ - break; - } + { + case ColorFilter::RED: + r->value |= 0x24; + break; + case ColorFilter::BLUE: + r->value |= 0x2c; + break; + case ColorFilter::GREEN: + r->value |= 0x28; + break; + default: + break; // should not happen + } } else r->value |= 0x20; /* mono */ @@ -1023,16 +1022,16 @@ gl846_init_optical_regs_scan (Genesys_Device * dev, r = sanei_genesys_get_address (reg, 0x87); r->value &= ~REG87_LEDADD; if (channels == 1 && (flags & OPTICAL_FLAG_ENABLE_LEDADD)) - { - r->value |= REG87_LEDADD; - } + { + r->value |= REG87_LEDADD; + } /* RGB weighting r = sanei_genesys_get_address (reg, 0x01); r->value &= ~REG01_TRUEGRAY; if (channels == 1 && (flags & OPTICAL_FLAG_ENABLE_LEDADD)) - { - r->value |= REG01_TRUEGRAY; - }*/ + { + r->value |= REG01_TRUEGRAY; + }*/ } /* words(16bit) before gamma, conversion to 8 bit or lineart*/ @@ -1097,19 +1096,11 @@ gl846_init_optical_regs_scan (Genesys_Device * dev, * this function sets up the scanner to scan in normal or single line mode */ static SANE_Status -gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, - Genesys_Register_Set * reg, - float xres, /*dpi */ - float yres, /*dpi */ - float startx, /*optical_res, from dummy_pixel+1 */ - float starty, /*base_ydpi, from home! */ - float pixels, - float lines, - unsigned int depth, - unsigned int channels, - int color_filter, - unsigned int flags) +gl846_init_scan_regs(Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Register_Set * reg, + SetupParams& params) { + params.assert_valid(); + int used_res; int start, used_pixels; int bytes_per_line; @@ -1131,17 +1122,11 @@ gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, int optical_res; SANE_Status status; - DBG(DBG_info, "%s settings:\n" - "Resolution : %gDPI/%gDPI\n" - "Lines : %g\n" - "PPL : %g\n" - "Startpos : %g/%g\n" - "Depth/Channels: %u/%u\n" - "Flags : %x\n\n", - __func__, xres, yres, lines, pixels, startx, starty, depth, channels, flags); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, params); /* we may have 2 domains for ccd: xres below or above half ccd max dpi */ - if (sensor.get_ccd_size_divisor_for_dpi(xres) > 1) + if (sensor.get_ccd_size_divisor_for_dpi(params.xres) > 1) { half_ccd = SANE_TRUE; } @@ -1157,20 +1142,20 @@ gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, /* stagger */ if ((!half_ccd) && (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE)) - stagger = (4 * yres) / dev->motor.base_ydpi; + stagger = (4 * params.yres) / dev->motor.base_ydpi; else stagger = 0; DBG(DBG_info, "%s : stagger=%d lines\n", __func__, stagger); /* used_res */ - if (flags & SCAN_FLAG_USE_OPTICAL_RES) + if (params.flags & SCAN_FLAG_USE_OPTICAL_RES) { used_res = optical_res; } else { /* resolution is choosen from a list */ - used_res = xres; + used_res = params.xres; } /* compute scan parameters values */ @@ -1178,28 +1163,28 @@ gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, /* use detected left margin and fixed value */ /* start */ /* add x coordinates */ - start = startx; + start = params.startx; if (stagger > 0) start |= 1; /* compute correct pixels number */ /* pixels */ - used_pixels = (pixels * optical_res) / xres; + used_pixels = (params.pixels * optical_res) / params.xres; /* round up pixels number if needed */ - if (used_pixels * xres < pixels * optical_res) + if (used_pixels * params.xres < params.pixels * optical_res) used_pixels++; - dummy = 3-channels; + dummy = 3-params.channels; /* slope_dpi */ /* cis color scan is effectively a gray scan with 3 gray lines per color line and a FILTER of 0 */ if (dev->model->is_cis) - slope_dpi = yres * channels; + slope_dpi = params.yres * params.channels; else - slope_dpi = yres; + slope_dpi = params.yres; slope_dpi = slope_dpi * (1 + dummy); @@ -1212,20 +1197,19 @@ gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, /*** optical parameters ***/ /* in case of dynamic lineart, we use an internal 8 bit gray scan * to generate 1 lineart data */ - if ((flags & SCAN_FLAG_DYNAMIC_LINEART) && (dev->settings.scan_mode == SCAN_MODE_LINEART)) - { - depth = 8; + if (params.flags & SCAN_FLAG_DYNAMIC_LINEART) { + params.depth = 8; } /* we enable true gray for cis scanners only, and just when doing * scan since color calibration is OK for this mode */ oflags = 0; - if(flags & SCAN_FLAG_DISABLE_SHADING) + if(params.flags & SCAN_FLAG_DISABLE_SHADING) oflags |= OPTICAL_FLAG_DISABLE_SHADING; - if(flags & SCAN_FLAG_DISABLE_GAMMA) + if(params.flags & SCAN_FLAG_DISABLE_GAMMA) oflags |= OPTICAL_FLAG_DISABLE_GAMMA; - if(flags & SCAN_FLAG_DISABLE_LAMP) + if(params.flags & SCAN_FLAG_DISABLE_LAMP) oflags |= OPTICAL_FLAG_DISABLE_LAMP; if (dev->model->is_cis && dev->settings.true_gray) @@ -1234,15 +1218,15 @@ gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, } status = gl846_init_optical_regs_scan (dev, sensor, - reg, - exposure_time, - used_res, - start, - used_pixels, - channels, - depth, - half_ccd, - color_filter, + reg, + exposure_time, + used_res, + start, + used_pixels, + params.channels, + params.depth, + half_ccd, + params.color_filter, oflags); if (status != SANE_STATUS_GOOD) @@ -1251,19 +1235,19 @@ gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, /*** motor parameters ***/ /* max_shift */ - max_shift=sanei_genesys_compute_max_shift(dev,channels,yres,flags); + max_shift=sanei_genesys_compute_max_shift(dev,params.channels,params.yres,params.flags); /* lincnt */ - lincnt = lines + max_shift + stagger; + lincnt = params.lines + max_shift + stagger; /* add tl_y to base movement */ - move = starty; + move = params.starty; DBG(DBG_info, "%s: move=%d steps\n", __func__, move); mflags=0; - if(flags & SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE) + if(params.flags & SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE) mflags |= MOTOR_FLAG_DISABLE_BUFFER_FULL_MOVE; - if(flags & SCAN_FLAG_FEEDING) + if(params.flags & SCAN_FLAG_FEEDING) mflags |= MOTOR_FLAG_FEED; status = gl846_init_motor_regs_scan (dev, sensor, @@ -1272,7 +1256,7 @@ gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, slope_dpi, scan_step_type, dev->model->is_cis ? lincnt * - channels : lincnt, dummy, move, + params.channels : lincnt, dummy, move, scan_power_mode, mflags); @@ -1284,13 +1268,13 @@ gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, /* words_per_line */ bytes_per_line = (used_pixels * used_res) / optical_res; - bytes_per_line = (bytes_per_line * channels * depth) / 8; + bytes_per_line = (bytes_per_line * params.channels * params.depth) / 8; requested_buffer_size = 8 * bytes_per_line; read_buffer_size = 2 * requested_buffer_size + - ((max_shift + stagger) * used_pixels * channels * depth) / 8; + ((max_shift + stagger) * used_pixels * params.channels * params.depth) / 8; dev->read_buffer.clear(); dev->read_buffer.alloc(read_buffer_size); @@ -1302,21 +1286,21 @@ gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, dev->shrink_buffer.alloc(requested_buffer_size); dev->out_buffer.clear(); - dev->out_buffer.alloc((8 * dev->settings.pixels * channels * depth) / 8); + dev->out_buffer.alloc((8 * params.pixels * params.channels * params.depth) / 8); dev->read_bytes_left = bytes_per_line * lincnt; DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left); dev->read_active = SANE_TRUE; - + dev->current_setup.params = params; dev->current_setup.pixels = (used_pixels * used_res) / optical_res; dev->current_setup.lines = lincnt; - dev->current_setup.depth = depth; - dev->current_setup.channels = channels; + dev->current_setup.depth = params.depth; + dev->current_setup.channels = params.channels; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = used_res; - dev->current_setup.yres = yres; + dev->current_setup.yres = params.yres; dev->current_setup.ccd_size_divisor = half_ccd ? 2 : 1; dev->current_setup.stagger = stagger; dev->current_setup.max_shift = max_shift + stagger; @@ -1325,7 +1309,7 @@ gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, /* scan bytes to send to the frontend */ /* theory : target_size = - (dev->settings.pixels * dev->settings.lines * channels * depth) / 8; + (params.pixels * params.lines * channels * depth) / 8; but it suffers from integer overflow so we do the following: 1 bit color images store color data byte-wise, eg byte 0 contains @@ -1337,14 +1321,14 @@ gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, */ dev->total_bytes_read = 0; - if (depth == 1) + if (params.depth == 1) dev->total_bytes_to_read = - ((dev->settings.pixels * dev->settings.lines) / 8 + - (((dev->settings.pixels * dev->settings.lines) % 8) ? 1 : 0)) * - channels; + ((params.pixels * params.lines) / 8 + + (((params.pixels * params.lines) % 8) ? 1 : 0)) * + params.channels; else dev->total_bytes_to_read = - dev->settings.pixels * dev->settings.lines * channels * (depth / 8); + params.pixels * params.lines * params.channels * (params.depth / 8); DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); /* END TODO */ @@ -1360,12 +1344,6 @@ gl846_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor int depth; int start; - float xres; /*dpi */ - float yres; /*dpi */ - float startx; /*optical_res, from dummy_pixel+1 */ - float pixels; - float lines; - int used_res; int used_pixels; unsigned int lincnt; @@ -1379,24 +1357,18 @@ gl846_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor SANE_Bool half_ccd; /* false: full CCD res is used, true, half max CCD res is used */ int optical_res; - DBG(DBG_info, "%s settings:\n" - "Resolution: %uDPI\n" - "Lines : %u\n" - "PPL : %u\n" - "Startpos : %.3f/%.3f\n" - "Scan mode : %d\n\n", __func__, - dev->settings.yres, dev->settings.lines, dev->settings.pixels, - dev->settings.tl_x, dev->settings.tl_y, dev->settings.scan_mode); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, dev->settings); /* channels */ - if (dev->settings.scan_mode == 4) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; else channels = 1; /* depth */ depth = dev->settings.depth; - if (dev->settings.scan_mode == 0) + if (dev->settings.scan_mode == ScanColorMode::LINEART) depth = 1; /* start */ @@ -1405,23 +1377,26 @@ gl846_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor start = (start * sensor.optical_res) / MM_PER_INCH; - xres = dev->settings.xres; /*dpi */ - yres = dev->settings.yres; /*dpi */ - startx = start; /*optical_res, from dummy_pixel+1 */ - pixels = dev->settings.pixels; - lines = dev->settings.lines; + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = start; // not used + params.starty = 0; // not used + params.pixels = dev->settings.pixels; + params.lines = dev->settings.lines; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = 0; - DBG(DBG_info, "%s settings:\n" - "Resolution : %gDPI/%gDPI\n" - "Lines : %g\n" - "PPL : %g\n" - "Startpos : %g\n" - "Depth/Channels: %u/%u\n\n", - __func__, xres, yres, lines, pixels, startx, depth, channels); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, params); /* half_ccd */ /* we have 2 domains for ccd: xres below or above half ccd max dpi */ - if (sensor.get_ccd_size_divisor_for_dpi(xres) > 1) { + if (sensor.get_ccd_size_divisor_for_dpi(params.xres) > 1) { half_ccd = SANE_TRUE; } else { half_ccd = SANE_FALSE; @@ -1432,48 +1407,48 @@ gl846_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor /* stagger */ if (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE) - stagger = (4 * yres) / dev->motor.base_ydpi; + stagger = (4 * params.yres) / dev->motor.base_ydpi; else stagger = 0; DBG(DBG_info, "%s: stagger=%d lines\n", __func__, stagger); /* resolution is choosen from a fixed list */ - used_res = xres; + used_res = params.xres; /* compute scan parameters values */ /* pixels are allways given at half or full CCD optical resolution */ /* use detected left margin and fixed value */ /* compute correct pixels number */ - used_pixels = (pixels * optical_res) / used_res; - dummy = 3-channels; + used_pixels = (params.pixels * optical_res) / used_res; + dummy = 3 - params.channels; - /* slope_dpi */ /* cis color scan is effectively a gray scan with 3 gray lines per color line and a FILTER of 0 */ - if (dev->model->is_cis) - slope_dpi = yres * channels; - else - slope_dpi = yres; + if (dev->model->is_cis) { + slope_dpi = params.yres * params.channels; + } else { + slope_dpi = params.yres; + } slope_dpi = slope_dpi * (1 + dummy); exposure_time = gl846_compute_exposure (dev, used_res); DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); - /* max_shift */ - max_shift=sanei_genesys_compute_max_shift(dev,channels,yres,0); + max_shift = sanei_genesys_compute_max_shift(dev, params.channels, params.yres, 0); /* lincnt */ - lincnt = lines + max_shift + stagger; + lincnt = params.lines + max_shift + stagger; + dev->current_setup.params = params; dev->current_setup.pixels = (used_pixels * used_res) / optical_res; dev->current_setup.lines = lincnt; - dev->current_setup.depth = depth; - dev->current_setup.channels = channels; + dev->current_setup.depth = params.depth; + dev->current_setup.channels = params.channels; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = used_res; - dev->current_setup.yres = yres; + dev->current_setup.yres = params.yres; dev->current_setup.ccd_size_divisor = half_ccd ? 2 : 1; dev->current_setup.stagger = stagger; dev->current_setup.max_shift = max_shift + stagger; @@ -1482,46 +1457,6 @@ gl846_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor return SANE_STATUS_GOOD; } -static void -gl846_set_motor_power (Genesys_Register_Set * regs, SANE_Bool set) -{ - - DBG(DBG_proc, "%s\n", __func__); - - if (set) - { - sanei_genesys_set_reg_from_set (regs, REG02, - sanei_genesys_read_reg_from_set (regs, - REG02) - | REG02_MTRPWR); - } - else - { - sanei_genesys_set_reg_from_set (regs, REG02, - sanei_genesys_read_reg_from_set (regs, - REG02) - & ~REG02_MTRPWR); - } -} - -static void -gl846_set_lamp_power (Genesys_Device __sane_unused__ * dev, const Genesys_Sensor& /*sensor*/, - Genesys_Register_Set * regs, SANE_Bool set) -{ - if (set) - { - sanei_genesys_set_reg_from_set (regs, REG03, - sanei_genesys_read_reg_from_set (regs, REG03) - | REG03_LAMPPWR); - } - else - { - sanei_genesys_set_reg_from_set (regs, REG03, - sanei_genesys_read_reg_from_set (regs, REG03) - & ~REG03_LAMPPWR); - } -} - /*for fast power saving methods only, like disabling certain amplifiers*/ static SANE_Status gl846_save_power (Genesys_Device * dev, SANE_Bool enable) @@ -1601,24 +1536,24 @@ gl846_stop_action (Genesys_Device * dev) { status = sanei_genesys_get_status (dev, &val); if (DBG_LEVEL >= DBG_io) - { - sanei_genesys_print_status (val); - } + { + sanei_genesys_print_status (val); + } status = sanei_genesys_read_register (dev, REG40, &val40); if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: failed to read home sensor: %s\n", __func__, sane_strstatus(status)); + { + DBG(DBG_error, "%s: failed to read home sensor: %s\n", __func__, sane_strstatus(status)); DBGCOMPLETED; - return status; - } + return status; + } /* if scanner is in command mode, we are done */ if (!(val40 & REG40_DATAENB) && !(val40 & REG40_MOTMFLG) - && !(val & REG41_MOTORENB)) - { + && !(val & REG41_MOTORENB)) + { DBGCOMPLETED; - return SANE_STATUS_GOOD; - } + return SANE_STATUS_GOOD; + } sanei_genesys_sleep_ms(100); loop--; @@ -1631,7 +1566,7 @@ gl846_stop_action (Genesys_Device * dev) /* Send the low-level scan command */ static SANE_Status gl846_begin_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Register_Set * reg, - SANE_Bool start_motor) + SANE_Bool start_motor) { (void) sensor; SANE_Status status; @@ -1675,7 +1610,7 @@ gl846_begin_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Re /* Send the stop scan command */ static SANE_Status gl846_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg, - SANE_Bool check_stop) + SANE_Bool check_stop) { SANE_Status status; @@ -1691,10 +1626,10 @@ gl846_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg, { status = gl846_stop_action (dev); if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: failed to stop: %s\n", __func__, sane_strstatus(status)); - return status; - } + { + DBG(DBG_error, "%s: failed to stop: %s\n", __func__, sane_strstatus(status)); + return status; + } } DBGCOMPLETED; @@ -1711,7 +1646,7 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) float resolution; uint8_t val; int loop = 0; - int scan_mode; + ScanColorMode scan_mode; DBG(DBG_proc, "%s (wait_until_home = %d)\n", __func__, wait_until_home); @@ -1760,21 +1695,26 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) /* TODO add scan_mode to the API */ scan_mode= dev->settings.scan_mode; - dev->settings.scan_mode=SCAN_MODE_LINEART; - status = gl846_init_scan_regs (dev, sensor, - &local_reg, - resolution, - resolution, - 100, - 30000, - 100, - 100, - 8, - 1, - 0, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + dev->settings.scan_mode = ScanColorMode::LINEART; + + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 100; + params.starty = 30000; + params.pixels = 100; + params.lines = 100; + params.depth = 8; + params.channels = 1; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::GRAY; + params.color_filter = ColorFilter::RED; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl846_init_scan_regs(dev, sensor, &local_reg, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to set up registers: %s\n", __func__, sane_strstatus(status)); @@ -1808,26 +1748,26 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) if (wait_until_home) { while (loop < 300) /* do not wait longer then 30 seconds */ - { - status = sanei_genesys_get_status (dev, &val); - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: failed to read home sensor: %s\n", __func__, - sane_strstatus(status)); - return status; - } + { + status = sanei_genesys_get_status (dev, &val); + if (status != SANE_STATUS_GOOD) + { + DBG(DBG_error, "%s: failed to read home sensor: %s\n", __func__, + sane_strstatus(status)); + return status; + } - if (val & HOMESNR) /* home sensor */ - { - DBG(DBG_info, "%s: reached home position\n", __func__); + if (val & HOMESNR) /* home sensor */ + { + DBG(DBG_info, "%s: reached home position\n", __func__); gl846_stop_action (dev); dev->scanhead_position_in_steps = 0; - DBGCOMPLETED; - return SANE_STATUS_GOOD; - } + DBGCOMPLETED; + return SANE_STATUS_GOOD; + } sanei_genesys_sleep_ms(100); - ++loop; - } + ++loop; + } /* when we come here then the scanner needed too much time for this, so we better stop the motor */ gl846_stop_action (dev); @@ -1864,11 +1804,24 @@ gl846_search_start_position (Genesys_Device * dev) // whith employ different sensors with potentially different settings. auto& sensor = sanei_genesys_find_sensor_for_write(dev, dpi); - status = gl846_init_scan_regs (dev, sensor, &local_reg, dpi, dpi, 0, 0, /*we should give a small offset here~60 steps */ - 600, dev->model->search_lines, 8, 1, 1, /*green */ - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + SetupParams params; + params.xres = dpi; + params.yres = dpi; + params.startx = 0; + params.starty = 0; /*we should give a small offset here~60 steps */ + params.pixels = 600; + params.lines = dev->model->search_lines; + params.depth = 8; + params.channels = 1; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::GRAY; + params.color_filter = ColorFilter::GREEN; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl846_init_scan_regs(dev, sensor, &local_reg, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to set up registers: %s\n", __func__, sane_strstatus(status)); @@ -1927,7 +1880,7 @@ gl846_search_start_position (Genesys_Device * dev) stores information, and use that correctly*/ status = sanei_genesys_search_reference_point (dev, sensor, data.data(), 0, dpi, pixels, - dev->model->search_lines); + dev->model->search_lines); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to set search reference point: %s\n", __func__, @@ -1942,7 +1895,8 @@ gl846_search_start_position (Genesys_Device * dev) * sets up register for coarse gain calibration * todo: check it for scanners using it */ static SANE_Status -gl846_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl846_init_regs_for_coarse_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status; uint8_t channels; @@ -1951,29 +1905,34 @@ gl846_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sens DBG(DBG_proc, "%s\n", __func__); - cksel = (dev->calib_reg.find_reg(0x18).value & REG18_CKSEL) + 1; /* clock speed = 1..4 clocks */ + cksel = (regs.find_reg(0x18).value & REG18_CKSEL) + 1; /* clock speed = 1..4 clocks */ /* set line size */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; - else + else { channels = 1; + } + + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = 0; + params.starty = 0; + params.pixels = sensor.optical_res / cksel; + params.lines = 20; + params.depth = 16; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl846_init_scan_regs(dev, sensor, ®s, params); - status = gl846_init_scan_regs (dev, sensor, - &dev->calib_reg, - dev->settings.xres, - dev->settings.yres, - 0, - 0, - sensor.optical_res / cksel, - 20, - 16, - channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: Failed to setup scan: %s\n", __func__, sane_strstatus(status)); @@ -1983,7 +1942,7 @@ gl846_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sens DBG(DBG_info, "%s: optical sensor res: %d dpi, actual res: %d\n", __func__, sensor.optical_res / cksel, dev->settings.xres); - status = dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg); + status = dev->model->cmd_set->bulk_write_register(dev, regs); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: Failed to bulk write registers: %s\n", __func__, sane_strstatus(status)); @@ -2015,21 +1974,26 @@ gl846_feed (Genesys_Device * dev, unsigned int steps) resolution=sanei_genesys_get_lowest_ydpi(dev); const auto& sensor = sanei_genesys_find_sensor(dev, resolution); - status = gl846_init_scan_regs (dev, sensor, - &local_reg, - resolution, - resolution, - 0, - steps, - 100, - 3, - 8, - 3, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_FEEDING | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 0; + params.starty = steps; + params.pixels = 100; + params.lines = 3; + params.depth = 8; + params.channels = 3; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_FEEDING | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl846_init_scan_regs(dev, sensor, &local_reg, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to set up registers: %s\n", __func__, sane_strstatus(status)); @@ -2082,7 +2046,8 @@ gl846_feed (Genesys_Device * dev, unsigned int steps) /* init registers for shading calibration */ static SANE_Status -gl846_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl846_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status; float move; @@ -2091,7 +2056,7 @@ gl846_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) dev->calib_channels = 3; /* initial calibration reg values */ - dev->calib_reg = dev->reg; + regs = dev->reg; dev->calib_resolution = sanei_genesys_compute_dpihw(dev, sensor, dev->settings.xres); dev->calib_total_bytes_to_read = 0; @@ -2110,21 +2075,24 @@ gl846_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) move=40; } - status = gl846_init_scan_regs (dev, sensor, - &dev->calib_reg, - dev->calib_resolution, - dev->calib_resolution, - 0, - move, - dev->calib_pixels, - dev->calib_lines, - 16, - dev->calib_channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + SetupParams params; + params.xres = dev->calib_resolution; + params.yres = dev->calib_resolution; + params.startx = 0; + params.starty = move; + params.pixels = dev->calib_pixels; + params.lines = dev->calib_lines; + params.depth = 16; + params.channels = dev->calib_channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl846_init_scan_regs(dev, sensor, ®s, params); if (status != SANE_STATUS_GOOD) { @@ -2132,7 +2100,7 @@ gl846_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) return status; } - status = dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg); + status = dev->model->cmd_set->bulk_write_register(dev, regs); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to bulk write registers: %s\n", __func__, sane_strstatus(status)); @@ -2160,20 +2128,18 @@ gl846_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) SANE_Status status; - DBG(DBG_info, "%s settings:\nResolution: %uDPI\n" - "Lines : %u\nPPL : %u\nStartpos : %.3f/%.3f\nScan mode : %d\n\n", __func__, - dev->settings.yres, dev->settings.lines, dev->settings.pixels, - dev->settings.tl_x, dev->settings.tl_y, dev->settings.scan_mode); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, dev->settings); /* channels */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; else channels = 1; /* depth */ depth = dev->settings.depth; - if (dev->settings.scan_mode == SCAN_MODE_LINEART) + if (dev->settings.scan_mode == ScanColorMode::LINEART) depth = 1; @@ -2231,7 +2197,7 @@ gl846_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) flags = 0; /* emulated lineart from gray data is required for now */ - if(dev->settings.scan_mode == SCAN_MODE_LINEART + if(dev->settings.scan_mode == ScanColorMode::LINEART && dev->settings.dynamic_lineart) { flags |= SCAN_FLAG_DYNAMIC_LINEART; @@ -2240,18 +2206,21 @@ gl846_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) /* backtracking isn't handled well, so don't enable it */ flags |= SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE; - status = gl846_init_scan_regs (dev, sensor, - &dev->reg, - dev->settings.xres, - dev->settings.yres, - start, - move, - dev->settings.pixels, - dev->settings.lines, - depth, - channels, - dev->settings.color_filter, - flags); + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = start; + params.starty = move; + params.pixels = dev->settings.pixels; + params.lines = dev->settings.lines; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = flags; + + status = gl846_init_scan_regs(dev, sensor, &dev->reg, params); if (status != SANE_STATUS_GOOD) return status; @@ -2371,7 +2340,7 @@ gl846_send_shading_data (Genesys_Device * dev, const Genesys_Sensor& sensor, * @param dev device to calibrate */ static SANE_Status -gl846_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) +gl846_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor, Genesys_Register_Set& regs) { int num_pixels; int total_size; @@ -2404,24 +2373,27 @@ gl846_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) num_pixels = (sensor.sensor_pixels*used_res)/sensor.optical_res; /* initial calibration reg values */ - dev->calib_reg = dev->reg; + regs = dev->reg; + + SetupParams params; + params.xres = used_res; + params.yres = used_res; + params.startx = 0; + params.starty = 0; + params.pixels = num_pixels; + params.lines = 1; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl846_init_scan_regs(dev, sensor, ®s, params); - /* set up for the calibration scan */ - status = gl846_init_scan_regs (dev, sensor, - &dev->calib_reg, - used_res, - used_res, - 0, - 0, - num_pixels, - 1, - depth, - channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus(status)); @@ -2447,50 +2419,50 @@ gl846_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) turn = 0; /* no move during led calibration */ - gl846_set_motor_power (&dev->calib_reg, SANE_FALSE); + sanei_genesys_set_motor_power(regs, false); do { /* set up exposure */ - sanei_genesys_set_double(&dev->calib_reg,REG_EXPR,exp[0]); - sanei_genesys_set_double(&dev->calib_reg,REG_EXPG,exp[1]); - sanei_genesys_set_double(&dev->calib_reg,REG_EXPB,exp[2]); + sanei_genesys_set_double(®s,REG_EXPR,exp[0]); + sanei_genesys_set_double(®s,REG_EXPG,exp[1]); + sanei_genesys_set_double(®s,REG_EXPB,exp[2]); /* write registers and scan data */ - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting line reading\n", __func__); - RIE(gl846_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl846_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, line.data(), total_size)); /* stop scanning */ RIE(gl846_stop_action(dev)); if (DBG_LEVEL >= DBG_data) - { + { char fn[30]; snprintf(fn, 30, "gl846_led_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), depth, channels, num_pixels, 1); - } + } /* compute average */ for (j = 0; j < channels; j++) - { - avg[j] = 0; - for (i = 0; i < num_pixels; i++) - { - if (dev->model->is_cis) - val = - line[i * 2 + j * 2 * num_pixels + 1] * 256 + - line[i * 2 + j * 2 * num_pixels]; - else - val = - line[i * 2 * channels + 2 * j + 1] * 256 + - line[i * 2 * channels + 2 * j]; - avg[j] += val; - } + { + avg[j] = 0; + for (i = 0; i < num_pixels; i++) + { + if (dev->model->is_cis) + val = + line[i * 2 + j * 2 * num_pixels + 1] * 256 + + line[i * 2 + j * 2 * num_pixels]; + else + val = + line[i * 2 * channels + 2 * j + 1] * 256 + + line[i * 2 * channels + 2 * j]; + avg[j] += val; + } - avg[j] /= num_pixels; - } + avg[j] /= num_pixels; + } DBG(DBG_info, "%s: average: %d,%d,%d\n", __func__, avg[0], avg[1], avg[2]); @@ -2726,14 +2698,10 @@ gl846_update_hardware_sensors (Genesys_Scanner * s) } RIE (sanei_genesys_read_register (s->dev, REG6D, &val)); - if (s->val[OPT_SCAN_SW].b == s->last_val[OPT_SCAN_SW].b) - s->val[OPT_SCAN_SW].b = (val & scan) == 0; - if (s->val[OPT_FILE_SW].b == s->last_val[OPT_FILE_SW].b) - s->val[OPT_FILE_SW].b = (val & file) == 0; - if (s->val[OPT_EMAIL_SW].b == s->last_val[OPT_EMAIL_SW].b) - s->val[OPT_EMAIL_SW].b = (val & email) == 0; - if (s->val[OPT_COPY_SW].b == s->last_val[OPT_COPY_SW].b) - s->val[OPT_COPY_SW].b = (val & copy) == 0; + s->buttons[BUTTON_SCAN_SW].write((val & scan) == 0); + s->buttons[BUTTON_FILE_SW].write((val & file) == 0); + s->buttons[BUTTON_EMAIL_SW].write((val & email) == 0); + s->buttons[BUTTON_COPY_SW].write((val & copy) == 0); return status; } @@ -2781,7 +2749,7 @@ gl846_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor, for (x = 0; x < MAX_RESOLUTIONS; x++) { if (dev->model->xdpi_values[x] > 0 && dev->model->xdpi_values[x] < dpi) - dpi = dev->model->xdpi_values[x]; + dpi = dev->model->xdpi_values[x]; } channels = 1; /* 10 MM */ @@ -2797,19 +2765,22 @@ gl846_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor, local_reg = dev->reg; - status = gl846_init_scan_regs (dev, sensor, - &local_reg, - dpi, - dpi, - 0, - 0, - pixels, - lines, - depth, - channels, - 0, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA); + SetupParams params; + params.xres = dpi; + params.yres = dpi; + params.startx = 0; + params.starty = 0; + params.pixels = pixels; + params.lines = lines; + params.depth = depth; + params.channels = channels; + params.scan_mode = ScanColorMode::GRAY; + params.color_filter = ColorFilter::RED; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA; + + status = gl846_init_scan_regs(dev, sensor, &local_reg, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup for scan: %s\n", __func__, sane_strstatus(status)); @@ -2872,122 +2843,122 @@ gl846_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor, { status = dev->model->cmd_set->bulk_write_register(dev, local_reg); if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: Failed to bulk write registers: %s\n", __func__, - sane_strstatus(status)); - return status; - } + { + DBG(DBG_error, "%s: Failed to bulk write registers: %s\n", __func__, + sane_strstatus(status)); + return status; + } /* now start scan */ status = gl846_begin_scan(dev, sensor, &local_reg, SANE_TRUE); if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: failed to begin scan: %s\n", __func__, sane_strstatus(status)); - return status; - } + { + DBG(DBG_error, "%s: failed to begin scan: %s\n", __func__, sane_strstatus(status)); + return status; + } /* waits for valid data */ do - sanei_genesys_test_buffer_empty (dev, &steps); + sanei_genesys_test_buffer_empty (dev, &steps); while (steps); /* now we're on target, we can read data */ status = sanei_genesys_read_data_from_scanner(dev, data.data(), size); if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: failed to read data: %s\n", __func__, sane_strstatus(status)); - return status; - } + { + DBG(DBG_error, "%s: failed to read data: %s\n", __func__, sane_strstatus(status)); + return status; + } status = gl846_stop_action (dev); if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: gl846_stop_action failed\n", __func__); - return status; - } + { + DBG(DBG_error, "%s: gl846_stop_action failed\n", __func__); + return status; + } if (DBG_LEVEL >= DBG_data) - { + { sprintf(title, "gl846_search_strip_%s_%s%02d.pnm", black ? "black" : "white", forward ? "fwd" : "bwd", (int)pass); sanei_genesys_write_pnm_file(title, data.data(), depth, channels, pixels, lines); - } + } /* search data to find black strip */ /* when searching forward, we only need one line of the searched color since we * will scan forward. But when doing backward search, we need all the area of the * same color */ if (forward) - { - for (y = 0; y < lines && !found; y++) - { - count = 0; - /* count of white/black pixels depending on the color searched */ - for (x = 0; x < pixels; x++) - { - /* when searching for black, detect white pixels */ - if (black && data[y * pixels + x] > 90) - { - count++; - } - /* when searching for white, detect black pixels */ - if (!black && data[y * pixels + x] < 60) - { - count++; - } - } + { + for (y = 0; y < lines && !found; y++) + { + count = 0; + /* count of white/black pixels depending on the color searched */ + for (x = 0; x < pixels; x++) + { + /* when searching for black, detect white pixels */ + if (black && data[y * pixels + x] > 90) + { + count++; + } + /* when searching for white, detect black pixels */ + if (!black && data[y * pixels + x] < 60) + { + count++; + } + } - /* at end of line, if count >= 3%, line is not fully of the desired color - * so we must go to next line of the buffer */ - /* count*100/pixels < 3 */ - if ((count * 100) / pixels < 3) - { - found = 1; - DBG(DBG_data, "%s: strip found forward during pass %d at line %d\n", __func__, - pass, y); - } - else - { - DBG(DBG_data, "%s: pixels=%d, count=%d (%d%%)\n", __func__, pixels, count, - (100 * count) / pixels); - } - } - } + /* at end of line, if count >= 3%, line is not fully of the desired color + * so we must go to next line of the buffer */ + /* count*100/pixels < 3 */ + if ((count * 100) / pixels < 3) + { + found = 1; + DBG(DBG_data, "%s: strip found forward during pass %d at line %d\n", __func__, + pass, y); + } + else + { + DBG(DBG_data, "%s: pixels=%d, count=%d (%d%%)\n", __func__, pixels, count, + (100 * count) / pixels); + } + } + } else /* since calibration scans are done forward, we need the whole area - to be of the required color when searching backward */ - { - count = 0; - for (y = 0; y < lines; y++) - { - /* count of white/black pixels depending on the color searched */ - for (x = 0; x < pixels; x++) - { - /* when searching for black, detect white pixels */ - if (black && data[y * pixels + x] > 90) - { - count++; - } - /* when searching for white, detect black pixels */ - if (!black && data[y * pixels + x] < 60) - { - count++; - } - } - } + to be of the required color when searching backward */ + { + count = 0; + for (y = 0; y < lines; y++) + { + /* count of white/black pixels depending on the color searched */ + for (x = 0; x < pixels; x++) + { + /* when searching for black, detect white pixels */ + if (black && data[y * pixels + x] > 90) + { + count++; + } + /* when searching for white, detect black pixels */ + if (!black && data[y * pixels + x] < 60) + { + count++; + } + } + } - /* at end of area, if count >= 3%, area is not fully of the desired color - * so we must go to next buffer */ - if ((count * 100) / (pixels * lines) < 3) - { - found = 1; - DBG(DBG_data, "%s: strip found backward during pass %d \n", __func__, pass); - } - else - { - DBG(DBG_data, "%s: pixels=%d, count=%d (%d%%)\n", __func__, pixels, count, - (100 * count) / pixels); - } - } + /* at end of area, if count >= 3%, area is not fully of the desired color + * so we must go to next buffer */ + if ((count * 100) / (pixels * lines) < 3) + { + found = 1; + DBG(DBG_data, "%s: strip found backward during pass %d \n", __func__, pass); + } + else + { + DBG(DBG_data, "%s: pixels=%d, count=%d (%d%%)\n", __func__, pixels, count, + (100 * count) / pixels); + } + } pass++; } @@ -3011,7 +2982,7 @@ gl846_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor, */ static int dark_average (uint8_t * data, unsigned int pixels, unsigned int lines, - unsigned int channels, unsigned int black) + unsigned int channels, unsigned int black) { unsigned int i, j, k, average, count; unsigned int avg[3]; @@ -3023,16 +2994,16 @@ dark_average (uint8_t * data, unsigned int pixels, unsigned int lines, avg[k] = 0; count = 0; for (i = 0; i < lines; i++) - { - for (j = 0; j < black; j++) - { - val = data[i * channels * pixels + j + k]; - avg[k] += val; - count++; - } - } + { + for (j = 0; j < black; j++) + { + val = data[i * channels * pixels + j + k]; + avg[k] += val; + count++; + } + } if (count) - avg[k] /= count; + avg[k] /= count; DBG(DBG_info, "%s: avg[%d] = %d\n", __func__, k, avg[k]); } average = 0; @@ -3044,7 +3015,8 @@ dark_average (uint8_t * data, unsigned int pixels, unsigned int lines, } static SANE_Status -gl846_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) +gl846_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status = SANE_STATUS_GOOD; uint8_t reg04; @@ -3073,27 +3045,31 @@ gl846_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) black_pixels = (sensor.black_pixels * resolution) / sensor.optical_res; DBG(DBG_io2, "%s: black_pixels=%d\n", __func__, black_pixels); - status = gl846_init_scan_regs (dev, sensor, - &dev->calib_reg, - resolution, - resolution, - 0, - 0, - pixels, - lines, - bpp, - channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 0; + params.starty = 0; + params.pixels = pixels; + params.lines = lines; + params.depth = bpp; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl846_init_scan_regs(dev, sensor, ®s, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus(status)); return status; } - gl846_set_motor_power (&dev->calib_reg, SANE_FALSE); + sanei_genesys_set_motor_power(regs, false); /* allocate memory for scans */ total_size = pixels * channels * lines * (bpp/8); /* colors * bytes_per_color * scan lines */ @@ -3113,9 +3089,9 @@ gl846_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) dev->frontend.set_offset(2, bottom); RIE(gl846_set_fe(dev, sensor, AFE_SET)); - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting first line reading\n", __func__); - RIE(gl846_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl846_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner (dev, first_line.data(), total_size)); if (DBG_LEVEL >= DBG_data) { @@ -3133,9 +3109,9 @@ gl846_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) dev->frontend.set_offset(1, top); dev->frontend.set_offset(2, top); RIE(gl846_set_fe(dev, sensor, AFE_SET)); - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting second line reading\n", __func__); - RIE(gl846_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl846_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner (dev, second_line.data(), total_size)); topavg = dark_average(second_line.data(), pixels, lines, channels, black_pixels); @@ -3153,32 +3129,32 @@ gl846_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) /* scan with no move */ RIE(gl846_set_fe(dev, sensor, AFE_SET)); - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting second line reading\n", __func__); - RIE(gl846_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl846_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner (dev, second_line.data(), total_size)); if (DBG_LEVEL >= DBG_data) - { + { char fn[30]; snprintf(fn, 30, "gl846_offset%03d.pnm", dev->frontend.get_offset(1)); sanei_genesys_write_pnm_file(fn, second_line.data(), bpp, channels, pixels, lines); - } + } avg = dark_average(second_line.data(), pixels, lines, channels, black_pixels); DBG(DBG_info, "%s: avg=%d offset=%d\n", __func__, avg, dev->frontend.get_offset(1)); /* compute new boundaries */ if (topavg == avg) - { - topavg = avg; + { + topavg = avg; top = dev->frontend.get_offset(1); - } + } else - { - bottomavg = avg; + { + bottomavg = avg; bottom = dev->frontend.get_offset(1); - } + } } DBG(DBG_info, "%s: offset=(%d,%d,%d)\n", __func__, dev->frontend.get_offset(0), @@ -3190,7 +3166,8 @@ gl846_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor) } static SANE_Status -gl846_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, int dpi) +gl846_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs, int dpi) { int pixels; int total_size; @@ -3232,22 +3209,26 @@ gl846_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor bpp=8; pixels = (sensor.sensor_pixels * resolution) / sensor.optical_res; - status = gl846_init_scan_regs (dev, sensor, - &dev->calib_reg, - resolution, - resolution, - 0, - 0, - pixels, - lines, - bpp, - channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); - gl846_set_motor_power(&dev->calib_reg, SANE_FALSE); + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 0; + params.starty = 0; + params.pixels = pixels; + params.lines = lines; + params.depth = bpp; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl846_init_scan_regs(dev, sensor, ®s, params); + + sanei_genesys_set_motor_power(regs, false); if (status != SANE_STATUS_GOOD) { @@ -3255,14 +3236,14 @@ gl846_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor return status; } - RIE (dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE (dev->model->cmd_set->bulk_write_register(dev, regs)); total_size = pixels * channels * (16/bpp) * lines; std::vector line(total_size); RIE(gl846_set_fe(dev, sensor, AFE_SET)); - RIE(gl846_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl846_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, line.data(), total_size)); if (DBG_LEVEL >= DBG_data) @@ -3273,14 +3254,14 @@ gl846_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor { max[j] = 0; for (i = pixels/4; i < (pixels*3/4); i++) - { - if (dev->model->is_cis) - val = line[i + j * pixels]; - else - val = line[i * channels + j]; + { + if (dev->model->is_cis) + val = line[i + j * pixels]; + else + val = line[i * channels + j]; - max[j] += val; - } + max[j] += val; + } max[j] = max[j] / (pixels/2); gain[j] = ((float) sensor.gain_white_ref*coeff) / max[j]; @@ -3288,9 +3269,9 @@ gl846_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor /* turn logical gain value into gain code, checking for overflow */ code = 283 - 208 / gain[j]; if (code > 255) - code = 255; + code = 255; else if (code < 0) - code = 0; + code = 0; dev->frontend.set_gain(j, code); DBG(DBG_proc, "%s: channel %d, max=%d, gain = %f, setting:%d\n", __func__, j, max[j], gain[j], @@ -3341,9 +3322,6 @@ static Genesys_Command_Set gl846_cmd_set = { gl846_set_powersaving, gl846_save_power, - gl846_set_motor_power, - gl846_set_lamp_power, - gl846_begin_scan, gl846_end_scan, @@ -3373,8 +3351,7 @@ static Genesys_Command_Set gl846_cmd_set = { NULL, gl846_send_shading_data, gl846_calculate_current_setup, - gl846_boot, - NULL + gl846_boot }; SANE_Status diff --git a/backend/genesys_gl846.h b/backend/genesys_gl846.h index 9e1709cdb..797c60580 100644 --- a/backend/genesys_gl846.h +++ b/backend/genesys_gl846.h @@ -342,18 +342,8 @@ * * this function sets up the scanner to scan in normal or single line mode */ -static SANE_Status gl846_init_scan_regs (Genesys_Device * dev, const Genesys_Sensor& sensor, - Genesys_Register_Set * reg, - float xres, /*dpi */ - float yres, /*dpi */ - float startx, /*optical_res, from dummy_pixel+1 */ - float starty, /*base_ydpi, from home! */ - float pixels, - float lines, - unsigned int depth, - unsigned int channels, - int color_filter, - unsigned int flags); +static SANE_Status gl846_init_scan_regs(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set * reg, SetupParams& params); /* Send the low-level scan command */ static SANE_Status gl846_begin_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index 4569ba344..6aa084da7 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -668,7 +668,7 @@ gl847_init_motor_regs_scan (Genesys_Device * dev, /* compute register 02 value */ r = sanei_genesys_get_address (reg, REG02); r->value = 0x00; - r->value |= REG02_MTRPWR; + sanei_genesys_set_motor_power(*reg, true); if (use_fast_fed) r->value |= REG02_FASTFED; @@ -867,7 +867,7 @@ gl847_init_optical_regs_scan (Genesys_Device * dev, unsigned int pixels, int channels, int depth, - SANE_Bool half_ccd, int color_filter, int flags) + SANE_Bool half_ccd, ColorFilter color_filter, int flags) { unsigned int words_per_line; unsigned int startx, endx, used_pixels; @@ -957,10 +957,7 @@ gl847_init_optical_regs_scan (Genesys_Device * dev, r = sanei_genesys_get_address (reg, REG03); r->value &= ~REG03_AVEENB; - if (flags & OPTICAL_FLAG_DISABLE_LAMP) - r->value &= ~REG03_LAMPPWR; - else - r->value |= REG03_LAMPPWR; + sanei_genesys_set_lamp_power(dev, sensor, *reg, !(flags & OPTICAL_FLAG_DISABLE_LAMP)); /* BW threshold */ r = sanei_genesys_get_address (reg, 0x2e); @@ -990,15 +987,18 @@ gl847_init_optical_regs_scan (Genesys_Device * dev, { switch (color_filter) { - case 0: - r->value |= 0x14; /* red filter */ - break; - case 2: - r->value |= 0x1c; /* blue filter */ - break; - default: - r->value |= 0x18; /* green filter */ - break; + + case ColorFilter::RED: + r->value |= 0x14; + break; + case ColorFilter::BLUE: + r->value |= 0x1c; + break; + case ColorFilter::GREEN: + r->value |= 0x18; + break; + default: + break; // should not happen } } else @@ -1112,20 +1112,12 @@ gl847_init_optical_regs_scan (Genesys_Device * dev, * this function sets up the scanner to scan in normal or single line mode */ static SANE_Status -gl847_init_scan_regs (Genesys_Device * dev, - const Genesys_Sensor& sensor, - Genesys_Register_Set * reg, - float xres, /*dpi */ - float yres, /*dpi */ - float startx, /*optical_res, from dummy_pixel+1 */ - float starty, /*base_ydpi, from home! */ - float pixels, - float lines, - unsigned int depth, - unsigned int channels, - int color_filter, - unsigned int flags) +gl847_init_scan_regs(Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Register_Set * reg, + SetupParams& params) + { + params.assert_valid(); + int used_res; int start, used_pixels; int bytes_per_line; @@ -1147,17 +1139,11 @@ gl847_init_scan_regs (Genesys_Device * dev, int optical_res; SANE_Status status; - DBG(DBG_info, "%s settings:\n" - "Resolution : %gDPI/%gDPI\n" - "Lines : %g\n" - "PPL : %g\n" - "Startpos : %g/%g\n" - "Depth/Channels: %u/%u\n" - "Flags : %x\n\n", - __func__, xres, yres, lines, pixels, startx, starty, depth, channels, flags); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, params); /* we may have 2 domains for ccd: xres below or above half ccd max dpi */ - if (sensor.get_ccd_size_divisor_for_dpi(xres) > 1) + if (sensor.get_ccd_size_divisor_for_dpi(params.xres) > 1) { half_ccd = SANE_TRUE; } @@ -1173,20 +1159,20 @@ gl847_init_scan_regs (Genesys_Device * dev, /* stagger */ if ((!half_ccd) && (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE)) - stagger = (4 * yres) / dev->motor.base_ydpi; + stagger = (4 * params.yres) / dev->motor.base_ydpi; else stagger = 0; DBG(DBG_info, "%s : stagger=%d lines\n", __func__, stagger); /* used_res */ - if (flags & SCAN_FLAG_USE_OPTICAL_RES) + if (params.flags & SCAN_FLAG_USE_OPTICAL_RES) { used_res = optical_res; } else { /* resolution is choosen from a list */ - used_res = xres; + used_res = params.xres; } /* compute scan parameters values */ @@ -1194,28 +1180,28 @@ gl847_init_scan_regs (Genesys_Device * dev, /* use detected left margin and fixed value */ /* start */ /* add x coordinates */ - start = startx; + start = params.startx; if (stagger > 0) start |= 1; /* compute correct pixels number */ /* pixels */ - used_pixels = (pixels * optical_res) / xres; + used_pixels = (params.pixels * optical_res) / params.xres; /* round up pixels number if needed */ - if (used_pixels * xres < pixels * optical_res) + if (used_pixels * params.xres < params.pixels * optical_res) used_pixels++; - dummy = 3-channels; + dummy = 3-params.channels; /* slope_dpi */ /* cis color scan is effectively a gray scan with 3 gray lines per color line and a FILTER of 0 */ if (dev->model->is_cis) - slope_dpi = yres * channels; + slope_dpi = params.yres * params.channels; else - slope_dpi = yres; + slope_dpi = params.yres; slope_dpi = slope_dpi * (1 + dummy); @@ -1228,20 +1214,19 @@ gl847_init_scan_regs (Genesys_Device * dev, /*** optical parameters ***/ /* in case of dynamic lineart, we use an internal 8 bit gray scan * to generate 1 lineart data */ - if ((flags & SCAN_FLAG_DYNAMIC_LINEART) && (dev->settings.scan_mode == SCAN_MODE_LINEART)) - { - depth = 8; + if (params.flags & SCAN_FLAG_DYNAMIC_LINEART) { + params.depth = 8; } /* we enable true gray for cis scanners only, and just when doing * scan since color calibration is OK for this mode */ oflags = 0; - if(flags & SCAN_FLAG_DISABLE_SHADING) + if(params.flags & SCAN_FLAG_DISABLE_SHADING) oflags |= OPTICAL_FLAG_DISABLE_SHADING; - if(flags & SCAN_FLAG_DISABLE_GAMMA) + if(params.flags & SCAN_FLAG_DISABLE_GAMMA) oflags |= OPTICAL_FLAG_DISABLE_GAMMA; - if(flags & SCAN_FLAG_DISABLE_LAMP) + if(params.flags & SCAN_FLAG_DISABLE_LAMP) oflags |= OPTICAL_FLAG_DISABLE_LAMP; if (dev->model->is_cis && dev->settings.true_gray) @@ -1255,10 +1240,10 @@ gl847_init_scan_regs (Genesys_Device * dev, used_res, start, used_pixels, - channels, - depth, + params.channels, + params.depth, half_ccd, - color_filter, + params.color_filter, oflags); if (status != SANE_STATUS_GOOD) @@ -1267,19 +1252,19 @@ gl847_init_scan_regs (Genesys_Device * dev, /*** motor parameters ***/ /* max_shift */ - max_shift=sanei_genesys_compute_max_shift(dev,channels,yres,flags); + max_shift=sanei_genesys_compute_max_shift(dev,params.channels,params.yres,params.flags); /* lincnt */ - lincnt = lines + max_shift + stagger; + lincnt = params.lines + max_shift + stagger; /* add tl_y to base movement */ - move = starty; + move = params.starty; DBG(DBG_info, "%s: move=%d steps\n", __func__, move); mflags=0; - if(flags & SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE) + if(params.flags & SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE) mflags |= MOTOR_FLAG_DISABLE_BUFFER_FULL_MOVE; - if(flags & SCAN_FLAG_FEEDING) + if(params.flags & SCAN_FLAG_FEEDING) mflags |= MOTOR_FLAG_FEED; status = gl847_init_motor_regs_scan (dev, sensor, @@ -1288,7 +1273,7 @@ gl847_init_scan_regs (Genesys_Device * dev, slope_dpi, scan_step_type, dev->model->is_cis ? lincnt * - channels : lincnt, dummy, move, + params.channels : lincnt, dummy, move, scan_power_mode, mflags); @@ -1300,13 +1285,13 @@ gl847_init_scan_regs (Genesys_Device * dev, /* words_per_line */ bytes_per_line = (used_pixels * used_res) / optical_res; - bytes_per_line = (bytes_per_line * channels * depth) / 8; + bytes_per_line = (bytes_per_line * params.channels * params.depth) / 8; requested_buffer_size = 8 * bytes_per_line; read_buffer_size = 2 * requested_buffer_size + - ((max_shift + stagger) * used_pixels * channels * depth) / 8; + ((max_shift + stagger) * used_pixels * params.channels * params.depth) / 8; dev->read_buffer.clear(); dev->read_buffer.alloc(read_buffer_size); @@ -1318,21 +1303,21 @@ gl847_init_scan_regs (Genesys_Device * dev, dev->shrink_buffer.alloc(requested_buffer_size); dev->out_buffer.clear(); - dev->out_buffer.alloc((8 * dev->settings.pixels * channels * depth) / 8); + dev->out_buffer.alloc((8 * params.pixels * params.channels * params.depth) / 8); dev->read_bytes_left = bytes_per_line * lincnt; DBG(DBG_info, "%s: physical bytes to read = %lu\n", __func__, (u_long) dev->read_bytes_left); dev->read_active = SANE_TRUE; - + dev->current_setup.params = params; dev->current_setup.pixels = (used_pixels * used_res) / optical_res; dev->current_setup.lines = lincnt; - dev->current_setup.depth = depth; - dev->current_setup.channels = channels; + dev->current_setup.depth = params.depth; + dev->current_setup.channels = params.channels; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = used_res; - dev->current_setup.yres = yres; + dev->current_setup.yres = params.yres; dev->current_setup.ccd_size_divisor = half_ccd ? 2 : 1; dev->current_setup.stagger = stagger; dev->current_setup.max_shift = max_shift + stagger; @@ -1341,7 +1326,7 @@ gl847_init_scan_regs (Genesys_Device * dev, /* scan bytes to send to the frontend */ /* theory : target_size = - (dev->settings.pixels * dev->settings.lines * channels * depth) / 8; + (params.pixels * params.lines * channels * depth) / 8; but it suffers from integer overflow so we do the following: 1 bit color images store color data byte-wise, eg byte 0 contains @@ -1353,14 +1338,14 @@ gl847_init_scan_regs (Genesys_Device * dev, */ dev->total_bytes_read = 0; - if (depth == 1) + if (params.depth == 1) dev->total_bytes_to_read = - ((dev->settings.pixels * dev->settings.lines) / 8 + - (((dev->settings.pixels * dev->settings.lines) % 8) ? 1 : 0)) * - channels; + ((params.pixels * params.lines) / 8 + + (((params.pixels * params.lines) % 8) ? 1 : 0)) * + params.channels; else dev->total_bytes_to_read = - dev->settings.pixels * dev->settings.lines * channels * (depth / 8); + params.pixels * params.lines * params.channels * (params.depth / 8); DBG(DBG_info, "%s: total bytes to send = %lu\n", __func__, (u_long) dev->total_bytes_to_read); /* END TODO */ @@ -1376,12 +1361,6 @@ gl847_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor int depth; int start; - float xres; /*dpi */ - float yres; /*dpi */ - float startx; /*optical_res, from dummy_pixel+1 */ - float pixels; - float lines; - int used_res; int used_pixels; unsigned int lincnt; @@ -1395,24 +1374,18 @@ gl847_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor SANE_Bool half_ccd; /* false: full CCD res is used, true, half max CCD res is used */ int optical_res; - DBG(DBG_info, "%s settings:\n" - "Resolution: %uDPI\n" - "Lines : %u\n" - "PPL : %u\n" - "Startpos : %.3f/%.3f\n" - "Scan mode : %d\n\n", __func__, - dev->settings.yres, dev->settings.lines, dev->settings.pixels, - dev->settings.tl_x, dev->settings.tl_y, dev->settings.scan_mode); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, dev->settings); /* channels */ - if (dev->settings.scan_mode == 4) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; else channels = 1; /* depth */ depth = dev->settings.depth; - if (dev->settings.scan_mode == 0) + if (dev->settings.scan_mode == ScanColorMode::LINEART) depth = 1; /* start */ @@ -1420,24 +1393,26 @@ gl847_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor start += dev->settings.tl_x; start = (start * sensor.optical_res) / MM_PER_INCH; + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = start; // not used + params.starty = 0; // not used + params.pixels = dev->settings.pixels; + params.lines = dev->settings.lines; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = 0; - xres = dev->settings.xres; /*dpi */ - yres = dev->settings.yres; /*dpi */ - startx = start; /*optical_res, from dummy_pixel+1 */ - pixels = dev->settings.pixels; - lines = dev->settings.lines; - - DBG(DBG_info, "%s settings:\n" - "Resolution : %gDPI/%gDPI\n" - "Lines : %g\n" - "PPL : %g\n" - "Startpos : %g\n" - "Depth/Channels: %u/%u\n\n", - __func__, xres, yres, lines, pixels, startx, depth, channels); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, params); /* half_ccd */ /* we have 2 domains for ccd: xres below or above half ccd max dpi */ - if (sensor.get_ccd_size_divisor_for_dpi(xres) > 1) { + if (sensor.get_ccd_size_divisor_for_dpi(params.xres) > 1) { half_ccd = SANE_TRUE; } else { half_ccd = SANE_FALSE; @@ -1448,29 +1423,30 @@ gl847_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor /* stagger */ if (dev->model->flags & GENESYS_FLAG_STAGGERED_LINE) - stagger = (4 * yres) / dev->motor.base_ydpi; + stagger = (4 * params.yres) / dev->motor.base_ydpi; else stagger = 0; DBG(DBG_info, "%s: stagger=%d lines\n", __func__, stagger); /* resolution is choosen from a fixed list */ - used_res = xres; + used_res = params.xres; /* compute scan parameters values */ /* pixels are allways given at half or full CCD optical resolution */ /* use detected left margin and fixed value */ /* compute correct pixels number */ - used_pixels = (pixels * optical_res) / used_res; - dummy = 3-channels; + used_pixels = (params.pixels * optical_res) / used_res; + dummy = 3 - params.channels; /* slope_dpi */ /* cis color scan is effectively a gray scan with 3 gray lines per color line and a FILTER of 0 */ - if (dev->model->is_cis) - slope_dpi = yres * channels; - else - slope_dpi = yres; + if (dev->model->is_cis) { + slope_dpi = params.yres * params.channels; + } else { + slope_dpi = params.yres; + } slope_dpi = slope_dpi * (1 + dummy); @@ -1478,18 +1454,19 @@ gl847_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor DBG(DBG_info, "%s : exposure_time=%d pixels\n", __func__, exposure_time); /* max_shift */ - max_shift=sanei_genesys_compute_max_shift(dev,channels,yres,0); + max_shift = sanei_genesys_compute_max_shift(dev, params.channels, params.yres, 0); /* lincnt */ - lincnt = lines + max_shift + stagger; + lincnt = params.lines + max_shift + stagger; + dev->current_setup.params = params; dev->current_setup.pixels = (used_pixels * used_res) / optical_res; dev->current_setup.lines = lincnt; - dev->current_setup.depth = depth; - dev->current_setup.channels = channels; + dev->current_setup.depth = params.depth; + dev->current_setup.channels = params.channels; dev->current_setup.exposure_time = exposure_time; dev->current_setup.xres = used_res; - dev->current_setup.yres = yres; + dev->current_setup.yres = params.yres; dev->current_setup.ccd_size_divisor = half_ccd ? 2 : 1; dev->current_setup.stagger = stagger; dev->current_setup.max_shift = max_shift + stagger; @@ -1498,46 +1475,6 @@ gl847_calculate_current_setup(Genesys_Device * dev, const Genesys_Sensor& sensor return SANE_STATUS_GOOD; } -static void -gl847_set_motor_power (Genesys_Register_Set * regs, SANE_Bool set) -{ - - DBG(DBG_proc, "%s\n", __func__); - - if (set) - { - sanei_genesys_set_reg_from_set (regs, REG02, - sanei_genesys_read_reg_from_set (regs, - REG02) - | REG02_MTRPWR); - } - else - { - sanei_genesys_set_reg_from_set (regs, REG02, - sanei_genesys_read_reg_from_set (regs, - REG02) - & ~REG02_MTRPWR); - } -} - -static void -gl847_set_lamp_power (Genesys_Device __sane_unused__ * dev, const Genesys_Sensor& /*sensor*/, - Genesys_Register_Set * regs, SANE_Bool set) -{ - if (set) - { - sanei_genesys_set_reg_from_set (regs, REG03, - sanei_genesys_read_reg_from_set (regs, REG03) - | REG03_LAMPPWR); - } - else - { - sanei_genesys_set_reg_from_set (regs, REG03, - sanei_genesys_read_reg_from_set (regs, REG03) - & ~REG03_LAMPPWR); - } -} - /*for fast power saving methods only, like disabling certain amplifiers*/ static SANE_Status gl847_save_power (Genesys_Device * dev, SANE_Bool enable) @@ -1774,7 +1711,7 @@ gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) float resolution; uint8_t val; int loop = 0; - int scan_mode; + ScanColorMode scan_mode; DBG(DBG_proc, "%s (wait_until_home = %d)\n", __func__, wait_until_home); @@ -1822,22 +1759,27 @@ gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) const auto& sensor = sanei_genesys_find_sensor_any(dev); /* TODO add scan_mode to the API */ - scan_mode= dev->settings.scan_mode; - dev->settings.scan_mode=SCAN_MODE_LINEART; - status = gl847_init_scan_regs (dev, sensor, - &local_reg, - resolution, - resolution, - 100, - 30000, - 100, - 100, - 8, - 1, - 0, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + scan_mode = dev->settings.scan_mode; + dev->settings.scan_mode = ScanColorMode::LINEART; + + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 100; + params.starty = 30000; + params.pixels = 100; + params.lines = 100; + params.depth = 8; + params.channels = 1; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::GRAY; + params.color_filter = ColorFilter::RED; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl847_init_scan_regs(dev, sensor, &local_reg, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to set up registers: %s\n", __func__, sane_strstatus(status)); @@ -1845,7 +1787,7 @@ gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) return status; } - dev->settings.scan_mode=scan_mode; + dev->settings.scan_mode = scan_mode; /* clear scan and feed count */ RIE (sanei_genesys_write_register (dev, REG0D, REG0D_CLRLNCNT | REG0D_CLRMCNT)); @@ -1928,11 +1870,24 @@ gl847_search_start_position (Genesys_Device * dev) // whith employ different sensors with potentially different settings. auto& sensor = sanei_genesys_find_sensor_for_write(dev, dpi); - status = gl847_init_scan_regs (dev, sensor, &local_reg, dpi, dpi, 0, 0, /*we should give a small offset here~60 steps */ - 600, dev->model->search_lines, 8, 1, 1, /*green */ - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + SetupParams params; + params.xres = dpi; + params.yres = dpi; + params.startx = 0; + params.starty = 0; /*we should give a small offset here~60 steps */ + params.pixels = 600; + params.lines = dev->model->search_lines; + params.depth = 8; + params.channels = 1; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::GRAY; + params.color_filter = ColorFilter::GREEN; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl847_init_scan_regs(dev, sensor, &local_reg, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to set up registers: %s\n", __func__, sane_strstatus(status)); @@ -2006,7 +1961,8 @@ gl847_search_start_position (Genesys_Device * dev) * sets up register for coarse gain calibration * todo: check it for scanners using it */ static SANE_Status -gl847_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl847_init_regs_for_coarse_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status; uint8_t channels; @@ -2015,29 +1971,34 @@ gl847_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sens DBG(DBG_proc, "%s\n", __func__); - cksel = (dev->calib_reg.find_reg(0x18).value & REG18_CKSEL) + 1; /* clock speed = 1..4 clocks */ + cksel = (regs.find_reg(0x18).value & REG18_CKSEL) + 1; /* clock speed = 1..4 clocks */ /* set line size */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; - else + else { channels = 1; + } + + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = 0; + params.starty = 0; + params.pixels = sensor.optical_res / cksel; + params.lines = 20; + params.depth = 16; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl847_init_scan_regs(dev, sensor, ®s, params); - status = gl847_init_scan_regs (dev, sensor, - &dev->calib_reg, - dev->settings.xres, - dev->settings.yres, - 0, - 0, - sensor.optical_res / cksel, - 20, - 16, - channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: Failed to setup scan: %s\n", __func__, sane_strstatus(status)); @@ -2048,7 +2009,7 @@ gl847_init_regs_for_coarse_calibration (Genesys_Device * dev, const Genesys_Sens sensor.optical_res / cksel, dev->settings.xres); status = - dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg); + dev->model->cmd_set->bulk_write_register(dev, regs); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: Failed to bulk write registers: %s\n", __func__, sane_strstatus(status)); @@ -2079,21 +2040,26 @@ gl847_feed (Genesys_Device * dev, unsigned int steps) resolution=sanei_genesys_get_lowest_ydpi(dev); const auto& sensor = sanei_genesys_find_sensor(dev, resolution); - status = gl847_init_scan_regs (dev, sensor, - &local_reg, - resolution, - resolution, - 0, - steps, - 100, - 3, - 8, - 3, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_FEEDING | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 0; + params.starty = steps; + params.pixels = 100; + params.lines = 3; + params.depth = 8; + params.channels = 3; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_FEEDING | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl847_init_scan_regs(dev, sensor, &local_reg, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to set up registers: %s\n", __func__, sane_strstatus(status)); @@ -2146,7 +2112,8 @@ gl847_feed (Genesys_Device * dev, unsigned int steps) /* init registers for shading calibration */ static SANE_Status -gl847_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl847_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status; float move; @@ -2155,7 +2122,7 @@ gl847_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) dev->calib_channels = 3; /* initial calibration reg values */ - dev->calib_reg = dev->reg; + regs = dev->reg; dev->calib_resolution = sanei_genesys_compute_dpihw(dev, sensor, dev->settings.xres); dev->calib_total_bytes_to_read = 0; @@ -2174,21 +2141,24 @@ gl847_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) move=40; } - status = gl847_init_scan_regs (dev, sensor, - &dev->calib_reg, - dev->calib_resolution, - dev->calib_resolution, - 0, - move, - dev->calib_pixels, - dev->calib_lines, - 16, - dev->calib_channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + SetupParams params; + params.xres = dev->calib_resolution; + params.yres = dev->calib_resolution; + params.startx = 0; + params.starty = move; + params.pixels = dev->calib_pixels; + params.lines = dev->calib_lines; + params.depth = 16; + params.channels = dev->calib_channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl847_init_scan_regs(dev, sensor, ®s, params); if (status != SANE_STATUS_GOOD) { @@ -2196,7 +2166,7 @@ gl847_init_regs_for_shading (Genesys_Device * dev, const Genesys_Sensor& sensor) return status; } - status = dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg); + status = dev->model->cmd_set->bulk_write_register(dev, regs); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to bulk write registers: %s\n", __func__, sane_strstatus(status)); @@ -2224,20 +2194,18 @@ gl847_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) SANE_Status status; - DBG(DBG_info, "%s settings:\nResolution: %uDPI\n" - "Lines : %u\nPPL : %u\nStartpos : %.3f/%.3f\nScan mode : %d\n\n", __func__, - dev->settings.yres, dev->settings.lines, dev->settings.pixels, - dev->settings.tl_x, dev->settings.tl_y, dev->settings.scan_mode); + DBG(DBG_info, "%s ", __func__); + debug_dump(DBG_info, dev->settings); /* channels */ - if (dev->settings.scan_mode == SCAN_MODE_COLOR) /* single pass color */ + if (dev->settings.scan_mode == ScanColorMode::COLOR_SINGLE_PASS) channels = 3; else channels = 1; /* depth */ depth = dev->settings.depth; - if (dev->settings.scan_mode == SCAN_MODE_LINEART) + if (dev->settings.scan_mode == ScanColorMode::LINEART) depth = 1; @@ -2295,7 +2263,7 @@ gl847_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) flags = 0; /* emulated lineart from gray data is required for now */ - if(dev->settings.scan_mode == SCAN_MODE_LINEART + if(dev->settings.scan_mode == ScanColorMode::LINEART && dev->settings.dynamic_lineart) { flags |= SCAN_FLAG_DYNAMIC_LINEART; @@ -2304,18 +2272,21 @@ gl847_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor) /* backtracking isn't handled well, so don't enable it */ flags |= SCAN_FLAG_DISABLE_BUFFER_FULL_MOVE; - status = gl847_init_scan_regs (dev, sensor, - &dev->reg, - dev->settings.xres, - dev->settings.yres, - start, - move, - dev->settings.pixels, - dev->settings.lines, - depth, - channels, - dev->settings.color_filter, - flags); + SetupParams params; + params.xres = dev->settings.xres; + params.yres = dev->settings.yres; + params.startx = start; + params.starty = move; + params.pixels = dev->settings.pixels; + params.lines = dev->settings.lines; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = dev->settings.scan_mode; + params.color_filter = dev->settings.color_filter; + params.flags = flags; + + status = gl847_init_scan_regs(dev, sensor, &dev->reg, params); if (status != SANE_STATUS_GOOD) return status; @@ -2435,7 +2406,7 @@ gl847_send_shading_data (Genesys_Device * dev, const Genesys_Sensor& sensor, * @param dev device to calibrate */ static SANE_Status -gl847_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) +gl847_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor, Genesys_Register_Set& regs) { int num_pixels; int total_size; @@ -2468,24 +2439,27 @@ gl847_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) num_pixels = (sensor.sensor_pixels*used_res)/sensor.optical_res; /* initial calibration reg values */ - dev->calib_reg = dev->reg; + regs = dev->reg; + + SetupParams params; + params.xres = used_res; + params.yres = used_res; + params.startx = 0; + params.starty = 0; + params.pixels = num_pixels; + params.lines = 1; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl847_init_scan_regs(dev, sensor, ®s, params); - /* set up for the calibration scan */ - status = gl847_init_scan_regs (dev, sensor, - &dev->calib_reg, - used_res, - used_res, - 0, - 0, - num_pixels, - 1, - depth, - channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus(status)); @@ -2511,19 +2485,19 @@ gl847_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor) turn = 0; /* no move during led calibration */ - gl847_set_motor_power(&dev->calib_reg, SANE_FALSE); + sanei_genesys_set_motor_power(regs, false); do { /* set up exposure */ - sanei_genesys_set_double(&dev->calib_reg,REG_EXPR,exp[0]); - sanei_genesys_set_double(&dev->calib_reg,REG_EXPG,exp[1]); - sanei_genesys_set_double(&dev->calib_reg,REG_EXPB,exp[2]); + sanei_genesys_set_double(®s,REG_EXPR,exp[0]); + sanei_genesys_set_double(®s,REG_EXPG,exp[1]); + sanei_genesys_set_double(®s,REG_EXPB,exp[2]); /* write registers and scan data */ - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting line reading\n", __func__); - RIE(gl847_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl847_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, line.data(), total_size)); /* stop scanning */ @@ -2832,14 +2806,10 @@ gl847_update_hardware_sensors (Genesys_Scanner * s) } RIE (sanei_genesys_read_register (s->dev, REG6D, &val)); - if (s->val[OPT_SCAN_SW].b == s->last_val[OPT_SCAN_SW].b) - s->val[OPT_SCAN_SW].b = (val & scan) == 0; - if (s->val[OPT_FILE_SW].b == s->last_val[OPT_FILE_SW].b) - s->val[OPT_FILE_SW].b = (val & file) == 0; - if (s->val[OPT_EMAIL_SW].b == s->last_val[OPT_EMAIL_SW].b) - s->val[OPT_EMAIL_SW].b = (val & email) == 0; - if (s->val[OPT_COPY_SW].b == s->last_val[OPT_COPY_SW].b) - s->val[OPT_COPY_SW].b = (val & copy) == 0; + s->buttons[BUTTON_SCAN_SW].write((val & scan) == 0); + s->buttons[BUTTON_FILE_SW].write((val & file) == 0); + s->buttons[BUTTON_EMAIL_SW].write((val & email) == 0); + s->buttons[BUTTON_COPY_SW].write((val & copy) == 0); return status; } @@ -2896,19 +2866,23 @@ gl847_search_strip (Genesys_Device * dev, const Genesys_Sensor& sensor, local_reg = dev->reg; - status = gl847_init_scan_regs (dev, sensor, - &local_reg, - dpi, - dpi, - 0, - 0, - pixels, - lines, - depth, - channels, - 0, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA); + SetupParams params; + params.xres = dpi; + params.yres = dpi; + params.startx = 0; + params.starty = 0; + params.pixels = pixels; + params.lines = lines; + params.depth = depth; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::GRAY; + params.color_filter = ColorFilter::RED; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA; + + status = gl847_init_scan_regs(dev, sensor, &local_reg, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup for scan: %s\n", __func__, sane_strstatus(status)); @@ -3144,7 +3118,8 @@ dark_average (uint8_t * data, unsigned int pixels, unsigned int lines, } static SANE_Status -gl847_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) +gl847_offset_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs) { SANE_Status status = SANE_STATUS_GOOD; uint8_t reg04; @@ -3173,27 +3148,31 @@ gl847_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) black_pixels = (sensor.black_pixels * resolution) / sensor.optical_res; DBG(DBG_io2, "%s: black_pixels=%d\n", __func__, black_pixels); - status = gl847_init_scan_regs (dev, sensor, - &dev->calib_reg, - resolution, - resolution, - 0, - 0, - pixels, - lines, - bpp, - channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 0; + params.starty = 0; + params.pixels = pixels; + params.lines = lines; + params.depth = bpp; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl847_init_scan_regs(dev, sensor, ®s, params); + if (status != SANE_STATUS_GOOD) { DBG(DBG_error, "%s: failed to setup scan: %s\n", __func__, sane_strstatus(status)); return status; } - gl847_set_motor_power(&dev->calib_reg, SANE_FALSE); + sanei_genesys_set_motor_power(regs, false); /* allocate memory for scans */ total_size = pixels * channels * lines * (bpp/8); /* colors * bytes_per_color * scan lines */ @@ -3213,9 +3192,9 @@ gl847_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) dev->frontend.set_offset(2, bottom); RIE(gl847_set_fe(dev, sensor, AFE_SET)); - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting first line reading\n", __func__); - RIE(gl847_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl847_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, first_line.data(), total_size)); if (DBG_LEVEL >= DBG_data) { @@ -3233,9 +3212,9 @@ gl847_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) dev->frontend.set_offset(1, top); dev->frontend.set_offset(2, top); RIE(gl847_set_fe(dev, sensor, AFE_SET)); - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting second line reading\n", __func__); - RIE(gl847_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl847_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner (dev, second_line.data(), total_size)); topavg = dark_average(second_line.data(), pixels, lines, channels, black_pixels); @@ -3253,9 +3232,9 @@ gl847_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) /* scan with no move */ RIE(gl847_set_fe(dev, sensor, AFE_SET)); - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); DBG(DBG_info, "%s: starting second line reading\n", __func__); - RIE(gl847_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl847_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner (dev, second_line.data(), total_size)); if (DBG_LEVEL >= DBG_data) @@ -3290,7 +3269,8 @@ gl847_offset_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor) } static SANE_Status -gl847_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor, int dpi) +gl847_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs, int dpi) { int pixels; int total_size; @@ -3332,22 +3312,26 @@ gl847_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso bpp=8; pixels = (sensor.sensor_pixels * resolution) / sensor.optical_res; - status = gl847_init_scan_regs (dev, sensor, - &dev->calib_reg, - resolution, - resolution, - 0, - 0, - pixels, - lines, - bpp, - channels, - dev->settings.color_filter, - SCAN_FLAG_DISABLE_SHADING | - SCAN_FLAG_DISABLE_GAMMA | - SCAN_FLAG_SINGLE_LINE | - SCAN_FLAG_IGNORE_LINE_DISTANCE); - gl847_set_motor_power(&dev->calib_reg, SANE_FALSE); + SetupParams params; + params.xres = resolution; + params.yres = resolution; + params.startx = 0; + params.starty = 0; + params.pixels = pixels; + params.lines = lines; + params.depth = bpp; + params.channels = channels; + params.scan_method = dev->settings.scan_method; + params.scan_mode = ScanColorMode::COLOR_SINGLE_PASS; + params.color_filter = dev->settings.color_filter; + params.flags = SCAN_FLAG_DISABLE_SHADING | + SCAN_FLAG_DISABLE_GAMMA | + SCAN_FLAG_SINGLE_LINE | + SCAN_FLAG_IGNORE_LINE_DISTANCE; + + status = gl847_init_scan_regs(dev, sensor, ®s, params); + + sanei_genesys_set_motor_power(regs, false); if (status != SANE_STATUS_GOOD) { @@ -3355,14 +3339,14 @@ gl847_coarse_gain_calibration (Genesys_Device * dev, const Genesys_Sensor& senso return status; } - RIE(dev->model->cmd_set->bulk_write_register(dev, dev->calib_reg)); + RIE(dev->model->cmd_set->bulk_write_register(dev, regs)); total_size = pixels * channels * (16/bpp) * lines; std::vector line(total_size); RIE(gl847_set_fe(dev, sensor, AFE_SET)); - RIE(gl847_begin_scan(dev, sensor, &dev->calib_reg, SANE_TRUE)); + RIE(gl847_begin_scan(dev, sensor, ®s, SANE_TRUE)); RIE(sanei_genesys_read_data_from_scanner(dev, line.data(), total_size)); if (DBG_LEVEL >= DBG_data) @@ -3460,9 +3444,6 @@ static Genesys_Command_Set gl847_cmd_set = { gl847_set_powersaving, gl847_save_power, - gl847_set_motor_power, - gl847_set_lamp_power, - gl847_begin_scan, gl847_end_scan, @@ -3492,8 +3473,7 @@ static Genesys_Command_Set gl847_cmd_set = { NULL, gl847_send_shading_data, gl847_calculate_current_setup, - gl847_boot, - NULL + gl847_boot }; SANE_Status diff --git a/backend/genesys_gl847.h b/backend/genesys_gl847.h index 0128548a4..7af9c362a 100644 --- a/backend/genesys_gl847.h +++ b/backend/genesys_gl847.h @@ -326,19 +326,8 @@ * * this function sets up the scanner to scan in normal or single line mode */ -static SANE_Status gl847_init_scan_regs (Genesys_Device * dev, - const Genesys_Sensor& sensor, - Genesys_Register_Set * reg, - float xres, /*dpi */ - float yres, /*dpi */ - float startx, /*optical_res, from dummy_pixel+1 */ - float starty, /*base_ydpi, from home! */ - float pixels, - float lines, - unsigned int depth, - unsigned int channels, - int color_filter, - unsigned int flags); +static SANE_Status gl847_init_scan_regs(Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set * reg, SetupParams& params); /* Send the low-level scan command */ static SANE_Status gl847_begin_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, diff --git a/backend/genesys_low.cc b/backend/genesys_low.cc index 2c2c6ae83..647905723 100644 --- a/backend/genesys_low.cc +++ b/backend/genesys_low.cc @@ -1070,6 +1070,50 @@ sanei_genesys_read_feed_steps (Genesys_Device * dev, unsigned int *steps) return SANE_STATUS_GOOD; } +void sanei_genesys_set_lamp_power(Genesys_Device* dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs, bool set) +{ + static const uint8_t REG03_LAMPPWR = 0x10; + + if (set) { + regs.find_reg(0x03).value |= REG03_LAMPPWR; + + if (dev->model->asic_type == GENESYS_GL841) { + sanei_genesys_set_exposure(regs, sanei_genesys_fixup_exposure(sensor.exposure)); + regs.set8(0x19, 0x50); + } + + if (dev->model->asic_type == GENESYS_GL843) { + sanei_genesys_set_exposure(regs, sensor.exposure); + } + } else { + regs.find_reg(0x03).value &= ~REG03_LAMPPWR; + + if (dev->model->asic_type == GENESYS_GL841) { + sanei_genesys_set_exposure(regs, {0x0101, 0x0101, 0x0101}); + regs.set8(0x19, 0xff); + } + + if (dev->model->asic_type == GENESYS_GL843) { + if (dev->model->model_id != MODEL_CANON_CANOSCAN_8600F) { + // BUG: datasheet says we shouldn't set exposure to zero + sanei_genesys_set_exposure(regs, {0, 0, 0}); + } + } + } + regs.state.is_lamp_on = set; +} + +void sanei_genesys_set_motor_power(Genesys_Register_Set& regs, bool set) +{ + static const uint8_t REG02_MTRPWR = 0x10; + + if (set) { + regs.find_reg(0x02).value |= REG02_MTRPWR; + } else { + regs.find_reg(0x02).value &= ~REG02_MTRPWR; + } +} /** * Write to many registers at once @@ -1440,7 +1484,7 @@ sanei_genesys_asic_init(Genesys_Device* dev, int /*max_regs*/) dev->white_average_data.clear(); dev->dark_average_data.clear(); - dev->settings.color_filter = 0; + dev->settings.color_filter = ColorFilter::RED; /* duplicate initial values into calibration registers */ dev->calib_reg = dev->reg; @@ -1853,7 +1897,6 @@ sanei_genesys_is_compatible_calibration (Genesys_Device * dev, sane_strstatus (status)); return status; } - dev->current_setup.scan_method = dev->settings.scan_method; DBG (DBG_proc, "%s: checking\n", __func__); @@ -1880,10 +1923,11 @@ sanei_genesys_is_compatible_calibration (Genesys_Device * dev, dev->current_setup.ccd_size_divisor, cache->used_setup.ccd_size_divisor); compatible = 0; } - if (dev->current_setup.scan_method != cache->used_setup.scan_method) + if (dev->current_setup.params.scan_method != cache->used_setup.params.scan_method) { DBG (DBG_io, "%s: current method=%d, used=%d\n", __func__, - dev->current_setup.scan_method, cache->used_setup.scan_method); + static_cast(dev->current_setup.params.scan_method), + static_cast(cache->used_setup.params.scan_method)); compatible = 0; } if (!compatible) @@ -1900,7 +1944,7 @@ sanei_genesys_is_compatible_calibration (Genesys_Device * dev, gettimeofday (&time, NULL); if ((time.tv_sec - cache->last_calibration > dev->settings.expiration_time*60) && (dev->model->is_sheetfed == SANE_FALSE) - && (dev->settings.scan_method == SCAN_METHOD_FLATBED)) + && (dev->settings.scan_method == ScanMethod::FLATBED)) { DBG (DBG_proc, "%s: expired entry, non compatible cache\n", __func__); return SANE_STATUS_UNSUPPORTED; @@ -2080,3 +2124,39 @@ void run_functions_at_backend_exit() } s_functions_run_at_backend_exit.release(); } + +void debug_dump(unsigned level, const Genesys_Settings& settings) +{ + DBG(level, "settings:\n" + "Resolution X/Y : %u / %u dpi\n" + "Lines : %u\n" + "Pixels per line : %u\n" + "Depth : %u\n" + "Start position X/Y : %.3f/%.3f\n" + "Scan mode : %d\n\n", + settings.xres, settings.yres, + settings.lines, settings.pixels, settings.depth, + settings.tl_x, settings.tl_y, + static_cast(settings.scan_mode)); +} + +void debug_dump(unsigned level, const SetupParams& params) +{ + DBG(level, "settings:\n" + "Resolution X/Y : %u / %u dpi\n" + "Lines : %u\n" + "Pixels per line : %u\n" + "Depth : %u\n" + "Channels : %u\n" + "Start position X/Y : %g / %g\n" + "Scan mode : %d\n" + "Color filter : %d\n" + "Flags : %x\n", + params.xres, params.yres, + params.lines, params.pixels, + params.depth, params.channels, + params.startx, params.starty, + static_cast(params.scan_mode), + static_cast(params.color_filter), + params.flags); +} diff --git a/backend/genesys_low.h b/backend/genesys_low.h index 573fa9edc..dde71f625 100644 --- a/backend/genesys_low.h +++ b/backend/genesys_low.h @@ -85,6 +85,7 @@ #include #include #include +#include #include #include #include @@ -151,6 +152,8 @@ #define GENESYS_FLAG_SHADING_NO_MOVE (1 << 17) /**< scanner doesn't move sensor during shading calibration */ #define GENESYS_FLAG_SHADING_REPARK (1 << 18) /**< repark head between shading scans */ #define GENESYS_FLAG_FULL_HWDPI_MODE (1 << 19) /**< scanner always use maximum hw dpi to setup the sensor */ +// scanner has infrared transparency scanning capability +#define GENESYS_FLAG_HAS_UTA_INFRARED (1 << 20) #define GENESYS_HAS_NO_BUTTONS 0 /**< scanner has no supported button */ #define GENESYS_HAS_SCAN_SW (1 << 0) /**< scanner has SCAN button */ @@ -218,6 +221,29 @@ #define GENESYS_MAX_REGS 256 +enum class ScanMethod : unsigned { + // normal scan method + FLATBED = 0, + // scan using transparency adaptor + TRANSPARENCY = 1, + // scan using transparency adaptor via infrared channel + TRANSPARENCY_INFRARED = 2 +}; + +enum class ScanColorMode : unsigned { + LINEART = 0, + HALFTONE, + GRAY, + COLOR_SINGLE_PASS +}; + +enum class ColorFilter : unsigned { + RED = 0, + GREEN, + BLUE, + NONE +}; + struct GenesysRegister { uint16_t address = 0; uint8_t value = 0; @@ -228,12 +254,20 @@ inline bool operator<(const GenesysRegister& lhs, const GenesysRegister& rhs) return lhs.address < rhs.address; } +struct GenesysRegisterSetState { + bool is_lamp_on = false; + bool is_xpa_on = false; +}; + class Genesys_Register_Set { public: using container = std::vector; using iterator = typename container::iterator; using const_iterator = typename container::const_iterator; + // FIXME: this shouldn't live here, but in a separate struct that contains Genesys_Register_Set + GenesysRegisterSetState state; + enum Options { SEQUENTIAL = 1 }; @@ -559,8 +593,8 @@ struct Genesys_Sensor { int min_resolution = -1; int max_resolution = -1; - // whether the sensor is transparency sensor. - bool is_transparency = false; + // the scan method used with the sensor + ScanMethod method = ScanMethod::FLATBED; // CCD may present itself as half or quarter-size CCD on certain resolutions int ccd_size_divisor = 1; @@ -930,8 +964,10 @@ typedef struct Genesys_Command_Set Genesys_Register_Set * regs, int *channels, int *total_size); SANE_Status (*init_regs_for_coarse_calibration) (Genesys_Device * dev, - const Genesys_Sensor& sensor); - SANE_Status (*init_regs_for_shading) (Genesys_Device * dev, const Genesys_Sensor& sensor); + const Genesys_Sensor& sensor, + Genesys_Register_Set& regs); + SANE_Status (*init_regs_for_shading) (Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs); SANE_Status (*init_regs_for_scan) (Genesys_Device * dev, const Genesys_Sensor& sensor); SANE_Bool (*get_filter_bit) (Genesys_Register_Set * reg); @@ -947,11 +983,6 @@ typedef struct Genesys_Command_Set SANE_Status (*set_powersaving) (Genesys_Device * dev, int delay); SANE_Status (*save_power) (Genesys_Device * dev, SANE_Bool enable); - void (*set_motor_power) (Genesys_Register_Set * regs, SANE_Bool set); - void (*set_lamp_power) (Genesys_Device * dev, const Genesys_Sensor& sensor, - Genesys_Register_Set * regs, - SANE_Bool set); - SANE_Status (*begin_scan) (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Register_Set * regs, @@ -966,16 +997,19 @@ typedef struct Genesys_Command_Set SANE_Status (*send_gamma_table) (Genesys_Device * dev, const Genesys_Sensor& sensor); SANE_Status (*search_start_position) (Genesys_Device * dev); - SANE_Status (*offset_calibration) (Genesys_Device * dev, const Genesys_Sensor& sensor); + SANE_Status (*offset_calibration) (Genesys_Device * dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs); SANE_Status (*coarse_gain_calibration) (Genesys_Device * dev, - const Genesys_Sensor& sensor, int dpi); - SANE_Status (*led_calibration) (Genesys_Device * dev, Genesys_Sensor& sensor); + const Genesys_Sensor& sensor, + Genesys_Register_Set& regs, int dpi); + SANE_Status (*led_calibration) (Genesys_Device * dev, Genesys_Sensor& sensor, + Genesys_Register_Set& regs); SANE_Status (*slow_back_home) (Genesys_Device * dev, SANE_Bool wait_until_home); SANE_Status (*rewind) (Genesys_Device * dev); SANE_Status (*bulk_write_register) (Genesys_Device * dev, - Genesys_Register_Set& reg); + Genesys_Register_Set& regs); SANE_Status (*bulk_write_data) (Genesys_Device * dev, uint8_t addr, uint8_t * data, size_t len); @@ -983,13 +1017,7 @@ typedef struct Genesys_Command_Set SANE_Status (*bulk_read_data) (Genesys_Device * dev, uint8_t addr, uint8_t * data, size_t len); - /* Updates hardware sensor information in Genesys_Scanner.val[]. - If possible, just get information for given option. - The sensor state in Genesys_Scanner.val[] should be merged with the - new sensor state, using the information that was last read by the frontend - in Genesys_Scanner.last_val[], in such a way that a button up/down - relative to Genesys_Scanner.last_val[] is not lost. - */ + // Updates hardware sensor information in Genesys_Scanner.val[]. SANE_Status (*update_hardware_sensors) (struct Genesys_Scanner * s); /* functions for sheetfed scanners */ @@ -1041,25 +1069,6 @@ typedef struct Genesys_Command_Set */ SANE_Status (*asic_boot) (Genesys_Device * dev, SANE_Bool cold); - /** - * Scan register setting interface - */ - SANE_Status (*init_scan_regs) (Genesys_Device * dev, - const Genesys_Sensor& sensor, - Genesys_Register_Set * reg, - float xres, - float yres, - float startx, - float starty, - float pixels, - float lines, - unsigned int depth, - unsigned int channels, - int scan_method, - int scan_mode, - int color_filter, - unsigned int flags); - } Genesys_Command_Set; /** @brief structure to describe a scanner model @@ -1124,21 +1133,11 @@ typedef struct Genesys_Model SANE_Int search_lines; /* how many lines are used to search start position */ } Genesys_Model; -#define SCAN_METHOD_FLATBED 0 /**< normal scan method */ -#define SCAN_METHOD_TRANSPARENCY 2 /**< scan using transparency adaptor */ -#define SCAN_METHOD_NEGATIVE 0x88 /**< scan using negative adaptor */ - -#define SCAN_MODE_LINEART 0 /**< lineart scan mode */ -#define SCAN_MODE_HALFTONE 1 /**< halftone scan mode */ -#define SCAN_MODE_GRAY 2 /**< gray scan mode */ -#define SCAN_MODE_COLOR 4 /**< color scan mode */ - struct Genesys_Settings { - // TODO: change >=2: Transparency, 0x88: negative film - int scan_method = 0; - // TODO: change 0,1 = lineart, halftone; 2 = gray, 3 = 3pass color, 4=single pass color - int scan_mode = 0; + ScanMethod scan_method = ScanMethod::FLATBED; + ScanColorMode scan_mode = ScanColorMode::LINEART; + // horizontal dpi int xres = 0; // vertical dpi @@ -1157,10 +1156,7 @@ struct Genesys_Settings // bit depth of the scan unsigned int depth = 0; - /* todo : remove these fields ? */ - int exposure_time = 0; - - unsigned int color_filter = 0; + ColorFilter color_filter = ColorFilter::NONE; // true if scan is true gray, false if monochrome scan int true_gray = 0; @@ -1174,9 +1170,6 @@ struct Genesys_Settings // Disable interpolation for xres::max(); + + // resolution in x direction + unsigned xres = NOT_SET; + // resolution in y direction + unsigned yres = NOT_SET; + // start pixel in X direction, from dummy_pixel + 1 + float startx = -1; + // start pixel in Y direction, counted according to base_ydpi + float starty = -1; + // the number of pixels in X direction + unsigned pixels = NOT_SET; + // the number of pixels in Y direction + unsigned lines = NOT_SET; + // the depth of the scan in bits. Allowed are 1, 8, 16 + unsigned depth = NOT_SET; + // the number of channels + unsigned channels = NOT_SET; + + ScanMethod scan_method = static_cast(NOT_SET); + + ScanColorMode scan_mode = static_cast(NOT_SET); + + ColorFilter color_filter = static_cast(NOT_SET); + + unsigned flags = NOT_SET; + + void assert_valid() const + { + if (xres == NOT_SET || yres == NOT_SET || startx < 0 || starty < 0 || + pixels == NOT_SET || lines == NOT_SET ||depth == NOT_SET || channels == NOT_SET || + scan_method == static_cast(NOT_SET) || + scan_mode == static_cast(NOT_SET) || + color_filter == static_cast(NOT_SET) || + flags == NOT_SET) + { + throw std::runtime_error("SetupParams are not valid"); + } + } +}; + struct Genesys_Current_Setup { + // params used for this setup + SetupParams params; + // pixel count expected from scanner int pixels = 0; // line count expected from scanner @@ -1200,8 +1239,7 @@ struct Genesys_Current_Setup int depth = 0; // channel count expected from scanner int channels = 0; - // scanning method: flatbed or XPA - int scan_method = 0; + // used exposure time int exposure_time = 0; // used xres @@ -1300,8 +1338,6 @@ struct Genesys_Device Genesys_Frontend frontend, frontend_initial; Genesys_Gpo gpo; Genesys_Motor motor; - uint16_t slope_table0[256] = {}; - uint16_t slope_table1[256] = {}; uint8_t control[6] = {}; time_t init_date = 0; @@ -1508,7 +1544,7 @@ sanei_genesys_write_hregister (Genesys_Device * dev, uint16_t reg, uint8_t val); extern SANE_Status sanei_genesys_bulk_write_register(Genesys_Device * dev, - Genesys_Register_Set& reg); + Genesys_Register_Set& regs); extern SANE_Status sanei_genesys_write_0x8c (Genesys_Device * dev, uint8_t index, uint8_t val); @@ -1532,9 +1568,9 @@ extern void sanei_genesys_init_structs (Genesys_Device * dev); const Genesys_Sensor& sanei_genesys_find_sensor_any(Genesys_Device* dev); Genesys_Sensor& sanei_genesys_find_sensor_any_for_write(Genesys_Device* dev); const Genesys_Sensor& sanei_genesys_find_sensor(Genesys_Device* dev, int dpi, - int scan_method = SCAN_METHOD_FLATBED); + ScanMethod scan_method = ScanMethod::FLATBED); Genesys_Sensor& sanei_genesys_find_sensor_for_write(Genesys_Device* dev, int dpi, - int scan_method = SCAN_METHOD_FLATBED); + ScanMethod scan_method = ScanMethod::FLATBED); extern SANE_Status sanei_genesys_init_shading_data (Genesys_Device * dev, const Genesys_Sensor& sensor, @@ -1549,6 +1585,11 @@ extern SANE_Status sanei_genesys_read_scancnt (Genesys_Device * dev, extern SANE_Status sanei_genesys_read_feed_steps (Genesys_Device * dev, unsigned int *steps); +void sanei_genesys_set_lamp_power(Genesys_Device* dev, const Genesys_Sensor& sensor, + Genesys_Register_Set& regs, bool set); + +void sanei_genesys_set_motor_power(Genesys_Register_Set& regs, bool set); + extern void sanei_genesys_calculate_zmode2 (SANE_Bool two_table, uint32_t exposure_time, @@ -1885,4 +1926,7 @@ extern StaticInit> s_sensors; void genesys_init_sensor_tables(); void genesys_init_frontend_tables(); +void debug_dump(unsigned level, const Genesys_Settings& settings); +void debug_dump(unsigned level, const SetupParams& params); + #endif /* not GENESYS_LOW_H */