capability.c 16.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright 2000 Corel Corporation
 * Copyright 2006 Marcus Meissner
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
 */

#define NONAMELESSUNION
#define NONAMELESSSTRUCT

#include "config.h"

#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "twain.h"
#include "gphoto2_i.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(twain);

static TW_UINT16 GPHOTO2_ICAPXferMech (pTW_CAPABILITY,TW_UINT16);
static TW_UINT16 GPHOTO2_ICAPPixelType (pTW_CAPABILITY,TW_UINT16);
static TW_UINT16 GPHOTO2_ICAPPixelFlavor (pTW_CAPABILITY,TW_UINT16);
static TW_UINT16 GPHOTO2_ICAPBitDepth (pTW_CAPABILITY,TW_UINT16);
static TW_UINT16 GPHOTO2_ICAPUnits (pTW_CAPABILITY,TW_UINT16);

TW_UINT16 GPHOTO2_SaneCapability (pTW_CAPABILITY pCapability, TW_UINT16 action)
{
    TW_UINT16 twCC = TWCC_SUCCESS;

    TRACE("capability=%d action=%d\n", pCapability->Cap, action);

    switch (pCapability->Cap)
    {
        case CAP_DEVICEEVENT:
        case CAP_ALARMS:
        case CAP_ALARMVOLUME:
        case ACAP_AUDIOFILEFORMAT:
        case ACAP_XFERMECH:
        case ICAP_AUTOMATICBORDERDETECTION:
        case ICAP_AUTOMATICDESKEW:
        case ICAP_AUTODISCARDBLANKPAGES:
        case ICAP_AUTOMATICROTATE:
        case ICAP_FLIPROTATION:
        case CAP_AUTOMATICCAPTURE:
        case CAP_TIMEBEFOREFIRSTCAPTURE:
        case CAP_TIMEBETWEENCAPTURES:
        case CAP_AUTOSCAN:
        case CAP_CLEARBUFFERS:
        case CAP_MAXBATCHBUFFERS:
        case ICAP_BARCODEDETECTIONENABLED:
        case ICAP_SUPPORTEDBARCODETYPES:
        case ICAP_BARCODEMAXSEARCHPRIORITIES:
        case ICAP_BARCODESEARCHPRIORITIES:
        case ICAP_BARCODESEARCHMODE:
        case ICAP_BARCODEMAXRETRIES:
        case ICAP_BARCODETIMEOUT:
        case CAP_EXTENDEDCAPS:
        case CAP_SUPPORTEDCAPS:
        case ICAP_FILTER:
        case ICAP_GAMMA:
        case ICAP_PLANARCHUNKY:
        case ICAP_BITORDERCODES:
        case ICAP_CCITTKFACTOR:
        case ICAP_JPEGPIXELTYPE:
        /*case ICAP_JPEGQUALITY:*/
        case ICAP_PIXELFLAVORCODES:
        case ICAP_TIMEFILL:
        case CAP_DEVICEONLINE:
        case CAP_DEVICETIMEDATE:
        case CAP_SERIALNUMBER:
        case ICAP_EXPOSURETIME:
        case ICAP_FLASHUSED2:
        case ICAP_IMAGEFILTER:
        case ICAP_LAMPSTATE:
        case ICAP_LIGHTPATH:
        case ICAP_NOISEFILTER:
        case ICAP_OVERSCAN:
        case ICAP_PHYSICALHEIGHT:
        case ICAP_PHYSICALWIDTH:
        case ICAP_ZOOMFACTOR:
        case CAP_PRINTER:
        case CAP_PRINTERENABLED:
        case CAP_PRINTERINDEX:
        case CAP_PRINTERMODE:
        case CAP_PRINTERSTRING:
        case CAP_PRINTERSUFFIX:
        case CAP_AUTHOR:
        case CAP_CAPTION:
        case CAP_TIMEDATE:
        case ICAP_AUTOBRIGHT:
        case ICAP_BRIGHTNESS:
        case ICAP_CONTRAST:
        case ICAP_HIGHLIGHT:
        case ICAP_ORIENTATION:
        case ICAP_ROTATION:
        case ICAP_SHADOW:
        case ICAP_XSCALING:
        case ICAP_YSCALING:
        case ICAP_BITDEPTHREDUCTION:
        case ICAP_BITORDER:
        case ICAP_CUSTHALFTONE:
        case ICAP_HALFTONES:
        case ICAP_THRESHOLD:
        case CAP_LANGUAGE:
        case ICAP_FRAMES:
        case ICAP_MAXFRAMES:
        case ICAP_SUPPORTEDSIZES:
        case CAP_AUTOFEED:
        case CAP_CLEARPAGE:
        case CAP_FEEDERALIGNMENT:
        case CAP_FEEDERENABLED:
        case CAP_FEEDERLOADED:
        case CAP_FEEDERORDER:
        case CAP_FEEDPAGE:
        case CAP_PAPERBINDING:
        case CAP_PAPERDETECTABLE:
        case CAP_REACQUIREALLOWED:
        case CAP_REWINDPAGE:
        case ICAP_PATCHCODEDETECTIONENABLED:
        case ICAP_SUPPORTEDPATCHCODETYPES:
        case ICAP_PATCHCODEMAXSEARCHPRIORITIES:
        case ICAP_PATCHCODESEARCHPRIORITIES:
        case ICAP_PATCHCODESEARCHMODE:
        case ICAP_PATCHCODEMAXRETRIES:
        case ICAP_PATCHCODETIMEOUT:
        case CAP_BATTERYMINUTES:
        case CAP_BATTERYPERCENTAGE:
        case CAP_POWERDOWNTIME:
        case CAP_POWERSUPPLY:
        case ICAP_XNATIVERESOLUTION:
        case ICAP_XRESOLUTION:
        case ICAP_YNATIVERESOLUTION:
        case ICAP_YRESOLUTION:
            twCC = TWCC_CAPUNSUPPORTED;
            break;
        case CAP_XFERCOUNT:
            /* This is a required capability that every source need to
               support but we haven't implemented yet. */
            twCC = TWCC_SUCCESS;
            break;
        /*case ICAP_COMPRESSION:*/
        case ICAP_IMAGEFILEFORMAT:
        case ICAP_TILES:
            twCC = TWCC_CAPUNSUPPORTED;
            break;
        case ICAP_XFERMECH:
            twCC = GPHOTO2_ICAPXferMech (pCapability, action);
            break;
        case ICAP_PIXELTYPE:
            twCC = GPHOTO2_ICAPPixelType (pCapability, action);
	    break;
        case ICAP_PIXELFLAVOR:
            twCC = GPHOTO2_ICAPPixelFlavor (pCapability, action);
	    break;
        case ICAP_BITDEPTH:
            twCC = GPHOTO2_ICAPBitDepth (pCapability, action);
	    break;
        case ICAP_UNITS:
            twCC = GPHOTO2_ICAPUnits (pCapability, action);
	    break;
        case ICAP_UNDEFINEDIMAGESIZE:
        case CAP_CAMERAPREVIEWUI:
        case CAP_ENABLEDSUIONLY:
        case CAP_INDICATORS:
        case CAP_UICONTROLLABLE:
            twCC = TWCC_CAPUNSUPPORTED;
            break;

        case ICAP_COMPRESSION:
            twCC = TWCC_SUCCESS;
	    break;
        default:
            twCC = TWRC_FAILURE;
	    break;
    }
    return twCC;
}

