kernelbase: Let GetModuleBaseName succeed on 64bit modules in wow64.
[wine.git] / dlls / gphoto2.ds / capability.c
blobdbbf2a04855f129a8c467846d745cacb81045ef2
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 #include <stdarg.h>
22 #include "gphoto2_i.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(twain);
27 static TW_UINT16 GPHOTO2_ICAPXferMech (pTW_CAPABILITY,TW_UINT16);
28 static TW_UINT16 GPHOTO2_ICAPPixelType (pTW_CAPABILITY,TW_UINT16);
29 static TW_UINT16 GPHOTO2_ICAPPixelFlavor (pTW_CAPABILITY,TW_UINT16);
30 static TW_UINT16 GPHOTO2_ICAPBitDepth (pTW_CAPABILITY,TW_UINT16);
31 static TW_UINT16 GPHOTO2_ICAPUnits (pTW_CAPABILITY,TW_UINT16);
33 TW_UINT16 GPHOTO2_SaneCapability (pTW_CAPABILITY pCapability, TW_UINT16 action)
35 TW_UINT16 twCC = TWCC_SUCCESS;
37 TRACE("capability=%d action=%d\n", pCapability->Cap, action);
39 switch (pCapability->Cap)
41 case CAP_DEVICEEVENT:
42 case CAP_ALARMS:
43 case CAP_ALARMVOLUME:
44 case ACAP_AUDIOFILEFORMAT:
45 case ACAP_XFERMECH:
46 case ICAP_AUTOMATICBORDERDETECTION:
47 case ICAP_AUTOMATICDESKEW:
48 case ICAP_AUTODISCARDBLANKPAGES:
49 case ICAP_AUTOMATICROTATE:
50 case ICAP_FLIPROTATION:
51 case CAP_AUTOMATICCAPTURE:
52 case CAP_TIMEBEFOREFIRSTCAPTURE:
53 case CAP_TIMEBETWEENCAPTURES:
54 case CAP_AUTOSCAN:
55 case CAP_CLEARBUFFERS:
56 case CAP_MAXBATCHBUFFERS:
57 case ICAP_BARCODEDETECTIONENABLED:
58 case ICAP_SUPPORTEDBARCODETYPES:
59 case ICAP_BARCODEMAXSEARCHPRIORITIES:
60 case ICAP_BARCODESEARCHPRIORITIES:
61 case ICAP_BARCODESEARCHMODE:
62 case ICAP_BARCODEMAXRETRIES:
63 case ICAP_BARCODETIMEOUT:
64 case CAP_EXTENDEDCAPS:
65 case CAP_SUPPORTEDCAPS:
66 case ICAP_FILTER:
67 case ICAP_GAMMA:
68 case ICAP_PLANARCHUNKY:
69 case ICAP_BITORDERCODES:
70 case ICAP_CCITTKFACTOR:
71 case ICAP_JPEGPIXELTYPE:
72 /*case ICAP_JPEGQUALITY:*/
73 case ICAP_PIXELFLAVORCODES:
74 case ICAP_TIMEFILL:
75 case CAP_DEVICEONLINE:
76 case CAP_DEVICETIMEDATE:
77 case CAP_SERIALNUMBER:
78 case ICAP_EXPOSURETIME:
79 case ICAP_FLASHUSED2:
80 case ICAP_IMAGEFILTER:
81 case ICAP_LAMPSTATE:
82 case ICAP_LIGHTPATH:
83 case ICAP_NOISEFILTER:
84 case ICAP_OVERSCAN:
85 case ICAP_PHYSICALHEIGHT:
86 case ICAP_PHYSICALWIDTH:
87 case ICAP_ZOOMFACTOR:
88 case CAP_PRINTER:
89 case CAP_PRINTERENABLED:
90 case CAP_PRINTERINDEX:
91 case CAP_PRINTERMODE:
92 case CAP_PRINTERSTRING:
93 case CAP_PRINTERSUFFIX:
94 case CAP_AUTHOR:
95 case CAP_CAPTION:
96 case CAP_TIMEDATE:
97 case ICAP_AUTOBRIGHT:
98 case ICAP_BRIGHTNESS:
99 case ICAP_CONTRAST:
100 case ICAP_HIGHLIGHT:
101 case ICAP_ORIENTATION:
102 case ICAP_ROTATION:
103 case ICAP_SHADOW:
104 case ICAP_XSCALING:
105 case ICAP_YSCALING:
106 case ICAP_BITDEPTHREDUCTION:
107 case ICAP_BITORDER:
108 case ICAP_CUSTHALFTONE:
109 case ICAP_HALFTONES:
110 case ICAP_THRESHOLD:
111 case CAP_LANGUAGE:
112 case ICAP_FRAMES:
113 case ICAP_MAXFRAMES:
114 case ICAP_SUPPORTEDSIZES:
115 case CAP_AUTOFEED:
116 case CAP_CLEARPAGE:
117 case CAP_FEEDERALIGNMENT:
118 case CAP_FEEDERENABLED:
119 case CAP_FEEDERLOADED:
120 case CAP_FEEDERORDER:
121 case CAP_FEEDPAGE:
122 case CAP_PAPERBINDING:
123 case CAP_PAPERDETECTABLE:
124 case CAP_REACQUIREALLOWED:
125 case CAP_REWINDPAGE:
126 case ICAP_PATCHCODEDETECTIONENABLED:
127 case ICAP_SUPPORTEDPATCHCODETYPES:
128 case ICAP_PATCHCODEMAXSEARCHPRIORITIES:
129 case ICAP_PATCHCODESEARCHPRIORITIES:
130 case ICAP_PATCHCODESEARCHMODE:
131 case ICAP_PATCHCODEMAXRETRIES:
132 case ICAP_PATCHCODETIMEOUT:
133 case CAP_BATTERYMINUTES:
134 case CAP_BATTERYPERCENTAGE:
135 case CAP_POWERDOWNTIME:
136 case CAP_POWERSUPPLY:
137 case ICAP_XNATIVERESOLUTION:
138 case ICAP_XRESOLUTION:
139 case ICAP_YNATIVERESOLUTION:
140 case ICAP_YRESOLUTION:
141 twCC = TWCC_CAPUNSUPPORTED;
142 break;
143 case CAP_XFERCOUNT:
144 /* This is a required capability that every source need to
145 support but we haven't implemented yet. */
146 twCC = TWCC_SUCCESS;
147 break;
148 /*case ICAP_COMPRESSION:*/
149 case ICAP_IMAGEFILEFORMAT:
150 case ICAP_TILES:
151 twCC = TWCC_CAPUNSUPPORTED;
152 break;
153 case ICAP_XFERMECH:
154 twCC = GPHOTO2_ICAPXferMech (pCapability, action);
155 break;
156 case ICAP_PIXELTYPE:
157 twCC = GPHOTO2_ICAPPixelType (pCapability, action);
158 break;
159 case ICAP_PIXELFLAVOR:
160 twCC = GPHOTO2_ICAPPixelFlavor (pCapability, action);
161 break;
162 case ICAP_BITDEPTH:
163 twCC = GPHOTO2_ICAPBitDepth (pCapability, action);
164 break;
165 case ICAP_UNITS:
166 twCC = GPHOTO2_ICAPUnits (pCapability, action);
167 break;
168 case ICAP_UNDEFINEDIMAGESIZE:
169 case CAP_CAMERAPREVIEWUI:
170 case CAP_ENABLEDSUIONLY:
171 case CAP_INDICATORS:
172 case CAP_UICONTROLLABLE:
173 twCC = TWCC_CAPUNSUPPORTED;
174 break;
176 case ICAP_COMPRESSION:
177 twCC = TWCC_SUCCESS;
178 break;
179 default:
180 twCC = TWRC_FAILURE;
181 break;
183 return twCC;
186 static TW_BOOL GPHOTO2_OneValueSet32 (pTW_CAPABILITY pCapability, TW_UINT32 value)
188 pCapability->hContainer = GlobalAlloc (0, sizeof(TW_ONEVALUE));
190 TRACE("-> %ld\n", value);
192 if (pCapability->hContainer)
194 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
195 pVal->ItemType = TWTY_UINT32;
196 pVal->Item = value;
197 GlobalUnlock (pCapability->hContainer);
198 pCapability->ConType = TWON_ONEVALUE;
199 return TRUE;
201 else
202 return FALSE;
205 static TW_BOOL GPHOTO2_OneValueSet16 (pTW_CAPABILITY pCapability, TW_UINT16 value)
207 pCapability->hContainer = GlobalAlloc (0, sizeof(TW_ONEVALUE));
209 TRACE("-> %d\n", value);
211 if (pCapability->hContainer)
213 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
214 pVal->ItemType = TWTY_UINT16;
215 pVal->Item = value;
216 GlobalUnlock (pCapability->hContainer);
217 pCapability->ConType = TWON_ONEVALUE;
218 return TRUE;
220 else
221 return FALSE;
224 static TW_BOOL GPHOTO2_EnumSet16 (pTW_CAPABILITY pCapability, int nrofvalues,
225 const TW_UINT16 *values, int current, int def)
227 pTW_ENUMERATION pVal;
228 pCapability->hContainer = GlobalAlloc (0, sizeof(TW_ENUMERATION) + nrofvalues * sizeof(TW_UINT16));
230 if (!pCapability->hContainer)
231 return FALSE;
233 pVal = GlobalLock (pCapability->hContainer);
234 pVal->ItemType = TWTY_UINT16;
235 pVal->NumItems = nrofvalues;
236 memcpy(pVal->ItemList, values, sizeof(TW_UINT16)*nrofvalues);
237 pVal->CurrentIndex = current;
238 pVal->DefaultIndex = def;
239 pCapability->ConType = TWON_ENUMERATION;
240 GlobalUnlock (pCapability->hContainer);
241 return TRUE;
244 static TW_BOOL GPHOTO2_EnumGet16 (pTW_CAPABILITY pCapability, int *nrofvalues, TW_UINT16 **values)
246 pTW_ENUMERATION pVal = GlobalLock (pCapability->hContainer);
248 if (!pVal)
249 return FALSE;
250 *nrofvalues = pVal->NumItems;
251 *values = HeapAlloc( GetProcessHeap(), 0, sizeof(TW_UINT16)*pVal->NumItems);
252 memcpy (*values, pVal->ItemList, sizeof(TW_UINT16)*(*nrofvalues));
253 FIXME("Current Index %ld, Default Index %ld\n", pVal->CurrentIndex, pVal->DefaultIndex);
254 GlobalUnlock (pCapability->hContainer);
255 return TRUE;
258 static TW_BOOL GPHOTO2_OneValueGet32 (pTW_CAPABILITY pCapability, TW_UINT32 *pValue)
260 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
262 if (pVal)
264 *pValue = pVal->Item;
265 GlobalUnlock (pCapability->hContainer);
266 return TRUE;
268 else
269 return FALSE;
272 static TW_BOOL GPHOTO2_OneValueGet16 (pTW_CAPABILITY pCapability, TW_UINT16 *pValue)
274 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
276 if (pVal)
278 *pValue = pVal->Item;
279 GlobalUnlock (pCapability->hContainer);
280 return TRUE;
282 else
283 return FALSE;
286 /* ICAP_XFERMECH */
287 static TW_UINT16 GPHOTO2_ICAPXferMech (pTW_CAPABILITY pCapability, TW_UINT16 action)
289 TRACE("ICAP_XFERMECH, action %d\n", action);
291 switch (action)
293 case MSG_GET:
294 if (!GPHOTO2_OneValueSet32 (pCapability, activeDS.capXferMech))
295 return TWCC_LOWMEMORY;
296 return TWCC_SUCCESS;
297 case MSG_SET:
298 if (pCapability->ConType == TWON_ONEVALUE)
300 TW_UINT32 xfermechtemp = 0;
302 if (!GPHOTO2_OneValueGet32 (pCapability, &xfermechtemp))
303 return TWCC_LOWMEMORY;
304 activeDS.capXferMech = xfermechtemp;
305 TRACE("xfermech is %ld\n", xfermechtemp);
306 return TWCC_SUCCESS;
308 else if (pCapability->ConType == TWON_ENUMERATION)
312 FIXME("GET FAILED\n");
313 break;
314 case MSG_GETCURRENT:
315 if (!GPHOTO2_OneValueSet32 (pCapability, activeDS.capXferMech))
316 return TWCC_LOWMEMORY;
317 break;
318 case MSG_GETDEFAULT:
319 if (!GPHOTO2_OneValueSet32 (pCapability, TWSX_NATIVE))
320 return TWCC_LOWMEMORY;
321 break;
322 case MSG_RESET:
323 activeDS.capXferMech = TWSX_NATIVE;
324 break;
326 return TWCC_SUCCESS;
329 /* ICAP_PIXELTYPE */
330 static TW_UINT16 GPHOTO2_ICAPPixelType (pTW_CAPABILITY pCapability, TW_UINT16 action)
332 TRACE("Action %d\n", action);
334 switch (action)
336 case MSG_GET:
337 if ((pCapability->ConType == TWON_DONTCARE16) ||
338 (pCapability->ConType == TWON_ONEVALUE)
340 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixeltype))
341 return TWCC_LOWMEMORY;
342 return TWCC_SUCCESS;
344 FIXME("Unknown container type %x in MSG_GET\n", pCapability->ConType);
345 return TWCC_CAPBADOPERATION;
346 case MSG_SET:
347 if (pCapability->ConType == TWON_ONEVALUE)
349 TW_UINT16 pixeltype = 0;
351 if (!GPHOTO2_OneValueGet16 (pCapability, &pixeltype))
352 return TWCC_LOWMEMORY;
353 activeDS.pixeltype = pixeltype;
354 FIXME("pixeltype changed to %d!\n", pixeltype);
355 return TWCC_SUCCESS;
357 FIXME("set not done\n");
358 if (pCapability->ConType == TWON_ENUMERATION) {
359 TW_UINT16 *values = NULL;
360 int i, nrofvalues = 0;
362 if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
363 return TWCC_LOWMEMORY;
364 for (i=0;i<nrofvalues;i++)
365 FIXME("SET PixelType %d:%d\n", i, values[i]);
366 HeapFree (GetProcessHeap(), 0, values);
368 break;
369 case MSG_GETCURRENT:
370 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixeltype)) {
371 FIXME("Failed one value set in GETCURRENT, contype %d!\n", pCapability->ConType);
372 return TWCC_LOWMEMORY;
374 break;
375 case MSG_GETDEFAULT:
376 if (!GPHOTO2_OneValueSet16 (pCapability, TWPT_RGB)) {
377 FIXME("Failed onevalue set in GETDEFAULT!\n");
378 return TWCC_LOWMEMORY;
380 break;
381 case MSG_RESET:
382 activeDS.pixeltype = TWPT_RGB;
383 break;
385 return TWCC_SUCCESS;
388 /* ICAP_PIXELFLAVOR */
389 static TW_UINT16 GPHOTO2_ICAPPixelFlavor (pTW_CAPABILITY pCapability, TW_UINT16 action)
391 TRACE("Action %d\n", action);
393 switch (action)
395 case MSG_GET:
396 if ((pCapability->ConType == TWON_DONTCARE16) ||
397 (pCapability->ConType == TWON_ONEVALUE)
399 if (!GPHOTO2_OneValueSet16 (pCapability, TWPF_CHOCOLATE))
400 return TWCC_LOWMEMORY;
401 return TWCC_SUCCESS;
403 if (!pCapability->ConType) {
404 TW_UINT16 arr[2];
405 arr[0] = TWPF_CHOCOLATE;
406 arr[1] = TWPF_VANILLA;
408 if (!GPHOTO2_EnumSet16 (pCapability, 2, arr, 1, 1))
409 return TWCC_LOWMEMORY;
410 return TWCC_SUCCESS;
412 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
413 return TWCC_BADVALUE;
414 case MSG_SET:
415 if (pCapability->ConType == TWON_ONEVALUE)
417 TW_UINT16 pixelflavor = 0;
419 if (!GPHOTO2_OneValueGet16 (pCapability, &pixelflavor))
420 return TWCC_LOWMEMORY;
421 activeDS.pixelflavor = pixelflavor;
422 FIXME("pixelflavor is %d\n", pixelflavor);
424 break;
425 case MSG_GETCURRENT:
426 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixelflavor))
427 return TWCC_LOWMEMORY;
428 break;
429 case MSG_GETDEFAULT:
430 if (!GPHOTO2_OneValueSet16 (pCapability, TWPF_CHOCOLATE))
431 return TWCC_LOWMEMORY;
432 break;
433 case MSG_RESET:
434 break;
436 return TWCC_SUCCESS;
439 /* ICAP_BITDEPTH */
440 static TW_UINT16 GPHOTO2_ICAPBitDepth (pTW_CAPABILITY pCapability, TW_UINT16 action)
442 TRACE("Action %d\n", action);
444 switch (action)
446 case MSG_GET:
447 if ((pCapability->ConType == TWON_DONTCARE16) ||
448 (pCapability->ConType == TWON_ONEVALUE)
450 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
451 return TWCC_LOWMEMORY;
452 return TWCC_SUCCESS;
454 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
455 return TWCC_SUCCESS;
456 case MSG_SET:
457 if (pCapability->ConType == TWON_ONEVALUE) {
458 TW_UINT16 bitdepth = 0;
460 if (!GPHOTO2_OneValueGet16 (pCapability, &bitdepth))
461 return TWCC_LOWMEMORY;
462 if (bitdepth != 24)
463 return TWCC_BADVALUE;
464 return TWCC_SUCCESS;
466 if (pCapability->ConType == TWON_ENUMERATION)
468 int i, nrofvalues = 0;
469 TW_UINT16 *values = NULL;
471 if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
472 return TWCC_LOWMEMORY;
473 for (i=0;i<nrofvalues;i++)
474 FIXME("SET: enum element %d = %d\n", i, values[i]);
475 HeapFree (GetProcessHeap(), 0, values);
476 return TWCC_SUCCESS;
478 FIXME("Unhandled container type %d in MSG_SET\n", pCapability->ConType);
479 break;
480 case MSG_GETCURRENT:
481 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
482 return TWCC_LOWMEMORY;
483 break;
484 case MSG_GETDEFAULT:
485 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
486 return TWCC_LOWMEMORY;
487 break;
488 case MSG_RESET:
489 break;
491 return TWCC_SUCCESS;
494 /* ICAP_UNITS */
495 static TW_UINT16 GPHOTO2_ICAPUnits (pTW_CAPABILITY pCapability, TW_UINT16 action)
497 TRACE("Action %d\n", action);
499 switch (action)
501 case MSG_GET:
502 if ((pCapability->ConType == TWON_DONTCARE16) ||
503 (pCapability->ConType == TWON_ONEVALUE)
505 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_PIXELS))
506 return TWCC_LOWMEMORY;
507 return TWCC_SUCCESS;
509 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
510 return TWCC_SUCCESS;
511 case MSG_SET:
512 if (pCapability->ConType == TWON_ONEVALUE) {
513 TW_UINT16 units = 0;
515 if (!GPHOTO2_OneValueGet16 (pCapability, &units))
516 return TWCC_LOWMEMORY;
517 FIXME("SET to type %d, stub.\n", units);
518 return TWCC_SUCCESS;
520 if (pCapability->ConType == TWON_ENUMERATION)
522 int i, nrofvalues = 0;
523 TW_UINT16 *values = NULL;
525 if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
526 return TWCC_LOWMEMORY;
527 for (i=0;i<nrofvalues;i++)
528 FIXME("SET: enum element %d = %d\n", i, values[i]);
529 HeapFree (GetProcessHeap(), 0, values);
530 return TWCC_SUCCESS;
532 FIXME("Unhandled container type %d in MSG_SET\n", pCapability->ConType);
533 break;
534 case MSG_GETCURRENT:
535 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_INCHES))
536 return TWCC_LOWMEMORY;
537 break;
538 case MSG_GETDEFAULT:
539 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_PIXELS))
540 return TWCC_LOWMEMORY;
541 break;
542 case MSG_RESET:
543 break;
545 return TWCC_SUCCESS;