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,
233 const TW_UINT16 *values, int current, int def)
235 pTW_ENUMERATION pVal;
236 pCapability->hContainer = (TW_HANDLE)GlobalAlloc (0, sizeof(TW_ENUMERATION) + nrofvalues * sizeof(TW_UINT16));
238 if (!pCapability->hContainer)
241 pVal = GlobalLock ((HGLOBAL) 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 ((HGLOBAL) pCapability->hContainer);
252 static TW_BOOL GPHOTO2_EnumGet16 (pTW_CAPABILITY pCapability, int *nrofvalues, TW_UINT16 **values)
254 pTW_ENUMERATION pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
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 %ld, Default Index %ld\n", pVal->CurrentIndex, pVal->DefaultIndex);
262 GlobalUnlock ((HGLOBAL) pCapability->hContainer);
266 static TW_BOOL GPHOTO2_OneValueGet32 (pTW_CAPABILITY pCapability, TW_UINT32 *pValue)
268 pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
272 *pValue = pVal->Item;
273 GlobalUnlock ((HGLOBAL) pCapability->hContainer);
280 static TW_BOOL GPHOTO2_OneValueGet16 (pTW_CAPABILITY pCapability, TW_UINT16 *pValue)
282 pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
286 *pValue = pVal->Item;
287 GlobalUnlock ((HGLOBAL) pCapability->hContainer);
295 static TW_UINT16 GPHOTO2_ICAPXferMech (pTW_CAPABILITY pCapability, TW_UINT16 action)
297 TRACE("ICAP_XFERMECH, action %d\n", action);
302 if (!GPHOTO2_OneValueSet32 (pCapability, activeDS.capXferMech))
303 return TWCC_LOWMEMORY;
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 %ld\n", xfermechtemp);
316 else if (pCapability->ConType == TWON_ENUMERATION)
320 FIXME("GET FAILED\n");
323 if (!GPHOTO2_OneValueSet32 (pCapability, activeDS.capXferMech))
324 return TWCC_LOWMEMORY;
327 if (!GPHOTO2_OneValueSet32 (pCapability, TWSX_NATIVE))
328 return TWCC_LOWMEMORY;
331 activeDS.capXferMech = TWSX_NATIVE;
338 static TW_UINT16 GPHOTO2_ICAPPixelType (pTW_CAPABILITY pCapability, TW_UINT16 action)
340 TRACE("Action %d\n", action);
345 if ((pCapability->ConType == TWON_DONTCARE16) ||
346 (pCapability->ConType == TWON_ONEVALUE)
348 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixeltype))
349 return TWCC_LOWMEMORY;
352 FIXME("Unknown container type %x in MSG_GET\n", pCapability->ConType);
353 return TWCC_CAPBADOPERATION;
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);
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);
378 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixeltype)) {
379 FIXME("Failed one value set in GETCURRENT, contype %d!\n", pCapability->ConType);
380 return TWCC_LOWMEMORY;
384 if (!GPHOTO2_OneValueSet16 (pCapability, TWPT_RGB)) {
385 FIXME("Failed onevalue set in GETDEFAULT!\n");
386 return TWCC_LOWMEMORY;
390 activeDS.pixeltype = TWPT_RGB;
396 /* ICAP_PIXELFLAVOR */
397 static TW_UINT16 GPHOTO2_ICAPPixelFlavor (pTW_CAPABILITY pCapability, TW_UINT16 action)
399 TRACE("Action %d\n", action);
404 if ((pCapability->ConType == TWON_DONTCARE16) ||
405 (pCapability->ConType == TWON_ONEVALUE)
407 if (!GPHOTO2_OneValueSet16 (pCapability, TWPF_CHOCOLATE))
408 return TWCC_LOWMEMORY;
411 if (!pCapability->ConType) {
413 arr[0] = TWPF_CHOCOLATE;
414 arr[1] = TWPF_VANILLA;
416 if (!GPHOTO2_EnumSet16 (pCapability, 2, arr, 1, 1))
417 return TWCC_LOWMEMORY;
420 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
421 return TWCC_BADVALUE;
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);
434 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixelflavor))
435 return TWCC_LOWMEMORY;
438 if (!GPHOTO2_OneValueSet16 (pCapability, TWPF_CHOCOLATE))
439 return TWCC_LOWMEMORY;
448 static TW_UINT16 GPHOTO2_ICAPBitDepth (pTW_CAPABILITY pCapability, TW_UINT16 action)
450 TRACE("Action %d\n", action);
455 if ((pCapability->ConType == TWON_DONTCARE16) ||
456 (pCapability->ConType == TWON_ONEVALUE)
458 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
459 return TWCC_LOWMEMORY;
462 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
465 if (pCapability->ConType == TWON_ONEVALUE) {
466 TW_UINT16 bitdepth = 0;
468 if (!GPHOTO2_OneValueGet16 (pCapability, &bitdepth))
469 return TWCC_LOWMEMORY;
471 return TWCC_BADVALUE;
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);
486 FIXME("Unhandled container type %d in MSG_SET\n", pCapability->ConType);
489 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
490 return TWCC_LOWMEMORY;
493 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
494 return TWCC_LOWMEMORY;
503 static TW_UINT16 GPHOTO2_ICAPUnits (pTW_CAPABILITY pCapability, TW_UINT16 action)
505 TRACE("Action %d\n", action);
510 if ((pCapability->ConType == TWON_DONTCARE16) ||
511 (pCapability->ConType == TWON_ONEVALUE)
513 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_PIXELS))
514 return TWCC_LOWMEMORY;
517 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
520 if (pCapability->ConType == TWON_ONEVALUE) {
523 if (!GPHOTO2_OneValueGet16 (pCapability, &units))
524 return TWCC_LOWMEMORY;
525 FIXME("SET to type %d, stub.\n", units);
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);
540 FIXME("Unhandled container type %d in MSG_SET\n", pCapability->ConType);
543 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_INCHES))
544 return TWCC_LOWMEMORY;
547 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_PIXELS))
548 return TWCC_LOWMEMORY;