From: Ilia Docin ilya.docin@contentai.ru
--- dlls/sane.ds/capability.c | 50 +++++++++++++-------------------------- dlls/sane.ds/options.c | 37 ++++++++++++++++++++++------- dlls/sane.ds/sane_i.h | 2 +- 3 files changed, 46 insertions(+), 43 deletions(-)
diff --git a/dlls/sane.ds/capability.c b/dlls/sane.ds/capability.c index 555575c45a4..fecb4abb546 100644 --- a/dlls/sane.ds/capability.c +++ b/dlls/sane.ds/capability.c @@ -277,44 +277,19 @@ static TW_UINT16 SANE_CAPXferCount (pTW_CAPABILITY pCapability, TW_UINT16 action return twCC; }
-static TW_UINT16 set_color_mode(TW_UINT32 pixeltype) +static TW_UINT16 set_color_mode(TW_UINT32 pixeltype, char color_modes[3][256]) { TW_UINT16 twCC = TWCC_BADCAP; BOOL reload = FALSE; - int i; - const char * const * modes; - /* most of the values are taken from https://gitlab.gnome.org/GNOME/simple-scan/-/blob/master/src/scanner.vala */ - static const char * const gray[] = {"Gray", "Grayscale", "True Gray", "8-bit Grayscale", "Grayscale - 256 Levels", "gray", - 0}; - static const char * const rgb[] = {"Color", "24bit Color[Fast]", "24bit Color", - "24 bit Color", "Color - 16 Million Colors", 0}; - static const char * const bw[] = {"Lineart", "LineArt", "Black & White", "Binary", "Thresholded", "1-bit Black & White", - "Black and White - Line Art", "Black and White - Halftone", "Monochrome", 0}; - switch (pixeltype) + if (*(color_modes[pixeltype])) { - case TWPT_GRAY: - modes = gray; - break; - case TWPT_RGB: - modes = rgb; - break; - case TWPT_BW: - modes = bw; - break; - default: - ERR("Unsupported pixeltype %lu\n", pixeltype); - return TWCC_BADVALUE; - break; - } - TRACE("Setting pixeltype to %lu\n", pixeltype); - for(i=0; modes[i]; ++i) - { - twCC = sane_option_set_str("mode", (char*)modes[i], &reload); + twCC = sane_option_set_str("mode", color_modes[pixeltype], &reload); if (twCC == TWCC_SUCCESS) { if (reload) get_sane_params(&activeDS.frame_params); - break; } } + else + ERR("Unsupported pixeltype %u\n", pixeltype); return twCC; }
@@ -326,10 +301,11 @@ static TW_UINT16 SANE_ICAPPixelType (pTW_CAPABILITY pCapability, TW_UINT16 actio int possible_value_count; TW_UINT32 val; TW_UINT16 current_pixeltype = TWPT_BW; + char color_modes[3][256] = {{'\0'}, {'\0'}, {'\0'}};
TRACE("ICAP_PIXELTYPE\n");
- twCC = sane_option_probe_mode(¤t_pixeltype, possible_values, &possible_value_count); + twCC = sane_option_probe_mode(¤t_pixeltype, color_modes); if (twCC != TWCC_SUCCESS) { ERR("Unable to retrieve mode from sane, ICAP_PIXELTYPE unsupported\n"); @@ -352,6 +328,12 @@ static TW_UINT16 SANE_ICAPPixelType (pTW_CAPABILITY pCapability, TW_UINT16 actio break;
case MSG_GET: + possible_value_count = 0; + for (val=TWPT_BW; val<=TWPT_RGB; ++val) + { + if (*(color_modes[val])) + possible_values[possible_value_count++] = val; + } twCC = msg_get_enum(pCapability, possible_values, possible_value_count, TWTY_UINT16, current_pixeltype, activeDS.defaultPixelType); break; @@ -360,8 +342,8 @@ static TW_UINT16 SANE_ICAPPixelType (pTW_CAPABILITY pCapability, TW_UINT16 actio twCC = msg_set(pCapability, &val); if (twCC == TWCC_SUCCESS) { - TRACE("Setting pixeltype to %ld\n", val); - twCC = set_color_mode(val); + TRACE("Setting pixeltype to %u\n", val); + twCC = set_color_mode(val, color_modes); } break;
@@ -370,7 +352,7 @@ static TW_UINT16 SANE_ICAPPixelType (pTW_CAPABILITY pCapability, TW_UINT16 actio break;
case MSG_RESET: - twCC = set_color_mode(activeDS.defaultPixelType); + twCC = set_color_mode(activeDS.defaultPixelType, color_modes); if (twCC == TWCC_SUCCESS) current_pixeltype = activeDS.defaultPixelType; else diff --git a/dlls/sane.ds/options.c b/dlls/sane.ds/options.c index 1d39844a770..39cef419e10 100644 --- a/dlls/sane.ds/options.c +++ b/dlls/sane.ds/options.c @@ -112,10 +112,35 @@ TW_UINT16 sane_option_probe_resolution(const char *option_name, struct option_de return sane_find_option(option_name, TYPE_INT, opt); }
-TW_UINT16 sane_option_probe_mode(TW_UINT16 *current, TW_UINT32 *choices, int *count) +static TW_UINT32 sane_register_color_mode(WCHAR* color_mode, char color_modes[3][256]) +{ + TW_UINT32 pixel_type, j; + static const WCHAR * const bw[] = {L"Lineart", L"Black", L"Binary", L"Threshold", L"Mono", 0}; + static const WCHAR * const gray[] = {L"Gray", L"gray", 0}; + static const WCHAR * const rgb[] = {L"Color", 0}; + static const WCHAR * const * const search_filters[3] = {bw, gray, rgb}; + for(pixel_type=TWPT_BW; pixel_type<=TWPT_RGB; ++pixel_type) + { + if (!*(color_modes[pixel_type])) + { + for(j=0; search_filters[pixel_type][j]; ++j) + { + if (wcsstr(search_filters[pixel_type][j], color_mode)) + { + wcstombs(color_modes[pixel_type], color_mode, 256); + return pixel_type; + } + } + } + } + return TWPT_BW; +} + +TW_UINT16 sane_option_probe_mode(TW_UINT16 *current, char color_modes[3][256]) { WCHAR *p; char buffer[256]; + WCHAR current_mode[256]; struct option_descriptor opt; TW_UINT16 rc = sane_find_option("mode", TYPE_STRING, &opt);
@@ -124,18 +149,14 @@ TW_UINT16 sane_option_probe_mode(TW_UINT16 *current, TW_UINT32 *choices, int *co rc = sane_option_get_value( opt.optno, buffer ); if (rc != TWCC_SUCCESS) return rc;
- if (!strcmp( buffer, "Lineart" )) *current = TWPT_BW; - else if (!strcmp( buffer, "Color" )) *current = TWPT_RGB; - else if (!strncmp( buffer, "Gray", 4 )) *current = TWPT_GRAY; + mbstowcs(current_mode, (char*)buffer, 256); + *current = sane_register_color_mode(current_mode, color_modes);
- *count = 0; if (opt.constraint_type == CONSTRAINT_STRING_LIST) { for (p = opt.constraint.strings; *p; p += lstrlenW(p) + 1) { - if (!wcscmp( p, L"Lineart" )) choices[(*count)++] = TWPT_BW; - else if (!wcscmp( p, L"Color" )) choices[(*count)++] = TWPT_RGB; - else if (!wcsncmp( p, L"Gray", 4 )) choices[(*count)++] = TWPT_GRAY; + sane_register_color_mode(p, color_modes); } } return rc; diff --git a/dlls/sane.ds/sane_i.h b/dlls/sane.ds/sane_i.h index 47c5d69c82e..cf6431efb8d 100644 --- a/dlls/sane.ds/sane_i.h +++ b/dlls/sane.ds/sane_i.h @@ -201,7 +201,7 @@ TW_UINT16 sane_option_set_int( const char *option_name, int val, BOOL *reload ); TW_UINT16 sane_option_get_str( const char *option_name, char *val, int len ); TW_UINT16 sane_option_set_str( const char *option_name, char *val, BOOL *reload ); TW_UINT16 sane_option_probe_resolution( const char *option_name, struct option_descriptor *opt ); -TW_UINT16 sane_option_probe_mode(TW_UINT16 *current, TW_UINT32 *choices, int *count); +TW_UINT16 sane_option_probe_mode( TW_UINT16 *current, char color_modes[3][256] ); TW_UINT16 sane_option_get_bool( const char *option_name, BOOL *val ); TW_UINT16 sane_option_set_bool( const char *option_name, BOOL val ); TW_UINT16 sane_option_get_scan_area( int *tlx, int *tly, int *brx, int *bry );