From cd768b3692e1fa18e97bb5565299ba2a2c83a354 Mon Sep 17 00:00:00 2001 From: thierry1970 Date: Fri, 18 Sep 2020 15:47:45 +0200 Subject: [PATCH] Check options scan and fix xml. --- backend/escl/escl.c | 50 +++++++++++++++++++++----------- backend/escl/escl_capabilities.c | 20 ++++++++----- backend/escl/escl_newjob.c | 4 +-- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/backend/escl/escl.c b/backend/escl/escl.c index 6b2c284f3..0b923c6f0 100644 --- a/backend/escl/escl.c +++ b/backend/escl/escl.c @@ -797,16 +797,23 @@ init_options(SANE_String_Const name_source, escl_sane_t *s) s->thresold_range.min= s->scanner->threshold->min; s->thresold_range.max=s->scanner->threshold->max; s->opt[OPT_THRESHOLD].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT; - s->opt[OPT_BRIGHTNESS].cap |= SANE_CAP_INACTIVE; - s->opt[OPT_CONTRAST].cap |= SANE_CAP_INACTIVE; + s->scanner->use_threshold = 1; + if (s->scanner->brightness) + s->opt[OPT_BRIGHTNESS].cap |= SANE_CAP_INACTIVE; + if (s->scanner->contrast) + s->opt[OPT_CONTRAST].cap |= SANE_CAP_INACTIVE; + if (s->scanner->sharpen) + s->opt[OPT_SHARPEN].cap |= SANE_CAP_INACTIVE; s->opt[OPT_THRESHOLD].cap |= SANE_CAP_INACTIVE; - s->opt[OPT_SHARPEN].cap |= SANE_CAP_INACTIVE; if (!strcasecmp(s->val[OPT_MODE].s, SANE_VALUE_SCAN_MODE_LINEART)) s->opt[OPT_THRESHOLD].cap &= ~SANE_CAP_INACTIVE; else { - s->opt[OPT_BRIGHTNESS].cap &= ~SANE_CAP_INACTIVE; - s->opt[OPT_CONTRAST].cap &= ~SANE_CAP_INACTIVE; - s->opt[OPT_SHARPEN].cap &= ~SANE_CAP_INACTIVE; + if (s->scanner->brightness) + s->opt[OPT_BRIGHTNESS].cap &= ~SANE_CAP_INACTIVE; + if (s->scanner->contrast) + s->opt[OPT_CONTRAST].cap &= ~SANE_CAP_INACTIVE; + if (s->scanner->sharpen) + s->opt[OPT_SHARPEN].cap &= ~SANE_CAP_INACTIVE; } } } @@ -1025,17 +1032,6 @@ sane_control_option(SANE_Handle h, SANE_Int n, SANE_Action a, void *v, SANE_Int case OPT_SCAN_SOURCE: case OPT_MODE: strcpy (v, handler->val[n].s); - handler->opt[OPT_BRIGHTNESS].cap |= SANE_CAP_INACTIVE; - handler->opt[OPT_CONTRAST].cap |= SANE_CAP_INACTIVE; - handler->opt[OPT_THRESHOLD].cap |= SANE_CAP_INACTIVE; - handler->opt[OPT_SHARPEN].cap |= SANE_CAP_INACTIVE; - if (!strcasecmp(handler->val[OPT_MODE].s, SANE_VALUE_SCAN_MODE_LINEART)) - handler->opt[OPT_THRESHOLD].cap &= ~SANE_CAP_INACTIVE; - else { - handler->opt[OPT_BRIGHTNESS].cap &= ~SANE_CAP_INACTIVE; - handler->opt[OPT_CONTRAST].cap &= ~SANE_CAP_INACTIVE; - handler->opt[OPT_SHARPEN].cap &= ~SANE_CAP_INACTIVE; - } break; case OPT_MODE_GROUP: default: @@ -1076,6 +1072,26 @@ sane_control_option(SANE_Handle h, SANE_Int n, SANE_Action a, void *v, SANE_Int } if (i) *i |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS | SANE_INFO_INEXACT; + if (handler->scanner->brightness) + handler->opt[OPT_BRIGHTNESS].cap |= SANE_CAP_INACTIVE; + if (handler->scanner->contrast) + handler->opt[OPT_CONTRAST].cap |= SANE_CAP_INACTIVE; + if (handler->scanner->threshold) + handler->opt[OPT_THRESHOLD].cap |= SANE_CAP_INACTIVE; + if (handler->scanner->sharpen) + handler->opt[OPT_SHARPEN].cap |= SANE_CAP_INACTIVE; + if (!strcasecmp(handler->val[n].s, SANE_VALUE_SCAN_MODE_LINEART)) { + if (handler->scanner->threshold) + handler->opt[OPT_THRESHOLD].cap &= ~SANE_CAP_INACTIVE; + } + else { + if (handler->scanner->brightness) + handler->opt[OPT_BRIGHTNESS].cap &= ~SANE_CAP_INACTIVE; + if (handler->scanner->contrast) + handler->opt[OPT_CONTRAST].cap &= ~SANE_CAP_INACTIVE; + if (handler->scanner->sharpen) + handler->opt[OPT_SHARPEN].cap &= ~SANE_CAP_INACTIVE; + } break; default: break; diff --git a/backend/escl/escl_capabilities.c b/backend/escl/escl_capabilities.c index 7a29fbdae..aeda7636c 100644 --- a/backend/escl/escl_capabilities.c +++ b/backend/escl/escl_capabilities.c @@ -317,18 +317,26 @@ static int find_struct_variables(xmlNode *node, capabilities_t *scanner) { const char *name = (const char *)node->name; - if (strcmp(name, "BrightnessSupport") == 0) + if (strcmp(name, "BrightnessSupport") == 0) { scanner->brightness = print_support(node->children); - else if (strcmp(name, "ContrastSupport") == 0) + return 1; + } + else if (strcmp(name, "ContrastSupport") == 0) { scanner->contrast = print_support(node->children); - else if (strcmp(name, "SharpenSupport") == 0) + return 1; + } + else if (strcmp(name, "SharpenSupport") == 0) { scanner->sharpen = print_support(node->children); - else if (strcmp(name, "ThresholdSupport") == 0) + return 1; + } + else if (strcmp(name, "ThresholdSupport") == 0) { scanner->threshold = print_support(node->children); + return 1; + } return (0); } @@ -361,8 +369,6 @@ find_true_variables(xmlNode *node, capabilities_t *scanner, int type) strcmp(name, "RiskyBottomMargin") == 0 || strcmp(name, "DocumentFormatExt") == 0) find_value_of_int_variables(node, scanner, type); - else - find_struct_variables(node, scanner); return (0); } @@ -401,7 +407,7 @@ print_xml_c(xmlNode *node, capabilities_t *scanner, int type) print_xml_c(node->children, scanner, ADFDUPLEX); scanner->caps[ADFDUPLEX].duplex = 1; } - else + else if (find_struct_variables(node, scanner) == 0) print_xml_c(node->children, scanner, type); node = node->next; } diff --git a/backend/escl/escl_newjob.c b/backend/escl/escl_newjob.c index c50a3e2cf..9f517ed1d 100644 --- a/backend/escl/escl_newjob.c +++ b/backend/escl/escl_newjob.c @@ -118,9 +118,9 @@ download_callback(void *str, size_t size, size_t nmemb, void *userp) static char* add_support_option(char *key, int val) { - int size = (strlen(key) * 2) + 10; + int size = (strlen(key) * 3) + 10; char *tmp = (char*)calloc(1, size); - snprintf (tmp, size, "<%s>%d\n", key, val, key); + snprintf (tmp, size, "%d\n", key, val, key); return tmp; }