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
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)
52 case ACAP_AUDIOFILEFORMAT:
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:
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:
76 case ICAP_PLANARCHUNKY:
77 case ICAP_BITORDERCODES:
78 case ICAP_CCITTKFACTOR:
79 case ICAP_JPEGPIXELTYPE:
80 /*case ICAP_JPEGQUALITY:*/
81 case ICAP_PIXELFLAVORCODES:
83 case CAP_DEVICEONLINE:
84 case CAP_DEVICETIMEDATE:
85 case CAP_SERIALNUMBER:
86 case ICAP_EXPOSURETIME:
88 case ICAP_IMAGEFILTER:
91 case ICAP_NOISEFILTER:
93 case ICAP_PHYSICALHEIGHT:
94 case ICAP_PHYSICALWIDTH:
97 case CAP_PRINTERENABLED:
98 case CAP_PRINTERINDEX:
100 case CAP_PRINTERSTRING:
101 case CAP_PRINTERSUFFIX:
105 case ICAP_AUTOBRIGHT:
106 case ICAP_BRIGHTNESS:
109 case ICAP_ORIENTATION:
114 case ICAP_BITDEPTHREDUCTION:
116 case ICAP_CUSTHALFTONE:
122 case ICAP_SUPPORTEDSIZES:
125 case CAP_FEEDERALIGNMENT:
126 case CAP_FEEDERENABLED:
127 case CAP_FEEDERLOADED:
128 case CAP_FEEDERORDER:
130 case CAP_PAPERBINDING:
131 case CAP_PAPERDETECTABLE:
132 case CAP_REACQUIREALLOWED:
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;
152 /* This is a required capability that every source need to
153 support but we haven't implemented yet. */
156 /*case ICAP_COMPRESSION:*/
157 case ICAP_IMAGEFILEFORMAT:
159 twCC = TWCC_CAPUNSUPPORTED;
162 twCC = GPHOTO2_ICAPXferMech (pCapability, action);
165 twCC = GPHOTO2_ICAPPixelType (pCapability, action);
167 case ICAP_PIXELFLAVOR:
168 twCC = GPHOTO2_ICAPPixelFlavor (pCapability, action);
171 twCC = GPHOTO2_ICAPBitDepth (pCapability, action);
174 twCC = GPHOTO2_ICAPUnits (pCapability, action);
176 case ICAP_UNDEFINEDIMAGESIZE:
177 case CAP_CAMERAPREVIEWUI:
178 case CAP_ENABLEDSUIONLY:
180 case CAP_UICONTROLLABLE:
181 twCC = TWCC_CAPUNSUPPORTED;
184 case ICAP_COMPRESSION:
194 static TW_BOOL GPHOTO2_OneValueSet32 (pTW_CAPABILITY pCapability, TW_UINT32 value)
196 pCapability->hContainer = (TW_HANDLE)GlobalAlloc (0, sizeof(TW_ONEVALUE));
198 TRACE("-> %ld\n", value);
200 if (pCapability->hContainer)
202 pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
203 pVal->ItemType = TWTY_UINT32;
205 GlobalUnlock ((HGLOBAL) pCapability->hContainer);
206 pCapability->ConType = TWON_ONEVALUE;
213 static TW_BOOL GPHOTO2_OneValueSet16 (pTW_CAPABILITY pCapability, TW_UINT16 value)
215 pCapability->hContainer = (TW_HANDLE)GlobalAlloc (0, sizeof(TW_ONEVALUE));
217 TRACE("-> %d\n", value);
219 if (pCapability->hContainer)
221 pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
222 pVal->ItemType = TWTY_UINT16;
224 GlobalUnlock ((HGLOBAL) pCapability->hContainer);
225 pCapability->ConType = TWON_ONEVALUE;
232 static TW_BOOL GPHOTO2_EnumSet16 (pTW_CAPABILITY pCapability, int nrofvalues, TW_UINT16 *values, int current, int def)
234 pTW_ENUMERATION pVal;
235 pCapability->hContainer = (TW_HANDLE)GlobalAlloc (0, sizeof(TW_ENUMERATION) + nrofvalues * sizeof(TW_UINT16));
237 if (!pCapability->hContainer)
240 pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
241 pVal->ItemType = TWTY_UINT16;
242 pVal->NumItems = nrofvalues;
243 memcpy(pVal->ItemList, values, sizeof(TW_UINT16)*nrofvalues);
244 pVal->CurrentIndex = current;
245 pVal->DefaultIndex = def;
246 pCapability->ConType = TWON_ENUMERATION;
247 GlobalUnlock ((HGLOBAL) pCapability->hContainer);
251 static TW_BOOL GPHOTO2_EnumGet16 (pTW_CAPABILITY pCapability, int *nrofvalues, TW_UINT16 **values)
253 pTW_ENUMERATION pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
257 *nrofvalues = pVal->NumItems;
258 *values = HeapAlloc( GetProcessHeap(), 0, sizeof(TW_UINT16)*pVal->NumItems);
259 memcpy (*values, pVal->ItemList, sizeof(TW_UINT16)*(*nrofvalues));
260 FIXME("Current Index %ld, Default Index %ld\n", pVal->CurrentIndex, pVal->DefaultIndex);
261 GlobalUnlock ((HGLOBAL) pCapability->hContainer);
265 static TW_BOOL GPHOTO2_OneValueGet32 (pTW_CAPABILITY pCapability, TW_UINT32 *pValue)
267 pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
271 *pValue = pVal->Item;
272 GlobalUnlock ((HGLOBAL) pCapability->hContainer);
279 static TW_BOOL GPHOTO2_OneValueGet16 (pTW_CAPABILITY pCapability, TW_UINT16 *pValue)
281 pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
285 *pValue = pVal->Item;
286 GlobalUnlock ((HGLOBAL) pCapability->hContainer);
294 static TW_UINT16 GPHOTO2_ICAPXferMech (pTW_CAPABILITY pCapability, TW_UINT16 action)
296 TRACE("ICAP_XFERMECH, action %d\n", action);
301 if (!GPHOTO2_OneValueSet32 (pCapability, activeDS.capXferMech))
302 return TWCC_LOWMEMORY;
305 if (pCapability->ConType == TWON_ONEVALUE)
307 TW_UINT32 xfermechtemp = 0;
309 if (!GPHOTO2_OneValueGet32 (pCapability, &xfermechtemp))
310 return TWCC_LOWMEMORY;
311 activeDS.capXferMech = xfermechtemp;
312 TRACE("xfermech is %ld\n", xfermechtemp);
315 else if (pCapability->ConType == TWON_ENUMERATION)
319 FIXME("GET FAILED\n");
322 if (!GPHOTO2_OneValueSet32 (pCapability, activeDS.capXferMech))
323 return TWCC_LOWMEMORY;
326 if (!GPHOTO2_OneValueSet32 (pCapability, TWSX_NATIVE))
327 return TWCC_LOWMEMORY;
330 activeDS.capXferMech = TWSX_NATIVE;
337 static TW_UINT16 GPHOTO2_ICAPPixelType (pTW_CAPABILITY pCapability, TW_UINT16 action)
339 TRACE("Action %d\n", action);
344 if ((pCapability->ConType == TWON_DONTCARE16) ||
345 (pCapability->ConType == TWON_ONEVALUE)
347 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixeltype))
348 return TWCC_LOWMEMORY;
351 FIXME("Unknown container type %x in MSG_GET\n", pCapability->ConType);
352 return TWCC_CAPBADOPERATION;
354 if (pCapability->ConType == TWON_ONEVALUE)
356 TW_UINT16 pixeltype = 0;
358 if (!GPHOTO2_OneValueGet16 (pCapability, &pixeltype))
359 return TWCC_LOWMEMORY;
360 activeDS.pixeltype = pixeltype;
361 FIXME("pixeltype changed to %d!\n", pixeltype);
364 FIXME("set not done\n");
365 if (pCapability->ConType == TWON_ENUMERATION) {
366 TW_UINT16 *values = NULL;
367 int i, nrofvalues = 0;
369 if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
370 return TWCC_LOWMEMORY;
371 for (i=0;i<nrofvalues;i++)
372 FIXME("SET PixelType %d:%d\n", i, values[i]);
373 HeapFree (GetProcessHeap(), 0, values);
377 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixeltype)) {
378 FIXME("Failed one value set in GETCURRENT, contype %d!\n", pCapability->ConType);
379 return TWCC_LOWMEMORY;
383 if (!GPHOTO2_OneValueSet16 (pCapability, TWPT_RGB)) {
384 FIXME("Failed onevalue set in GETDEFAULT!\n");
385 return TWCC_LOWMEMORY;
389 activeDS.pixeltype = TWPT_RGB;
395 /* ICAP_PIXELFLAVOR */
396 static TW_UINT16 GPHOTO2_ICAPPixelFlavor (pTW_CAPABILITY pCapability, TW_UINT16 action)
398 TRACE("Action %d\n", action);
403 if ((pCapability->ConType == TWON_DONTCARE16) ||
404 (pCapability->ConType == TWON_ONEVALUE)
406 if (!GPHOTO2_OneValueSet16 (pCapability, TWPF_CHOCOLATE))
407 return TWCC_LOWMEMORY;
410 if (!pCapability->ConType) {
412 arr[0] = TWPF_CHOCOLATE;
413 arr[1] = TWPF_VANILLA;
415 if (!GPHOTO2_EnumSet16 (pCapability, 2, arr, 1, 1))
416 return TWCC_LOWMEMORY;
419 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
420 return TWCC_BADVALUE;
422 if (pCapability->ConType == TWON_ONEVALUE)
424 TW_UINT16 pixelflavor = 0;
426 if (!GPHOTO2_OneValueGet16 (pCapability, &pixelflavor))
427 return TWCC_LOWMEMORY;
428 activeDS.pixelflavor = pixelflavor;
429 FIXME("pixelflavor is %d\n", pixelflavor);
433 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixelflavor))
434 return TWCC_LOWMEMORY;
437 if (!GPHOTO2_OneValueSet16 (pCapability, TWPF_CHOCOLATE))
438 return TWCC_LOWMEMORY;
447 static TW_UINT16 GPHOTO2_ICAPBitDepth (pTW_CAPABILITY pCapability, TW_UINT16 action)
449 TRACE("Action %d\n", action);
454 if ((pCapability->ConType == TWON_DONTCARE16) ||
455 (pCapability->ConType == TWON_ONEVALUE)
457 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
458 return TWCC_LOWMEMORY;
461 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
464 if (pCapability->ConType == TWON_ONEVALUE) {
465 TW_UINT16 bitdepth = 0;
467 if (!GPHOTO2_OneValueGet16 (pCapability, &bitdepth))
468 return TWCC_LOWMEMORY;
470 return TWCC_BADVALUE;
473 if (pCapability->ConType == TWON_ENUMERATION)
475 int i, nrofvalues = 0;
476 TW_UINT16 *values = NULL;
478 if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
479 return TWCC_LOWMEMORY;
480 for (i=0;i<nrofvalues;i++)
481 FIXME("SET: enum element %d = %d\n", i, values[i]);
482 HeapFree (GetProcessHeap(), 0, values);
485 FIXME("Unhandled container type %d in MSG_SET\n", pCapability->ConType);
488 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
489 return TWCC_LOWMEMORY;
492 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
493 return TWCC_LOWMEMORY;
502 static TW_UINT16 GPHOTO2_ICAPUnits (pTW_CAPABILITY pCapability, TW_UINT16 action)
504 TRACE("Action %d\n", action);
509 if ((pCapability->ConType == TWON_DONTCARE16) ||
510 (pCapability->ConType == TWON_ONEVALUE)
512 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_PIXELS))
513 return TWCC_LOWMEMORY;
516 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
519 if (pCapability->ConType == TWON_ONEVALUE) {
522 if (!GPHOTO2_OneValueGet16 (pCapability, &units))
523 return TWCC_LOWMEMORY;
524 FIXME("SET to type %d, stub.\n", units);
527 if (pCapability->ConType == TWON_ENUMERATION)
529 int i, nrofvalues = 0;
530 TW_UINT16 *values = NULL;
532 if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
533 return TWCC_LOWMEMORY;
534 for (i=0;i<nrofvalues;i++)
535 FIXME("SET: enum element %d = %d\n", i, values[i]);
536 HeapFree (GetProcessHeap(), 0, values);
539 FIXME("Unhandled container type %d in MSG_SET\n", pCapability->ConType);
542 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_INCHES))
543 return TWCC_LOWMEMORY;
546 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_PIXELS))
547 return TWCC_LOWMEMORY;