From: Bastian Dehn Date: Sun, 23 Feb 2025 11:33:43 +0000 (+0100) Subject: change image width to pixel X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=1ecef9cc3dbec339f035f51abc43b9b91fab624e;p=sane-kds-s2000w-net.git change image width to pixel --- diff --git a/src/kds_s2000w_handler_opts.c b/src/kds_s2000w_handler_opts.c index a77d8fa..5f3f4a0 100644 --- a/src/kds_s2000w_handler_opts.c +++ b/src/kds_s2000w_handler_opts.c @@ -11,6 +11,7 @@ #define OFFSET_X_MAX_INCH 75 #define OFFSET_Y_MAX_INCH 390 +#define MAX_IMAGE_WIDTH_INCH 85 void _kds_s2000w_handler_opts_write_string_value(json_object* value_object, void* value) { @@ -150,6 +151,21 @@ void _kds_s2000w_handler_opts_set_offset_y_range(json_object* config) range->quant = kds_s2000w_handler_opts_calc_pixel_quant(dpi); } +void _kds_s2000w_handler_opts_set_image_width_range(json_object* config) +{ + SANE_Option_Descriptor* image_offset_x = kds_s2000w_option_descriptors_get_by_name(SANE_NAME_PAGE_WIDTH); + + json_object* object_value = json_object_object_get(config, "DPI"); + int32_t dpi = json_object_get_int(object_value); + + SANE_Range* range = (SANE_Range*) image_offset_x->constraint.range; + + range->min = 0; + range->max = kds_s2000w_handler_opts_calc_inch_to_pixel(dpi, MAX_IMAGE_WIDTH_INCH); + range->quant = kds_s2000w_handler_opts_calc_pixel_quant(dpi); +} + + void _kds_s2000w_handler_opts_set_enable_suboptions_cropping_image(json_object* config) { json_object* cropping_image = json_object_object_get(config, "CroppingImage");; @@ -157,11 +173,12 @@ void _kds_s2000w_handler_opts_set_enable_suboptions_cropping_image(json_object* SANE_Option_Descriptor* image_offset_x = kds_s2000w_option_descriptors_get_by_name(SANE_NAME_SCAN_TL_X); SANE_Option_Descriptor* image_offset_y = kds_s2000w_option_descriptors_get_by_name(SANE_NAME_SCAN_TL_Y); - SANE_Option_Descriptor* image_width = kds_s2000w_option_descriptors_get_by_name("image-width"); + SANE_Option_Descriptor* image_width = kds_s2000w_option_descriptors_get_by_name(SANE_NAME_PAGE_WIDTH); SANE_Option_Descriptor* image_height = kds_s2000w_option_descriptors_get_by_name("image-height"); _kds_s2000w_handler_opts_set_offset_x_range(config); _kds_s2000w_handler_opts_set_offset_y_range(config); + _kds_s2000w_handler_opts_set_image_width_range(config); if (strcmp(cropping_image_value, "PartialDocument") == 0) { image_offset_x->cap |= SANE_CAP_SOFT_SELECT; @@ -359,12 +376,10 @@ void kds_s2000w_handler_opts_get_option(handler* h, uint32_t option, void* value _kds_s2000w_handler_opts_get_pixel_value_from_inch(config, "ImageOffsetX", value); break; case 10: - value_object = json_object_object_get(config, "ImageOffsetY"); - _kds_s2000w_handler_opts_write_int_value(value_object, value); + _kds_s2000w_handler_opts_get_pixel_value_from_inch(config, "ImageOffsetY", value); break; case 11: - value_object = json_object_object_get(config, "ImageWidth"); - _kds_s2000w_handler_opts_write_int_value(value_object, value); + _kds_s2000w_handler_opts_get_pixel_value_from_inch(config, "ImageWidth", value); break; case 12: value_object = json_object_object_get(config, "ImageHeight"); @@ -562,8 +577,7 @@ void kds_s2000w_handler_opts_set_option(handler* h, uint32_t option, void* value _kds_s2000w_handler_opts_set_inch_value_from_pixel(config, "ImageOffsetY", value); break; case 11: - value_object = json_object_object_get(config, "ImageWidth"); - _kds_s2000w_handler_opts_write_int_value_to_json(value_object, value); + _kds_s2000w_handler_opts_set_inch_value_from_pixel(config, "ImageWidth", value); break; case 12: value_object = json_object_object_get(config, "ImageHeight"); diff --git a/src/kds_s2000w_option_descriptors.c b/src/kds_s2000w_option_descriptors.c index a1de069..bd2dada 100644 --- a/src/kds_s2000w_option_descriptors.c +++ b/src/kds_s2000w_option_descriptors.c @@ -993,16 +993,16 @@ SANE_Option_Descriptor _kds_s2000w_option_descriptor_image_width() kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_image_width"); SANE_Range* constraint = malloc(sizeof(SANE_Range)); - constraint->min = 10; - constraint->max = 85; - constraint->quant = 1; + constraint->min = 200; + constraint->max = 1700; + constraint->quant = 20; SANE_Option_Descriptor descriptor = { - "image-width", - "Image Width", - "Image Width", + SANE_NAME_PAGE_WIDTH, + SANE_TITLE_PAGE_WIDTH, + SANE_DESC_PAGE_WIDTH, SANE_TYPE_INT, - SANE_UNIT_NONE, + SANE_UNIT_PIXEL, sizeof(SANE_Int), SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT, SANE_CONSTRAINT_RANGE, diff --git a/tests/kds_s2000w_net_get_opt_tests.c b/tests/kds_s2000w_net_get_opt_tests.c index 7fb0fdc..f071606 100644 --- a/tests/kds_s2000w_net_get_opt_tests.c +++ b/tests/kds_s2000w_net_get_opt_tests.c @@ -159,7 +159,7 @@ void sane_kds_s2000w_net_control_get_option_eleven_test(void** state) sane_kds_s2000w_net_control_option(h, 11, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(value, 10); + assert_int_equal(value, 200); kds_s2000w_handler_free(h); h = NULL; diff --git a/tests/kds_s2000w_option_descriptor_tests.c b/tests/kds_s2000w_option_descriptor_tests.c index f0635cc..f0498f2 100644 --- a/tests/kds_s2000w_option_descriptor_tests.c +++ b/tests/kds_s2000w_option_descriptor_tests.c @@ -208,17 +208,17 @@ void kds_s2000w_option_get_descriptor_eleven_test() { SANE_Option_Descriptor* option = kds_s2000w_option_descriptors_get(11); - assert_string_equal("image-width", option->name); - assert_string_equal("Image Width", option->title); - assert_string_equal("Image Width", option->desc); + assert_string_equal(SANE_NAME_PAGE_WIDTH, option->name); + assert_string_equal(SANE_TITLE_PAGE_WIDTH, option->title); + assert_string_equal(SANE_DESC_PAGE_WIDTH, option->desc); assert_int_equal(SANE_TYPE_INT, option->type); - assert_int_equal(SANE_UNIT_NONE, option->unit); + assert_int_equal(SANE_UNIT_PIXEL, option->unit); assert_int_equal(sizeof(SANE_Int), option->size); assert_int_equal(SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT, option->cap); assert_int_equal(SANE_CONSTRAINT_RANGE, option->constraint_type); - assert_int_equal(option->constraint.range->min, 10); - assert_int_equal(option->constraint.range->max, 85); - assert_int_equal(option->constraint.range->quant, 1); + assert_int_equal(option->constraint.range->min, 200); + assert_int_equal(option->constraint.range->max, 1700); + assert_int_equal(option->constraint.range->quant, 20); } void kds_s2000w_option_get_descriptor_twelve_test()