static TW_BOOL GPHOTO2_OneValueSet32 (pTW_CAPABILITY pCapability, TW_UINT32 value)
{
    pCapability->hContainer = (TW_HANDLE)GlobalAlloc (0, sizeof(TW_ONEVALUE));

    TRACE("-> %ld\n", value);

    if (pCapability->hContainer)
    {
        pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
        pVal->ItemType = TWTY_UINT32;
        pVal->Item = value;
        GlobalUnlock ((HGLOBAL) pCapability->hContainer);
	pCapability->ConType = TWON_ONEVALUE;
        return TRUE;
    }
    else
        return FALSE;
}

static TW_BOOL GPHOTO2_OneValueSet16 (pTW_CAPABILITY pCapability, TW_UINT16 value)
{
    pCapability->hContainer = (TW_HANDLE)GlobalAlloc (0, sizeof(TW_ONEVALUE));

    TRACE("-> %d\n", value);

    if (pCapability->hContainer)
    {
        pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
        pVal->ItemType = TWTY_UINT16;
        pVal->Item = value;
        GlobalUnlock ((HGLOBAL) pCapability->hContainer);
	pCapability->ConType = TWON_ONEVALUE;
        return TRUE;
    }
    else
        return FALSE;
}

232 233
static TW_BOOL GPHOTO2_EnumSet16 (pTW_CAPABILITY pCapability, int nrofvalues,
                                  const TW_UINT16 *values, int current, int def)
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
{
    pTW_ENUMERATION pVal;
    pCapability->hContainer = (TW_HANDLE)GlobalAlloc (0, sizeof(TW_ENUMERATION) + nrofvalues * sizeof(TW_UINT16));

    if (!pCapability->hContainer)
	return FALSE;

    pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);
    pVal->ItemType = TWTY_UINT16;
    pVal->NumItems = nrofvalues;
    memcpy(pVal->ItemList, values, sizeof(TW_UINT16)*nrofvalues);
    pVal->CurrentIndex = current;
    pVal->DefaultIndex = def;
    pCapability->ConType = TWON_ENUMERATION;
    GlobalUnlock ((HGLOBAL) pCapability->hContainer);
    return TRUE;
}

