]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change image width to pixel
authorBastian Dehn <hhaalo@arcor.de>
Sun, 23 Feb 2025 11:33:43 +0000 (12:33 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 6 Mar 2025 20:44:49 +0000 (21:44 +0100)
src/kds_s2000w_handler_opts.c
src/kds_s2000w_option_descriptors.c
tests/kds_s2000w_net_get_opt_tests.c
tests/kds_s2000w_option_descriptor_tests.c

index a77d8faa7b1072ecf0739adbac35ab5d1dff5f0b..5f3f4a0c0802ac2d4b9ed854ae47c0b9e0b3b116 100644 (file)
@@ -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");
index a1de069f691f537c5d364b4c5b8f46caa9262660..bd2dada14254bd5b19ef8b968fabc1859dc90220 100644 (file)
@@ -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,
index 7fb0fdc4caa3a6df53d322342836800aa846bd5c..f071606d11725cbf19f12d239697abac15712678 100644 (file)
@@ -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;
index f0635ccb14bb1432235c60d70ffd184e5b37c061..f0498f28a0a7a43c7dc33c36a74d92fd07375466 100644 (file)
@@ -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()