From 3066241e9037b2fb9b1a76c8ff02d97e94e345c5 Mon Sep 17 00:00:00 2001 From: Thierry HUCHARD Date: Sun, 29 Mar 2020 15:47:44 +0200 Subject: [PATCH 1/8] Sets the capabilities of the device according to the output format. --- backend/escl/escl_capabilities.c | 59 +++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/backend/escl/escl_capabilities.c b/backend/escl/escl_capabilities.c index 324018c93..6a75129ff 100644 --- a/backend/escl/escl_capabilities.c +++ b/backend/escl/escl_capabilities.c @@ -189,38 +189,33 @@ find_valor_of_array_variables(xmlNode *node, capabilities_t *scanner) else if (strcmp(name, "DocumentFormat") == 0) { int i = 0; + int _is_jpeg = 0, _is_png = 0, _is_tiff = 0, _is_pdf = 0; scanner->DocumentFormats = char_to_array(scanner->DocumentFormats, &scanner->DocumentFormatsSize, (SANE_String_Const)xmlNodeGetContent(node), 0); for(; i < scanner->DocumentFormatsSize; i++) { - if (scanner->default_format == NULL && !strcmp(scanner->DocumentFormats[i], "image/jpeg")) - { - scanner->default_format = strdup("image/jpeg"); - } + if (!strcmp(scanner->DocumentFormats[i], "image/jpeg")) + _is_jpeg = 1; #if(defined HAVE_LIBPNG) - else if(!strcmp(scanner->DocumentFormats[i], "image/png") && (scanner->default_format == NULL || strcmp(scanner->default_format, "image/tiff"))) - { - if (scanner->default_format) - free(scanner->default_format); - scanner->default_format = strdup("image/png"); - } + else if(!strcmp(scanner->DocumentFormats[i], "image/png")) + _is_png = 1; #endif #if(defined HAVE_TIFFIO_H) else if(!strcmp(scanner->DocumentFormats[i], "image/tiff")) - { - if (scanner->default_format) - free(scanner->default_format); - scanner->default_format = strdup("image/tiff"); - } + _is_tiff = 1; #endif #if(defined HAVE_POPPLER_GLIB) else if(!strcmp(scanner->DocumentFormats[i], "application/pdf")) - { - if (scanner->default_format) - free(scanner->default_format); - scanner->default_format = strdup("application/pdf"); - } + _is_pdf = 1; #endif } + if (_is_pdf) + scanner->default_format = strdup("application/pdf"); + else if (_is_tiff) + scanner->default_format = strdup("image/tiff"); + else if (_is_png) + scanner->default_format = strdup("image/png"); + else + scanner->default_format = strdup("image/jpeg"); fprintf(stderr, "Capability : [%s]\n", scanner->default_format); } else if (strcmp(name, "DocumentFormatExt") == 0) @@ -330,6 +325,27 @@ print_xml_c(xmlNode *node, capabilities_t *scanner) return (0); } +static void +_reduce_color_modes(capabilities_t *scanner) +{ + if (strcmp(scanner->default_format, "application/pdf")) { + if (scanner->ColorModesSize == 3) { + int i = à; + for (i = 0; i < scanner->ColorModesSize; i++) + free(scanner->ColorModes[i]); + free(scanner->ColorModes); + scanner->ColorModes = NULL; + scanner->ColorModesSize = 0; + colorModes = char_to_array(scanner->ColorModes, + &scanner->ColorModesSize, + (SANE_String_Const)SANE_VALUE_SCAN_MODE_GRAY, 0); + colorModes = char_to_array(scanner->ColorModes, + &scanner->ColorModesSize, + (SANE_String_Const)SANE_VALUE_SCAN_MODE_COLOR, 0); + } + } +} + /** * \fn capabilities_t *escl_capabilities(const ESCL_Device *device, SANE_Status *status) * \brief Function that finally recovers all the capabilities of the scanner, using curl. @@ -371,6 +387,9 @@ escl_capabilities(const ESCL_Device *device, SANE_Status *status) if (node == NULL) *status = SANE_STATUS_NO_MEM; print_xml_c(node, scanner); + + _reduce_color_modes(scanner); + xmlFreeDoc(data); xmlCleanupParser(); xmlMemoryDump(); From 9afdd20776d06ff5cceae9087eae038cc6dfc285 Mon Sep 17 00:00:00 2001 From: Ordissimo Date: Sun, 29 Mar 2020 13:53:42 +0000 Subject: [PATCH 2/8] Fix initialisation variable. --- backend/escl/escl_capabilities.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/escl/escl_capabilities.c b/backend/escl/escl_capabilities.c index 6a75129ff..d6709a0cc 100644 --- a/backend/escl/escl_capabilities.c +++ b/backend/escl/escl_capabilities.c @@ -330,7 +330,7 @@ _reduce_color_modes(capabilities_t *scanner) { if (strcmp(scanner->default_format, "application/pdf")) { if (scanner->ColorModesSize == 3) { - int i = à; + int i = 0; for (i = 0; i < scanner->ColorModesSize; i++) free(scanner->ColorModes[i]); free(scanner->ColorModes); From b4b1f2c7489912ec1243c576a6a6af1074565977 Mon Sep 17 00:00:00 2001 From: Thierry HUCHARD Date: Sun, 29 Mar 2020 16:12:19 +0200 Subject: [PATCH 3/8] Fix build. --- backend/escl/escl_capabilities.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/escl/escl_capabilities.c b/backend/escl/escl_capabilities.c index d6709a0cc..f12f2b2e2 100644 --- a/backend/escl/escl_capabilities.c +++ b/backend/escl/escl_capabilities.c @@ -336,10 +336,10 @@ _reduce_color_modes(capabilities_t *scanner) free(scanner->ColorModes); scanner->ColorModes = NULL; scanner->ColorModesSize = 0; - colorModes = char_to_array(scanner->ColorModes, + scanner->ColorModes = char_to_array(scanner->ColorModes, &scanner->ColorModesSize, (SANE_String_Const)SANE_VALUE_SCAN_MODE_GRAY, 0); - colorModes = char_to_array(scanner->ColorModes, + scanner->ColorModes = char_to_array(scanner->ColorModes, &scanner->ColorModesSize, (SANE_String_Const)SANE_VALUE_SCAN_MODE_COLOR, 0); } From 6c855b7662fd2d8d4c3688176d74843207b56d55 Mon Sep 17 00:00:00 2001 From: Thierry HUCHARD Date: Sun, 29 Mar 2020 16:20:16 +0200 Subject: [PATCH 4/8] Fix build. --- backend/escl/escl_capabilities.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/backend/escl/escl_capabilities.c b/backend/escl/escl_capabilities.c index f12f2b2e2..408222cf8 100644 --- a/backend/escl/escl_capabilities.c +++ b/backend/escl/escl_capabilities.c @@ -214,7 +214,7 @@ find_valor_of_array_variables(xmlNode *node, capabilities_t *scanner) scanner->default_format = strdup("image/tiff"); else if (_is_png) scanner->default_format = strdup("image/png"); - else + else if(_is_jpeg) scanner->default_format = strdup("image/jpeg"); fprintf(stderr, "Capability : [%s]\n", scanner->default_format); } @@ -330,9 +330,6 @@ _reduce_color_modes(capabilities_t *scanner) { if (strcmp(scanner->default_format, "application/pdf")) { if (scanner->ColorModesSize == 3) { - int i = 0; - for (i = 0; i < scanner->ColorModesSize; i++) - free(scanner->ColorModes[i]); free(scanner->ColorModes); scanner->ColorModes = NULL; scanner->ColorModesSize = 0; From d7df235a7e74602c51b002a6962eb72937f623c3 Mon Sep 17 00:00:00 2001 From: Thierry HUCHARD Date: Sun, 29 Mar 2020 21:30:21 +0200 Subject: [PATCH 5/8] Offset correction --- backend/escl/escl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/escl/escl.c b/backend/escl/escl.c index 9866598f9..3dc83c85a 100644 --- a/backend/escl/escl.c +++ b/backend/escl/escl.c @@ -548,7 +548,7 @@ init_options(const ESCL_Device *device, escl_sane_t *s) s->opt[OPT_TL_X].unit = SANE_UNIT_MM; s->opt[OPT_TL_X].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_TL_X].constraint.range = &s->x_range; - s->val[OPT_TL_X].w = 0; + s->val[OPT_TL_X].w = s->x_range.min; s->opt[OPT_TL_Y].name = SANE_NAME_SCAN_TL_Y; s->opt[OPT_TL_Y].title = SANE_TITLE_SCAN_TL_Y; @@ -559,7 +559,7 @@ init_options(const ESCL_Device *device, escl_sane_t *s) s->opt[OPT_TL_Y].unit = SANE_UNIT_MM; s->opt[OPT_TL_Y].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_TL_Y].constraint.range = &s->y_range; - s->val[OPT_TL_Y].w = 0; + s->val[OPT_TL_Y].w = s->y_range.min; s->opt[OPT_BR_X].name = SANE_NAME_SCAN_BR_X; s->opt[OPT_BR_X].title = SANE_TITLE_SCAN_BR_X; From 67c7ef9c4e1463d853db190db22e7f652119d664 Mon Sep 17 00:00:00 2001 From: Thierry HUCHARD Date: Sun, 29 Mar 2020 21:35:28 +0200 Subject: [PATCH 6/8] Correction of the zone cropping. --- backend/escl/escl_crop.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/backend/escl/escl_crop.c b/backend/escl/escl_crop.c index 0d1b9444c..87ad17688 100644 --- a/backend/escl/escl_crop.c +++ b/backend/escl/escl_crop.c @@ -48,37 +48,44 @@ escl_crop_surface(capabilities_t *scanner, scanner->width = w; if (scanner->pos_x < 0) scanner->pos_x = 0; + if (scanner->width > scanner->pos_x) + x_off = scanner->pos_x; + real_w = scanner->width - x_off; if (h < (int)scanner->height) scanner->height = h; - if (scanner->pos_x < 0) - scanner->pos_x = 0; - - x_off = scanner->pos_x; - real_w = scanner->width - x_off; - y_off = scanner->pos_y; + if (scanner->pos_y < 0) + scanner->pos_y = 0; + if (scanner->pos_y < scanner->height) + y_off = scanner->pos_y; real_h = scanner->height - y_off; + *width = real_w; *height = real_h; if (x_off > 0 || real_w < scanner->width || y_off > 0 || real_h < scanner->height) { surface_crop = (unsigned char *)malloc (sizeof (unsigned char) * real_w * real_h * bps); - if(!surface_crop) { + if(!surface_crop) { DBG( 1, "Escl Crop : Surface_crop Memory allocation problem\n"); - free(surface); - surface = NULL; - goto finish; - } + free(surface); + surface = NULL; + goto finish; + } for (y = 0; y < real_h; y++) { for (x = 0; x < real_w; x++) { - surface_crop[y * real_w + x] = surface[(y + y_off) * w + x + x_off]; + surface_crop[(y * real_w * bps) + (x * bps)] = + surface[((y + y_off) * w * bps) + ((x + x_off) * bps)]; + surface_crop[(y * real_w * bps) + (x * bps) + 1] = + surface[((y + y_off) * w * bps) + ((x + x_off) * bps) + 1]; + surface_crop[(y * real_w * bps) + (x * bps) + 2] = + surface[((y + y_off) * w * bps) + ((x + x_off) * bps) + 2]; } } free(surface); - surface = surface_crop; + surface = surface_crop; } // we don't need row pointers anymore scanner->img_data = surface; From 062fb40cf42220d9ab440b185afbfe023d85a650 Mon Sep 17 00:00:00 2001 From: Thierry HUCHARD Date: Sun, 29 Mar 2020 21:37:25 +0200 Subject: [PATCH 7/8] Revert "Correction of the zone cropping." This reverts commit 67c7ef9c4e1463d853db190db22e7f652119d664. --- backend/escl/escl_crop.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/backend/escl/escl_crop.c b/backend/escl/escl_crop.c index 87ad17688..0d1b9444c 100644 --- a/backend/escl/escl_crop.c +++ b/backend/escl/escl_crop.c @@ -48,44 +48,37 @@ escl_crop_surface(capabilities_t *scanner, scanner->width = w; if (scanner->pos_x < 0) scanner->pos_x = 0; - if (scanner->width > scanner->pos_x) - x_off = scanner->pos_x; - real_w = scanner->width - x_off; if (h < (int)scanner->height) scanner->height = h; - if (scanner->pos_y < 0) - scanner->pos_y = 0; - if (scanner->pos_y < scanner->height) - y_off = scanner->pos_y; - real_h = scanner->height - y_off; + if (scanner->pos_x < 0) + scanner->pos_x = 0; + x_off = scanner->pos_x; + real_w = scanner->width - x_off; + y_off = scanner->pos_y; + real_h = scanner->height - y_off; *width = real_w; *height = real_h; if (x_off > 0 || real_w < scanner->width || y_off > 0 || real_h < scanner->height) { surface_crop = (unsigned char *)malloc (sizeof (unsigned char) * real_w * real_h * bps); - if(!surface_crop) { + if(!surface_crop) { DBG( 1, "Escl Crop : Surface_crop Memory allocation problem\n"); - free(surface); - surface = NULL; - goto finish; - } + free(surface); + surface = NULL; + goto finish; + } for (y = 0; y < real_h; y++) { for (x = 0; x < real_w; x++) { - surface_crop[(y * real_w * bps) + (x * bps)] = - surface[((y + y_off) * w * bps) + ((x + x_off) * bps)]; - surface_crop[(y * real_w * bps) + (x * bps) + 1] = - surface[((y + y_off) * w * bps) + ((x + x_off) * bps) + 1]; - surface_crop[(y * real_w * bps) + (x * bps) + 2] = - surface[((y + y_off) * w * bps) + ((x + x_off) * bps) + 2]; + surface_crop[y * real_w + x] = surface[(y + y_off) * w + x + x_off]; } } free(surface); - surface = surface_crop; + surface = surface_crop; } // we don't need row pointers anymore scanner->img_data = surface; From d5fdbb0c7dcbaa26e29b114f09844abdb0d52a52 Mon Sep 17 00:00:00 2001 From: Thierry HUCHARD Date: Sun, 29 Mar 2020 21:37:35 +0200 Subject: [PATCH 8/8] Revert "Offset correction" This reverts commit d7df235a7e74602c51b002a6962eb72937f623c3. --- backend/escl/escl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/escl/escl.c b/backend/escl/escl.c index 3dc83c85a..9866598f9 100644 --- a/backend/escl/escl.c +++ b/backend/escl/escl.c @@ -548,7 +548,7 @@ init_options(const ESCL_Device *device, escl_sane_t *s) s->opt[OPT_TL_X].unit = SANE_UNIT_MM; s->opt[OPT_TL_X].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_TL_X].constraint.range = &s->x_range; - s->val[OPT_TL_X].w = s->x_range.min; + s->val[OPT_TL_X].w = 0; s->opt[OPT_TL_Y].name = SANE_NAME_SCAN_TL_Y; s->opt[OPT_TL_Y].title = SANE_TITLE_SCAN_TL_Y; @@ -559,7 +559,7 @@ init_options(const ESCL_Device *device, escl_sane_t *s) s->opt[OPT_TL_Y].unit = SANE_UNIT_MM; s->opt[OPT_TL_Y].constraint_type = SANE_CONSTRAINT_RANGE; s->opt[OPT_TL_Y].constraint.range = &s->y_range; - s->val[OPT_TL_Y].w = s->y_range.min; + s->val[OPT_TL_Y].w = 0; s->opt[OPT_BR_X].name = SANE_NAME_SCAN_BR_X; s->opt[OPT_BR_X].title = SANE_TITLE_SCAN_BR_X;