2 * Copyright 2009 Jeremy White <jwhite@codeweavers.com> for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
29 static SANE_Status
sane_find_option(SANE_Handle h
, const char *option_name
,
30 const SANE_Option_Descriptor
**opt_p
, int *optno
, SANE_Value_Type type
)
34 const SANE_Option_Descriptor
*opt
;
37 rc
= psane_control_option(h
, 0, SANE_ACTION_GET_VALUE
, &optcount
, NULL
);
38 if (rc
!= SANE_STATUS_GOOD
)
41 for (i
= 1; i
< optcount
; i
++)
43 opt
= psane_get_option_descriptor(h
, i
);
44 if (opt
&& (opt
->name
&& strcmp(opt
->name
, option_name
) == 0) &&
49 return SANE_STATUS_GOOD
;
52 return SANE_STATUS_EOF
;
55 SANE_Status
sane_option_get_int(SANE_Handle h
, const char *option_name
, SANE_Int
*val
)
59 const SANE_Option_Descriptor
*opt
;
61 rc
= sane_find_option(h
, option_name
, &opt
, &optno
, SANE_TYPE_INT
);
62 if (rc
!= SANE_STATUS_GOOD
)
65 return psane_control_option(h
, optno
, SANE_ACTION_GET_VALUE
, val
, NULL
);
68 SANE_Status
sane_option_set_int(SANE_Handle h
, const char *option_name
, SANE_Int val
, SANE_Int
*status
)
72 const SANE_Option_Descriptor
*opt
;
74 rc
= sane_find_option(h
, option_name
, &opt
, &optno
, SANE_TYPE_INT
);
75 if (rc
!= SANE_STATUS_GOOD
)
78 return psane_control_option(h
, optno
, SANE_ACTION_SET_VALUE
, (void *) &val
, status
);
81 SANE_Status
sane_option_probe_resolution(SANE_Handle h
, const char *option_name
, SANE_Int
*minval
, SANE_Int
*maxval
, SANE_Int
*quant
)
85 const SANE_Option_Descriptor
*opt
;
87 rc
= sane_find_option(h
, option_name
, &opt
, &optno
, SANE_TYPE_INT
);
88 if (rc
!= SANE_STATUS_GOOD
)
91 if (opt
->constraint_type
!= SANE_CONSTRAINT_RANGE
)
92 return SANE_STATUS_UNSUPPORTED
;
94 *minval
= opt
->constraint
.range
->min
;
95 *maxval
= opt
->constraint
.range
->max
;
96 *quant
= opt
->constraint
.range
->quant
;