wer: Add new stubbed wer.dll.
[wine/hramrach.git] / dlls / gphoto2.ds / capability.c
blob378ef2a0358c7dbff81696232e05ce80a5d68776
1 /*
2 * Copyright 2000 Corel Corporation
3 * Copyright 2006 Marcus Meissner
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
23 #include "config.h"
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "twain.h"
30 #include "gphoto2_i.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(twain);
35 static TW_UINT16 GPHOTO2_ICAPXferMech (pTW_CAPABILITY,TW_UINT16);
36 static TW_UINT16 GPHOTO2_ICAPPixelType (pTW_CAPABILITY,TW_UINT16);
37 static TW_UINT16 GPHOTO2_ICAPPixelFlavor (pTW_CAPABILITY,TW_UINT16);
38 static TW_UINT16 GPHOTO2_ICAPBitDepth (pTW_CAPABILITY,TW_UINT16);
39 static TW_UINT16 GPHOTO2_ICAPUnits (pTW_CAPABILITY,TW_UINT16);
41 TW_UINT16 GPHOTO2_SaneCapability (pTW_CAPABILITY pCapability, TW_UINT16 action)
43 TW_UINT16 twCC = TWCC_SUCCESS;
45 TRACE("capability=%d action=%d\n", pCapability->Cap, action);
47 switch (pCapability->Cap)
49 case CAP_DEVICEEVENT:
50 case CAP_ALARMS:
51 case CAP_ALARMVOLUME:
52 case ACAP_AUDIOFILEFORMAT:
53 case ACAP_XFERMECH:
54 case ICAP_AUTOMATICBORDERDETECTION:
55 case ICAP_AUTOMATICDESKEW:
56 case ICAP_AUTODISCARDBLANKPAGES:
57 case ICAP_AUTOMATICROTATE:
58 case ICAP_FLIPROTATION:
59 case CAP_AUTOMATICCAPTURE:
60 case CAP_TIMEBEFOREFIRSTCAPTURE:
61 case CAP_TIMEBETWEENCAPTURES:
62 case CAP_AUTOSCAN:
63 case CAP_CLEARBUFFERS:
64 case CAP_MAXBATCHBUFFERS:
65 case ICAP_BARCODEDETECTIONENABLED:
66 case ICAP_SUPPORTEDBARCODETYPES:
67 case ICAP_BARCODEMAXSEARCHPRIORITIES:
68 case ICAP_BARCODESEARCHPRIORITIES:
69 case ICAP_BARCODESEARCHMODE:
70 case ICAP_BARCODEMAXRETRIES:
71 case ICAP_BARCODETIMEOUT:
72 case CAP_EXTENDEDCAPS:
73 case CAP_SUPPORTEDCAPS:
74 case ICAP_FILTER:
75 case ICAP_GAMMA:
76 case ICAP_PLANARCHUNKY:
77 case ICAP_BITORDERCODES:
78 case ICAP_CCITTKFACTOR:
79 case ICAP_JPEGPIXELTYPE:
80 /*case ICAP_JPEGQUALITY:*/
81 case ICAP_PIXELFLAVORCODES:
82 case ICAP_TIMEFILL:
83 case CAP_DEVICEONLINE:
84 case CAP_DEVICETIMEDATE:
85 case CAP_SERIALNUMBER:
86 case ICAP_EXPOSURETIME:
87 case ICAP_FLASHUSED2:
88 case ICAP_IMAGEFILTER:
89 case ICAP_LAMPSTATE:
90 case ICAP_LIGHTPATH:
91 case ICAP_NOISEFILTER:
92 case ICAP_OVERSCAN:
93 case ICAP_PHYSICALHEIGHT:
94 case ICAP_PHYSICALWIDTH:
95 case ICAP_ZOOMFACTOR:
96 case CAP_PRINTER:
97 case CAP_PRINTERENABLED:
98 case CAP_PRINTERINDEX:
99 case CAP_PRINTERMODE:
100 case CAP_PRINTERSTRING:
101 case CAP_PRINTERSUFFIX:
102 case CAP_AUTHOR:
103 case CAP_CAPTION:
104 case CAP_TIMEDATE:
105 case ICAP_AUTOBRIGHT:
106 case ICAP_BRIGHTNESS:
107 case ICAP_CONTRAST:
108 case ICAP_HIGHLIGHT:
109 case ICAP_ORIENTATION:
110 case ICAP_ROTATION:
111 case ICAP_SHADOW:
112 case ICAP_XSCALING:
113 case ICAP_YSCALING:
114 case ICAP_BITDEPTHREDUCTION:
115 case ICAP_BITORDER:
116 case ICAP_CUSTHALFTONE:
117 case ICAP_HALFTONES:
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 need to
153 support but we haven't implemented 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 = GPHOTO2_ICAPXferMech (pCapability, action);
163 break;
164 case ICAP_PIXELTYPE:
165 twCC = GPHOTO2_ICAPPixelType (pCapability, action);
166 break;
167 case ICAP_PIXELFLAVOR:
168 twCC = GPHOTO2_ICAPPixelFlavor (pCapability, action);
169 break;
170 case ICAP_BITDEPTH:
171 twCC = GPHOTO2_ICAPBitDepth (pCapability, action);
172 break;
173 case ICAP_UNITS:
174 twCC = GPHOTO2_ICAPUnits (pCapability, action);
175 break;
176 case ICAP_UNDEFINEDIMAGESIZE:
177 case CAP_CAMERAPREVIEWUI:
178 case CAP_ENABLEDSUIONLY:
179 case CAP_INDICATORS:
180 case CAP_UICONTROLLABLE:
181 twCC = TWCC_CAPUNSUPPORTED;
182 break;
184 case ICAP_COMPRESSION:
185 twCC = TWCC_SUCCESS;
186 break;
187 default:
188 twCC = TWRC_FAILURE;
189 break;
191 return twCC;
194 static TW_BOOL GPHOTO2_OneValueSet32 (pTW_CAPABILITY pCapability, TW_UINT32 value)
196 pCapability->hContainer = GlobalAlloc (0, sizeof(TW_ONEVALUE));
198 TRACE("-> %d\n", value);
200 if (pCapability->hContainer)
202 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
203 pVal->ItemType = TWTY_UINT32;
204 pVal->Item = value;
205 GlobalUnlock (pCapability->hContainer);
206 pCapability->ConType = TWON_ONEVALUE;
207 return TRUE;
209 else
210 return FALSE;
213 static TW_BOOL GPHOTO2_OneValueSet16 (pTW_CAPABILITY pCapability, TW_UINT16 value)
215 pCapability->hContainer = GlobalAlloc (0, sizeof(TW_ONEVALUE));
217 TRACE("-> %d\n", value);
219 if (pCapability->hContainer)
221 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
222 pVal->ItemType = TWTY_UINT16;
223 pVal->Item = value;
224 GlobalUnlock (pCapability->hContainer);
225 pCapability->ConType = TWON_ONEVALUE;
226 return TRUE;
228 else
229 return FALSE;
232 static TW_BOOL GPHOTO2_EnumSet16 (pTW_CAPABILITY pCapability, int nrofvalues,
233 const TW_UINT16 *values, int current, int def)
235 pTW_ENUMERATION pVal;
236 pCapability->hContainer = GlobalAlloc (0, sizeof(TW_ENUMERATION) + nrofvalues * sizeof(TW_UINT16));
238 if (!pCapability->hContainer)
239 return FALSE;
241 pVal = GlobalLock (pCapability->hContainer);
242 pVal->ItemType = TWTY_UINT16;
243 pVal->NumItems = nrofvalues;
244 memcpy(pVal->ItemList, values, sizeof(TW_UINT16)*nrofvalues);
245 pVal->CurrentIndex = current;
246 pVal->DefaultIndex = def;
247 pCapability->ConType = TWON_ENUMERATION;
248 GlobalUnlock (pCapability->hContainer);
249 return TRUE;
252 static TW_BOOL GPHOTO2_EnumGet16 (pTW_CAPABILITY pCapability, int *nrofvalues, TW_UINT16 **values)
254 pTW_ENUMERATION pVal = GlobalLock (pCapability->hContainer);
256 if (!pVal)
257 return FALSE;
258 *nrofvalues = pVal->NumItems;
259 *values = HeapAlloc( GetProcessHeap(), 0, sizeof(TW_UINT16)*pVal->NumItems);
260 memcpy (*values, pVal->ItemList, sizeof(TW_UINT16)*(*nrofvalues));
261 FIXME("Current Index %d, Default Index %d\n", pVal->CurrentIndex, pVal->DefaultIndex);
262 GlobalUnlock (pCapability->hContainer);
263 return TRUE;
266 static TW_BOOL GPHOTO2_OneValueGet32 (pTW_CAPABILITY pCapability, TW_UINT32 *pValue)
268 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
270 if (pVal)
272 *pValue = pVal->Item;
273 GlobalUnlock (pCapability->hContainer);
274 return TRUE;
276 else
277 return FALSE;
280 static TW_BOOL GPHOTO2_OneValueGet16 (pTW_CAPABILITY pCapability, TW_UINT16 *pValue)
282 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
284 if (pVal)
286 *pValue = pVal->Item;
287 GlobalUnlock (pCapability->hContainer);
288 return TRUE;
290 else
291 return FALSE;
294 /* ICAP_XFERMECH */
295 static TW_UINT16 GPHOTO2_ICAPXferMech (pTW_CAPABILITY pCapability, TW_UINT16 action)
297 TRACE("ICAP_XFERMECH, action %d\n", action);
299 switch (action)
301 case MSG_GET:
302 if (!GPHOTO2_OneValueSet32 (pCapability, activeDS.capXferMech))
303 return TWCC_LOWMEMORY;
304 return TWCC_SUCCESS;
305 case MSG_SET:
306 if (pCapability->ConType == TWON_ONEVALUE)
308 TW_UINT32 xfermechtemp = 0;
310 if (!GPHOTO2_OneValueGet32 (pCapability, &xfermechtemp))
311 return TWCC_LOWMEMORY;
312 activeDS.capXferMech = xfermechtemp;
313 TRACE("xfermech is %d\n", xfermechtemp);
314 return TWCC_SUCCESS;
316 else if (pCapability->ConType == TWON_ENUMERATION)
320 FIXME("GET FAILED\n");
321 break;
322 case MSG_GETCURRENT:
323 if (!GPHOTO2_OneValueSet32 (pCapability, activeDS.capXferMech))
324 return TWCC_LOWMEMORY;
325 break;
326 case MSG_GETDEFAULT:
327 if (!GPHOTO2_OneValueSet32 (pCapability, TWSX_NATIVE))
328 return TWCC_LOWMEMORY;
329 break;
330 case MSG_RESET:
331 activeDS.capXferMech = TWSX_NATIVE;
332 break;
334 return TWCC_SUCCESS;
337 /* ICAP_PIXELTYPE */
338 static TW_UINT16 GPHOTO2_ICAPPixelType (pTW_CAPABILITY pCapability, TW_UINT16 action)
340 TRACE("Action %d\n", action);
342 switch (action)
344 case MSG_GET:
345 if ((pCapability->ConType == TWON_DONTCARE16) ||
346 (pCapability->ConType == TWON_ONEVALUE)
348 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixeltype))
349 return TWCC_LOWMEMORY;
350 return TWCC_SUCCESS;
352 FIXME("Unknown container type %x in MSG_GET\n", pCapability->ConType);
353 return TWCC_CAPBADOPERATION;
354 case MSG_SET:
355 if (pCapability->ConType == TWON_ONEVALUE)
357 TW_UINT16 pixeltype = 0;
359 if (!GPHOTO2_OneValueGet16 (pCapability, &pixeltype))
360 return TWCC_LOWMEMORY;
361 activeDS.pixeltype = pixeltype;
362 FIXME("pixeltype changed to %d!\n", pixeltype);
363 return TWCC_SUCCESS;
365 FIXME("set not done\n");
366 if (pCapability->ConType == TWON_ENUMERATION) {
367 TW_UINT16 *values = NULL;
368 int i, nrofvalues = 0;
370 if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
371 return TWCC_LOWMEMORY;
372 for (i=0;i<nrofvalues;i++)
373 FIXME("SET PixelType %d:%d\n", i, values[i]);
374 HeapFree (GetProcessHeap(), 0, values);
376 break;
377 case MSG_GETCURRENT:
378 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixeltype)) {
379 FIXME("Failed one value set in GETCURRENT, contype %d!\n", pCapability->ConType);
380 return TWCC_LOWMEMORY;
382 break;
383 case MSG_GETDEFAULT:
384 if (!GPHOTO2_OneValueSet16 (pCapability, TWPT_RGB)) {
385 FIXME("Failed onevalue set in GETDEFAULT!\n");
386 return TWCC_LOWMEMORY;
388 break;
389 case MSG_RESET:
390 activeDS.pixeltype = TWPT_RGB;
391 break;
393 return TWCC_SUCCESS;
396 /* ICAP_PIXELFLAVOR */
397 static TW_UINT16 GPHOTO2_ICAPPixelFlavor (pTW_CAPABILITY pCapability, TW_UINT16 action)
399 TRACE("Action %d\n", action);
401 switch (action)
403 case MSG_GET:
404 if ((pCapability->ConType == TWON_DONTCARE16) ||
405 (pCapability->ConType == TWON_ONEVALUE)
407 if (!GPHOTO2_OneValueSet16 (pCapability, TWPF_CHOCOLATE))
408 return TWCC_LOWMEMORY;
409 return TWCC_SUCCESS;
411 if (!pCapability->ConType) {
412 TW_UINT16 arr[2];
413 arr[0] = TWPF_CHOCOLATE;
414 arr[1] = TWPF_VANILLA;
416 if (!GPHOTO2_EnumSet16 (pCapability, 2, arr, 1, 1))
417 return TWCC_LOWMEMORY;
418 return TWCC_SUCCESS;
420 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
421 return TWCC_BADVALUE;
422 case MSG_SET:
423 if (pCapability->ConType == TWON_ONEVALUE)
425 TW_UINT16 pixelflavor = 0;
427 if (!GPHOTO2_OneValueGet16 (pCapability, &pixelflavor))
428 return TWCC_LOWMEMORY;
429 activeDS.pixelflavor = pixelflavor;
430 FIXME("pixelflavor is %d\n", pixelflavor);
432 break;
433 case MSG_GETCURRENT:
434 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixelflavor))
435 return TWCC_LOWMEMORY;
436 break;
437 case MSG_GETDEFAULT:
438 if (!GPHOTO2_OneValueSet16 (pCapability, TWPF_CHOCOLATE))
439 return TWCC_LOWMEMORY;
440 break;
441 case MSG_RESET:
442 break;
444 return TWCC_SUCCESS;
447 /* ICAP_BITDEPTH */
448 static TW_UINT16 GPHOTO2_ICAPBitDepth (pTW_CAPABILITY pCapability, TW_UINT16 action)
450 TRACE("Action %d\n", action);
452 switch (action)
454 case MSG_GET:
455 if ((pCapability->ConType == TWON_DONTCARE16) ||
456 (pCapability->ConType == TWON_ONEVALUE)
458 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
459 return TWCC_LOWMEMORY;
460 return TWCC_SUCCESS;
462 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
463 return TWCC_SUCCESS;
464 case MSG_SET:
465 if (pCapability->ConType == TWON_ONEVALUE) {
466 TW_UINT16 bitdepth = 0;
468 if (!GPHOTO2_OneValueGet16 (pCapability, &bitdepth))
469 return TWCC_LOWMEMORY;
470 if (bitdepth != 24)
471 return TWCC_BADVALUE;
472 return TWCC_SUCCESS;
474 if (pCapability->ConType == TWON_ENUMERATION)
476 int i, nrofvalues = 0;
477 TW_UINT16 *values = NULL;
479 if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
480 return TWCC_LOWMEMORY;
481 for (i=0;i<nrofvalues;i++)
482 FIXME("SET: enum element %d = %d\n", i, values[i]);
483 HeapFree (GetProcessHeap(), 0, values);
484 return TWCC_SUCCESS;
486 FIXME("Unhandled container type %d in MSG_SET\n", pCapability->ConType);
487 break;
488 case MSG_GETCURRENT:
489 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
490 return TWCC_LOWMEMORY;
491 break;
492 case MSG_GETDEFAULT:
493 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
494 return TWCC_LOWMEMORY;
495 break;
496 case MSG_RESET:
497 break;
499 return TWCC_SUCCESS;
502 /* ICAP_UNITS */
503 static TW_UINT16 GPHOTO2_ICAPUnits (pTW_CAPABILITY pCapability, TW_UINT16 action)
505 TRACE("Action %d\n", action);
507 switch (action)
509 case MSG_GET:
510 if ((pCapability->ConType == TWON_DONTCARE16) ||
511 (pCapability->ConType == TWON_ONEVALUE)
513 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_PIXELS))
514 return TWCC_LOWMEMORY;
515 return TWCC_SUCCESS;
517 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
518 return TWCC_SUCCESS;
519 case MSG_SET:
520 if (pCapability->ConType == TWON_ONEVALUE) {
521 TW_UINT16 units = 0;
523 if (!GPHOTO2_OneValueGet16 (pCapability, &units))
524 return TWCC_LOWMEMORY;
525 FIXME("SET to type %d, stub.\n", units);
526 return TWCC_SUCCESS;
528 if (pCapability->ConType == TWON_ENUMERATION)
530 int i, nrofvalues = 0;
531 TW_UINT16 *values = NULL;
533 if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
534 return TWCC_LOWMEMORY;
535 for (i=0;i<nrofvalues;i++)
536 FIXME("SET: enum element %d = %d\n", i, values[i]);
537 HeapFree (GetProcessHeap(), 0, values);
538 return TWCC_SUCCESS;
540 FIXME("Unhandled container type %d in MSG_SET\n", pCapability->ConType);
541 break;
542 case MSG_GETCURRENT:
543 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_INCHES))
544 return TWCC_LOWMEMORY;
545 break;
546 case MSG_GETDEFAULT:
547 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_PIXELS))
548 return TWCC_LOWMEMORY;
549 break;
550 case MSG_RESET:
551 break;
553 return TWCC_SUCCESS;