From: Bastian Dehn Date: Sat, 15 Mar 2025 07:42:25 +0000 (+0100) Subject: set width and height X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=b29500cec5d8511f904727403a4608a8cf79cf15;p=sane-kds-s2000w-net.git set width and height --- diff --git a/src/kds_s2000w_handler_opts.c b/src/kds_s2000w_handler_opts.c index 6507f91..6754517 100644 --- a/src/kds_s2000w_handler_opts.c +++ b/src/kds_s2000w_handler_opts.c @@ -305,6 +305,36 @@ void _kds_s2000w_handler_opts_set_enable_color_drop_out_aggressiveness(json_obje color_drop_out_aggressiveness->cap &= ~SANE_CAP_SOFT_SELECT; } +void _kds_s2000w_handler_opts_set_width(json_object* config, handler* h) +{ + json_object* object_value = json_object_object_get(config, "DPI"); + int32_t dpi = json_object_get_int(object_value); + object_value = json_object_object_get(config, "ImageOffsetX"); + int32_t tl_x = json_object_get_int(object_value); + SANE_Option_Descriptor* width_option = kds_s2000w_option_descriptors_get_by_name(SANE_NAME_PAGE_WIDTH); + + int32_t width_pixel = kds_s2000w_handler_opts_calc_diff(width_option->constraint.range->max, tl_x, h->br->x); + int32_t width_inch = kds_s2000w_handler_opts_calc_pixel_to_inch(dpi, width_pixel); + + object_value = json_object_object_get(config, "ImageWidth"); + _kds_s2000w_handler_opts_write_int_value(object_value, (void*) &width_inch); +} + +void _kds_s2000w_handler_opts_set_height(json_object* config, handler* h) +{ + json_object* object_value = json_object_object_get(config, "DPI"); + int32_t dpi = json_object_get_int(object_value); + object_value = json_object_object_get(config, "ImageOffsetY"); + int32_t tl_y = json_object_get_int(object_value); + SANE_Option_Descriptor* height_option = kds_s2000w_option_descriptors_get_by_name(SANE_NAME_PAGE_HEIGHT); + + int32_t height_pixel = kds_s2000w_handler_opts_calc_diff(height_option->constraint.range->max, tl_y, h->br->y); + int32_t height_inch = kds_s2000w_handler_opts_calc_pixel_to_inch(dpi, height_pixel); + + object_value = json_object_object_get(config, "ImageHeight"); + _kds_s2000w_handler_opts_write_int_value(object_value, (void*) &height_inch); +} + int32_t _kds_s2000w_handler_opts_inch_to_pixel(json_object* config, int32_t inch) { json_object* object_value = json_object_object_get(config, "DPI"); @@ -605,9 +635,17 @@ void kds_s2000w_handler_opts_set_option(handler* h, uint32_t option, void* value break; case 9: _kds_s2000w_handler_opts_set_inch_value_from_pixel(config, "ImageOffsetX", value); + _kds_s2000w_handler_opts_set_width(config, h); + + if (info != NULL) + *info = RELOAD_OPTIONS; break; case 10: _kds_s2000w_handler_opts_set_inch_value_from_pixel(config, "ImageOffsetY", value); + _kds_s2000w_handler_opts_set_height(config, h); + + if (info != NULL) + *info = RELOAD_OPTIONS; break; case 11: _kds_s2000w_handler_opts_set_inch_value_from_pixel(config, "ImageWidth", value); @@ -772,10 +810,18 @@ void kds_s2000w_handler_opts_set_option(handler* h, uint32_t option, void* value case 47: int32_t* br_x = (int32_t*) value; *br_x = _kds_s2000w_handler_opts_pixel_to_inch(config, h->br->x); + _kds_s2000w_handler_opts_set_width(config, h); + + if (info != NULL) + *info = RELOAD_OPTIONS; break; case 48: int32_t* br_y = (int32_t*) value; *br_y = _kds_s2000w_handler_opts_pixel_to_inch(config, h->br->y); + _kds_s2000w_handler_opts_set_height(config, h); + + if (info != NULL) + *info = RELOAD_OPTIONS; break; default: break;