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
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
)
46 case ACAP_AUDIOFILEFORMAT
:
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
:
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
:
70 case ICAP_PLANARCHUNKY
:
71 case ICAP_BITORDERCODES
:
72 case ICAP_CCITTKFACTOR
:
73 case ICAP_JPEGPIXELTYPE
:
74 /*case ICAP_JPEGQUALITY:*/
75 case ICAP_PIXELFLAVORCODES
:
77 case CAP_DEVICEONLINE
:
78 case CAP_DEVICETIMEDATE
:
79 case CAP_SERIALNUMBER
:
80 case ICAP_EXPOSURETIME
:
82 case ICAP_IMAGEFILTER
:
85 case ICAP_NOISEFILTER
:
87 case ICAP_PHYSICALHEIGHT
:
88 case ICAP_PHYSICALWIDTH
:
91 case CAP_PRINTERENABLED
:
92 case CAP_PRINTERINDEX
:
94 case CAP_PRINTERSTRING
:
95 case CAP_PRINTERSUFFIX
:
100 case ICAP_BRIGHTNESS
:
103 case ICAP_ORIENTATION
:
108 case ICAP_BITDEPTHREDUCTION
:
110 case ICAP_CUSTHALFTONE
:
116 case ICAP_SUPPORTEDSIZES
:
119 case CAP_FEEDERALIGNMENT
:
120 case CAP_FEEDERENABLED
:
121 case CAP_FEEDERLOADED
:
122 case CAP_FEEDERORDER
:
124 case CAP_PAPERBINDING
:
125 case CAP_PAPERDETECTABLE
:
126 case CAP_REACQUIREALLOWED
:
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
;
146 /* This is a required capability that every source need to
147 support but we haven't implemented yet. */
150 /*case ICAP_COMPRESSION:*/
151 case ICAP_IMAGEFILEFORMAT
:
153 twCC
= TWCC_CAPUNSUPPORTED
;
156 twCC
= GPHOTO2_ICAPXferMech (pCapability
, action
);
159 twCC
= GPHOTO2_ICAPPixelType (pCapability
, action
);
161 case ICAP_PIXELFLAVOR
:
162 twCC
= GPHOTO2_ICAPPixelFlavor (pCapability
, action
);
165 twCC
= GPHOTO2_ICAPBitDepth (pCapability
, action
);
168 twCC
= GPHOTO2_ICAPUnits (pCapability
, action
);
170 case ICAP_UNDEFINEDIMAGESIZE
:
171 case CAP_CAMERAPREVIEWUI
:
172 case CAP_ENABLEDSUIONLY
:
174 case CAP_UICONTROLLABLE
:
175 twCC
= TWCC_CAPUNSUPPORTED
;
178 case ICAP_COMPRESSION
:
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
;
199 GlobalUnlock (pCapability
->hContainer
);
200 pCapability
->ConType
= TWON_ONEVALUE
;
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
;
218 GlobalUnlock (pCapability
->hContainer
);
219 pCapability
->ConType
= TWON_ONEVALUE
;
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
)
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
);
246 static TW_BOOL
GPHOTO2_EnumGet16 (pTW_CAPABILITY pCapability
, int *nrofvalues
, TW_UINT16
**values
)
248 pTW_ENUMERATION pVal
= GlobalLock (pCapability
->hContainer
);
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
);
260 static TW_BOOL
GPHOTO2_OneValueGet32 (pTW_CAPABILITY pCapability
, TW_UINT32
*pValue
)
262 pTW_ONEVALUE pVal
= GlobalLock (pCapability
->hContainer
);
266 *pValue
= pVal
->Item
;
267 GlobalUnlock (pCapability
->hContainer
);
274 static TW_BOOL
GPHOTO2_OneValueGet16 (pTW_CAPABILITY pCapability
, TW_UINT16
*pValue
)
276 pTW_ONEVALUE pVal
= GlobalLock (pCapability
->hContainer
);
280 *pValue
= pVal
->Item
;
281 GlobalUnlock (pCapability
->hContainer
);
289 static TW_UINT16
GPHOTO2_ICAPXferMech (pTW_CAPABILITY pCapability
, TW_UINT16 action
)
291 TRACE("ICAP_XFERMECH, action %d\n", action
);
296 if (!GPHOTO2_OneValueSet32 (pCapability
, activeDS
.capXferMech
))
297 return TWCC_LOWMEMORY
;
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
);
310 else if (pCapability
->ConType
== TWON_ENUMERATION
)
314 FIXME("GET FAILED\n");
317 if (!GPHOTO2_OneValueSet32 (pCapability
, activeDS
.capXferMech
))
318 return TWCC_LOWMEMORY
;
321 if (!GPHOTO2_OneValueSet32 (pCapability
, TWSX_NATIVE
))
322 return TWCC_LOWMEMORY
;
325 activeDS
.capXferMech
= TWSX_NATIVE
;
332 static TW_UINT16
GPHOTO2_ICAPPixelType (pTW_CAPABILITY pCapability
, TW_UINT16 action
)
334 TRACE("Action %d\n", action
);
339 if ((pCapability
->ConType
== TWON_DONTCARE16
) ||
340 (pCapability
->ConType
== TWON_ONEVALUE
)
342 if (!GPHOTO2_OneValueSet16 (pCapability
, activeDS
.pixeltype
))
343 return TWCC_LOWMEMORY
;
346 FIXME("Unknown container type %x in MSG_GET\n", pCapability
->ConType
);
347 return TWCC_CAPBADOPERATION
;
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
);
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
);
372 if (!GPHOTO2_OneValueSet16 (pCapability
, activeDS
.pixeltype
)) {
373 FIXME("Failed one value set in GETCURRENT, contype %d!\n", pCapability
->ConType
);
374 return TWCC_LOWMEMORY
;
378 if (!GPHOTO2_OneValueSet16 (pCapability
, TWPT_RGB
)) {
379 FIXME("Failed onevalue set in GETDEFAULT!\n");
380 return TWCC_LOWMEMORY
;
384 activeDS
.pixeltype
= TWPT_RGB
;
390 /* ICAP_PIXELFLAVOR */
391 static TW_UINT16
GPHOTO2_ICAPPixelFlavor (pTW_CAPABILITY pCapability
, TW_UINT16 action
)
393 TRACE("Action %d\n", action
);
398 if ((pCapability
->ConType
== TWON_DONTCARE16
) ||
399 (pCapability
->ConType
== TWON_ONEVALUE
)
401 if (!GPHOTO2_OneValueSet16 (pCapability
, TWPF_CHOCOLATE
))
402 return TWCC_LOWMEMORY
;
405 if (!pCapability
->ConType
) {
407 arr
[0] = TWPF_CHOCOLATE
;
408 arr
[1] = TWPF_VANILLA
;
410 if (!GPHOTO2_EnumSet16 (pCapability
, 2, arr
, 1, 1))
411 return TWCC_LOWMEMORY
;
414 FIXME("MSG_GET container type %x unhandled\n", pCapability
->ConType
);
415 return TWCC_BADVALUE
;
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
);
428 if (!GPHOTO2_OneValueSet16 (pCapability
, activeDS
.pixelflavor
))
429 return TWCC_LOWMEMORY
;
432 if (!GPHOTO2_OneValueSet16 (pCapability
, TWPF_CHOCOLATE
))
433 return TWCC_LOWMEMORY
;
442 static TW_UINT16
GPHOTO2_ICAPBitDepth (pTW_CAPABILITY pCapability
, TW_UINT16 action
)
444 TRACE("Action %d\n", action
);
449 if ((pCapability
->ConType
== TWON_DONTCARE16
) ||
450 (pCapability
->ConType
== TWON_ONEVALUE
)
452 if (!GPHOTO2_OneValueSet16 (pCapability
, 24))
453 return TWCC_LOWMEMORY
;
456 FIXME("MSG_GET container type %x unhandled\n", pCapability
->ConType
);
459 if (pCapability
->ConType
== TWON_ONEVALUE
) {
460 TW_UINT16 bitdepth
= 0;
462 if (!GPHOTO2_OneValueGet16 (pCapability
, &bitdepth
))
463 return TWCC_LOWMEMORY
;
465 return TWCC_BADVALUE
;
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
);
480 FIXME("Unhandled container type %d in MSG_SET\n", pCapability
->ConType
);
483 if (!GPHOTO2_OneValueSet16 (pCapability
, 24))
484 return TWCC_LOWMEMORY
;
487 if (!GPHOTO2_OneValueSet16 (pCapability
, 24))
488 return TWCC_LOWMEMORY
;
497 static TW_UINT16
GPHOTO2_ICAPUnits (pTW_CAPABILITY pCapability
, TW_UINT16 action
)
499 TRACE("Action %d\n", action
);
504 if ((pCapability
->ConType
== TWON_DONTCARE16
) ||
505 (pCapability
->ConType
== TWON_ONEVALUE
)
507 if (!GPHOTO2_OneValueSet16 (pCapability
, TWUN_PIXELS
))
508 return TWCC_LOWMEMORY
;
511 FIXME("MSG_GET container type %x unhandled\n", pCapability
->ConType
);
514 if (pCapability
->ConType
== TWON_ONEVALUE
) {
517 if (!GPHOTO2_OneValueGet16 (pCapability
, &units
))
518 return TWCC_LOWMEMORY
;
519 FIXME("SET to type %d, stub.\n", units
);
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
);
534 FIXME("Unhandled container type %d in MSG_SET\n", pCapability
->ConType
);
537 if (!GPHOTO2_OneValueSet16 (pCapability
, TWUN_INCHES
))
538 return TWCC_LOWMEMORY
;
541 if (!GPHOTO2_OneValueSet16 (pCapability
, TWUN_PIXELS
))
542 return TWCC_LOWMEMORY
;