From: Bastian Dehn Date: Wed, 8 Oct 2025 10:59:44 +0000 (+0200) Subject: change refactor set coord X-Git-Tag: v1.1.9^2~1^2~6 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=53d5b3646bb63f8fa32880328330949fdd5d15cf;p=sane-kds-s2000w-net.git change refactor set coord --- diff --git a/src/kds_s2000w_handler_opts.c b/src/kds_s2000w_handler_opts.c index 565f0fc..2e7627a 100644 --- a/src/kds_s2000w_handler_opts.c +++ b/src/kds_s2000w_handler_opts.c @@ -37,7 +37,7 @@ void _kds_s2000w_handler_opts_write_value(json_object* value_object, SANE_Value_ } } -void _kds_s2000w_handler_opts_set_valid_coord(handler* h, option_descriptor* descriptor) +void _kds_s2000w_handler_opts_set_valid_coord(option_descriptor* descriptor, handler* h) { bool valid = h->coord->offset_x >= 0 && h->coord->offset_x <= 75; valid = valid && h->coord->offset_y >= 0 && h->coord->offset_y <= 130; @@ -285,6 +285,50 @@ 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_offset_x(option_descriptor* descriptor, handler* h, void* value) +{ + if (strcmp(descriptor->config_name, IMAGE_OFFSET_X) != 0) + return; + + int32_t* int_value = (int32_t*) value; + uint32_t tenth_inch = kds_s2000w_pixel_converter_pixel_to_tenth_inch(GUI_DPI, *int_value); + h->coord->offset_x = tenth_inch; +} + +void _kds_s2000w_handler_opts_set_offset_y(option_descriptor* descriptor, handler* h, void* value) +{ + if (strcmp(descriptor->config_name, IMAGE_OFFSET_Y) != 0) + return; + + int32_t* int_value = (int32_t*) value; + uint32_t tenth_inch = kds_s2000w_pixel_converter_pixel_to_tenth_inch(GUI_DPI, *int_value); + h->coord->offset_y = tenth_inch; +} + +void _kds_s2000w_handler_opts_set_width(option_descriptor* descriptor, handler* h, void* value) +{ + if (strcmp(descriptor->config_name, IMAGE_WIDTH) != 0) + return; + + int32_t* int_value = (int32_t*) value; + uint32_t offset_x_pixel = kds_s2000w_pixel_converter_tenth_inch_to_pixel(GUI_DPI, h->coord->offset_x); + uint32_t width_pixel = *int_value - offset_x_pixel; + uint32_t tenth_inch_width = kds_s2000w_pixel_converter_pixel_to_tenth_inch(GUI_DPI, width_pixel); + h->coord->width = tenth_inch_width; +} + +void _kds_s2000w_handler_opts_set_height(option_descriptor* descriptor, handler* h, void* value) +{ + if (strcmp(descriptor->config_name, IMAGE_HEIGHT) != 0) + return; + + int32_t* int_value = (int32_t*) value; + uint32_t offset_y_pixel = kds_s2000w_pixel_converter_tenth_inch_to_pixel(GUI_DPI, h->coord->offset_y); + uint32_t height_pixel = *int_value - offset_y_pixel; + uint32_t tenth_inch_height = kds_s2000w_pixel_converter_pixel_to_tenth_inch(GUI_DPI, height_pixel); + h->coord->height = tenth_inch_height; +} + void _kds_s2000w_handler_opts_set_info_option(option_descriptor* descriptor, int32_t* info) { if (info == NULL) return; @@ -450,35 +494,11 @@ void kds_s2000w_handler_opts_set_option(handler* h, uint32_t option, void* value option_descriptor* descriptor = kds_s2000w_option_descriptors_full_get_by_number(option); json_object* value_object = json_object_object_get(config, descriptor->config_name); - if (strcmp(descriptor->config_name, IMAGE_OFFSET_X) == 0) { - int32_t* int_value = (int32_t*) value; - uint32_t tenth_inch = kds_s2000w_pixel_converter_pixel_to_tenth_inch(GUI_DPI, *int_value); - h->coord->offset_x = tenth_inch; - } - - if (strcmp(descriptor->config_name, IMAGE_OFFSET_Y) == 0) { - int32_t* int_value = (int32_t*) value; - uint32_t tenth_inch = kds_s2000w_pixel_converter_pixel_to_tenth_inch(GUI_DPI, *int_value); - h->coord->offset_y = tenth_inch; - } - - if (strcmp(descriptor->config_name, IMAGE_WIDTH) == 0) { - int32_t* int_value = (int32_t*) value; - uint32_t offset_x_pixel = kds_s2000w_pixel_converter_tenth_inch_to_pixel(GUI_DPI, h->coord->offset_x); - uint32_t width_pixel = *int_value - offset_x_pixel; - uint32_t tenth_inch_width = kds_s2000w_pixel_converter_pixel_to_tenth_inch(GUI_DPI, width_pixel); - h->coord->width = tenth_inch_width; - } - - if (strcmp(descriptor->config_name, IMAGE_HEIGHT) == 0) { - int32_t* int_value = (int32_t*) value; - uint32_t offset_y_pixel = kds_s2000w_pixel_converter_tenth_inch_to_pixel(GUI_DPI, h->coord->offset_y); - uint32_t height_pixel = *int_value - offset_y_pixel; - uint32_t tenth_inch_height = kds_s2000w_pixel_converter_pixel_to_tenth_inch(GUI_DPI, height_pixel); - h->coord->height = tenth_inch_height; - } - - _kds_s2000w_handler_opts_set_valid_coord(h, descriptor); + _kds_s2000w_handler_opts_set_offset_x(descriptor, h, value); + _kds_s2000w_handler_opts_set_offset_y(descriptor, h, value); + _kds_s2000w_handler_opts_set_width(descriptor, h, value); + _kds_s2000w_handler_opts_set_height(descriptor, h, value); + _kds_s2000w_handler_opts_set_valid_coord(descriptor, h); if (strcmp(descriptor->config_name, IMAGE_OFFSET_X) != 0 && strcmp(descriptor->config_name, IMAGE_OFFSET_Y) != 0