static TW_BOOL GPHOTO2_EnumGet16 (pTW_CAPABILITY pCapability, int *nrofvalues, TW_UINT16 **values)
{
    pTW_ENUMERATION pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);

    if (!pVal)
	return FALSE;
    *nrofvalues = pVal->NumItems;
    *values = HeapAlloc( GetProcessHeap(), 0, sizeof(TW_UINT16)*pVal->NumItems);
    memcpy (*values, pVal->ItemList, sizeof(TW_UINT16)*(*nrofvalues));
    FIXME("Current Index %ld, Default Index %ld\n", pVal->CurrentIndex, pVal->DefaultIndex);
    GlobalUnlock ((HGLOBAL) pCapability->hContainer);
    return TRUE;
}

static TW_BOOL GPHOTO2_OneValueGet32 (pTW_CAPABILITY pCapability, TW_UINT32 *pValue)
{
    pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);

    if (pVal)
    {
        *pValue = pVal->Item;
        GlobalUnlock ((HGLOBAL) pCapability->hContainer);
        return TRUE;
    }
    else
        return FALSE;
}

static TW_BOOL GPHOTO2_OneValueGet16 (pTW_CAPABILITY pCapability, TW_UINT16 *pValue)
{
    pTW_ONEVALUE pVal = GlobalLock ((HGLOBAL) pCapability->hContainer);

    if (pVal)
    {
        *pValue = pVal->Item;
        GlobalUnlock ((HGLOBAL) pCapability->hContainer);
        return TRUE;
    }
    else
        return FALSE;
}

/* ICAP_XFERMECH */
static TW_UINT16 GPHOTO2_ICAPXferMech (pTW_CAPABILITY pCapability, TW_UINT16 action)
{
    TRACE("ICAP_XFERMECH, action %d\n", action);

    switch (action)
    {
        case MSG_GET:
            if (!GPHOTO2_OneValueSet32 (pCapability, activeDS.capXferMech))
                return TWCC_LOWMEMORY;
	    return TWCC_SUCCESS;
        case MSG_SET:
            if (pCapability->ConType == TWON_ONEVALUE)
            {
		TW_UINT32 xfermechtemp = 0;

                if (!GPHOTO2_OneValueGet32 (pCapability, &xfermechtemp))
                    return TWCC_LOWMEMORY;
		activeDS.capXferMech = xfermechtemp;
		TRACE("xfermech is %ld\n", xfermechtemp);
		return TWCC_SUCCESS;
            }
            else if (pCapability->ConType == TWON_ENUMERATION)
            {

            }
	    FIXME("GET FAILED\n");
            break;
        case MSG_GETCURRENT:
            if (!GPHOTO2_OneValueSet32 (pCapability, activeDS.capXferMech))
                return TWCC_LOWMEMORY;
            break;
        case MSG_GETDEFAULT:
            if (!GPHOTO2_OneValueSet32 (pCapability, TWSX_NATIVE))
                return TWCC_LOWMEMORY;
            break;
        case MSG_RESET:
            activeDS.capXferMech = TWSX_NATIVE;
            break;
    }
    return TWCC_SUCCESS;
}

