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