diff --git a/twain/twain/twain_2.4.h b/twain/twain/twain_2.4.h deleted file mode 100644 index 0d1ce92..0000000 --- a/twain/twain/twain_2.4.h +++ /dev/null @@ -1,2265 +0,0 @@ -/* ======================================================================== *\ - - Copyright (C) 2007 TWAIN Working Group: Adobe Systems Incorporated, - AnyDoc Software Inc., Eastman Kodak Company, Fujitsu Computer Products - of America, JFL Peripheral Solutions Inc., Ricoh Corporation, and - Xerox Corporation. All rights reserved. - - Copyright (C) 1991, 1992 TWAIN Working Group: Aldus, Caere, Eastman-Kodak, - Hewlett-Packard and Logitech Corporations. All rights reserved. - - Copyright (C) 1997 TWAIN Working Group: Bell+Howell, Canon, DocuMagix, - Fujitsu, Genoa Technology, Hewlett-Packard, Kofax Imaging Products, and - Ricoh Corporation. All rights reserved. - - Copyright (C) 1998 TWAIN Working Group: Adobe Systems Incorporated, - Canon Information Systems, Eastman Kodak Company, - Fujitsu Computer Products of America, Genoa Technology, - Hewlett-Packard Company, Intel Corporation, Kofax Image Products, - JFL Peripheral Solutions Inc., Ricoh Corporation, and Xerox Corporation. - All rights reserved. - - Copyright (C) 2000 TWAIN Working Group: Adobe Systems Incorporated, - Canon Information Systems, Digimarc Corporation, Eastman Kodak Company, - Fujitsu Computer Products of America, Hewlett-Packard Company, - JFL Peripheral Solutions Inc., Ricoh Corporation, and Xerox Corporation. - All rights reserved. - - - TWAIN.h - This is the definitive include file for applications and - data sources written to the TWAIN specification. - It defines constants, data structures, messages etc. - for the public interface to TWAIN. - - Revision History: - version 1.0, March 6, 1992. TWAIN 1.0. - version 1.1, January 1993. Tech Notes 1.1 - version 1.5, June 1993. Specification Update 1.5 - Change DC to TW - Change filename from DC.H to TWAIN.H - version 1.5, July 1993. Remove spaces from country identifiers - - version 1.7, July 1997 Added Capabilities and data structure for - document imaging and digital cameras. - KHL. - version 1.7, July 1997 Inserted Borland compatibile structure packing - directives provided by Mentor. JMH - version 1.7, Aug 1997 Expanded file tabs to spaces. - NOTE: future authors should be sure to have - their editors set to automatically expand tabs - to spaces (original tab setting was 4 spaces). - version 1.7, Sept 1997 Added job control values - Added return codes - version 1.7, Sept 1997 changed definition of pRGBRESPONSE to - pTW_RGBRESPONSE - version 1.7 Aug 1998 Added missing TWEI_BARCODEROTATION values - TWBCOR_ types JMH - version 1.8 August 1998 Added new types and definitions required - for 1.8 Specification JMH - version 1.8 January 1999 Changed search mode from SRCH_ to TWBD_ as - in 1.8 Specification, added TWBT_MAXICODE JMH - version 1.8 January 1999 Removed undocumented duplicate AUTO JMH - version 1.8 March 1999 Removed undocumented 1.8 caps: - CAP_FILESYSTEM - CAP_PAPERBINDING - CAP_PASSTHRU - CAP_POWERDOWNTIME - ICAP_AUTODISCARDBLANKPAGES - * CAP_PAGEMULTIPLEACQUIRE - is CAP_REACQUIREALLOWED, - requires spec change. JMH - Added Mac structure packing modifications JMH - version 1.9 March 2000 Added new types and definations required - for 1.9 Specification MLM - version 1.9 March 2000 Added ICAP_JPEGQUALITY, TWJQ_ values, - updated TWON_PROTOCOLMINOR for Release v1.9 MN - version 1.91 August 2007 Added new types and definitions required - for 1.91 Specification MLM - version 2.0 Sept 2007 Added new types and definitions required - for 2.0 Specification FHH - version 2.0 Mar 2008 Depreciated ICAP_PIXELTYPEs TWPT_SRGB64, TWPT_BGR, - TWPT_CIELAB, TWPT_CIELUV, and TWPT_YCBCR JMW - version 2.0 Mar 2008 Added missing new 2.0 CAP_ definitions JMW - version 2.0 Dec 2008 Updated TW_INFO structure for 64bit JMW - version 2.1 Mar 2009 Added new types and definitions required - for 2.1 Specification JMW - version 2.2 Nov 2010 Added new types and definitions required - for 2.2 Specification MSM - version 2.3 Feb 2013 Added new types and definitions required - for 2.3 Specification MLM - version 2.3a Apr 2015 Errata fixes to TWCY_ANDORRA and TWCY_CUBA - version 2.4 Aug 2015 Added new types and definitions required - for 2.4 Specification MLM - version 2.4a June 2016 Added TW_INT32 and TW_UINT32 fixes for Linux, - (I just added this comment today) - version 2.4b March 2017 Missing changeset from 2.3 verion (2013/06/20) - - -\* ======================================================================== */ - -#ifndef TWAIN -#define TWAIN - -/**************************************************************************** - * TWAIN Version * - ****************************************************************************/ -#define TWON_PROTOCOLMINOR 4 /* Changed for Version 2.4 */ -#define TWON_PROTOCOLMAJOR 2 - -/**************************************************************************** - * Platform Dependent Definitions and Typedefs * - ****************************************************************************/ - -/* Microsoft C/C++ Compiler */ -#if defined(WIN32) || defined(WIN64) || defined (_WINDOWS) - #define TWH_CMP_MSC - #if defined(_WIN64) || defined(WIN64) - #define TWH_64BIT - #elif defined(WIN32) || defined(_WIN32) - #define TWH_32BIT - #endif - -/* GNU C/C++ Compiler */ -#elif defined(__GNUC__) - #define TWH_CMP_GNU - #if defined(__alpha__)\ - ||defined(__ia64__)\ - ||defined(__ppc64__)\ - ||defined(__s390x__)\ - ||defined(__x86_64__) - #define TWH_64BIT - #else - #define TWH_32BIT - #endif - - -/* Borland C/C++ Compiler */ -#elif defined(__BORLAND__) - #define TWH_CMP_BORLAND - #define TWH_32BIT -/* Unrecognized */ -#else - #error Unrecognized compiler -#endif - -/* Apple Compiler (which is GNU now) */ -#if defined(__APPLE__) - #define TWH_CMP_XCODE - #ifdef __MWERKS__ - #include - #else - #include - #endif -#endif - -/* Win32 and Win64 systems */ -#if defined(TWH_CMP_MSC) | defined(TWH_CMP_BORLAND) - typedef HANDLE TW_HANDLE; - typedef LPVOID TW_MEMREF; - typedef UINT_PTR TW_UINTPTR; - -/* MacOS/X... */ -#elif defined(TWH_CMP_XCODE) - #define PASCAL pascal - #define FAR - typedef Handle TW_HANDLE; - typedef char *TW_MEMREF; - typedef unsigned char BYTE; - - #ifdef TWH_32BIT - //32 bit GNU - typedef unsigned long TW_UINTPTR; - #else - //64 bit GNU - typedef unsigned long long TW_UINTPTR; - #endif - -/* Everything else... */ -#else - #define PASCAL - #define FAR - typedef void* TW_HANDLE; - typedef void* TW_MEMREF; - typedef unsigned char BYTE; - - #ifdef TWH_32BIT - //32 bit GNU - typedef unsigned long TW_UINTPTR; - #else - //64 bit GNU - typedef unsigned long long TW_UINTPTR; - #endif -#endif - - -/* Set the packing: this occurs before any structures are defined */ -#ifdef TWH_CMP_MSC - #pragma pack (push, before_twain) - #pragma pack (2) -#elif defined(TWH_CMP_GNU) - #if defined(__APPLE__) /* cf: Mac version of TWAIN.h */ - #pragma options align = power - #else - #pragma pack (push, before_twain) - #pragma pack (2) - #endif -#elif defined(TWH_CMP_BORLAND) - #pragma option -a2 -#endif - - -/**************************************************************************** - * Type Definitions * - ****************************************************************************/ - -/* String types. These include room for the strings and a NULL char, * - * or, on the Mac, a length byte followed by the string. * - * TW_STR255 must hold less than 256 chars so length fits in first byte. */ -#if defined(__APPLE__)/* cf: Mac version of TWAIN.h */ - typedef unsigned char TW_STR32[34], FAR *pTW_STR32; - typedef unsigned char TW_STR64[66], FAR *pTW_STR64; - typedef unsigned char TW_STR128[130], FAR *pTW_STR128; - typedef unsigned char TW_STR255[256], FAR *pTW_STR255; -#else - typedef char TW_STR32[34], FAR *pTW_STR32; - typedef char TW_STR64[66], FAR *pTW_STR64; - typedef char TW_STR128[130], FAR *pTW_STR128; - typedef char TW_STR255[256], FAR *pTW_STR255; -#endif - -/* Numeric types. */ -typedef char TW_INT8, FAR *pTW_INT8; -typedef short TW_INT16, FAR *pTW_INT16; -#if defined(_WIN32) - typedef long TW_INT32, FAR *pTW_INT32; -#else - typedef int TW_INT32, FAR *pTW_INT32; -#endif -typedef unsigned char TW_UINT8, FAR *pTW_UINT8; -typedef unsigned short TW_UINT16, FAR *pTW_UINT16; -#if defined(_WIN32) - typedef unsigned long TW_UINT32, FAR *pTW_UINT32; -#else - typedef unsigned int TW_UINT32, FAR *pTW_UINT32; -#endif -typedef unsigned short TW_BOOL, FAR *pTW_BOOL; - - -/**************************************************************************** - * Structure Definitions * - ****************************************************************************/ - -/* Fixed point structure type. */ -typedef struct { - TW_INT16 Whole; - TW_UINT16 Frac; -} TW_FIX32, FAR *pTW_FIX32; - -/* Defines a frame rectangle in ICAP_UNITS coordinates. */ -typedef struct { - TW_FIX32 Left; - TW_FIX32 Top; - TW_FIX32 Right; - TW_FIX32 Bottom; -} TW_FRAME, FAR * pTW_FRAME; - -/* Defines the parameters used for channel-specific transformation. */ -typedef struct { - TW_FIX32 StartIn; - TW_FIX32 BreakIn; - TW_FIX32 EndIn; - TW_FIX32 StartOut; - TW_FIX32 BreakOut; - TW_FIX32 EndOut; - TW_FIX32 Gamma; - TW_FIX32 SampleCount; -} TW_DECODEFUNCTION, FAR * pTW_DECODEFUNCTION; - -/* Stores a Fixed point number in two parts, a whole and a fractional part. */ -typedef struct { - TW_DECODEFUNCTION Decode[3]; - TW_FIX32 Mix[3][3]; -} TW_TRANSFORMSTAGE, FAR * pTW_TRANSFORMSTAGE; - -/* Container for array of values */ -typedef struct { - TW_UINT16 ItemType; - TW_UINT32 NumItems; - TW_UINT8 ItemList[1]; -} TW_ARRAY, FAR * pTW_ARRAY; - -/* Information about audio data */ -typedef struct { - TW_STR255 Name; - TW_UINT32 Reserved; -} TW_AUDIOINFO, FAR * pTW_AUDIOINFO; - -/* Used to register callbacks. */ -typedef struct { - TW_MEMREF CallBackProc; - #if defined(__APPLE__) /* cf: Mac version of TWAIN.h */ - TW_MEMREF RefCon; - #else - TW_UINT32 RefCon; - #endif - TW_INT16 Message; -} TW_CALLBACK, FAR * pTW_CALLBACK; - -/* Used to register callbacks. */ -typedef struct { - TW_MEMREF CallBackProc; - TW_UINTPTR RefCon; - TW_INT16 Message; -} TW_CALLBACK2, FAR * pTW_CALLBACK2; - -/* Used by application to get/set capability from/in a data source. */ -typedef struct { - TW_UINT16 Cap; - TW_UINT16 ConType; - TW_HANDLE hContainer; -} TW_CAPABILITY, FAR * pTW_CAPABILITY; - -/* Defines a CIE XYZ space tri-stimulus value. */ -typedef struct { - TW_FIX32 X; - TW_FIX32 Y; - TW_FIX32 Z; -} TW_CIEPOINT, FAR * pTW_CIEPOINT; - -/* Defines the mapping from an RGB color space device into CIE 1931 (XYZ) color space. */ -typedef struct { - TW_UINT16 ColorSpace; - TW_INT16 LowEndian; - TW_INT16 DeviceDependent; - TW_INT32 VersionNumber; - TW_TRANSFORMSTAGE StageABC; - TW_TRANSFORMSTAGE StageLMN; - TW_CIEPOINT WhitePoint; - TW_CIEPOINT BlackPoint; - TW_CIEPOINT WhitePaper; - TW_CIEPOINT BlackInk; - TW_FIX32 Samples[1]; -} TW_CIECOLOR, FAR * pTW_CIECOLOR; - -/* Allows for a data source and application to pass custom data to each other. */ -typedef struct { - TW_UINT32 InfoLength; - TW_HANDLE hData; -}TW_CUSTOMDSDATA, FAR *pTW_CUSTOMDSDATA; - -/* Provides information about the Event that was raised by the Source */ -typedef struct { - TW_UINT32 Event; - TW_STR255 DeviceName; - TW_UINT32 BatteryMinutes; - TW_INT16 BatteryPercentage; - TW_INT32 PowerSupply; - TW_FIX32 XResolution; - TW_FIX32 YResolution; - TW_UINT32 FlashUsed2; - TW_UINT32 AutomaticCapture; - TW_UINT32 TimeBeforeFirstCapture; - TW_UINT32 TimeBetweenCaptures; -} TW_DEVICEEVENT, FAR * pTW_DEVICEEVENT; - -/* This structure holds the tri-stimulus color palette information for TW_PALETTE8 structures.*/ -typedef struct { - TW_UINT8 Index; - TW_UINT8 Channel1; - TW_UINT8 Channel2; - TW_UINT8 Channel3; -} TW_ELEMENT8, FAR * pTW_ELEMENT8; - -/* Stores a group of individual values describing a capability. */ -typedef struct { - TW_UINT16 ItemType; - TW_UINT32 NumItems; - TW_UINT32 CurrentIndex; - TW_UINT32 DefaultIndex; - TW_UINT8 ItemList[1]; -} TW_ENUMERATION, FAR * pTW_ENUMERATION; - -/* Used to pass application events/messages from the application to the Source. */ -typedef struct { - TW_MEMREF pEvent; - TW_UINT16 TWMessage; -} TW_EVENT, FAR * pTW_EVENT; - -/* This structure is used to pass specific information between the data source and the application. */ -typedef struct { - TW_UINT16 InfoID; - TW_UINT16 ItemType; - TW_UINT16 NumItems; - union { - TW_UINT16 ReturnCode; - TW_UINT16 CondCode; // Deprecated, do not use - }; - TW_UINTPTR Item; -}TW_INFO, FAR* pTW_INFO; - -typedef struct { - TW_UINT32 NumInfos; - TW_INFO Info[1]; -}TW_EXTIMAGEINFO, FAR* pTW_EXTIMAGEINFO; - -/* Provides information about the currently selected device */ -typedef struct { - TW_STR255 InputName; - TW_STR255 OutputName; - TW_MEMREF Context; - union { - int Recursive; - TW_BOOL Subdirectories; - }; - union { - TW_INT32 FileType; - TW_UINT32 FileSystemType; - }; - TW_UINT32 Size; - TW_STR32 CreateTimeDate; - TW_STR32 ModifiedTimeDate; - TW_UINT32 FreeSpace; - TW_INT32 NewImageSize; - TW_UINT32 NumberOfFiles; - TW_UINT32 NumberOfSnippets; - TW_UINT32 DeviceGroupMask; - TW_INT8 Reserved[508]; -} TW_FILESYSTEM, FAR * pTW_FILESYSTEM; - -/* This structure is used by the application to specify a set of mapping values to be applied to grayscale data. */ -typedef struct { - TW_ELEMENT8 Response[1]; -} TW_GRAYRESPONSE, FAR * pTW_GRAYRESPONSE; - -/* A general way to describe the version of software that is running. */ -typedef struct { - TW_UINT16 MajorNum; - TW_UINT16 MinorNum; - TW_UINT16 Language; - TW_UINT16 Country; - TW_STR32 Info; -} TW_VERSION, FAR * pTW_VERSION; - -/* Provides identification information about a TWAIN entity.*/ -typedef struct { - #if defined(__APPLE__) /* cf: Mac version of TWAIN.h */ - TW_MEMREF Id; - #else - TW_UINT32 Id; - #endif - TW_VERSION Version; - TW_UINT16 ProtocolMajor; - TW_UINT16 ProtocolMinor; - TW_UINT32 SupportedGroups; - TW_STR32 Manufacturer; - TW_STR32 ProductFamily; - TW_STR32 ProductName; -} TW_IDENTITY, FAR * pTW_IDENTITY; - -/* Describes the "real" image data, that is, the complete image being transferred between the Source and application. */ -typedef struct { - TW_FIX32 XResolution; - TW_FIX32 YResolution; - TW_INT32 ImageWidth; - TW_INT32 ImageLength; - TW_INT16 SamplesPerPixel; - TW_INT16 BitsPerSample[8]; - TW_INT16 BitsPerPixel; - TW_BOOL Planar; - TW_INT16 PixelType; - TW_UINT16 Compression; -} TW_IMAGEINFO, FAR * pTW_IMAGEINFO; - -/* Involves information about the original size of the acquired image. */ -typedef struct { - TW_FRAME Frame; - TW_UINT32 DocumentNumber; - TW_UINT32 PageNumber; - TW_UINT32 FrameNumber; -} TW_IMAGELAYOUT, FAR * pTW_IMAGELAYOUT; - -/* Provides information for managing memory buffers. */ -typedef struct { - TW_UINT32 Flags; - TW_UINT32 Length; - TW_MEMREF TheMem; -} TW_MEMORY, FAR * pTW_MEMORY; - -/* Describes the form of the acquired data being passed from the Source to the application.*/ -typedef struct { - TW_UINT16 Compression; - TW_UINT32 BytesPerRow; - TW_UINT32 Columns; - TW_UINT32 Rows; - TW_UINT32 XOffset; - TW_UINT32 YOffset; - TW_UINT32 BytesWritten; - TW_MEMORY Memory; -} TW_IMAGEMEMXFER, FAR * pTW_IMAGEMEMXFER; - -/* Describes the information necessary to transfer a JPEG-compressed image. */ -typedef struct { - TW_UINT16 ColorSpace; - TW_UINT32 SubSampling; - TW_UINT16 NumComponents; - TW_UINT16 RestartFrequency; - TW_UINT16 QuantMap[4]; - TW_MEMORY QuantTable[4]; - TW_UINT16 HuffmanMap[4]; - TW_MEMORY HuffmanDC[2]; - TW_MEMORY HuffmanAC[2]; -} TW_JPEGCOMPRESSION, FAR * pTW_JPEGCOMPRESSION; - -/* Collects scanning metrics after returning to state 4 */ -typedef struct { - TW_UINT32 SizeOf; - TW_UINT32 ImageCount; - TW_UINT32 SheetCount; -} TW_METRICS, FAR * pTW_METRICS; - -/* Stores a single value (item) which describes a capability. */ -typedef struct { - TW_UINT16 ItemType; - TW_UINT32 Item; -} TW_ONEVALUE, FAR * pTW_ONEVALUE; - -/* This structure holds the color palette information. */ -typedef struct { - TW_UINT16 NumColors; - TW_UINT16 PaletteType; - TW_ELEMENT8 Colors[256]; -} TW_PALETTE8, FAR * pTW_PALETTE8; - -/* Used to bypass the TWAIN protocol when communicating with a device */ -typedef struct { - TW_MEMREF pCommand; - TW_UINT32 CommandBytes; - TW_INT32 Direction; - TW_MEMREF pData; - TW_UINT32 DataBytes; - TW_UINT32 DataBytesXfered; -} TW_PASSTHRU, FAR * pTW_PASSTHRU; - -/* This structure tells the application how many more complete transfers the Source currently has available. */ -typedef struct { - TW_UINT16 Count; - union { - TW_UINT32 EOJ; - TW_UINT32 Reserved; - #if defined(__APPLE__) /* cf: Mac version of TWAIN.h */ - union { - TW_UINT32 EOJ; - TW_UINT32 Reserved; - } TW_JOBCONTROL; - #endif - }; -} TW_PENDINGXFERS, FAR *pTW_PENDINGXFERS; - -/* Stores a range of individual values describing a capability. */ -typedef struct { - TW_UINT16 ItemType; - TW_UINT32 MinValue; - TW_UINT32 MaxValue; - TW_UINT32 StepSize; - TW_UINT32 DefaultValue; - TW_UINT32 CurrentValue; -} TW_RANGE, FAR * pTW_RANGE; - -/* This structure is used by the application to specify a set of mapping values to be applied to RGB color data. */ -typedef struct { - TW_ELEMENT8 Response[1]; -} TW_RGBRESPONSE, FAR * pTW_RGBRESPONSE; - -/* Describes the file format and file specification information for a transfer through a disk file. */ -typedef struct { - TW_STR255 FileName; - TW_UINT16 Format; - TW_INT16 VRefNum; -} TW_SETUPFILEXFER, FAR * pTW_SETUPFILEXFER; - -/* Provides the application information about the Source's requirements and preferences regarding allocation of transfer buffer(s). */ -typedef struct { - TW_UINT32 MinBufSize; - TW_UINT32 MaxBufSize; - TW_UINT32 Preferred; -} TW_SETUPMEMXFER, FAR * pTW_SETUPMEMXFER; - -/* Describes the status of a source. */ -typedef struct { - TW_UINT16 ConditionCode; - union { - TW_UINT16 Data; - TW_UINT16 Reserved; - }; -} TW_STATUS, FAR * pTW_STATUS; - -/* Translates the contents of Status into a localized UTF8string. */ -typedef struct { - TW_STATUS Status; - TW_UINT32 Size; - TW_HANDLE UTF8string; -} TW_STATUSUTF8, FAR * pTW_STATUSUTF8; - -typedef struct { - TW_UINT32 SizeOf; - TW_UINT16 CommunicationManager; - TW_HANDLE Send; - TW_UINT32 SendSize; - TW_HANDLE Receive; - TW_UINT32 ReceiveSize; -} TW_TWAINDIRECT, FAR * pTW_TWAINDIRECT; - -/* This structure is used to handle the user interface coordination between an application and a Source. */ -typedef struct { - TW_BOOL ShowUI; - TW_BOOL ModalUI; - TW_HANDLE hParent; -} TW_USERINTERFACE, FAR * pTW_USERINTERFACE; - - -/**************************************************************************** - * Generic Constants * - ****************************************************************************/ - -#define TWON_ARRAY 3 -#define TWON_ENUMERATION 4 -#define TWON_ONEVALUE 5 -#define TWON_RANGE 6 - -#define TWON_ICONID 962 -#define TWON_DSMID 461 -#define TWON_DSMCODEID 63 - -#define TWON_DONTCARE8 0xff -#define TWON_DONTCARE16 0xffff -#define TWON_DONTCARE32 0xffffffff - -/* Flags used in TW_MEMORY structure. */ -#define TWMF_APPOWNS 0x0001 -#define TWMF_DSMOWNS 0x0002 -#define TWMF_DSOWNS 0x0004 -#define TWMF_POINTER 0x0008 -#define TWMF_HANDLE 0x0010 - -#define TWTY_INT8 0x0000 -#define TWTY_INT16 0x0001 -#define TWTY_INT32 0x0002 - -#define TWTY_UINT8 0x0003 -#define TWTY_UINT16 0x0004 -#define TWTY_UINT32 0x0005 - -#define TWTY_BOOL 0x0006 - -#define TWTY_FIX32 0x0007 - -#define TWTY_FRAME 0x0008 - -#define TWTY_STR32 0x0009 -#define TWTY_STR64 0x000a -#define TWTY_STR128 0x000b -#define TWTY_STR255 0x000c -#define TWTY_HANDLE 0x000f - - -/**************************************************************************** - * Capability Constants * - ****************************************************************************/ - -/* CAP_ALARMS values */ -#define TWAL_ALARM 0 -#define TWAL_FEEDERERROR 1 -#define TWAL_FEEDERWARNING 2 -#define TWAL_BARCODE 3 -#define TWAL_DOUBLEFEED 4 -#define TWAL_JAM 5 -#define TWAL_PATCHCODE 6 -#define TWAL_POWER 7 -#define TWAL_SKEW 8 - -/* ICAP_AUTOSIZE values */ -#define TWAS_NONE 0 -#define TWAS_AUTO 1 -#define TWAS_CURRENT 2 - -/* TWEI_BARCODEROTATION values */ -#define TWBCOR_ROT0 0 -#define TWBCOR_ROT90 1 -#define TWBCOR_ROT180 2 -#define TWBCOR_ROT270 3 -#define TWBCOR_ROTX 4 - -/* ICAP_BARCODESEARCHMODE values */ -#define TWBD_HORZ 0 -#define TWBD_VERT 1 -#define TWBD_HORZVERT 2 -#define TWBD_VERTHORZ 3 - -/* ICAP_BITORDER values */ -#define TWBO_LSBFIRST 0 -#define TWBO_MSBFIRST 1 - -/* ICAP_AUTODISCARDBLANKPAGES values */ -#define TWBP_DISABLE -2 -#define TWBP_AUTO -1 - -/* ICAP_BITDEPTHREDUCTION values */ -#define TWBR_THRESHOLD 0 -#define TWBR_HALFTONE 1 -#define TWBR_CUSTHALFTONE 2 -#define TWBR_DIFFUSION 3 -#define TWBR_DYNAMICTHRESHOLD 4 - -/* ICAP_SUPPORTEDBARCODETYPES and TWEI_BARCODETYPE values*/ -#define TWBT_3OF9 0 -#define TWBT_2OF5INTERLEAVED 1 -#define TWBT_2OF5NONINTERLEAVED 2 -#define TWBT_CODE93 3 -#define TWBT_CODE128 4 -#define TWBT_UCC128 5 -#define TWBT_CODABAR 6 -#define TWBT_UPCA 7 -#define TWBT_UPCE 8 -#define TWBT_EAN8 9 -#define TWBT_EAN13 10 -#define TWBT_POSTNET 11 -#define TWBT_PDF417 12 -#define TWBT_2OF5INDUSTRIAL 13 -#define TWBT_2OF5MATRIX 14 -#define TWBT_2OF5DATALOGIC 15 -#define TWBT_2OF5IATA 16 -#define TWBT_3OF9FULLASCII 17 -#define TWBT_CODABARWITHSTARTSTOP 18 -#define TWBT_MAXICODE 19 -#define TWBT_QRCODE 20 - -/* ICAP_COMPRESSION values*/ -#define TWCP_NONE 0 -#define TWCP_PACKBITS 1 -#define TWCP_GROUP31D 2 -#define TWCP_GROUP31DEOL 3 -#define TWCP_GROUP32D 4 -#define TWCP_GROUP4 5 -#define TWCP_JPEG 6 -#define TWCP_LZW 7 -#define TWCP_JBIG 8 -#define TWCP_PNG 9 -#define TWCP_RLE4 10 -#define TWCP_RLE8 11 -#define TWCP_BITFIELDS 12 -#define TWCP_ZIP 13 -#define TWCP_JPEG2000 14 - -/* CAP_CAMERASIDE and TWEI_PAGESIDE values */ -#define TWCS_BOTH 0 -#define TWCS_TOP 1 -#define TWCS_BOTTOM 2 - -/* CAP_DEVICEEVENT values */ -#define TWDE_CUSTOMEVENTS 0x8000 -#define TWDE_CHECKAUTOMATICCAPTURE 0 -#define TWDE_CHECKBATTERY 1 -#define TWDE_CHECKDEVICEONLINE 2 -#define TWDE_CHECKFLASH 3 -#define TWDE_CHECKPOWERSUPPLY 4 -#define TWDE_CHECKRESOLUTION 5 -#define TWDE_DEVICEADDED 6 -#define TWDE_DEVICEOFFLINE 7 -#define TWDE_DEVICEREADY 8 -#define TWDE_DEVICEREMOVED 9 -#define TWDE_IMAGECAPTURED 10 -#define TWDE_IMAGEDELETED 11 -#define TWDE_PAPERDOUBLEFEED 12 -#define TWDE_PAPERJAM 13 -#define TWDE_LAMPFAILURE 14 -#define TWDE_POWERSAVE 15 -#define TWDE_POWERSAVENOTIFY 16 - -/* TW_PASSTHRU.Direction values. */ -#define TWDR_GET 1 -#define TWDR_SET 2 - -/* TWEI_DESKEWSTATUS values. */ -#define TWDSK_SUCCESS 0 -#define TWDSK_REPORTONLY 1 -#define TWDSK_FAIL 2 -#define TWDSK_DISABLED 3 - -/* CAP_DUPLEX values */ -#define TWDX_NONE 0 -#define TWDX_1PASSDUPLEX 1 -#define TWDX_2PASSDUPLEX 2 - -/* CAP_FEEDERALIGNMENT values */ -#define TWFA_NONE 0 -#define TWFA_LEFT 1 -#define TWFA_CENTER 2 -#define TWFA_RIGHT 3 - -/* ICAP_FEEDERTYPE values*/ -#define TWFE_GENERAL 0 -#define TWFE_PHOTO 1 - -/* ICAP_IMAGEFILEFORMAT values */ -#define TWFF_TIFF 0 -#define TWFF_PICT 1 -#define TWFF_BMP 2 -#define TWFF_XBM 3 -#define TWFF_JFIF 4 -#define TWFF_FPX 5 -#define TWFF_TIFFMULTI 6 -#define TWFF_PNG 7 -#define TWFF_SPIFF 8 -#define TWFF_EXIF 9 -#define TWFF_PDF 10 -#define TWFF_JP2 11 -#define TWFF_JPX 13 -#define TWFF_DEJAVU 14 -#define TWFF_PDFA 15 -#define TWFF_PDFA2 16 -#define TWFF_PDFRASTER 17 - -/* ICAP_FLASHUSED2 values */ -#define TWFL_NONE 0 -#define TWFL_OFF 1 -#define TWFL_ON 2 -#define TWFL_AUTO 3 -#define TWFL_REDEYE 4 - -/* CAP_FEEDERORDER values */ -#define TWFO_FIRSTPAGEFIRST 0 -#define TWFO_LASTPAGEFIRST 1 - -/* CAP_FEEDERPOCKET values*/ -#define TWFP_POCKETERROR 0 -#define TWFP_POCKET1 1 -#define TWFP_POCKET2 2 -#define TWFP_POCKET3 3 -#define TWFP_POCKET4 4 -#define TWFP_POCKET5 5 -#define TWFP_POCKET6 6 -#define TWFP_POCKET7 7 -#define TWFP_POCKET8 8 -#define TWFP_POCKET9 9 -#define TWFP_POCKET10 10 -#define TWFP_POCKET11 11 -#define TWFP_POCKET12 12 -#define TWFP_POCKET13 13 -#define TWFP_POCKET14 14 -#define TWFP_POCKET15 15 -#define TWFP_POCKET16 16 - -/* ICAP_FLIPROTATION values */ -#define TWFR_BOOK 0 -#define TWFR_FANFOLD 1 - -/* ICAP_FILTER values */ -#define TWFT_RED 0 -#define TWFT_GREEN 1 -#define TWFT_BLUE 2 -#define TWFT_NONE 3 -#define TWFT_WHITE 4 -#define TWFT_CYAN 5 -#define TWFT_MAGENTA 6 -#define TWFT_YELLOW 7 -#define TWFT_BLACK 8 - -/* TW_FILESYSTEM.FileType values */ -#define TWFY_CAMERA 0 -#define TWFY_CAMERATOP 1 -#define TWFY_CAMERABOTTOM 2 -#define TWFY_CAMERAPREVIEW 3 -#define TWFY_DOMAIN 4 -#define TWFY_HOST 5 -#define TWFY_DIRECTORY 6 -#define TWFY_IMAGE 7 -#define TWFY_UNKNOWN 8 - -/* ICAP_ICCPROFILE values */ -#define TWIC_NONE 0 -#define TWIC_LINK 1 -#define TWIC_EMBED 2 - -/* ICAP_IMAGEFILTER values */ -#define TWIF_NONE 0 -#define TWIF_AUTO 1 -#define TWIF_LOWPASS 2 -#define TWIF_BANDPASS 3 -#define TWIF_HIGHPASS 4 -#define TWIF_TEXT TWIF_BANDPASS -#define TWIF_FINELINE TWIF_HIGHPASS - -/* ICAP_IMAGEMERGE values */ -#define TWIM_NONE 0 -#define TWIM_FRONTONTOP 1 -#define TWIM_FRONTONBOTTOM 2 -#define TWIM_FRONTONLEFT 3 -#define TWIM_FRONTONRIGHT 4 - -/* CAP_JOBCONTROL values */ -#define TWJC_NONE 0 -#define TWJC_JSIC 1 -#define TWJC_JSIS 2 -#define TWJC_JSXC 3 -#define TWJC_JSXS 4 - -/* ICAP_JPEGQUALITY values */ -#define TWJQ_UNKNOWN -4 -#define TWJQ_LOW -3 -#define TWJQ_MEDIUM -2 -#define TWJQ_HIGH -1 - -/* ICAP_LIGHTPATH values */ -#define TWLP_REFLECTIVE 0 -#define TWLP_TRANSMISSIVE 1 - -/* ICAP_LIGHTSOURCE values */ -#define TWLS_RED 0 -#define TWLS_GREEN 1 -#define TWLS_BLUE 2 -#define TWLS_NONE 3 -#define TWLS_WHITE 4 -#define TWLS_UV 5 -#define TWLS_IR 6 - -/* TWEI_MAGTYPE values */ -#define TWMD_MICR 0 -#define TWMD_RAW 1 -#define TWMD_INVALID 2 - -/* ICAP_NOISEFILTER values */ -#define TWNF_NONE 0 -#define TWNF_AUTO 1 -#define TWNF_LONEPIXEL 2 -#define TWNF_MAJORITYRULE 3 - -/* ICAP_ORIENTATION values */ -#define TWOR_ROT0 0 -#define TWOR_ROT90 1 -#define TWOR_ROT180 2 -#define TWOR_ROT270 3 -#define TWOR_PORTRAIT TWOR_ROT0 -#define TWOR_LANDSCAPE TWOR_ROT270 -#define TWOR_AUTO 4 -#define TWOR_AUTOTEXT 5 -#define TWOR_AUTOPICTURE 6 - -/* ICAP_OVERSCAN values */ -#define TWOV_NONE 0 -#define TWOV_AUTO 1 -#define TWOV_TOPBOTTOM 2 -#define TWOV_LEFTRIGHT 3 -#define TWOV_ALL 4 - -/* Palette types for TW_PALETTE8 */ -#define TWPA_RGB 0 -#define TWPA_GRAY 1 -#define TWPA_CMY 2 - -/* ICAP_PLANARCHUNKY values */ -#define TWPC_CHUNKY 0 -#define TWPC_PLANAR 1 - -/* TWEI_PATCHCODE values*/ -#define TWPCH_PATCH1 0 -#define TWPCH_PATCH2 1 -#define TWPCH_PATCH3 2 -#define TWPCH_PATCH4 3 -#define TWPCH_PATCH6 4 -#define TWPCH_PATCHT 5 - -/* ICAP_PIXELFLAVOR values */ -#define TWPF_CHOCOLATE 0 -#define TWPF_VANILLA 1 - -/* CAP_PRINTERMODE values */ -#define TWPM_SINGLESTRING 0 -#define TWPM_MULTISTRING 1 -#define TWPM_COMPOUNDSTRING 2 - -/* CAP_PRINTER values */ -#define TWPR_IMPRINTERTOPBEFORE 0 -#define TWPR_IMPRINTERTOPAFTER 1 -#define TWPR_IMPRINTERBOTTOMBEFORE 2 -#define TWPR_IMPRINTERBOTTOMAFTER 3 -#define TWPR_ENDORSERTOPBEFORE 4 -#define TWPR_ENDORSERTOPAFTER 5 -#define TWPR_ENDORSERBOTTOMBEFORE 6 -#define TWPR_ENDORSERBOTTOMAFTER 7 - -/* CAP_PRINTERFONTSTYLE Added 2.3 */ -#define TWPF_NORMAL 0 -#define TWPF_BOLD 1 -#define TWPF_ITALIC 2 -#define TWPF_LARGESIZE 3 -#define TWPF_SMALLSIZE 4 - -/* CAP_PRINTERINDEXTRIGGER Added 2.3 */ -#define TWCT_PAGE 0 -#define TWCT_PATCH1 1 -#define TWCT_PATCH2 2 -#define TWCT_PATCH3 3 -#define TWCT_PATCH4 4 -#define TWCT_PATCHT 5 -#define TWCT_PATCH6 6 - -/* CAP_POWERSUPPLY values */ -#define TWPS_EXTERNAL 0 -#define TWPS_BATTERY 1 - -/* ICAP_PIXELTYPE values (PT_ means Pixel Type) */ -#define TWPT_BW 0 -#define TWPT_GRAY 1 -#define TWPT_RGB 2 -#define TWPT_PALETTE 3 -#define TWPT_CMY 4 -#define TWPT_CMYK 5 -#define TWPT_YUV 6 -#define TWPT_YUVK 7 -#define TWPT_CIEXYZ 8 -#define TWPT_LAB 9 -#define TWPT_SRGB 10 -#define TWPT_SCRGB 11 -#define TWPT_INFRARED 16 - -/* CAP_SEGMENTED values */ -#define TWSG_NONE 0 -#define TWSG_AUTO 1 -#define TWSG_MANUAL 2 - -/* ICAP_FILMTYPE values */ -#define TWFM_POSITIVE 0 -#define TWFM_NEGATIVE 1 - -/* CAP_DOUBLEFEEDDETECTION */ -#define TWDF_ULTRASONIC 0 -#define TWDF_BYLENGTH 1 -#define TWDF_INFRARED 2 - -/* CAP_DOUBLEFEEDDETECTIONSENSITIVITY */ -#define TWUS_LOW 0 -#define TWUS_MEDIUM 1 -#define TWUS_HIGH 2 - -/* CAP_DOUBLEFEEDDETECTIONRESPONSE */ -#define TWDP_STOP 0 -#define TWDP_STOPANDWAIT 1 -#define TWDP_SOUND 2 -#define TWDP_DONOTIMPRINT 3 - -/* ICAP_MIRROR values */ -#define TWMR_NONE 0 -#define TWMR_VERTICAL 1 -#define TWMR_HORIZONTAL 2 - -/* ICAP_JPEGSUBSAMPLING values */ -#define TWJS_444YCBCR 0 -#define TWJS_444RGB 1 -#define TWJS_422 2 -#define TWJS_421 3 -#define TWJS_411 4 -#define TWJS_420 5 -#define TWJS_410 6 -#define TWJS_311 7 - -/* CAP_PAPERHANDLING values */ -#define TWPH_NORMAL 0 -#define TWPH_FRAGILE 1 -#define TWPH_THICK 2 -#define TWPH_TRIFOLD 3 -#define TWPH_PHOTOGRAPH 4 - -/* CAP_INDICATORSMODE values */ -#define TWCI_INFO 0 -#define TWCI_WARNING 1 -#define TWCI_ERROR 2 -#define TWCI_WARMUP 3 - -/* ICAP_SUPPORTEDSIZES values (SS_ means Supported Sizes) */ -#define TWSS_NONE 0 -#define TWSS_A4 1 -#define TWSS_JISB5 2 -#define TWSS_USLETTER 3 -#define TWSS_USLEGAL 4 -#define TWSS_A5 5 -#define TWSS_ISOB4 6 -#define TWSS_ISOB6 7 -#define TWSS_USLEDGER 9 -#define TWSS_USEXECUTIVE 10 -#define TWSS_A3 11 -#define TWSS_ISOB3 12 -#define TWSS_A6 13 -#define TWSS_C4 14 -#define TWSS_C5 15 -#define TWSS_C6 16 -#define TWSS_4A0 17 -#define TWSS_2A0 18 -#define TWSS_A0 19 -#define TWSS_A1 20 -#define TWSS_A2 21 -#define TWSS_A7 22 -#define TWSS_A8 23 -#define TWSS_A9 24 -#define TWSS_A10 25 -#define TWSS_ISOB0 26 -#define TWSS_ISOB1 27 -#define TWSS_ISOB2 28 -#define TWSS_ISOB5 29 -#define TWSS_ISOB7 30 -#define TWSS_ISOB8 31 -#define TWSS_ISOB9 32 -#define TWSS_ISOB10 33 -#define TWSS_JISB0 34 -#define TWSS_JISB1 35 -#define TWSS_JISB2 36 -#define TWSS_JISB3 37 -#define TWSS_JISB4 38 -#define TWSS_JISB6 39 -#define TWSS_JISB7 40 -#define TWSS_JISB8 41 -#define TWSS_JISB9 42 -#define TWSS_JISB10 43 -#define TWSS_C0 44 -#define TWSS_C1 45 -#define TWSS_C2 46 -#define TWSS_C3 47 -#define TWSS_C7 48 -#define TWSS_C8 49 -#define TWSS_C9 50 -#define TWSS_C10 51 -#define TWSS_USSTATEMENT 52 -#define TWSS_BUSINESSCARD 53 -#define TWSS_MAXSIZE 54 - -/* ICAP_XFERMECH values (SX_ means Setup XFer) */ -#define TWSX_NATIVE 0 -#define TWSX_FILE 1 -#define TWSX_MEMORY 2 -#define TWSX_MEMFILE 4 - -/* ICAP_UNITS values (UN_ means UNits) */ -#define TWUN_INCHES 0 -#define TWUN_CENTIMETERS 1 -#define TWUN_PICAS 2 -#define TWUN_POINTS 3 -#define TWUN_TWIPS 4 -#define TWUN_PIXELS 5 -#define TWUN_MILLIMETERS 6 - - -/**************************************************************************** - * Country Constants * - ****************************************************************************/ - -#define TWCY_AFGHANISTAN 1001 -#define TWCY_ALGERIA 213 -#define TWCY_AMERICANSAMOA 684 -#define TWCY_ANDORRA 33 -#define TWCY_ANGOLA 1002 -#define TWCY_ANGUILLA 8090 -#define TWCY_ANTIGUA 8091 -#define TWCY_ARGENTINA 54 -#define TWCY_ARUBA 297 -#define TWCY_ASCENSIONI 247 -#define TWCY_AUSTRALIA 61 -#define TWCY_AUSTRIA 43 -#define TWCY_BAHAMAS 8092 -#define TWCY_BAHRAIN 973 -#define TWCY_BANGLADESH 880 -#define TWCY_BARBADOS 8093 -#define TWCY_BELGIUM 32 -#define TWCY_BELIZE 501 -#define TWCY_BENIN 229 -#define TWCY_BERMUDA 8094 -#define TWCY_BHUTAN 1003 -#define TWCY_BOLIVIA 591 -#define TWCY_BOTSWANA 267 -#define TWCY_BRITAIN 6 -#define TWCY_BRITVIRGINIS 8095 -#define TWCY_BRAZIL 55 -#define TWCY_BRUNEI 673 -#define TWCY_BULGARIA 359 -#define TWCY_BURKINAFASO 1004 -#define TWCY_BURMA 1005 -#define TWCY_BURUNDI 1006 -#define TWCY_CAMAROON 237 -#define TWCY_CANADA 2 -#define TWCY_CAPEVERDEIS 238 -#define TWCY_CAYMANIS 8096 -#define TWCY_CENTRALAFREP 1007 -#define TWCY_CHAD 1008 -#define TWCY_CHILE 56 -#define TWCY_CHINA 86 -#define TWCY_CHRISTMASIS 1009 -#define TWCY_COCOSIS 1009 -#define TWCY_COLOMBIA 57 -#define TWCY_COMOROS 1010 -#define TWCY_CONGO 1011 -#define TWCY_COOKIS 1012 -#define TWCY_COSTARICA 506 -#define TWCY_CUBA 5 -#define TWCY_CYPRUS 357 -#define TWCY_CZECHOSLOVAKIA 42 -#define TWCY_DENMARK 45 -#define TWCY_DJIBOUTI 1013 -#define TWCY_DOMINICA 8097 -#define TWCY_DOMINCANREP 8098 -#define TWCY_EASTERIS 1014 -#define TWCY_ECUADOR 593 -#define TWCY_EGYPT 20 -#define TWCY_ELSALVADOR 503 -#define TWCY_EQGUINEA 1015 -#define TWCY_ETHIOPIA 251 -#define TWCY_FALKLANDIS 1016 -#define TWCY_FAEROEIS 298 -#define TWCY_FIJIISLANDS 679 -#define TWCY_FINLAND 358 -#define TWCY_FRANCE 33 -#define TWCY_FRANTILLES 596 -#define TWCY_FRGUIANA 594 -#define TWCY_FRPOLYNEISA 689 -#define TWCY_FUTANAIS 1043 -#define TWCY_GABON 241 -#define TWCY_GAMBIA 220 -#define TWCY_GERMANY 49 -#define TWCY_GHANA 233 -#define TWCY_GIBRALTER 350 -#define TWCY_GREECE 30 -#define TWCY_GREENLAND 299 -#define TWCY_GRENADA 8099 -#define TWCY_GRENEDINES 8015 -#define TWCY_GUADELOUPE 590 -#define TWCY_GUAM 671 -#define TWCY_GUANTANAMOBAY 5399 -#define TWCY_GUATEMALA 502 -#define TWCY_GUINEA 224 -#define TWCY_GUINEABISSAU 1017 -#define TWCY_GUYANA 592 -#define TWCY_HAITI 509 -#define TWCY_HONDURAS 504 -#define TWCY_HONGKONG 852 -#define TWCY_HUNGARY 36 -#define TWCY_ICELAND 354 -#define TWCY_INDIA 91 -#define TWCY_INDONESIA 62 -#define TWCY_IRAN 98 -#define TWCY_IRAQ 964 -#define TWCY_IRELAND 353 -#define TWCY_ISRAEL 972 -#define TWCY_ITALY 39 -#define TWCY_IVORYCOAST 225 -#define TWCY_JAMAICA 8010 -#define TWCY_JAPAN 81 -#define TWCY_JORDAN 962 -#define TWCY_KENYA 254 -#define TWCY_KIRIBATI 1018 -#define TWCY_KOREA 82 -#define TWCY_KUWAIT 965 -#define TWCY_LAOS 1019 -#define TWCY_LEBANON 1020 -#define TWCY_LIBERIA 231 -#define TWCY_LIBYA 218 -#define TWCY_LIECHTENSTEIN 41 -#define TWCY_LUXENBOURG 352 -#define TWCY_MACAO 853 -#define TWCY_MADAGASCAR 1021 -#define TWCY_MALAWI 265 -#define TWCY_MALAYSIA 60 -#define TWCY_MALDIVES 960 -#define TWCY_MALI 1022 -#define TWCY_MALTA 356 -#define TWCY_MARSHALLIS 692 -#define TWCY_MAURITANIA 1023 -#define TWCY_MAURITIUS 230 -#define TWCY_MEXICO 3 -#define TWCY_MICRONESIA 691 -#define TWCY_MIQUELON 508 -#define TWCY_MONACO 33 -#define TWCY_MONGOLIA 1024 -#define TWCY_MONTSERRAT 8011 -#define TWCY_MOROCCO 212 -#define TWCY_MOZAMBIQUE 1025 -#define TWCY_NAMIBIA 264 -#define TWCY_NAURU 1026 -#define TWCY_NEPAL 977 -#define TWCY_NETHERLANDS 31 -#define TWCY_NETHANTILLES 599 -#define TWCY_NEVIS 8012 -#define TWCY_NEWCALEDONIA 687 -#define TWCY_NEWZEALAND 64 -#define TWCY_NICARAGUA 505 -#define TWCY_NIGER 227 -#define TWCY_NIGERIA 234 -#define TWCY_NIUE 1027 -#define TWCY_NORFOLKI 1028 -#define TWCY_NORWAY 47 -#define TWCY_OMAN 968 -#define TWCY_PAKISTAN 92 -#define TWCY_PALAU 1029 -#define TWCY_PANAMA 507 -#define TWCY_PARAGUAY 595 -#define TWCY_PERU 51 -#define TWCY_PHILLIPPINES 63 -#define TWCY_PITCAIRNIS 1030 -#define TWCY_PNEWGUINEA 675 -#define TWCY_POLAND 48 -#define TWCY_PORTUGAL 351 -#define TWCY_QATAR 974 -#define TWCY_REUNIONI 1031 -#define TWCY_ROMANIA 40 -#define TWCY_RWANDA 250 -#define TWCY_SAIPAN 670 -#define TWCY_SANMARINO 39 -#define TWCY_SAOTOME 1033 -#define TWCY_SAUDIARABIA 966 -#define TWCY_SENEGAL 221 -#define TWCY_SEYCHELLESIS 1034 -#define TWCY_SIERRALEONE 1035 -#define TWCY_SINGAPORE 65 -#define TWCY_SOLOMONIS 1036 -#define TWCY_SOMALI 1037 -#define TWCY_SOUTHAFRICA 27 -#define TWCY_SPAIN 34 -#define TWCY_SRILANKA 94 -#define TWCY_STHELENA 1032 -#define TWCY_STKITTS 8013 -#define TWCY_STLUCIA 8014 -#define TWCY_STPIERRE 508 -#define TWCY_STVINCENT 8015 -#define TWCY_SUDAN 1038 -#define TWCY_SURINAME 597 -#define TWCY_SWAZILAND 268 -#define TWCY_SWEDEN 46 -#define TWCY_SWITZERLAND 41 -#define TWCY_SYRIA 1039 -#define TWCY_TAIWAN 886 -#define TWCY_TANZANIA 255 -#define TWCY_THAILAND 66 -#define TWCY_TOBAGO 8016 -#define TWCY_TOGO 228 -#define TWCY_TONGAIS 676 -#define TWCY_TRINIDAD 8016 -#define TWCY_TUNISIA 216 -#define TWCY_TURKEY 90 -#define TWCY_TURKSCAICOS 8017 -#define TWCY_TUVALU 1040 -#define TWCY_UGANDA 256 -#define TWCY_USSR 7 -#define TWCY_UAEMIRATES 971 -#define TWCY_UNITEDKINGDOM 44 -#define TWCY_USA 1 -#define TWCY_URUGUAY 598 -#define TWCY_VANUATU 1041 -#define TWCY_VATICANCITY 39 -#define TWCY_VENEZUELA 58 -#define TWCY_WAKE 1042 -#define TWCY_WALLISIS 1043 -#define TWCY_WESTERNSAHARA 1044 -#define TWCY_WESTERNSAMOA 1045 -#define TWCY_YEMEN 1046 -#define TWCY_YUGOSLAVIA 38 -#define TWCY_ZAIRE 243 -#define TWCY_ZAMBIA 260 -#define TWCY_ZIMBABWE 263 -#define TWCY_ALBANIA 355 -#define TWCY_ARMENIA 374 -#define TWCY_AZERBAIJAN 994 -#define TWCY_BELARUS 375 -#define TWCY_BOSNIAHERZGO 387 -#define TWCY_CAMBODIA 855 -#define TWCY_CROATIA 385 -#define TWCY_CZECHREPUBLIC 420 -#define TWCY_DIEGOGARCIA 246 -#define TWCY_ERITREA 291 -#define TWCY_ESTONIA 372 -#define TWCY_GEORGIA 995 -#define TWCY_LATVIA 371 -#define TWCY_LESOTHO 266 -#define TWCY_LITHUANIA 370 -#define TWCY_MACEDONIA 389 -#define TWCY_MAYOTTEIS 269 -#define TWCY_MOLDOVA 373 -#define TWCY_MYANMAR 95 -#define TWCY_NORTHKOREA 850 -#define TWCY_PUERTORICO 787 -#define TWCY_RUSSIA 7 -#define TWCY_SERBIA 381 -#define TWCY_SLOVAKIA 421 -#define TWCY_SLOVENIA 386 -#define TWCY_SOUTHKOREA 82 -#define TWCY_UKRAINE 380 -#define TWCY_USVIRGINIS 340 -#define TWCY_VIETNAM 84 - -/**************************************************************************** - * Language Constants * - ****************************************************************************/ -#define TWLG_USERLOCALE -1 -#define TWLG_DAN 0 -#define TWLG_DUT 1 -#define TWLG_ENG 2 -#define TWLG_FCF 3 -#define TWLG_FIN 4 -#define TWLG_FRN 5 -#define TWLG_GER 6 -#define TWLG_ICE 7 -#define TWLG_ITN 8 -#define TWLG_NOR 9 -#define TWLG_POR 10 -#define TWLG_SPA 11 -#define TWLG_SWE 12 -#define TWLG_USA 13 -#define TWLG_AFRIKAANS 14 -#define TWLG_ALBANIA 15 -#define TWLG_ARABIC 16 -#define TWLG_ARABIC_ALGERIA 17 -#define TWLG_ARABIC_BAHRAIN 18 -#define TWLG_ARABIC_EGYPT 19 -#define TWLG_ARABIC_IRAQ 20 -#define TWLG_ARABIC_JORDAN 21 -#define TWLG_ARABIC_KUWAIT 22 -#define TWLG_ARABIC_LEBANON 23 -#define TWLG_ARABIC_LIBYA 24 -#define TWLG_ARABIC_MOROCCO 25 -#define TWLG_ARABIC_OMAN 26 -#define TWLG_ARABIC_QATAR 27 -#define TWLG_ARABIC_SAUDIARABIA 28 -#define TWLG_ARABIC_SYRIA 29 -#define TWLG_ARABIC_TUNISIA 30 -#define TWLG_ARABIC_UAE 31 -#define TWLG_ARABIC_YEMEN 32 -#define TWLG_BASQUE 33 -#define TWLG_BYELORUSSIAN 34 -#define TWLG_BULGARIAN 35 -#define TWLG_CATALAN 36 -#define TWLG_CHINESE 37 -#define TWLG_CHINESE_HONGKONG 38 -#define TWLG_CHINESE_PRC 39 -#define TWLG_CHINESE_SINGAPORE 40 -#define TWLG_CHINESE_SIMPLIFIED 41 -#define TWLG_CHINESE_TAIWAN 42 -#define TWLG_CHINESE_TRADITIONAL 43 -#define TWLG_CROATIA 44 -#define TWLG_CZECH 45 -#define TWLG_DANISH TWLG_DAN -#define TWLG_DUTCH TWLG_DUT -#define TWLG_DUTCH_BELGIAN 46 -#define TWLG_ENGLISH TWLG_ENG -#define TWLG_ENGLISH_AUSTRALIAN 47 -#define TWLG_ENGLISH_CANADIAN 48 -#define TWLG_ENGLISH_IRELAND 49 -#define TWLG_ENGLISH_NEWZEALAND 50 -#define TWLG_ENGLISH_SOUTHAFRICA 51 -#define TWLG_ENGLISH_UK 52 -#define TWLG_ENGLISH_USA TWLG_USA -#define TWLG_ESTONIAN 53 -#define TWLG_FAEROESE 54 -#define TWLG_FARSI 55 -#define TWLG_FINNISH TWLG_FIN -#define TWLG_FRENCH TWLG_FRN -#define TWLG_FRENCH_BELGIAN 56 -#define TWLG_FRENCH_CANADIAN TWLG_FCF -#define TWLG_FRENCH_LUXEMBOURG 57 -#define TWLG_FRENCH_SWISS 58 -#define TWLG_GERMAN TWLG_GER -#define TWLG_GERMAN_AUSTRIAN 59 -#define TWLG_GERMAN_LUXEMBOURG 60 -#define TWLG_GERMAN_LIECHTENSTEIN 61 -#define TWLG_GERMAN_SWISS 62 -#define TWLG_GREEK 63 -#define TWLG_HEBREW 64 -#define TWLG_HUNGARIAN 65 -#define TWLG_ICELANDIC TWLG_ICE -#define TWLG_INDONESIAN 66 -#define TWLG_ITALIAN TWLG_ITN -#define TWLG_ITALIAN_SWISS 67 -#define TWLG_JAPANESE 68 -#define TWLG_KOREAN 69 -#define TWLG_KOREAN_JOHAB 70 -#define TWLG_LATVIAN 71 -#define TWLG_LITHUANIAN 72 -#define TWLG_NORWEGIAN TWLG_NOR -#define TWLG_NORWEGIAN_BOKMAL 73 -#define TWLG_NORWEGIAN_NYNORSK 74 -#define TWLG_POLISH 75 -#define TWLG_PORTUGUESE TWLG_POR -#define TWLG_PORTUGUESE_BRAZIL 76 -#define TWLG_ROMANIAN 77 -#define TWLG_RUSSIAN 78 -#define TWLG_SERBIAN_LATIN 79 -#define TWLG_SLOVAK 80 -#define TWLG_SLOVENIAN 81 -#define TWLG_SPANISH TWLG_SPA -#define TWLG_SPANISH_MEXICAN 82 -#define TWLG_SPANISH_MODERN 83 -#define TWLG_SWEDISH TWLG_SWE -#define TWLG_THAI 84 -#define TWLG_TURKISH 85 -#define TWLG_UKRANIAN 86 -#define TWLG_ASSAMESE 87 -#define TWLG_BENGALI 88 -#define TWLG_BIHARI 89 -#define TWLG_BODO 90 -#define TWLG_DOGRI 91 -#define TWLG_GUJARATI 92 -#define TWLG_HARYANVI 93 -#define TWLG_HINDI 94 -#define TWLG_KANNADA 95 -#define TWLG_KASHMIRI 96 -#define TWLG_MALAYALAM 97 -#define TWLG_MARATHI 98 -#define TWLG_MARWARI 99 -#define TWLG_MEGHALAYAN 100 -#define TWLG_MIZO 101 -#define TWLG_NAGA 102 -#define TWLG_ORISSI 103 -#define TWLG_PUNJABI 104 -#define TWLG_PUSHTU 105 -#define TWLG_SERBIAN_CYRILLIC 106 -#define TWLG_SIKKIMI 107 -#define TWLG_SWEDISH_FINLAND 108 -#define TWLG_TAMIL 109 -#define TWLG_TELUGU 110 -#define TWLG_TRIPURI 111 -#define TWLG_URDU 112 -#define TWLG_VIETNAMESE 113 - - -/**************************************************************************** - * Data Groups * - ****************************************************************************/ -#define DG_CONTROL 0x0001L -#define DG_IMAGE 0x0002L -#define DG_AUDIO 0x0004L - -/* More Data Functionality may be added in the future. - * These are for items that need to be determined before DS is opened. - * NOTE: Supported Functionality constants must be powers of 2 as they are - * used as bitflags when Application asks DSM to present a list of DSs. - * to support backward capability the App and DS will not use the fields - */ -#define DF_DSM2 0x10000000L -#define DF_APP2 0x20000000L - -#define DF_DS2 0x40000000L - -#define DG_MASK 0xFFFFL - -/**************************************************************************** - * * - ****************************************************************************/ -#define DAT_NULL 0x0000 -#define DAT_CUSTOMBASE 0x8000 - -/* Data Argument Types for the DG_CONTROL Data Group. */ -#define DAT_CAPABILITY 0x0001 -#define DAT_EVENT 0x0002 -#define DAT_IDENTITY 0x0003 -#define DAT_PARENT 0x0004 -#define DAT_PENDINGXFERS 0x0005 -#define DAT_SETUPMEMXFER 0x0006 -#define DAT_SETUPFILEXFER 0x0007 -#define DAT_STATUS 0x0008 -#define DAT_USERINTERFACE 0x0009 -#define DAT_XFERGROUP 0x000a -#define DAT_CUSTOMDSDATA 0x000c -#define DAT_DEVICEEVENT 0x000d -#define DAT_FILESYSTEM 0x000e -#define DAT_PASSTHRU 0x000f -#define DAT_CALLBACK 0x0010 -#define DAT_STATUSUTF8 0x0011 -#define DAT_CALLBACK2 0x0012 -#define DAT_METRICS 0x0013 -#define DAT_TWAINDIRECT 0x0014 - -/* Data Argument Types for the DG_IMAGE Data Group. */ -#define DAT_IMAGEINFO 0x0101 -#define DAT_IMAGELAYOUT 0x0102 -#define DAT_IMAGEMEMXFER 0x0103 -#define DAT_IMAGENATIVEXFER 0x0104 -#define DAT_IMAGEFILEXFER 0x0105 -#define DAT_CIECOLOR 0x0106 -#define DAT_GRAYRESPONSE 0x0107 -#define DAT_RGBRESPONSE 0x0108 -#define DAT_JPEGCOMPRESSION 0x0109 -#define DAT_PALETTE8 0x010a -#define DAT_EXTIMAGEINFO 0x010b -#define DAT_FILTER 0x010c - -/* Data Argument Types for the DG_AUDIO Data Group. */ -#define DAT_AUDIOFILEXFER 0x0201 -#define DAT_AUDIOINFO 0x0202 -#define DAT_AUDIONATIVEXFER 0x0203 - -/* misplaced */ -#define DAT_ICCPROFILE 0x0401 -#define DAT_IMAGEMEMFILEXFER 0x0402 -#define DAT_ENTRYPOINT 0x0403 - - -/**************************************************************************** - * Messages * - ****************************************************************************/ - -/* All message constants are unique. - * Messages are grouped according to which DATs they are used with.*/ - -#define MSG_NULL 0x0000 -#define MSG_CUSTOMBASE 0x8000 - -/* Generic messages may be used with any of several DATs. */ -#define MSG_GET 0x0001 -#define MSG_GETCURRENT 0x0002 -#define MSG_GETDEFAULT 0x0003 -#define MSG_GETFIRST 0x0004 -#define MSG_GETNEXT 0x0005 -#define MSG_SET 0x0006 -#define MSG_RESET 0x0007 -#define MSG_QUERYSUPPORT 0x0008 -#define MSG_GETHELP 0x0009 -#define MSG_GETLABEL 0x000a -#define MSG_GETLABELENUM 0x000b -#define MSG_SETCONSTRAINT 0x000c - -/* Messages used with DAT_NULL */ -#define MSG_XFERREADY 0x0101 -#define MSG_CLOSEDSREQ 0x0102 -#define MSG_CLOSEDSOK 0x0103 -#define MSG_DEVICEEVENT 0X0104 - -/* Messages used with a pointer to DAT_PARENT data */ -#define MSG_OPENDSM 0x0301 -#define MSG_CLOSEDSM 0x0302 - -/* Messages used with a pointer to a DAT_IDENTITY structure */ -#define MSG_OPENDS 0x0401 -#define MSG_CLOSEDS 0x0402 -#define MSG_USERSELECT 0x0403 - -/* Messages used with a pointer to a DAT_USERINTERFACE structure */ -#define MSG_DISABLEDS 0x0501 -#define MSG_ENABLEDS 0x0502 -#define MSG_ENABLEDSUIONLY 0x0503 - -/* Messages used with a pointer to a DAT_EVENT structure */ -#define MSG_PROCESSEVENT 0x0601 - -/* Messages used with a pointer to a DAT_PENDINGXFERS structure */ -#define MSG_ENDXFER 0x0701 -#define MSG_STOPFEEDER 0x0702 - -/* Messages used with a pointer to a DAT_FILESYSTEM structure */ -#define MSG_CHANGEDIRECTORY 0x0801 -#define MSG_CREATEDIRECTORY 0x0802 -#define MSG_DELETE 0x0803 -#define MSG_FORMATMEDIA 0x0804 -#define MSG_GETCLOSE 0x0805 -#define MSG_GETFIRSTFILE 0x0806 -#define MSG_GETINFO 0x0807 -#define MSG_GETNEXTFILE 0x0808 -#define MSG_RENAME 0x0809 -#define MSG_COPY 0x080A -#define MSG_AUTOMATICCAPTUREDIRECTORY 0x080B - -/* Messages used with a pointer to a DAT_PASSTHRU structure */ -#define MSG_PASSTHRU 0x0901 - -/* used with DAT_CALLBACK */ -#define MSG_REGISTER_CALLBACK 0x0902 - -/* used with DAT_CAPABILITY */ -#define MSG_RESETALL 0x0A01 - -/* used with DAT_TWAINDIRECT */ -#define MSG_SETTASK 0x0B01 - -/**************************************************************************** - * Capabilities * - ****************************************************************************/ - -#define CAP_CUSTOMBASE 0x8000 /* Base of custom capabilities */ - -/* all data sources are REQUIRED to support these caps */ -#define CAP_XFERCOUNT 0x0001 - -/* image data sources are REQUIRED to support these caps */ -#define ICAP_COMPRESSION 0x0100 -#define ICAP_PIXELTYPE 0x0101 -#define ICAP_UNITS 0x0102 -#define ICAP_XFERMECH 0x0103 - -/* all data sources MAY support these caps */ -#define CAP_AUTHOR 0x1000 -#define CAP_CAPTION 0x1001 -#define CAP_FEEDERENABLED 0x1002 -#define CAP_FEEDERLOADED 0x1003 -#define CAP_TIMEDATE 0x1004 -#define CAP_SUPPORTEDCAPS 0x1005 -#define CAP_EXTENDEDCAPS 0x1006 -#define CAP_AUTOFEED 0x1007 -#define CAP_CLEARPAGE 0x1008 -#define CAP_FEEDPAGE 0x1009 -#define CAP_REWINDPAGE 0x100a -#define CAP_INDICATORS 0x100b -#define CAP_PAPERDETECTABLE 0x100d -#define CAP_UICONTROLLABLE 0x100e -#define CAP_DEVICEONLINE 0x100f -#define CAP_AUTOSCAN 0x1010 -#define CAP_THUMBNAILSENABLED 0x1011 -#define CAP_DUPLEX 0x1012 -#define CAP_DUPLEXENABLED 0x1013 -#define CAP_ENABLEDSUIONLY 0x1014 -#define CAP_CUSTOMDSDATA 0x1015 -#define CAP_ENDORSER 0x1016 -#define CAP_JOBCONTROL 0x1017 -#define CAP_ALARMS 0x1018 -#define CAP_ALARMVOLUME 0x1019 -#define CAP_AUTOMATICCAPTURE 0x101a -#define CAP_TIMEBEFOREFIRSTCAPTURE 0x101b -#define CAP_TIMEBETWEENCAPTURES 0x101c -#define CAP_MAXBATCHBUFFERS 0x101e -#define CAP_DEVICETIMEDATE 0x101f -#define CAP_POWERSUPPLY 0x1020 -#define CAP_CAMERAPREVIEWUI 0x1021 -#define CAP_DEVICEEVENT 0x1022 -#define CAP_SERIALNUMBER 0x1024 -#define CAP_PRINTER 0x1026 -#define CAP_PRINTERENABLED 0x1027 -#define CAP_PRINTERINDEX 0x1028 -#define CAP_PRINTERMODE 0x1029 -#define CAP_PRINTERSTRING 0x102a -#define CAP_PRINTERSUFFIX 0x102b -#define CAP_LANGUAGE 0x102c -#define CAP_FEEDERALIGNMENT 0x102d -#define CAP_FEEDERORDER 0x102e -#define CAP_REACQUIREALLOWED 0x1030 -#define CAP_BATTERYMINUTES 0x1032 -#define CAP_BATTERYPERCENTAGE 0x1033 -#define CAP_CAMERASIDE 0x1034 -#define CAP_SEGMENTED 0x1035 -#define CAP_CAMERAENABLED 0x1036 -#define CAP_CAMERAORDER 0x1037 -#define CAP_MICRENABLED 0x1038 -#define CAP_FEEDERPREP 0x1039 -#define CAP_FEEDERPOCKET 0x103a -#define CAP_AUTOMATICSENSEMEDIUM 0x103b -#define CAP_CUSTOMINTERFACEGUID 0x103c -#define CAP_SUPPORTEDCAPSSEGMENTUNIQUE 0x103d -#define CAP_SUPPORTEDDATS 0x103e -#define CAP_DOUBLEFEEDDETECTION 0x103f -#define CAP_DOUBLEFEEDDETECTIONLENGTH 0x1040 -#define CAP_DOUBLEFEEDDETECTIONSENSITIVITY 0x1041 -#define CAP_DOUBLEFEEDDETECTIONRESPONSE 0x1042 -#define CAP_PAPERHANDLING 0x1043 -#define CAP_INDICATORSMODE 0x1044 -#define CAP_PRINTERVERTICALOFFSET 0x1045 -#define CAP_POWERSAVETIME 0x1046 -#define CAP_PRINTERCHARROTATION 0x1047 -#define CAP_PRINTERFONTSTYLE 0x1048 -#define CAP_PRINTERINDEXLEADCHAR 0x1049 -#define CAP_PRINTERINDEXMAXVALUE 0x104A -#define CAP_PRINTERINDEXNUMDIGITS 0x104B -#define CAP_PRINTERINDEXSTEP 0x104C -#define CAP_PRINTERINDEXTRIGGER 0x104D -#define CAP_PRINTERSTRINGPREVIEW 0x104E -#define CAP_SHEETCOUNT 0x104F - - - -/* image data sources MAY support these caps */ -#define ICAP_AUTOBRIGHT 0x1100 -#define ICAP_BRIGHTNESS 0x1101 -#define ICAP_CONTRAST 0x1103 -#define ICAP_CUSTHALFTONE 0x1104 -#define ICAP_EXPOSURETIME 0x1105 -#define ICAP_FILTER 0x1106 -#define ICAP_FLASHUSED 0x1107 -#define ICAP_GAMMA 0x1108 -#define ICAP_HALFTONES 0x1109 -#define ICAP_HIGHLIGHT 0x110a -#define ICAP_IMAGEFILEFORMAT 0x110c -#define ICAP_LAMPSTATE 0x110d -#define ICAP_LIGHTSOURCE 0x110e -#define ICAP_ORIENTATION 0x1110 -#define ICAP_PHYSICALWIDTH 0x1111 -#define ICAP_PHYSICALHEIGHT 0x1112 -#define ICAP_SHADOW 0x1113 -#define ICAP_FRAMES 0x1114 -#define ICAP_XNATIVERESOLUTION 0x1116 -#define ICAP_YNATIVERESOLUTION 0x1117 -#define ICAP_XRESOLUTION 0x1118 -#define ICAP_YRESOLUTION 0x1119 -#define ICAP_MAXFRAMES 0x111a -#define ICAP_TILES 0x111b -#define ICAP_BITORDER 0x111c -#define ICAP_CCITTKFACTOR 0x111d -#define ICAP_LIGHTPATH 0x111e -#define ICAP_PIXELFLAVOR 0x111f -#define ICAP_PLANARCHUNKY 0x1120 -#define ICAP_ROTATION 0x1121 -#define ICAP_SUPPORTEDSIZES 0x1122 -#define ICAP_THRESHOLD 0x1123 -#define ICAP_XSCALING 0x1124 -#define ICAP_YSCALING 0x1125 -#define ICAP_BITORDERCODES 0x1126 -#define ICAP_PIXELFLAVORCODES 0x1127 -#define ICAP_JPEGPIXELTYPE 0x1128 -#define ICAP_TIMEFILL 0x112a -#define ICAP_BITDEPTH 0x112b -#define ICAP_BITDEPTHREDUCTION 0x112c -#define ICAP_UNDEFINEDIMAGESIZE 0x112d -#define ICAP_IMAGEDATASET 0x112e -#define ICAP_EXTIMAGEINFO 0x112f -#define ICAP_MINIMUMHEIGHT 0x1130 -#define ICAP_MINIMUMWIDTH 0x1131 -#define ICAP_AUTODISCARDBLANKPAGES 0x1134 -#define ICAP_FLIPROTATION 0x1136 -#define ICAP_BARCODEDETECTIONENABLED 0x1137 -#define ICAP_SUPPORTEDBARCODETYPES 0x1138 -#define ICAP_BARCODEMAXSEARCHPRIORITIES 0x1139 -#define ICAP_BARCODESEARCHPRIORITIES 0x113a -#define ICAP_BARCODESEARCHMODE 0x113b -#define ICAP_BARCODEMAXRETRIES 0x113c -#define ICAP_BARCODETIMEOUT 0x113d -#define ICAP_ZOOMFACTOR 0x113e -#define ICAP_PATCHCODEDETECTIONENABLED 0x113f -#define ICAP_SUPPORTEDPATCHCODETYPES 0x1140 -#define ICAP_PATCHCODEMAXSEARCHPRIORITIES 0x1141 -#define ICAP_PATCHCODESEARCHPRIORITIES 0x1142 -#define ICAP_PATCHCODESEARCHMODE 0x1143 -#define ICAP_PATCHCODEMAXRETRIES 0x1144 -#define ICAP_PATCHCODETIMEOUT 0x1145 -#define ICAP_FLASHUSED2 0x1146 -#define ICAP_IMAGEFILTER 0x1147 -#define ICAP_NOISEFILTER 0x1148 -#define ICAP_OVERSCAN 0x1149 -#define ICAP_AUTOMATICBORDERDETECTION 0x1150 -#define ICAP_AUTOMATICDESKEW 0x1151 -#define ICAP_AUTOMATICROTATE 0x1152 -#define ICAP_JPEGQUALITY 0x1153 -#define ICAP_FEEDERTYPE 0x1154 -#define ICAP_ICCPROFILE 0x1155 -#define ICAP_AUTOSIZE 0x1156 -#define ICAP_AUTOMATICCROPUSESFRAME 0x1157 -#define ICAP_AUTOMATICLENGTHDETECTION 0x1158 -#define ICAP_AUTOMATICCOLORENABLED 0x1159 -#define ICAP_AUTOMATICCOLORNONCOLORPIXELTYPE 0x115a -#define ICAP_COLORMANAGEMENTENABLED 0x115b -#define ICAP_IMAGEMERGE 0x115c -#define ICAP_IMAGEMERGEHEIGHTTHRESHOLD 0x115d -#define ICAP_SUPPORTEDEXTIMAGEINFO 0x115e -#define ICAP_FILMTYPE 0x115f -#define ICAP_MIRROR 0x1160 -#define ICAP_JPEGSUBSAMPLING 0x1161 - -/* image data sources MAY support these audio caps */ -#define ACAP_XFERMECH 0x1202 - - -/*************************************************************************** - * Extended Image Info Attributes section Added 1.7 * - ***************************************************************************/ - -#define TWEI_BARCODEX 0x1200 -#define TWEI_BARCODEY 0x1201 -#define TWEI_BARCODETEXT 0x1202 -#define TWEI_BARCODETYPE 0x1203 -#define TWEI_DESHADETOP 0x1204 -#define TWEI_DESHADELEFT 0x1205 -#define TWEI_DESHADEHEIGHT 0x1206 -#define TWEI_DESHADEWIDTH 0x1207 -#define TWEI_DESHADESIZE 0x1208 -#define TWEI_SPECKLESREMOVED 0x1209 -#define TWEI_HORZLINEXCOORD 0x120A -#define TWEI_HORZLINEYCOORD 0x120B -#define TWEI_HORZLINELENGTH 0x120C -#define TWEI_HORZLINETHICKNESS 0x120D -#define TWEI_VERTLINEXCOORD 0x120E -#define TWEI_VERTLINEYCOORD 0x120F -#define TWEI_VERTLINELENGTH 0x1210 -#define TWEI_VERTLINETHICKNESS 0x1211 -#define TWEI_PATCHCODE 0x1212 -#define TWEI_ENDORSEDTEXT 0x1213 -#define TWEI_FORMCONFIDENCE 0x1214 -#define TWEI_FORMTEMPLATEMATCH 0x1215 -#define TWEI_FORMTEMPLATEPAGEMATCH 0x1216 -#define TWEI_FORMHORZDOCOFFSET 0x1217 -#define TWEI_FORMVERTDOCOFFSET 0x1218 -#define TWEI_BARCODECOUNT 0x1219 -#define TWEI_BARCODECONFIDENCE 0x121A -#define TWEI_BARCODEROTATION 0x121B -#define TWEI_BARCODETEXTLENGTH 0x121C -#define TWEI_DESHADECOUNT 0x121D -#define TWEI_DESHADEBLACKCOUNTOLD 0x121E -#define TWEI_DESHADEBLACKCOUNTNEW 0x121F -#define TWEI_DESHADEBLACKRLMIN 0x1220 -#define TWEI_DESHADEBLACKRLMAX 0x1221 -#define TWEI_DESHADEWHITECOUNTOLD 0x1222 -#define TWEI_DESHADEWHITECOUNTNEW 0x1223 -#define TWEI_DESHADEWHITERLMIN 0x1224 -#define TWEI_DESHADEWHITERLAVE 0x1225 -#define TWEI_DESHADEWHITERLMAX 0x1226 -#define TWEI_BLACKSPECKLESREMOVED 0x1227 -#define TWEI_WHITESPECKLESREMOVED 0x1228 -#define TWEI_HORZLINECOUNT 0x1229 -#define TWEI_VERTLINECOUNT 0x122A -#define TWEI_DESKEWSTATUS 0x122B -#define TWEI_SKEWORIGINALANGLE 0x122C -#define TWEI_SKEWFINALANGLE 0x122D -#define TWEI_SKEWCONFIDENCE 0x122E -#define TWEI_SKEWWINDOWX1 0x122F -#define TWEI_SKEWWINDOWY1 0x1230 -#define TWEI_SKEWWINDOWX2 0x1231 -#define TWEI_SKEWWINDOWY2 0x1232 -#define TWEI_SKEWWINDOWX3 0x1233 -#define TWEI_SKEWWINDOWY3 0x1234 -#define TWEI_SKEWWINDOWX4 0x1235 -#define TWEI_SKEWWINDOWY4 0x1236 -#define TWEI_BOOKNAME 0x1238 -#define TWEI_CHAPTERNUMBER 0x1239 -#define TWEI_DOCUMENTNUMBER 0x123A -#define TWEI_PAGENUMBER 0x123B -#define TWEI_CAMERA 0x123C -#define TWEI_FRAMENUMBER 0x123D -#define TWEI_FRAME 0x123E -#define TWEI_PIXELFLAVOR 0x123F -#define TWEI_ICCPROFILE 0x1240 -#define TWEI_LASTSEGMENT 0x1241 -#define TWEI_SEGMENTNUMBER 0x1242 -#define TWEI_MAGDATA 0x1243 -#define TWEI_MAGTYPE 0x1244 -#define TWEI_PAGESIDE 0x1245 -#define TWEI_FILESYSTEMSOURCE 0x1246 -#define TWEI_IMAGEMERGED 0x1247 -#define TWEI_MAGDATALENGTH 0x1248 -#define TWEI_PAPERCOUNT 0x1249 -#define TWEI_PRINTERTEXT 0x124A -#define TWEI_TWAINDIRECTMETADATA 0x124B - -#define TWEJ_NONE 0x0000 -#define TWEJ_MIDSEPARATOR 0x0001 -#define TWEJ_PATCH1 0x0002 -#define TWEJ_PATCH2 0x0003 -#define TWEJ_PATCH3 0x0004 -#define TWEJ_PATCH4 0x0005 -#define TWEJ_PATCH6 0x0006 -#define TWEJ_PATCHT 0x0007 - - -/*************************************************************************** - * Return Codes and Condition Codes section * - ***************************************************************************/ - -#define TWRC_CUSTOMBASE 0x8000 - -#define TWRC_SUCCESS 0 -#define TWRC_FAILURE 1 -#define TWRC_CHECKSTATUS 2 -#define TWRC_CANCEL 3 -#define TWRC_DSEVENT 4 -#define TWRC_NOTDSEVENT 5 -#define TWRC_XFERDONE 6 -#define TWRC_ENDOFLIST 7 -#define TWRC_INFONOTSUPPORTED 8 -#define TWRC_DATANOTAVAILABLE 9 -#define TWRC_BUSY 10 -#define TWRC_SCANNERLOCKED 11 - -/* Condition Codes: Application gets these by doing DG_CONTROL DAT_STATUS MSG_GET. */ -#define TWCC_CUSTOMBASE 0x8000 - -#define TWCC_SUCCESS 0 -#define TWCC_BUMMER 1 -#define TWCC_LOWMEMORY 2 -#define TWCC_NODS 3 -#define TWCC_MAXCONNECTIONS 4 -#define TWCC_OPERATIONERROR 5 -#define TWCC_BADCAP 6 -#define TWCC_BADPROTOCOL 9 -#define TWCC_BADVALUE 10 -#define TWCC_SEQERROR 11 -#define TWCC_BADDEST 12 -#define TWCC_CAPUNSUPPORTED 13 -#define TWCC_CAPBADOPERATION 14 -#define TWCC_CAPSEQERROR 15 -#define TWCC_DENIED 16 -#define TWCC_FILEEXISTS 17 -#define TWCC_FILENOTFOUND 18 -#define TWCC_NOTEMPTY 19 -#define TWCC_PAPERJAM 20 -#define TWCC_PAPERDOUBLEFEED 21 -#define TWCC_FILEWRITEERROR 22 -#define TWCC_CHECKDEVICEONLINE 23 -#define TWCC_INTERLOCK 24 -#define TWCC_DAMAGEDCORNER 25 -#define TWCC_FOCUSERROR 26 -#define TWCC_DOCTOOLIGHT 27 -#define TWCC_DOCTOODARK 28 -#define TWCC_NOMEDIA 29 - -/* bit patterns: for query the operation that are supported by the data source on a capability */ -/* Application gets these through DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */ -#define TWQC_GET 0x0001 -#define TWQC_SET 0x0002 -#define TWQC_GETDEFAULT 0x0004 -#define TWQC_GETCURRENT 0x0008 -#define TWQC_RESET 0x0010 -#define TWQC_SETCONSTRAINT 0x0020 -#define TWQC_GETHELP 0x0100 -#define TWQC_GETLABEL 0x0200 -#define TWQC_GETLABELENUM 0x0400 - -/**************************************************************************** - * Depreciated Items * - ****************************************************************************/ -#if defined(WIN32) || defined(WIN64) - #define TW_HUGE -#elif !defined(TWH_CMP_GNU) - #define TW_HUGE huge -#else - #define TW_HUGE -#endif - -typedef BYTE TW_HUGE * HPBYTE; -typedef void TW_HUGE * HPVOID; - -typedef unsigned char TW_STR1024[1026], FAR *pTW_STR1026, FAR *pTW_STR1024; -typedef wchar_t TW_UNI512[512], FAR *pTW_UNI512; - -#define TWTY_STR1024 0x000d -#define TWTY_UNI512 0x000e - -#define TWFF_JPN 12 - -#define DAT_TWUNKIDENTITY 0x000b -#define DAT_SETUPFILEXFER2 0x0301 - -#define CAP_CLEARBUFFERS 0x101d -#define CAP_SUPPORTEDCAPSEXT 0x100c -#define CAP_FILESYSTEM //0x???? -#define CAP_PAGEMULTIPLEACQUIRE 0x1023 -#define CAP_PAPERBINDING 0x102f -#define CAP_PASSTHRU 0x1031 -#define CAP_POWERDOWNTIME 0x1034 -#define ACAP_AUDIOFILEFORMAT 0x1201 - -#define MSG_CHECKSTATUS 0x0201 - -#define MSG_INVOKE_CALLBACK 0x0903 /* Mac Only, deprecated - use DAT_NULL and MSG_xxx instead */ - -#define TWQC_CONSTRAINABLE 0x0040 - -#define TWSX_FILE2 3 - -/* CAP_FILESYSTEM values (FS_ means file system) */ -#define TWFS_FILESYSTEM 0 -#define TWFS_RECURSIVEDELETE 1 - -/* ICAP_PIXELTYPE values (PT_ means Pixel Type) */ -#define TWPT_SRGB64 11 -#define TWPT_BGR 12 -#define TWPT_CIELAB 13 -#define TWPT_CIELUV 14 -#define TWPT_YCBCR 15 - -/* ICAP_SUPPORTEDSIZES values (SS_ means Supported Sizes) */ -#define TWSS_B 8 -#define TWSS_A4LETTER TWSS_A4 -#define TWSS_B3 TWSS_ISOB3 -#define TWSS_B4 TWSS_ISOB4 -#define TWSS_B6 TWSS_ISOB6 -#define TWSS_B5LETTER TWSS_JISB5 - -/* ACAP_AUDIOFILEFORMAT values (AF_ means audio format). Added 1.8 */ -#define TWAF_WAV 0 -#define TWAF_AIFF 1 -#define TWAF_AU 3 -#define TWAF_SND 4 - -/* CAP_CLEARBUFFERS values */ -#define TWCB_AUTO 0 -#define TWCB_CLEAR 1 -#define TWCB_NOCLEAR 2 - -/* DAT_SETUPFILEXFER2. Sets up DS to application data transfer via a file. Added 1.9 */ -typedef struct { - TW_MEMREF FileName; - TW_UINT16 FileNameType; - TW_UINT16 Format; - TW_INT16 VRefNum; - TW_UINT32 parID; -} TW_SETUPFILEXFER2, FAR * pTW_SETUPFILEXFER2; - -/* DAT_TWUNKIDENTITY. Provides DS identity and 'other' information necessary */ -/* across thunk link. */ -typedef struct { - TW_IDENTITY identity; - TW_STR255 dsPath; -} TW_TWUNKIDENTITY, FAR * pTW_TWUNKIDENTITY; - -/* Provides DS_Entry parameters over thunk link. */ -typedef struct -{ - TW_INT8 destFlag; - TW_IDENTITY dest; - TW_INT32 dataGroup; - TW_INT16 dataArgType; - TW_INT16 message; - TW_INT32 pDataSize; - // TW_MEMREF pData; -} TW_TWUNKDSENTRYPARAMS, FAR * pTW_TWUNKDSENTRYPARAMS; - -/* Provides DS_Entry results over thunk link. */ -typedef struct -{ - TW_UINT16 returnCode; - TW_UINT16 conditionCode; - TW_INT32 pDataSize; - // TW_MEMREF pData; -} TW_TWUNKDSENTRYRETURN, FAR * pTW_TWUNKDSENTRYRETURN; - -typedef struct -{ - TW_UINT16 Cap; - TW_UINT16 Properties; -} TW_CAPEXT, FAR * pTW_CAPEXT; - -/* DAT_SETUPAUDIOFILEXFER, information required to setup an audio file transfer */ -typedef struct { - TW_STR255 FileName; /* full path target file */ - TW_UINT16 Format; /* one of TWAF_xxxx */ - TW_INT16 VRefNum; -} TW_SETUPAUDIOFILEXFER, FAR * pTW_SETUPAUDIOFILEXFER; - - -/**************************************************************************** - * Entry Points * - ****************************************************************************/ - -/********************************************************************** - * Function: DSM_Entry, the only entry point into the Data Source Manager. - ********************************************************************/ -#ifdef TWH_CMP_MSC - #define TW_CALLINGSTYLE PASCAL -#else - #define TW_CALLINGSTYLE -#endif - -/* Don't mangle the name "DSM_Entry" if we're compiling in C++! */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -TW_UINT16 TW_CALLINGSTYLE DSM_Entry( pTW_IDENTITY pOrigin, - pTW_IDENTITY pDest, - TW_UINT32 DG, - TW_UINT16 DAT, - TW_UINT16 MSG, - TW_MEMREF pData); - -typedef TW_UINT16 (TW_CALLINGSTYLE *DSMENTRYPROC)(pTW_IDENTITY pOrigin, - pTW_IDENTITY pDest, - TW_UINT32 DG, - TW_UINT16 DAT, - TW_UINT16 MSG, - TW_MEMREF pData); -#ifdef __cplusplus -} -#endif /* cplusplus */ - - -/********************************************************************** - * Function: DS_Entry, the entry point provided by a Data Source. - ********************************************************************/ -/* Don't mangle the name "DS_Entry" if we're compiling in C++! */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -TW_UINT16 TW_CALLINGSTYLE DS_Entry(pTW_IDENTITY pOrigin, - TW_UINT32 DG, - TW_UINT16 DAT, - TW_UINT16 MSG, - TW_MEMREF pData); - -typedef TW_UINT16 (FAR PASCAL *DSENTRYPROC)(pTW_IDENTITY pOrigin, - TW_UINT32 DG, - TW_UINT16 DAT, - TW_UINT16 MSG, - TW_MEMREF pData); - -TW_UINT16 TW_CALLINGSTYLE TWAIN_Callback( pTW_IDENTITY pOrigin, - pTW_IDENTITY pDest, - TW_UINT32 DG, - TW_UINT16 DAT, - TW_UINT16 MSG, - TW_MEMREF pData); -typedef TW_UINT16 (TW_CALLINGSTYLE *TWAINCALLBACKPROC)(pTW_IDENTITY pOrigin, - pTW_IDENTITY pDest, - TW_UINT32 DG, - TW_UINT16 DAT, - TW_UINT16 MSG, - TW_MEMREF pData); - -TW_HANDLE TW_CALLINGSTYLE DSM_MemAllocate (TW_UINT32); -typedef TW_HANDLE (TW_CALLINGSTYLE *DSM_MEMALLOCATE)(TW_UINT32 _size); - -void TW_CALLINGSTYLE DSM_MemFree (TW_HANDLE); -typedef void (TW_CALLINGSTYLE *DSM_MEMFREE)(TW_HANDLE _handle); - -TW_MEMREF TW_CALLINGSTYLE DSM_MemLock (TW_HANDLE); -typedef TW_MEMREF (TW_CALLINGSTYLE *DSM_MEMLOCK)(TW_HANDLE _handle); - -void TW_CALLINGSTYLE DSM_MemUnlock (TW_HANDLE); -typedef void (TW_CALLINGSTYLE *DSM_MEMUNLOCK)(TW_HANDLE _handle); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* DAT_ENTRYPOINT. returns essential entry points. */ -typedef struct { - TW_UINT32 Size; - DSMENTRYPROC DSM_Entry; - DSM_MEMALLOCATE DSM_MemAllocate; - DSM_MEMFREE DSM_MemFree; - DSM_MEMLOCK DSM_MemLock; - DSM_MEMUNLOCK DSM_MemUnlock; -} TW_ENTRYPOINT, FAR * pTW_ENTRYPOINT; - -/* DAT_FILTER*/ -typedef struct { - TW_UINT32 Size; - TW_UINT32 HueStart; - TW_UINT32 HueEnd; - TW_UINT32 SaturationStart; - TW_UINT32 SaturationEnd; - TW_UINT32 ValueStart; - TW_UINT32 ValueEnd; - TW_UINT32 Replacement; -} TW_FILTER_DESCRIPTOR, *pTW_FILTER_DESCRIPTOR; - -/* DAT_FILTER */ -typedef struct { - TW_UINT32 Size; - TW_UINT32 DescriptorCount; - TW_UINT32 MaxDescriptorCount; - TW_UINT32 Condition; - TW_HANDLE hDescriptors; -} TW_FILTER, *pTW_FILTER; - - -/* Restore the previous packing alignment: this occurs after all structures are defined */ -#ifdef TWH_CMP_MSC - #pragma pack (pop, before_twain) -#elif defined(TWH_CMP_GNU) - #if defined(__APPLE__) /* cf: Mac version of TWAIN.h */ - #pragma options align = reset - #else - #pragma pack (pop, before_twain) - #endif -#elif defined(TWH_CMP_BORLAND) - #pragma option -a. -#endif - -#endif /* TWAIN */ diff --git a/twain/twain/twpp.hpp b/twain/twain/twpp.hpp deleted file mode 100644 index a3d95a1..0000000 --- a/twain/twain/twpp.hpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_TWPP_HPP -#define TWPP_DETAIL_FILE_TWPP_HPP - -#include "twpp/env.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "twpp/utils.hpp" - -#include "twpp/types.hpp" -#include "twpp/strings.hpp" -#include "twpp/fix32.hpp" -#include "twpp/frame.hpp" -#include "twpp/exception.hpp" -#include "twpp/typesops.hpp" - -#include "twpp/memoryops.hpp" -#include "twpp/memory.hpp" - -#include "twpp/enums.hpp" -#include "twpp/status.hpp" -#include "twpp/identity.hpp" -#include "twpp/imageinfo.hpp" -#include "twpp/imagelayout.hpp" -#include "twpp/deviceevent.hpp" -#include "twpp/element8.hpp" - -#include "twpp/audio.hpp" -#include "twpp/capability.hpp" -#include "twpp/customdata.hpp" -#include "twpp/cie.hpp" -#include "twpp/curveresponse.hpp" -#include "twpp/event.hpp" -#include "twpp/extimageinfo.hpp" -#include "twpp/filesystem.hpp" -#include "twpp/imagememxfer.hpp" -#include "twpp/imagenativexfer.hpp" -#include "twpp/internal.hpp" -#include "twpp/jpegcompression.hpp" -#include "twpp/palette8.hpp" -#include "twpp/passthrough.hpp" -#include "twpp/pendingxfers.hpp" -#include "twpp/setupfilexfer.hpp" -#include "twpp/setupmemxfer.hpp" -#include "twpp/userinterface.hpp" - -#if !defined(TWPP_IS_DS) -# include "twpp/application.hpp" -#else -# include "twpp/datasource.hpp" -#endif - - -#if !defined(TWPP_NO_NOTES) -# if !defined(TWPP_IS_DS) -# pragma message ("note: using APPLICATION version of TWPP library, define TWPP_IS_DS before including twpp.hpp if you want DATA SOURCE version") -# if defined(TWPP_DETAIL_OS_WIN32) -# pragma message ("note: place the following into your module-definition (.def) file: EXPORTS DS_Entry @1") -# endif -# else -# pragma message ("note: using DATA SOURCE version of TWPP library, undefine TWPP_IS_DS if you want APPLICATION version") -# pragma message ("note: make sure to place TWPP_ENTRY() macro in exactly one source file") -# endif -# if defined(TWPP_DETAIL_OS_MAC) -# pragma message "warning: Str32, Str64, Str128 and Str255 are not null-terminated" -# endif -# pragma message ("note: to disable notes and warnings, define TWPP_NO_NOTES before including TWPP header") -#endif - - -#endif // TWPP_DETAIL_FILE_TWPP_HPP diff --git a/twain/twain/twpp/application.hpp b/twain/twain/twpp/application.hpp deleted file mode 100644 index 7ad02c7..0000000 --- a/twain/twain/twpp/application.hpp +++ /dev/null @@ -1,1153 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015-2017 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_APPLICATION_HPP -#define TWPP_DETAIL_FILE_APPLICATION_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -namespace Detail { - -struct ManagerData { - - ManagerData(const Identity& appId) noexcept : - m_appId(appId){} - - Identity m_appId; - DsmState m_state = DsmState::PreSession; - Detail::DsmLib m_lib; - Detail::DsmEntry m_entry = nullptr; - -#if defined(TWPP_DETAIL_OS_WIN) - Handle m_rootWindow; - bool m_ownRootWindow; -#elif defined(TWPP_DETAIL_OS_MAC) - Detail::NSAutoreleasePool m_autoreleasePool; -#elif !defined(TWPP_DETAIL_OS_LINUX) -# error "ManagerData for your platform here" -#endif - -}; - -struct SourceData { - - SourceData(ManagerData* mgr, const Identity& srcIdent) noexcept : - m_mgr(mgr), m_srcId(srcIdent){} - - ManagerData* m_mgr; - std::function m_devEvent; - Handle m_uiHandle; - Identity m_srcId; - DsState m_state = DsState::Closed; - Msg m_readyMsg = Msg::Null; - -#if defined(TWPP_DETAIL_OS_LINUX) - std::mutex m_cbMutex; - std::condition_variable m_cbCond; -#elif !defined(TWPP_DETAIL_OS_WIN) && !defined(TWPP_DETAIL_OS_MAC) -# error "SourceData for your platform here" -#endif - -}; - -} - -class Manager; - -/// A single TWAIN source. -/// Source must belong to a manager in order to perform operations on it. -/// Any valid source instance must be destroyed or at least cleaned by `cleanup` -/// before parent manager is itself destroyed. -/// -/// `call` vs -/// They are ultimately the same: -/// `call` is more suitable for cases that need fixed number of arguments. -/// is better for user-defined calls. -class Source { - - friend class Manager; - -public: - typedef std::function EventCallBack; - - /// Creates an invalid source. - /// Calling any method on such source results in - /// undefined behaviour, and possibly segfault. - /// Only isValid() and operator bool() may be called. - Source() noexcept{} - - ~Source(){ - if (isValid()){ - cleanup(); - } - } - - Source(Source&&) = default; - Source& operator=(Source&& o) noexcept{ - if (&o != this){ - if (isValid()){ - cleanup(); - } - - m_data = std::move(o.m_data); - } - - return *this; - } - - /// Performs explicit cleanup. - /// Ultimately closes the source. - void cleanup() noexcept{ - assert(isValid()); - - PendingXfers xfers; - - switch (d()->m_state){ - case DsState::Xferring: - pendingXfers(Msg::EndXfer, xfers); - // fallthrough - case DsState::XferReady: - if (d()->m_state == DsState::XferReady){ // EndXfer might have moved to DsState::Enabled - pendingXfers(Msg::Reset, xfers); - } - - // fallthrough - case DsState::Enabled: - disable(); - // fallthrough - case DsState::Open: - close(); - // reset the ref even if close() fails somehow - Static::g_openSource = nullptr; - // fallthrough - case DsState::Closed: - break; - } - } - - /// TWAIN state of the source. - DsState state() const noexcept{ - assert(isValid()); - - return d()->m_state; - } - - /// Whether the source is valid. - /// Valid source was created by manager. - /// Invalid source was created using default constructor. - bool isValid() const noexcept{ - return static_cast(m_data); - } - - operator bool() const noexcept{ - return isValid(); - } - - /// Identity of the source. - const Identity& identity() const noexcept{ - assert(isValid()); - - return d()->m_srcId; - } - - /// Sets function (object) to receive device event notifications. - /// - /// {In state 5 (enabled), the function should only set a flag and return immediately. - /// `waitReady()` then returns CheckStatus, and the device event may be processed in - /// the main thread. Call `waitReady()` again once you are done.} - void setEventCallBack(EventCallBack devEvent){ - assert(isValid()); - - d()->m_devEvent = std::move(devEvent); - } - - - // Control -> - - /// Opens the source. - /// Only up to 1 source may be opened at the same time. - /// \throw std::bad_alloc - ReturnCode open(){ - assert(Static::g_openSource == nullptr); - - auto rc = dsm(nullptr, DataGroup::Control, Dat::Identity, Msg::OpenDs, d()->m_srcId); - if (success(rc)){ - d()->m_state = DsState::Open; - - // TWAIN manual is rather confusing on this topic. - // Their example sends the registration to DSM, operation tripet documentation mentions DS as destination. - // Looking at some other applications, Windows seems to send this to DS, MacOS to DSM. - Detail::CallBack cb1(callBack, static_cast(0), Msg::Null); - -#if defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX) - Detail::CallBack2 cb2(callBack, 0, Msg::Null); - - bool usesCb = success(dsm(DataGroup::Control, Dat::Callback2, Msg::RegisterCallback, cb2)) || - success(dsm(DataGroup::Control, Dat::Callback, Msg::RegisterCallback, cb1)); -#elif defined(TWPP_DETAIL_OS_MAC) - bool usesCb = success(dsm(nullptr, DataGroup::Control, Dat::Callback, Msg::RegisterCallback, cb1)); -#else -# error "callback setup for your platform here" -#endif - -#if defined(TWPP_DETAIL_OS_WIN) - Detail::unused(usesCb); -#elif defined(TWPP_DETAIL_OS_MAC) || defined(TWPP_DETAIL_OS_LINUX) - if (!usesCb){ - close(); - return ReturnCode::Failure; - } -#else -# error "source open setup for your platform here" -#endif - Static::g_openSource = d(); - } - - return rc; - } - - /// Closes the source. - ReturnCode close(){ - ReturnCode rc = dsm(nullptr, DataGroup::Control, Dat::Identity, Msg::CloseDs, d()->m_srcId); - if (success(rc)){ - Static::g_openSource = nullptr; - d()->m_state = DsState::Closed; - } - - return rc; - } - - /// Enables the source, showing its GUI if requested. - /// A call to `waitReady` must follow, advanced users may look at `processEvent` on Windows. - /// \param ui GUI settings. - /// \param uiOnly Whether the GUI should only be used to change values, not scan. - ReturnCode enable(const UserInterface& ui, bool uiOnly = false) noexcept{ - auto uiTmp = ui; // allow ui to be const, dsm doesnt take const - ReturnCode rc = dsm(DataGroup::Control, Dat::UserInterface, uiOnly ? Msg::EnableDsUiOnly : Msg::EnableDs, uiTmp); - if (success(rc) || (!uiOnly && rc == ReturnCode::CheckStatus)){ - d()->m_readyMsg = Msg::Null; - d()->m_uiHandle = ui.parent(); - d()->m_state = DsState::Enabled; - } - - return rc; - } - - /// Disables this source. - ReturnCode disable(){ - assert(isValid()); - - UserInterface ui(false, false, d()->m_uiHandle); - auto rc = dsm(DataGroup::Control, Dat::UserInterface, Msg::DisableDs, ui); - if (success(rc)){ - d()->m_state = DsState::Open; - } - - return rc; - } - - /// Waits on source GUI, blocking. - /// This method is meant for CMD applications, see `processEvent()` for GUI-friendly version. - /// The state is moved to XferReady, when Success is returned, and the source is enabled with full UI (uiOnly = false). - /// On Windows and Mac OS, call this method from the main thread, GUI events are processed here. - /// On Linux, this method may be called from any thread, GUI events are NOT processed. - /// Call this again after processing device event. - /// \return {Failure on error, Cancel on CANCEL button, Success on SAVE or SCAN button, - /// CheckStatus on device event.} - ReturnCode waitReady(){ - assert(isValid()); - - if (d()->m_state != DsState::Enabled){ - return ReturnCode::Failure; - } - -#if defined(TWPP_DETAIL_OS_WIN) - MSG msg; - memset(&msg, 0, sizeof(msg)); - - Event event(&msg, Msg::Null); - while (d()->m_readyMsg == Msg::Null){ - auto val = GetMessage(&msg, nullptr, 0, 0); - if (val == 0 || val == -1){ // 0 ... WM_QUIT; -1 ... error; otherwise ... success - return ReturnCode::Failure; - } - - auto rc = dsm(DataGroup::Control, Dat::Event, Msg::ProcessEvent, event); - switch (rc){ - case ReturnCode::NotDsEvent: - TranslateMessage(&msg); - DispatchMessage(&msg); - // fallthrough - case ReturnCode::DsEvent: - if (d()->m_readyMsg == Msg::Null){ - d()->m_readyMsg = event.message(); - } - - break; - - default: - return rc; - } - } -#elif defined(TWPP_DETAIL_OS_MAC) - Detail::NSAutoreleasePool pool; - - while(d()->m_readyMsg == Msg::Null) { - Detail::NSLoop::processEvent(); - } - - pool.release(); - -#elif defined(TWPP_DETAIL_OS_LINUX) - std::unique_lock lock(d()->m_cbMutex); - while (d()->m_readyMsg == Msg::Null){ - d()->m_cbCond.wait(lock); - } -#else -# error "waitReady for your platform here" -#endif - - switch (d()->m_readyMsg){ - case Msg::XferReady: // ok/scan button <=> Msg::EnableDs - d()->m_state = DsState::XferReady; - case Msg::CloseDsOk: // ok/scan button <=> Msg::EnableDsUiOnly - return ReturnCode::Success; - - case Msg::CloseDsReq: // cancel button - return ReturnCode::Cancel; - - case Msg::DeviceEvent: - d()->m_readyMsg = Msg::Null; - return ReturnCode::CheckStatus; - - default: - return ReturnCode::Failure; - } - } - - /// Processes a single GUI event without blocking. - /// Can be used instead of `waitReady()` to process a single event. - /// Windows users must pass events from GUI loop to this method to be sent to DS. - /// \return {Failure on error, Cancel on CANCEL button, Success on SAVE or SCAN button, - /// CheckStatus on device event. NotDsEvent OR DsEvent when not ready yet.} -#if defined (TWPP_DETAIL_OS_WIN) - ReturnCode processEvent(MSG* event){ - Event twEvent(event, Msg::Null); - auto rc = dsm(DataGroup::Control, Dat::Event, Msg::ProcessEvent, twEvent); - switch (rc){ - case ReturnCode::DsEvent: - case ReturnCode::NotDsEvent: - if (d()->m_readyMsg == Msg::Null){ - d()->m_readyMsg = twEvent.message(); - } - - break; - - default: - return rc; - } - - auto msg = d()->m_readyMsg; - -#elif defined(TWPP_DETAIL_OS_LINUX) || defined(TWPP_DETAIL_OS_MAC) - ReturnCode processEvent(){ - assert(isValid()); - auto rc = ReturnCode::NotDsEvent; - -# if defined(TWPP_DETAIL_OS_MAC) - auto msg = d()->m_readyMsg; -# else - std::unique_lock lock(d()->m_cbMutex); - auto msg = d()->m_readyMsg; - lock.unlock(); -# endif - -#else -# error "processEvent for your platform here" -#endif - switch (msg){ - case Msg::XferReady: // ok/scan button <=> Msg::EnableDs - d()->m_state = DsState::XferReady; - // fallthrough - case Msg::CloseDsOk: // ok/scan button <=> Msg::EnableDsUiOnly - return ReturnCode::Success; - - case Msg::CloseDsReq: // cancel button - return ReturnCode::Cancel; - - case Msg::DeviceEvent: - d()->m_readyMsg = Msg::Null; - return ReturnCode::CheckStatus; - - case Msg::Null: - return rc; - - default: - return ReturnCode::Failure; - } - } - - /// Sends custom, user-defined data to the source. - /// This operation is unsafe, there is no way to discover - /// possible connection state changes. - /// \tparam T Data type. - /// \param dg Data group. - /// \param dat Custom data type identifier. Dat::CustomBase and greater. - /// \param msg Message, action to perform. - /// \param data Custom data. - template - ReturnCode customBase(DataGroup dg, Dat dat, Msg msg, T& data){ - return dsm(dg, dat, msg, data); - } - - /// Sends custom, user-defined data to the source. - /// This operation is unsafe, there is no way to discover - /// possible connection state changes. - /// \param dg Data group. - /// \param dat Custom data type identifier. Dat::CustomBase and greater. - /// \param msg Message, action to perform. - /// \param data Custom data. - ReturnCode customBase(DataGroup dg, Dat dat, Msg msg, void* data){ - return dsmPtr(dg, dat, msg, data); - } - - ReturnCode capability(Msg msg, Capability& inOut){ - return call(DataGroup::Control, msg, inOut); - } - - /// \throw CapTypeException When input capability type does not match the - /// capability type of this template class. - /// \throw CapItemTypeException When input capability item type does not match - /// the expected item type of the capability. - template - ReturnCode capability(Msg msg, Cap& inOut){ - return call(DataGroup::Control, msg, inOut); - } - - ReturnCode customData(Msg msg, CustomData& inOut){ - return call(DataGroup::Control, msg, inOut); - } - - ReturnCode deviceEvent(DeviceEvent& out){ - return call(DataGroup::Control, Msg::Get, out); - } - - ReturnCode fileSystem(Msg msg, FileSystem& inOut){ - return call(DataGroup::Control, msg, inOut); - } - - ReturnCode passThrough(PassThrough& inOut){ - return call(DataGroup::Control, Msg::PassThrough, inOut); - } - - ReturnCode pendingXfers(Msg msg, PendingXfers& inOut){ - return call(DataGroup::Control, msg, inOut); - } - - ReturnCode setupFileXfer(Msg msg, SetupFileXfer& inOut){ - return call(DataGroup::Control, msg, inOut); - } - - ReturnCode setupMemXfer(SetupMemXfer& out){ - return call(DataGroup::Control, Msg::Get, out); - } - - ReturnCode xferGroup(Msg msg, DataGroup& inOut){ - return call(DataGroup::Control, msg, inOut); - } - - ReturnCode status(Status& out){ - return call(DataGroup::Control, Msg::Get, out); - } - - ReturnCode statusUtf8(StatusUtf8& inOut){ - return call(DataGroup::Control, Msg::Get, inOut); - } - // <- Control - - - // Image -> - // TODO CieColor - /* - ReturnCode cieColor(CieColor& out){ - return call(DataGroup::Image, Msg::Get, out); - }*/ - - ReturnCode extImageInfo(ExtImageInfo& inOut){ - return call(DataGroup::Image, Msg::Get, inOut); - } - - ReturnCode grayResponse(Msg msg, GrayResponse& inOut){ - return call(DataGroup::Image, msg, inOut); - } - - ReturnCode iccProfile(IccProfileMemory& out){ - return call(DataGroup::Image, Msg::Get, out); - } - - ReturnCode imageFileXfer(){ - return call(DataGroup::Image, Msg::Get, ImageFileXfer()); - } - - ReturnCode imageInfo(ImageInfo& out){ - return call(DataGroup::Image, Msg::Get, out); - } - - ReturnCode imageLayout(Msg msg, ImageLayout& inOut){ - return call(DataGroup::Image, msg, inOut); - } - - ReturnCode imageMemFileXfer(ImageMemFileXfer& inOut){ - return call(DataGroup::Image, Msg::Get, inOut); - } - - ReturnCode imageMemXfer(ImageMemXfer& inOut){ - return call(DataGroup::Image, Msg::Get, inOut); - } - - ReturnCode imageNativeXfer(ImageNativeXfer& out){ - return call(DataGroup::Image, Msg::Get, out); - } - - ReturnCode jpegCompression(Msg msg, JpegCompression& inOut){ - return call(DataGroup::Image, msg, inOut); - } - - ReturnCode palette8(Msg msg, Palette8& inOut){ - return call(DataGroup::Image, msg, inOut); - } - - ReturnCode rgbResponse(Msg msg, RgbResponse& inOut){ - return call(DataGroup::Image, msg, inOut); - } - // <- Image - - - // Audio -> - ReturnCode audioFileXfer(){ - return call(DataGroup::Audio, Msg::Get, AudioFileXfer()); - } - - ReturnCode audioInfo(AudioInfo& out){ - return call(DataGroup::Audio, Msg::Get, out); - } - - ReturnCode audioNativeXfer(AudioNativeXfer& out){ - return call(DataGroup::Audio, Msg::Get, out); - } - // <- Audio - - - // Raw -> - - // dg:: control follows - ReturnCode call(DataGroup dg, Msg msg, Capability& data){ - return dsm(dg, Dat::Capability, msg, data); - } - - /// \throw CapTypeException When input capability type does not match the - /// capability type of this template class. - /// \throw CapItemTypeException When input capability item type does not match - /// the expected item type of the capability. - template - ReturnCode call(DataGroup dg, Msg msg, Cap& data){ - auto rc = call(dg, msg, data.m_cap); - data.checkTypes(); - return rc; - } - - ReturnCode call(DataGroup dg, Msg msg, CustomData& data){ - return dsm(dg, Dat::CustomData, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, DeviceEvent& data){ - return dsm(dg, Dat::DeviceEvent, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, FileSystem& data){ - return dsm(dg, Dat::FileSystem, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, PassThrough& data){ - return dsm(dg, Dat::PassThrough, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, PendingXfers& data){ - auto rc = dsm(dg, Dat::PendingXfers, msg, data); - if (success(rc)){ - // FIXME: unsure about audio state transitions - DataGroup xg = DataGroup::Image; - switch (msg){ - case Msg::EndXfer: - xferGroup(Msg::Get, xg); - if (xg == DataGroup::Image && data.count() == 0){ - d()->m_state = DsState::Enabled; - } else { - d()->m_state = DsState::XferReady; - } - - break; - - case Msg::Reset: - xferGroup(Msg::Get, xg); - if (xg == DataGroup::Image){ - d()->m_state = DsState::Enabled; - } - - break; - - default: - break; - } - - - } - - return rc; - } - - ReturnCode call(DataGroup dg, Msg msg, SetupFileXfer& data){ - return dsm(dg, Dat::SetupFileXfer, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, SetupMemXfer& data){ - return dsm(dg, Dat::SetupMemXfer, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, DataGroup& data){ - return dsm(dg, Dat::XferGroup, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, Status& data){ - return dsm(dg, Dat::Status, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, StatusUtf8& data){ - return dsm(dg, Dat::StatusUtf8, msg, data); - } - - // dg::image follows - // TODO CieColor - /* - ReturnCode call(DataGroup dg, Msg msg, CieColor& data){ - return dsm(dg, Dat::CieColor, msg, data); - }*/ - - ReturnCode call(DataGroup dg, Msg msg, ExtImageInfo& data){ - char* raw = *Detail::alias_cast(&data); // ExtImageInfo is just an envelope; raw ~ ExtImageInfo.m_data - return dsmPtr(dg, Dat::ExtImageInfo, msg, raw); - } - - ReturnCode call(DataGroup dg, Msg msg, GrayResponse& data){ - return dsmPtr(dg, Dat::GrayResponse, msg, data.data()); - } - - ReturnCode call(DataGroup dg, Msg msg, IccProfileMemory& data){ - Memory mem; // DS allocates and owns the memory - ReturnCode rc = dsm(dg, Dat::IccProfile, msg, mem); - if (success(rc)){ - data = std::move(mem); - } - - return rc; - } - - ReturnCode call(DataGroup dg, Msg msg, const ImageFileXfer&){ - ReturnCode rc = dsmPtr(dg, Dat::ImageFileXfer, msg, nullptr); - if (success(rc)){ - d()->m_state = DsState::Xferring; - } - - return rc; - } - - ReturnCode call(DataGroup dg, Msg msg, ImageInfo& data){ - return dsm(dg, Dat::ImageInfo, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, ImageLayout& data){ - return dsm(dg, Dat::ImageLayout, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, ImageMemFileXfer& data){ - ReturnCode rc = dsm(dg, Dat::ImageMemFileXfer, msg, data); - if (success(rc) || rc == ReturnCode::XferDone){ - d()->m_state = DsState::Xferring; - } - - return rc; - } - - ReturnCode call(DataGroup dg, Msg msg, ImageMemXfer& data){ - ReturnCode rc = dsm(dg, Dat::ImageMemXfer, msg, data); - if (success(rc) || rc == ReturnCode::XferDone){ - d()->m_state = DsState::Xferring; - } - - return rc; - } - - ReturnCode call(DataGroup dg, Msg msg, ImageNativeXfer& data){ - Handle h; - ReturnCode rc = dsm(dg, Dat::ImageNativeXfer, msg, h); - if (rc == ReturnCode::XferDone){ - d()->m_state = DsState::Xferring; - } - - if (h){ - data = ImageNativeXfer(h); - } - - return rc; - } - - ReturnCode call(DataGroup dg, Msg msg, JpegCompression& data){ - return dsm(dg, Dat::JpegCompression, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, Palette8& data){ - return dsm(dg, Dat::Palette8, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, RgbResponse& data){ - return dsmPtr(dg, Dat::RgbResponse, msg, data.data()); - } - - // dg::audio follows - ReturnCode call(DataGroup dg, Msg msg, const AudioFileXfer&){ - // FIXME: unsure about state transitions - ReturnCode rc = dsmPtr(dg, Dat::AudioFileXfer, msg, nullptr); - if (rc == ReturnCode::XferDone){ - d()->m_state = DsState::Xferring; - } - - return rc; - } - - ReturnCode call(DataGroup dg, Msg msg, AudioInfo& data){ - return dsm(dg, Dat::AudioInfo, msg, data); - } - - ReturnCode call(DataGroup dg, Msg msg, AudioNativeXfer& data){ - Handle h; - ReturnCode rc = dsm(dg, Dat::AudioNativeXfer, msg, h); - if (success(rc)){ - d()->m_state = DsState::Xferring; - } - - if (h){ - data = AudioNativeXfer(h); - } - - return rc; - } - // <- Raw - -private: - Source(Detail::ManagerData* mgr, const Identity& srcId) : - m_data(new Detail::SourceData(mgr, srcId)){} - - Detail::SourceData* d() noexcept{ - return m_data.get(); - } - - const Detail::SourceData* d() const noexcept{ - return m_data.get(); - } - - template - ReturnCode dsm(Identity* dest, DataGroup dg, Dat dat, Msg msg, T& data) noexcept{ - return dsmPtr(dest, dg, dat, msg, &data); - } - - ReturnCode dsmPtr(Identity* dest, DataGroup dg, Dat dat, Msg msg, void* data) noexcept{ - assert(isValid()); - - auto mgr = d()->m_mgr; - return mgr->m_entry(&mgr->m_appId, dest, dg, dat, msg, data); - } - - template - ReturnCode dsm(DataGroup dg, Dat dat, Msg msg, T& data) noexcept{ - return dsm(&d()->m_srcId, dg, dat, msg, data); - } - - ReturnCode dsmPtr(DataGroup dg, Dat dat, Msg msg, void* data) noexcept{ - return dsmPtr(&d()->m_srcId, dg, dat, msg, data); - } - - // header-only, yet we need static variables - // templates behave as if defined in at most one source file - template - struct Static { - static Detail::SourceData* g_openSource; - }; - - template - static ReturnCode TWPP_DETAIL_CALLSTYLE callBack( - Identity*, - Identity*, - DataGroup, - Dat, - Msg msg, - void* - ) noexcept{ - Detail::SourceData* src = Static::g_openSource; - if (src == nullptr){ - return ReturnCode::Failure; - } - -#if defined(TWPP_DETAIL_OS_LINUX) - std::unique_lock lock(src->m_cbMutex); - if (src->m_state != DsState::Enabled){ - lock.unlock(); - } -#elif !defined(TWPP_DETAIL_OS_WIN) && !defined(TWPP_DETAIL_OS_MAC) -# error "callBack preparation for your platform here" -#endif - if (msg == Msg::DeviceEvent){ - if (!src->m_devEvent){ - return ReturnCode::Failure; - } - - src->m_devEvent(); - } - - if (src->m_state == DsState::Enabled){ - src->m_readyMsg = msg; - -#if defined(TWPP_DETAIL_OS_WIN) - PostMessageA(static_cast(src->m_mgr->m_rootWindow.raw()), WM_NULL, 0, 0); -#elif defined(TWPP_DETAIL_OS_LINUX) - src->m_cbCond.notify_one(); -#elif defined(TWPP_DETAIL_OS_MAC) - Detail::NSLoop::postDummy(); -#else -# error "callBack for your platform here" -#endif - } - - - return ReturnCode::Success; - } - - std::unique_ptr m_data; - -}; - -template -Detail::SourceData* Source::Static::g_openSource = nullptr; - -/// TWAIN data source manager. -/// At most one valid instance may exist at all times. -/// All corresponding valid sources must be destroyed or cleaned up -/// BEFORE their parent valid manager is closed (destroyed/cleaned up). -class Manager { - -public: - /// Creates an invalid manager. - Manager() noexcept{} - - /// Creates a valid, unloaded manager. - /// \param appIdentity Application identity. - explicit Manager(const Identity& appIdentity) : - m_data(new Detail::ManagerData(appIdentity)){} - - ~Manager(){ - if (isValid()){ - cleanup(); - } - } - - Manager(Manager&&) = default; - Manager& operator=(Manager&& o) noexcept{ - if (&o != this){ - if (isValid()){ - cleanup(); - } - - m_data = std::move(o.m_data); - } - - return *this; - } - - /// Explicitly cleanes the manager, ultimately closing it. - void cleanup() noexcept{ - assert(isValid()); - - switch (d()->m_state){ - case DsmState::Open: - close(); - // fallthrough - case DsmState::Loaded: - unload(); - // fallthrough - case DsmState::PreSession: - // nothing to do now - break; - } - } - - /// Loads the manager library. - /// Not a TWAIN call. - /// \param preferOld {Whether to prefer old DSM (TWAIN_32) instead - /// of the new one (TWAINDSM) on 32bit Windows. - /// Has no effect anywhere else.} - /// \return Whether this call loaded the library. - bool load(bool preferOld = false) noexcept{ - assert(isValid()); - - if (d()->m_state != DsmState::PreSession){ - return false; - } - - if (!d()->m_lib.load(preferOld)){ - return false; - } - - d()->m_state = DsmState::Loaded; - d()->m_entry = d()->m_lib.resolve(); - bool resolved = d()->m_entry != nullptr; - if (!resolved){ - unload(); - } - - return resolved; - } - - /// Unloads the manager library. - /// Not a TWAIN call. - /// \return Whether this call unloaded the library. - bool unload() noexcept{ - assert(isValid()); - - if (d()->m_state != DsmState::Loaded){ - return false; - } - - closeRootWindow(); - d()->m_lib.unload(); - d()->m_state = DsmState::PreSession; - return true; - } - - /// Opens the manager. - ReturnCode open(Handle rootWindow = Handle()) noexcept{ - assert(isValid()); - - if (d()->m_state != DsmState::Loaded){ - return ReturnCode::Failure; - } - -#if defined(TWPP_DETAIL_OS_WIN) - if (rootWindow){ - closeRootWindow(); - d()->m_rootWindow = rootWindow; - d()->m_ownRootWindow = false; - } else { - if (!d()->m_rootWindow || !d()->m_ownRootWindow){ - d()->m_rootWindow = Handle(CreateWindowA("STATIC", nullptr, 0, 0, 0, 0, 0, nullptr, nullptr, nullptr, nullptr)); - if (!d()->m_rootWindow){ - return ReturnCode::Failure; - } - } - - d()->m_ownRootWindow = true; - rootWindow = d()->m_rootWindow; - } -#elif !defined(TWPP_DETAIL_OS_MAC) && !defined(TWPP_DETAIL_OS_LINUX) -# error "manager open setup for your platform here" -#endif - - auto rc = dsm(nullptr, DataGroup::Control, Dat::Parent, Msg::OpenDsm, rootWindow); - if (success(rc)){ - Detail::resetMemFuncs(); - if (d()->m_appId.isDsmV2()){ - Detail::EntryPoint e; - if (success(dsm(nullptr, DataGroup::Control, Dat::EntryPoint, Msg::Get, e))){ - Detail::setMemFuncs(e.m_alloc, e.m_free, e.m_lock, e.m_unlock); - } - } - - d()->m_state = DsmState::Open; - } - - return rc; - } - - /// Closes the manager. - ReturnCode close() noexcept{ - assert(isValid()); - - // no need to check state, dsm will do it for us - -#if defined(TWPP_DETAIL_OS_WIN) - Handle rootWindow = d()->m_rootWindow; -#elif defined(TWPP_DETAIL_OS_MAC) || defined(TWPP_DETAIL_OS_LINUX) - Handle rootWindow; -#else -# error "close manager for your platform here" -#endif - - auto rc = dsm(nullptr, DataGroup::Control, Dat::Parent, Msg::CloseDsm, rootWindow); - if (success(rc)){ - d()->m_state = DsmState::Loaded; - } - - return rc; - } - - /// Creates a valid closed source. - /// Whether the source may be opened depends whether - /// a source with the supplied product name and manufacturer exists. - /// \throw std::bad_alloc - Source createSource(const Str32& productName, const Str32& manufacturer){ - assert(isValid()); - - return Source(d(), Identity(Version(), DataGroup::Control, manufacturer, Str32(), productName)); - } - - /// Creates a valid closed default source. - /// It is almost certain the source may be opened. - /// \throw std::bad_alloc - ReturnCode defaultSource(Source& out){ - Identity id; - auto rc = dsm(nullptr, DataGroup::Control, Dat::Identity, Msg::GetDefault, id); - if (success(rc)){ - out = Source(d(), id); - } - - return rc; - } - - /// Sets default source. - ReturnCode setDefaultSource(Source& in) noexcept{ - return dsm(nullptr, DataGroup::Control, Dat::Identity, Msg::Set, in.d()->m_srcId); - } - - /// Lists all available sources. - /// \tparam Container Container type, usually std::vector. - /// \param out The container to be filled with sources. - /// \return {RC::Success if one source, RC::EndOfList if more sources, RC::Failure if error.} - template - ReturnCode sources(Container& out){ - Identity id; - auto rc = dsm(nullptr, DataGroup::Control, Dat::Identity, Msg::GetFirst, id); - if (success(rc)){ - do { - out.push_back(Source(d(), id)); - - rc = dsm(nullptr, DataGroup::Control, Dat::Identity, Msg::GetNext, id); - } while(success(rc)); - } - - return rc; - } - - /// Shows a source-selection dialog. - /// Available only on Windows and MacOS. - ReturnCode showSourceDialog(Source& out){ - Identity id; - ReturnCode rc = dsm(nullptr, DataGroup::Control, Dat::Identity, Msg::UserSelect, id); - if (success(rc)){ - out = Source(d(), id); - } - - return rc; - } - - /// Obtains the last manager status. - ReturnCode status(Status& status) noexcept{ - return dsm(nullptr, DataGroup::Control, Dat::Status, Msg::Get, status); - } - - /// The current manager TWAIN state. - DsmState state() const noexcept{ - assert(isValid()); - - return d()->m_state; - } - - /// Application identity the manager was/will be open with. - const Identity& identity() const noexcept{ - assert(isValid()); - - return d()->m_appId; - } - - /// Whether this object is a valid manager. - /// Valid manager object is created using constructor with at least one parameter. - /// Using constructor without any parameters results in invalid manager. - bool isValid() const noexcept{ - return static_cast(m_data); - } - - operator bool() noexcept{ - return isValid(); - } - -private: - void closeRootWindow() noexcept{ -#if defined(TWPP_DETAIL_OS_WIN) - if (d()->m_rootWindow && d()->m_ownRootWindow){ - DestroyWindow(static_cast(d()->m_rootWindow.raw())); - d()->m_ownRootWindow = Handle(); - } -#elif !defined(TWPP_DETAIL_OS_MAC) && !defined(TWPP_DETAIL_OS_LINUX) -# error "closeRootWindow for your platform here" -#endif - } - - Detail::ManagerData* d() noexcept{ - return m_data.get(); - } - - const Detail::ManagerData* d() const noexcept{ - return m_data.get(); - } - - template - ReturnCode dsm(Identity* dest, DataGroup dg, Dat dat, Msg msg, T& data){ - return dsmPtr(dest, dg, dat, msg, &data); - } - - ReturnCode dsmPtr(Identity* dest, DataGroup dg, Dat dat, Msg msg, void* data){ - assert(isValid()); - - return d()->m_entry(&d()->m_appId, dest, dg, dat, msg, data); - } - - std::unique_ptr m_data; - -}; - -} - -#endif // TWPP_DETAIL_FILE_APPLICATION_HPP - diff --git a/twain/twain/twpp/audio.hpp b/twain/twain/twpp/audio.hpp deleted file mode 100644 index 6aa8491..0000000 --- a/twain/twain/twpp/audio.hpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_AUDIO_HPP -#define TWPP_DETAIL_FILE_AUDIO_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Information about current audio transfer. -/// ArgType::AudioInfo -class AudioInfo { - -public: - /// Creates empty audio info. - constexpr AudioInfo() noexcept : - m_name(), m_reserved(){} - - /// Creates audio info with set name of audio data. - explicit constexpr AudioInfo(const Str255& name, UInt32 reserved = 0) noexcept : - m_name(name), m_reserved(reserved){} - - /// Name of audio data. - constexpr const Str255& name() const noexcept{ - return m_name; - } - - /// Name of audio data. - Str255& name() noexcept{ - return m_name; - } - - constexpr UInt32 reserved() const noexcept{ - return m_reserved; - } - - void setReserved(UInt32 reserved) noexcept{ - m_reserved = reserved; - } - -private: - Str255 m_name; - UInt32 m_reserved; - -}; - -/// Owner of audio transfer handle. -class AudioNativeXfer { - -public: - template - using Data = Detail::Lock::type>; - - template - using ConstData = Detail::Lock::type>; - - - /// Creates an empty handle owner. - AudioNativeXfer() noexcept : - m_handle(){} - - /// Creates a memory area of desired size for audio native transfer. - /// \throw std::bad_alloc - explicit AudioNativeXfer(UInt32 size) : - m_handle(Detail::alloc(size)){} - - /// Audio data. - template - Data data() noexcept{ - return m_handle.lock::type>(); - } - - /// Audio data. - template - ConstData data() const noexcept{ - return m_handle.lock::type>(); - } - - /// Releases the owned handle. - /// The user becomes responsible for freeing the handle. - Handle release() noexcept{ - return m_handle.release(); - } - -private: - Detail::UniqueHandle m_handle; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_AUDIO_HPP - diff --git a/twain/twain/twpp/capability.hpp b/twain/twain/twpp/capability.hpp deleted file mode 100644 index 6f08b43..0000000 --- a/twain/twain/twpp/capability.hpp +++ /dev/null @@ -1,2323 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_CAPABILITY_HPP -#define TWPP_DETAIL_FILE_CAPABILITY_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -namespace Detail { - -/// Mapping of capability type to type identifier and data type. -template struct Cap {}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef Alarm DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Int32; typedef Int32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Str128; typedef Str128 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Int32; typedef Int32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef XferMech DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Int32; typedef Int32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Int16; typedef Int16 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef PixelType DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef CameraSide DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef ClearBuffers DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef DeviceEvent::Type DataType;}; // Capability->UInt16, DeviceEvent->UInt32 -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Str32; typedef Str32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef DoubleFeedDetection DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef DoubleFeedResponse DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef DoubleFeedSensitivity DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef Duplex DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef CapType DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef FeederAlignment DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef FeederOrder DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef FeederPocket DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Int32; typedef DiscardBlankPages DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef PixelType DataType;}; // only BW/Gray -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef AutoSize DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef SearchMode DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef BarCodeType DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef UInt16 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef BitDepthReduction DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef BitOrder DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef BitOrder DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef UInt16 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef Compression DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt8; typedef UInt8 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef FeederType DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef FilmType DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef Filter DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef Flash DataType;}; // Capability->UInt16, DeviceEvent->UInt32 -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef FlipRotation DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Frame; typedef Frame DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Str32; typedef Str32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef IccProfile DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef ImageFileFormat DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef ImageFilter DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef ImageMerge DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef PixelType DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef JpegQuality DataType;}; // JpegQuality or 0-100 -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef JpegSubSampling DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef LightPath DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef LightSource DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef UInt16 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef Mirror DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef IndicatorsMode DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef NoiseFilter DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef Orientation DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef OverScan DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef SearchMode DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef PatchCode DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef PixelFlavor DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef PixelFlavor DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef PixelType DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef ColorFormat DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef BarCodeType DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef Twpp::InfoId DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef PatchCode DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef PaperSize DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef UInt16 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef Unit DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef XferMech DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Int16; typedef Int16 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef JobControl DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef Language DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef PaperHandling DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Int32; typedef Int32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef PowerSupply DataType;}; // Capability->UInt16, DeviceEvent->Int32 -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef Printer DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef FontStyle DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Str32; typedef Str32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef IndexTrigger DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef PrinterMode DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Fix32; typedef Fix32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef Segmented DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef CapType DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt16; typedef CapType DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Int32; typedef Int32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Int32; typedef Int32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Str32; typedef Str32 DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Cap {static constexpr const Type twty = Type::Int16; typedef Int16 DataType;}; - -TWPP_DETAIL_PACK_BEGIN -// certain apps assume that size of OneValue item is always at least 4 bytes -// add padding that extends the sign of signed integers -// and pads with zeroes for unsigned integers -// all other cases use their data types directly -template // false, any -struct OneValueProxy { - OneValueProxy& operator=(const DataType& value) noexcept{ - m_data = value; - return *this; - } - - operator const DataType&() const noexcept{ - return m_data; - } - - operator DataType&() noexcept{ - return m_data; - } - - DataType m_data; -}; - -template -struct OneValueProxy { - OneValueProxy& operator=(DataType value) noexcept{ - m_signed = static_cast(value); - return *this; - } - - operator DataType() const noexcept{ - return m_data; - } - - operator DataType&() noexcept{ - return m_data; - } - - union { - DataType m_data; - Int32 m_signed; - }; -}; - -template -struct OneValueProxy { - OneValueProxy& operator=(DataType value) noexcept{ - m_unsigned = static_cast(value); - return *this; - } - - operator DataType() const noexcept{ - return m_data; - } - - operator DataType&() noexcept{ - return m_data; - } - - union { - DataType m_data; - UInt32 m_unsigned; - }; -}; - -template -struct OneValueData { - Type m_itemType; - OneValueProxy::value> m_item; -}; - -template -struct ArrayData { - Type m_itemType; - UInt32 m_numItems; - DataType m_items[1]; -}; - -template -struct EnumerationData { - Type m_itemType; - UInt32 m_numItems; - UInt32 m_currIndex; - UInt32 m_defIndex; - DataType m_items[1]; -}; - -// Range items are always 4 bytes large, -// add padding for smaller data types -template -struct RangeProxy { - typedef typename std::conditional< - std::is_signed::value, Int32, UInt32 - >::type InnerType; - - RangeProxy& operator=(DataType value) noexcept{ - m_data = value; - return *this; - } - - operator DataType() const noexcept{ - return static_cast(m_data); - } - - operator DataType&() noexcept{ - return *alias_cast(&m_data); - } - - InnerType m_data; -}; - -template<> -struct RangeProxy { - RangeProxy& operator=(Fix32 value) noexcept{ - m_data = value; - return *this; - } - - operator Fix32() const noexcept{ - return m_data; - } - - operator Fix32&() noexcept{ - return m_data; - } - - Fix32 m_data; -}; - -template -struct RangeData { - Type m_itemType; - RangeProxy m_minValue; - RangeProxy m_maxValue; - RangeProxy m_stepSize; - RangeProxy m_defValue; - RangeProxy m_currValue; -}; -TWPP_DETAIL_PACK_END - - -template -struct IsNumeric { - static constexpr bool value = std::is_integral::value || std::is_same::value; -}; - -} - -class Capability; - -/// Capability container holding a single value. -/// \tparam twty ID of the internal data type. -/// \tparam DataType Exported data type. -template::Type> -class OneValue { - - friend class Capability; - -public: - static constexpr const ConType contype = ConType::OneValue; - typedef DataType* iterator; - typedef const DataType* const_iterator; - - /// Creates an invalid container. - constexpr OneValue() noexcept{} - - /// ID of the internal data type. - Type type() const noexcept{ - return m_data->m_itemType; - } - - /// The contained value. - DataType& item() noexcept{ - return m_data->m_item; - } - - /// The contained value. - const DataType& item() const noexcept{ - return m_data->m_item; - } - - /// Sets the contained value. - void setItem(const DataType& item) noexcept{ - m_data->m_item = item; - } - - operator bool() const noexcept{ - return m_data; - } - - - iterator begin() noexcept{ - return &m_data->m_item; - } - - const_iterator begin() const noexcept{ - return cbegin(); - } - - const_iterator cbegin() const noexcept{ - return &m_data->m_item; - } - - iterator end() noexcept{ - return &m_data->m_item + 1; - } - - const_iterator end() const noexcept{ - return cend(); - } - - const_iterator cend() const noexcept{ - return &m_data->m_item + 1; - } - -private: - OneValue(Handle h) : m_data(h){} - - Detail::Lock > m_data; - -}; - -// disable OneValue for incompatible types -template -class OneValue; -template -class OneValue; - - -/// Capability container holding an array of values. -/// \tparam twty ID of the internal data type. -/// \tparam DataType Exported data type. -template::Type> -class Array { - - friend class Capability; - -public: - static constexpr const ConType contype = ConType::Array; - typedef DataType* iterator; - typedef const DataType* const_iterator; - - /// Creates an invalid container. - constexpr Array() noexcept{} - - /// ID of the internal data type. - Type type() const noexcept{ - return m_data->m_itemType; - } - - /// Number of items in the array. - UInt32 size() const noexcept{ - return m_data->m_numItems; - } - - /// Access contained value in array. - DataType& at(std::size_t i) noexcept{ - return m_data->m_items[i]; - } - - /// Access contained value in array. - const DataType& at(std::size_t i) const noexcept{ - return m_data->m_items[i]; - } - - /// Sets value in array. - void set(std::size_t i, const DataType& val) noexcept{ - at(i) = val; - } - - - DataType& operator[](std::size_t i) noexcept{ - return at(i); - } - - const DataType& operator[](std::size_t i) const noexcept{ - return at(i); - } - - operator bool() const noexcept{ - return m_data; - } - - - iterator begin() noexcept{ - return m_data->m_items; - } - - const_iterator begin() const noexcept{ - return cbegin(); - } - - const_iterator cbegin() const noexcept{ - return m_data->m_items; - } - - iterator end() noexcept{ - return m_data->m_items + m_data->m_numItems; - } - - const_iterator end() const noexcept{ - return cend(); - } - - const_iterator cend() const noexcept{ - return m_data->m_items + m_data->m_numItems; - } - -private: - Array(Handle h) : m_data(h){} - - Detail::Lock > m_data; - -}; - -// disable Array for incompatible types -template -class Array; -template -class Array; - - -/// Capability container holding an array of values, -/// and default and current indexes. -/// \tparam twty ID of the internal data type. -/// \tparam DataType Exported data type. -template::Type> -class Enumeration { - - friend class Capability; - -public: - static constexpr const ConType contype = ConType::Enumeration; - typedef DataType* iterator; - typedef const DataType* const_iterator; - - /// Creates an invalid container. - constexpr Enumeration() noexcept{} - - /// ID of the internal data type. - Type type() const noexcept{ - return m_data->m_itemType; - } - - /// Number of items in the array. - UInt32 size() const noexcept{ - return m_data->m_numItems; - } - - - /// Index of the currently selected item. - UInt32 currentIndex() const noexcept{ - return m_data->m_currIndex; - } - - /// Sets index of the currently selected item. - void setCurrentIndex(UInt32 index) noexcept{ - m_data->m_currIndex = index; - } - - /// Item at the current index. - DataType& currentItem() noexcept{ - return at(m_data->m_currIndex); - } - - /// Item at the current index. - const DataType& currentItem() const noexcept{ - return at(m_data->m_currIndex); - } - - /// Sets item at the current index. - void setCurrentItem(const DataType& item) noexcept{ - currentItem() = item; - } - - - /// Index of the default item. - UInt32 defaultIndex() const noexcept{ - return m_data->m_defIndex; - } - - /// Sets index of the default item. - void setDefaultIndex(UInt32 index) noexcept{ - m_data->m_defIndex = index; - } - - /// Item at the default index. - DataType& defaultItem() noexcept{ - return at(m_data->m_defIndex); - } - - /// Item at the default index. - const DataType& defaultItem() const noexcept{ - return at(m_data->m_defIndex); - } - - /// Sets item at the default index. - void setDefaultItem(const DataType& item) noexcept{ - defaultItem() = item; - } - - - /// Access contained value in array. - DataType& at(std::size_t i) noexcept{ - return m_data->m_items[i]; - } - - /// Access contained value in array. - const DataType& at(std::size_t i) const noexcept{ - return m_data->m_items[i]; - } - - /// Sets value in array. - void set(std::size_t i, const DataType& val) noexcept{ - at(i) = val; - } - - - DataType& operator[](std::size_t i) noexcept{ - return at(i); - } - - const DataType& operator[](std::size_t i) const noexcept{ - return at(i); - } - - operator bool() const noexcept{ - return m_data; - } - - - iterator begin() noexcept{ - return m_data->m_items; - } - - const_iterator begin() const noexcept{ - return cbegin(); - } - - const_iterator cbegin() const noexcept{ - return m_data->m_items; - } - - iterator end() noexcept{ - return m_data->m_items + m_data->m_numItems; - } - - const_iterator end() const noexcept{ - return cend(); - } - - const_iterator cend() const noexcept{ - return m_data->m_items + m_data->m_numItems; - } - -private: - Enumeration(Handle h) : m_data(h){} - - Detail::Lock > m_data; - -}; - -// disable Enumeration for incompatible types -template -class Enumeration; -template -class Enumeration; - - -/// Capability container holding a range of numeric values, -/// and default and current values. -/// \tparam twty ID of the internal data type. -/// \tparam DataType Exported data type. -template::Type> -class Range { - - friend class Capability; - static_assert(Detail::IsNumeric::value, "not a numeric type"); - -private: - static constexpr const ConType contype = ConType::Range; - template - class IteratorImpl { - - friend class Range; - - public: - constexpr IteratorImpl() noexcept : - m_curr(), m_parent(nullptr){} - - IterDataType operator*() const noexcept{ - return m_curr; - } - - IteratorImpl& operator++() noexcept{ // prefix - m_curr += step(); - checkValue(); - return *this; - } - - IteratorImpl operator++(int) noexcept{ // postfix - IteratorImpl ret(*this); - m_curr += step(); - checkValue(); - return ret; - } - - IteratorImpl& operator--() noexcept{ // prefix - m_curr -= step(); - return *this; - } - - IteratorImpl operator--(int) noexcept{ // postfix - IteratorImpl ret(*this); - m_curr -= step(); - return ret; - } - - bool operator==(const IteratorImpl& o) const noexcept{ - return m_curr == o.m_curr && - (m_parent == o.m_parent || - (m_parent && o.m_parent && step() == o.step()) - ); - } - - bool operator!=(const IteratorImpl& o) const noexcept{ - return (*this == o); - } - - private: - IterDataType step() const noexcept{ - return m_parent->stepSize(); - } - - IterDataType max() const noexcept{ - return m_parent->maxValue(); - } - - void checkValue() noexcept{ - // avoid infinite loops in case no such N exists: `min + N * step == max` - if (m_curr > max()){ - m_curr = max() + step(); - } - } - - IteratorImpl(IterDataType curr, const Range& parent) noexcept : - m_curr(curr), m_parent(&parent){} - - IterDataType m_curr; - const Range* m_parent; - - }; - -public: - typedef IteratorImpl const_iterator; - - /// Creates an invalid container. - constexpr Range() noexcept{} - - /// ID of the internal data type. - Type type() const noexcept{ - return m_data->m_itemType; - } - - /// Minimal value in the range. - DataType minValue() const noexcept{ - return m_data->m_minValue; - } - - /// Sets minimal value in the range. - void setMinValue(DataType val) noexcept{ - m_data->m_minValue = val; - } - - /// Maximal value in the range. - DataType maxValue() const noexcept{ - return m_data->m_maxValue; - } - - /// Sets maximal value in the range. - void setMaxValue(DataType val) noexcept{ - m_data->m_maxValue = val; - } - - /// Size of a single step. - DataType stepSize() const noexcept{ - return m_data->m_stepSize; - } - - ///Sets size of a single step. - void setStepSize(DataType val) noexcept{ - m_data->m_stepSize = val; - } - - /// Default value in the range. - DataType defaultValue() const noexcept{ - return m_data->m_defValue; - } - - /// Sets default value in the range. - void setDefaultValue(DataType val) noexcept{ - m_data->m_defValue = val; - } - - /// Current value in the range. - DataType currentValue() const noexcept{ - return m_data->m_currValue; - } - - /// Sets current value in the range. - void setCurrentValue(DataType val) noexcept{ - m_data->m_currValue = val; - } - - operator bool() const noexcept{ - return m_data; - } - - const_iterator begin() const noexcept{ - return cbegin(); - } - - const_iterator cbegin() const noexcept{ - return const_iterator(m_data->m_minValue, *this); - } - - const_iterator end() const noexcept{ - return cend(); - } - - const_iterator cend() const noexcept{ - auto step = m_data->m_stepSize; - if (step != DataType()){ - return const_iterator(m_data->m_maxValue + step, *this); - } else { - return cbegin(); // no items with step equal to zero - } - } - -private: - Range(Handle h) : m_data(h){} - - Detail::Lock > m_data; - -}; - -// disable Range for incompatible types -// (non-numeric types) -template -class Range; -template -class Range; -template -class Range; -template -class Range; -template -class Range; -template -class Range; -template -class Range; -template -class Range; - - -namespace Detail { - -template -class CapDataImpl; - -template -class CapData; - -/// Capability iterator. -/// The default implementation is designed for non-numeric values. -/// Meaning it can't handle ranges. -template // false -class CapIterator { - - friend class Capability; - - template - friend class CapDataImpl; - -public: - constexpr CapIterator() noexcept : - m_ptr(nullptr){} - - DataType& operator*() const noexcept{ - return *m_ptr; - } - - CapIterator& operator++() noexcept{ // prefix - ++m_ptr; - return *this; - } - - CapIterator operator++(int) noexcept{ // postfix - CapIterator ret(*this); - ++m_ptr; - return ret; - } - - CapIterator& operator--() noexcept{ // prefix - --m_ptr; - return *this; - } - - CapIterator operator--(int) noexcept{ // postfix - CapIterator ret(*this); - --m_ptr; - return ret; - } - - bool operator==(const CapIterator& o) const noexcept{ - return m_ptr == o.m_ptr; - } - - bool operator!=(const CapIterator& o) const noexcept{ - return !(*this == o); - } - -private: - constexpr CapIterator(DataType* ptr) noexcept : - m_ptr(ptr){} - - DataType* m_ptr; - -}; - -/// Capability iterator. -/// This specialization can handles numeric values only. -/// Ranges included. -template -class CapIterator { - - friend class Capability; - - template - friend class CapDataImpl; - -public: - typedef typename std::remove_const::type ReturnType; - - constexpr CapIterator() noexcept : - m_ptr(nullptr), m_isPtr(true){} - - ReturnType operator*() const noexcept{ - if (m_isPtr){ - return *m_ptr; - } else { - return *m_rng; - } - } - - CapIterator& operator++() noexcept{ // prefix - if (m_isPtr){ - ++m_ptr; - } else { - ++m_rng; - } - - return *this; - } - - CapIterator operator++(int) noexcept{ // postfix - CapIterator ret(*this); - if (m_isPtr){ - ++m_ptr; - } else { - ++m_rng; - } - - return ret; - } - - CapIterator& operator--() noexcept{ // prefix - if (m_isPtr){ - --m_ptr; - } else { - --m_rng; - } - - return *this; - } - - CapIterator operator--(int) noexcept{ // postfix - CapIterator ret(*this); - if (m_isPtr){ - --m_ptr; - } else { - --m_rng; - } - - return ret; - } - - bool operator==(const CapIterator& o) const noexcept{ - if (m_isPtr != o.m_isPtr){ - return false; - } - - return m_isPtr ? m_ptr == o.m_ptr : m_rng == o.m_rng; - } - - bool operator!=(const CapIterator& o) const noexcept{ - return !(*this == o); - } - -private: - constexpr CapIterator(DataType* ptr) noexcept : - m_ptr(ptr), m_isPtr(true){} - - constexpr CapIterator(typename Range::const_iterator rng) noexcept : - m_rng(rng), m_isPtr(false){} - - union { - DataType* m_ptr; - typename Range::const_iterator m_rng; - }; - bool m_isPtr; - -}; - -/// Capability iterator lock implementation. -/// The default implementation is designed for non-numeric values. -/// Meaning it can't handle ranges. -template::Type> // numeric=false -class CapDataImpl { - - friend class Capability; - - template - friend class CapData; - -public: - typedef CapIterator const_iterator; - - /// Creates an invalid container. - constexpr CapDataImpl() noexcept : - m_data(){ - - static_assert(type != Type::DontCare, "type may not be DontCare"); - static_assert(sizeof(typename Detail::Twty::Type) == sizeof(DataType), "type sizes dont match"); - } - - const_iterator begin() const noexcept{ - return cbegin(); - } - - const_iterator cbegin() const noexcept{ - return const_iterator(reinterpret_cast(m_data.data() + offset())); - } - - const_iterator end() const noexcept{ - return cend(); - } - - const_iterator cend() const noexcept{ - return const_iterator(reinterpret_cast(m_data.data() + offset()) + size()); - } - - UInt32 size() const noexcept{ - switch (m_conType){ - case ConType::Array: - case ConType::Enumeration: - return reinterpret_cast*>(m_data.data())->m_numItems; - case ConType::OneValue: - return 1; - case ConType::Range: - default: - return 0; // should not happen - } - } - -private: - CapDataImpl(const Capability& cap); - - UInt32 offset() const noexcept{ - switch (m_conType){ - case ConType::Array: - return sizeof(Type) + sizeof(UInt32); - case ConType::Enumeration: - return sizeof(Type) + 3 * sizeof(UInt32); - case ConType::OneValue: - return sizeof(Type); - case ConType::Range: - default: - return 0; // should not happen - } - } - - ConType m_conType; - Detail::Lock m_data; // actual type resolved at runtime - -}; - -/// Capability iterator lock implementation. -/// This specialization can handles numeric values only. -/// Ranges included. -template -class CapDataImpl { - - friend class Capability; - - template - friend class CapData; - -public: - typedef CapIterator const_iterator; - - /// Creates an invalid container. - constexpr CapDataImpl() noexcept : - m_data(){ - - static_assert(type != Type::DontCare, "type may not be DontCare"); - static_assert(sizeof(typename Detail::Twty::Type) == sizeof(DataType), "type sizes dont match"); - } - - const_iterator begin() const noexcept{ - return cbegin(); - } - - const_iterator cbegin() const noexcept{ - if (m_conType != ConType::Range){ - return const_iterator(reinterpret_cast(m_data.data() + offset())); - } else { - const auto& rng = *Detail::alias_cast*>(&m_data); - return const_iterator(rng.cbegin()); - } - } - - const_iterator end() const noexcept{ - return cend(); - } - - const_iterator cend() const noexcept{ - if (m_conType != ConType::Range){ - return const_iterator(reinterpret_cast(m_data.data() + offset()) + size()); - } else { - const auto& rng = *Detail::alias_cast*>(&m_data); - return const_iterator(rng.cend()); - } - } - - UInt32 size() const noexcept{ - switch (m_conType){ - case ConType::Array: - case ConType::Enumeration: - return reinterpret_cast*>(m_data.data())->m_numItems; - case ConType::OneValue: - return 1; - case ConType::Range: { - auto& rng = *reinterpret_cast*>(m_data.data()); - if (rng.m_stepSize != DataType()){ - return static_cast((Detail::abs(rng.m_maxValue - rng.m_minValue) / rng.m_stepSize).toFloat()) + 1; - } else { - return 0; - } - } - default: - return 0; // should not happen - } - } - -private: - CapDataImpl(const Capability& cap); - - UInt32 offset() const noexcept{ - switch (m_conType){ - case ConType::Array: - return sizeof(Type) + sizeof(UInt32); - case ConType::Enumeration: - return sizeof(Type) + 3 * sizeof(UInt32); - case ConType::OneValue: - return sizeof(Type); - case ConType::Range: - default: - return 0; // should not happen - } - } - - ConType m_conType; - Detail::Lock m_data; // actual type resolved at runtime - -}; - -/// Capability iterator lock. -template -class CapData : public CapDataImpl::value, DataType> { - - typedef CapDataImpl::value, DataType> Base; - -public: - constexpr CapData() noexcept{} - - CapData(const Capability& cap) : - Base(cap){} - -}; - - -/// Capability current item implementation. -/// The default implementation is designed for non-numeric values. -/// Meaning it can't handle ranges. -template // false -struct CurrentItemImpl { - static DataType item(Capability& cap); -}; - -/// Capability current item implementation. -/// This specialization can handles numeric values only. -/// Ranges included. -template -struct CurrentItemImpl { - static DataType item(Capability& cap); -}; - -/// Capability current item. -template -struct CurrentItem : CurrentItemImpl::value> { - -}; - -} - -/// Base capability exception. -class CapabilityException : public Exception { - -public: - virtual const char* what() const noexcept override{ - return "Capability handling error."; - } - -}; - -/// Invalid or unsupported container capability exception. -class ContainerException : public CapabilityException { - -public: - virtual const char* what() const noexcept override{ - return "Unexpected container."; - } - -}; - -/// Invalid, unsupported or mismatched item type identifier capability exception. -class ItemTypeException : public CapabilityException { - -public: - virtual const char* what() const noexcept override{ - return "Invalid item type."; - } - -}; - -/// No data capability exception. -/// Capability does not contain any data (container). -class DataException : public CapabilityException { - -public: - virtual const char* what() const noexcept override{ - return "No data."; - } - -}; - -TWPP_DETAIL_PACK_BEGIN -/// TWAIN capability. -/// Any access to containers must be finished before destroying -/// the according capability instance. -class Capability { - - template - friend class Detail::CapDataImpl; - -public: - /// Creates capability holding OneValue container. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \param cap Capability type. - /// \param value Initial value. - /// \throw std::bad_alloc - template - static Capability createOneValue(CapType cap, const DataType& value = DataType()){ - Capability ret(cap, ConType::OneValue, type, sizeof(Detail::OneValueData)); - auto ov = ret.oneValue(); - ov.setItem(value); - return std::move(ret); - } - - /// Creates capability holding OneValue container. - /// \tparam type ID of the internal data type. - /// \param cap Capability type. - /// \param value Initial value. - /// \throw std::bad_alloc - template - static Capability createOneValue(CapType cap, const typename Detail::Twty::Type& value = typename Detail::Twty::Type()){ - return createOneValue::Type>(cap, value); - } - - /// Creates capability holding OneValue container. - /// \tparam T Data type. - /// \param cap Capability type. - /// \param value Initial value. - /// \throw std::bad_alloc - template - static Capability createOneValue(CapType cap, const T& value = T()){ - return createOneValue::twty, T>(cap, value); - } - - /// Creates capability holding OneValue container. - /// \tparam cap Capability type. Data types are set accordingly. - /// \param value Initial value. - /// \throw std::bad_alloc - template - static Capability createOneValue(const typename Detail::Cap::DataType& value = typename Detail::Cap::DataType()){ - return createOneValue::twty, typename Detail::Cap::DataType>(cap, value); - } - - - /// Creates capability holding Array container. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \param cap Capability type. - /// \param size Number of elements in the array. - /// \throw std::bad_alloc - template - static Capability createArray(CapType cap, UInt32 size){ - Capability ret(cap, ConType::Array, type, sizeof(Detail::ArrayData) - sizeof(DataType) + size * sizeof(DataType)); - auto arr = ret.array(); - arr.m_data->m_numItems = size; - return std::move(ret); - } - - /// Creates capability holding Array container. - /// \tparam type ID of the internal data type. - /// \param cap Capability type. - /// \param size Number of elements in the array. - /// \throw std::bad_alloc - template - static Capability createArray(CapType cap, UInt32 size){ - return createArray::Type>(cap, size); - } - - /// Creates capability holding Array container. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \param cap Capability type. - /// \param values Initial values in the array. - /// \throw std::bad_alloc - template - static Capability createArray(CapType cap, std::initializer_list values){ - Capability ret = createArray(cap, static_cast(values.size())); - auto arr = ret.array(); - - UInt32 i = 0; - for (const auto& val : values){ - arr[i] = val; - i++; - } - - return std::move(ret); - } - - /// Creates capability holding Array container. - /// \tparam type ID of the internal data type. - /// \param cap Capability type. - /// \param values Initial values in the array. - /// \throw std::bad_alloc - template - static Capability createArray(CapType cap, std::initializer_list::Type> values){ - return createArray::Type>(cap, values); - } - - /// Creates capability holding Array container. - /// \tparam T Data type. - /// \param cap Capability type. - /// \param size Number of elements in the array. - /// \throw std::bad_alloc - template - static Capability createArray(CapType cap, UInt32 size){ - return createArray::twty, T>(cap, size); - } - - /// Creates capability holding Array container. - /// \tparam T Data type. - /// \param cap Capability type. - /// \param values Initial values in the array. - /// \throw std::bad_alloc - template - static Capability createArray(CapType cap, std::initializer_list values){ - return createArray::twty, T>(cap, values); - } - - /// Creates capability holding Array container. - /// \tparam cap Capability type. Data types are set accordingly. - /// \param size Number of elements in the array. - /// \throw std::bad_alloc - template - static Capability createArray(UInt32 size){ - return createArray::twty, typename Detail::Cap::DataType>(cap, size); - } - - /// Creates capability holding Array container. - /// \tparam cap Capability type. Data types are set accordingly. - /// \param values Initial values in the array. - /// \throw std::bad_alloc - template - static Capability createArray(std::initializer_list::DataType> values){ - return createArray::twty, typename Detail::Cap::DataType>(cap, values); - } - - - /// Creates capability holding Enumeration container. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \param cap Capability type. - /// \param size Number of elements in the array. - /// \param currIndex Index of the currently selected item. - /// \param defIndex Index of the default item. - /// \throw std::bad_alloc - template - static Capability createEnumeration(CapType cap, UInt32 size, UInt32 currIndex = 0, UInt32 defIndex = 0){ - Capability ret(cap, ConType::Enumeration, type, sizeof(Detail::EnumerationData) - sizeof(DataType) + size * sizeof(DataType)); - auto enm = ret.enumeration(); - enm.m_data->m_numItems = size; - enm.m_data->m_currIndex = currIndex; - enm.m_data->m_defIndex = defIndex; - return std::move(ret); - } - - /// Creates capability holding Enumeration container. - /// \tparam type ID of the internal data type. - /// \param cap Capability type. - /// \param size Number of elements in the array. - /// \param currIndex Index of the currently selected item. - /// \param defIndex Index of the default item. - /// \throw std::bad_alloc - template - static Capability createEnumeration(CapType cap, UInt32 size, UInt32 currIndex = 0, UInt32 defIndex = 0){ - return createEnumeration::Type>(cap, size, currIndex, defIndex); - } - - /// Creates capability holding Enumeration container. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \param cap Capability type. - /// \param values Initial values in the array. - /// \param currIndex Index of the currently selected item. - /// \param defIndex Index of the default item. - /// \throw std::bad_alloc - template - static Capability createEnumeration(CapType cap, std::initializer_list values, UInt32 currIndex = 0, UInt32 defIndex = 0){ - Capability ret = createEnumeration(cap, static_cast(values.size()), currIndex, defIndex); - auto enm = ret.enumeration(); - - UInt32 i = 0; - for (const auto& val : values){ - enm[i] = val; - i++; - } - - return std::move(ret); - } - template - static Capability createEnumeration(CapType cap, std::list values, UInt32 currIndex = 0, UInt32 defIndex = 0){ - Capability ret = createEnumeration(cap, static_cast(values.size()), currIndex, defIndex); - auto enm = ret.enumeration(); - - UInt32 i = 0; - for (const auto& val : values){ - enm[i] = val; - i++; - } - - return std::move(ret); - } - - /// Creates capability holding Enumeration container. - /// \tparam type ID of the internal data type. - /// \param cap Capability type. - /// \param values Initial values in the array. - /// \param currIndex Index of the currently selected item. - /// \param defIndex Index of the default item. - /// \throw std::bad_alloc - template - static Capability createEnumeration(CapType cap, std::initializer_list::Type> values, UInt32 currIndex = 0, UInt32 defIndex = 0){ - return createEnumeration::Type>(cap, values, currIndex, defIndex); - } - - /// Creates capability holding Enumeration container. - /// \tparam T Data type. - /// \param cap Capability type. - /// \param size Number of elements in the array. - /// \param currIndex Index of the currently selected item. - /// \param defIndex Index of the default item. - /// \throw std::bad_alloc - template - static Capability createEnumeration(CapType cap, UInt32 size, UInt32 currIndex = 0, UInt32 defIndex = 0){ - return createEnumeration::twty, T>(cap, size, currIndex, defIndex); - } - - /// Creates capability holding Enumeration container. - /// \tparam T Data type. - /// \param cap Capability type. - /// \param values Initial values in the array. - /// \param currIndex Index of the currently selected item. - /// \param defIndex Index of the default item. - /// \throw std::bad_alloc - template - static Capability createEnumeration(CapType cap, std::initializer_list values, UInt32 currIndex = 0, UInt32 defIndex = 0){ - return createEnumeration::twty, T>(cap, values, currIndex, defIndex); - } - template - static Capability createEnumeration(CapType cap, std::list values, UInt32 currIndex = 0, UInt32 defIndex = 0){ - return createEnumeration::twty, T>(cap, values, currIndex, defIndex); - } - - /// Creates capability holding Enumeration container. - /// \tparam cap Capability type. Data types are set accordingly. - /// \param size Number of elements in the array. - /// \param currIndex Index of the currently selected item. - /// \param defIndex Index of the default item. - /// \throw std::bad_alloc - template - static Capability createEnumeration(UInt32 size, UInt32 currIndex = 0, UInt32 defIndex = 0){ - return createEnumeration::twty, typename Detail::Cap::DataType>(cap, size, currIndex, defIndex); - } - - /// Creates capability holding Enumeration container. - /// \tparam cap Capability type. Data types are set accordingly. - /// \param values Initial values in the array. - /// \param currIndex Index of the currently selected item. - /// \param defIndex Index of the default item. - /// \throw std::bad_alloc - template - static Capability createEnumeration(std::initializer_list::DataType> values, UInt32 currIndex = 0, UInt32 defIndex = 0){ - return createEnumeration::twty, typename Detail::Cap::DataType>(cap, values, currIndex, defIndex); - } - template - static Capability createEnumeration(std::list::DataType> values, UInt32 currIndex = 0, UInt32 defIndex = 0){ - return createEnumeration::twty, typename Detail::Cap::DataType>(cap, values, currIndex, defIndex); - } - - - /// Creates capability holding Range container. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \param cap Capability type. - /// \param min Minimal range value. - /// \param max Maximal range value. - /// \param step Size of a single step. - /// \param curr Current value. - /// \param def Default value. - /// \throw std::bad_alloc - template - static Capability createRange(CapType cap, DataType min, DataType max, DataType step, DataType curr, DataType def){ - Capability ret(cap, ConType::Range, type, sizeof(Detail::RangeData)); - auto rng = ret.range(); - rng.setMinValue(min); - rng.setMaxValue(max); - rng.setStepSize(step); - rng.setCurrentValue(curr); - rng.setDefaultValue(def); - return std::move(ret); - } - - /// Creates capability holding Range container. - /// \tparam type ID of the internal data type. - /// \param cap Capability type. - /// \param min Minimal range value. - /// \param max Maximal range value. - /// \param step Size of a single step. - /// \param curr Current value. - /// \param def Default value. - /// \throw std::bad_alloc - template - static Capability createRange( - CapType cap, - typename Detail::Twty::Type min, - typename Detail::Twty::Type max, - typename Detail::Twty::Type step, - typename Detail::Twty::Type curr, - typename Detail::Twty::Type def - ){ - return createRange::Type>(cap, min, max, step, curr, def); - } - - /// Creates capability holding Range container. - /// \tparam T Data type. - /// \param cap Capability type. - /// \param min Minimal range value. - /// \param max Maximal range value. - /// \param step Size of a single step. - /// \param curr Current value. - /// \param def Default value. - /// \throw std::bad_alloc - template - static Capability createRange(CapType cap, T min, T max, T step, T curr, T def){ - return createRange::twty, T>(cap, min, max, step, curr, def); - } - - /// Creates capability holding Range container. - /// \tparam cap Capability type. Data types are set accordingly. - /// \param min Minimal range value. - /// \param max Maximal range value. - /// \param step Size of a single step. - /// \param curr Current value. - /// \param def Default value. - /// \throw std::bad_alloc - template - static Capability createRange( - typename Detail::Cap::DataType min, - typename Detail::Cap::DataType max, - typename Detail::Cap::DataType step, - typename Detail::Cap::DataType curr, - typename Detail::Cap::DataType def - ){ - return createRange::twty, typename Detail::Cap::DataType>( - cap, min, max, step, curr, def); - } - - - /// Creates capability of the supplied type without any data. - /// Useful for retrieving data from data source. - explicit Capability(CapType cap) noexcept : - m_cap(cap), m_conType(ConType::DontCare), m_cont(){} - - Capability(Capability&&) = default; - Capability& operator=(Capability&&) = default; - - /// Capability type. - CapType type() const noexcept{ - return m_cap; - } - - /// dangerous set CapType - void dangerous_set_cap(CapType cap) { - m_cap = cap; - } - - /// Container type. - ConType container() const noexcept{ - return m_conType; - } - - /// Item type. - /// Valid only if the capability contains data. - /// \throw DataException When there is no data. - Type itemType() const{ - if (!m_cont){ - throw DataException(); - } - - return *m_cont.lock().data(); - } - - operator bool() const noexcept{ - return m_cont; - } - - /// Contained OneValue container. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not OneValue. - /// \throw ItemTypeException When item type does not match. - template - OneValue oneValue(){ - return containerCheck(); - } - - /// Contained OneValue container. - /// \tparam type ID of the internal data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not OneValue. - /// \throw ItemTypeException When item type does not match. - template - OneValue::Type> oneValue(){ - return oneValue::Type>(); - } - - /// Contained OneValue container. - /// \tparam T Data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not OneValue. - /// \throw ItemTypeException When item type does not match. - template - OneValue::twty, T> oneValue(){ - return oneValue::twty, T>(); - } - - /// Contained OneValue container. - /// \tparam cap Capability type. Data types are set accordingly. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not OneValue. - /// \throw ItemTypeException When item type does not match. - template - OneValue::twty, typename Detail::Cap::DataType> oneValue(){ - return oneValue::twty, typename Detail::Cap::DataType>(); - } - - /// Contained Array container. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Array. - /// \throw ItemTypeException When item type does not match. - template - Array array(){ - return containerCheck(); - } - - /// Contained Array container. - /// \tparam type ID of the internal data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Array. - /// \throw ItemTypeException When item type does not match. - template - Array::Type> array(){ - return array::Type>(); - } - - /// Contained Array container. - /// \tparam T Data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Array. - /// \throw ItemTypeException When item type does not match. - template - Array::twty, T> array(){ - return array::twty, T>(); - } - - /// Contained Array container. - /// \tparam cap Capability type. Data types are set accordingly. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Array. - /// \throw ItemTypeException When item type does not match. - template - Array::twty, typename Detail::Cap::DataType> array(){ - return array::twty, typename Detail::Cap::DataType>(); - } - - /// Contained Enumeration container. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration. - /// \throw ItemTypeException When item type does not match. - template - Enumeration enumeration(){ - return containerCheck(); - } - - /// Contained Enumeration container. - /// \tparam type ID of the internal data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration. - /// \throw ItemTypeException When item type does not match. - template - Enumeration::Type> enumeration(){ - return enumeration::Type>(); - } - - /// Contained Enumeration container. - /// \tparam T Data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration. - /// \throw ItemTypeException When item type does not match. - template - Enumeration::twty, T> enumeration(){ - return enumeration::twty, T>(); - } - - /// Contained Enumeration container. - /// \tparam cap Capability type. Data types are set accordingly. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration. - /// \throw ItemTypeException When item type does not match. - template - Enumeration::twty, typename Detail::Cap::DataType> enumeration(){ - return enumeration::twty, typename Detail::Cap::DataType>(); - } - - /// Contained Range container. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration. - /// \throw ItemTypeException When item type does not match. - template - Range range(){ - return containerCheck(); - } - - /// Contained Range container. - /// \tparam type ID of the internal data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration. - /// \throw ItemTypeException When item type does not match. - template - Range::Type> range(){ - return range::Type>(); - } - - /// Contained Range container. - /// \tparam T Data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Range. - /// \throw ItemTypeException When item type does not match. - template - Range::twty, T> range(){ - return range::twty, T>(); - } - - /// Contained Range container. - /// \tparam cap Capability type. Data types are set accordingly. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Range. - /// \throw ItemTypeException When item type does not match. - template - Range::twty, typename Detail::Cap::DataType> range(){ - return range::twty, typename Detail::Cap::DataType>(); - } - - template - using Data = Detail::CapData; - - /// Returns a data container for iterating over all possible values. - /// Use this only if you don't care about current or default values and container type. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is invalid. - /// \throw ItemTypeException When item type does not match. - template - Data data() const{ - return *this; - } - - /// Returns a data container for iterating over all possible values. - /// Use this only if you don't care about current or default values and container type. - /// \tparam type ID of the internal data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is invalid. - /// \throw ItemTypeException When item type does not match. - template - Data::Type> data() const{ - return *this; - } - - /// Returns a data container for iterating over all possible values. - /// Use this only if you don't care about current or default values and container type. - /// \tparam T Data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is invalid. - /// \throw ItemTypeException When item type does not match. - template - Data::twty, T> data() const{ - return *this; - } - - /// Returns a data container for iterating over all possible values. - /// Use this only if you don't care about current or default values and container type. - /// \tparam cap Capability type. Data types are set accordingly. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is invalid. - /// \throw ItemTypeException When item type does not match. - template - Data::twty, typename Detail::Cap::DataType> data() const{ - return *this; - } - - - /// Returns a copy of the current item of this capability. - /// Can be used only with Enumeration, OneValue, and Range containers. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration, OneValue, nor Range. - /// \throw ItemTypeException When item type does not match. - template - DataType currentItem(){ - return Detail::CurrentItem::item(*this); - } - - /// Returns a copy of the current item of this capability. - /// Can be used only with Enumeration, OneValue, and Range containers. - /// \tparam type ID of the internal data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration, OneValue, nor Range. - /// \throw ItemTypeException When item type does not match. - template - typename Detail::Twty::Type currentItem(){ - return currentItem::Type>(); - } - - /// Returns a copy of the current item of this capability. - /// Can be used only with Enumeration, OneValue, and Range containers. - /// \tparam T Data type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration, OneValue, nor Range. - /// \throw ItemTypeException When item type does not match. - template - T currentItem(){ - return currentItem::twty, T>(); - } - - /// Returns a copy of the current item of this capability. - /// Can be used only with Enumeration, OneValue, and Range containers. - /// \tparam cap Capability type. Data types are set accordingly. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration, OneValue, nor Range. - /// \throw ItemTypeException When item type does not match. - template - typename Detail::Cap::DataType currentItem(){ - return currentItem::twty, typename Detail::Cap::DataType>(); - } - -private: - /// \throw DataException - /// \throw ContainerException - /// \throw ItemTypeException - Capability(CapType cap, ConType conType, Type twty, UInt32 size) : - m_cap(cap), m_conType(conType), m_cont(Detail::alloc(size)){ - - *m_cont.lock().data() = twty; - } - - template class Container, Type type, typename DataType> - Container containerCheck(){ - static_assert(type != Type::DontCare, "type may not be DontCare"); - static_assert(sizeof(typename Detail::Twty::Type) == sizeof(DataType), "type sizes dont match"); - - if (!m_cont){ - throw DataException(); - } - - if (Container::contype != container()){ - throw ContainerException(); - } - - Container ret(m_cont.get()); - UINT16 r_type = (UINT16)ret.type(); - UINT16 m_type = (UINT16)type; - if (!((((r_type >= 0) || (r_type <= 5)) && ((m_type >= 0) || (m_type <= 5))) || (((r_type >= 9) || (r_type <= 12)) && ((m_type >= 9) || (m_type <= 12))) || (m_type == r_type))) { - //if (type != r_type){ - throw ItemTypeException(); - } - - return std::move(ret); - } - - CapType m_cap; - ConType m_conType; - Detail::UniqueHandle m_cont; - -}; -TWPP_DETAIL_PACK_END - -/// Invalid, unsupported or mismatched item type identifier capability exception. -/// Holds the Capability instance that caused the exception. -class CapItemTypeException : public ItemTypeException { - -public: - CapItemTypeException(Capability cap) noexcept : - m_cap(std::move(cap)){} - - CapItemTypeException(CapItemTypeException&&) = default; - CapItemTypeException& operator=(CapItemTypeException&&) = default; - - CapItemTypeException(const CapItemTypeException&) = delete; - CapItemTypeException& operator=(const CapItemTypeException&) = delete; - - Capability& capability() noexcept{ - return m_cap; - } - - const Capability& capability() const noexcept{ - return m_cap; - } - - virtual const char* what() const noexcept override{ - return "Unexpected item type."; - } - -private: - Capability m_cap; - -}; - -/// Invalid, unexpected, unmatched capability type. -/// Holds the Capability instance that caused the exception. -class CapTypeException : public CapabilityException { - -public: - CapTypeException(Capability cap) noexcept : - m_cap(std::move(cap)){} - - CapTypeException(CapTypeException&&) = default; - CapTypeException& operator=(CapTypeException&&) = default; - - CapTypeException(const CapTypeException&) = delete; - CapTypeException& operator=(const CapTypeException&) = delete; - - Capability& capability() noexcept{ - return m_cap; - } - - const Capability& capability() const noexcept{ - return m_cap; - } - - virtual const char* what() const noexcept override{ - return "Unexpected capability type."; - } - -private: - Capability m_cap; - -}; - -class Source; - -/// Convenience Capability wrapper class. -/// Guaranteed to contain the same capability type and item type -/// throughout the whole lifetime. -template -class Cap { - - friend class Source; - -public: - typedef typename Detail::Cap::DataType DataType; - static constexpr const Type twty = Detail::Cap::twty; - - /// Creates capability holding OneValue container. - /// \param value Initial value. - /// \throw std::bad_alloc - static Cap createOneValue(const DataType& value = DataType()){ - return Cap(Capability::createOneValue(value), 0); - } - - - /// Creates capability holding Array container. - /// \param size Number of elements in the array. - /// \throw std::bad_alloc - static Cap createArray(UInt32 size){ - return Cap(Capability::createArray(size), 0); - } - - /// Creates capability holding Array container. - /// \param values Initial values in the array. - /// \throw std::bad_alloc - static Cap createArray(std::initializer_list values){ - return Cap(Capability::createArray(values), 0); - } - - - /// Creates capability holding Enumeration container. - /// \param size Number of elements in the array. - /// \param currIndex Index of the currently selected item. - /// \param defIndex Index of the default item. - /// \throw std::bad_alloc - static Cap createEnumeration(UInt32 size, UInt32 currIndex = 0, UInt32 defIndex = 0){ - return Cap(Capability::createEnumeration(size, currIndex, defIndex), 0); - } - - /// Creates capability holding Enumeration container. - /// \param values Initial values in the array. - /// \param currIndex Index of the currently selected item. - /// \param defIndex Index of the default item. - /// \throw std::bad_alloc - static Cap createEnumeration(std::initializer_list values, UInt32 currIndex = 0, UInt32 defIndex = 0){ - return Cap(Capability::createEnumeration(values, currIndex, defIndex), 0); - } - - - /// Creates capability holding Range container. - /// \param min Minimal range value. - /// \param max Maximal range value. - /// \param step Size of a single step. - /// \param curr Current value. - /// \param def Default value. - /// \throw std::bad_alloc - static Cap createRange(DataType min, DataType max, DataType step, DataType curr, DataType def){ - return Cap(Capability::createRange(min, max, step, curr, def), 0); - } - - /// Creates capability of the supplied type without any data. - /// Useful for retrieving data from data source. - Cap() noexcept : m_cap(cap){} - - /// Converts Capability to Cap. - /// The capability ownership is taken over. - /// Capability type and item type checkings are performed. In case of exception, - /// the original Capability instance may be retrieved from the exception object. - /// \param capability Capability to be converted to Cap. - /// \throw CapTypeException When input capability type does not match the - /// capability type of this template class. - /// \throw CapItemTypeException When input capability item type does not match - /// the expected item type of the capability. - explicit Cap(Capability capability) : - m_cap(std::move(capability)){ - - checkTypes(); - } - - Cap(Cap&&) = default; - Cap& operator=(Cap&&) = default; - - Cap(const Cap&) = delete; - Cap& operator=(const Cap&) = delete; - - /// Capability type. - CapType type() const noexcept{ - return m_cap.type(); - } - - /// Container type. - ConType container() const noexcept{ - return m_cap.container(); - } - - /// Item type. - /// Valid only if the capability contains data. - /// \throw DataException When there is no data. - Type itemType() const{ - return m_cap.itemType(); - } - - operator bool() const noexcept{ - return m_cap; - } - - /// Contained OneValue container. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not OneValue. - /// \throw ItemTypeException When item type does not match. - OneValue oneValue(){ - return m_cap.oneValue(); - } - - /// Contained Array container. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Array. - /// \throw ItemTypeException When item type does not match. - Array array(){ - return m_cap.array(); - } - - /// Contained Enumeration container. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration. - /// \throw ItemTypeException When item type does not match. - Enumeration enumeration(){ - return m_cap.enumeration(); - } - - /// Contained Range container. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration. - /// \throw ItemTypeException When item type does not match. - Range range(){ - return m_cap.range(); - } - - - typedef Detail::CapData Data; - - /// Returns a data container for iterating over all possible values. - /// Use this only if you don't care about current or default values and container type. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is invalid. - /// \throw ItemTypeException When item type does not match. - Data data() const{ - return m_cap.data(); - } - - - /// Returns a copy of the current item of this capability. - /// Can be used only with Enumeration, OneValue, and Range containers. - /// \throw DataException When there is no data. - /// \throw ContainerException When container is not Enumeration, OneValue, nor Range. - /// \throw ItemTypeException When item type does not match. - DataType currentItem(){ - return m_cap.currentItem(); - } - - /// Moves out the contained Capability instance. - /// This instance becomes empty. - Capability toCapability() noexcept{ - return std::move(m_cap); - } - -private: - Cap(Capability capability, int) noexcept : - m_cap(std::move(capability)){} - - void checkTypes(){ - if (m_cap){ - if (m_cap.type() != cap){ - throw CapTypeException(std::move(m_cap)); - } - - if (m_cap.itemType() != twty){ - throw CapItemTypeException(std::move(m_cap)); - } - } - } - - Capability m_cap; - -}; - - -namespace Detail { - -/// \throw DataException -/// \throw ContainerException -/// \throw ItemTypeException -template // numeric = false -inline CapDataImpl::CapDataImpl(const Capability& cap) : - m_conType(cap.m_conType), m_data(cap.m_cont.get()){ - - static_assert(type != Type::DontCare, "type may not be DontCare"); - static_assert(sizeof(typename Detail::Twty::Type) == sizeof(DataType), "type sizes dont match"); - - if (!cap.m_cont){ - throw DataException(); - } - - switch (m_conType){ - case ConType::Array: - case ConType::Enumeration: - case ConType::OneValue: - break; - case ConType::Range: - default: - throw ContainerException(); - } - - if (type != cap.itemType()){ - throw ItemTypeException(); - } -} - -/// \throw DataException -/// \throw ContainerException -/// \throw ItemTypeException -template -inline CapDataImpl::CapDataImpl(const Capability& cap) : - m_conType(cap.m_conType), m_data(cap.m_cont.get()){ - - static_assert(type != Type::DontCare, "type may not be DontCare"); - static_assert(sizeof(typename Detail::Twty::Type) == sizeof(DataType), "type sizes dont match"); - - if (!cap.m_cont){ - throw DataException(); - } - - switch (m_conType){ - case ConType::Array: - case ConType::Enumeration: - case ConType::OneValue: - case ConType::Range: - break; - default: - throw ContainerException(); - } - - if (type != cap.itemType()){ - throw ItemTypeException(); - } -} - -/// \throw DataException -/// \throw ContainerException -/// \throw ItemTypeException -template // false -DataType CurrentItemImpl::item(Capability& cap){ - switch (cap.container()){ - case ConType::Enumeration: - return cap.enumeration().currentItem(); - - case ConType::OneValue: - return cap.oneValue().item(); - - default: - throw ContainerException(); - } -} - -/// \throw DataException -/// \throw ContainerException -/// \throw ItemTypeException -template -DataType CurrentItemImpl::item(Capability& cap){ - switch (cap.container()){ - case ConType::Enumeration: - return cap.enumeration().currentItem(); - - case ConType::OneValue: - return cap.oneValue().item(); - - case ConType::Range: - return cap.range().currentValue(); - - default: - throw ContainerException(); - } -} - -} - -} - -#endif // TWPP_DETAIL_FILE_CAPABILITY_HPP - diff --git a/twain/twain/twpp/cie.hpp b/twain/twain/twpp/cie.hpp deleted file mode 100644 index 2a1f641..0000000 --- a/twain/twain/twpp/cie.hpp +++ /dev/null @@ -1,269 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_CIE_HPP -#define TWPP_DETAIL_FILE_CIE_HPP - -#if 0 -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Part of CieColor structure. -class CiePoint { - -public: - /// Creates zero-initialized cie point. - constexpr CiePoint() noexcept : - m_x(), m_y(), m_z(){} - - /// Creates cie point with desired values. - constexpr CiePoint(Fix32 x, Fix32 y, Fix32 z) noexcept : - m_x(x), m_y(y), m_z(z){} - - /// X value of CIE space. - constexpr Fix32 x() const noexcept{ - return m_x; - } - - /// Y value of CIE space. - constexpr Fix32 y() const noexcept{ - return m_y; - } - - /// Z value of CIE space. - constexpr Fix32 z() const noexcept{ - return m_z; - } - - /// Sets x value of CIE space. - void setX(Fix32 x) noexcept{ - m_x = x; - } - - /// Sets y value of CIE space. - void setY(Fix32 y) noexcept{ - m_y = y; - } - - /// Sets z value of CIE space. - void setZ(Fix32 z) noexcept{ - m_z = z; - } - -private: - Fix32 m_x; - Fix32 m_y; - Fix32 m_z; - -}; - -/// Defines parameters for channel transformations. -/// Part of TransformStage. -class DecodeFunction { - -public: - /// Creates zero-initialized decode function. - constexpr DecodeFunction() noexcept{} - - /// Creates initialized decode function. - constexpr DecodeFunction( - Fix32 startIn, - Fix32 breakIn, - Fix32 endIn, - Fix32 startOut, - Fix32 breakOut, - Fix32 endOut, - Fix32 gamma, - Fix32 sampleCount - ) noexcept : - m_startIn(startIn), m_breakIn(breakIn), m_endIn(endIn), - m_startOut(startOut), m_breakOut(breakOut), m_endOut(endOut), - m_gamma(gamma), m_sampleCount(sampleCount){} - - /// Starting input value. - constexpr Fix32 startIn() const noexcept{ - return m_startIn; - } - - /// Sets starting input value. - void setStartIn(Fix32 startIn) noexcept{ - m_startIn = startIn; - } - - /// Ending input value. - constexpr Fix32 breakIn() const noexcept{ - return m_breakIn; - } - - /// Sets ending input value. - void setBreakIn(Fix32 breakIn) noexcept{ - m_breakIn = breakIn; - } - - /// Input value when to switch from linear to gamma transformation. - constexpr Fix32 endIn() const noexcept{ - return m_endIn; - } - - /// Sets input value when to switch from linear to gamma transformation. - void setEndIn(Fix32 endIn) noexcept{ - m_endIn = endIn; - } - - /// Starting output value. - constexpr Fix32 startOut() const noexcept{ - return m_startOut; - } - - /// Sets starting output value. - void setStartOut(Fix32 startOut) noexcept{ - m_startOut = startOut; - } - - /// Ending output value. - constexpr Fix32 breakOut() const noexcept{ - return m_breakOut; - } - - /// Sets ending output value. - void setBreakOut(Fix32 breakOut) noexcept{ - m_breakOut = breakOut; - } - - /// Output value when to switch from linear to gamma transformation. - constexpr Fix32 endOut() const noexcept{ - return m_endOut; - } - - /// Sets output value when to switch from linear to gamma transformation. - void setEndOut(Fix32 endOut) noexcept{ - m_endOut = endOut; - } - - /// Constant, exponential used in gamma funciton. - constexpr Fix32 gamma() const noexcept{ - return m_gamma; - } - - /// Sets constant, exponential used in gamma funciton. - void setGamma(Fix32 gamma) noexcept{ - m_gamma = gamma; - } - - /// Number of samples in lookup table. - constexpr Fix32 sampleCount() const noexcept{ - return m_sampleCount; - } - - /// Sets number of samples in lookup table. - void setSampleCount(Fix32 sampleCount) noexcept{ - m_sampleCount = sampleCount; - } - -private: - Fix32 m_startIn; - Fix32 m_breakIn; - Fix32 m_endIn; - Fix32 m_startOut; - Fix32 m_breakOut; - Fix32 m_endOut; - Fix32 m_gamma; - Fix32 m_sampleCount; - -}; - -/// Parameters of ABC or LMN transformations. -/// Refer to manual for more information about members. -class TransformStage { - -public: - typedef std::array Decode; - typedef std::array, 3> Mix; - - constexpr TransformStage() noexcept : - m_decode(), m_mix(){} - - constexpr TransformStage(const Decode& decode) noexcept : - m_decode(decode), m_mix(){} - - constexpr TransformStage(const Mix& mix) noexcept : - m_decode(), m_mix(mix){} - - constexpr TransformStage(const Decode& decode, const Mix& mix) noexcept : - m_decode(decode), m_mix(mix){} - - constexpr const Decode& decode() const noexcept{ - return m_decode; - } - - Decode& decode() noexcept{ - return m_decode; - } - - constexpr const Mix& mix() const noexcept{ - return m_mix; - } - - Mix& mix() noexcept{ - return m_mix; - } - -private: - Decode m_decode; - Mix m_mix; - -}; - -namespace Unsupported { - -// TODO CieColor -/// Cie color -/// Currently stub, more info required. -struct CieColor { - UInt16 m_colorSpace; - Bool m_lowEndian; - Bool m_deviceDependent; - Int32 m_versionNumber; - TransformStage m_stageAbc; - TransformStage m_stageLmn; - CiePoint m_whitePoint; - CiePoint m_blackPoint; - CiePoint m_whitePaper; - CiePoint m_blackInk; - Fix32 m_samples[1]; // <- how many elements? how to use? -}; - -} - -TWPP_DETAIL_PACK_END - -} -#endif - -#endif // TWPP_DETAIL_FILE_CIE_HPP - diff --git a/twain/twain/twpp/curveresponse.hpp b/twain/twain/twpp/curveresponse.hpp deleted file mode 100644 index e5d71f7..0000000 --- a/twain/twain/twpp/curveresponse.hpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_CURVERESPONSE_HPP -#define TWPP_DETAIL_FILE_CURVERESPONSE_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -namespace Detail { - -/// Base response class. -class CurveResponse { - -public: - CurveResponse() noexcept{} - - /// Creates a new (Rgb|Gray)Response with default elements, make sure that info.bitsPerPixel() is <= 8. - /// \throw RangeException When info.bitsPerPixel() is negative or greater than 8. - explicit CurveResponse(const ImageInfo& info) : CurveResponse(info.bitsPerPixel()){} - - /// Creates a new (Rgb|Gray)Response with default elements, make sure that bitsPerPixel is <= 8. - /// \throw RangeException When bitsPerPixel is negative or greater than 8. - explicit CurveResponse(Int16 bitsPerPixel){ - if (bitsPerPixel <= 0 || bitsPerPixel > 8){ - throw RangeException(); - } - - UInt16 size = 1 << static_cast(bitsPerPixel); - m_data.reset(new Element8[size]); - for (UInt16 i = 0; i < size; i++){ - m_data[i] = Element8(static_cast(i)); // 0..255 max - } - } - - /// Array of size `2^ImageInfo.bitesPerPixel()`, up to 256 elements (2^8) - Element8* data() noexcept{ - return m_data.get(); - } - - /// Array of size `2^ImageInfo.bitesPerPixel()`, up to 256 elements (2^8) - const Element8* data() const noexcept{ - return m_data.get(); - } - -private: - std::unique_ptr m_data; - -}; - -} - -/// Rgb response class. -class RgbResponse : public Detail::CurveResponse { - -public: - RgbResponse() noexcept{} - - /// Creates a new RgbResponse with default elements, make sure that info.bitesPerPixel() is <= 8. - /// \throw RangeException When info.bitsPerPixel() is negative or greater than 8. - explicit RgbResponse(const ImageInfo& info) : - Detail::CurveResponse(info) {} - - /// Creates a new RgbResponse with default elements, make sure that bitsPerPixel is <= 8. - /// \throw RangeException When bitsPerPixel is negative or greater than 8. - explicit RgbResponse(Int16 bitsPerPixel) : - Detail::CurveResponse(bitsPerPixel) {} - -}; - -/// Gray response class. -class GrayResponse : public Detail::CurveResponse { - -public: - GrayResponse() noexcept{} - - /// Creates a new GrayResponse with default elements, make sure that info.bitesPerPixel() is <= 8. - /// \throw RangeException When info.bitsPerPixel() is negative or greater than 8. - explicit GrayResponse(const ImageInfo& info) : - Detail::CurveResponse(info) {} - - /// Creates a new GrayResponse with default elements, make sure that bitsPerPixel is <= 8. - /// \throw RangeException When bitsPerPixel is negative or greater than 8. - explicit GrayResponse(Int16 bitsPerPixel) : - Detail::CurveResponse(bitsPerPixel) {} - -}; - -} - -#endif // TWPP_DETAIL_FILE_CURVERESPONSE_HPP - diff --git a/twain/twain/twpp/customdata.hpp b/twain/twain/twpp/customdata.hpp deleted file mode 100644 index fb3e004..0000000 --- a/twain/twain/twpp/customdata.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_CUSTOMDATA_HPP -#define TWPP_DETAIL_FILE_CUSTOMDATA_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Structure for sending custom data to source or application. -class CustomData { - -public: - template - using Data = typename Detail::Lock; - - /// Creates empty custom data. - CustomData() noexcept : - m_size(0), m_handle(){} - - /// Creates custom data with allocated memory. - /// \throw std::bad_alloc - explicit CustomData(UInt32 size) : - m_size(size), m_handle(Detail::alloc(size)){} - - /// Locks and returns pointer to custom data memory. - template - Data lock() const noexcept{ - return Data(m_handle.get()); - } - - /// The size of contained memory block. - UInt32 size() const noexcept{ - return m_size; - } - -private: - UInt32 m_size; - Detail::UniqueHandle m_handle; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_CUSTOMDATA_HPP diff --git a/twain/twain/twpp/datasource.hpp b/twain/twain/twpp/datasource.hpp deleted file mode 100644 index 85d82bb..0000000 --- a/twain/twain/twpp/datasource.hpp +++ /dev/null @@ -1,2225 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015-2018 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_DATASOURCE_HPP -#define TWPP_DETAIL_FILE_DATASOURCE_HPP - -#include "../twpp.hpp" - -namespace Twpp { - - namespace Detail { - - TWPP_DETAIL_PACK_BEGIN - struct AppCapability { - - CapType m_cap; - ConType m_conType; - Handle m_cont; - - }; - TWPP_DETAIL_PACK_END - - struct DoNotFreeHandle { - - DoNotFreeHandle(Handle handle) { - Detail::GlobalMemFuncs::doNotFreeHandle = handle; - } - - ~DoNotFreeHandle() { - Detail::GlobalMemFuncs::doNotFreeHandle = Handle(); - } - - }; - - } - -#define TWPP_ENTRY(SourceClass)\ - extern "C" TWPP_DETAIL_EXPORT Twpp::ReturnCode TWPP_DETAIL_CALLSTYLE \ - DS_Entry(Twpp::Identity* origin, Twpp::DataGroup dg, Twpp::Dat dat, Twpp::Msg msg, void* data){\ - static_assert(\ - std::is_base_of, SourceClass>::value ||\ - std::is_base_of, SourceClass>::value,\ - "Class " #SourceClass " is not derived from SourceFromThis."\ - );\ - return SourceClass::entry(origin, dg, dat, msg, data);\ - } - - /// Result of a data source operation. - /// Contains both return code and status. - class Result { - - public: - /// Creates successful result. - constexpr Result() noexcept : - m_status(), m_rc(ReturnCode::Success) {} - - /// Creates result with supplied return code and status. - constexpr Result(ReturnCode rc, Status status) noexcept : - m_status(status), m_rc(rc) {} - - /// Status part of the result. - constexpr Status status() const noexcept { - return m_status; - } - - /// Return code part of the result. - constexpr ReturnCode returnCode() const noexcept { - return m_rc; - } - - /// Sets status part of the result. - void setStatus(Status status) noexcept { - m_status = status; - } - - /// Sets return code part of the result. - void setReturnCode(ReturnCode rc) noexcept { - m_rc = rc; - } - - constexpr operator ReturnCode() const noexcept { - return m_rc; - } - - constexpr operator Status() const noexcept { - return m_status; - } - - private: - Status m_status; - ReturnCode m_rc; - - }; - - static constexpr inline bool success(const Result& res) noexcept { - return success(res.returnCode()); - } - - - namespace Detail { - - template // false - struct StaticCustomBaseProc { - Result operator()(Dat, Msg, void*) { - return { ReturnCode::Failure, ConditionCode::BadProtocol }; - } - }; - - template - struct StaticCustomBaseProc { - Result operator()(Dat dat, Msg msg, void* data) { - return Derived::staticCustomBase(dat, msg, data); - } - }; - - TWPP_DETAIL_CREATE_HAS_STATIC_METHOD(defaultIdentity) - TWPP_DETAIL_CREATE_HAS_STATIC_METHOD(staticCustomBase) - - } - - namespace SourceFromThisProcs { - - /// Returns data source identity not associated with any instance. - const Identity& defaultIdentity(); - - /// Processes custom TWAIN operations without having any opened connection. - /// DataGroup is always Control. - /// \param dat Type of data. Dat::CustomBase + X. - /// \param msg Message, action to perform. - /// \param data The data, may be null. - /// \return Operation result code. - Result staticCustomBase(Dat dat, Msg msg, void* data); - - } - - /// Base class of a TWAIN data source. - /// It handles instances creation and all static calls. - /// - /// The derived class must: - /// 1) Implement at least all pure virtual methods. - /// 2) Provide `static const Identity& defaultIdentity()`. - /// 3) If hasStaticCustomBaseProc == true, provide - /// `static Result staticCustomBase(Dat dat, Msg msg, void* data)`. - /// - /// After defining your source class, do not forget to use macro - /// TWPP_ENTRY() - /// where the name is a literal, not string: - /// - /// TWPP_ENTRY(Source) // <- no semicolon required - /// \tparam Derived The class inheriting from this. - /// \tparam hasStaticCustomBaseProc {Whether the Derived - /// class handles static custom base operations, see above.} - template - class SourceFromThis { - - public: - SourceFromThis(const SourceFromThis&) = delete; - SourceFromThis& operator=(const SourceFromThis&) = delete; - - SourceFromThis(SourceFromThis&&) = delete; - SourceFromThis& operator=(SourceFromThis&&) = delete; - - virtual ~SourceFromThis() noexcept = default; - - protected: - /// Creates closed instance. - constexpr SourceFromThis() noexcept : - m_lastStatus(ConditionCode::Bummer), m_state(DsState::Closed) {} - - /// The last TWAIN status. - Status lastStatus() const noexcept { - return m_lastStatus; - } - - /// Current TWAIN state. - DsState state() const noexcept { - return m_state; - } - - /// Whether the source is in the supplied TWAIN state. - bool inState(DsState state) const noexcept { - return m_state == state; - } - - /// Whether the source is between min and max states (both inclusive). - bool inState(DsState min, DsState max) const noexcept { - return m_state >= min && m_state <= max; - } - - /// Whether there exists an enabled source. - static bool hasEnabled() noexcept { - for (auto& src : g_sources) { - if (src.inState(DsState::Enabled, DsState::Xferring)) { - return true; - } - } - - return false; - } - - /// Source identity. - const Identity& sourceIdentity() const noexcept { - return m_srcId; - } - - /// Identity of the application that opened the source. - const Identity& applicationIdentity() const noexcept { - return m_appId; - } - - /// Sets current TWAIN state, use with care. - void setState(DsState state) noexcept { - m_state = state; - } - - /// Sets current source identity, use with care. - void setSourceIdentity(const Identity& sourceIdentity) noexcept { - m_srcId = sourceIdentity; - } - - /// Sets current application identity, use with care. - void setApplicationIdentity(const Identity& appIdentity) noexcept { - m_appId = appIdentity; - } - - /// Shortcut for Result(RC::Success, CC::Success). - static constexpr Result success() noexcept { - return { ReturnCode::Success, ConditionCode::Success }; - } - - /// Shortcut for Result(RC::Failure, CC::BadValue). - static constexpr Result badValue() noexcept { - return { ReturnCode::Failure, ConditionCode::BadValue }; - } - - /// Shortcut for Result(RC::Failure, CC::BadProtocol). - static constexpr Result badProtocol() noexcept { - return { ReturnCode::Failure, ConditionCode::BadProtocol }; - } - - /// Shortcut for Result(RC::Failure, CC::SeqError). - static constexpr Result seqError() noexcept { - return { ReturnCode::Failure, ConditionCode::SeqError }; - } - - /// Shortcut for Result(RC::Failure, CC::CapBadOperation). - static constexpr Result capBadOperation() noexcept { - return { ReturnCode::Failure, ConditionCode::CapBadOperation }; - } - - /// Shortcut for Result(RC::Failure, CC::CapUnsupported). - static constexpr Result capUnsupported() noexcept { - return { ReturnCode::Failure, ConditionCode::CapUnsupported }; - } - - /// Shortcut for Result(RC::Failure, CC::Bummber). - static constexpr Result bummer() noexcept { - return { ReturnCode::Failure, ConditionCode::Bummer }; - } - - - /// Notifies application about clicking on OK button. - ReturnCode notifyCloseOk() noexcept { - return notifyApp(Msg::CloseDsOk); - } - - /// Notifies application about clicking on Cancel button. - ReturnCode notifyCloseCancel() noexcept { - return notifyApp(Msg::CloseDsReq); - } - - /// Notifies application about a device event. - ReturnCode notifyDeviceEvent() noexcept { - return notifyApp(Msg::DeviceEvent); - } - - /// Notifies application about ready transfer (after clicking scan button is GUI is shown). - ReturnCode notifyXferReady() noexcept { - return notifyApp(Msg::XferReady); - } - - /// Notifies application scanning complete with no image got - added on 2022-07-02 - ReturnCode notifyEndWithoutImages() noexcept { - return notifyApp(Msg::Null); - } - - - - /// Root of source TWAIN calls. - /// \param origin Identity of the caller. - /// \param dg Data group of the call. - /// \param dat Type of data. - /// \param msg Message, action to perform. - /// \param data The data, may be null. - virtual Result call(const Identity& origin, DataGroup dg, Dat dat, Msg msg, void* data) { - switch (dg) { - case DataGroup::Control: - return control(origin, dat, msg, data); - - case DataGroup::Image: - return image(origin, dat, msg, data); - - case DataGroup::Audio: - return audio(origin, dat, msg, data); - - default: - return badProtocol(); - - } - } - - /// Root of source control TWAIN calls. - /// \param origin Identity of the caller. - /// \param dat Type of data. - /// \param msg Message, action to perform. - /// \param data The data, may be null. - virtual Result control(const Identity& origin, Dat dat, Msg msg, void* data) { - if (!data) { - // all control triplets require data - return badValue(); - } - - switch (dat) { - case Dat::Capability: - return capability(origin, msg, *static_cast(data)); - case Dat::CustomData: - return customData(origin, msg, *static_cast(data)); - case Dat::DeviceEvent: - return deviceEvent(origin, msg, *static_cast(data)); - case Dat::Event: // Windows only - return event(origin, msg, *static_cast(data)); - case Dat::FileSystem: - return fileSystem(origin, msg, *static_cast(data)); - case Dat::Identity: - return identity(origin, msg, *static_cast(data)); - case Dat::PassThrough: - return passThrough(origin, msg, *static_cast(data)); - case Dat::PendingXfers: - return pendingXfers(origin, msg, *static_cast(data)); - case Dat::SetupFileXfer: - return setupFileXfer(origin, msg, *static_cast(data)); - case Dat::SetupMemXfer: - return setupMemXfer(origin, msg, *static_cast(data)); - case Dat::Status: - return status(origin, msg, *static_cast(data)); - case Dat::StatusUtf8: - return statusUtf8(origin, msg, *static_cast(data)); - case Dat::UserInterface: - return userInterface(origin, msg, *static_cast(data)); - case Dat::XferGroup: { - return xferGroup(origin, msg, *static_cast(data)); - } - default: - return badProtocol(); - } - } - - /// Capability TWAIN call. - /// Reset, set and set constraint operations are limited to - /// state DsState::Open (4), override this method if you - /// support CapType::ExtendedCaps. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Capability data. - virtual Result capability(const Identity& origin, Msg msg, Capability& data) { - switch (msg) { - case Msg::Get: - // 4 - 7 - return capabilityGet(origin, data); - - case Msg::GetCurrent: - // 4 - 7 - return capabilityGetCurrent(origin, data); - - case Msg::GetDefault: - // 4 - 7 - return capabilityGetDefault(origin, data); - - case Msg::GetHelp: - if (!inState(DsState::Open)) { - return seqError(); - } - - return capabilityGetHelp(origin, data); - - case Msg::GetLabel: - if (!inState(DsState::Open)) { - return seqError(); - } - - return capabilityGetLabel(origin, data); - - case Msg::GetLabelEnum: - if (!inState(DsState::Open)) { - return seqError(); - } - - return capabilityGetLabelEnum(origin, data); - - case Msg::QuerySupport: - // 4 - 7 - return capabilityQuerySupport(origin, data); - - case Msg::Reset: - // 4, extended: 5, 6, 7 - if (!inState(DsState::Open)) { - return seqError(); - } - - return capabilityReset(origin, data); - - case Msg::ResetAll: - if (!inState(DsState::Open)) { - return seqError(); - } - - return capabilityResetAll(origin); // data has no meaning here - - case Msg::Set: - // 4, extended: 5, 6, 7 - if (!inState(DsState::Open)) { - return seqError(); - } - - if (!data) { - return badValue(); - } - - return capabilitySet(origin, data); - - case Msg::SetConstraint: - // 4, extended: 5, 6, 7 - if (!inState(DsState::Open)) { - return seqError(); - } - - if (!data) { - return badValue(); - } - - return capabilitySetConstraint(origin, data); - - default: - return badProtocol(); - } - } - - /// Get capability TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Capability data. - virtual Result capabilityGet(const Identity& origin, Capability& data) = 0; - - /// Get current capability TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Capability data. - virtual Result capabilityGetCurrent(const Identity& origin, Capability& data) = 0; - - /// Get default capability TWAIN call. - /// \param origin Identity of the caller. - /// \param data Capability data. - virtual Result capabilityGetDefault(const Identity& origin, Capability& data) = 0; - - /// Get help capability TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Capability data. - virtual Result capabilityGetHelp(const Identity& origin, Capability& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Get label capability TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Capability data. - virtual Result capabilityGetLabel(const Identity& origin, Capability& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Get label enum capability TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Capability data. - virtual Result capabilityGetLabelEnum(const Identity& origin, Capability& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Query support capability TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Capability data. - virtual Result capabilityQuerySupport(const Identity& origin, Capability& data) = 0; - - /// Reset capability TWAIN call. - /// Always called in correct state: 4, if you support extended - /// capabilities, override `capability` method. - /// \param origin Identity of the caller. - /// \param data Capability data. - virtual Result capabilityReset(const Identity& origin, Capability& data) = 0; - - /// Reset all capability TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - virtual Result capabilityResetAll(const Identity& origin) = 0; - - /// Set capability TWAIN call. - /// Always called in correct state: 4, if you support extended - /// capabilities, override `capability` method. - /// \param origin Identity of the caller. - /// \param data Capability data. - virtual Result capabilitySet(const Identity& origin, Capability& data) = 0; - - /// Set capability TWAIN call. - /// Always called in correct state: 4, if you support extended - /// capabilities, override `capability` method. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Capability data. - virtual Result capabilitySetConstraint(const Identity& origin, Capability& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - - - /// Custom data TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Custom data. - virtual Result customData(const Identity& origin, Msg msg, CustomData& data) { - if (!inState(DsState::Open)) { - return seqError(); - } - - switch (msg) { - case Msg::Get: - return customDataGet(origin, data); - - case Msg::Set: - return customDataSet(origin, data); - - default: - return badProtocol(); - } - } - - /// Get custom data TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Custom data. - virtual Result customDataGet(const Identity& origin, CustomData& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Set custom data TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Custom data. - virtual Result customDataSet(const Identity& origin, CustomData& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Device event TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Device event data. - virtual Result deviceEvent(const Identity& origin, Msg msg, DeviceEvent& data) { - if (msg != Msg::Get) { - return badProtocol(); - } - - return deviceEventGet(origin, data); - } - - /// Get device event TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Device event data. - virtual Result deviceEventGet(const Identity& origin, DeviceEvent& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - - - /// Event TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Event data. - virtual Result event(const Identity& origin, Msg msg, Event& data) { - if (msg != Msg::ProcessEvent) { - return badProtocol(); - } - - if (!inState(DsState::Enabled, DsState::Xferring)) { - return seqError(); - } - return eventProcess(origin, data); - } - -#if defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_MAC) - /// Process event TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Event data. - virtual Result eventProcess(const Identity& origin, Event& data) = 0; -#elif defined(TWPP_DETAIL_OS_LINUX) - /// Process event TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Event data. - virtual Result eventProcess(const Identity& origin, Event& data) { - Detail::unused(origin, data); - return badProtocol(); - } -#else -# error "eventProcess for your platform here" -#endif - - /// Identity TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Identity data. - virtual Result identity(const Identity& origin, Msg msg, Identity& data) { - Result rc; - switch (msg) { - case Msg::Get: - // any state - data = sourceIdentity(); - return success(); - - case Msg::OpenDs: { - if (!inState(DsState::Closed)) { - return seqError(); - } - - setSourceIdentity(data); - setApplicationIdentity(origin); - rc = identityOpenDs(origin); - if (Twpp::success(rc)) { - setState(DsState::Open); - } - - return rc; - } - - case Msg::CloseDs: { - if (inState(DsState::Enabled)) { - setState(DsState::Open); - } - if (!inState(DsState::Open)) { - return seqError(); - } - - rc = identityCloseDs(origin); - if (Twpp::success(rc)) { - setState(DsState::Closed); - } - - return rc; - } - - default: - return badProtocol(); - } - } - - /// Open source identity TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - virtual Result identityOpenDs(const Identity& origin) = 0; - - /// Close source identity TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - virtual Result identityCloseDs(const Identity& origin) = 0; - - /// File system TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data File system data. - virtual Result fileSystem(const Identity& origin, Msg msg, FileSystem& data) { - switch (msg) { - case Msg::AutomaticCaptureDir: - if (!inState(DsState::Open)) { - return seqError(); - } - - return fileSystemAutomatic(origin, data); - - case Msg::ChangeDir: - if (!inState(DsState::Open)) { - return seqError(); - } - - return fileSystemChange(origin, data); - - case Msg::Copy: - if (!inState(DsState::Open)) { - return seqError(); - } - - return fileSystemCopy(origin, data); - - case Msg::CreateDir: - if (!inState(DsState::Open)) { - return seqError(); - } - - return fileSystemCreate(origin, data); - - case Msg::Delete: - if (!inState(DsState::Open)) { - return seqError(); - } - - return fileSystemDelete(origin, data); - - case Msg::FormatMedia: - if (!inState(DsState::Open)) { - return seqError(); - } - - return fileSystemFormat(origin, data); - - case Msg::GetClose: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return fileSystemGetClose(origin, data); - - case Msg::GetFirstFile: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return fileSystemGetFirst(origin, data); - - case Msg::GetInfo: - // 4 - 7 - return fileSystemGetInfo(origin, data); - - case Msg::GetNextFile: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return fileSystemGetNext(origin, data); - - case Msg::Rename: - if (!inState(DsState::Open)) { - return seqError(); - } - - return fileSystemRename(origin, data); - - default: - return badProtocol(); - } - } - - /// Automatic capture directory file system TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data File system data. - virtual Result fileSystemAutomatic(const Identity& origin, FileSystem& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Change directory file system TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data File system data. - virtual Result fileSystemChange(const Identity& origin, FileSystem& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - - /// Copy file system TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data File system data. - virtual Result fileSystemCopy(const Identity& origin, FileSystem& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Create directory file system TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data File system data. - virtual Result fileSystemCreate(const Identity& origin, FileSystem& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Delete file system TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data File system data. - virtual Result fileSystemDelete(const Identity& origin, FileSystem& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Format media file system TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data File system data. - virtual Result fileSystemFormat(const Identity& origin, FileSystem& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Get close file system TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data File system data. - virtual Result fileSystemGetClose(const Identity& origin, FileSystem& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Get first file file system TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data File system data. - virtual Result fileSystemGetFirst(const Identity& origin, FileSystem& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Get info file system TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data File system data. - virtual Result fileSystemGetInfo(const Identity& origin, FileSystem& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Get next file file system TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data File system data. - virtual Result fileSystemGetNext(const Identity& origin, FileSystem& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Rename file system TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data File system data. - virtual Result fileSystemRename(const Identity& origin, FileSystem& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - - /// Pass through TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Pass through data. - virtual Result passThrough(const Identity& origin, Msg msg, PassThrough& data) { - if (msg != Msg::PassThrough) { - return badProtocol(); - } - - // 4 - 7 - return passThroughPass(origin, data); - } - - /// Pass through pass through TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Pass through data. - virtual Result passThroughPass(const Identity& origin, PassThrough& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Pending xfers TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Pending xfers data. - virtual Result pendingXfers(const Identity& origin, Msg msg, PendingXfers& data) { - switch (msg) { - case Msg::EndXfer: { - if (!inState(DsState::XferReady, DsState::Xferring)) { - return seqError(); - } - - auto rc = pendingXfersEnd(origin, data); - if (Twpp::success(rc)) { - DataGroup xferGroup = DataGroup::Image; - if (!Twpp::success(this->xferGroup(origin, Msg::Get, xferGroup))) { - xferGroup = DataGroup::Image; - } - - if (xferGroup == DataGroup::Audio) { - setState(DsState::XferReady); - } - else { - //setState(data.count() ? DsState::XferReady : DsState::Enabled); - setState(data.count() ? DsState::XferReady : DsState::Enabled); - } - } - - return rc; - } - - - case Msg::Reset: { - if (!inState(DsState::XferReady)) { - return seqError(); - } - - auto rc = pendingXfersReset(origin, data); - if (Twpp::success(rc)) { - DataGroup xferGroup = DataGroup::Image; - if (!Twpp::success(this->xferGroup(origin, Msg::Get, xferGroup))) { - xferGroup = DataGroup::Image; - } - - if (xferGroup != DataGroup::Audio) { - setState(DsState::Enabled); - } - } - - return rc; - } - - case Msg::StopFeeder: - if (!inState(DsState::XferReady)) { - return seqError(); - } - - return pendingXfersStopFeeder(origin, data); - - case Msg::Get: - if (!inState(DsState::Open, DsState::Xferring)) { - return seqError(); - } - - return pendingXfersGet(origin, data); - - default: - return badProtocol(); - } - } - - /// Get pending xfers TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Pending xfers data. - virtual Result pendingXfersGet(const Identity& origin, PendingXfers& data) = 0; - - /// End xfer pending xfers TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Pending xfers data. - virtual Result pendingXfersEnd(const Identity& origin, PendingXfers& data) = 0; - - /// Reset xfers pending xfers TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Pending xfers data. - virtual Result pendingXfersReset(const Identity& origin, PendingXfers& data) = 0; - - /// Stop feeder pending xfers TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Pending xfers data. - virtual Result pendingXfersStopFeeder(const Identity& origin, PendingXfers& data) = 0; - - /// Setup file xfer TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Setup file xfer data. - virtual Result setupFileXfer(const Identity& origin, Msg msg, SetupFileXfer& data) { - switch (msg) { - case Msg::Get: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return setupFileXferGet(origin, data); - - case Msg::GetDefault: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return setupFileXferGetDefault(origin, data); - - case Msg::Set: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return setupFileXferSet(origin, data); - - case Msg::Reset: - if (!inState(DsState::Open)) { - return seqError(); - } - - return setupFileXferReset(origin, data); - - default: - return badProtocol(); - } - } - - /// Get setup file xfer TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Setup file xfer data. - virtual Result setupFileXferGet(const Identity& origin, SetupFileXfer& data) = 0; - - /// Get default setup file xfer TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Setup file xfer data. - virtual Result setupFileXferGetDefault(const Identity& origin, SetupFileXfer& data) = 0; - - /// Set setup file xfer TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Setup file xfer data. - virtual Result setupFileXferSet(const Identity& origin, SetupFileXfer& data) = 0; - - /// Reset setup file xfer TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Setup file xfer data. - virtual Result setupFileXferReset(const Identity& origin, SetupFileXfer& data) = 0; - - /// Setup memory xfer TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Setup memory xfer data. - virtual Result setupMemXfer(const Identity& origin, Msg msg, SetupMemXfer& data) { - if (msg != Msg::Get) { - return badProtocol(); - } - - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return setupMemXferGet(origin, data); - } - - /// Get setup memory xfer TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Setup memory xfer data. - virtual Result setupMemXferGet(const Identity& origin, SetupMemXfer& data) = 0; - - /// Status TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Status data. - virtual Result status(const Identity& origin, Msg msg, Status& data) { - if (msg != Msg::Get) { - return badProtocol(); - } - - return statusGet(origin, data); - } - - /// Get status TWAIN call. - /// Always called in correct state. - /// Default implementation returns last status. - /// \param origin Identity of the caller. - /// \param data Status data. - virtual Result statusGet(const Identity& origin, Status& data) { - Detail::unused(origin); - data = lastStatus(); - return success(); - } - - /// Status utf8 TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Status utf8 data. - virtual Result statusUtf8(const Identity& origin, Msg msg, StatusUtf8& data) { - if (msg != Msg::Get) { - return badProtocol(); - } - - // 3 - 7 - return statusUtf8Get(origin, data); - } - - /// Get status utf8 TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Status utf8 data. - virtual Result statusUtf8Get(const Identity& origin, StatusUtf8& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// User interface TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data User interface data. - virtual Result userInterface(const Identity& origin, Msg msg, UserInterface& data) { - Result rc; - switch (msg) { - case Msg::DisableDs: - if (!inState(DsState::Enabled)) { - setState(DsState::Enabled); - } - - rc = userInterfaceDisable(origin, data); - if (Twpp::success(rc)) { - setState(DsState::Open); - } - - return rc; - - case Msg::EnableDs: - if (!inState(DsState::Open) || hasEnabled()) { // only a single source can be enabled at any given time - return seqError(); - } - - rc = userInterfaceEnable(origin, data); - if (Twpp::success(rc) || rc == ReturnCode::CheckStatus) { - if (inState(DsState::Open)) { // allow userInterfaceEnable to transfer to higher states - setState(DsState::Enabled); - //if(!data.showUi()) - // notifyXferReady(); - } - } - - return rc; - - case Msg::EnableDsUiOnly: - if (!inState(DsState::Open)) { - return seqError(); - } - - rc = userInterfaceEnableUiOnly(origin, data); - if (Twpp::success(rc)) { - setState(DsState::Enabled); - } - - return rc; - - default: - return badProtocol(); - } - } - - /// Disable user interface TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data User interface data. - virtual Result userInterfaceDisable(const Identity& origin, UserInterface& data) = 0; - - /// Enable user interface TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data User interface data. - virtual Result userInterfaceEnable(const Identity& origin, UserInterface& data) = 0; - - /// Enable UI only user interface TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data User interface data. - virtual Result userInterfaceEnableUiOnly(const Identity& origin, UserInterface& data) = 0; - - /// Xfer group TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Xfer group data. - virtual Result xferGroup(const Identity& origin, Msg msg, DataGroup& data) { - switch (msg) { - case Msg::Get: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return xferGroupGet(origin, data); - - case Msg::Set: - if (!inState(DsState::XferReady)) { - return seqError(); - } - - return xferGroupSet(origin, data); - - default: - return badProtocol(); - } - } - - /// Get xfer group TWAIN call. - /// Always called in correct state. - /// Default implementation returns DataGroup::Image. - /// \param origin Identity of the caller. - /// \param data Xfer group data. - virtual Result xferGroupGet(const Identity& origin, DataGroup& data) { - Detail::unused(origin); - data = DataGroup::Image; - return success(); - } - - /// Set xfer group TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Xfer group data. - virtual Result xferGroupSet(const Identity& origin, DataGroup& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Root of source image TWAIN calls. - /// - /// Special data to type casts: - /// ExtImageInfo: reinterpret_cast(data) - /// GrayResponse: reinterpret_cast(data) - /// RgbResponse: reinterpret_cast(data) - /// - /// \param origin Identity of the caller. - /// \param dat Type of data. - /// \param msg Message, action to perform. - /// \param data The data, may be null. - virtual Result image(const Identity& origin, Dat dat, Msg msg, void* data) { - if (dat != Dat::ImageFileXfer && !data) { - return badValue(); - } - - switch (dat) { - // TODO CieColor - /*case Dat::CieColor: - return cieColor(origin, msg, *static_cast(data));*/ - case Dat::ExtImageInfo: - return extImageInfo(origin, msg, reinterpret_cast(data)); // ExtImageInfo is simply a `pointer to TW_EXTIMAGEINFO` - case Dat::GrayResponse: - return grayResponse(origin, msg, reinterpret_cast(data)); // GrayResponse is simply a `pointer to TW_GRAYRESPONSE` - case Dat::IccProfile: - return iccProfile(origin, msg, *static_cast(data)); - case Dat::ImageFileXfer: - return imageFileXfer(origin, msg); - case Dat::ImageInfo: - return imageInfo(origin, msg, *static_cast(data)); - case Dat::ImageLayout: - return imageLayout(origin, msg, *static_cast(data)); - case Dat::ImageMemFileXfer: - return imageMemFileXfer(origin, msg, *static_cast(data)); - case Dat::ImageMemXfer: - return imageMemXfer(origin, msg, *static_cast(data)); - case Dat::ImageNativeXfer: - return imageNativeXfer(origin, msg, *static_cast(data)); - case Dat::JpegCompression: - return jpegCompression(origin, msg, *static_cast(data)); - case Dat::Palette8: - return palette8(origin, msg, *static_cast(data)); - case Dat::RgbResponse: - return rgbResponse(origin, msg, reinterpret_cast(data)); // RgbResponse is simply a `pointer to TW_RGBRESPONSE` - default: - return badProtocol(); - } - } - - // TODO CieColor - /* - /// Cie color TWAIN call. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Cie color data. - virtual Result cieColor(const Identity& origin, Msg msg, CieColor& data){ - Detail::unused(origin, msg, data); - return badProtocol(); - }*/ - - /// Ext image info TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Ext image info data. - virtual Result extImageInfo(const Identity& origin, Msg msg, ExtImageInfo& data) { - if (msg != Msg::Get) { - return badProtocol(); - } - - if (!inState(DsState::Xferring)) { - return seqError(); - } - - return extImageInfoGet(origin, data); - } - - /// Get ext image info TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Ext image info data. - virtual Result extImageInfoGet(const Identity& origin, ExtImageInfo& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Gray response TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Gray response data. - virtual Result grayResponse(const Identity& origin, Msg msg, GrayResponse& data) { - if (!inState(DsState::Open)) { - return seqError(); - } - - switch (msg) { - case Msg::Set: - return grayResponseSet(origin, data); - - case Msg::Reset: - return grayResponseReset(origin, data); - - default: - return badProtocol(); - } - } - - /// Set gray response TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Gray response data. - virtual Result grayResponseSet(const Identity& origin, GrayResponse& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Reset gray response TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Gray response data. - virtual Result grayResponseReset(const Identity& origin, GrayResponse& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// ICC profile TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data ICC profile data. - virtual Result iccProfile(const Identity& origin, Msg msg, IccProfileMemory& data) { - if (msg != Msg::Get) { - return badProtocol(); - } - - if (!inState(DsState::XferReady, DsState::Xferring)) { - return seqError(); - } - - return iccProfileGet(origin, data); - } - - /// Get ICC profile TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data ICC profile data. - virtual Result iccProfileGet(const Identity& origin, IccProfileMemory& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Image file xfer TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - virtual Result imageFileXfer(const Identity& origin, Msg msg) { - if (msg != Msg::Get) { - return badProtocol(); - } - - if (!inState(DsState::XferReady)) { - return seqError(); - } - - auto rc = imageFileXferGet(origin); - if (rc == ReturnCode::XferDone) { - setState(DsState::Xferring); - } - - return rc; - } - - /// Get image file xfer TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// Always called in correct state. - /// \param origin Identity of the caller. - virtual Result imageFileXferGet(const Identity& origin) = 0; - - /// Image info TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Image info data. - virtual Result imageInfo(const Identity& origin, Msg msg, ImageInfo& data) { - if (msg != Msg::Get) { - return badProtocol(); - } - - if (!inState(DsState::XferReady, DsState::Xferring)) { - return seqError(); - } - - return imageInfoGet(origin, data); - } - - /// Get image info TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Image info data. - virtual Result imageInfoGet(const Identity& origin, ImageInfo& data) = 0; - - - /// Image layout TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Image layout data. - virtual Result imageLayout(const Identity& origin, Msg msg, ImageLayout& data) { - switch (msg) { - case Msg::Get: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return imageLayoutGet(origin, data); - - case Msg::GetDefault: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return imageLayoutGetDefault(origin, data); - - case Msg::Set: - if (!inState(DsState::Open)) { - return seqError(); - } - - return imageLayoutSet(origin, data); - - case Msg::Reset: - if (!inState(DsState::Open)) { - return seqError(); - } - - return imageLayoutReset(origin, data); - - default: - return badProtocol(); - } - } - - /// Get image layout TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Image layout data. - virtual Result imageLayoutGet(const Identity& origin, ImageLayout& data) = 0; - - /// Get default image layout TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Image layout data. - virtual Result imageLayoutGetDefault(const Identity& origin, ImageLayout& data) = 0; - - /// Set image layout TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Image layout data. - virtual Result imageLayoutSet(const Identity& origin, ImageLayout& data) = 0; - - /// Reset image layout TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Image layout data. - virtual Result imageLayoutReset(const Identity& origin, ImageLayout& data) = 0; - - - /// Image memory file xfer TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Image memory file xfer data. - virtual Result imageMemFileXfer(const Identity& origin, Msg msg, ImageMemFileXfer& data) { - if (msg != Msg::Get) { - return badProtocol(); - } - - if (!inState(DsState::XferReady)) { - return seqError(); - } - - auto rc = imageMemFileXferGet(origin, data); - if (rc == ReturnCode::XferDone) { - setState(DsState::Xferring); - } - - return rc; - } - - /// Get image memory file xfer TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Image memory file xfer data. - virtual Result imageMemFileXferGet(const Identity& origin, ImageMemFileXfer& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Image memory xfer TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Image memory xfer data. - virtual Result imageMemXfer(const Identity& origin, Msg msg, ImageMemXfer& data) { - if (msg != Msg::Get) { - return badProtocol(); - } - - if (!inState(DsState::XferReady, DsState::Xferring)) { - return seqError(); - } - - auto rc = imageMemXferGet(origin, data); - if (Twpp::success(rc) || rc == ReturnCode::XferDone) { - setState(DsState::Xferring); - } - - return rc; - } - - /// Get image memory xfer TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Image memory xfer data. - virtual Result imageMemXferGet(const Identity& origin, ImageMemXfer& data) = 0; - - /// Image native xfer TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Handle to image native xfer data. - virtual Result imageNativeXfer(const Identity& origin, Msg msg, ImageNativeXfer& data) { - if (msg != Msg::Get) { - return badProtocol(); - } - - if (!inState(DsState::XferReady)) { - return seqError(); - } - - auto rc = imageNativeXferGet(origin, data); - if (rc == ReturnCode::XferDone) { - setState(DsState::Xferring); - } - - return rc; - } - - /// Get image native xfer TWAIN call. - /// Always called in correct state. - /// \param origin Identity of the caller. - /// \param data Handle to image native xfer data. - virtual Result imageNativeXferGet(const Identity& origin, ImageNativeXfer& data) = 0; - - /// JPEG compression TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data JPEG compression data. - virtual Result jpegCompression(const Identity& origin, Msg msg, JpegCompression& data) { - switch (msg) { - case Msg::Get: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return jpegCompressionGet(origin, data); - - case Msg::GetDefault: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return jpegCompressionGetDefault(origin, data); - - case Msg::Set: - if (!inState(DsState::Open)) { - return seqError(); - } - - return jpegCompressionSet(origin, data); - - case Msg::Reset: - if (!inState(DsState::Open)) { - return seqError(); - } - - return jpegCompressionReset(origin, data); - - default: - return badProtocol(); - } - } - - /// Get JPEG compression TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data JPEG compression data. - virtual Result jpegCompressionGet(const Identity& origin, JpegCompression& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Get default JPEG compression TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data JPEG compression data. - virtual Result jpegCompressionGetDefault(const Identity& origin, JpegCompression& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Set JPEG compression TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data JPEG compression data. - virtual Result jpegCompressionSet(const Identity& origin, JpegCompression& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Reset JPEG compression TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data JPEG compression data. - virtual Result jpegCompressionReset(const Identity& origin, JpegCompression& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Palette8 TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Palette8 data. - virtual Result palette8(const Identity& origin, Msg msg, Palette8& data) { - switch (msg) { - case Msg::Get: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return palette8Get(origin, data); - - case Msg::GetDefault: - if (!inState(DsState::Open, DsState::XferReady)) { - return seqError(); - } - - return palette8GetDefault(origin, data); - - case Msg::Set: - if (!inState(DsState::Open)) { - return seqError(); - } - - return palette8Set(origin, data); - - case Msg::Reset: - if (!inState(DsState::Open)) { - return seqError(); - } - - return palette8Reset(origin, data); - - default: - return badProtocol(); - } - } - - /// Get Palette8 TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Palette8 data. - virtual Result palette8Get(const Identity& origin, Palette8& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Get default Palette8 TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Palette8 data. - virtual Result palette8GetDefault(const Identity& origin, Palette8& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Set Palette8 TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Palette8 data. - virtual Result palette8Set(const Identity& origin, Palette8& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Reset Palette8 TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Palette8 data. - virtual Result palette8Reset(const Identity& origin, Palette8& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// RGB response TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data RGB response data. - virtual Result rgbResponse(const Identity& origin, Msg msg, RgbResponse& data) { - if (!inState(DsState::Open)) { - return seqError(); - } - - switch (msg) { - case Msg::Set: - return rgbResponseSet(origin, data); - - case Msg::Reset: - return rgbResponseReset(origin, data); - - default: - return badProtocol(); - } - } - - /// Set RGB response TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data RGB response data. - virtual Result rgbResponseSet(const Identity& origin, RgbResponse& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Reset RGB response TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data RGB response data. - virtual Result rgbResponseReset(const Identity& origin, RgbResponse& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - - /// Root of source audio TWAIN calls. - /// \param origin Identity of the caller. - /// \param dat Type of data. - /// \param msg Message, action to perform. - /// \param data The data, may be null. - virtual Result audio(const Identity& origin, Dat dat, Msg msg, void* data) { - if (dat != Dat::AudioFileXfer && !data) { - return badValue(); - } - - switch (dat) { - case Dat::AudioFileXfer: - return audioFileXfer(origin, msg); - case Dat::AudioInfo: - return audioInfo(origin, msg, *static_cast(data)); - case Dat::AudioNativeXfer: - return audioNativeXfer(origin, msg, *static_cast(data)); - default: - return badProtocol(); - } - } - - /// Audio file xfer TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - virtual Result audioFileXfer(const Identity& origin, Msg msg) { - if (msg != Msg::Get) { - return badProtocol(); - } - - if (!inState(DsState::XferReady)) { - return seqError(); - } - - auto rc = audioFileXferGet(origin); - if (rc == ReturnCode::XferDone) { - setState(DsState::Xferring); - } - - return rc; - } - - /// Get audio file xfer TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - virtual Result audioFileXferGet(const Identity& origin) { - Detail::unused(origin); - return badProtocol(); - } - - /// Audio info TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Audio info data. - virtual Result audioInfo(const Identity& origin, Msg msg, AudioInfo& data) { - if (msg != Msg::Get) { - return badProtocol(); - } - - if (!inState(DsState::XferReady, DsState::Xferring)) { - return seqError(); - } - - return audioInfoGet(origin, data); - } - - /// Get audio info TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Audio info data. - virtual Result audioInfoGet(const Identity& origin, AudioInfo& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - /// Audio native xfer TWAIN call. - /// \param origin Identity of the caller. - /// \param msg Message, action to perform. - /// \param data Handle to audio native xfer data. - virtual Result audioNativeXfer(const Identity& origin, Msg msg, AudioNativeXfer& data) { - if (msg != Msg::Get) { - return badProtocol(); - } - - if (!inState(DsState::XferReady)) { - return seqError(); - } - - auto rc = audioNativeXferGet(origin, data); - if (Twpp::success(rc)) { - setState(DsState::Xferring); - } - - return rc; - } - - /// Get audio native xfer TWAIN call. - /// Always called in correct state. - /// Default implementation does nothing. - /// \param origin Identity of the caller. - /// \param data Handle to audio native xfer data. - virtual Result audioNativeXferGet(const Identity& origin, AudioNativeXfer& data) { - Detail::unused(origin, data); - return badProtocol(); - } - - private: - ReturnCode notifyApp(Msg msg) noexcept { - switch (msg) { - case Msg::XferReady: - if (!inState(DsState::Enabled)) { - return ReturnCode::Failure; - } - - break; - case Msg::CloseDsOk: - case Msg::CloseDsReq: - if (!inState(DsState::Enabled, DsState::Xferring)) { - return ReturnCode::Failure; - } - - break; - default: - break; - } - - auto rc = g_entry(&m_srcId, &m_appId, DataGroup::Control, Dat::Null, msg, nullptr); - if (Twpp::success(rc)) { - switch (msg) { - case Msg::XferReady: - setState(DsState::XferReady); - break; - case Msg::CloseDsOk: - case Msg::CloseDsReq: - setState(DsState::Enabled); - break; - default: - break; - } - } - - return rc; - } - - Result callRoot(Identity* origin, DataGroup dg, Dat dat, Msg msg, void* data) noexcept { - if (!origin) { - return badProtocol(); - } - - bool isCapability = dg == DataGroup::Control && dat == Dat::Capability && data != nullptr; - try { - return isCapability - ? callCapability(*origin, dg, dat, msg, data) - : call(*origin, dg, dat, msg, data); - } - catch (const std::bad_alloc&) { - return { ReturnCode::Failure, ConditionCode::LowMemory }; - } - catch (...) { - // the exception would be caught in the static handler below - // that would set static status, we want to set local one - return bummer(); - } - } - - Result callCapability(const Identity& origin, DataGroup dg, Dat dat, Msg msg, void* data) { - // it is the responsibility of the APP to free capability handle - // we must assume the APP does not set the handle to zero after freeing it - // that would break capability (handle) move-assignment operator - // make sure such handle is not freed - Detail::AppCapability& cap = *static_cast(data); - Detail::DoNotFreeHandle doNotFree(cap.m_cont); - Detail::unused(doNotFree); - - return call(origin, dg, dat, msg, data); - } - - - Identity m_srcId; - Identity m_appId; - Status m_lastStatus; - DsState m_state; - - - static typename std::list::iterator find(Identity* origin) noexcept { - if (origin) { - for (auto it = g_sources.begin(); it != g_sources.end(); ++it) { - if (it->m_appId.id() == origin->id()) { - return it; - } - } - } - - return g_sources.end(); - } - - static void resetDsm() { - g_entry = nullptr; - -#if defined(TWPP_DETAIL_OS_WIN32) - g_dsm.unload(); -#endif - } - - static Result staticCall(typename std::list::iterator src, Identity* origin, - DataGroup dg, Dat dat, Msg msg, void* data) { - -#if defined(TWPP_DETAIL_OS_WIN32) - if (!g_entry) { - if (!g_dsm && !g_dsm.load(true)) { - return bummer(); - } - - g_entry = g_dsm.resolve(); - } -#endif - - if (!g_entry) { - return bummer(); - } - - auto rc = src->callRoot(origin, dg, dat, msg, data); - src->m_lastStatus = rc.status(); - - if (dg == DataGroup::Control && dat == Dat::Identity && ( - (msg == Msg::CloseDs && Twpp::success(rc)) || - (msg == Msg::OpenDs && !Twpp::success(rc)) - ) - ) { - g_sources.erase(src); - if (g_sources.empty()) { - resetDsm(); - } - } - - return rc; - } - - static Result staticControl(Identity* origin, DataGroup dg, Dat dat, Msg msg, void* data) { - if (dg != DataGroup::Control) { - return seqError(); - } - - switch (dat) { - case Dat::EntryPoint: - if (msg == Msg::Set) { - if (!data) { - return badValue(); - } - - auto& e = *static_cast(data); - g_entry = e.m_entry; - Detail::setMemFuncs(e.m_alloc, e.m_free, e.m_lock, e.m_unlock); - return success(); - } - - break; - - case Dat::Status: { - if (msg == Msg::Get) { - if (!data) { - return badValue(); - } - - *static_cast(data) = g_lastStatus; - return success(); - } - - break; - } - - case Dat::Identity: { - switch (msg) { - case Msg::Get: { - if (!data) { - return badValue(); - } - - static_assert(Detail::HasStaticMethod_defaultIdentity::value, - "Your source class lacks `static const Identity& defaultIdentity()` method."); - - auto& ident = *static_cast(data); - const Identity& def = Derived::defaultIdentity(); - ident = Identity(ident.id(), def.version(), def.protocolMajor(), - def.protocolMinor(), def.dataGroupsRaw(), def.manufacturer(), - def.productFamily(), def.productName()); - - return success(); - } - - case Msg::OpenDs: { - g_sources.emplace_back(); - return staticCall(--g_sources.end(), origin, dg, dat, msg, data); - } - - case Msg::CloseDs: - // not open yet - return success(); - - case Msg::UserSelect: - if (!data) { - return badValue(); - } - else - { - auto& ident = *static_cast(data); - - return Derived::selectIdentity(ident); - - return success(); - } - break; - - default: - break; - } - - break; - } - - default: - if (dat >= Dat::CustomBase) { - static_assert(Detail::HasStaticMethod_staticCustomBase::value || - !hasStaticCustomBaseProc, - "Your source class lacks `static Result staticCustomBase(Dat, Msg, void*)` method."); - - return Detail::StaticCustomBaseProc()(dat, msg, data); - } - - break; - } - - return badProtocol(); - } - - public: - /// TWAIN entry, do not call from data source. - static ReturnCode entry(Identity* origin, DataGroup dg, Dat dat, Msg msg, void* data) noexcept { - auto src = find(origin); - //FileTools::write_log("D:\\1.txt", "call:datagroup-" + to_string((int)dg) + "dat-" + to_string(int(dat)) + "msg-" + to_string(int(msg))); - try { - auto rc = src == g_sources.end() ? - staticControl(origin, dg, dat, msg, data) : - staticCall(src, origin, dg, dat, msg, data); - - g_lastStatus = rc.status(); - return rc.returnCode(); - } - catch (const std::bad_alloc&) { - g_lastStatus = ConditionCode::LowMemory; - return ReturnCode::Failure; - } - catch (...) { - // we can't throw exceptions out of data sources - // the C interface can't really handle them - // especially when there are different implementations - g_lastStatus = ConditionCode::Bummer; - return ReturnCode::Failure; - } - } - - private: - static std::list g_sources; - static Detail::DsmEntry g_entry; - static Status g_lastStatus; - -#if defined(TWPP_DETAIL_OS_WIN32) - static Detail::DsmLib g_dsm; // only old windows dsm requires this -#endif - - }; - - template - std::list SourceFromThis::g_sources; - - template - Detail::DsmEntry SourceFromThis::g_entry; - - template - Status SourceFromThis::g_lastStatus = ConditionCode::Bummer; - -#if defined(TWPP_DETAIL_OS_WIN32) - template - Detail::DsmLib SourceFromThis::g_dsm; -#endif - -} - -#endif // TWPP_DETAIL_FILE_DATASOURCE_HPP - diff --git a/twain/twain/twpp/deviceevent.hpp b/twain/twain/twpp/deviceevent.hpp deleted file mode 100644 index cdf530a..0000000 --- a/twain/twain/twpp/deviceevent.hpp +++ /dev/null @@ -1,251 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_DEVICEEVENT_HPP -#define TWPP_DETAIL_FILE_DEVICEEVENT_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Information about event sent by source. -class DeviceEvent { - -public: - /// Event type. - enum class Type : UInt16 { // Capability->UInt16, DeviceEvent->UInt32 - CheckAutomaticCapture = 0, - CheckBattery = 1, - CheckDeviceOnline = 2, - CheckFlash = 3, - CheckPowerSupply = 4, - CheckResolution = 5, - DeviceAdded = 6, - DeviceOffline = 7, - DeviceReady = 8, - DeviceRemoved = 9, - ImageCaptured = 10, - ImageDeleted = 11, - PaperDoubleFeed = 12, - PaperJam = 13, - LampFailure = 14, - PowerSave = 15, - PowerSaveNotify = 16, - CustomEvents = 0x8000 - }; - - /// Creates event with only type and device name set. - static constexpr DeviceEvent simple(Type type, const Str255& deviceName) noexcept; - - /// Creates event for checking battery. - static constexpr DeviceEvent checkBattery( - const Str255& deviceName, - UInt32 batteryMinutes, - Int16 batteryPercentage - ) noexcept; - - /// Creates event for checking power supply. - static constexpr DeviceEvent checkPowerSupply( - const Str255& deviceName, - PowerSupply powerSupply - ) noexcept; - - /// Creates event for checking resolution. - static constexpr DeviceEvent checkResolution( - const Str255& deviceName, - Fix32 xres, - Fix32 yres - ) noexcept; - - /// Creates event for checking flash settings. - static constexpr DeviceEvent checkFlash( - const Str255& deviceName, - Flash flash - ) noexcept; - - /// Creates event for checking number of images camera is going to capture. - static constexpr DeviceEvent checkAutomaticCapture( - const Str255& deviceName, - UInt32 autoCapture, - UInt32 timeBeforeFirstCapture, - UInt32 timeBetweenCaptures - ) noexcept; - - /// Creates uninitialized deice event. - constexpr DeviceEvent() noexcept : - m_type(static_cast(Type::CheckAutomaticCapture)), m_batteryMinutes(0), - m_batteryPercent(0), m_powerSupply(static_cast(PowerSupply::External)), - m_flashUsed(static_cast(Flash::None)), m_autoCapture(0), - m_timeBeforeFirstCapture(0), m_timeBetweenCaptures(0){} - - /// Event type. - constexpr Type type() const noexcept{ - return static_cast(m_type); - } - - /// Name of the device that sent the event. - constexpr const Str255& deviceName() const noexcept{ - return m_deviceName; - } - - /// Minutes of battery power remaining. - /// Valid only for Type::CheckBattery. - constexpr UInt32 batteryMinutes() const noexcept{ - return m_batteryMinutes; - } - - /// Percentage of battery power remaining. - /// Valid only for Type::CheckBattery. - constexpr Int16 batteryPercentage() const noexcept{ - return m_batteryPercent; - } - - /// Power supply in use. - /// Valid only for Type::CheckPowerSupply. - constexpr PowerSupply powerSupply() const noexcept{ - return static_cast(m_powerSupply); - } - - /// X resolution. - /// Valif only for Type::CheckResolution. - constexpr Fix32 xResolution() const noexcept{ - return m_xres; - } - - /// Y resolution. - /// Valid only for Type::CheckResolution. - constexpr Fix32 yResolution() const noexcept{ - return m_yres; - } - - /// Flash settings. - /// Valid only for Type::CheckFlash. - constexpr Flash flash() const noexcept{ - return static_cast(m_flashUsed); - } - - /// Number of images camera will capture. - /// Valid only for Type::CheckAutomaticCapture. - constexpr UInt32 automaticCapture() const noexcept{ - return m_autoCapture; - } - - /// Number of seconds before first capture. - /// Valid only for Type::CheckAutomaticCapture. - constexpr UInt32 timeBeforeFirstCapture() const noexcept{ - return m_timeBeforeFirstCapture; - } - - /// Number of 1/100-seconds between captures. - /// Valid only for Type::CheckAutomaticCapture. - constexpr UInt32 timeBetweenCaptures() const noexcept{ - return m_timeBetweenCaptures; - } - -private: - constexpr DeviceEvent( - Type type, - const Str255& deviceName, - UInt32 batteryMinutes, - Int16 batteryPercentage, - PowerSupply powerSupply, - Fix32 xres, - Fix32 yres, - Flash flash, - UInt32 autoCapture, - UInt32 tbfc, - UInt32 tbc - ) noexcept : - m_type(static_cast(type)), m_deviceName(deviceName), - m_batteryMinutes(batteryMinutes), m_batteryPercent(batteryPercentage), - m_powerSupply(static_cast(powerSupply)), m_xres(xres), m_yres(yres), - m_flashUsed(static_cast(flash)), m_autoCapture(autoCapture), - m_timeBeforeFirstCapture(tbfc), m_timeBetweenCaptures(tbc){} - - UInt32 m_type; - Str255 m_deviceName; - UInt32 m_batteryMinutes; - Int16 m_batteryPercent; - Int32 m_powerSupply; - Fix32 m_xres; - Fix32 m_yres; - UInt32 m_flashUsed; - UInt32 m_autoCapture; - UInt32 m_timeBeforeFirstCapture; - UInt32 m_timeBetweenCaptures; - -}; -TWPP_DETAIL_PACK_END - -// must be defined outside the class because of msvc2015 -constexpr inline DeviceEvent DeviceEvent::simple(Type type, const Str255& deviceName) noexcept{ - return DeviceEvent(type, deviceName, 0, 0, PowerSupply::External, Fix32(), Fix32(), Flash::None, 0, 0, 0); -} - -constexpr inline DeviceEvent DeviceEvent::checkBattery( - const Str255& deviceName, - UInt32 batteryMinutes, - Int16 batteryPercentage -) noexcept{ - return DeviceEvent(Type::CheckBattery, deviceName, batteryMinutes, batteryPercentage, PowerSupply::External, Fix32(), Fix32(), Flash::None, 0, 0, 0); -} - -constexpr inline DeviceEvent DeviceEvent::checkPowerSupply( - const Str255& deviceName, - PowerSupply powerSupply -) noexcept{ - return DeviceEvent(Type::CheckPowerSupply, deviceName, 0, 0, powerSupply, Fix32(), Fix32(), Flash::None, 0, 0, 0); -} - -constexpr inline DeviceEvent DeviceEvent::checkResolution( - const Str255& deviceName, - Fix32 xres, - Fix32 yres -) noexcept{ - return DeviceEvent(Type::CheckResolution, deviceName, 0, 0, PowerSupply::External, xres, yres, Flash::None, 0, 0, 0); -} - -constexpr inline DeviceEvent DeviceEvent::checkFlash( - const Str255& deviceName, - Flash flash -) noexcept{ - return DeviceEvent(Type::CheckFlash, deviceName, 0, 0, PowerSupply::External, Fix32(), Fix32(), flash, 0, 0, 0); -} - -constexpr inline DeviceEvent DeviceEvent::checkAutomaticCapture( - const Str255& deviceName, - UInt32 autoCapture, - UInt32 timeBeforeFirstCapture, - UInt32 timeBetweenCaptures -) noexcept{ - return DeviceEvent(Type::CheckAutomaticCapture, deviceName, 0, 0, PowerSupply::External, - Fix32(), Fix32(), Flash::None, autoCapture, timeBeforeFirstCapture, timeBetweenCaptures); -} - -} - -#endif // TWPP_DETAIL_FILE_DEVICEEVENT_HPP diff --git a/twain/twain/twpp/element8.hpp b/twain/twain/twpp/element8.hpp deleted file mode 100644 index 585d571..0000000 --- a/twain/twain/twpp/element8.hpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_ELEMENT8_HPP -#define TWPP_DETAIL_FILE_ELEMENT8_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Element in a palette consisting of 3 parts (RGB, CMY, ...) -/// in the order of the type alphabetic representation. -class Element8 { - -public: - /// Creates zero-initialized element. - constexpr Element8() noexcept : - m_index(0), m_channel1(0), m_channel2(0), m_channel3(0){} - - /// Creates zero-initialized element with specified index. - explicit constexpr Element8(UInt8 index) noexcept : - m_index(index), m_channel1(0), m_channel2(0), m_channel3(0){} - - /// Creates element with set channels. - constexpr Element8( - UInt8 channel1, - UInt8 channel2, - UInt8 channel3 - ) noexcept : - m_index(0), m_channel1(channel1), m_channel2(channel2), - m_channel3(channel3){} - - /// Creates element with set channels at index. - constexpr Element8( - UInt8 index, - UInt8 channel1, - UInt8 channel2, - UInt8 channel3 - ) noexcept : - m_index(index), m_channel1(channel1), m_channel2(channel2), - m_channel3(channel3){} - - /// Index of the element in palette. - constexpr UInt8 index() const noexcept{ - return m_index; - } - - /// Sets index of the element in palette. - void setIndex(UInt8 index) noexcept{ - m_index = index; - } - - /// Channel 1 information. - constexpr UInt8 channel1() const noexcept{ - return m_channel1; - } - - /// Sets channel 1 information. - void setChannel1(UInt8 channel1) noexcept{ - m_channel1 = channel1; - } - - /// Channel 2 information. - constexpr UInt8 channel2() const noexcept{ - return m_channel2; - } - - /// Sets channel 2 information. - void setChannel2(UInt8 channel2) noexcept{ - m_channel2 = channel2; - } - - /// Channel 3 information. - constexpr UInt8 channel3() const noexcept{ - return m_channel3; - } - - /// Sets channel 3 information. - void setChannel3(UInt8 channel3) noexcept{ - m_channel3 = channel3; - } - -private: - UInt8 m_index; - UInt8 m_channel1; - UInt8 m_channel2; - UInt8 m_channel3; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_ELEMENT8_HPP diff --git a/twain/twain/twpp/enums.hpp b/twain/twain/twpp/enums.hpp deleted file mode 100644 index 9a51b96..0000000 --- a/twain/twain/twpp/enums.hpp +++ /dev/null @@ -1,1459 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_ENUMS_HPP -#define TWPP_DETAIL_FILE_ENUMS_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -enum class Alarm : UInt16 { - General = 0, // aka TWAL_ALARM - FeederError = 1, - FeederWarning = 2, - BarCode = 3, - DoubleFeed = 4, - Jam = 5, - PatchCode = 6, - Power = 7, - Skew = 8 -}; - -/// Argument types. -enum class Dat : UInt16 { - Null = 0x0000, - Capability = 0x0001, - Event = 0x0002, - Identity = 0x0003, - Parent = 0x0004, - PendingXfers = 0x0005, - SetupMemXfer = 0x0006, - SetupFileXfer = 0x0007, - Status = 0x0008, - UserInterface = 0x0009, - XferGroup = 0x000a, - CustomData = 0x000c, - DeviceEvent = 0x000d, - FileSystem = 0x000e, - PassThrough = 0x000f, - Callback = 0x0010, - StatusUtf8 = 0x0011, - Callback2 = 0x0012, - ImageInfo = 0x0101, - ImageLayout = 0x0102, - ImageMemXfer = 0x0103, - ImageNativeXfer = 0x0104, - ImageFileXfer = 0x0105, - CieColor = 0x0106, - GrayResponse = 0x0107, - RgbResponse = 0x0108, - JpegCompression = 0x0109, - Palette8 = 0x010a, - ExtImageInfo = 0x010b, - Filter = 0x010c, - AudioFileXfer = 0x0201, - AudioInfo = 0x0202, - AudioNativeXfer = 0x0203, - IccProfile = 0x0401, - ImageMemFileXfer = 0x0402, - EntryPoint = 0x0403, - - CustomBase = 0x8000 -}; - -/// Values of CapType::IAutoSize. -enum class AutoSize : UInt16 { - None = 0, - Auto = 1, - Current = 2 -}; - -/// Values of CapType::ISupportedBarcodeTypes. -enum class BarCodeType : UInt16 { - ThreeOfNine = 0, - ThreeOfFiveInterleaved = 1, - ThreeOfFiveNonInterleaved = 2, - Code93 = 3, - Code128 = 4, - Ucc128 = 5, - CodaBar = 6, - Upca = 7, - Upce = 8, - Ean8 = 9, - Ean13 = 10, - Postnet = 11, - Pdf417 = 12, - TwoOfFiveIndustrial = 13, - TwoOfFiveMatrix = 14, - TwoOfFiveDatalogic = 15, - TwoOfFiveIata = 16, - ThreeOfNineFullAscii = 17, - CodaBarWithStartStop = 18, - MaxiCode = 19, - QrCode = 20 -}; - -/// Values of CapType::IBitDepthReduction. -enum class BitDepthReduction : UInt16 { - Threshold = 0, - HalfTone = 1, - CustHalfTone = 2, - Diffusion = 3, - DynamicThreshold = 4 -}; - -/// Values of CapType::IBitOrder. -enum class BitOrder : UInt16 { - LsbFirst = 0, - MsbFirst = 1 -}; - -/// Values of CapType::CameraSide. -enum class CameraSide : UInt16 { - Both = 0, - Top = 1, - Bottom = 2 -}; - -enum class ConditionCode : UInt16 { - Success = 0, - Bummer = 1, - LowMemory = 2, - NoDs = 3, - MaxConnections = 4, - OperationError = 5, - BadCap = 6, - BadProtocol = 9, - BadValue = 10, - SeqError = 11, - BadDest = 12, - CapUnsupported = 13, - CapBadOperation = 14, - CapSeqError = 15, - Denied = 16, - FileExists = 17, - FileNotFound = 18, - NotEmpty = 19, - PaperJam = 20, - PaperDoubleFeed = 21, - FileWriteError = 22, - CheckDeviceOnline = 23, - InterLock = 24, - DamagedCorner = 25, - FocusError = 26, - DocTooLight = 27, - DocTooDark = 28, - NoMedia = 29, - - CustomBase = 0x8000 -}; - -typedef ConditionCode CC; - -static inline constexpr bool success(CC cc) noexcept{ - return cc == CC::Success; -} - -/// Capability container type. -enum class ConType : UInt16 { - Array = 3, - Enumeration = 4, - OneValue = 5, - Range = 6, - DontCare = 0xFFFF -}; - -/// Capability type. -enum class CapType : UInt16 { - XferCount = 0x0001, - ICompression = 0x0100, - IPixelType = 0x0101, - IUnits = 0x0102, - IXferMech = 0x0103, - Author = 0x1000, - Caption = 0x1001, - FeederEnabled = 0x1002, - FeederLoaded = 0x1003, - TimeDate = 0x1004, - SupportedCaps = 0x1005, - ExtendedCaps = 0x1006, - AutoFeed = 0x1007, - ClearPage = 0x1008, - FeedPage = 0x1009, - RewindPage = 0x100a, - Indicators = 0x100b, - PaperDetectable = 0x100d, - UiControllable = 0x100e, - DeviceOnline = 0x100f, - AutoScan = 0x1010, - ThumbnailsEnabled = 0x1011, - Duplex = 0x1012, - DuplexEnabled = 0x1013, - EnableDsUiOnly = 0x1014, - CustomDsData = 0x1015, - Endorser = 0x1016, - JobControl = 0x1017, - Alarms = 0x1018, - AlarmVolume = 0x1019, - AutomaticCapture = 0x101a, - TimeBeforeFirstCapture = 0x101b, - TimeBetweenCaptures = 0x101c, - ClearBuffers = 0x101d, - MaxBatchBuffers = 0x101e, - DeviceTimeDate = 0x101f, - PowerSupply = 0x1020, - CameraPreviewUi = 0x1021, - DeviceEvent = 0x1022, - SerialNumber = 0x1024, - Printer = 0x1026, - PrinterEnabled = 0x1027, - PrinterIndex = 0x1028, - PrinterMode = 0x1029, - PrinterString = 0x102a, - PrinterSuffix = 0x102b, - Language = 0x102c, - FeederAlignment = 0x102d, - FeederOrder = 0x102e, - ReacquireAllowed = 0x1030, - BatteryMinutes = 0x1032, - BatteryPercentage = 0x1033, - CameraSide = 0x1034, - Segmented = 0x1035, - CameraEnabled = 0x1036, - CameraOrder = 0x1037, - MicrEnabled = 0x1038, - FeederPrep = 0x1039, - FeederPocket = 0x103a, - AutomaticSenseMedium = 0x103b, - CustomInterfaceGuid = 0x103c, - SupportedCapsSegmentUnique = 0x103d, - SupportedDats = 0x103e, - DoubleFeedDetection = 0x103f, - DoubleFeedDetectionLength = 0x1040, - DoubleFeedDetectionSensitivity = 0x1041, - DoubleFeedDetectionResponse = 0x1042, - PaperHandling = 0x1043, - IndicatorsMode = 0x1044, - PrinterVerticalOffset = 0x1045, - PowerSaveTime = 0x1046, - PrinterCharRotation = 0x1047, - PrinterFontStyle = 0x1048, - PrinterIndexLeadChar = 0x1049, - PrinterIndexMaxValue = 0x104A, - PrinterIndexNumDigits = 0x104B, - PrinterIndexStep = 0x104C, - PrinterIndexTrigger = 0x104D, - PrinterStringPreview = 0x104E, - IAutoBright = 0x1100, - IBrightness = 0x1101, - IContrast = 0x1103, - ICustHalfTone = 0x1104, - IExposureTime = 0x1105, - IFilter = 0x1106, - IFlashUsed = 0x1107, - IGamma = 0x1108, - IHalfTones = 0x1109, - IHighLight = 0x110a, - IImageFileFormat = 0x110c, - ILampState = 0x110d, - ILightSource = 0x110e, - IOrientation = 0x1110, - IPhysicalWidth = 0x1111, - IPhysicalHeight = 0x1112, - IShadow = 0x1113, - IFrames = 0x1114, - IXNativeResolution = 0x1116, - IYNativeResolution = 0x1117, - IXResolution = 0x1118, - IYResolution = 0x1119, - IMaxFrames = 0x111a, - ITiles = 0x111b, - IBitOrder = 0x111c, - ICcittKFactor = 0x111d, - ILightPath = 0x111e, - IPixelFlavor = 0x111f, - IPlanarChunky = 0x1120, - IRotation = 0x1121, - ISupportedSizes = 0x1122, - IThreshold = 0x1123, - IXScaling = 0x1124, - IYScaling = 0x1125, - IBitOrderCodes = 0x1126, - IPixelFlavorCodes = 0x1127, - IJpegPixelType = 0x1128, - ITimeFill = 0x112a, - IBitDepth = 0x112b, - IBitDepthReduction = 0x112c, - IUndefinedImageSize = 0x112d, - IImageDataSet = 0x112e, - IExtImageInfo = 0x112f, - IMinimumHeight = 0x1130, - IMinimumWidth = 0x1131, - IAutoDiscardBlankPages = 0x1134, - IFlipRotation = 0x1136, - IBarCodeDetectionEnabled = 0x1137, - ISupportedBarCodeTypes = 0x1138, - IBarCodeMaxSearchPriorities = 0x1139, - IBarCodeSearchPriorities = 0x113a, - IBarCodeSearchMode = 0x113b, - IBarCodeMaxRetries = 0x113c, - IBarCodeTimeOut = 0x113d, - IZoomFactor = 0x113e, - IPatchCodeDetectionEnabled = 0x113f, - ISupportedPatchCodeTypes = 0x1140, - IPatchCodeMaxSearchPriorities = 0x1141, - IPatchCodeSearchPriorities = 0x1142, - IPatchCodeSearchMode = 0x1143, - IPatchCodeMaxRetries = 0x1144, - IPatchCodeTimeOut = 0x1145, - IFlashUsed2 = 0x1146, - IImageFilter = 0x1147, - INoiseFilter = 0x1148, - IOverScan = 0x1149, - IAutomaticBorderDetection = 0x1150, - IAutomaticDeskew = 0x1151, - IAutomaticRotate = 0x1152, - IJpegQuality = 0x1153, - IFeederType = 0x1154, - IIccProfile = 0x1155, - IAutoSize = 0x1156, - IAutomaticCropUsesFrame = 0x1157, - IAutomaticLengthDetection = 0x1158, - IAutomaticColorEnabled = 0x1159, - IAutomaticColorNonColorPixelType = 0x115a, - IColorManagementEnabled = 0x115b, - IImageMerge = 0x115c, - IImageMergeHeightThreshold = 0x115d, - ISupportedExtImageInfo = 0x115e, - IFilmType = 0x115f, - IMirror = 0x1160, - IJpegSubSampling = 0x1161, - AXferMech = 0x1202, - CustomBase = 0x8000 -}; - -/// Values of CapType::ClearBuffers. -enum class ClearBuffers : UInt16 { - Auto = 0, - Clear = 1, - NoClear = 2 -}; - -/// Values of CapType::IPlanarChunky. -enum class ColorFormat : UInt16 { - Chunky = 0, - Planar = 1 -}; - -typedef ColorFormat PlanarChunky; - -/// Values of CapType::ICompression. -/// Also used in ImageInfo and ImageMemXfer. -enum class Compression : UInt16 { - None = 0, - PackBits = 1, - Group31D = 2, - Group31DEol = 3, - Group32D = 4, - Group4 = 5, - Jpeg = 6, - Lzw = 7, - JBig = 8, - Png = 9, - Rle4 = 10, - Rle8 = 11, - BitFields = 12, - Ziz = 13, - Jpeg2000 = 14, - DontCare = 0xFFFF -}; - -/// Countries for Version. -enum class Country : UInt16 { - Afghanistan = 1001, - Algeria = 213, - AmericanSamoa = 684, - Andorra = 033, - Angola = 1002, - Anguilla = 8090, - Antigua = 8091, - Argentina = 54, - Aruba = 297, - Ascensioni = 247, - Australia = 61, - Austria = 43, - Bahamas = 8092, - Bahrain = 973, - Bangladesh = 880, - Barbados = 8093, - Belgium = 32, - Belize = 501, - Benin = 229, - Bermuda = 8094, - Bhutan = 1003, - Bolivia = 591, - Botswana = 267, - Britain = 6, - BritVirginIs = 8095, - Brazil = 55, - Brunei = 673, - Bulgaria = 359, - BurkinaFaso = 1004, - Burma = 1005, - Burundi = 1006, - Camaroon = 237, - Canada = 2, - CapeVerdeIs = 238, - CaymanIs = 8096, - CentralAfRep = 1007, - Chad = 1008, - Chile = 56, - China = 86, - ChristmasIs = 1009, - CocosIs = 1009, - Colombia = 57, - Comoros = 1010, - Congo = 1011, - CookIs = 1012, - Costarica = 506, - Cuba = 005, - Cyprus = 357, - Czechoslovakia = 42, - Denmark = 45, - Djibouti = 1013, - Dominica = 8097, - DomincanRep = 8098, - EasterIs = 1014, - Ecuador = 593, - Egypt = 20, - ElSalvador = 503, - EqGuinea = 1015, - Ethiopia = 251, - FalklandIs = 1016, - FaeroeIs = 298, - FijiIslands = 679, - Finland = 358, - France = 33, - FrAntilles = 596, - FrGuiana = 594, - FrPolyneisa = 689, - FutanaIs = 1043, - Gabon = 241, - Gambia = 220, - Germany = 49, - Ghana = 233, - Gibralter = 350, - Greece = 30, - Greenland = 299, - Grenada = 8099, - Grenedines = 8015, - Guadeloupe = 590, - Guam = 671, - GuantanamoBay = 5399, - Guatemala = 502, - Guinea = 224, - GuineaBissau = 1017, - Guyana = 592, - Haiti = 509, - Honduras = 504, - HongKong = 852, - Hungary = 36, - Iceland = 354, - India = 91, - Indonesia = 62, - Iran = 98, - Iraq = 964, - Ireland = 353, - Israel = 972, - Italy = 39, - IvoryCoast = 225, - Jamaica = 8010, - Japan = 81, - Jordan = 962, - Kenya = 254, - Kiribati = 1018, - Korea = 82, - Kuwait = 965, - Laos = 1019, - Lebanon = 1020, - Liberia = 231, - Libya = 218, - Liechtenstein = 41, - Luxenbourg = 352, - Macao = 853, - Madagascar = 1021, - Malawi = 265, - Malaysia = 60, - Maldives = 960, - Mali = 1022, - Malta = 356, - MarshallIs = 692, - Mauritania = 1023, - Mauritius = 230, - Mexico = 3, - Micronesia = 691, - Miquelon = 508, - Monaco = 33, - Mongolia = 1024, - Montserrat = 8011, - Morocco = 212, - Mozambique = 1025, - Namibia = 264, - Nauru = 1026, - Nepal = 977, - Netherlands = 31, - NethAntilles = 599, - Nevis = 8012, - NewCaledonia = 687, - NewZealand = 64, - Nicaragua = 505, - Niger = 227, - Nigeria = 234, - Niue = 1027, - Norfolki = 1028, - Norway = 47, - Oman = 968, - Pakistan = 92, - Palau = 1029, - Panama = 507, - Paraguay = 595, - Peru = 51, - Phillippines = 63, - PitcairnIs = 1030, - PNewGuinea = 675, - Poland = 48, - Portugal = 351, - Qatar = 974, - Reunioni = 1031, - Romania = 40, - Rwanda = 250, - Saipan = 670, - SanMarino = 39, - SaoTome = 1033, - SaudiArabia = 966, - Senegal = 221, - Seychellesis = 1034, - SierraLeone = 1035, - Singapore = 65, - SolomonIs = 1036, - Somali = 1037, - SouthAfrica = 27, - Spain = 34, - SriLanka = 94, - StHelena = 1032, - StKitts = 8013, - StLucia = 8014, - StPierre = 508, - StVincent = 8015, - Sudan = 1038, - Suriname = 597, - Swaziland = 268, - Sweden = 46, - Switzerland = 41, - Syria = 1039, - Taiwan = 886, - Tanzania = 255, - Thailand = 66, - Tobago = 8016, - Togo = 228, - Tongais = 676, - Trinidad = 8016, - Tunisia = 216, - Turkey = 90, - TurksCaicos = 8017, - Tuvalu = 1040, - Uganda = 256, - Ussr = 7, - UaEmirates = 971, - UnitedKingdom = 44, - Usa = 1, - Uruguay = 598, - Vanuatu = 1041, - VaticanCity = 39, - Venezuela = 58, - Wake = 1042, - WallisIs = 1043, - WesternSahara = 1044, - WesternSamoa = 1045, - Yemen = 1046, - Yugoslavia = 38, - Zaire = 243, - Zambia = 260, - Zimbabwe = 263, - Albania = 355, - Armenia = 374, - Azerbaijan = 994, - Belarus = 375, - BosniaHerzgo = 387, - Cambodia = 855, - Croatia = 385, - CzechRepublic = 420, - DiegoGarcia = 246, - Eritrea = 291, - Estonia = 372, - Georgia = 995, - Latvia = 371, - Lesotho = 266, - Lithuania = 370, - Macedonia = 389, - MayotteIs = 269, - Moldova = 373, - Myanmar = 95, - NorthKorea = 850, - Puertorico = 787, - Russia = 7, - Serbia = 381, - Slovakia = 421, - Slovenia = 386, - SouthKorea = 82, - Ukraine = 380, - UsVirginIs = 340, - Vietnam = 84 -}; - -/// Data group for distinguishing different categories of TWAIN operations. -enum class DataGroup : UInt32 { - Control = 0x0001L, - Image = 0x0002L, - Audio = 0x0004L -}; - -typedef DataGroup DG; - -static constexpr inline UInt32 operator~(DataGroup g) noexcept{ - return ~static_cast(g); -} - -static constexpr inline UInt32 operator|(DataGroup a, DataGroup b) noexcept{ - return static_cast(a) | static_cast(b); -} - -static constexpr inline UInt32 operator|(DataGroup a, UInt32 b) noexcept{ - return static_cast(a) | b; -} - -static constexpr inline UInt32 operator&(DataGroup a, DataGroup b) noexcept{ - return static_cast(a) & static_cast(b); -} - -static constexpr inline UInt32 operator&(UInt32 a, DataGroup b) noexcept{ - return static_cast(a) & b; -} - - -/// Values of CapType::IAutoDiscardBlankPages. -enum class DiscardBlankPages : Int32 { - Disabled = -2, - Auto = -1 -}; - -static constexpr inline DiscardBlankPages discardBytes(Int32 value) noexcept{ - return static_cast(value); -} - -/// Values of CapType::DoubleFeedDetection. -enum class DoubleFeedDetection : UInt16 { - Ultrasonic = 0, - ByLength = 1, - Infrared = 2, -}; - -/// Values of CapType::DoubleFeedDetectionResponse. -enum class DoubleFeedResponse : UInt16 { - Stop = 0, - StopAndWait = 1, - Sound = 2, - DoNotImprint = 3 -}; - -/// Values of CapType::DoubleFeedDetectionSensitivity. -enum class DoubleFeedSensitivity : UInt16 { - Low = 0, - Medium = 1, - High = 2 -}; - -/// Values of CapType::Duplex. -enum class Duplex : UInt16 { - None = 0, - OnePass = 1, - TwoPass = 2 -}; - -/// Values for CapType::FeederAlignment. -enum class FeederAlignment : UInt16 { - None = 0, - Left = 1, - Center = 2, - Right = 3 -}; - -/// Values for CapType::FeederOrder. -enum class FeederOrder : UInt16 { - FirstPageFirst = 0, - LastPageFirst = 1 -}; - - -/// Values for CapType::FeederPocket. -enum class FeederPocket : UInt16 { - PError = 0, - P1 = 1, - P2 = 2, - P3 = 3, - P4 = 4, - P5 = 5, - P6 = 6, - P7 = 7, - P8 = 8, - P9 = 9, - P10 = 10, - P11 = 11, - P12 = 12, - P13 = 13, - P14 = 14, - P15 = 15, - P16 = 16 -}; - -/// Values for CapType::IFeederType. -enum class FeederType : UInt16 { - General = 0, - Photo = 1, -}; - -/// Values for CapType::IFilmType. -enum class FilmType : UInt16 { - Positive = 0, - Negative = 1 -}; - -/// Values for CapType::IFilter. -enum class Filter : UInt16 { - Red = 0, - Green = 1, - Blue = 2, - None = 3, - White = 4, - Cyan = 5, - Magenta = 6, - Yellow = 7, - Black = 8 -}; - -/// Values for CapType::IFlashUsed2 and DeviceEvent.flash. -enum class Flash : UInt16 { // Capability->UInt16, DeviceEvent->UInt32 - None = 0, - Off = 1, - On = 2, - Auto = 3, - RedEye = 4 -}; - -/// Values for CapType::IFlipRotation. -enum class FlipRotation : UInt16 { - Book = 0, - Fanfold = 1 -}; - -/// Values for CapType::PrinterFontStyle -enum class FontStyle : UInt16 { - Normal = 0, - Bold = 1, - Italic = 2, - LargeSize = 3, - SmallSize = 4 -}; - -/// Values for CapType::IIccProfile. -enum class IccProfile : UInt16 { - None = 0, - Link = 1, - Embed = 2 -}; - -/// Values for CapType::IImageFileFormat. -enum class ImageFileFormat : UInt16 { - Tiff = 0, - Pict = 1, - Bmp = 2, - Xbm = 3, - Jfif = 4, - Fpx = 5, - TiffMulti = 6, - Png = 7, - Spiff = 8, - Exif = 9, - Pdf = 10, - Jp2 = 11, - Jpx = 13, - Dejavu = 14, - PdfA = 15, - PdfA2 = 16 -}; - -/// Values for CapType::IImageFilter. -enum class ImageFilter : UInt16 { - None = 0, - Auto = 1, - LowPass = 2, - BandPass = 3, - HighPass = 4, - Text = 3, - FineLine = 4 -}; - -/// Values of CapType::IImageMerge. -enum class ImageMerge : UInt16 { - None = 0, - FrontOnTop = 1, - FrontOnBottom = 2, - FrontOnLeft = 3, - FrontOnRight = 4 -}; - -/// Values of CapType::PrinterIndexTrigger. -enum class IndexTrigger : UInt16 { - Page = 0, - Patch1 = 1, - Patch2 = 2, - Patch3 = 3, - Patch4 = 4, - PatchT = 5, - Patch6 = 6 -}; - -/// Values of CapType::IndicatorsMode. -enum class IndicatorsMode : UInt16 { - Info = 0, - Warning = 1, - Error = 2, - Warmup = 3 -}; - -/// Values of CapType::JobControl. -enum class JobControl : UInt16 { - None = 0, - InclSepContScan = 1, - InclSepStopScan = 2, - ExclSepContScan = 3, - ExclSepStopScap = 4 -}; - -/// Values of CapType::IJpegQuality. -enum class JpegQuality : Int16 { - Unknown = -4, - Low = -3, - Medium = -2, - High = -1 -}; - -static constexpr inline JpegQuality jpegQuality(Int16 value) noexcept{ - return static_cast(value); -} - - -/// Values of CapType::IJpegSubSampling. -enum class JpegSubSampling : UInt16 { - Jp444Ycbcr = 0, - Jp444Rgb = 1, - Jp422 = 2, - Jp421 = 3, - Jp411 = 4, - Jp420 = 5, - Jp410 = 6, - Jp311 = 7 -}; - -/// Values of CapType::Language and Version structure. -enum class Language : UInt16 { - UserLocale = 0xFFFF, - Afrikaans = 14, - Albania = 15, - Arabic = 16, - ArabicAlgeria = 17, - ArabicBahrain = 18, - ArabicEgypt = 19, - ArabicIraq = 20, - ArabicJordan = 21, - ArabicKuwait = 22, - ArabicLebanon = 23, - ArabicLibya = 24, - ArabicMorocco = 25, - ArabicOman = 26, - ArabicQatar = 27, - ArabicSaudiArabia = 28, - ArabicSyria = 29, - ArabicTunisia = 30, - ArabicUae = 31, - ArabicYemen = 32, - Basque = 33, - ByeloRussian = 34, - Bulgarian = 35, - Catalan = 36, - Chinese = 37, - ChineseHongKong = 38, - ChinesePrc = 39, - ChineseSingapore = 40, - ChineseSimplified = 41, - ChineseTaiwan = 42, - ChineseTraditional = 43, - Croatia = 44, - Czech = 45, - Danish = 0, - Dutch = 1, - DutchBelgian = 46, - English = 2, - EnglishAustralian = 47, - EnglishCanadian = 48, - EnglishIreland = 49, - EnglishNewZealand = 50, - EnglishSouthAfrica = 51, - EnglishUk = 52, - EnglishUsa = 13, - Estonian = 53, - Faeroese = 54, - Farsi = 55, - Finnish = 4, - French = 5, - FrenchBelgian = 56, - FrenchCanadian = 3, - FrenchLuxembourg = 57, - FrenchSwiss = 58, - German = 6, - GermanAustrian = 59, - GermanLuxembourg = 60, - GermanLiechtenstein = 61, - GermanSwiss = 62, - Greek = 63, - Hebrew = 64, - Hungarian = 65, - Icelandic = 7, - Indonesian = 66, - Italian = 8, - ItalianSwiss = 67, - Japanese = 68, - Korean = 69, - KoreanJohab = 70, - Latvian = 71, - Lithuanian = 72, - Norwegian = 9, - NorwegianBokmal = 73, - NorwegianNynorsk = 74, - Polish = 75, - Portuguese = 10, - PortugueseBrazil = 76, - Romanian = 77, - Russian = 78, - SerbianLatin = 79, - Slovak = 80, - Slovenian = 81, - Spanish = 11, - SpanishMexican = 82, - SpanishModern = 83, - Swedish = 12, - Thai = 84, - Turkish = 85, - Ukranian = 86, - Assamese = 87, - Bengali = 88, - Bihari = 89, - Bodo = 90, - Dogri = 91, - Gujarati = 92, - Haryanvi = 93, - Hindi = 94, - Kannada = 95, - Kashmiri = 96, - Malayalam = 97, - Marathi = 98, - Marwari = 99, - Meghalayan = 100, - Mizo = 101, - Naga = 102, - Orissi = 103, - Punjabi = 104, - Pushtu = 105, - SerbianCyrillic = 106, - Sikkimi = 107, - SwedishFinland = 108, - Tamil = 109, - Telugu = 110, - Tripuri = 111, - Urdu = 112, - Vietnamese = 113 -}; - -/// Values of CapType::ILightPath. -enum class LightPath : UInt16 { - Reflective = 0, - Transmissive = 1 -}; - -/// Values of CapType::ILightSource. -enum class LightSource : UInt16 { - Red = 0, - Green = 1, - Blue = 2, - None = 3, - White = 4, - Uv = 5, - Ir = 6 -}; - -/// Values for CapType::IMirror. -enum class Mirror : UInt16 { - None = 0, - Vertical = 1, - Horizontal = 2 -}; - -/// Values of possible actions of TWAIN operations. -enum class Msg : UInt16 { - Null = 0x0000, - Get = 0x0001, - GetCurrent = 0x0002, - GetDefault = 0x0003, - GetFirst = 0x0004, - GetNext = 0x0005, - Set = 0x0006, - Reset = 0x0007, - QuerySupport = 0x0008, - GetHelp = 0x0009, - GetLabel = 0x000a, - GetLabelEnum = 0x000b, - SetConstraint = 0x000c, - XferReady = 0x0101, - CloseDsReq = 0x0102, - CloseDsOk = 0x0103, - DeviceEvent = 0x0104, - OpenDsm = 0x0301, - CloseDsm = 0x0302, - OpenDs = 0x0401, - CloseDs = 0x0402, - UserSelect = 0x0403, - DisableDs = 0x0501, - EnableDs = 0x0502, - EnableDsUiOnly = 0x0503, - ProcessEvent = 0x0601, - EndXfer = 0x0701, - StopFeeder = 0x0702, - ChangeDir = 0x0801, - CreateDir = 0x0802, - Delete = 0x0803, - FormatMedia = 0x0804, - GetClose = 0x0805, - GetFirstFile = 0x0806, - GetInfo = 0x0807, - GetNextFile = 0x0808, - Rename = 0x0809, - Copy = 0x080A, - AutomaticCaptureDir = 0x080B, - PassThrough = 0x0901, - RegisterCallback = 0x0902, - ResetAll = 0x0A01, - CustomBase = 0x8000 -}; - -/// Capability action support flags. -enum class MsgSupport : Int32 { - Get = 0x0001, - Set = 0x0002, - GetDefault = 0x0004, - GetCurrent = 0x0008, - Reset = 0x0010, - SetConstraint = 0x0020, - GetHelp = 0x0100, - GetLabel = 0x0200, - GetLabelEnum = 0x0400 -}; - -static inline constexpr MsgSupport operator|(MsgSupport a, MsgSupport b){ - return static_cast(static_cast(a) | static_cast(b)); -} - -static inline constexpr MsgSupport operator&(MsgSupport a, MsgSupport b){ - return static_cast(static_cast(a) & static_cast(b)); -} - -static inline constexpr MsgSupport operator^(MsgSupport a, MsgSupport b){ - return static_cast(static_cast(a) ^ static_cast(b)); -} - -/// Action support flags, nothing supported. -static constexpr const MsgSupport msgSupportEmpty = static_cast(0); - -/// Action support flags, all `get` actions. -static constexpr const MsgSupport msgSupportGetAll = MsgSupport::Get | MsgSupport::GetDefault | MsgSupport::GetCurrent; - -/// Action support flags, all `get` actions, `set` and `reset`. -static constexpr const MsgSupport msgSupportGetAllSetReset = msgSupportGetAll | MsgSupport::Set | MsgSupport::Reset; - -/// Values for CapType::INoiseFilter. -enum class NoiseFilter : UInt16 { - None = 0, - Auto = 1, - LonePixel = 2, - MajorityRule = 3 -}; - -/// Values for CapType::IOrientation. -enum class Orientation : UInt16 { - Rot0 = 0, - Rot90 = 1, - Rot180 = 2, - Rot270 = 3, - Portrait = 0, - Landscape = 3, - Auto = 4, - AutoText = 5, - AutoPicture = 6 -}; - -/// Values for CapType::IOverscan. -enum class OverScan : UInt16 { - None = 0, - Auto = 1, - TopBottom = 2, - LeftRight = 3, - All = 4 -}; - -/// Values for CapType::PaperHandling. -enum class PaperHandling : UInt16 { - Normal = 0, - Fragile = 1, - Thick = 2, - TriFold = 3, - Photograph = 4 -}; - -/// Values for CapType::ISupportedSizes. -enum class PaperSize : UInt16 { - None = 0, - A4 = 1, - JisB5 = 2, - UsLetter = 3, - UsLegal = 4, - A5 = 5, - IsoB4 = 6, - IsoB6 = 7, - UsLedger = 9, - UsExecutive = 10, - A3 = 11, - IsoB3 = 12, - A6 = 13, - C4 = 14, - C5 = 15, - C6 = 16, - Ps4A0 = 17, // 4A0 - Ps2A0 = 18, // 2A0 - A0 = 19, - A1 = 20, - A2 = 21, - A7 = 22, - A8 = 23, - A9 = 24, - A10 = 25, - IsoB0 = 26, - IsoB1 = 27, - IsoB2 = 28, - IsoB5 = 29, - IsoB7 = 30, - IsoB8 = 31, - IsoB9 = 32, - IsoB10 = 33, - JisB0 = 34, - JisB1 = 35, - JisB2 = 36, - JisB3 = 37, - JisB4 = 38, - JisB6 = 39, - JisB7 = 40, - JisB8 = 41, - JisB9 = 42, - JisB10 = 43, - C0 = 44, - C1 = 45, - C2 = 46, - C3 = 47, - C7 = 48, - C8 = 49, - C9 = 50, - C10 = 51, - UsStatement = 52, - BusinessCard = 53, - MaxSize = 54 -}; - -/// Values for CapType::IPixelFlavor, CapType::IPixelFlavorCodes, InfoId::PixelFlavor. -/// Chocolate - pixel represents darkest data. -/// Vanilla - pixel represents lightest data. -enum class PixelFlavor : UInt16 { - Chocolate = 0, - Vanilla = 1 -}; - -/// Values for CapType::IPixelType, ImageInfo. -enum class PixelType : UInt16 { - BlackWhite = 0, - Gray = 1, - Rgb = 2, - Palette = 3, - Cmy = 4, - Cmyk = 5, - Yuv = 6, - Yuvk = 7, - CieXyz = 8, - Lab = 9, - SRgb = 10, - ScRgb = 11, - Infrared = 16 -}; - -/// Values for CapType::PowerSupply. -enum class PowerSupply : UInt16 { // Capability->UInt16, DeviceEvent->Int32 - External = 0, - Battery = 1, -}; - -/// Values for CapType::Printer. -enum class Printer : UInt16 { - ImprinterTopBefore = 0, - ImprinterTopAfter = 1, - ImprinterBottomBefore = 2, - ImprinterBottomAfter = 3, - EndorserTopBefore = 4, - EndorserTopAfter = 5, - EndorserBottomBefore = 6, - EndorserBottomAfter = 7 -}; - -/// Values for CapType::PrinterMode. -enum class PrinterMode : UInt16 { - SingleString = 0, - MultiString = 1, - CompoundString = 2 -}; - -enum class ReturnCode : UInt16 { - Success = 0, - Failure = 1, - CheckStatus = 2, - Cancel = 3, - DsEvent = 4, - NotDsEvent = 5, - XferDone = 6, - EndOfList = 7, - InfoNotSupported = 8, - DataNotAvailable = 9, - Busy = 10, - ScannerLocked = 11, - - CustomBase = 0x8000 -}; - -typedef ReturnCode RC; - -static inline constexpr bool success(ReturnCode rc) noexcept{ - return rc == RC::Success; -} - - -/// Values for CapType::IBarCodeSearchMode. -enum class SearchMode : UInt16 { - Horizontal = 0, - Vertical = 1, - HorizVert = 2, - VertHoriz = 3 -}; - -/// Values for CapType::Segmented. -enum class Segmented : UInt16 { - None = 0, - Auto = 1, - Manual = 2 -}; - -/// TWAIN manager states. -enum class DsmState : UInt16 { - PreSession = 1, - Loaded = 2, - Open = 3 -}; - -/// TWAIN source states. -enum class DsState : UInt16 { - Closed = 3, - Open = 4, - Enabled = 5, - XferReady = 6, - Xferring = 7 -}; - -/// Values for CapType::IUnits. -enum class Unit : UInt16 { - Inches = 0, - CentiMetres = 1, - Picas = 2, - Points = 3, - Twips = 4, - Pixels = 5, - MilliMetres = 6 -}; - -/// Values for CapType::IXferMech, CapType::AXferMech. -enum class XferMech : UInt16 { - Native = 0, - File = 1, - Memory = 2, - MemFile = 4, -}; - - -/// Type of the extended information. -enum class InfoId : UInt16 { - BarCodeX = 0x1200, - BarCodeY = 0x1201, - BarCodeText = 0x1202, - BarCodeType = 0x1203, - DeShadeTop = 0x1204, - DeShadeLeft = 0x1205, - DeShadeHeight = 0x1206, - DeShadeWidth = 0x1207, - DeShadeSize = 0x1208, - SpecklesRemoved = 0x1209, - HorzLineXCoord = 0x120A, - HorzLineYCoord = 0x120B, - HorzLineLength = 0x120C, - HorzLineThickness = 0x120D, - VertLineXCoord = 0x120E, - VertLineYCoord = 0x120F, - VertLineLength = 0x1210, - VertLineThickness = 0x1211, - PatchCode = 0x1212, - EndorsedText = 0x1213, - FormConfidence = 0x1214, - FormTemplateMatch = 0x1215, - FormTemplatePageMatch = 0x1216, - FormHorzDocOffset = 0x1217, - FormVertDocOffset = 0x1218, - BarCodeCount = 0x1219, - BarCodeConfidence = 0x121A, - BarCodeRotation = 0x121B, - BarCodeTextLength = 0x121C, - DeShadeCount = 0x121D, - DeShadeBlackCountOld = 0x121E, - DeShadeBlackCountNew = 0x121F, - DeShadeBlackRlMin = 0x1220, - DeShadeBlackRlMax = 0x1221, - DeShadeWhiteCountOld = 0x1222, - DeShadeWhiteCountNew = 0x1223, - DeShadeWhiteRlMin = 0x1224, - DeShadEWhiteRlAve = 0x1225, - DeShadeWhiteRlMax = 0x1226, - BlackSpecklesRemoved = 0x1227, - WhiteSpecklesRemoved = 0x1228, - HorzLineCount = 0x1229, - VertLineCount = 0x122A, - DeskewStatus = 0x122B, - SkewOriginalAngle = 0x122C, - SkewFinalAngle = 0x122D, - SkewConfidence = 0x122E, - SkewWindowX1 = 0x122F, - SkewWindowY1 = 0x1230, - SkewWindowX2 = 0x1231, - SkewWindowY2 = 0x1232, - SkewWindowX3 = 0x1233, - SkewWindowY3 = 0x1234, - SkewWindowX4 = 0x1235, - SkewWindowY4 = 0x1236, - BookName = 0x1238, - ChapterNumber = 0x1239, - DocumentNumber = 0x123A, - PageNumber = 0x123B, - Camera = 0x123C, - FrameNumber = 0x123D, - Frame = 0x123E, - PixelFlavor = 0x123F, - IccProfile = 0x1240, - LastSegment = 0x1241, - SegmentNumber = 0x1242, - MagData = 0x1243, - MagType = 0x1244, - PageSide = 0x1245, - FileSystemSource = 0x1246, - ImageMerged = 0x1247, - MagDataLength = 0x1248, - PaperCount = 0x1249, - PrinterText = 0x124A -}; - -/// Values for InfoId::BarCodeRotation. -enum class BarCodeRotation : UInt16 { - Rot0 = 0, - Rot90 = 1, - Rot180 = 2, - Rot270 = 3, - RotUnknown = 4 -}; - -/// Values for InfoId::PageSide. -enum class PageSide : UInt16 { - Top = 1, - Bottom = 2 -}; - -/// Values for InfoId::DeskewStatus. -enum class DeskewStatus : UInt16 { - Success = 0, - ReportOnly = 1, - Fail = 2, - Disabled = 3 -}; - -/// Values for InfoId::MagType. -enum class MagType : UInt16 { - Micr = 0, - Raw = 1, - Invalid = 2 -}; - -/// Values for InfoId::PatchCode. -enum class PatchCode : UInt16 { - P1 = 0, - P2 = 1, - P3 = 2, - P4 = 3, - P6 = 4, - PT = 5 -}; - -} - -#endif // TWPP_DETAIL_FILE_ENUMS_HPP - diff --git a/twain/twain/twpp/env.hpp b/twain/twain/twpp/env.hpp deleted file mode 100644 index fae3d4b..0000000 --- a/twain/twain/twpp/env.hpp +++ /dev/null @@ -1,356 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015-2017 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_ENV_HPP -#define TWPP_DETAIL_FILE_ENV_HPP - -// ============= -// Twpp specific - -namespace Twpp { - -namespace Detail { - -enum { - ProtoMajor = 2, - ProtoMinor = 3, - Dsm2 = 0x10000000L, - App2 = 0x20000000L, - Ds2 = 0x40000000L -}; - -} - -} - -#if defined(TWPP_IS_DS) -# define TWPP_DETAIL_IS_DS 1 -#else -# define TWPP_DETAIL_IS_DS 0 -#endif - - -// =========== -// OS specific - -// Windows -#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) -# define TWPP_DETAIL_OS_WIN 1 -# if defined(WIN64) || defined(_WIN64) -# define TWPP_DETAIL_OS_WIN64 1 -# else -# define TWPP_DETAIL_OS_WIN32 1 -# endif -# if !defined(WIN32_LEAN_AND_MEAN) -# define WIN32_LEAN_AND_MEAN -# endif -# if !defined(NOMINMAX) -# define NOMINMAX -# endif -extern "C" { -# include -} -# define TWPP_DETAIL_CALLSTYLE PASCAL -# define TWPP_DETAIL_EXPORT __declspec(dllexport) -namespace Twpp { - -namespace Detail { - -typedef HANDLE RawHandle; - - -namespace DsmLibOs { - -typedef HMODULE Handle; -static constexpr const Handle nullHandle = nullptr; - -template -static inline T resolve(Handle h) noexcept{ - return reinterpret_cast(::GetProcAddress(h, "DSM_Entry")); -} - -# if defined(TWPP_DETAIL_OS_WIN32) -static inline Handle load(bool old) noexcept{ - if (old){ - auto h = ::LoadLibraryA("TWAIN_32.dll"); - if (!h){ - h = ::LoadLibraryA("TWAINDSM.dll"); - } - - return h; - } else { - auto h = ::LoadLibraryA("TWAINDSM.dll"); - if (!h){ - h = ::LoadLibraryA("TWAIN_32.dll"); - } - - return h; - } -} -# else -static inline Handle load(bool) noexcept{ - return ::LoadLibraryA("TWAINDSM.dll"); -} -# endif - -static inline void unload(Handle h) noexcept{ - ::FreeLibrary(h); -} - -} // namespace DsmLibOs - -} // namespace Detail - -} // namespace Twpp - - -// Mac OS -#elif defined(__APPLE__) -# pragma message "No testing has been done on this platform, this framework might not work correctly." -# define TWPP_DETAIL_OS_MAC 1 -# include -extern "C" { -# include -# include -# include -# include -# include -} -# define TWPP_DETAIL_CALLSTYLE pascal -namespace Twpp { - -namespace Detail { - -typedef Handle RawHandle; - - -namespace DsmLibOs { - -typedef void* Handle; -static constexpr const Handle nullHandle = nullptr; - -template -static inline T resolve(Handle h) noexcept{ - return reinterpret_cast(::dlsym(h, "DSM_Entry")); -} - -static inline Handle load(bool) noexcept{ - return ::dlopen("/System/Library/Frameworks/TWAIN.framework/TWAIN", RTLD_LAZY); -} - -static inline void unload(Handle h) noexcept{ - ::dlclose(h); -} - -} // namespace DsmLibOs - -template -struct MacStatic { - - static const ::Class g_autoreleasePool; - static const ::SEL g_release; - static const ::SEL g_alloc; - static const ::SEL g_init; - - static const ::SEL g_nextEvent; - static const ::SEL g_postEvent; - static const ::SEL g_sendEvent; - static const ::id g_app; - static const ::id g_distantFuture; - - static const ::Class g_event; - static const ::SEL g_otherEventWithType; - -}; - -template const ::Class MacStatic::g_autoreleasePool = objc_getClass("NSAutoreleasePool"); -template const ::SEL MacStatic::g_release = sel_registerName("release"); -template const ::SEL MacStatic::g_alloc = sel_registerName("alloc"); -template const ::SEL MacStatic::g_init = sel_registerName("init"); - -template const ::SEL MacStatic::g_nextEvent = sel_registerName("nextEventMatchingMask:untilDate:inMode:dequeue:"); -template const ::SEL MacStatic::g_postEvent = sel_registerName("postEvent:atStart:"); -template const ::SEL MacStatic::g_sendEvent = sel_registerName("sendEvent:"); -template const ::id MacStatic::g_app = objc_msgSend(reinterpret_cast<::id>(objc_getClass("NSApplication")), sel_registerName("sharedApplication")); -template const ::id MacStatic::g_distantFuture = objc_msgSend(reinterpret_cast<::id>(objc_getClass("NSDate")), sel_registerName("distantFuture")); - -template const ::Class MacStatic::g_event = objc_getClass("NSEvent"); -template const ::SEL MacStatic::g_otherEventWithType = sel_registerName("otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:"); - -class NSAutoreleasePool { - -public: - NSAutoreleasePool() noexcept : - m_id(createPool()) {} - - ~NSAutoreleasePool(){ - release(); - } - - NSAutoreleasePool(const NSAutoreleasePool&) = delete; - NSAutoreleasePool& operator=(const NSAutoreleasePool&) = delete; - - NSAutoreleasePool(NSAutoreleasePool&& o) noexcept : - m_id(o.m_id){ - - o.m_id = nullptr; - } - - NSAutoreleasePool& operator=(NSAutoreleasePool&& o) noexcept{ - if (this != &o){ - release(); - std::swap(m_id, o.m_id); - } - - return *this; - } - - void release() noexcept{ - if (m_id != nullptr){ - objc_msgSend(m_id, MacStatic::g_release); - m_id = nullptr; - } - } - -private: - static ::id createPool() noexcept{ - auto poolId = objc_msgSend(reinterpret_cast<::id>(MacStatic::g_autoreleasePool), MacStatic::g_alloc); - return objc_msgSend(poolId, MacStatic::g_init); - } - - ::id m_id; - -}; - -namespace NSLoop { - -static constexpr ::NSUInteger NSAnyEventMask = std::numeric_limits<::NSUInteger>::max(); -static constexpr ::NSUInteger NSApplicationDefined = 15; - -static void processEvent() noexcept{ - auto event = objc_msgSend(MacStatic::g_app, MacStatic::g_nextEvent, NSAnyEventMask, MacStatic::g_distantFuture, kCFRunLoopDefaultMode, YES); - objc_msgSend(MacStatic::g_app, MacStatic::g_sendEvent, event); -} - -static void postDummy() noexcept{ - auto event = objc_msgSend(reinterpret_cast<::id>(MacStatic::g_event), MacStatic::g_otherEventWithType, NSApplicationDefined, nullptr, 1, 0.0, 0, nullptr, static_cast(0), 0, 0); - objc_msgSend(MacStatic::g_app, MacStatic::g_postEvent, event, NO); -} - -} // namespace NSLoop - -} // namespace Detail - -} // namespace Twpp - -// Linux -#elif defined(__linux__) -# warning "No testing has been done on this platform, this framework might not work correctly." -# define TWPP_DETAIL_OS_LINUX 1 -extern "C" { -# include -} -# define TWPP_DETAIL_CALLSTYLE -namespace Twpp { - -namespace Detail { - -typedef void* RawHandle; - - -namespace DsmLibOs { - -typedef void* Handle; -static constexpr const Handle nullHandle = nullptr; - -template -static inline T resolve(Handle h) noexcept{ - return reinterpret_cast(::dlsym(h, "DSM_Entry")); -} - -static inline Handle load(bool) noexcept{ - return ::dlopen("libtwaindsm.so", RTLD_LAZY); -} - -static inline void unload(Handle h) noexcept{ - ::dlclose(h); -} - -} // namespace DsmLibOs - -} // namespace Detail - -} // namespace Twpp - -// fail everything else -#else -# error "unsupported platform, supports only Windows, Mac OS and Linux" -#endif - - -// ================= -// compiler specific - -// MSVC -#if defined(_MSC_VER) -# define TWPP_DETAIL_PACK_BEGIN \ - __pragma(pack (push, beforeTwpp)) \ - __pragma(pack (2)) -# define TWPP_DETAIL_PACK_END __pragma(pack (pop, beforeTwpp)); - -// GNU or CLang -#elif defined(__GNUC__) || defined(__clang__) -# if defined(TWPP_DETAIL_OS_MAC) -# define TWPP_DETAIL_PACK_BEGIN _Pragma("options align = power") -# define TWPP_DETAIL_PACK_END _Pragma("options align = reset") -# else -# define TWPP_DETAIL_PACK_BEGIN \ - _Pragma("pack (push, beforeTwpp)") \ - _Pragma("pack (2)") -# define TWPP_DETAIL_PACK_END _Pragma("pack (pop, beforeTwpp)") -# endif -# if !defined(TWPP_DETAIL_EXPORT) -# define TWPP_DETAIL_EXPORT __attribute__((__visibility__("default"))) -# endif - -// Borland -#elif defined(__BORLAND__) || defined(__BORLANDC__) || defined(__CODEGEARC__) -# define TWPP_DETAIL_PACK_BEGIN _Pragma("option -a2") -# define TWPP_DETAIL_PACK_END _Pragma("option -a") - -// fail everything else -#else -# error "unsupported compiler, please define your own TWPP_DETAIL_PACK_BEGIN and TWPP_DETAIL_PACK_END and possibly TWPP_DETAIL_EXPORT in twpp/env.hpp and send me your patch" -#endif - - -#if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1900) // msvc2015 -# error "C++11 or later is required" -#endif - - -#endif // TWPP_DETAIL_FILE_ENV_HPP - diff --git a/twain/twain/twpp/event.hpp b/twain/twain/twpp/event.hpp deleted file mode 100644 index 1aff32d..0000000 --- a/twain/twain/twpp/event.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_EVENT_HPP -#define TWPP_DETAIL_FILE_EVENT_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Loop event on Windows. -/// Used while waiting for transfer. -/// See manual for more info. -class Event { - -public: - constexpr Event() noexcept : - m_event(nullptr), m_msg(Msg::Null){} - - constexpr Event(void* event, Msg msg) noexcept : - m_event(event), m_msg(msg){} - - constexpr void* event() const noexcept{ - return m_event; - } - - void setEvent(void* event) noexcept{ - m_event = event; - } - - constexpr Msg message() const noexcept{ - return m_msg; - } - - void setMessage(Msg msg) noexcept{ - m_msg = msg; - } - -private: - void* m_event; - Msg m_msg; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_EVENT_HPP diff --git a/twain/twain/twpp/exception.hpp b/twain/twain/twpp/exception.hpp deleted file mode 100644 index 3aa34dc..0000000 --- a/twain/twain/twpp/exception.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef TWPP_DETAIL_FILE_EXCEPTION_HPP -#define TWPP_DETAIL_FILE_EXCEPTION_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -/// Base class of TWPP exceptions. -class Exception : public std::exception { - -public: - virtual const char* what() const noexcept override{ - return "General TWPP error."; - } - -}; - -/// Invalid type exception. -/// Used when an invalid or unsupported type identifier is used. -class TypeException : public Exception { - -public: - virtual const char* what() const noexcept override{ - return "Invalid type."; - } - -}; - -/// Value out of valid range exception. -class RangeException : Exception { - -public: - virtual const char* what() const noexcept override{ - return "Value out of allowed range."; - } - -}; - -} - -#endif // TWPP_DETAIL_FILE_EXCEPTION_HPP - diff --git a/twain/twain/twpp/extimageinfo.hpp b/twain/twain/twpp/extimageinfo.hpp deleted file mode 100644 index f2a3246..0000000 --- a/twain/twain/twpp/extimageinfo.hpp +++ /dev/null @@ -1,547 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_EXTIMAGEINFO_HPP -#define TWPP_DETAIL_FILE_EXTIMAGEINFO_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -namespace Detail { - -/// Mapping of info type to type identifier and data type. -template struct Ext {}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef BarCodeRotation DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::Handle; typedef char DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef BarCodeType DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef PatchCode DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef DeskewStatus DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::Frame; typedef Frame DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt16; typedef PixelFlavor DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::UInt16; typedef MagType DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::Bool; typedef Bool DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::Str255; typedef char DataType;}; // NOTE: InfoId::MagData may also contain Handle -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; -template<> struct Ext {static constexpr const Type twty = Type::UInt16; typedef PageSide DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::UInt32; typedef UInt32 DataType;}; - -template<> struct Ext {static constexpr const Type twty = Type::Str255; typedef Str255 DataType;}; - -} - -class Info; -class ExtImageInfo; - -namespace Detail { - -static Handle handleItem(Info& info) noexcept; - -static void deleteInfo(Info& info) noexcept; - -} - -TWPP_DETAIL_PACK_BEGIN -/// Extended image information entry. -class Info { - - friend class ExtImageInfo; - friend Handle Detail::handleItem(Info& info) noexcept; - friend void Detail::deleteInfo(Info& info) noexcept; - static constexpr const UInt32 DATA_HANDLE_THRESHOLD = sizeof(UIntPtr); // NOTE: specification says 4 bytes, yet pointer size makes more sense - -public: - template - class Items { - - friend class Info; - - public: - typedef Detail::MaybeLock Data; - - constexpr Items() noexcept : - m_parent(nullptr){} - - Items(const Items&) = default; - Items& operator=(const Items&) = default; - - Items(Items&&) = default; - Items& operator=(Items&&) = default; - - operator bool() const noexcept{ - return m_data; - } - - Data at(UInt32 i) const{ - if (m_parent->hasDataHandle() && m_parent->type() == Type::Handle){ - return reinterpret_cast(m_data.data())[i]; - } else { - return reinterpret_cast(m_data.data() + i * typeSize(m_parent->type())); - } - } - - Data operator[](UInt32 i) const{ - return at(i); - } - - private: - Items(Info& parent, Detail::MaybeLock data) noexcept : - m_parent(&parent), m_data(data){} - - Info* m_parent; - Detail::MaybeLock m_data; - // [items] <=> !(big and handle) - // [handles]->handles*[items] <=> big and handle (this should teoretically not happen) - - }; - - Info(const Info&) = delete; - Info& operator=(const Info&) = delete; - - Info(Info&&) = delete; - Info& operator=(Info&&) = delete; - - /// Information type ID. - InfoId id() const noexcept{ - return m_infoId; - } - - /// Information data type ID. - Type type() const noexcept{ - return m_itemType; - } - - /// Number of items in this entry. - UInt16 size() const noexcept{ - return m_numItems; - } - - /// Allocates space for the supplied number of items. - /// Allocating handles is not supported. - /// \tparam id Information type ID. Data types are set accordingly. - /// \param count Number of items to allocate. - /// \throw TypeException When `type` is handle or invalid. - /// \throw std::bad_alloc - template - void allocSimple(UInt16 count = 1){ - allocSimple(Detail::Ext::twty, count); - } - - /// Allocates space for the supplied number of items. - /// Allocating handles is not supported. - /// \param type Data type ID. - /// \param count Number of items to allocate. - /// \throw TypeException When `type` is handle or invalid. - /// \throw std::bad_alloc - void allocSimple(Type type, UInt16 count = 1){ - if (type == Type::Handle){ - throw TypeException(); - } - - if (type == m_itemType && count == m_numItems){ - return; - } - - auto itemSize = typeSize(type); - - bool big = hasDataHandle(type, count); - // [items] <=> !big - // handle->[items] <=> big - - Detail::UniqueHandle newItem; - if (big){ - newItem = Detail::alloc(itemSize * count); - } - - Detail::deleteInfo(*this); - - if (big){ - *Detail::alias_cast(&m_item) = newItem.release(); - } - - m_itemType = type; - m_numItems = count; - } - - /// Allocates a single memory area owned by a handle. - /// Info type changes to handle. - /// \param itemSize Number of bytes to allocate. - /// \throw std::bad_alloc - void allocHandle(UInt32 itemSize){ - // handle->[chars] - auto newItem = Detail::UniqueHandle(Detail::alloc(itemSize)); - - Detail::deleteInfo(*this); - *Detail::alias_cast(&m_item) = newItem.release(); - - m_itemType = Type::Handle; - m_numItems = 1; - } - - /// Status of this entry. - ReturnCode returnCode() const noexcept{ - return m_returnCode; - } - - /// Sets status of this entry. - void setReturnCode(ReturnCode rc) noexcept{ - m_returnCode = rc; - } - - /// Returns items contained in this entry. - /// \tparam type ID of the internal data type. - /// \tparam DataType Exported data type. - /// \throw TypeException When types don't match. - template - Items items(){ - if (type != m_itemType || (type != Type::Handle && typeSize(type) != sizeof(DataType))){ - throw TypeException(); - } - - return itemsPriv(); - } - - /// Returns items contained in this entry. - /// \tparam type ID of the internal data type. - /// \throw TypeException When types don't match. - template - Items::Type> items(){ - if (type != m_itemType){ - throw TypeException(); - } - - return itemsPriv::Type>(); - } - - /// Returns items contained in this entry. - /// \tparam id Information type ID. Data types are set accordingly. - /// \throw TypeException When types don't match. - template - Items::DataType> items(){ - if (Detail::Ext::twty != m_itemType){ - throw TypeException(); - } - - return itemsPriv::DataType>(); - } - -private: - bool hasDataHandle() const{ - return hasDataHandle(type(), size()); - } - - static bool hasDataHandle(Type type, UInt16 size){ - return type != Type::DontCare && size * typeSize(type) > DATA_HANDLE_THRESHOLD; - } - - template - Items itemsPriv(){ - bool big = hasDataHandle(); - bool handle = m_itemType == Type::Handle; - - Detail::MaybeLock lock; - if (!big && !handle){ - lock = Detail::alias_cast(&m_item); - } else { - lock = *Detail::alias_cast(&m_item); - } - - return {*this, std::move(lock)}; - } - - template - static bool arrContains(const T(& arr)[len], const T& val) noexcept{ - for (std::size_t i = 0; i < len; i++){ - if (arr[i] == val){ - return true; - } - } - - return false; - } - - InfoId m_infoId; - Type m_itemType; - UInt16 m_numItems; - ReturnCode m_returnCode; - UIntPtr m_item; - // [items] <=> !big and !handle - // handle->[items] <=> big xor handle - // handle->[handles]->handles*[items] <=> big and handle (this should teoretically not happen) - -}; - -namespace Detail { - -static inline Handle handleItem(Info& info) noexcept{ - return Handle(*Detail::alias_cast(&info.m_item)); -} - -static inline void deleteInfo(Info& info) noexcept{ - bool big = isType(info.type()) && info.hasDataHandle(); - bool handle = info.type() == Type::Handle; - - // [items] <=> !big and !handle - // handle->[items] <=> big xor handle - // handle->[handles]->handles*[items] <=> big and handle (this should teoretically not happen) - - if (big && handle){ - Detail::Lock lock(handleItem(info)); - for (UInt16 i = 0; i < info.size(); i++){ - Detail::free(lock.data()[i]); - } - } - - if (big || handle){ - Detail::free(handleItem(info)); - } -} - -struct ExtImageInfoData { - UInt32 m_numInfos; - Info m_infos[1]; -}; - -} - -TWPP_DETAIL_PACK_END -/// Extended image information. -/// Application sends list of info IDs, -/// source sets their data. -class ExtImageInfo { - -public: - typedef Info* iterator; - typedef const Info* const_iterator; - - /// Creates an invalid object. - ExtImageInfo() noexcept {} - - /// Creates a new structure for all supplied info IDs. - /// Sources must not call this constructor, they - /// are required to fill data in existing instance. - /// \param ids List of requested info IDs to be filled in by the source. - ExtImageInfo(std::initializer_list ids) : - m_data(new char[sizeof(Detail::ExtImageInfoData) - sizeof(Info) + ids.size() * sizeof(Info)]()) { - - d()->m_numInfos = static_cast(ids.size()); - - Info* infos = d()->m_infos; - - UInt32 i = 0; - for (auto id : ids) { - auto& info = infos[i]; - i++; - - info.m_infoId = id; - info.m_itemType = Type::DontCare; - } - } - void set_data(const std::list& ids) noexcept { - m_data.reset(new char[sizeof(Detail::ExtImageInfoData) - sizeof(Info) + ids.size() * sizeof(Info)]); - - d()->m_numInfos = static_cast(ids.size()); - - Info* infos = d()->m_infos; - UInt32 i = 0; - for (const auto id : ids) { - auto& info = infos[i]; - i++; - - info.m_infoId = id; - info.m_itemType = Type::DontCare; - } - } - - ExtImageInfo(ExtImageInfo&&) = default; - ExtImageInfo& operator=(ExtImageInfo&&) = default; - - operator bool() const noexcept{ - return isValid(); - } - - bool isValid() const noexcept{ - return static_cast(m_data); - } - - /// Number of requested entries. - UInt32 size() const noexcept{ - assert(isValid()); - return d()->m_numInfos; - } - - /// Information entry. - Info& at(UInt32 i) noexcept{ - assert(isValid()); - return d()->m_infos[i]; - } - - /// Information entry. - const Info& at(UInt32 i) const noexcept{ - assert(isValid()); - return d()->m_infos[i]; - } - - Info& operator[](UInt32 i) noexcept{ - return at(i); - } - - const Info& operator[](UInt32 i) const noexcept{ - return at(i); - } - - - iterator begin() noexcept{ - assert(isValid()); - return d()->m_infos; - } - - const_iterator begin() const noexcept{ - return cbegin(); - } - - const_iterator cbegin() const noexcept{ - assert(isValid()); - return d()->m_infos; - } - - iterator end() noexcept{ - assert(isValid()); - return d()->m_infos + d()->m_numInfos; - } - - const_iterator end() const noexcept{ - return cend(); - } - - const_iterator cend() const noexcept{ - assert(isValid()); - return d()->m_infos + d()->m_numInfos; - } - -private: - Detail::ExtImageInfoData* d() noexcept{ - return reinterpret_cast(m_data.get()); - } - - Detail::ExtImageInfoData* d() const noexcept{ - return reinterpret_cast(m_data.get()); - } - - struct Deleter { - void operator()(char* ptr) noexcept{ - Detail::ExtImageInfoData* data = reinterpret_cast(ptr); - if (data){ - for (UInt32 i = 0; i < data->m_numInfos; i++){ - Detail::deleteInfo(data->m_infos[i]); - } - - delete [] ptr; - } - } - }; - - std::unique_ptr m_data; - -}; - -} - -#endif // TWPP_DETAIL_FILE_EXTIMAGEINFO_HPP - diff --git a/twain/twain/twpp/filesystem.hpp b/twain/twain/twpp/filesystem.hpp deleted file mode 100644 index b7bbc79..0000000 --- a/twain/twain/twpp/filesystem.hpp +++ /dev/null @@ -1,248 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_FILESYSTEM_HPP -#define TWPP_DETAIL_FILE_FILESYSTEM_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Structure representing device filesystem and operations on it. -class FileSystem { - -public: - /// Type of file. - enum class Type : Int32 { - Camera = 0, - CameraTop = 1, - CameraBottom = 2, - CameraPreview = 3, - Domain = 4, - Host = 5, - Directory = 6, - Image = 7, - Unknown = 8 - }; - - /// Creates uninitialized file system. - constexpr FileSystem() noexcept : - m_context(nullptr), m_recursiveBool(), m_fileType(Type::Camera), m_size(), - m_freeSpace(), m_newImageSize(), m_numberOfFiles(), m_numberOfSnippets(), - m_deviceGroupMask(), m_reserved(){} - - /// Creates file system with input and output paths and optional context. - constexpr FileSystem(const Str255& inputPath, const Str255& outputPath, void* context = nullptr) noexcept : - m_inputPath(inputPath), m_outputPath(outputPath), m_context(context), - m_recursiveBool(), m_fileType(Type::Camera), m_size(), m_freeSpace(), m_newImageSize(), - m_numberOfFiles(), m_numberOfSnippets(), m_deviceGroupMask(), m_reserved(){} - - /// Input or source file. - constexpr const Str255& inputPath() const noexcept{ - return m_inputPath; - } - - /// Sets input or source file. - void setInputPath(const Str255& path) noexcept{ - m_inputPath = path; - } - - /// Operation result, or destination file. - constexpr const Str255& outputPath() const noexcept{ - return m_outputPath; - } - - /// Sets operation result, or destination file. - void setOutputPath(const Str255& path) noexcept{ - m_outputPath = path; - } - - /// Source specific context. - constexpr void* context() const noexcept{ - return m_context; - } - - /// Sets source specific context. - void setContext(void* context) noexcept{ - m_context = context; - } - - /// Whether the operation is recursive. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::Delete. - constexpr Bool recursive() const noexcept{ - return m_recursiveBool; - } - - /// Sets whether the operation is recursive. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::Delete. - void setRecursive(Bool recursive) noexcept{ - m_recursiveBool = recursive; - } - - /// File type. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - constexpr Type type() const noexcept{ - return m_fileType; - } - - /// Sets file type. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - void setType(Type type) noexcept{ - m_fileType = type; - } - - /// Number of bytes of the entry. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - constexpr UInt32 size() const noexcept{ - return m_size; - } - - /// Sets number of bytes of the entry. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - void setSize(UInt32 size) noexcept{ - m_size = size; - } - - /// Creation date of the file. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - /// YYYY/MM/DD HH:mm:SS:sss - constexpr const Str32& createdTimeDate() const noexcept{ - return m_createdTimeDate; - } - - /// Sets creation date of the file. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - /// YYYY/MM/DD HH:mm:SS:sss - void setCreatedTimeDate(const Str32& val) noexcept{ - m_createdTimeDate = val; - } - - /// Modification date of the file. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - /// YYYY/MM/DD HH:mm:SS:sss - constexpr const Str32& modifiedTimeDate() const noexcept{ - return m_modifiedTimeDate; - } - - /// Sets modification date of the file. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - /// YYYY/MM/DD HH:mm:SS:sss - void setModifiedTimeDate(const Str32& val) noexcept{ - m_modifiedTimeDate = val; - } - - /// Number of bytes left on the device. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - constexpr UInt32 freeSpace() const noexcept{ - return m_freeSpace; - } - - /// Sets number of bytes left on the device. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - void setFreeSpace(UInt32 freeSpace) noexcept{ - m_freeSpace = freeSpace; - } - - /// Estimated image size in bytes. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - constexpr Int32 newImageSize() const noexcept{ - return m_newImageSize; - } - - /// Sets estimated image size in bytes. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - void setNewImageSize(Int32 newImageSize) noexcept{ - m_newImageSize = newImageSize; - } - - /// Total number of files including subdirectories. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - constexpr UInt32 files() const noexcept{ - return m_numberOfFiles; - } - - /// Sets total number of files including subdirectories. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - void setFiles(UInt32 files) noexcept{ - m_numberOfFiles = files; - } - - /// Number of audio snippets. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - constexpr UInt32 snippets() const noexcept{ - return m_numberOfSnippets; - } - - /// Sets number of audio snippets. - /// Valid for Msg::GetInfo, Msg::GetFileFirst and Msg::GetFileNext. - void snippets(UInt32 snippets) noexcept{ - m_numberOfSnippets = snippets; - } - - /// See manual for explanation of this field, `DeviceGroupMask`. - constexpr UInt32 groupMask() const noexcept{ - return m_deviceGroupMask; - } - - /// See manual for explanation of this field, `DeviceGroupMask`. - void groupMask(UInt32 groupMask) noexcept{ - m_deviceGroupMask = groupMask; - } - -private: - void unused() const{ - Detail::unused(m_reserved); - } - - Str255 m_inputPath; - Str255 m_outputPath; - void* m_context; - - // Copy, Delete - union { - int m_recursive; - Bool m_recursiveBool; - }; - - // GetInfo - Type m_fileType; - UInt32 m_size; - Str32 m_createdTimeDate; - Str32 m_modifiedTimeDate; - UInt32 m_freeSpace; - Int32 m_newImageSize; - UInt32 m_numberOfFiles; - UInt32 m_numberOfSnippets; - UInt32 m_deviceGroupMask; - Int8 m_reserved[508]; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_FILESYSTEM_HPP diff --git a/twain/twain/twpp/fix32.hpp b/twain/twain/twpp/fix32.hpp deleted file mode 100644 index fc99b79..0000000 --- a/twain/twain/twpp/fix32.hpp +++ /dev/null @@ -1,198 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_FIX32_HPP -#define TWPP_DETAIL_FILE_FIX32_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -namespace Detail { - -static constexpr inline Int32 floatToValue(float val){ - return static_cast( - (val >= 0.0f) ? - (val * 65536.0f + 0.5f) : - (val * 65536.0f - 0.5f) - ); -} - -static constexpr inline Int16 floatToWhole(float val){ - return static_cast(floatToValue(val) >> 16); -} - -static constexpr inline UInt16 floatToFrac(float val){ - return static_cast(floatToValue(val) & 0xFFFF); -} - -} - -TWPP_DETAIL_PACK_BEGIN -/// TWAIN fixed point fractional type. -/// The fractional part has resolution of 1/65536. -class Fix32 { - -public: - /// Creates zero-initialized fixed type. - constexpr Fix32() noexcept : - m_whole(0), m_frac(0){} - - /// Creates fixed type from float at compile time if possible. - constexpr Fix32(float value) noexcept : - m_whole(Detail::floatToWhole(value)), m_frac(Detail::floatToFrac(value)){} - - /// Creates fixed type from whole and fractional parts. - /// The fractional part has resolution of 1/65536. - constexpr Fix32(Int16 whole, UInt16 frac) noexcept : - m_whole(whole), m_frac(frac){} - - - /// Whole part of this fixed type. - constexpr Int16 whole() const noexcept{ - return m_whole; - } - - /// Sets whole part of this fixed type. - void setWhole(Int16 whole) noexcept{ - m_whole = whole; - } - - /// Fractional part of this fixed type. - /// Resolution of 1/65536. - constexpr UInt16 frac() const noexcept{ - return m_frac; - } - - /// Sets fractional part of this fixed type. - /// Resolution of 1/65536. - void setFrac(UInt16 frac) noexcept{ - m_frac = frac; - } - - explicit constexpr operator float() const noexcept{ - return m_whole + m_frac / 65536.0f; - } - - constexpr float toFloat() const noexcept{ - return m_whole + m_frac / 65536.0f; - } - - constexpr Fix32 operator-() const noexcept{ - return -toFloat(); - } - -private: - Int16 m_whole; - UInt16 m_frac; - -}; -TWPP_DETAIL_PACK_END - -namespace Detail { - -static inline constexpr Fix32 fix32AddHelper(Int32 frac, Int16 whole){ - return frac < 65536 ? Fix32(whole, frac) : Fix32(whole + 1, frac - 65536); -} - -static inline constexpr Fix32 fix32SubHelper(Int32 frac, Int16 whole){ - return frac >= 0 ? Fix32(whole, frac) : Fix32(whole - 1, frac + 65536); -} - -} - -static inline constexpr bool operator>(Fix32 a, Fix32 b) noexcept{ - return a.whole() > b.whole() || (a.whole() == b.whole() && a.frac() > b.frac()); -} - -static inline constexpr bool operator<(Fix32 a, Fix32 b) noexcept{ - return a.whole() < b.whole() || (a.whole() == b.whole() && a.frac() < b.frac()); -} - -static inline constexpr bool operator>=(Fix32 a, Fix32 b) noexcept{ - return !(a < b); -} - -static inline constexpr bool operator<=(Fix32 a, Fix32 b) noexcept{ - return !(a > b); -} - -static inline constexpr bool operator==(Fix32 a, Fix32 b) noexcept{ - return a.whole() == b.whole() && a.frac() == b.frac(); -} - -static inline constexpr bool operator!=(Fix32 a, Fix32 b) noexcept{ - return !(a == b); -} - -static inline constexpr Fix32 operator+(Fix32 a, Fix32 b) noexcept{ - return Detail::fix32AddHelper(static_cast(a.frac()) + b.frac(), a.whole() + b.whole()); -} - -static inline constexpr Fix32 operator-(Fix32 a, Fix32 b) noexcept{ - return Detail::fix32SubHelper(static_cast(a.frac()) - b.frac(), a.whole() - b.whole()); -} - -static inline constexpr Fix32 operator*(Fix32 a, Fix32 b) noexcept{ - return Fix32(static_cast(a) * static_cast(b)); -} - -static inline constexpr Fix32 operator/(Fix32 a, Fix32 b) noexcept{ // wonder about zero b - return Fix32(static_cast(a) / static_cast(b)); -} - -static inline Fix32& operator+=(Fix32& a, Fix32 b) noexcept{ - return a = a + b; -} - -static inline Fix32& operator-=(Fix32& a, Fix32 b) noexcept{ - return a = a - b; -} - -static inline Fix32& operator*=(Fix32& a, Fix32 b) noexcept{ - return a = a * b; -} - -static inline Fix32& operator/=(Fix32& a, Fix32 b) noexcept{ // wonder about zero b - return a = a / b; -} - -namespace Literals { - -static inline constexpr Fix32 operator "" _fix(long double val) noexcept{ - return Fix32(static_cast(val)); -} - -static inline constexpr Fix32 operator "" _fix(unsigned long long val) noexcept{ - return Fix32(static_cast(val)); -} - -} - -} - -#endif // TWPP_DETAIL_FILE_FIX32_HPP - diff --git a/twain/twain/twpp/frame.hpp b/twain/twain/twpp/frame.hpp deleted file mode 100644 index 7c87816..0000000 --- a/twain/twain/twpp/frame.hpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_FRAME_HPP -#define TWPP_DETAIL_FILE_FRAME_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Section of an image to retrieve. -class Frame { - -public: - /// Creates zero-initialized frame. - constexpr Frame() noexcept{} - - /// Creates frame with set top-left and bottom-right corners. - constexpr Frame(Fix32 left, Fix32 top, Fix32 right, Fix32 bottom) noexcept : - m_left(left), m_top(top), m_right(right), m_bottom(bottom){} - - /// Left position of the image frame. - constexpr Fix32 left() const noexcept{ - return m_left; - } - - /// Sets left position of the image frame. - void setLeft(Fix32 left) noexcept{ - m_left = left; - } - - /// Top position of the image frame. - constexpr Fix32 top() const noexcept{ - return m_top; - } - - /// Sets top position of the image frame. - void setTop(Fix32 top) noexcept{ - m_top = top; - } - - /// Right position of the image frame. - constexpr Fix32 right() const noexcept{ - return m_right; - } - - /// Sets right position of the image frame. - void setRight(Fix32 right) noexcept{ - m_right = right; - } - - /// Bottom position of the image frame. - constexpr Fix32 bottom() const noexcept{ - return m_bottom; - } - - /// Sets bottom position of the image frame. - void setBottom(Fix32 bottom) noexcept{ - m_bottom = bottom; - } - -private: - Fix32 m_left; - Fix32 m_top; - Fix32 m_right; - Fix32 m_bottom; - -}; -TWPP_DETAIL_PACK_END - -static constexpr inline bool operator==(const Frame& a, const Frame& b) noexcept{ - return a.left() == b.left() && a.top() == b.top() && a.right() == b.right() && a.bottom() == b.bottom(); -} - -static constexpr inline bool operator!=(const Frame& a, const Frame& b) noexcept{ - return !(a == b); -} - -} - -#endif // TWPP_DETAIL_FILE_FRAME_HPP - diff --git a/twain/twain/twpp/identity.hpp b/twain/twain/twpp/identity.hpp deleted file mode 100644 index b50e930..0000000 --- a/twain/twain/twpp/identity.hpp +++ /dev/null @@ -1,247 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015-2017 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_IDENTITY_HPP -#define TWPP_DETAIL_FILE_IDENTITY_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -namespace Detail { - -static constexpr const UInt32 identV2 = TWPP_DETAIL_IS_DS ? Detail::Ds2 : Detail::App2; - -} - -TWPP_DETAIL_PACK_BEGIN -/// Source or application version information. -class Version { - -public: - /// Creates default-initialized version. - constexpr Version() noexcept : - m_majorNum(0), m_minorNum(0), m_language(Language::English), - m_country(Country::UnitedKingdom){} - - /// Creates version initialized with supplied values. - constexpr Version( - UInt16 majorNumber, - UInt16 minorNumber, - Language language, - Country country, - const Str32& info = Str32()) noexcept : - m_majorNum(majorNumber), m_minorNum(minorNumber), m_language(language), - m_country(country), m_info(info){} - - /// Major version number of the source or application. - constexpr UInt16 majorNumber() const noexcept{ - return m_majorNum; - } - - /// Sets major version number of the source or application. - void setMajorNumber(UInt16 major) noexcept{ - m_majorNum = major; - } - - /// Minor version number of the source or application. - constexpr UInt16 minorNumber() const noexcept{ - return m_minorNum; - } - - /// Sets minor version number of the source or application. - void setMinorNumber(UInt16 minor) noexcept{ - m_minorNum = minor; - } - - /// Language of the source or application. - constexpr Language language() const noexcept{ - return m_language; - } - - /// Sets language of the source or application. - void setLanguage(Language language) noexcept{ - m_language = language; - } - - /// Original country of the source or application. - constexpr Country country() const noexcept{ - return m_country; - } - - /// Set original country of the source or application. - void setCountry(Country country) noexcept{ - m_country = country; - } - - /// Additional version information of the source or application. - constexpr const Str32& info() const noexcept{ - return m_info; - } - - /// Sets additional version information of the source or application. - void setInfo(const Str32& info) noexcept{ - m_info = info; - } - -private: - UInt16 m_majorNum; - UInt16 m_minorNum; - Language m_language; - Country m_country; - Str32 m_info; - -}; - -/// Source or application identity. -/// Uniquely identifies an endpoint. -class Identity { - -public: - typedef -#if defined(TWPP_DETAIL_OS_MAC) - void* -#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX) - UInt32 -#else -# error "Identity::Id for your platform here" -#endif - Id; - - /// Creates default-initialized identity. - /// ID is set to zero. - /// TWAIN protocol is always Detail::ProtoMajor and Detail::ProtoMinor. - /// Supported group always contains DG::Control and V2. - constexpr Identity() noexcept : - m_id(), m_protoMaj(Detail::ProtoMajor), m_protoMin(Detail::ProtoMinor), - m_groups(DataGroup::Control | Detail::identV2){} - - /// Creates identity initialized with supplied values. - /// ID is set to zero. - /// TWAIN protocol is always Detail::ProtoMajor and Detail::ProtoMinor. - /// Supported group always contains DG::Control and V2. - constexpr Identity( - const Version& version, - DataGroup group, - const Str32& manufacturer, - const Str32& productFamily, - const Str32& productName) noexcept : - m_id(), m_version(version), m_protoMaj(Detail::ProtoMajor), - m_protoMin(Detail::ProtoMinor), m_groups(DataGroup::Control | group | Detail::identV2), - m_manuf(manufacturer), m_prodFamily(productFamily), m_prodName(productName){} - - /// Creates identity initialized with supplied values. - constexpr Identity( - Id id, - const Version& version, - UInt16 protoMajor, - UInt16 protoMinor, - UInt32 groups, - const Str32& manufacturer, - const Str32& productFamily, - const Str32& productName) noexcept : - m_id(id), m_version(version), m_protoMaj(protoMajor), m_protoMin(protoMinor), - m_groups(groups), m_manuf(manufacturer), m_prodFamily(productFamily), - m_prodName(productName){} - - /// DSM-supplied ID of this identity. - constexpr Id id() const{ - return m_id; - } - - /// Version information. - constexpr const Version& version() const noexcept{ - return m_version; - } - - /// Whether a data group is supported. - constexpr bool supports(DataGroup group) const noexcept{ - return (m_groups & group) != 0; - } - - /// Whether this is V2 application. - constexpr bool isAppV2() const noexcept{ - return (m_groups & Detail::App2) != 0; - } - - /// Whether this is V2 DSM. - constexpr bool isDsmV2() const noexcept{ - return (m_groups & Detail::Dsm2) != 0; - } - - /// Whether this is V2 source. - constexpr bool isDsV2() const noexcept{ - return (m_groups & Detail::Ds2) != 0; - } - - /// The manufacturer. - /// Manufacturer and product name uniquely identify a source. - constexpr const Str32& manufacturer() const noexcept{ - return m_manuf; - } - - /// The product name. - /// Manufacturer and product name uniquely identify a source. - constexpr const Str32& productName() const noexcept{ - return m_prodName; - } - - /// The product family. - constexpr const Str32& productFamily() const noexcept{ - return m_prodFamily; - } - - /// Raw data group flags. - constexpr UInt32 dataGroupsRaw() const noexcept{ - return m_groups; - } - - /// TWAIN protocol major version. - constexpr UInt16 protocolMajor() const noexcept{ - return m_protoMaj; - } - - /// TWAIN protocol minor version. - constexpr UInt16 protocolMinor() const noexcept{ - return m_protoMin; - } - -private: - Id m_id; - Version m_version; - UInt16 m_protoMaj; - UInt16 m_protoMin; - UInt32 m_groups; - Str32 m_manuf; - Str32 m_prodFamily; - Str32 m_prodName; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_IDENTITY_HPP diff --git a/twain/twain/twpp/imageinfo.hpp b/twain/twain/twpp/imageinfo.hpp deleted file mode 100644 index 78cbf84..0000000 --- a/twain/twain/twpp/imageinfo.hpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_IMAGEINFO_HPP -#define TWPP_DETAIL_FILE_IMAGEINFO_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Contains information about transfered image. -class ImageInfo { - - typedef Detail::FixedArray BitsPerSampleImpl; - -public: - typedef Int16 BitsPerSample[8]; - - /// Creates zero-initialized info. - constexpr ImageInfo() noexcept : - m_imgWidth(0), m_imgHeight(0), m_spp(0), m_bps(), m_bpp(0), - m_planar(0), m_pixelType(PixelType::BlackWhite), m_compression(Compression::None){} - - /// Creates info with supplied values. - template - constexpr ImageInfo( - Fix32 xResolution, - Fix32 yResolution, - Int32 width, - Int32 height, - Int16 samplesPerPixel, - const Int16(& bitsPerSample)[inputSize], - Int16 bitsPerPixel, - Bool planar, - PixelType pixelType, - Compression compression - ) noexcept : - m_xres(xResolution), m_yres(yResolution), m_imgWidth(width), m_imgHeight(height), - m_spp(samplesPerPixel), m_bps(bitsPerSample), m_bpp(bitsPerPixel), m_planar(planar), - m_pixelType(pixelType), m_compression(compression){} - - /// X-axis resolution of the image. - constexpr Fix32 xResolution() const noexcept{ - return m_xres; - } - - /// Sets x-axis resolution of the image. - void setXResolution(Fix32 xres) noexcept{ - m_xres = xres; - } - - /// Y-axis resolution of the image. - constexpr Fix32 yResolution() const noexcept{ - return m_yres; - } - - /// Sets y-axis resolution of the image. - void setYResolution(Fix32 yres) noexcept{ - m_yres = yres; - } - - /// Image width in pixels. - constexpr Int32 width() const noexcept{ - return m_imgWidth; - } - - /// Sets image width in pixels. - void setWidth(Int32 width) noexcept{ - m_imgWidth = width; - } - - /// Image height in pixels. - constexpr Int32 height() const noexcept{ - return m_imgHeight; - } - - /// Sets image height in pixels. - void setHeight(Int32 height) noexcept{ - m_imgHeight = height; - } - - /// Samples per single pixel. - constexpr Int16 samplesPerPixel() const noexcept{ - return m_spp; - } - - /// Sets samples per single pixel. - void setSamplesPerPixel(Int16 spp) noexcept{ - m_spp = spp; - } - - /// Array of bits per sample. - /// Contains `samplesPerPixel` entries. - constexpr const BitsPerSample& bitsPerSample() const noexcept{ - return m_bps.array(); - } - - /// Array of bits per sample. - /// Contains `samplesPerPixel` entries. - BitsPerSample& bitsPerSample() noexcept{ - return m_bps.array(); - } - - /// Total number of bits per pixel. - /// This should be true: bitsPerPixel = SUM[i=0..samplesPerPixel-1](bitsPerSample[i]) - constexpr Int16 bitsPerPixel() const noexcept{ - return m_bpp; - } - - /// Sets total number of bits per pixel. - /// This should be true: bitsPerPixel = SUM[i=0..samplesPerPixel-1](bitsPerSample[i]) - void setBitsPerPixel(Int16 bpp) noexcept{ - m_bpp = bpp; - } - - /// Whether the image is planar (consists of several sample planes) or is chunky - /// (samples are transferes in one plane and are interlaced). - constexpr Bool planar() const noexcept{ - return m_planar; - } - - /// Sets whether the image is planar (consists of several sample planes) or is chunky - /// (samples are transferes in one plane and are interlaced). - void setPlanar(Bool planar) noexcept{ - m_planar = planar; - } - - /// The type of image. - constexpr PixelType pixelType() const noexcept{ - return m_pixelType; - } - - /// Sets the type of image. - void setPixelType(PixelType pixelType) noexcept{ - m_pixelType = pixelType; - } - - /// Image compression. - constexpr Compression compression() const noexcept{ - return m_compression; - } - - /// Sets image compression. - void compression(Compression compression) noexcept{ - m_compression = compression; - } - -private: - Fix32 m_xres; - Fix32 m_yres; - Int32 m_imgWidth; - Int32 m_imgHeight; - Int16 m_spp; - BitsPerSampleImpl m_bps; - Int16 m_bpp; - Bool m_planar; - PixelType m_pixelType; - Compression m_compression; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_IMAGEINFO_HPP - diff --git a/twain/twain/twpp/imagelayout.hpp b/twain/twain/twpp/imagelayout.hpp deleted file mode 100644 index c61eb5b..0000000 --- a/twain/twain/twpp/imagelayout.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_IMAGELAYOUT_HPP -#define TWPP_DETAIL_FILE_IMAGELAYOUT_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Provides image size and its position on the scanner and information about order of the image. -class ImageLayout { - -public: - /// Creates layout. - constexpr ImageLayout( - const Frame& frame = Frame(), - UInt32 documentNumber = 1, - UInt32 pageNumber = 1, - UInt32 frameNumber = 1 - ) noexcept : - m_frame(frame), m_docNumber(documentNumber), - m_pageNumber(pageNumber), m_frameNumber(frameNumber){} - - /// The image frame. - constexpr const Frame& frame() const noexcept{ - return m_frame; - } - - /// Sets the image frame. - void setFrame(const Frame& frame) noexcept{ - m_frame = frame; - } - - /// Number of the document, set by source. - constexpr UInt32 documentNumber() const noexcept{ - return m_docNumber; - } - - /// Sets number of the document. - void setDocumentNumber(UInt32 documentNumber) noexcept{ - m_docNumber = documentNumber; - } - - /// Number of the page, set by source. - constexpr UInt32 pageNumber() const noexcept{ - return m_pageNumber; - } - - /// Sets number of the page. - void setPageNumber(UInt32 pageNumber) noexcept{ - m_pageNumber = pageNumber; - } - - /// Number of the frame, set by source. - constexpr UInt32 frameNumber() const noexcept{ - return m_frameNumber; - } - - /// Sets number of the frame. - void setFrameNumber(UInt32 frameNumber) noexcept{ - m_frameNumber = frameNumber; - } - -private: - Frame m_frame; - UInt32 m_docNumber; - UInt32 m_pageNumber; - UInt32 m_frameNumber; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_IMAGELAYOUT_HPP diff --git a/twain/twain/twpp/imagememxfer.hpp b/twain/twain/twpp/imagememxfer.hpp deleted file mode 100644 index 2be7a3a..0000000 --- a/twain/twain/twpp/imagememxfer.hpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_IMAGEMEMXFER_HPP -#define TWPP_DETAIL_FILE_IMAGEMEMXFER_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -namespace Detail { - -/// Structure holding the information and data of memory and memory file transfers. -class ImageMemXferImpl { - -public: - /// Creates a zero-initialized structure without any memory. - ImageMemXferImpl() noexcept : - m_compression(Compression::None), m_bytesPerRow(0), m_columns(0), m_rows(0), - m_xoff(0), m_yoff(0), m_bytesWritten(0){} - - /// Creates an initialized structure from the supplied values and memory. - /// The ownership of the memory is taken over. - ImageMemXferImpl( - Compression compression, - UInt32 bytesPerRow, - UInt32 columns, - UInt32 rows, - UInt32 xOffset, - UInt32 yOffset, - UInt32 bytesWritten, - Memory memory - ) noexcept : - m_compression(compression), m_bytesPerRow(bytesPerRow), - m_columns(columns), m_rows(rows), m_xoff(xOffset), m_yoff(yOffset), - m_bytesWritten(bytesWritten), m_memory(std::move(memory)){} - - /// Compression used in the transfer. - Compression compression() const noexcept{ - return m_compression; - } - - /// Sets compression used in the transfer. - void setCompression(Compression compression) noexcept{ - m_compression = compression; - } - - /// Number of bytes per single row. - UInt32 bytesPerRow() const noexcept{ - return m_bytesPerRow; - } - - /// Sets number of bytes per single row. - void setBytesPerRow(UInt32 bytesPerRow) noexcept{ - m_bytesPerRow = bytesPerRow; - } - - /// Number of columns in the transfer. - UInt32 columns() const noexcept{ - return m_columns; - } - - /// Sets number of columns in the transfer. - void setColumns(UInt32 columns) noexcept{ - m_columns = columns; - } - - /// Number of rows in the transfer. - UInt32 rows() const noexcept{ - return m_rows; - } - - /// Sets number of rows in the transfer. - void setRows(UInt32 rows) noexcept{ - m_rows = rows; - } - - /// X offset from top-left corner in pixels of the image data in the transfer. - UInt32 xOffset() const noexcept{ - return m_xoff; - } - - /// Sets X offset from top-left corner in pixels of the image data in the transfer. - void setXOffset(UInt32 xOffset) noexcept{ - m_xoff = xOffset; - } - - /// Y offset from top-left corner in pixels of the image data in the transfer. - UInt32 yOffset() const noexcept{ - return m_yoff; - } - - /// Sets Y offset from top-left corner in pixels of the image data in the transfer. - void setYOffset(UInt32 yOffset) noexcept{ - m_yoff = yOffset; - } - - /// Number of bytes in this transfer, always contains whole rows or tiles. - UInt32 bytesWritten() const noexcept{ - return m_bytesWritten; - } - - /// Sets number of bytes in this transfer. - void setBytesWritten(UInt32 bytesWritten) noexcept{ - m_bytesWritten = bytesWritten; - } - - /// Contained memory structure. - const Memory& memory() const noexcept{ - return m_memory; - } - - /// Contained memory structure. - Memory& memory() noexcept{ - return m_memory; - } - -private: - Compression m_compression; - UInt32 m_bytesPerRow; - UInt32 m_columns; - UInt32 m_rows; - UInt32 m_xoff; - UInt32 m_yoff; - UInt32 m_bytesWritten; - Memory m_memory; - -}; - -} - -/// Structure holding the information and data of memory transfer. -class ImageMemXfer : public Detail::ImageMemXferImpl { - -public: - /// Creates a zero-initialized structure without any memory. - ImageMemXfer() noexcept : Detail::ImageMemXferImpl(){} - - /// Creates an initialized structure from the supplied values and memory. - /// The ownership of the memory is taken over. - ImageMemXfer( - Compression compression, - UInt32 bytesPerRow, - UInt32 columns, - UInt32 rows, - UInt32 xOffset, - UInt32 yOffset, - UInt32 bytesWritten, - Memory memory - ) noexcept : Detail::ImageMemXferImpl( - compression, bytesPerRow, columns, rows, xOffset, - yOffset, bytesWritten, std::move(memory)){} - -}; - -/// Structure holding the information and data of memory file transfer. -class ImageMemFileXfer : public Detail::ImageMemXferImpl { - -public: - /// Creates a zero-initialized structure without any memory. - ImageMemFileXfer() noexcept : Detail::ImageMemXferImpl(){} - - /// Creates an initialized structure from the supplied values and memory. - /// The ownership of the memory is taken over. - ImageMemFileXfer( - Compression compression, - UInt32 bytesPerRow, - UInt32 columns, - UInt32 rows, - UInt32 xOffset, - UInt32 yOffset, - UInt32 bytesWritten, - Memory memory - ) noexcept : Detail::ImageMemXferImpl( - compression, bytesPerRow, columns, rows, xOffset, - yOffset, bytesWritten, std::move(memory)){} - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_IMAGEMEMXFER_HPP diff --git a/twain/twain/twpp/imagenativexfer.hpp b/twain/twain/twpp/imagenativexfer.hpp deleted file mode 100644 index 8a90bc0..0000000 --- a/twain/twain/twpp/imagenativexfer.hpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_IMAGENATIVEXFER_HPP -#define TWPP_DETAIL_FILE_IMAGENATIVEXFER_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Structure holding native transfer image handle. -class ImageNativeXfer { - -public: - template - using Data = Detail::Lock::type>; - - template - using ConstData = Detail::Lock::type>; - - - /// Creates empty, invalid native transfer. - ImageNativeXfer() noexcept : - m_handle(){} - - /// Creates a new ImageNativeXfer object from a handle. - /// The ownership of the handle is taken over. - explicit ImageNativeXfer(Handle h) : - m_handle(h){} - - /// Creates uninitialized native image with defines size in bytes. - /// \throw std::bad_alloc - explicit ImageNativeXfer(UInt32 size) : - m_handle(Detail::alloc(size)){} - - /// Data of this native transfer. - /// Actual type depends on system and source. - /// Windows sources use BMP format without file header, version varies. - /// Linux uses TIFF, version varies. - /// Mac uses QuickDraw Picture. - template - Data data() noexcept{ - return m_handle.lock::type>(); - } - - /// Data of this native transfer. - /// Actual type depends on system and source. - /// Windows sources use BMP format without file header, version varies. - /// Linux uses TIFF, version varies. - /// Mac uses QuickDraw Picture. - template - ConstData data() const noexcept{ - return m_handle.lock::type>(); - } - - operator bool() const noexcept{ - return m_handle; - } - - /// Releases the contained handle, making user responsible for freeing it. - Handle release() noexcept{ - return m_handle.release(); - } - -private: - Detail::UniqueHandle m_handle; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_IMAGENATIVEXFER_HPP - diff --git a/twain/twain/twpp/internal.hpp b/twain/twain/twpp/internal.hpp deleted file mode 100644 index 8abe360..0000000 --- a/twain/twain/twpp/internal.hpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015-2017 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_INTERNAL_HPP -#define TWPP_DETAIL_FILE_INTERNAL_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -struct AudioFileXfer {}; -struct ImageFileXfer {}; -typedef Memory IccProfileMemory; - -namespace Detail { - -typedef ReturnCode (TWPP_DETAIL_CALLSTYLE* DsmEntry)( - Identity* origin, - Identity* dest, - DataGroup dg, - Dat dat, - Msg msg, - void* data -); - -typedef DsmEntry CallBackFunc; - -typedef -#if defined(TWPP_DETAIL_OS_MAC) -void* -#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX) -UInt32 -#else -# error "CallBackConstant for your platform here" -#endif -CallBackConstant; - - -TWPP_DETAIL_PACK_BEGIN -struct EntryPoint { - constexpr EntryPoint() noexcept : - m_size(sizeof(EntryPoint)), m_entry(nullptr), m_alloc(nullptr), - m_free(nullptr), m_lock(nullptr), m_unlock(nullptr){} - - UInt32 m_size; - DsmEntry m_entry; - MemAlloc m_alloc; - MemFree m_free; - MemLock m_lock; - MemUnlock m_unlock; -}; - -struct CallBack { - - constexpr CallBack(CallBackFunc func, CallBackConstant constant, Msg msg) noexcept : - m_func(func), m_constant(constant), m_msg(msg){} - - CallBackFunc m_func; - CallBackConstant m_constant; - Msg m_msg; - -}; - -struct CallBack2 { - - constexpr CallBack2(CallBackFunc func, UIntPtr constant, Msg msg) noexcept : - m_func(func), m_constant(constant), m_msg(msg){} - - CallBackFunc m_func; - UIntPtr m_constant; - Msg m_msg; -}; -TWPP_DETAIL_PACK_END - -/// Manages DSM dll/so/framework connection. -class DsmLib { - -public: - constexpr DsmLib() noexcept : - m_handle(DsmLibOs::nullHandle){} - - ~DsmLib(){ - unload(); - } - - DsmLib(const DsmLib&) = delete; - DsmLib& operator=(const DsmLib&) = delete; - - DsmLib(DsmLib&& o) noexcept : - m_handle(o.m_handle){ - - o.m_handle = DsmLibOs::nullHandle; - } - - DsmLib& operator=(DsmLib&& o) noexcept{ - if (&o != this){ - unload(); - - m_handle = o.m_handle; - o.m_handle = DsmLibOs::nullHandle; - } - - return *this; - } - - operator bool() const noexcept{ - return m_handle != DsmLibOs::nullHandle; - } - - bool load(bool preferOld = false) noexcept{ - m_handle = DsmLibOs::load(preferOld); - return m_handle != DsmLibOs::nullHandle; - } - - void unload() noexcept{ - if (m_handle != DsmLibOs::nullHandle){ - DsmLibOs::unload(m_handle); - m_handle = DsmLibOs::nullHandle; - } - } - - DsmEntry resolve() const noexcept{ - return DsmLibOs::resolve(m_handle); - } - -private: - DsmLibOs::Handle m_handle; - -}; - -} - -} - -#endif // TWPP_DETAIL_FILE_INTERNAL_HPP diff --git a/twain/twain/twpp/jpegcompression.hpp b/twain/twain/twpp/jpegcompression.hpp deleted file mode 100644 index b42a176..0000000 --- a/twain/twain/twpp/jpegcompression.hpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_JPEGCOMPRESSION_HPP -#define TWPP_DETAIL_FILE_JPEGCOMPRESSION_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// See manual for more info. -class JpegCompression { - -public: - typedef UInt16 UInt16Arr4[4]; - typedef Memory MemoryArr2[2]; - typedef Memory MemoryArr4[4]; - - JpegCompression() noexcept : - m_colorSpace(PixelType::BlackWhite), m_subSampling(0x10001000), m_components(0), - m_restartFrequency(0), m_quantMap(), m_huffmanMap(){} - - template< - std::size_t quantTableMapSize, - std::size_t quantTableSize, - std::size_t huffmanTableMapSize, - std::size_t huffmanDcSize, - std::size_t huffmanAcSize - > - JpegCompression( - PixelType colorSpace, - UInt32 subSampling, - UInt16 components, - UInt16 restartFrequency, - const UInt16(& quantTableMap)[quantTableMapSize], - Memory(& quantTable)[quantTableSize], - const UInt16(& huffmanTableMap)[huffmanTableMapSize], - Memory(& huffmanDc)[huffmanDcSize], - Memory(& huffmanAc)[huffmanAcSize] - ) noexcept : - m_colorSpace(colorSpace), - m_subSampling(subSampling), - m_components(components), - m_restartFrequency(restartFrequency), - m_quantMap(quantTableMap), - m_huffmanMap(huffmanTableMap){ - - for (std::size_t i = 0; i < quantTableSize; i++){ - m_quantTable[i] = std::move(quantTable[i]); - } - - for (std::size_t i = 0; i < huffmanDcSize; i++){ - m_huffmanDc[i] = std::move(huffmanDc[i]); - } - - for (std::size_t i = 0; i < huffmanAcSize; i++){ - m_huffmanAc[i] = std::move(huffmanAc[i]); - } - } - - PixelType pixelType() const noexcept{ - return m_colorSpace; - } - - void setPixelType(PixelType pixelType) noexcept{ - m_colorSpace = pixelType; - } - - UInt32 subSampling() const noexcept{ - return m_subSampling; - } - - void setSubSampling(UInt32 subSampling) noexcept{ - m_subSampling = subSampling; - } - - UInt16 components() const noexcept{ - return m_components; - } - - void setComponents(UInt16 components) noexcept{ - m_components = components; - } - - UInt16 restartFrequency() const noexcept{ - return m_restartFrequency; - } - - void setRestartFrequency(UInt16 restartFrequency) noexcept{ - m_restartFrequency = restartFrequency; - } - - const UInt16Arr4& quantTableMap() const noexcept{ - return m_quantMap.array(); - } - - UInt16Arr4& quantTableMap() noexcept{ - return m_quantMap.array(); - } - - const MemoryArr4& quantTable() const noexcept{ - return m_quantTable; - } - - MemoryArr4& quantTable() noexcept{ - return m_quantTable; - } - - const UInt16Arr4& huffmanTableMap() const noexcept{ - return m_huffmanMap.array(); - } - - UInt16Arr4& huffmanTableMap() noexcept{ - return m_huffmanMap.array(); - } - - const MemoryArr2& huffmanDc() const noexcept{ - return m_huffmanDc; - } - - MemoryArr2& huffmanDc() noexcept{ - return m_huffmanDc; - } - - const MemoryArr2& huffmanAc() const noexcept{ - return m_huffmanAc; - } - - MemoryArr2& huffmanAc() noexcept{ - return m_huffmanAc; - } - -private: - PixelType m_colorSpace; - UInt32 m_subSampling; - UInt16 m_components; - UInt16 m_restartFrequency; - Detail::FixedArray m_quantMap; - MemoryArr4 m_quantTable; - Detail::FixedArray m_huffmanMap; - MemoryArr2 m_huffmanDc; - MemoryArr2 m_huffmanAc; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_JPEGCOMPRESSION_HPP diff --git a/twain/twain/twpp/memory.hpp b/twain/twain/twpp/memory.hpp deleted file mode 100644 index 63859b1..0000000 --- a/twain/twain/twpp/memory.hpp +++ /dev/null @@ -1,194 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_MEMORY_HPP -#define TWPP_DETAIL_FILE_MEMORY_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -namespace Detail { - -namespace Flags { - -enum { - AppOwns = 0x0001, - DsmOwns = 0x0002, - DsOwns = 0x0004, - Pointer = 0x0008, - Handle = 0x0010 -}; - - -#if !defined(TWPP_IS_DS) -static constexpr const UInt32 thisOwns = AppOwns; -static constexpr const UInt32 otherOwns = DsOwns; -#else -static constexpr const UInt32 thisOwns = DsOwns; -static constexpr const UInt32 otherOwns = AppOwns; -#endif - -} - -} - -TWPP_DETAIL_PACK_BEGIN -/// Holds and potentially owns a block of memory using either pointer or handle. -class Memory { - -public: - typedef Detail::MaybeLock Data; - typedef Detail::MaybeLock ConstData; - - /// Creates an empty memory. - constexpr Memory() noexcept : - m_flags(0), m_size(0), m_data(nullptr){} - - /// Creates a memory block of supplied size. - /// \throw std::bad_alloc - explicit Memory(UInt32 size) : - m_flags(Detail::Flags::thisOwns | Detail::Flags::Handle), m_size(size), - m_data(Detail::alloc(size).raw()){} - - /// Creates a new memory object from Handle. - /// The memory ownership is taken over. - /// \param h The handle, see thisOwns for more information about memory ownership. - /// \param size Size of the memory in bytes, that handle h manages. - /// \param thisOwns { - /// If true, this object frees the memory once it goes out of scope. - /// - /// If false the memory is not freed, and MUST be passed to the other side - /// (APP->DS or DS->APP) of the connection, that will free it. - /// } - Memory(Handle h, UInt32 size, bool thisOwns = true) noexcept : - m_flags((thisOwns ? Detail::Flags::thisOwns : Detail::Flags::otherOwns) | Detail::Flags::Handle), - m_size(size), - m_data(h.raw()){} - - /// Creates a memory object from container. - /// The memory object does NOT take over the ownership of the data. - /// Make sure the container is destroyed after the memory object is. - template - explicit Memory(const Container& container) noexcept : - m_flags(Detail::Flags::thisOwns | Detail::Flags::Pointer), - m_size(sizeof(Container::value_type) * container.size()), - m_data(container.data()){} - - /// Creates a memory object from pointer. - /// The memory object does NOT take over the ownership of the data. - /// Make sure the data is destroyed after the memory object is. - constexpr Memory(void* data, UInt32 size) noexcept : - m_flags(Detail::Flags::thisOwns | Detail::Flags::Pointer), m_size(size), - m_data(data){} - - ~Memory(){ - freePriv(); - } - - Memory(const Memory& o) = delete; - Memory& operator=(const Memory& o) = delete; - - Memory(Memory&& o) noexcept : - m_flags(o.m_flags), m_size(o.m_size), m_data(o.m_data) - { - o.m_flags = 0; - o.m_size = 0; - o.m_data = nullptr; - } - - Memory& operator=(Memory&& o) noexcept{ - if (&o != this){ - freePriv(); - - m_flags = o.m_flags; - m_size = o.m_size; - m_data = o.m_data; - - o.m_flags = 0; - o.m_size = 0; - o.m_data = nullptr; - } - - return *this; - } - - /// The data in this memory block. - ConstData data() const noexcept{ - return m_flags & Detail::Flags::Handle ? - ConstData(Handle(static_cast(m_data))) : - ConstData(static_cast(m_data)); - } - - /// The data in this memory block. - Data data() noexcept{ - return m_flags & Detail::Flags::Handle ? - Data(Handle(static_cast(m_data))) : - Data(static_cast(m_data)); - } - - /// Number of bytes in the memory block. - UInt32 size() const noexcept{ - return m_size; - } - - /// In case of handle, frees memory regardless its owner; does nothing otherwise (pointer). - /// Potentially unsafe operation. - void free(){ - if (m_flags & Detail::Flags::Handle){ - Handle h(static_cast(m_data)); - if (h){ - Detail::free(h); - } - - m_size = 0; - m_data = nullptr; - m_flags = 0; - } - } - -private: - void freePriv(){ - if (m_flags & Detail::Flags::thisOwns){ - if (m_flags & Detail::Flags::Handle){ - Detail::free(Handle(static_cast(m_data))); - } - } - } - - UInt32 m_flags; - UInt32 m_size; - void* m_data; - -}; -TWPP_DETAIL_PACK_END - - - -} - -#endif // TWPP_DETAIL_FILE_MEMORY_HPP - diff --git a/twain/twain/twpp/memoryops.hpp b/twain/twain/twpp/memoryops.hpp deleted file mode 100644 index abf499a..0000000 --- a/twain/twain/twpp/memoryops.hpp +++ /dev/null @@ -1,439 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015-2017 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_MEMORYOPS_HPP -#define TWPP_DETAIL_FILE_MEMORYOPS_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -namespace Detail { - -extern "C" { - -typedef Handle::Raw (TWPP_DETAIL_CALLSTYLE* MemAlloc)(UInt32 size); -typedef void (TWPP_DETAIL_CALLSTYLE* MemFree)(Handle::Raw handle); -typedef void* (TWPP_DETAIL_CALLSTYLE* MemLock)(Handle::Raw handle); -typedef void (TWPP_DETAIL_CALLSTYLE* MemUnlock)(Handle::Raw handle); - -} - -// templates behave as if they were defined in at most one module -// ideal for storing static data -template -struct GlobalMemFuncs { - -#if defined(TWPP_DETAIL_OS_WIN) - static Handle::Raw TWPP_DETAIL_CALLSTYLE defAlloc(UInt32 size){ - return ::GlobalAlloc(GHND, size); - } - - static void TWPP_DETAIL_CALLSTYLE defFree(Handle::Raw handle){ - ::GlobalFree(handle); - } - - static void* TWPP_DETAIL_CALLSTYLE defLock(Handle::Raw handle){ - return ::GlobalLock(handle); - } - - static void TWPP_DETAIL_CALLSTYLE defUnlock(Handle::Raw handle){ - ::GlobalUnlock(handle); - } -#elif defined(TWPP_DETAIL_OS_MAC) - static Handle::Raw TWPP_DETAIL_CALLSTYLE defAlloc(UInt32 size){ - return ::NewHandle(size); - } - - static void TWPP_DETAIL_CALLSTYLE defFree(Handle::Raw handle){ - ::DisposeHandle(handle); - } - - static void* TWPP_DETAIL_CALLSTYLE defLock(Handle::Raw handle){ - return *handle; - } - - static void TWPP_DETAIL_CALLSTYLE defUnlock(Handle::Raw){ - // noop - } -#elif !defined(TWPP_DETAIL_OS_LINUX) // Linux doesnt need default functions -# error "default memory functions for your platform here" -#endif - - static MemAlloc alloc; - static MemFree free; - static MemLock lock; - static MemUnlock unlock; - -#if defined(TWPP_IS_DS) - static Handle doNotFreeHandle; -#endif - -}; - -#if defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_MAC) -template -MemAlloc GlobalMemFuncs::alloc = GlobalMemFuncs::defAlloc; - -template -MemFree GlobalMemFuncs::free = GlobalMemFuncs::defFree; - -template -MemLock GlobalMemFuncs::lock = GlobalMemFuncs::defLock; - -template -MemUnlock GlobalMemFuncs::unlock = GlobalMemFuncs::defUnlock; -#elif defined(TWPP_DETAIL_OS_LINUX) -template -MemAlloc GlobalMemFuncs::alloc = nullptr; - -template -MemFree GlobalMemFuncs::free = nullptr; - -template -MemLock GlobalMemFuncs::lock = nullptr; - -template -MemUnlock GlobalMemFuncs::unlock = nullptr; -#else -# error "default memory functions setup for your platform here" -#endif - -#if defined(TWPP_IS_DS) - template - Handle GlobalMemFuncs::doNotFreeHandle; -#endif - -inline static void setMemFuncs(MemAlloc alloc, MemFree free, MemLock lock, MemUnlock unlock) noexcept{ - GlobalMemFuncs::alloc = alloc; - GlobalMemFuncs::free = free; - GlobalMemFuncs::lock = lock; - GlobalMemFuncs::unlock = unlock; -} - -inline static void resetMemFuncs() noexcept{ -#if defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_MAC) - GlobalMemFuncs::alloc = GlobalMemFuncs::defAlloc; - GlobalMemFuncs::free = GlobalMemFuncs::defFree; - GlobalMemFuncs::lock = GlobalMemFuncs::defLock; - GlobalMemFuncs::unlock = GlobalMemFuncs::defUnlock; -#elif defined(TWPP_DETAIL_OS_LINUX) - GlobalMemFuncs::alloc = nullptr; - GlobalMemFuncs::free = nullptr; - GlobalMemFuncs::lock = nullptr; - GlobalMemFuncs::unlock = nullptr; -#else -# error "resetMemFuncs for your platform here" -#endif -} - -inline static Handle alloc(UInt32 size){ - auto h = GlobalMemFuncs::alloc(size); - if (!h){ - throw std::bad_alloc(); - } - - return Handle(h); -} - -inline static void* lock(Handle handle) noexcept{ - return GlobalMemFuncs::lock(handle.raw()); -} - -inline static void unlock(Handle handle) noexcept{ - GlobalMemFuncs::unlock(handle.raw()); -} - -inline static void free(Handle handle) noexcept{ - GlobalMemFuncs::free(handle.raw()); -} - -template -static inline T* typeLock(Handle handle) noexcept{ - return static_cast(lock(handle)); -} - -/// A lock that can contain either handle or raw pointer. -/// Locks and unlocks handle, noop for pointer. -template -class MaybeLock { - -public: - constexpr MaybeLock() noexcept : - m_handle(), m_pointer(nullptr){} - - MaybeLock(Handle h) noexcept : - m_handle(h), m_pointer(typeLock(h)){} - - constexpr MaybeLock(T* ptr) noexcept : - m_handle(), m_pointer(ptr){} - - ~MaybeLock(){ - unlock(); - } - - MaybeLock(const MaybeLock& o) noexcept : - m_handle(o.m_handle), m_pointer(o.m_handle ? typeLock(o.m_handle) : o.m_pointer){} - - MaybeLock& operator=(const MaybeLock& o) noexcept{ - if (&o != this){ - unlock(); - - m_handle = o.m_handle; - m_pointer = m_handle ? typeLock(m_handle) : o.m_pointer; - } - - return *this; - } - - - MaybeLock(MaybeLock&& o) noexcept : - m_handle(o.m_handle), m_pointer(o.m_pointer){ - - o.m_handle = Handle(); - o.m_pointer = nullptr; - } - - MaybeLock& operator=(MaybeLock&& o) noexcept{ - if (&o != this){ - unlock(); - - m_handle = o.m_handle; - m_pointer = o.m_pointer; - - o.m_handle = Handle(); - o.m_pointer = nullptr; - } - - return *this; - } - - T* data() const noexcept{ - return m_pointer; - } - - operator T*() const noexcept{ - return m_pointer; - } - - T* operator->() noexcept{ - return m_pointer; - } - - T* operator->() const noexcept{ - return m_pointer; - } - - bool hasData() const noexcept{ - return m_pointer; - } - - operator bool() const noexcept{ - return m_pointer; - } - -private: - void unlock() noexcept{ - if (m_handle){ - Detail::unlock(m_handle); - } - } - - Handle m_handle; - T* m_pointer; - -}; - -/// Simple handle lock. -/// Locks on creation and unlocks on destruction. -template -class Lock { - -public: - constexpr Lock() noexcept : - m_handle(), m_pointer(nullptr){} - - Lock(Handle h) noexcept : - m_handle(h), m_pointer(typeLock(h)){} - - ~Lock(){ - unlock(); - } - - - Lock(const Lock& o) noexcept : - m_handle(o.m_handle), m_pointer(typeLock(o.m_handle)){} - - Lock& operator=(const Lock& o) noexcept{ - if (&o != this){ - unlock(); - - m_handle = o.m_handle; - m_pointer = typeLock(m_handle); - } - - return *this; - } - - - Lock(Lock&& o) noexcept : - m_handle(o.m_handle), m_pointer(o.m_pointer){ - - o.m_handle = Handle(); - o.m_pointer = nullptr; - } - - Lock& operator=(Lock&& o) noexcept{ - if (&o != this){ - unlock(); - - m_handle = o.m_handle; - m_pointer = o.m_pointer; - - o.m_handle = Handle(); - o.m_pointer = nullptr; - } - - return *this; - } - - - T* data() const noexcept{ - return m_pointer; - } - - operator T*() const noexcept{ - return m_pointer; - } - - T* operator->() noexcept{ - return m_pointer; - } - - T* operator->() const noexcept{ - return m_pointer; - } - - bool hasData() const noexcept{ - return m_pointer; - } - - operator bool() const noexcept{ - return m_pointer; - } - -private: - void unlock() noexcept{ - if (m_handle){ - Detail::unlock(m_handle); - } - } - - Handle m_handle; - T* m_pointer; - -}; - -/// Owns a handle and frees it upon destruction, -/// unless `release` is called beforehand. -class UniqueHandle { - -public: - constexpr UniqueHandle(Handle h = Handle()) noexcept : - m_handle(h){} - - ~UniqueHandle(){ - free(); - } - - UniqueHandle(const UniqueHandle&) = delete; - UniqueHandle& operator=(const UniqueHandle&) = delete; - - UniqueHandle(UniqueHandle&& o) noexcept : - m_handle(o.m_handle){ - - o.m_handle = Handle(); - } - - UniqueHandle& operator=(UniqueHandle&& o) noexcept{ - if (&o != this){ - free(); - - m_handle = o.m_handle; - - o.m_handle = Handle(); - } - - return *this; - } - - operator bool() const noexcept{ - return m_handle; - } - - /// The contained handle. - Handle get() noexcept{ - return m_handle; - } - - /// The contained handle. - Handle get() const noexcept{ - return m_handle; - } - - /// Releases the contained handle, making the user responsible for freeing it. - Handle release() noexcept{ - Handle ret = m_handle; - m_handle = Handle(); - return ret; - } - - template - Lock lock() const{ - return m_handle; - } - -private: - void free() noexcept{ -#if defined(TWPP_IS_DS) - if (m_handle && m_handle != GlobalMemFuncs::doNotFreeHandle){ -#else - if (m_handle){ -#endif - Detail::free(m_handle); - } - } - - Handle m_handle; - -}; - -} - -} - -#endif // TWPP_DETAIL_FILE_MEMORYOPS_HPP - diff --git a/twain/twain/twpp/palette8.hpp b/twain/twain/twpp/palette8.hpp deleted file mode 100644 index 71a05bc..0000000 --- a/twain/twain/twpp/palette8.hpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_PALETTE8_HPP -#define TWPP_DETAIL_FILE_PALETTE8_HPP - -#include "../twpp.hpp" - - -namespace Twpp { - -namespace Detail { - -// specialization for Element8 -// we also want to set index of the element when placing it inside array -template -struct FixedArrayData > { - - static constexpr Element8 updateIndex(UInt8 index, const Element8& e) noexcept{ - return Element8(index, e.channel1(), e.channel2(), e.channel3()); - } - - template - constexpr FixedArrayData(const Element8(& arr)[inputSize]) noexcept : - m_arr{updateIndex(i, FixedArrayFlat(arr)[i])...}{} - - constexpr FixedArrayData() noexcept : - m_arr{Element8(i)...}{} - - Element8 m_arr[arraySize]; - -}; - -} - - -TWPP_DETAIL_PACK_BEGIN -/// Palette information for memory transfers -class Palette8 { - -public: - enum class Type : UInt16 { - Rgb = 0, - Gray = 1, - Cmy = 2 - }; - - typedef Element8 Element8Arr256[256]; - - /// Creates an uninitialized palette. - constexpr Palette8() noexcept : - m_size(0), m_type(Type::Rgb), m_colors(){} - - /// Creates a palette with the supplied type and elements. - template - constexpr Palette8(Type type, const Element8(& colors)[inputSize]) noexcept : - m_size(inputSize), m_type(type), - m_colors(colors){ - - static_assert(inputSize <= 256, "too many colors"); - } - - /// Creates a palette with the supplied type and elements from container. - /// \throw RangeException When there are more than 256 colors. - template - Palette8(Type type, const Container& colors) : - m_size(static_cast(colors.size())), m_type(type){ - - if (colors.size() > 256){ - throw RangeException(); - } - - auto& array = m_colors.array(); - for (UInt16 i = 0; i < m_size; i++){ - array[i] = colors[i]; - array[i].setIndex(i); - } - } - - /// Creates a palette with the supplied type and elements. - /// \throw RangeException When there are more than 256 colors. - Palette8(Type type, const Element8* colors, UInt16 size) : - m_size(size), m_type(type){ - - if (m_size > 256){ - throw RangeException(); - } - - auto& array = m_colors.array(); - for (UInt16 i = 0; i < m_size; i++){ - array[i] = colors[i]; - array[i].setIndex(static_cast(i)); // 0..255 max - } - } - - /// Number of elements in the palette. - constexpr UInt16 size() const noexcept{ - return m_size; - } - - /// Type of palette data. - constexpr Type type() const noexcept{ - return m_type; - } - - /// Array of palette elements. - constexpr const Element8Arr256& colors() const noexcept{ - return m_colors.array(); - } - -private: - UInt16 m_size; - Type m_type; - Detail::FixedArray m_colors; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_PALETTE8_HPP - diff --git a/twain/twain/twpp/passthrough.hpp b/twain/twain/twpp/passthrough.hpp deleted file mode 100644 index 49c33fd..0000000 --- a/twain/twain/twpp/passthrough.hpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_PASSTHROUGH_HPP -#define TWPP_DETAIL_FILE_PASSTHROUGH_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Structure for raw comminication with device in source. -/// See manual for more information, DAT_PASSTHRU, MSG_PASSTHRU. -class PassThrough { - -public: - enum class Direction : Int32 { - Get = 1, - Set = 2 - }; - - constexpr PassThrough( - void* command, - UInt32 commandSize, - Direction direction, - void* data, - UInt32 dataSize, - UInt32 dataXfered - ) noexcept : - m_cmd(command), m_cmdSize(commandSize), - m_direction(direction), - m_data(data), m_dataSize(dataSize), m_dataXfered(dataXfered){} - - constexpr void* command() const noexcept{ - return m_cmd; - } - - constexpr UInt32 commandSize() const noexcept{ - return m_cmdSize; - } - - template - void setCommand(const Container& command) noexcept{ - m_cmd = command.data(); - m_cmdSize = sizeof(Container::value_type) * command.size(); - } - - void setCommand(void* command, UInt32 size) noexcept{ - m_cmd = command; - m_cmdSize = size; - } - - constexpr Direction direction() const noexcept{ - return m_direction; - } - - void setDirection(Direction direction) noexcept{ - m_direction = direction; - } - - constexpr void* data() const noexcept{ - return m_data; - } - - constexpr UInt32 dataSize() const noexcept{ - return m_dataSize; - } - - template - void setData(const Container& data) noexcept{ - m_data = data.data(); - m_dataSize = sizeof(Container::value_type) * data.size(); - m_dataXfered = 0; - } - - void setData(void* data, UInt32 dataSize) noexcept{ - m_data = data; - m_dataSize = dataSize; - m_dataXfered = 0; - } - - constexpr UInt32 dataXfered() const noexcept{ - return m_dataXfered; - } - - void setDataXfered(Int32 dataXfered) noexcept{ - m_dataXfered = dataXfered; - } - -private: - void* m_cmd; - UInt32 m_cmdSize; - Direction m_direction; - void* m_data; - UInt32 m_dataSize; - UInt32 m_dataXfered; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_PASSTHROUGH_HPP diff --git a/twain/twain/twpp/pendingxfers.hpp b/twain/twain/twpp/pendingxfers.hpp deleted file mode 100644 index 9ba875b..0000000 --- a/twain/twain/twpp/pendingxfers.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_PENDINGXFERS_HPP -#define TWPP_DETAIL_FILE_PENDINGXFERS_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Reports number of pending images, transfers. -class PendingXfers { - -public: - /// Job control settings. - enum class JobPatch : UInt32 { - None = 0x0000, - MidSeparator = 0x0001, - P1 = 0x0002, - P2 = 0x0003, - P3 = 0x0004, - P4 = 0x0005, - P6 = 0x0006, - PT = 0x0007 - }; - - /// Creates object to report number of pending transfers. - /// \param count Number of pending transfers. - /// \param patch Job control settings. - constexpr PendingXfers(UInt16 count = 0, JobPatch patch = JobPatch::None) noexcept : - m_count(count), m_eoj(patch){} - - /// Number of pending images/transfers. - constexpr UInt16 count() const noexcept{ - return m_count; - } - - /// Sets number of pending images/transfers. - void setCount(UInt16 count) noexcept{ - m_count = count; - } - - /// Job control settings. - constexpr JobPatch jobPatch() const noexcept{ - return m_eoj; - } - - /// Sets job control settings. - void setJobPatch(JobPatch eoj) noexcept{ - m_eoj = eoj; - } - -private: - UInt16 m_count; - JobPatch m_eoj; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_PENDINGXFERS_HPP diff --git a/twain/twain/twpp/setupfilexfer.hpp b/twain/twain/twpp/setupfilexfer.hpp deleted file mode 100644 index f4a4a2f..0000000 --- a/twain/twain/twpp/setupfilexfer.hpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015-2017 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_SETUPFILEXFER_HPP -#define TWPP_DETAIL_FILE_SETUPFILEXFER_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Structure for setting up file transfer. -class SetupFileXfer { - -public: - /// Creates zero-initialized instance. - constexpr SetupFileXfer() noexcept : - m_format(ImageFileFormat::Tiff), m_volRefNum(0){} - - /// Creates instance with set file path and format. - /// And volume reference number on Mac OS. - /// \param filePath Path to transfered file. - /// \param format File format. - /// \param vrn Volume reference number. Mac OS only. - constexpr SetupFileXfer( - const Str255& filePath, - ImageFileFormat format, - Int16 vrn -#if defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX) - = -1 -#elif !defined(TWPP_DETAIL_OS_MAC) -# error "Volume reference number for your platform here" -#endif - ) noexcept : - m_filePath(filePath), m_format(format), - m_volRefNum(vrn){} - - /// Path to transfered file. - constexpr const Str255& filePath() const noexcept{ - return m_filePath; - } - - /// Sets path to transfered file. - void setFilePath(const Str255& filePath) noexcept{ - m_filePath = filePath; - } - - /// Format of the transfered file. - constexpr ImageFileFormat format() const noexcept{ - return m_format; - } - - /// Sets format of the transfered file. - void setFormat(ImageFileFormat format) noexcept{ - m_format = format; - } - - /// Volume reference number. - /// Mac OS only. - constexpr Int16 volumeReferenceNumber() const noexcept{ - return m_volRefNum; - } - - /// Sets volume reference number. - /// Mac OS only. - void setVolumeReferenceNumber(Int16 volumeReferenceNumber) noexcept{ - m_volRefNum = volumeReferenceNumber; - } - -private: - Str255 m_filePath; - ImageFileFormat m_format; - Int16 m_volRefNum; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_SETUPFILEXFER_HPP diff --git a/twain/twain/twpp/setupmemxfer.hpp b/twain/twain/twpp/setupmemxfer.hpp deleted file mode 100644 index e645f68..0000000 --- a/twain/twain/twpp/setupmemxfer.hpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_SETUPMEMXFER_HPP -#define TWPP_DETAIL_FILE_SETUPMEMXFER_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Structure for setting up memory transfer. -class SetupMemXfer { - -public: - /// Creates zero-initialized instance. - constexpr SetupMemXfer() noexcept : - m_minSize(0), m_maxSize(0), m_prefSize(0){} - - /// Creates an initialized instance with set minimal, maximal and preferred sizes. - /// Must be true, or the behaviour is undefined: minSize <= preferredSize <= maxSize - constexpr SetupMemXfer( - UInt32 minSize, - UInt32 maxSize, - UInt32 preferredSize - ) noexcept : - m_minSize(minSize), m_maxSize(maxSize), m_prefSize(preferredSize){} - - /// Minimal supported buffer size in bytes. - constexpr UInt32 minSize() const noexcept{ - return m_minSize; - } - - /// Sets minimal supported buffer size in bytes. - void setMinSize(UInt32 minSize) noexcept{ - m_minSize = minSize; - } - - /// Maximal supported buffer size in bytes. - constexpr UInt32 maxSize() const noexcept{ - return m_maxSize; - } - - /// Sets maximal supported buffer size in bytes. - void setMaxSize(UInt32 maxSize) noexcept{ - m_maxSize = maxSize; - } - - /// Preferred buffer size in bytes. - constexpr UInt32 preferredSize() const noexcept{ - return m_prefSize; - } - - /// Sets preferred buffer size in bytes. - void setPreferredSize(UInt32 prefSize) noexcept{ - m_prefSize = prefSize; - } - -private: - UInt32 m_minSize; - UInt32 m_maxSize; - UInt32 m_prefSize; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_SETUPMEMXFER_HPP diff --git a/twain/twain/twpp/status.hpp b/twain/twain/twpp/status.hpp deleted file mode 100644 index 7d72a5f..0000000 --- a/twain/twain/twpp/status.hpp +++ /dev/null @@ -1,230 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_STATUS_HPP -#define TWPP_DETAIL_FILE_STATUS_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Additional status information about a performed TWAIN operation. -class Status { - -public: - /// Creates operation status. - /// \param cond Status condition code. - /// \param data Additional status data, source-specific. - constexpr Status(CC cond = CC::Success, UInt16 data = 0) noexcept : - m_cond(cond), m_data(data){} - - /// Status condition code. - constexpr CC condition() const noexcept{ - return m_cond; - } - - /// Sets status condition code. - void setCondition(CC cc) noexcept{ - m_cond = cc; - } - - /// Aditional status data, source-specific. - constexpr UInt16 data() const noexcept{ - return m_data; - } - - /// Sets aditional status data, source-specific. - void setData(UInt16 data) noexcept{ - m_data = data; - } - - constexpr operator CC() const noexcept{ - return m_cond; - } - - constexpr operator bool() const noexcept{ - return success(m_cond); - } - - constexpr bool operator==(CC o) const noexcept{return m_cond == o;} - constexpr bool operator!=(CC o) const noexcept{return m_cond != o;} - - constexpr bool operator==(Status o) const noexcept{return m_cond == o.m_cond && m_data == o.m_data;} - constexpr bool operator!=(Status o) const noexcept{return m_cond != o.m_cond || m_data != o.m_data;} - - -private: - CC m_cond; - UInt16 m_data; - -}; - -static inline constexpr bool success(Status stat) noexcept{ - return stat; -} - -/// Structure for translating status to UTF8 text. -class StatusUtf8 { - -public: - typedef Detail::Lock ConstString; - - - /// Creates a status utf8 without string data. - StatusUtf8(Status status = Status()) noexcept : - m_status(status), m_size(0), m_string(){} - - /// Creates a status utf8 containing copy of string data. - /// The string must be null-terminated. - /// \tparam inputSize Size of the string including null terminator. - /// \param str The string, must be null-terminated. - /// \throw std::bad_alloc - template - StatusUtf8(Status status, const char(& str)[inputSize]) : - m_status(status), m_size(inputSize), m_string(Detail::alloc(inputSize)){ - - std::copy(str, str + inputSize, string().data()); - } - - /// Creates a new status utf8 containing a copy of the supplied string. - /// \param status - /// \param str Utf-8 string to copy, must be null-terminated. - /// \throw RangeException When string is too long, could not insert null terminator. - /// \throw std::bad_alloc - StatusUtf8(Status status, const char* str) : - m_status(status), m_size(0), m_string(){ - - auto len = strlen(str); - if (len >= std::numeric_limits::max()){ - throw RangeException(); - } - - m_size = static_cast(len) + 1; - m_string = Detail::alloc(m_size); - std::copy(str, str + len + 1, m_string.lock().data()); - } - - /// Creates a new status utf8 containing a copy of the supplied string. - /// \param status - /// \param str Utf-8 string to copy. - /// \throw RangeException When string is too long, could not insert null terminator. - /// \throw std::bad_alloc - StatusUtf8(Status status, const std::string& str) : - m_status(status), m_size(0), m_string(){ - - auto len = str.length(); - if (len >= std::numeric_limits::max()){ - throw RangeException(); - } - - m_size = static_cast(len) + 1; - m_string = Detail::alloc(m_size); - - auto lock = m_string.lock(); - std::copy(str.cbegin(), str.cend(), lock.data()); - lock[len] = '\0'; - } - - /// Creates a new StatusUtf8 containing a copy of the supplied string. - /// \param status - /// \param str Utf-8 string to copy, null terminator is not required. - /// \param strSize {Number of bytes to copy including null terminator. - /// Null terminator is inserted automatically.} - /// \throw RangeException When string is too short to satisfy the requested size. - /// \throw std::bad_alloc - StatusUtf8(Status status, const char* str, UInt32 strSize) : - m_status(status), m_size(0), m_string(){ - - auto len = strlen(str); - if (len < strSize){ - throw RangeException(); - } - - m_size = static_cast(strSize) + 1; - m_string = Detail::alloc(m_size); - - auto lock = m_string.lock(); - std::copy(str, str + strSize, lock.data()); - lock[strSize] = '\0'; - } - - StatusUtf8(const StatusUtf8&) = delete; - StatusUtf8& operator=(const StatusUtf8&) = delete; - - StatusUtf8(StatusUtf8&& o) noexcept : - m_status(o.m_status), m_size(o.m_size), m_string(std::move(o.m_string)){ - - o.m_status = Status(); - o.m_size = 0; - } - - StatusUtf8& operator=(StatusUtf8&& o) noexcept{ - if (&o != this){ - m_status = o.m_status; - m_size = o.m_size; - m_string = std::move(o.m_string); - - o.m_status = Status(); - o.m_size = 0; - } - - return *this; - } - - /// Returns the interpreted status. - Status status() const noexcept{ - return m_status; - } - - /// Sets the status to be interpreted. - void setStatus(Status status) noexcept{ - m_status = status; - } - - /// Returns the total number of bytes including null byte. - UInt32 size() const noexcept{ - return m_string ? m_size : 0; - } - - /// The UTF8 string itself. - ConstString string() const noexcept{ - return m_string.lock(); - } - -private: - Status m_status; - UInt32 m_size; - Detail::UniqueHandle m_string; - -}; - -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_STATUS_HPP - diff --git a/twain/twain/twpp/strings.hpp b/twain/twain/twpp/strings.hpp deleted file mode 100644 index 8698402..0000000 --- a/twain/twain/twpp/strings.hpp +++ /dev/null @@ -1,310 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015-2017 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_STRINGS_HPP -#define TWPP_DETAIL_FILE_STRINGS_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -namespace Detail { - -// specialization for twain strings -// on mac os, these strings do not contain null terminator -// instead, the first byte contains the length -template -struct FixedArrayData > { - - template - constexpr FixedArrayData(const char(& arr)[inputSize]) noexcept : - m_arr{ -#if defined(TWPP_DETAIL_OS_MAC) - unsignedToSigned(inputSize - 1), -#elif !defined(TWPP_DETAIL_OS_WIN) && !defined(TWPP_DETAIL_OS_LINUX) -# error "string data setup for yout platform here" -#endif - FixedArrayFlat(arr)[i]... - }{} - - constexpr FixedArrayData() noexcept : - m_arr(){} - - char m_arr[arraySize]; - -}; - -// specialization for twain strings -// on mac os, these strings do not contain null terminator -// instead, the first byte contains the length -// so we provide one less index for the fixed array -// on windows, its element is zero-initialized due to it not being specified -// on mac os, the first byte contains the length, so the index is not used anyway -template -struct FixedArray : public FixedArrayData::Result> { - - typedef FixedArrayData::Result> ParentType; - typedef char Array[arraySize]; - - constexpr FixedArray() noexcept : - ParentType(){} - - template - constexpr FixedArray(const char(& arr)[inputSize]) noexcept : - ParentType(arr){ - - static_assert(inputSize <= arraySize, "string literal is too long"); - } - - constexpr const Array& array() const noexcept{ - return ParentType::m_arr; - } - - Array& array() noexcept{ - return ParentType::m_arr; - } - -}; - -/// TWAIN string template. -/// \tparam arraySize String capacity, including either null byte, or length byte (Mac OS). -template -class Str : private FixedArray{ - - typedef FixedArray DataType; - -public: - typedef const char* const_iterator; - typedef char* iterator; - - /// Maximal number of characters this string may hold. - /// Excluding null byte (length byte). - static constexpr UInt32 maxSize() noexcept{ - return arraySize - 1; - } - - static_assert(maxSize() <= std::numeric_limits::max(), "string type exceeds allowed sizes"); - - - /// Creates an empty, zero-initialized string. - constexpr Str() noexcept{} - - /// Creates a compile-time string from string literal (or char array). - /// \tparam inputSize Size of the string literal including null terminator. - /// \param str The string literal. - template - constexpr Str(const char(& str)[inputSize]) noexcept : - DataType(str){ - - static_assert(inputSize <= arraySize, "string literal is too long"); - } - - /// Alias to length(). - constexpr UInt32 size() const noexcept{ - return length(); - } - - /// Length of the string (number of 8-bit characters). - /// O(1) on Mac OS, O(n) anywhere else. - constexpr UInt32 length() const noexcept{ -#if defined(TWPP_DETAIL_OS_MAC) - return static_cast(this->array()[0]); -#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX) - return strLen(data()); -#else -# error "String::length for your platform here" -#endif - } - - /// Pointer to constant data. - /// On Mac OS, the data is NOT null-terminated, - /// and points to the first character after size byte. - /// This operation is unsafe, and its use may not be platform-independent. - constexpr const char* data() const noexcept{ -#if defined(TWPP_DETAIL_OS_MAC) - return this->array() + 1; -#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX) - return this->array(); -#else -# error "String::data for your platform here" -#endif - } - - /// Pointer to data. - /// On Mac OS, the data is NOT null-terminated, - /// and points to the first character after size byte. - /// This operation is unsafe, and its use may not be platform-independent. - char* data() noexcept{ -#if defined(TWPP_DETAIL_OS_MAC) - return this->array() + 1; -#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX) - return this->array(); -#else -# error "String::data for your platform here" -#endif - } - - /// Sets string data. - /// Copies as much data as possible, discarding the rest. - /// The data needn't be null terminated. - /// \param str Data to copy. - /// \param size Maximal number of bytes to copy. - /// \return Number of bytes copied - the new length of this string. - UInt32 setData(const char* data, UInt32 size) noexcept{ - char* arr = this->data(); - UInt32 i = 0; - - auto maxLen = std::min(maxSize(), size); - for ( ; i < maxLen && *data; i++, data++){ - arr[i] = *data; - } - -#if defined(TWPP_DETAIL_OS_MAC) - *reinterpret_cast(this->array()) = static_cast(i); -#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX) - arr[i] = '\0'; -#else -# error "String::setData for your platform here" -#endif - - return i; - } - - /// Sets string data. - /// Copies as much data as possible, discarding the rest. - /// The string must be null terminated. - /// \param str String to copy. - /// \return Number of characters copied - the new length of this string. - UInt32 setData(const char* str) noexcept{ - return setData(str, maxSize()); - } - - /// Sets string data from container (e.g. std::string). - /// Copies as much data as possible, discarding the rest. - /// The string needn't be null terminated. - /// \tparam Contaier Container type. - /// \param cont Container with data to be copied. - /// \return Number of characters copied - the new length of this string. - template::value>::type> - UInt32 setData(const Container& cont) noexcept{ - return setData(cont.data(), static_cast(std::min(cont.size(), maxSize()))); - } - - char operator[](UInt32 i) const noexcept{ - return data()[i]; - } - - char& operator[](UInt32 i) noexcept{ - return data()[i]; - } - - iterator begin() noexcept{ - return data(); - } - - constexpr const_iterator begin() const noexcept{ - return cbegin(); - } - - constexpr const_iterator cbegin() const noexcept{ - return data(); - } - - iterator end() noexcept{ - return data() + length(); - } - - constexpr const_iterator end() const noexcept{ - return cend(); - } - - constexpr const_iterator cend() const noexcept{ - return data() + length(); - } - - std::string string() const{ - return std::string(cbegin(), cend()); - } - -}; - -} - -template -constexpr bool operator==(const Detail::Str& a, const Detail::Str& b) noexcept{ - // length() is O(1) on mac os, O(n) anywhere else -#if defined(TWPP_DETAIL_OS_MAC) - return a.length() == b.length() && Detail::strCmp(a.data(), b.data()) == 0; -#elif defined(TWPP_DETAIL_OS_WIN) || defined(TWPP_DETAIL_OS_LINUX) - return Detail::strCmp(a.data(), b.data()) == 0; -#else -# error "String equals operator for your platform here" -#endif - -} - -template -constexpr bool operator<(const Detail::Str& a, const Detail::Str& b) noexcept{ - return Detail::strCmp(a.data(), b.data()) < 0; -} - -template -constexpr bool operator>(const Detail::Str& a, const Detail::Str& b) noexcept{ - return Detail::strCmp(a.data(), b.data()) > 0; -} - -template -constexpr bool operator!=(const Detail::Str& a, const Detail::Str& b) noexcept{ - return !(a == b); -} - -template -constexpr bool operator<=(const Detail::Str& a, const Detail::Str& b) noexcept{ - return !(a > b); -} - -template -constexpr bool operator>=(const Detail::Str& a, const Detail::Str& b) noexcept{ - return !(a < b); -} - -/// TWAIN string that can contain up to 33 characters (bytes). -typedef Detail::Str<34> Str32; - -/// TWAIN string that can contain up to 65 characters (bytes). -typedef Detail::Str<66> Str64; - -/// TWAIN string that can contain up to 129 characters (bytes). -typedef Detail::Str<130> Str128; - -/// TWAIN string that can contain up to 255 characters (bytes). -typedef Detail::Str<256> Str255; - -} - - -#endif // TWPP_DETAIL_FILE_STRINGS_HPP - diff --git a/twain/twain/twpp/twglue.hpp b/twain/twain/twpp/twglue.hpp deleted file mode 100644 index be5b549..0000000 --- a/twain/twain/twpp/twglue.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef TWGLUE_HPP -#define TWGLUE_HPP - -#include -// #include "Device/PublicFunc.h" - -struct TwGlue { - - TwGlue(const std::function& scan, const std::function& cancel) : - m_scan(scan), m_cancel(cancel){} - - std::function m_scan; - std::function m_cancel; - -}; - -#endif // TWGLUE_HPP diff --git a/twain/twain/twpp/types.hpp b/twain/twain/twpp/types.hpp deleted file mode 100644 index ef01d75..0000000 --- a/twain/twain/twpp/types.hpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_TYPES_HPP -#define TWPP_DETAIL_FILE_TYPES_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -typedef std::uintptr_t UIntPtr; -typedef std::uint8_t UInt8; -typedef std::uint16_t UInt16; -typedef std::uint32_t UInt32; -typedef std::int8_t Int8; -typedef std::int16_t Int16; -typedef std::int32_t Int32; - -/// Boolean value. -/// Implemented as a class to provide better type safety. -class Bool { - -public: - constexpr Bool(bool value = false) noexcept : - m_value(value){} - - constexpr operator bool() const noexcept{ - return m_value != 0; - } - -private: - Int16 m_value; - -}; - -/// Handle to memory area. -/// Implemented as a class to provide better type safety. -class Handle { - -public: - typedef Detail::RawHandle Raw; - - constexpr explicit Handle(Raw raw = Raw()) noexcept : - m_raw(raw){} - - /// Underlying OS-dependent handle. - constexpr Raw raw() const noexcept{ - return m_raw; - } - - constexpr operator bool() const noexcept{ - return m_raw != Raw(); - } - -private: - Raw m_raw; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_TYPES_HPP - diff --git a/twain/twain/twpp/typesops.hpp b/twain/twain/twpp/typesops.hpp deleted file mode 100644 index 3c187fd..0000000 --- a/twain/twain/twpp/typesops.hpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_TYPESOPS_HPP -#define TWPP_DETAIL_FILE_TYPESOPS_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -/// Enumeration representing basic types. -enum class Type : UInt16 { - DontCare = 0xFFFF, - Int8 = 0x0000, - Int16 = 0x0001, - Int32 = 0x0002, - UInt8 = 0x0003, - UInt16 = 0x0004, - UInt32 = 0x0005, - Bool = 0x0006, - Fix32 = 0x0007, - Frame = 0x0008, - Str32 = 0x0009, - Str64 = 0x000a, - Str128 = 0x000b, - Str255 = 0x000c, - Handle = 0x000f -}; - -/// Whether the enum value actually is a type, DontCare is not a type. -static inline bool isType(Type type){ - switch (type){ - case Type::Int8: - case Type::UInt8: - case Type::Int16: - case Type::UInt16: - case Type::Int32: - case Type::UInt32: - case Type::Bool: - case Type::Fix32: - case Type::Str32: - case Type::Str64: - case Type::Str128: - case Type::Str255: - case Type::Frame: - case Type::Handle: - return true; - - default: - return false; - } -} - -/// Size in bytes of a type represented by enum value. -static inline UInt32 typeSize(Type type){ - switch (type){ - case Type::Int8: return sizeof(Int8); - case Type::UInt8: return sizeof(UInt8); - case Type::Int16: return sizeof(Int16); - case Type::UInt16: return sizeof(UInt16); - case Type::Int32: return sizeof(Int32); - case Type::UInt32: return sizeof(UInt32); - case Type::Bool: return sizeof(Bool); - case Type::Fix32: return sizeof(Fix32); - case Type::Str32: return sizeof(Str32); - case Type::Str64: return sizeof(Str64); - case Type::Str128: return sizeof(Str128); - case Type::Str255: return sizeof(Str255); - case Type::Frame: return sizeof(Frame); - case Type::Handle: return sizeof(Handle); - default: throw TypeException(); - } -} - -namespace Detail { - -/// Conversion from Type enum to actual data type. -template struct Twty {}; -template<> struct Twty {typedef Int8 Type;}; -template<> struct Twty {typedef Int16 Type;}; -template<> struct Twty {typedef Int32 Type;}; -template<> struct Twty {typedef UInt8 Type;}; -template<> struct Twty {typedef UInt16 Type;}; -template<> struct Twty {typedef UInt32 Type;}; -template<> struct Twty {typedef Bool Type;}; -template<> struct Twty {typedef Fix32 Type;}; -template<> struct Twty {typedef Frame Type;}; -template<> struct Twty {typedef Str32 Type;}; -template<> struct Twty {typedef Str64 Type;}; -template<> struct Twty {typedef Str128 Type;}; -template<> struct Twty {typedef Str255 Type;}; -template<> struct Twty {typedef Handle Type;}; - - -// Conversion from data type to Type enum helpers. -template struct Tytw; - -template // true -struct TytwHelper : Tytw::type> {}; - -template -struct TytwHelper {}; - -/// Conversion from data type to Type enum. -template struct Tytw : TytwHelper::value> {}; -template<> struct Tytw {static constexpr const Type twty = Type::Int8;}; -template<> struct Tytw {static constexpr const Type twty = Type::Int16;}; -template<> struct Tytw {static constexpr const Type twty = Type::Int32;}; -template<> struct Tytw {static constexpr const Type twty = Type::UInt8;}; -template<> struct Tytw {static constexpr const Type twty = Type::UInt16;}; -template<> struct Tytw {static constexpr const Type twty = Type::UInt32;}; -template<> struct Tytw {static constexpr const Type twty = Type::Bool;}; -template<> struct Tytw {static constexpr const Type twty = Type::Fix32;}; -template<> struct Tytw {static constexpr const Type twty = Type::Frame;}; -template<> struct Tytw {static constexpr const Type twty = Type::Str32;}; -template<> struct Tytw {static constexpr const Type twty = Type::Str64;}; -template<> struct Tytw {static constexpr const Type twty = Type::Str128;}; -template<> struct Tytw {static constexpr const Type twty = Type::Str255;}; -template<> struct Tytw {static constexpr const Type twty = Type::Handle;}; - -} - -} - -#endif // TWPP_DETAIL_FILE_TYPESOPS_HPP - diff --git a/twain/twain/twpp/userinterface.hpp b/twain/twain/twpp/userinterface.hpp deleted file mode 100644 index ba42bcd..0000000 --- a/twain/twain/twpp/userinterface.hpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015-2017 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_USERINTERFACE_HPP -#define TWPP_DETAIL_FILE_USERINTERFACE_HPP - -#include "../twpp.hpp" - -namespace Twpp { - -TWPP_DETAIL_PACK_BEGIN -/// Structure holding parameters for enabling or disabling data source. -class UserInterface { - -public: - /// Creates a new UserInterface. - /// \param showUi Whether to show internal DS GUI. Disabling DS GUI might not be supported. - /// \param modalUi Whether DS GUI should be modal. Not used on Linux. Might not be supported on Windows. - /// \param parent Windows-only, others set to null. Handle to parent window. This object does NOT take ownership. -#if defined(TWPP_DETAIL_OS_WIN) - constexpr UserInterface(Bool showUi, Bool modalUi, Handle parent) noexcept : - m_showUi(showUi), m_modalUi(modalUi), m_parent(parent){} -#elif defined(TWPP_DETAIL_OS_MAC) || defined(TWPP_DETAIL_OS_LINUX) - constexpr UserInterface(Bool showUi, Bool modalUi, Handle parent = Handle()) noexcept : - m_showUi(showUi), m_modalUi(modalUi), m_parent(parent){} -#else -# error "UserInterface constructor for your platform here" -#endif - - /// Whether to show internal DS GUI. - constexpr Bool showUi() const noexcept{ - return m_showUi; - } - - /// Whether DS GUI should be modal - constexpr Bool modalUi() const noexcept{ - return m_modalUi; - } - - /// Handle to parent window. - constexpr Handle parent() const noexcept{ - return m_parent; - } - -private: - Bool m_showUi; - Bool m_modalUi; - Handle m_parent; - -}; -TWPP_DETAIL_PACK_END - -} - -#endif // TWPP_DETAIL_FILE_USERINTERFACE_HPP - diff --git a/twain/twain/twpp/utils.hpp b/twain/twain/twpp/utils.hpp deleted file mode 100644 index 5eb122c..0000000 --- a/twain/twain/twpp/utils.hpp +++ /dev/null @@ -1,485 +0,0 @@ -/* - -The MIT License (MIT) - -Copyright (c) 2015 Martin Richter - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -#ifndef TWPP_DETAIL_FILE_UTILS_HPP -#define TWPP_DETAIL_FILE_UTILS_HPP - -#undef max -#undef min -#include -#include "../twpp.hpp" - -namespace Twpp { - -namespace Detail { - -/// Creates a template for testing whether a class contains public static method. -/// Use this macro anywhere a class may be defined, and pass method name -/// as its parameter. Then use `HasStaticMethod_` template. -/// -/// E. g.: -/// TWPP_DETAIL_CREATE_HAS_STATIC_METHOD(myMethod) // <- semicolon not required -/// HasStaticMethod_myMethod::value -/// -/// This test whether `MyClass` has static method `void MyClass::myMethod(int, char)`. -/// That is whether you may do this: -/// MyClass::myMethod(10, 'a'); -#define TWPP_DETAIL_CREATE_HAS_STATIC_METHOD(methodName) \ - template\ - class HasStaticMethod_ ## methodName;\ - \ - template\ - class HasStaticMethod_ ## methodName {\ - \ - template\ - static constexpr auto test(U*) ->\ - typename std::is_same()...)), Ret>::type;\ - \ - template\ - static constexpr std::false_type test(...);\ - \ - public:\ - typedef decltype(test(0)) type;\ - static constexpr const bool value = type::value;\ - \ - }; - -/// Creates a template for testing whether a class contains public method. -/// Use this macro anywhere a class may be defined, and pass method name -/// as its parameter. Then use `HasMethod_` template. -/// -/// E. g.: -/// TWPP_DETAIL_CREATE_HAS_METHOD(myMethod) // <- semicolon not required -/// HasMethod_myMethod::value -/// -/// This test whether `MyClass` has method (AKA member function) `void MyClass::myMethod(int, char)`. -/// That is whether you may do this: -/// MyClass o ... ; -/// o.myMethod(10, 'a'); -#define TWPP_DETAIL_CREATE_HAS_METHOD(methodName) \ - template\ - class HasMethod_ ## methodName;\ - \ - template\ - class HasMethod_ ## methodName {\ - \ - template\ - static constexpr auto test(U*) ->\ - typename std::is_same().methodName(std::declval()...)), Ret>::type;\ - \ - template\ - static constexpr std::false_type test(...);\ - \ - public:\ - typedef decltype(test(0)) type;\ - static constexpr const bool value = type::value;\ - \ - }; - -/// Performs a pointer type cast, suppresses strict aliasing warnings. -/// \tparam T Type of the returned pointer. Must be pointer type (e.g. `char*`). -/// \param ptr Pointer to be cast. -/// \return Cast pointer. -template -static constexpr inline T alias_cast(void* ptr) noexcept{ - return reinterpret_cast(ptr); -} - -/// Performs a constant pointer type cast, suppresses strict aliasing warnings. -/// \tparam T Type of the returned pointer. Must be pointer type (e.g. `char*`). -/// \param ptr Pointer to be cast. -/// \return Cast pointer. -template -static constexpr inline T alias_cast(const void* ptr) noexcept{ - return reinterpret_cast(ptr); -} - -/// Suppresses warnings about unused parameters or arguments. -/// \tparam Args List of argument types. No need to specify explicitly. -template -static inline void unused(const Args& ...) noexcept{} - - - -// CODE FROM http://www.macieira.org/blog/2011/07/initialising-an-array-with-cx0x-using-constexpr-and-variadic-templates/ -// BEGIN -template struct IndexList {}; - -template struct Append; -template -struct Append, Right>{ typedef IndexList Result; }; - -template struct Indexes { - typedef typename Append::Result, N - 1>::Result Result; -}; -template<> struct Indexes<0> { typedef IndexList<> Result; }; -// END - -/// Converts an array of arbitary size to array-like recursive structure of fixed size (at compile time). -/// Provide template specialization if special handling of elements is required, and you do care -/// about their positions - otherwise see FixedArrayData below. -/// \tparam T Element type. -/// \tparam arraySize Number of elements in the fixed array. -template -struct FixedArrayFlat : FixedArrayFlat { - - /// The index this structure (with this `arraySize`) holds. - static constexpr const std::size_t g_index = arraySize - 1; - - /// Performs the conversion from arbiraty-size array to fixed-size structure. - /// We use left recursion to initialize values of all inherited structures first. - /// Then the value of this one is initialized, either copied from the input array itself, - /// or default-initialized in case the array is not large enough. - /// \tparam inputSize {Size of the input array. If smaller than the fixed array, - /// excessive elements are default-initialized (may be changed in specializations). - /// Providing larger array results in undefined behaviour.} - /// \param arr The arbitary-size array. - template - constexpr inline FixedArrayFlat(const T(& arr)[inputSize]) noexcept : - FixedArrayFlat(arr), m_val(g_index < inputSize ? arr[g_index] : T()){} - - /// Returns value contained at specific index. - /// If the index if smaller than the size of the input array, a value is returned - /// as if the operation was performed on that array. Otherwise a default value - /// of the type `T` is returned (or anything else a specialization provides). - /// Behaviour of this operator is undefined if the index equals to or is greater than - /// the size of the fixed array. - /// \param i Value index. - /// \return Value at index. - constexpr inline T operator[](std::size_t i) const noexcept{ - return i == g_index ? m_val : FixedArrayFlat::operator [](i); - } - - /// Value held by this structure. - T m_val; - -}; - -/// Converts an array of arbitary size to array-like recursive structure of fixed size (at compile time). -/// This template specialization terminates the recursion. -/// No need to provide any further specializations. -/// \tparam T Element type. -template -struct FixedArrayFlat { - - template - constexpr inline FixedArrayFlat(const T(&)[inputSize]) noexcept{} - - constexpr inline T operator[](std::size_t) const noexcept{ - return T(); - } - -}; - - -/// Converts an array of arbitary size to array of fixed size at compile time. -/// The job itself is done in the specialization below. -/// \tparam T Element type. -/// \tparam arraySize Number of elements in the fixed array. -/// \tparam IndexList Type holding indexes of the fixed array. -template -struct FixedArrayData {}; - -/// Converts an array of arbitary size to array of fixed size at compile time. -/// Provide template specialization if special handling of elements is required, and you -/// don't care about their positions. -/// \tparam T Element type. -/// \tparam arraySize Number of elements in the fixed array. -/// \tparam i Indexes of the fixed array. -template -struct FixedArrayData > { - - /// Performs the conversion from arbiraty-size array to fixed-size array. - /// Uses FixedArrayFlat to extend the input array to desired size. - /// \tparam inputSize Size of the input array. - /// \param arr The input array. - template - constexpr FixedArrayData(const T(& arr)[inputSize]) noexcept : - m_arr{FixedArrayFlat(arr)[i]...}{} - - /// Creates default-initialized array. - constexpr FixedArrayData() noexcept : - m_arr(){} - - /// The fixed array. - T m_arr[arraySize]; - -}; - -/// Compile-time constructible fixed-size array of type `T` and length `arraySize`. -/// The array can be constructed from variable-sized array -/// of up to `arraySize` elements at compile time. -/// \tparam T Element type. -/// \tparam arraySize Number of elements in the array. -template -struct FixedArray : public FixedArrayData::Result> { - - typedef FixedArrayData::Result> ParentType; - typedef T Array[arraySize]; - - /// Creates default-initialized array. - constexpr FixedArray() noexcept : - ParentType(){} - - /// Creates fixed-size array from variable-size array at compile time. - /// If the size of input array exceeds `arraySize`, a compile-time error is emited. - /// \tparam inputSize Number of elements of the input array. - /// \param arr The input array. - template - constexpr FixedArray(const T(& arr)[inputSize]) noexcept : - ParentType(arr){ - - static_assert(inputSize <= arraySize, "array literal is too big"); - } - - /// The contained array. - constexpr const Array& array() const noexcept{ - return ParentType::m_arr; - } - - /// The contained array. - Array& array() noexcept{ - return ParentType::m_arr; - } - -}; - -/// Joins two arrays at compile time. -/// The job itself is done in the specialization below. -/// \tparam T Element type. -/// \tparam lenA Size of the first array. -/// \tparam lenB Size of the second array. -/// \tparam IndexList Type holding indexes of the resulting array. -template -struct ArrayJoinData {}; - -/// Joins two arrays at compile time. -/// The result of this operation is an array that contains all the elements -/// from the first array immediately followed by all the elements from -/// the second array. -/// \tparam T Element type. -/// \tparam lenA Size of the first array. -/// \tparam lenB Size of the second array. -/// \tparam i Indexes of the resulting array. -template -struct ArrayJoinData > { - - /// Performs the join operation. - /// \param a The first array. - /// \param b The second array. - constexpr ArrayJoinData(const T(& a)[lenA], const T(& b)[lenB]) noexcept : - m_arr{(i < lenA ? a[i] : b[i - lenA])...}{} - - /// The resulting array. - T m_arr[lenA + lenB]; - -}; - -/// Compile-time join operation of two arrays of the same type. -/// \tparam T Element type. -/// \tparam lenA Size of the first array. -/// \tparam lenB Size of the second array. -template -struct ArrayJoin : public ArrayJoinData::Result> { - - typedef ArrayJoinData::Result> ParentType; - typedef T Array[lenA + lenB]; - - /// Performs the join operation. - /// \param a The first array. - /// \param b The second array. - constexpr ArrayJoin(const T(& a)[lenA], const T(& b)[lenB]) noexcept : - ParentType(a, b){} - - /// The joined array. - constexpr const Array& array() const noexcept{ - return ParentType::m_arr; - } - - /// The joined array. - Array& array() noexcept{ - return ParentType::m_arr; - } - -}; - -/// Performs compile-time array join operation. -/// This is a helper function, see ArrayJoin and ArrayJoinData for more info. -/// \tparam T Element type. -/// \tparam lenA Size of the first array. -/// \tparam lenB Size of the second array. -/// \param a The first array. -/// \param b The second array. -/// \return The joined array. -template -static constexpr inline ArrayJoin arrayJoin(const T(& a)[lenA], const T(& b)[lenB]) noexcept{ - return {a, b}; -} - - -/// The loop that checks the suffix at compile time, see endsWith below. -/// Checks are performed from right to left. -/// \tparam T Element type. -/// \tparam arrLen The size of the array to be checked for the suffix. -/// \tparam subLen The size of the suffix array. -/// \param arr The array to be checked for the suffix. -/// \param sub The suffix array. -/// \param endOff Offset from the last element to be checked in this call. -/// \return Whether the suffix is contained. -template -static constexpr inline bool endsWithLoop(const T(& arr)[arrLen], const T(& sub)[subLen], std::size_t endOff){ - return endOff >= subLen || (arr[arrLen - 1 - endOff] == sub[subLen - 1 - endOff] && endsWithLoop(arr, sub, endOff + 1)); -} - -/// Checks whether the input array contains supplied suffix at compile time. -/// \tparam T Element type. -/// \tparam arrLen The size of the array to be checked for the suffix. -/// \tparam subLen The size of the suffix array. -/// \param arr The array to be checked for the suffix. -/// \param sub The suffix array. -/// \return Whether the suffix is contained. -template -static constexpr inline bool endsWith(const T(& arr)[arrLen], const T(& sub)[subLen]){ - return arrLen >= subLen && endsWithLoop(arr, sub, 0); -} - -/// Implementation of compile-time C string length. -/// Uses tail recursion. -/// \param str The string, or its remaining part. -/// \param len Length of the previous, already processed, part of the string. -/// \return Length of the string. -static constexpr inline std::size_t strLenImpl(const char* str, std::size_t len = 0) noexcept{ - return *str == '\0' ? len : strLenImpl(str + 1, len + 1); -} - -/// Compile-time C string length. -/// \param str The string. -/// \return Length of the string. -static constexpr inline std::size_t strLen(const char* str) noexcept{ - return strLenImpl(str); -} - - -/// Unsigned to signed conversion, using static_cast. -/// Available only if integers are represented using 2 complement. -/// Specialization handles non-2 complement cases. -/// \tparam T An integral type. -/// \tparam _2complement Whether ints are represented as 2 complement. -template // true -struct UnsigToSig { - typedef typename std::make_signed::type Signed; - typedef typename std::make_unsigned::type Unsigned; - - static constexpr Signed convert(Unsigned val) noexcept{ - return static_cast(val); - } -}; - -/// Unsigned to signed conversion. -/// This specialization is used when architecture does not use 2 complement. -/// \tparam T An integral type. -template -struct UnsigToSig { - typedef typename std::make_signed::type Signed; - typedef typename std::make_unsigned::type Unsigned; - - static constexpr Signed convert(Unsigned val) noexcept{ - return val <= std::numeric_limits::max() ? - static_cast(val) : - static_cast(val - std::numeric_limits::min()) + std::numeric_limits::min(); - } -}; - -/// Converts, at compile time, an unsigned integer to its signed counterpart. -/// This holds true: unsignedValue == static_cast(unsignedToSigned(unsignedValue)) -/// \tparam T Unsigned integral type. -/// \param val Unsigned value to be converted to signed. -/// \return Signed value that can be converted back to its unsigned type. -template::value>::type> -static constexpr inline typename std::make_signed::type unsignedToSigned(T val) noexcept{ - typedef typename std::make_signed::type Signed; - typedef typename std::make_unsigned::type Unsigned; - - return UnsigToSig(-1) == static_cast(~Unsigned(0))>::convert(val); -} - -/// Compares two C strings at compile time as if strcmp was used. -/// \param a First string. -/// \param b Second string. -/// \return See strcmp. -static constexpr inline int strCmp(const char* a, const char* b) noexcept{ - return *a != *b ? (static_cast(*a) - *b) : (*a == '\0' ? 0 : strCmp(a + 1, b + 1)); -} - -/// Absolute value. -/// Default implementation handles signed values -/// of non-integral types. -/// \tparam T Data type. -/// \tparam integral Whether the type is integral. -/// \tparam unsig Whether the data type is unsigned. -template // false, false -struct Abs { - static constexpr inline T abs(T a) noexcept{ - return a >= T() ? a : -a; - } -}; - -/// Absolute value. -/// This handles signed values of integral types. -/// \tparam T Data type. -template -struct Abs { - static constexpr inline T abs(T a) noexcept{ - return std::abs(a); - } -}; - -/// Absolute value. -/// This handles unsigned values. -/// \tparam T Data type. -template -struct Abs { - static constexpr inline T abs(T a) noexcept{ - return a; - } -}; - -/// Absolute value. -/// Handles anything that has `bool operator >=(const T&)` (or equiv.), -/// `T operator-()`, and its default value represents `zero`. -/// \tparam T Data type. -/// \param a Value. -template -static constexpr inline T abs(T a) noexcept{ - return Abs::value, std::is_unsigned::value>::abs(a); -} - -} - -} - -#endif // TWPP_DETAIL_FILE_UTILS_HPP -