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
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
)
44 case ACAP_AUDIOFILEFORMAT
:
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
:
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
:
68 case ICAP_PLANARCHUNKY
:
69 case ICAP_BITORDERCODES
:
70 case ICAP_CCITTKFACTOR
:
71 case ICAP_JPEGPIXELTYPE
:
72 /*case ICAP_JPEGQUALITY:*/
73 case ICAP_PIXELFLAVORCODES
:
75 case CAP_DEVICEONLINE
:
76 case CAP_DEVICETIMEDATE
:
77 case CAP_SERIALNUMBER
:
78 case ICAP_EXPOSURETIME
:
80 case ICAP_IMAGEFILTER
:
83 case ICAP_NOISEFILTER
:
85 case ICAP_PHYSICALHEIGHT
:
86 case ICAP_PHYSICALWIDTH
:
89 case CAP_PRINTERENABLED
:
90 case CAP_PRINTERINDEX
:
92 case CAP_PRINTERSTRING
:
93 case CAP_PRINTERSUFFIX
:
101 case ICAP_ORIENTATION
:
106 case ICAP_BITDEPTHREDUCTION
:
108 case ICAP_CUSTHALFTONE
:
114 case ICAP_SUPPORTEDSIZES
:
117 case CAP_FEEDERALIGNMENT
:
118 case CAP_FEEDERENABLED
:
119 case CAP_FEEDERLOADED
:
120 case CAP_FEEDERORDER
:
122 case CAP_PAPERBINDING
:
123 case CAP_PAPERDETECTABLE
:
124 case CAP_REACQUIREALLOWED
:
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
;
144 /* This is a required capability that every source need to
145 support but we haven't implemented yet. */
148 /*case ICAP_COMPRESSION:*/
149 case ICAP_IMAGEFILEFORMAT
:
151 twCC
= TWCC_CAPUNSUPPORTED
;
154 twCC
= GPHOTO2_ICAPXferMech (pCapability
, action
);
157 twCC
= GPHOTO2_ICAPPixelType (pCapability
, action
);
159 case ICAP_PIXELFLAVOR
:
160 twCC
= GPHOTO2_ICAPPixelFlavor (pCapability
, action
);
163 twCC
= GPHOTO2_ICAPBitDepth (pCapability
, action
);
166 twCC
= GPHOTO2_ICAPUnits (pCapability
, action
);
168 case ICAP_UNDEFINEDIMAGESIZE
:
169 case CAP_CAMERAPREVIEWUI
:
170 case CAP_ENABLEDSUIONLY
:
172 case CAP_UICONTROLLABLE
:
173 twCC
= TWCC_CAPUNSUPPORTED
;
176 case ICAP_COMPRESSION
:
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
;
197 GlobalUnlock (pCapability
->hContainer
);
198 pCapability
->ConType
= TWON_ONEVALUE
;
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
;
216 GlobalUnlock (pCapability
->hContainer
);
217 pCapability
->ConType
= TWON_ONEVALUE
;
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
)
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
);
244 static TW_BOOL
GPHOTO2_EnumGet16 (pTW_CAPABILITY pCapability
, int *nrofvalues
, TW_UINT16
**values
)
246 pTW_ENUMERATION pVal
= GlobalLock (pCapability
->hContainer
);
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
);
258 static TW_BOOL
GPHOTO2_OneValueGet32 (pTW_CAPABILITY pCapability
, TW_UINT32
*pValue
)
260 pTW_ONEVALUE pVal
= GlobalLock (pCapability
->hContainer
);
264 *pValue
= pVal
->Item
;
265 GlobalUnlock (pCapability
->hContainer
);
272 static TW_BOOL
GPHOTO2_OneValueGet16 (pTW_CAPABILITY pCapability
, TW_UINT16
*pValue
)
274 pTW_ONEVALUE pVal
= GlobalLock (pCapability
->hContainer
);
278 *pValue
= pVal
->Item
;
279 GlobalUnlock (pCapability
->hContainer
);
287 static TW_UINT16
GPHOTO2_ICAPXferMech (pTW_CAPABILITY pCapability
, TW_UINT16 action
)
289 TRACE("ICAP_XFERMECH, action %d\n", action
);
294 if (!GPHOTO2_OneValueSet32 (pCapability
, activeDS
.capXferMech
))
295 return TWCC_LOWMEMORY
;
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
);
308 else if (pCapability
->ConType
== TWON_ENUMERATION
)
312 FIXME("GET FAILED\n");
315 if (!GPHOTO2_OneValueSet32 (pCapability
, activeDS
.capXferMech
))
316 return TWCC_LOWMEMORY
;
319 if (!GPHOTO2_OneValueSet32 (pCapability
, TWSX_NATIVE
))
320 return TWCC_LOWMEMORY
;
323 activeDS
.capXferMech
= TWSX_NATIVE
;
330 static TW_UINT16
GPHOTO2_ICAPPixelType (pTW_CAPABILITY pCapability
, TW_UINT16 action
)
332 TRACE("Action %d\n", action
);
337 if ((pCapability
->ConType
== TWON_DONTCARE16
) ||
338 (pCapability
->ConType
== TWON_ONEVALUE
)
340 if (!GPHOTO2_OneValueSet16 (pCapability
, activeDS
.pixeltype
))
341 return TWCC_LOWMEMORY
;
344 FIXME("Unknown container type %x in MSG_GET\n", pCapability
->ConType
);
345 return TWCC_CAPBADOPERATION
;
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
);
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
);
370 if (!GPHOTO2_OneValueSet16 (pCapability
, activeDS
.pixeltype
)) {
371 FIXME("Failed one value set in GETCURRENT, contype %d!\n", pCapability
->ConType
);
372 return TWCC_LOWMEMORY
;
376 if (!GPHOTO2_OneValueSet16 (pCapability
, TWPT_RGB
)) {
377 FIXME("Failed onevalue set in GETDEFAULT!\n");
378 return TWCC_LOWMEMORY
;
382 activeDS
.pixeltype
= TWPT_RGB
;
388 /* ICAP_PIXELFLAVOR */
389 static TW_UINT16
GPHOTO2_ICAPPixelFlavor (pTW_CAPABILITY pCapability
, TW_UINT16 action
)
391 TRACE("Action %d\n", action
);
396 if ((pCapability
->ConType
== TWON_DONTCARE16
) ||
397 (pCapability
->ConType
== TWON_ONEVALUE
)
399 if (!GPHOTO2_OneValueSet16 (pCapability
, TWPF_CHOCOLATE
))
400 return TWCC_LOWMEMORY
;
403 if (!pCapability
->ConType
) {
405 arr
[0] = TWPF_CHOCOLATE
;
406 arr
[1] = TWPF_VANILLA
;
408 if (!GPHOTO2_EnumSet16 (pCapability
, 2, arr
, 1, 1))
409 return TWCC_LOWMEMORY
;
412 FIXME("MSG_GET container type %x unhandled\n", pCapability
->ConType
);
413 return TWCC_BADVALUE
;
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
);
426 if (!GPHOTO2_OneValueSet16 (pCapability
, activeDS
.pixelflavor
))
427 return TWCC_LOWMEMORY
;
430 if (!GPHOTO2_OneValueSet16 (pCapability
, TWPF_CHOCOLATE
))
431 return TWCC_LOWMEMORY
;
440 static TW_UINT16
GPHOTO2_ICAPBitDepth (pTW_CAPABILITY pCapability
, TW_UINT16 action
)
442 TRACE("Action %d\n", action
);
447 if ((pCapability
->ConType
== TWON_DONTCARE16
) ||
448 (pCapability
->ConType
== TWON_ONEVALUE
)
450 if (!GPHOTO2_OneValueSet16 (pCapability
, 24))
451 return TWCC_LOWMEMORY
;
454 FIXME("MSG_GET container type %x unhandled\n", pCapability
->ConType
);
457 if (pCapability
->ConType
== TWON_ONEVALUE
) {
458 TW_UINT16 bitdepth
= 0;
460 if (!GPHOTO2_OneValueGet16 (pCapability
, &bitdepth
))
461 return TWCC_LOWMEMORY
;
463 return TWCC_BADVALUE
;
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
);
478 FIXME("Unhandled container type %d in MSG_SET\n", pCapability
->ConType
);
481 if (!GPHOTO2_OneValueSet16 (pCapability
, 24))
482 return TWCC_LOWMEMORY
;
485 if (!GPHOTO2_OneValueSet16 (pCapability
, 24))
486 return TWCC_LOWMEMORY
;
495 static TW_UINT16
GPHOTO2_ICAPUnits (pTW_CAPABILITY pCapability
, TW_UINT16 action
)
497 TRACE("Action %d\n", action
);
502 if ((pCapability
->ConType
== TWON_DONTCARE16
) ||
503 (pCapability
->ConType
== TWON_ONEVALUE
)
505 if (!GPHOTO2_OneValueSet16 (pCapability
, TWUN_PIXELS
))
506 return TWCC_LOWMEMORY
;
509 FIXME("MSG_GET container type %x unhandled\n", pCapability
->ConType
);
512 if (pCapability
->ConType
== TWON_ONEVALUE
) {
515 if (!GPHOTO2_OneValueGet16 (pCapability
, &units
))
516 return TWCC_LOWMEMORY
;
517 FIXME("SET to type %d, stub.\n", units
);
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
);
532 FIXME("Unhandled container type %d in MSG_SET\n", pCapability
->ConType
);
535 if (!GPHOTO2_OneValueSet16 (pCapability
, TWUN_INCHES
))
536 return TWCC_LOWMEMORY
;
539 if (!GPHOTO2_OneValueSet16 (pCapability
, TWUN_PIXELS
))
540 return TWCC_LOWMEMORY
;