From b914f846a8f69d7267cbf69ec7f37bfc7261e6c1 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 16 Feb 2025 09:54:59 +0100 Subject: [PATCH] add option descriptor for jpeg quality --- src/kds_s2000w_option_descriptors.c | 34 +++++++++++++++++-- tests/kds_s2000w_option_descriptor_tests.c | 22 +++++++++++- tests/kds_s2000w_option_descriptor_tests.h | 1 + .../kds_s2000w_option_descriptor_tests_run.c | 1 + 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/kds_s2000w_option_descriptors.c b/src/kds_s2000w_option_descriptors.c index f4f0b39..0dd405f 100644 --- a/src/kds_s2000w_option_descriptors.c +++ b/src/kds_s2000w_option_descriptors.c @@ -3,7 +3,7 @@ #include "kds_s2000w_option_descriptors.h" #include "kds_s2000w_debug.h" -#define MAX_OPTION_COUNT 29 +#define MAX_OPTION_COUNT 30 SANE_Option_Descriptor* descriptor_array = NULL; @@ -33,6 +33,7 @@ SANE_String_Const* constraint_post_scan_rotation = NULL; SANE_String_Const* constraint_edge_fill = NULL; SANE_String_Const* constraint_image_border = NULL; SANE_String_Const* constraint_transport_handling = NULL; +SANE_String_Const* constraint_jpeg_quality = NULL; SANE_Option_Descriptor _kds_s2000w_option_descriptor_standard_group() { @@ -679,6 +680,32 @@ SANE_Option_Descriptor _kds_s2000w_option_descriptor_transport_handling() return descriptor; } +SANE_Option_Descriptor _kds_s2000w_option_descriptor_jpeg_quality() +{ + kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_jpeg_quality"); + + constraint_jpeg_quality = malloc(sizeof(SANE_String_Const*) * 6); + constraint_jpeg_quality[0] = "Draft"; + constraint_jpeg_quality[1] = "Good"; + constraint_jpeg_quality[2] = "Better"; + constraint_jpeg_quality[3] = "Best"; + constraint_jpeg_quality[4] = "Superior"; + constraint_jpeg_quality[5] = NULL; + + SANE_Option_Descriptor descriptor = { + "jpeg-quality", + "jpeg quality", + "jpeg quality", + SANE_TYPE_STRING, + SANE_UNIT_NONE, + sizeof(SANE_String_Const*) * 6, + SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT, + SANE_CONSTRAINT_STRING_LIST, + {.string_list = constraint_jpeg_quality} + }; + + return descriptor; +} void kds_s2000w_option_descriptors_init() { @@ -713,7 +740,8 @@ void kds_s2000w_option_descriptors_init() descriptor_array[25] = _kds_s2000w_option_descriptor_edge_fill(); descriptor_array[26] = _kds_s2000w_option_descriptor_image_border(); descriptor_array[27] = _kds_s2000w_option_descriptor_transport_handling(); - descriptor_array[28] = _kds_s2000w_option_descriptor_config_reset(); + descriptor_array[28] = _kds_s2000w_option_descriptor_jpeg_quality(); + descriptor_array[29] = _kds_s2000w_option_descriptor_config_reset(); } void kds_s2000w_option_descriptors_free() @@ -755,6 +783,8 @@ void kds_s2000w_option_descriptors_free() free(constraint_transport_handling); constraint_transport_handling = NULL; free(descriptor_array); + free(constraint_jpeg_quality); + constraint_jpeg_quality = NULL; descriptor_array = NULL; } diff --git a/tests/kds_s2000w_option_descriptor_tests.c b/tests/kds_s2000w_option_descriptor_tests.c index 9864eb4..f6a1cf3 100644 --- a/tests/kds_s2000w_option_descriptor_tests.c +++ b/tests/kds_s2000w_option_descriptor_tests.c @@ -4,7 +4,7 @@ #include "kds_s2000w_client_mock.h" #include "../src/kds_s2000w_option_descriptors.h" -#define MAX_OPTION_COUNT 29 +#define MAX_OPTION_COUNT 30 int setup(void** state) { @@ -514,6 +514,26 @@ void kds_s2000w_option_get_descriptor_twentyeight_test() { SANE_Option_Descriptor* option = kds_s2000w_option_descriptors_get(28); + assert_string_equal("jpeg-quality", option->name); + assert_string_equal("jpeg quality", option->title); + assert_string_equal("jpeg quality", option->desc); + assert_int_equal(SANE_TYPE_STRING, option->type); + assert_int_equal(SANE_UNIT_NONE, option->unit); + assert_int_equal(sizeof(SANE_String_Const*) * 6, option->size); + assert_int_equal(SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT, option->cap); + assert_int_equal(SANE_CONSTRAINT_STRING_LIST, option->constraint_type); + assert_string_equal("Draft", option->constraint.string_list[0]); + assert_string_equal("Good", option->constraint.string_list[1]); + assert_string_equal("Better", option->constraint.string_list[2]); + assert_string_equal("Best", option->constraint.string_list[3]); + assert_string_equal("Superior", option->constraint.string_list[4]); + assert_null(option->constraint.string_list[5]); +} + +void kds_s2000w_option_get_descriptor_twentynine_test() +{ + SANE_Option_Descriptor* option = kds_s2000w_option_descriptors_get(29); + assert_string_equal("config-reset", option->name); assert_string_equal("reset config", option->title); assert_string_equal("load default configuration from scanner", option->desc); diff --git a/tests/kds_s2000w_option_descriptor_tests.h b/tests/kds_s2000w_option_descriptor_tests.h index 383c80c..0c5760d 100644 --- a/tests/kds_s2000w_option_descriptor_tests.h +++ b/tests/kds_s2000w_option_descriptor_tests.h @@ -37,5 +37,6 @@ void kds_s2000w_option_get_descriptor_twentyfive_test(); void kds_s2000w_option_get_descriptor_twentysix_test(); void kds_s2000w_option_get_descriptor_twentyseven_test(); void kds_s2000w_option_get_descriptor_twentyeight_test(); +void kds_s2000w_option_get_descriptor_twentynine_test(); void kds_s2000w_option_get_descriptor_over_max_options_test(); #endif \ No newline at end of file diff --git a/tests/kds_s2000w_option_descriptor_tests_run.c b/tests/kds_s2000w_option_descriptor_tests_run.c index ad8cb84..c44645c 100644 --- a/tests/kds_s2000w_option_descriptor_tests_run.c +++ b/tests/kds_s2000w_option_descriptor_tests_run.c @@ -32,6 +32,7 @@ int main() cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_twentysix_test, setup, teardown), cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_twentyseven_test, setup, teardown), cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_twentyeight_test, setup, teardown), + cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_twentynine_test, setup, teardown), cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_over_max_options_test, setup, teardown) }; -- 2.39.5