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
27 #include "gphoto2_i.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(twain);
32 static TW_UINT16 GPHOTO2_ICAPXferMech (pTW_CAPABILITY,TW_UINT16);
33 static TW_UINT16 GPHOTO2_ICAPPixelType (pTW_CAPABILITY,TW_UINT16);
34 static TW_UINT16 GPHOTO2_ICAPPixelFlavor (pTW_CAPABILITY,TW_UINT16);
35 static TW_UINT16 GPHOTO2_ICAPBitDepth (pTW_CAPABILITY,TW_UINT16);
36 static TW_UINT16 GPHOTO2_ICAPUnits (pTW_CAPABILITY,TW_UINT16);
38 TW_UINT16 GPHOTO2_SaneCapability (pTW_CAPABILITY pCapability, TW_UINT16 action)
40 TW_UINT16 twCC = TWCC_SUCCESS;
42 TRACE("capability=%d action=%d\n", pCapability->Cap, action);
44 switch (pCapability->Cap)
49 case ACAP_AUDIOFILEFORMAT:
51 case ICAP_AUTOMATICBORDERDETECTION:
52 case ICAP_AUTOMATICDESKEW:
53 case ICAP_AUTODISCARDBLANKPAGES:
54 case ICAP_AUTOMATICROTATE:
55 case ICAP_FLIPROTATION:
56 case CAP_AUTOMATICCAPTURE:
57 case CAP_TIMEBEFOREFIRSTCAPTURE:
58 case CAP_TIMEBETWEENCAPTURES:
60 case CAP_CLEARBUFFERS:
61 case CAP_MAXBATCHBUFFERS:
62 case ICAP_BARCODEDETECTIONENABLED:
63 case ICAP_SUPPORTEDBARCODETYPES:
64 case ICAP_BARCODEMAXSEARCHPRIORITIES:
65 case ICAP_BARCODESEARCHPRIORITIES:
66 case ICAP_BARCODESEARCHMODE:
67 case ICAP_BARCODEMAXRETRIES:
68 case ICAP_BARCODETIMEOUT:
69 case CAP_EXTENDEDCAPS:
70 case CAP_SUPPORTEDCAPS:
73 case ICAP_PLANARCHUNKY:
74 case ICAP_BITORDERCODES:
75 case ICAP_CCITTKFACTOR:
76 case ICAP_JPEGPIXELTYPE:
77 /*case ICAP_JPEGQUALITY:*/
78 case ICAP_PIXELFLAVORCODES:
80 case CAP_DEVICEONLINE:
81 case CAP_DEVICETIMEDATE:
82 case CAP_SERIALNUMBER:
83 case ICAP_EXPOSURETIME:
85 case ICAP_IMAGEFILTER:
88 case ICAP_NOISEFILTER:
90 case ICAP_PHYSICALHEIGHT:
91 case ICAP_PHYSICALWIDTH:
94 case CAP_PRINTERENABLED:
95 case CAP_PRINTERINDEX:
97 case CAP_PRINTERSTRING:
98 case CAP_PRINTERSUFFIX:
102 case ICAP_AUTOBRIGHT:
103 case ICAP_BRIGHTNESS:
106 case ICAP_ORIENTATION:
111 case ICAP_BITDEPTHREDUCTION:
113 case ICAP_CUSTHALFTONE:
119 case ICAP_SUPPORTEDSIZES:
122 case CAP_FEEDERALIGNMENT:
123 case CAP_FEEDERENABLED:
124 case CAP_FEEDERLOADED:
125 case CAP_FEEDERORDER:
127 case CAP_PAPERBINDING:
128 case CAP_PAPERDETECTABLE:
129 case CAP_REACQUIREALLOWED:
131 case ICAP_PATCHCODEDETECTIONENABLED:
132 case ICAP_SUPPORTEDPATCHCODETYPES:
133 case ICAP_PATCHCODEMAXSEARCHPRIORITIES:
134 case ICAP_PATCHCODESEARCHPRIORITIES:
135 case ICAP_PATCHCODESEARCHMODE:
136 case ICAP_PATCHCODEMAXRETRIES:
137 case ICAP_PATCHCODETIMEOUT:
138 case CAP_BATTERYMINUTES:
139 case CAP_BATTERYPERCENTAGE:
140 case CAP_POWERDOWNTIME:
141 case CAP_POWERSUPPLY:
142 case ICAP_XNATIVERESOLUTION:
143 case ICAP_XRESOLUTION:
144 case ICAP_YNATIVERESOLUTION:
145 case ICAP_YRESOLUTION:
146 twCC = TWCC_CAPUNSUPPORTED;
149 /* This is a required capability that every source need to
150 support but we haven't implemented yet. */
153 /*case ICAP_COMPRESSION:*/
154 case ICAP_IMAGEFILEFORMAT:
156 twCC = TWCC_CAPUNSUPPORTED;
159 twCC = GPHOTO2_ICAPXferMech (pCapability, action);
162 twCC = GPHOTO2_ICAPPixelType (pCapability, action);
164 case ICAP_PIXELFLAVOR:
165 twCC = GPHOTO2_ICAPPixelFlavor (pCapability, action);
168 twCC = GPHOTO2_ICAPBitDepth (pCapability, action);
171 twCC = GPHOTO2_ICAPUnits (pCapability, action);
173 case ICAP_UNDEFINEDIMAGESIZE:
174 case CAP_CAMERAPREVIEWUI:
175 case CAP_ENABLEDSUIONLY:
177 case CAP_UICONTROLLABLE:
178 twCC = TWCC_CAPUNSUPPORTED;
181 case ICAP_COMPRESSION:
191 static TW_BOOL GPHOTO2_OneValueSet32 (pTW_CAPABILITY pCapability, TW_UINT32 value)
193 pCapability->hContainer = GlobalAlloc (0, sizeof(TW_ONEVALUE));
195 TRACE("-> %d\n", value);
197 if (pCapability->hContainer)
199 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
200 pVal->ItemType = TWTY_UINT32;
202 GlobalUnlock (pCapability->hContainer);
203 pCapability->ConType = TWON_ONEVALUE;
210 static TW_BOOL GPHOTO2_OneValueSet16 (pTW_CAPABILITY pCapability, TW_UINT16 value)
212 pCapability->hContainer = GlobalAlloc (0, sizeof(TW_ONEVALUE));
214 TRACE("-> %d\n", value);
216 if (pCapability->hContainer)
218 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
219 pVal->ItemType = TWTY_UINT16;
221 GlobalUnlock (pCapability->hContainer);
222 pCapability->ConType = TWON_ONEVALUE;
229 static TW_BOOL GPHOTO2_EnumSet16 (pTW_CAPABILITY pCapability, int nrofvalues,
230 const TW_UINT16 *values, int current, int def)
232 pTW_ENUMERATION pVal;
233 pCapability->hContainer = GlobalAlloc (0, sizeof(TW_ENUMERATION) + nrofvalues * sizeof(TW_UINT16));
235 if (!pCapability->hContainer)
238 pVal = GlobalLock (pCapability->hContainer);
239 pVal->ItemType = TWTY_UINT16;
240 pVal->NumItems = nrofvalues;
241 memcpy(pVal->ItemList, values, sizeof(TW_UINT16)*nrofvalues);
242 pVal->CurrentIndex = current;
243 pVal->DefaultIndex = def;
244 pCapability->ConType = TWON_ENUMERATION;
245 GlobalUnlock (pCapability->hContainer);
249 static TW_BOOL GPHOTO2_EnumGet16 (pTW_CAPABILITY pCapability, int *nrofvalues, TW_UINT16 **values)
251 pTW_ENUMERATION pVal = GlobalLock (pCapability->hContainer);
255 *nrofvalues = pVal->NumItems;
256 *values = HeapAlloc( GetProcessHeap(), 0, sizeof(TW_UINT16)*pVal->NumItems);
257 memcpy (*values, pVal->ItemList, sizeof(TW_UINT16)*(*nrofvalues));
258 FIXME("Current Index %d, Default Index %d\n", pVal->CurrentIndex, pVal->DefaultIndex);
259 GlobalUnlock (pCapability->hContainer);
263 static TW_BOOL GPHOTO2_OneValueGet32 (pTW_CAPABILITY pCapability, TW_UINT32 *pValue)
265 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
269 *pValue = pVal->Item;
270 GlobalUnlock (pCapability->hContainer);
277 static TW_BOOL GPHOTO2_OneValueGet16 (pTW_CAPABILITY pCapability, TW_UINT16 *pValue)
279 pTW_ONEVALUE pVal = GlobalLock (pCapability->hContainer);
283 *pValue = pVal->Item;
284 GlobalUnlock (pCapability->hContainer);
292 static TW_UINT16 GPHOTO2_ICAPXferMech (pTW_CAPABILITY pCapability, TW_UINT16 action)
294 TRACE("ICAP_XFERMECH, action %d\n", action);
299 if (!GPHOTO2_OneValueSet32 (pCapability, activeDS.capXferMech))
300 return TWCC_LOWMEMORY;
303 if (pCapability->ConType == TWON_ONEVALUE)
305 TW_UINT32 xfermechtemp = 0;
307 if (!GPHOTO2_OneValueGet32 (pCapability, &xfermechtemp))
308 return TWCC_LOWMEMORY;
309 activeDS.capXferMech = xfermechtemp;
310 TRACE("xfermech is %d\n", xfermechtemp);
313 else if (pCapability->ConType == TWON_ENUMERATION)
317 FIXME("GET FAILED\n");
320 if (!GPHOTO2_OneValueSet32 (pCapability, activeDS.capXferMech))
321 return TWCC_LOWMEMORY;
324 if (!GPHOTO2_OneValueSet32 (pCapability, TWSX_NATIVE))
325 return TWCC_LOWMEMORY;
328 activeDS.capXferMech = TWSX_NATIVE;
335 static TW_UINT16 GPHOTO2_ICAPPixelType (pTW_CAPABILITY pCapability, TW_UINT16 action)
337 TRACE("Action %d\n", action);
342 if ((pCapability->ConType == TWON_DONTCARE16) ||
343 (pCapability->ConType == TWON_ONEVALUE)
345 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixeltype))
346 return TWCC_LOWMEMORY;
349 FIXME("Unknown container type %x in MSG_GET\n", pCapability->ConType);
350 return TWCC_CAPBADOPERATION;
352 if (pCapability->ConType == TWON_ONEVALUE)
354 TW_UINT16 pixeltype = 0;
356 if (!GPHOTO2_OneValueGet16 (pCapability, &pixeltype))
357 return TWCC_LOWMEMORY;
358 activeDS.pixeltype = pixeltype;
359 FIXME("pixeltype changed to %d!\n", pixeltype);
362 FIXME("set not done\n");
363 if (pCapability->ConType == TWON_ENUMERATION) {
364 TW_UINT16 *values = NULL;
365 int i, nrofvalues = 0;
367 if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
368 return TWCC_LOWMEMORY;
369 for (i=0;i<nrofvalues;i++)
370 FIXME("SET PixelType %d:%d\n", i, values[i]);
371 HeapFree (GetProcessHeap(), 0, values);
375 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixeltype)) {
376 FIXME("Failed one value set in GETCURRENT, contype %d!\n", pCapability->ConType);
377 return TWCC_LOWMEMORY;
381 if (!GPHOTO2_OneValueSet16 (pCapability, TWPT_RGB)) {
382 FIXME("Failed onevalue set in GETDEFAULT!\n");
383 return TWCC_LOWMEMORY;
387 activeDS.pixeltype = TWPT_RGB;
393 /* ICAP_PIXELFLAVOR */
394 static TW_UINT16 GPHOTO2_ICAPPixelFlavor (pTW_CAPABILITY pCapability, TW_UINT16 action)
396 TRACE("Action %d\n", action);
401 if ((pCapability->ConType == TWON_DONTCARE16) ||
402 (pCapability->ConType == TWON_ONEVALUE)
404 if (!GPHOTO2_OneValueSet16 (pCapability, TWPF_CHOCOLATE))
405 return TWCC_LOWMEMORY;
408 if (!pCapability->ConType) {
410 arr[0] = TWPF_CHOCOLATE;
411 arr[1] = TWPF_VANILLA;
413 if (!GPHOTO2_EnumSet16 (pCapability, 2, arr, 1, 1))
414 return TWCC_LOWMEMORY;
417 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
418 return TWCC_BADVALUE;
420 if (pCapability->ConType == TWON_ONEVALUE)
422 TW_UINT16 pixelflavor = 0;
424 if (!GPHOTO2_OneValueGet16 (pCapability, &pixelflavor))
425 return TWCC_LOWMEMORY;
426 activeDS.pixelflavor = pixelflavor;
427 FIXME("pixelflavor is %d\n", pixelflavor);
431 if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixelflavor))
432 return TWCC_LOWMEMORY;
435 if (!GPHOTO2_OneValueSet16 (pCapability, TWPF_CHOCOLATE))
436 return TWCC_LOWMEMORY;
445 static TW_UINT16 GPHOTO2_ICAPBitDepth (pTW_CAPABILITY pCapability, TW_UINT16 action)
447 TRACE("Action %d\n", action);
452 if ((pCapability->ConType == TWON_DONTCARE16) ||
453 (pCapability->ConType == TWON_ONEVALUE)
455 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
456 return TWCC_LOWMEMORY;
459 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
462 if (pCapability->ConType == TWON_ONEVALUE) {
463 TW_UINT16 bitdepth = 0;
465 if (!GPHOTO2_OneValueGet16 (pCapability, &bitdepth))
466 return TWCC_LOWMEMORY;
468 return TWCC_BADVALUE;
471 if (pCapability->ConType == TWON_ENUMERATION)
473 int i, nrofvalues = 0;
474 TW_UINT16 *values = NULL;
476 if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
477 return TWCC_LOWMEMORY;
478 for (i=0;i<nrofvalues;i++)
479 FIXME("SET: enum element %d = %d\n", i, values[i]);
480 HeapFree (GetProcessHeap(), 0, values);
483 FIXME("Unhandled container type %d in MSG_SET\n", pCapability->ConType);
486 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
487 return TWCC_LOWMEMORY;
490 if (!GPHOTO2_OneValueSet16 (pCapability, 24))
491 return TWCC_LOWMEMORY;
500 static TW_UINT16 GPHOTO2_ICAPUnits (pTW_CAPABILITY pCapability, TW_UINT16 action)
502 TRACE("Action %d\n", action);
507 if ((pCapability->ConType == TWON_DONTCARE16) ||
508 (pCapability->ConType == TWON_ONEVALUE)
510 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_PIXELS))
511 return TWCC_LOWMEMORY;
514 FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
517 if (pCapability->ConType == TWON_ONEVALUE) {
520 if (!GPHOTO2_OneValueGet16 (pCapability, &units))
521 return TWCC_LOWMEMORY;
522 FIXME("SET to type %d, stub.\n", units);
525 if (pCapability->ConType == TWON_ENUMERATION)
527 int i, nrofvalues = 0;
528 TW_UINT16 *values = NULL;
530 if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
531 return TWCC_LOWMEMORY;
532 for (i=0;i<nrofvalues;i++)
533 FIXME("SET: enum element %d = %d\n", i, values[i]);
534 HeapFree (GetProcessHeap(), 0, values);
537 FIXME("Unhandled container type %d in MSG_SET\n", pCapability->ConType);
540 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_INCHES))
541 return TWCC_LOWMEMORY;
544 if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_PIXELS))
545 return TWCC_LOWMEMORY;