2009-02-13 20:14:30 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Jeremy White <jwhite@codeweavers.com> for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-10-27 13:38:59 +02:00
|
|
|
#include <stdarg.h>
|
2009-02-13 20:14:30 +01:00
|
|
|
#include <stdlib.h>
|
2021-10-27 13:38:59 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
2009-02-13 20:14:30 +01:00
|
|
|
#include "sane_i.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2021-10-25 18:34:53 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(twain);
|
|
|
|
|
2021-10-25 17:32:04 +02:00
|
|
|
TW_UINT16 sane_option_get_value( int optno, void *val )
|
|
|
|
{
|
2021-10-27 15:27:52 +02:00
|
|
|
struct option_get_value_params params = { optno, val };
|
2021-10-25 17:32:04 +02:00
|
|
|
|
2021-10-27 15:27:52 +02:00
|
|
|
return SANE_CALL( option_get_value, ¶ms );
|
2021-10-25 17:32:04 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 15:27:52 +02:00
|
|
|
TW_UINT16 sane_option_set_value( int optno, void *val, BOOL *reload )
|
2009-02-13 20:14:30 +01:00
|
|
|
{
|
2021-10-27 15:27:52 +02:00
|
|
|
struct option_set_value_params params = { optno, val, reload };
|
2009-02-13 20:14:30 +01:00
|
|
|
|
2021-10-27 15:27:52 +02:00
|
|
|
return SANE_CALL( option_set_value, ¶ms );
|
2021-10-27 13:38:59 +02:00
|
|
|
}
|
2009-02-26 03:58:42 +01:00
|
|
|
|
2021-10-27 13:38:59 +02:00
|
|
|
static TW_UINT16 sane_find_option( const char *name, int type, struct option_descriptor *descr )
|
|
|
|
{
|
2021-10-27 15:27:52 +02:00
|
|
|
struct option_find_descriptor_params params = { name, type, descr };
|
|
|
|
return SANE_CALL( option_find_descriptor, ¶ms ) ? TWCC_CAPUNSUPPORTED : TWCC_SUCCESS;
|
2009-02-13 20:14:30 +01:00
|
|
|
}
|
2009-02-23 23:25:26 +01:00
|
|
|
|
2021-10-25 17:32:04 +02:00
|
|
|
TW_UINT16 sane_option_get_int(const char *option_name, int *val)
|
2009-02-23 23:25:26 +01:00
|
|
|
{
|
2021-10-27 13:38:59 +02:00
|
|
|
struct option_descriptor opt;
|
|
|
|
TW_UINT16 rc = sane_find_option(option_name, TYPE_INT, &opt);
|
2009-02-23 23:25:26 +01:00
|
|
|
|
2021-10-27 13:38:59 +02:00
|
|
|
if (rc == TWCC_SUCCESS) rc = sane_option_get_value( opt.optno, val );
|
2021-10-25 17:32:04 +02:00
|
|
|
return rc;
|
2009-02-23 23:25:26 +01:00
|
|
|
}
|
|
|
|
|
2021-10-25 17:32:04 +02:00
|
|
|
TW_UINT16 sane_option_set_int(const char *option_name, int val, BOOL *needs_reload )
|
2009-02-23 23:25:26 +01:00
|
|
|
{
|
2021-10-27 13:38:59 +02:00
|
|
|
struct option_descriptor opt;
|
|
|
|
TW_UINT16 rc = sane_find_option(option_name, TYPE_INT, &opt);
|
2009-02-23 23:25:26 +01:00
|
|
|
|
2021-10-27 13:38:59 +02:00
|
|
|
if (rc == TWCC_SUCCESS) rc = sane_option_set_value( opt.optno, &val, needs_reload );
|
2021-10-25 17:32:04 +02:00
|
|
|
return rc;
|
2009-02-23 23:25:26 +01:00
|
|
|
}
|
|
|
|
|
2021-10-25 17:32:04 +02:00
|
|
|
TW_UINT16 sane_option_get_bool(const char *option_name, int *val)
|
2009-03-05 20:15:13 +01:00
|
|
|
{
|
2021-10-27 13:38:59 +02:00
|
|
|
struct option_descriptor opt;
|
|
|
|
TW_UINT16 rc = sane_find_option(option_name, TYPE_BOOL, &opt);
|
2009-03-05 20:15:13 +01:00
|
|
|
|
2021-10-27 13:38:59 +02:00
|
|
|
if (rc == TWCC_SUCCESS) rc = sane_option_get_value( opt.optno, val );
|
2021-10-25 17:32:04 +02:00
|
|
|
return rc;
|
2009-03-05 20:15:13 +01:00
|
|
|
}
|
|
|
|
|
2021-10-25 17:32:04 +02:00
|
|
|
TW_UINT16 sane_option_set_bool(const char *option_name, int val )
|
2009-03-05 20:15:13 +01:00
|
|
|
{
|
2021-10-27 13:38:59 +02:00
|
|
|
struct option_descriptor opt;
|
|
|
|
TW_UINT16 rc = sane_find_option(option_name, TYPE_BOOL, &opt);
|
2009-03-05 20:15:13 +01:00
|
|
|
|
2021-10-27 13:38:59 +02:00
|
|
|
if (rc == TWCC_SUCCESS) rc = sane_option_set_value( opt.optno, &val, NULL );
|
2021-10-25 17:32:04 +02:00
|
|
|
return rc;
|
2009-03-05 20:15:13 +01:00
|
|
|
}
|
|
|
|
|
2021-10-25 17:32:04 +02:00
|
|
|
TW_UINT16 sane_option_get_str(const char *option_name, char *val, int len)
|
2009-03-05 20:15:20 +01:00
|
|
|
{
|
2021-10-27 13:38:59 +02:00
|
|
|
struct option_descriptor opt;
|
|
|
|
TW_UINT16 rc = sane_find_option(option_name, TYPE_STRING, &opt);
|
2009-03-05 20:15:20 +01:00
|
|
|
|
2021-10-25 17:32:04 +02:00
|
|
|
if (rc == TWCC_SUCCESS)
|
|
|
|
{
|
2021-10-27 13:38:59 +02:00
|
|
|
if (opt.size < len)
|
|
|
|
rc = sane_option_get_value( opt.optno, val );
|
2021-10-25 17:32:04 +02:00
|
|
|
else
|
|
|
|
rc = TWCC_BADVALUE;
|
|
|
|
}
|
|
|
|
return rc;
|
2009-03-05 20:15:20 +01:00
|
|
|
}
|
2009-03-05 20:15:13 +01:00
|
|
|
|
2009-04-20 14:47:23 +02:00
|
|
|
/* Important: SANE has the side effect of overwriting val with the returned value */
|
2021-10-25 17:32:04 +02:00
|
|
|
TW_UINT16 sane_option_set_str(const char *option_name, char *val, BOOL *needs_reload)
|
2009-02-26 03:58:42 +01:00
|
|
|
{
|
2021-10-27 13:38:59 +02:00
|
|
|
struct option_descriptor opt;
|
|
|
|
TW_UINT16 rc = sane_find_option(option_name, TYPE_STRING, &opt);
|
2009-02-26 03:58:42 +01:00
|
|
|
|
2021-10-27 13:38:59 +02:00
|
|
|
if (rc == TWCC_SUCCESS) rc = sane_option_set_value( opt.optno, &val, needs_reload );
|
2021-10-25 17:32:04 +02:00
|
|
|
return rc;
|
2009-02-26 03:58:42 +01:00
|
|
|
}
|
|
|
|
|
2021-10-25 17:32:04 +02:00
|
|
|
TW_UINT16 sane_option_probe_resolution(const char *option_name, int *minval, int *maxval, int *quant)
|
2009-02-23 23:25:26 +01:00
|
|
|
{
|
2021-10-27 13:38:59 +02:00
|
|
|
struct option_descriptor opt;
|
|
|
|
TW_UINT16 rc = sane_find_option(option_name, TYPE_INT, &opt);
|
2009-02-23 23:25:26 +01:00
|
|
|
|
2021-10-25 17:32:04 +02:00
|
|
|
if (rc != TWCC_SUCCESS) return rc;
|
2021-10-27 13:38:59 +02:00
|
|
|
if (opt.constraint_type != CONSTRAINT_RANGE) return TWCC_CAPUNSUPPORTED;
|
2009-02-23 23:25:26 +01:00
|
|
|
|
2021-10-27 13:38:59 +02:00
|
|
|
*minval = opt.constraint.range.min;
|
|
|
|
*maxval = opt.constraint.range.max;
|
|
|
|
*quant = opt.constraint.range.quant;
|
2009-02-23 23:25:26 +01:00
|
|
|
return rc;
|
|
|
|
}
|
2009-02-26 03:58:42 +01:00
|
|
|
|
2021-10-27 13:38:59 +02:00
|
|
|
TW_UINT16 sane_option_probe_mode(TW_UINT16 *current, TW_UINT32 *choices, int *count)
|
2009-02-26 03:58:42 +01:00
|
|
|
{
|
2021-10-27 13:38:59 +02:00
|
|
|
WCHAR *p;
|
|
|
|
char buffer[256];
|
|
|
|
struct option_descriptor opt;
|
|
|
|
TW_UINT16 rc = sane_find_option("mode", TYPE_STRING, &opt);
|
2009-02-26 03:58:42 +01:00
|
|
|
|
2021-10-25 17:32:04 +02:00
|
|
|
if (rc != TWCC_SUCCESS) return rc;
|
2021-10-27 13:38:59 +02:00
|
|
|
if (opt.size > sizeof(buffer)) return TWCC_BADVALUE;
|
|
|
|
rc = sane_option_get_value( opt.optno, buffer );
|
|
|
|
if (rc != TWCC_SUCCESS) return rc;
|
2009-02-26 03:58:42 +01:00
|
|
|
|
2021-10-27 13:38:59 +02:00
|
|
|
if (!strcmp( buffer, "Lineart" )) *current = TWPT_BW;
|
|
|
|
else if (!strcmp( buffer, "Color" )) *current = TWPT_RGB;
|
|
|
|
else if (!strncmp( buffer, "Gray", 4 )) *current = TWPT_GRAY;
|
2009-02-26 03:58:42 +01:00
|
|
|
|
2021-10-27 13:38:59 +02:00
|
|
|
*count = 0;
|
|
|
|
if (opt.constraint_type == CONSTRAINT_STRING_LIST)
|
|
|
|
{
|
2021-10-27 16:59:23 +02:00
|
|
|
for (p = opt.constraint.strings; *p; p += lstrlenW(p) + 1)
|
2021-10-27 13:38:59 +02:00
|
|
|
{
|
2021-10-27 16:59:23 +02:00
|
|
|
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;
|
2021-10-27 13:38:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rc;
|
2009-02-26 03:58:42 +01:00
|
|
|
}
|
2009-03-05 20:15:06 +01:00
|
|
|
|
2021-10-25 18:34:53 +02:00
|
|
|
TW_UINT16 sane_option_get_scan_area( int *tlx, int *tly, int *brx, int *bry )
|
2009-03-05 20:15:06 +01:00
|
|
|
{
|
2021-10-25 18:34:53 +02:00
|
|
|
TW_UINT16 rc;
|
2021-10-27 13:38:59 +02:00
|
|
|
struct option_descriptor opt;
|
|
|
|
|
|
|
|
if ((rc = sane_find_option( "tl-x", TYPE_FIXED, &opt )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_option_get_value( opt.optno, tlx )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_find_option( "tl-y", TYPE_FIXED, &opt )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_option_get_value( opt.optno, tly )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_find_option( "br-x", TYPE_FIXED, &opt )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_option_get_value( opt.optno, brx )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_find_option( "br-y", TYPE_FIXED, &opt )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_option_get_value( opt.optno, bry )) != TWCC_SUCCESS) return rc;
|
|
|
|
if (opt.unit != UNIT_MM) FIXME( "unsupported unit %u\n", opt.unit );
|
2009-03-05 20:15:06 +01:00
|
|
|
return rc;
|
|
|
|
}
|
2009-03-10 21:48:18 +01:00
|
|
|
|
2021-10-25 18:34:53 +02:00
|
|
|
TW_UINT16 sane_option_get_max_scan_area( int *tlx, int *tly, int *brx, int *bry )
|
2009-03-10 21:48:18 +01:00
|
|
|
{
|
2021-10-25 18:34:53 +02:00
|
|
|
TW_UINT16 rc;
|
2021-10-27 13:38:59 +02:00
|
|
|
struct option_descriptor opt;
|
|
|
|
|
|
|
|
if ((rc = sane_find_option( "tl-x", TYPE_FIXED, &opt )) != TWCC_SUCCESS) return rc;
|
|
|
|
*tlx = opt.constraint.range.min;
|
|
|
|
if ((rc = sane_find_option( "tl-y", TYPE_FIXED, &opt )) != TWCC_SUCCESS) return rc;
|
|
|
|
*tly = opt.constraint.range.min;
|
|
|
|
if ((rc = sane_find_option( "br-x", TYPE_FIXED, &opt )) != TWCC_SUCCESS) return rc;
|
|
|
|
*brx = opt.constraint.range.max;
|
|
|
|
if ((rc = sane_find_option( "br-y", TYPE_FIXED, &opt )) != TWCC_SUCCESS) return rc;
|
|
|
|
*bry = opt.constraint.range.max;
|
|
|
|
if (opt.unit != UNIT_MM) FIXME( "unsupported unit %u\n", opt.unit );
|
2021-10-25 18:34:53 +02:00
|
|
|
return rc;
|
2009-03-10 21:48:18 +01:00
|
|
|
}
|
|
|
|
|
2021-10-25 18:34:53 +02:00
|
|
|
TW_UINT16 sane_option_set_scan_area( int tlx, int tly, int brx, int bry, BOOL *reload )
|
2009-03-10 21:48:18 +01:00
|
|
|
{
|
2021-10-25 18:34:53 +02:00
|
|
|
TW_UINT16 rc;
|
2021-10-27 13:38:59 +02:00
|
|
|
struct option_descriptor opt;
|
|
|
|
|
|
|
|
if ((rc = sane_find_option( "tl-x", TYPE_FIXED, &opt )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_option_set_value( opt.optno, &tlx, reload )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_find_option( "tl-y", TYPE_FIXED, &opt )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_option_set_value( opt.optno, &tly, reload )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_find_option( "br-x", TYPE_FIXED, &opt )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_option_set_value( opt.optno, &brx, reload )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_find_option( "br-y", TYPE_FIXED, &opt )) != TWCC_SUCCESS) return rc;
|
|
|
|
if ((rc = sane_option_set_value( opt.optno, &bry, reload )) != TWCC_SUCCESS) return rc;
|
2021-10-25 18:34:53 +02:00
|
|
|
return rc;
|
|
|
|
}
|
2009-03-10 21:48:18 +01:00
|
|
|
|
2021-10-25 18:34:53 +02:00
|
|
|
TW_FIX32 convert_sane_res_to_twain(int res)
|
|
|
|
{
|
|
|
|
TW_FIX32 value;
|
|
|
|
res = MulDiv( res, 10, 254 ); /* mm -> inch */
|
|
|
|
value.Whole = res / 65536;
|
|
|
|
value.Frac = res & 0xffff;
|
|
|
|
return value;
|
2009-03-10 21:48:18 +01:00
|
|
|
}
|
2021-10-27 13:25:00 +02:00
|
|
|
|
|
|
|
TW_UINT16 get_sane_params( struct frame_parameters *params )
|
|
|
|
{
|
2021-10-27 15:27:52 +02:00
|
|
|
return SANE_CALL( get_params, params );
|
2021-10-27 13:25:00 +02:00
|
|
|
}
|