/* ICAP_PIXELTYPE */
static TW_UINT16 GPHOTO2_ICAPPixelType (pTW_CAPABILITY pCapability, TW_UINT16 action)
{
    TRACE("Action %d\n", action);

    switch (action)
    {
        case MSG_GET:
            if ((pCapability->ConType == TWON_DONTCARE16) ||
		(pCapability->ConType == TWON_ONEVALUE)
	    ) {
                if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixeltype))
                    return TWCC_LOWMEMORY;
    	        return TWCC_SUCCESS;
	    }
	    FIXME("Unknown container type %x in MSG_GET\n", pCapability->ConType);
	    return TWCC_CAPBADOPERATION;
        case MSG_SET:
            if (pCapability->ConType == TWON_ONEVALUE)
            {
		TW_UINT16 pixeltype = 0;

                if (!GPHOTO2_OneValueGet16 (pCapability, &pixeltype))
                    return TWCC_LOWMEMORY;
		activeDS.pixeltype = pixeltype;
		FIXME("pixeltype changed to %d!\n", pixeltype);
    		return TWCC_SUCCESS;
            }
	    FIXME("set not done\n");
            if (pCapability->ConType == TWON_ENUMERATION) {
		TW_UINT16	*values = NULL;
		int i, nrofvalues = 0;
		
		if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
		    return TWCC_LOWMEMORY;
		for (i=0;i<nrofvalues;i++)
		    FIXME("SET PixelType %d:%d\n", i, values[i]);
		HeapFree (GetProcessHeap(), 0, values);
	    }
            break;
        case MSG_GETCURRENT:
            if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixeltype)) {
	    	FIXME("Failed one value set in GETCURRENT, contype %d!\n", pCapability->ConType);
                return TWCC_LOWMEMORY;
	    }
            break;
        case MSG_GETDEFAULT:
            if (!GPHOTO2_OneValueSet16 (pCapability, TWPT_RGB)) {
	    	FIXME("Failed onevalue set in GETDEFAULT!\n");
                return TWCC_LOWMEMORY;
	    }
            break;
        case MSG_RESET:
            activeDS.pixeltype = TWPT_RGB;
            break;
    }
    return TWCC_SUCCESS;
}

/* ICAP_PIXELFLAVOR */
static TW_UINT16 GPHOTO2_ICAPPixelFlavor (pTW_CAPABILITY pCapability, TW_UINT16 action)
{
    TRACE("Action %d\n", action);

    switch (action)
    {
        case MSG_GET:
            if ((pCapability->ConType == TWON_DONTCARE16)	||
		(pCapability->ConType == TWON_ONEVALUE)
	    ) {
		if (!GPHOTO2_OneValueSet16 (pCapability, TWPF_CHOCOLATE))
		    return TWCC_LOWMEMORY;
		return TWCC_SUCCESS;
	    }
	    if (!pCapability->ConType) {
		TW_UINT16 arr[2];
		arr[0] = TWPF_CHOCOLATE;
		arr[1] = TWPF_VANILLA;

		if (!GPHOTO2_EnumSet16 (pCapability, 2, arr, 1, 1))
                    return TWCC_LOWMEMORY;
		return TWCC_SUCCESS;
	    }
	    FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
            return TWCC_BADVALUE;
        case MSG_SET:
            if (pCapability->ConType == TWON_ONEVALUE)
            {
		TW_UINT16 pixelflavor = 0;

                if (!GPHOTO2_OneValueGet16 (pCapability, &pixelflavor))
                    return TWCC_LOWMEMORY;
		activeDS.pixelflavor = pixelflavor;
		FIXME("pixelflavor is %d\n", pixelflavor);
            }
            break;
        case MSG_GETCURRENT:
            if (!GPHOTO2_OneValueSet16 (pCapability, activeDS.pixelflavor))
                return TWCC_LOWMEMORY;
            break;
        case MSG_GETDEFAULT:
            if (!GPHOTO2_OneValueSet16 (pCapability, TWPF_CHOCOLATE))
                return TWCC_LOWMEMORY;
            break;
        case MSG_RESET:
            break;
    }
    return TWCC_SUCCESS;
}

