push 3600ceb9798742c4473b49518e0ae238427fc4b7
[wine/hacks.git] / dlls / sane.ds / capability.c
blob615e4cb0b5fdf120ff90bf9610f734afab710853
1 /*
2 * Copyright 2000 Corel Corporation
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
19 #define NONAMELESSUNION
20 #define NONAMELESSSTRUCT
22 #include "config.h"
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "twain.h"
29 #include "sane_i.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(twain);
34 static TW_UINT16 SANE_ICAPXferMech (pTW_CAPABILITY pCapability, TW_UINT16 action);
36 TW_UINT16 SANE_SaneCapability (pTW_CAPABILITY pCapability, TW_UINT16 action)
38 TW_UINT16 twCC = TWCC_SUCCESS;
40 TRACE("capability=%d action=%d\n", pCapability->Cap, action);
42 switch (pCapability->Cap)
44 case CAP_DEVICEEVENT:
45 case CAP_ALARMS:
46 case CAP_ALARMVOLUME:
47 case ACAP_AUDIOFILEFORMAT:
48 case ACAP_XFERMECH:
49 case ICAP_AUTOMATICBORDERDETECTION:
50 case ICAP_AUTOMATICDESKEW:
51 case ICAP_AUTODISCARDBLANKPAGES:
52 case ICAP_AUTOMATICROTATE:
53 case ICAP_FLIPROTATION:
54 case CAP_AUTOMATICCAPTURE:
55 case CAP_TIMEBEFOREFIRSTCAPTURE:
56 case CAP_TIMEBETWEENCAPTURES:
57 case CAP_AUTOSCAN:
58 case CAP_CLEARBUFFERS:
59 case CAP_MAXBATCHBUFFERS:
60 case ICAP_BARCODEDETECTIONENABLED:
61 case ICAP_SUPPORTEDBARCODETYPES:
62 case ICAP_BARCODEMAXSEARCHPRIORITIES:
63 case ICAP_BARCODESEARCHPRIORITIES:
64 case ICAP_BARCODESEARCHMODE:
65 case ICAP_BARCODEMAXRETRIES:
66 case ICAP_BARCODETIMEOUT:
67 case CAP_EXTENDEDCAPS:
68 case CAP_SUPPORTEDCAPS:
69 case ICAP_FILTER:
70 case ICAP_GAMMA:
71 case ICAP_PLANARCHUNKY:
72 case ICAP_BITORDERCODES:
73 case ICAP_CCITTKFACTOR:
74 case ICAP_COMPRESSION:
75 case ICAP_JPEGPIXELTYPE:
76 /*case ICAP_JPEGQUALITY:*/
77 case ICAP_PIXELFLAVORCODES:
78 case ICAP_TIMEFILL:
79 case CAP_DEVICEONLINE:
80 case CAP_DEVICETIMEDATE:
81 case CAP_SERIALNUMBER:
82 case ICAP_EXPOSURETIME:
83 case ICAP_FLASHUSED2:
84 case ICAP_IMAGEFILTER:
85 case ICAP_LAMPSTATE:
86 case ICAP_LIGHTPATH:
87 case ICAP_NOISEFILTER:
88 case ICAP_OVERSCAN:
89 case ICAP_PHYSICALHEIGHT:
90 case ICAP_PHYSICALWIDTH:
91 case ICAP_UNITS:
92 case ICAP_ZOOMFACTOR:
93 case CAP_PRINTER:
94 case CAP_PRINTERENABLED:
95 case CAP_PRINTERINDEX:
96 case CAP_PRINTERMODE:
97 case CAP_PRINTERSTRING:
98 case CAP_PRINTERSUFFIX:
99 case CAP_AUTHOR:
100 case CAP_CAPTION:
101 case CAP_TIMEDATE:
102 case ICAP_AUTOBRIGHT:
103 case ICAP_BRIGHTNESS:
104 case ICAP_CONTRAST:
105 case ICAP_HIGHLIGHT:
106 case ICAP_ORIENTATION:
107 case ICAP_ROTATION:
108 case ICAP_SHADOW:
109 case ICAP_XSCALING:
110 case ICAP_YSCALING:
111 case ICAP_BITDEPTH:
112 case ICAP_BITDEPTHREDUCTION:
113 case ICAP_BITORDER:
114 case ICAP_CUSTHALFTONE:
115 case ICAP_HALFTONES:
116 case ICAP_PIXELFLAVOR:
117 case ICAP_PIXELTYPE:
118 case ICAP_THRESHOLD:
119 case CAP_LANGUAGE:
120 case ICAP_FRAMES:
121 case ICAP_MAXFRAMES:
122 case ICAP_SUPPORTEDSIZES:
123 case CAP_AUTOFEED:
124 case CAP_CLEARPAGE:
125 case CAP_FEEDERALIGNMENT:
126 case CAP_FEEDERENABLED:
127 case CAP_FEEDERLOADED:
128 case CAP_FEEDERORDER:
129 case CAP_FEEDPAGE:
130 case CAP_PAPERBINDING:
131 case CAP_PAPERDETECTABLE:
132 case CAP_REACQUIREALLOWED:
133 case CAP_REWINDPAGE:
134 case ICAP_PATCHCODEDETECTIONENABLED:
135 case ICAP_SUPPORTEDPATCHCODETYPES:
136 case ICAP_PATCHCODEMAXSEARCHPRIORITIES:
137 case ICAP_PATCHCODESEARCHPRIORITIES:
138 case ICAP_PATCHCODESEARCHMODE:
139 case ICAP_PATCHCODEMAXRETRIES:
140 case ICAP_PATCHCODETIMEOUT:
141 case CAP_BATTERYMINUTES:
142 case CAP_BATTERYPERCENTAGE:
143 case CAP_POWERDOWNTIME:
144 case CAP_POWERSUPPLY:
145 case ICAP_XNATIVERESOLUTION:
146 case ICAP_XRESOLUTION:
147 case ICAP_YNATIVERESOLUTION:
148 case ICAP_YRESOLUTION:
149 twCC = TWCC_CAPUNSUPPORTED;
150 break;
151 case CAP_XFERCOUNT:
152 /* This is a required capability that every source needs to
153 support but we haven't implemented it yet. */
154 twCC = TWCC_SUCCESS;
155 break;
156 /*case ICAP_COMPRESSION:*/
157 case ICAP_IMAGEFILEFORMAT:
158 case ICAP_TILES:
159 twCC = TWCC_CAPUNSUPPORTED;
160 break;
161 case ICAP_XFERMECH:
162 twCC = SANE_ICAPXferMech (pCapability, action);
163 break;
164 case ICAP_UNDEFINEDIMAGESIZE:
165 case CAP_CAMERAPREVIEWUI:
166 case CAP_ENABLEDSUIONLY:
167 case CAP_INDICATORS:
168 case CAP_UICONTROLLABLE:
169 twCC = TWCC_CAPUNSUPPORTED;
170 break;
171 default:
172 twCC = TWRC_FAILURE;
176 return twCC;
179 static TW_BOOL TWAIN_OneValueSet (pTW_CAPABILITY pCapability, TW_UINT32 value)
181 pCapability->hContainer = GlobalAlloc (0, sizeof(TW_ONEVALUE));
183 if (pCapability->hContainer)
185 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
186 pVal->ItemType = TWTY_UINT32;
187 pVal->Item = value;
188 GlobalUnlock (pCapability->hContainer);
189 return TRUE;
191 else
192 return FALSE;
195 static TW_BOOL TWAIN_OneValueGet (pTW_CAPABILITY pCapability, TW_UINT32 *pValue)
197 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
199 if (pVal)
201 *pValue = pVal->Item;
202 GlobalUnlock (pCapability->hContainer);
203 return TRUE;
205 else
206 return FALSE;
209 /* ICAP_XFERMECH */
210 static TW_UINT16 SANE_ICAPXferMech (pTW_CAPABILITY pCapability, TW_UINT16 action)
212 TRACE("ICAP_XFERMECH\n");
214 switch (action)
216 case MSG_GET:
217 if (pCapability->ConType == TWON_ONEVALUE)
219 if (!TWAIN_OneValueSet (pCapability, activeDS.capXferMech))
220 return TWCC_LOWMEMORY;
222 break;
223 case MSG_SET:
224 if (pCapability->ConType == TWON_ONEVALUE)
226 TW_UINT32 xfermechtemp = 0;
227 if (!TWAIN_OneValueGet (pCapability, &xfermechtemp))
228 return TWCC_LOWMEMORY;
229 activeDS.capXferMech = xfermechtemp;
231 else if (pCapability->ConType == TWON_ENUMERATION)
235 break;
236 case MSG_GETCURRENT:
237 if (!TWAIN_OneValueSet (pCapability, activeDS.capXferMech))
238 return TWCC_LOWMEMORY;
239 break;
240 case MSG_GETDEFAULT:
241 if (!TWAIN_OneValueSet (pCapability, TWSX_NATIVE))
242 return TWCC_LOWMEMORY;
243 break;
244 case MSG_RESET:
245 activeDS.capXferMech = TWSX_NATIVE;
246 break;
248 return TWCC_SUCCESS;