]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change coordinate validate before send
authorBastian Dehn <hhaalo@arcor.de>
Tue, 7 Oct 2025 20:58:58 +0000 (22:58 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 7 Oct 2025 20:58:58 +0000 (22:58 +0200)
src/kds_s2000w_handler.c
src/kds_s2000w_handler_opts.c
src/kds_s2000w_option_descriptors.c
tests/kds_s2000w_option_descriptor_tests.c

index a657edfd02be4b890d327c4488e3acf63deaba85..3f4d11a3b3c9d0fae128ce13314ba910a5fd7f72 100644 (file)
@@ -83,8 +83,8 @@ handler* kds_s2000w_handler_init()
        h->image->data = NULL;
        h->coord->offset_x = 0;
        h->coord->offset_y = 0;
-       h->coord->width = 10;
-       h->coord->height = 10;
+       h->coord->width = 0;
+       h->coord->height = 0;
 
        return h;
 }
index 04ed8ecf87b3e3b06df1af11ece3a7bfa30dceac..491c6baa3979b5dfe4166c83fc096f211f1e3489 100644 (file)
@@ -8,8 +8,6 @@
 
 #define AUTOSTART_ON 1
 #define GUI_DPI 300
-#define MAX_WIDTH_INCH 85
-#define MAX_HEIGHT_INCH 140
 
 void _kds_s2000w_handler_opts_write_value_to_json(json_object* value_object, SANE_Value_Type value_type, void* value)
 {
@@ -39,10 +37,14 @@ void _kds_s2000w_handler_opts_write_value(json_object* value_object, SANE_Value_
        }
 }
 
-void _kds_s2000w_handler_opts_set_valid_coord(handler* h)
+void _kds_s2000w_handler_opts_set_valid_coord(handler* h, option_descriptor* descriptor)
 {
-       bool valid = h->coord->offset_x + h->coord->width < MAX_WIDTH_INCH;
-       valid = valid && h->coord->offset_y + h->coord->height < MAX_HEIGHT_INCH;
+       bool valid = h->coord->offset_x >= 0 && h->coord->offset_x <= 75;
+       valid = valid && h->coord->offset_y >= 0 && h->coord->offset_y <= 130;
+       valid = valid && h->coord->width >= 10 && h->coord->width <= 85;
+       valid = valid && h->coord->height >= 10 && h->coord->height <= 140;
+       valid = valid && h->coord->offset_x + h->coord->width <= 85;
+       valid = valid && h->coord->offset_y + h->coord->height <= 140;
 
        if (!valid)
                return;
@@ -434,24 +436,9 @@ void kds_s2000w_handler_opts_set_option(handler* h, uint32_t option, void* value
                config = json_object_object_get(h->current_scanner_config, "Configuration");
 
        option_descriptor* descriptor = kds_s2000w_option_descriptors_full_get_by_number(option);
-       json_object* value_object = NULL;
-
-       value_object = json_object_object_get(config, descriptor->config_name);
-       _kds_s2000w_handler_opts_write_value_to_json(value_object, descriptor->descriptor->type, value);
-
-       if (strcmp(descriptor->config_name, COLOR_MODE) == 0) {
-               if (strcmp(value, "Flatbed") == 0)
-                       h->current_scan_status->feeder = Flatbed;
-
-               if (strcmp(value, "DocumentFeeder") == 0)
-                       h->current_scan_status->feeder = DocumentFeeder;
-
-               if (strcmp(value, "Automatic") == 0)
-                       h->current_scan_status->feeder = Automatic;
-       }
+       json_object* value_object = json_object_object_get(config, descriptor->config_name);
 
-       if (strcmp(descriptor->config_name, IMAGE_OFFSET_X) == 0
-               || strcmp(descriptor->config_name, IMAGE_OFFSET_Y) == 0) {
+       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;
@@ -460,14 +447,12 @@ void kds_s2000w_handler_opts_set_option(handler* h, uint32_t option, void* value
        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_x = tenth_inch;
+               h->coord->offset_y = tenth_inch;
        }
 
        if (strcmp(descriptor->config_name, IMAGE_WIDTH) == 0) {
                int32_t* int_value = (int32_t*) value;
-               value_object = json_object_object_get(config, IMAGE_OFFSET_X);
-               int32_t tenth_inch_offset_x = json_object_get_int(value_object);
-               uint32_t offset_x_pixel = kds_s2000w_pixel_converter_tenth_inch_to_pixel(GUI_DPI, tenth_inch_offset_x);
+               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;
@@ -475,15 +460,30 @@ void kds_s2000w_handler_opts_set_option(handler* h, uint32_t option, void* value
 
        if (strcmp(descriptor->config_name, IMAGE_HEIGHT) == 0) {
                int32_t* int_value = (int32_t*) value;
-               value_object = json_object_object_get(config, IMAGE_OFFSET_Y);
-               int32_t tenth_inch_offset_y = json_object_get_int(value_object);
-               uint32_t offset_y_pixel = kds_s2000w_pixel_converter_tenth_inch_to_pixel(GUI_DPI, tenth_inch_offset_y);
+               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);
+       _kds_s2000w_handler_opts_set_valid_coord(h, descriptor);
+
+       if (strcmp(descriptor->config_name, IMAGE_OFFSET_X) != 0
+               && strcmp(descriptor->config_name, IMAGE_OFFSET_Y) != 0
+               && strcmp(descriptor->config_name, IMAGE_WIDTH) != 0
+               && strcmp(descriptor->config_name, IMAGE_HEIGHT) != 0)
+               _kds_s2000w_handler_opts_write_value_to_json(value_object, descriptor->descriptor->type, value);
+
+       if (strcmp(descriptor->config_name, COLOR_MODE) == 0) {
+               if (strcmp(value, "Flatbed") == 0)
+                       h->current_scan_status->feeder = Flatbed;
+
+               if (strcmp(value, "DocumentFeeder") == 0)
+                       h->current_scan_status->feeder = DocumentFeeder;
+
+               if (strcmp(value, "Automatic") == 0)
+                       h->current_scan_status->feeder = Automatic;
+       }
 
        if (strcmp(descriptor->config_name, RESET) == 0) {
                _kds_s2000w_handler_opts_set_option_to_default(h);
index 9952ed846264b6f36c9c149a08b7f882b1aca383..86eac7e82fc0343731933e8bbc53b460534f09ec 100644 (file)
@@ -323,7 +323,7 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_image_height()
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
        constraint->min = 300;
-       constraint->max = 3900;
+       constraint->max = 4200;
        constraint->quant = 30;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
index c548f5da2f6ac143ff4d4e376c2e79fc102af88a..56822338cafaab4e1b689de0461f323d550893ba 100644 (file)
@@ -236,7 +236,7 @@ void kds_s2000w_option_get_descriptor_twelve_test()
        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, 300);
-       assert_int_equal(option->constraint.range->max, 3900);
+       assert_int_equal(option->constraint.range->max, 4200);
        assert_int_equal(option->constraint.range->quant, 30);
 }