/* ICAP_BITDEPTH */
static TW_UINT16 GPHOTO2_ICAPBitDepth (pTW_CAPABILITY pCapability, TW_UINT16 action)
{
    TRACE("Action %d\n", action);

    switch (action)
    {
        case MSG_GET:
            if ((pCapability->ConType == TWON_DONTCARE16) ||
		(pCapability->ConType == TWON_ONEVALUE)
	    ) {
		if (!GPHOTO2_OneValueSet16 (pCapability, 24))
		    return TWCC_LOWMEMORY;
		return TWCC_SUCCESS;
	    }
	    FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
            return TWCC_SUCCESS;
        case MSG_SET:
            if (pCapability->ConType == TWON_ONEVALUE) {
		TW_UINT16 bitdepth = 0;

                if (!GPHOTO2_OneValueGet16 (pCapability, &bitdepth))
                    return TWCC_LOWMEMORY;
		if (bitdepth != 24)
		    return TWCC_BADVALUE;
		return TWCC_SUCCESS;
            }
            if (pCapability->ConType == TWON_ENUMERATION)
	    {
		int i, nrofvalues = 0;
		TW_UINT16 *values = NULL;

                if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
                    return TWCC_LOWMEMORY;
		for (i=0;i<nrofvalues;i++)
		    FIXME("SET: enum element %d = %d\n", i, values[i]);
		HeapFree (GetProcessHeap(), 0, values);
		return TWCC_SUCCESS;
	    }
	    FIXME("Unhandled container type %d in MSG_SET\n", pCapability->ConType);
            break;
        case MSG_GETCURRENT:
            if (!GPHOTO2_OneValueSet16 (pCapability, 24))
                return TWCC_LOWMEMORY;
            break;
        case MSG_GETDEFAULT:
            if (!GPHOTO2_OneValueSet16 (pCapability, 24))
                return TWCC_LOWMEMORY;
            break;
        case MSG_RESET:
            break;
    }
    return TWCC_SUCCESS;
}

/* ICAP_UNITS */
static TW_UINT16 GPHOTO2_ICAPUnits (pTW_CAPABILITY pCapability, TW_UINT16 action)
{
    TRACE("Action %d\n", action);

    switch (action)
    {
        case MSG_GET:
            if ((pCapability->ConType == TWON_DONTCARE16) ||
		(pCapability->ConType == TWON_ONEVALUE)
	    ) {
		if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_PIXELS))
		    return TWCC_LOWMEMORY;
		return TWCC_SUCCESS;
	    }
	    FIXME("MSG_GET container type %x unhandled\n", pCapability->ConType);
            return TWCC_SUCCESS;
        case MSG_SET:
            if (pCapability->ConType == TWON_ONEVALUE) {
		TW_UINT16 units = 0;

                if (!GPHOTO2_OneValueGet16 (pCapability, &units))
                    return TWCC_LOWMEMORY;
		FIXME("SET to type %d, stub.\n", units);
		return TWCC_SUCCESS;
            }
            if (pCapability->ConType == TWON_ENUMERATION)
	    {
		int i, nrofvalues = 0;
		TW_UINT16 *values = NULL;

                if (!GPHOTO2_EnumGet16 (pCapability, &nrofvalues, &values))
                    return TWCC_LOWMEMORY;
		for (i=0;i<nrofvalues;i++)
		    FIXME("SET: enum element %d = %d\n", i, values[i]);
		HeapFree (GetProcessHeap(), 0, values);
		return TWCC_SUCCESS;
	    }
	    FIXME("Unhandled container type %d in MSG_SET\n", pCapability->ConType);
            break;
        case MSG_GETCURRENT:
            if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_INCHES))
                return TWCC_LOWMEMORY;
            break;
        case MSG_GETDEFAULT:
            if (!GPHOTO2_OneValueSet16 (pCapability, TWUN_PIXELS))
                return TWCC_LOWMEMORY;
            break;
        case MSG_RESET:
            break;
    }
    return TWCC_SUCCESS;
}