diff --git a/ci-scripts/osx/travis-install.sh b/ci-scripts/osx/travis-install.sh index afcf05b6..e2d1506c 100755 --- a/ci-scripts/osx/travis-install.sh +++ b/ci-scripts/osx/travis-install.sh @@ -6,6 +6,8 @@ brew install clang-format # from Homebrew 1.6.0 the old formula for obtaining Qt5.9.2 becomes invalid. # so we start to use the latest version of Qt. (#1910) brew install qt +# delete older qt versions and make sure to have only the latest +brew cleanup qt # temp workaround to brew installed glew cmake info overriding glew lib detection # which causes compiling issues later if [ -L /usr/local/lib/cmake/glew ] diff --git a/stuff/profiles/layouts/rooms/Default/menubar_template.xml b/stuff/profiles/layouts/rooms/Default/menubar_template.xml index f1124395..dae4e0e0 100644 --- a/stuff/profiles/layouts/rooms/Default/menubar_template.xml +++ b/stuff/profiles/layouts/rooms/Default/menubar_template.xml @@ -76,22 +76,6 @@ MI_SendBackward - - MI_DefineScanner - MI_ScanSettings - MI_Scan - MI_SetScanCropbox - MI_ResetScanCropbox - - MI_CleanupSettings - MI_CleanupPreview - MI_OpacityCheck - MI_CameraTest - MI_Cleanup - - MI_PencilTest - MI_Autocenter - MI_NewLevel @@ -241,6 +225,15 @@ MI_Link + + MI_CleanupSettings + MI_CleanupPreview + MI_OpacityCheck + MI_CameraTest + MI_Cleanup + + MI_PencilTest + MI_PreviewSettings MI_Preview diff --git a/toonz/sources/common/twain/ttwain.h b/toonz/sources/common/twain/ttwain.h deleted file mode 100644 index 5779a4d5..00000000 --- a/toonz/sources/common/twain/ttwain.h +++ /dev/null @@ -1,116 +0,0 @@ -#pragma once - -#ifndef __TTWAIN_H__ -#define __TTWAIN_H__ - -#ifdef _WIN32 -#include -#else -#ifndef _UNIX_ -#define _UNIX_ -#endif -#endif - -#include "twain.h" - -#include "tnztypes.h" - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef UCHAR -#define UCHAR unsigned char -#endif - -#ifndef USHORT -#define USHORT unsigned short -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum TTWAIN_PIXTYPE { - TTWAIN_BW, /* 1-bit per pixel, B&W */ - TTWAIN_WB, /* 1-bit per pixel, W&B */ - TTWAIN_GRAY8, /* 1,4, or 8-bit grayscale */ - TTWAIN_RGB24, /* 24-bit RGB color */ - TTWAIN_PIXTYPE_HOWMANY, - TTWAIN_PIXUNKNOWN = -1, -} TTWAIN_PIXTYPE; - -typedef enum TTWAIN_BITORDER { - TTWAIN_LSBFIRST = TWBO_LSBFIRST, - TTWAIN_MSBFIRST = TWBO_MSBFIRST -} TTWAIN_BITORDER; - -typedef enum TWAINAVAILABLE { - AVAIABLE_DONTKNOW = -1, - AVAIABLE_YES, - AVAIABLE_NO -} TWAINAVAILABLE; - -typedef enum TTWAIN_TRANSFER_MECH { - TTWAIN_TRANSFERMODE_NATIVE = TWSX_NATIVE, - TTWAIN_TRANSFERMODE_MEMORY = TWSX_MEMORY, - TTWAIN_TRANSFERMODE_FILE = TWSX_FILE -} TTWAIN_TRANSFER_MECH; - -typedef enum TTWAIN_USAGE_MODE { - TTWAIN_MODE_LEASHED, - TTWAIN_MODE_UNLEASHED -} TTWAIN_USAGE_MODE; - -/* application should return 0 to stop the scanning process, any other value - * elsewhere */ -typedef int TTWAIN_ONDONE_CB(UCHAR *buffer, TTWAIN_PIXTYPE pixelType, int lx, - int ly, int wrap, float xdpi, float ydpi, - void *usrData); - -typedef void TTWAIN_ONERROR_CB(void *usrData, void *alwaysZero); - -int TTWAIN_IsAvailable(void); -void TTWAIN_RegisterApp( - int majorNum, int minorNum, /* app. revision*/ - int nLanguage, /* (human) language (use TWLG_xxx from TWAIN.H) */ - int nCountry, /* country (use TWCY_xxx from TWAIN.H) */ - char *version, /* version info string */ - char *manufacter, /* name of manufacter */ - char *family, /* product family */ - char *product); /* specific product */ -int TTWAIN_SelectImageSource(void *hwnd); -/*---------------------------------------------------------------------------*/ -void *TTWAIN_AcquireNative(void *hwnd); -int TTWAIN_AcquireMemory(void *hwnd); -void TTWAIN_StopAcquire(void); - -/* -nb. AcquireMemory returns: an upside-down bitmap :) -nb. AcquireNative returns: - under Windows an HBITMAP - under Mac a PICT -*/ -/*---------------------------------------------------------------------------*/ -void TTWAIN_SetTwainUsage(TTWAIN_USAGE_MODE um); - -void TTWAIN_FreeMemory(void *hMem); -int TTWAIN_CloseAll(void *hwnd); -int TTWAIN_OpenSourceManager(void *hwnd); -int TTWAIN_OpenDefaultSource(void); - -int TTWAIN_GetHideUI(void); -void TTWAIN_SetHideUI(int flag); - -void TTWAIN_SetOnDoneCallback(TTWAIN_ONDONE_CB *proc, void *arg); -void TTWAIN_SetOnErrorCallback(TTWAIN_ONERROR_CB *proc, void *arg); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/toonz/sources/common/twain/ttwainP.h b/toonz/sources/common/twain/ttwainP.h deleted file mode 100644 index 4534c6cd..00000000 --- a/toonz/sources/common/twain/ttwainP.h +++ /dev/null @@ -1,102 +0,0 @@ -#pragma once - -#ifndef __TTWAINP_H__ -#define __TTWAINP_H__ - -#include "ttwain.h" - -#ifdef TTWAINLIB_MAIN -#define EXTERN -#else -#define EXTERN extern -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum TWAINSTATE { - TWAIN_PRESESSION = 1, /* source manager not loaded */ - TWAIN_SM_LOADED, /* source manager loaded */ - TWAIN_SM_OPEN, /* source manager open */ - TWAIN_SOURCE_OPEN, /* source open but not enabled*/ - TWAIN_SOURCE_ENABLED, /* source enabled to acquire */ - TWAIN_TRANSFER_READY, /* image ready to transfer */ - TWAIN_TRANSFERRING /* image in transit */ -} TWAINSTATE; - -#ifdef _WIN32 -#ifdef x64 -#define DSM_FILENAME "TWAINDSM.DLL" -#else -#define DSM_FILENAME "TWAIN_32.DLL" -#endif -#define DSM_ENTRYPOINT "DSM_Entry" -#else -#define DSM_FILENAME "" -#define DSM_ENTRYPOINT "" -#endif - -struct TRANSFER_INFO { - TTWAIN_TRANSFER_MECH transferMech; /*current transfer mechanism */ - TTWAIN_USAGE_MODE usageMode; - /*used by buffered memory tranfer */ - unsigned char *memoryBuffer; - unsigned long memorySize; - /*used by native tranfer */ - void *hDib; - /*common to all the transfer mode */ - int preferredLx; - int preferredLy; - int multiTransfer; - int nextImageNeedsToBeInverted; - int lastTransferWasOk; - TW_PENDINGXFERS pendingXfers; - int oneAtLeast; -}; - -struct CALLBACKS { - TTWAIN_ONDONE_CB *onDoneCb; - void *onDoneArg; - TTWAIN_ONERROR_CB *onErrorCb; - void *onErrorArg; -}; - -struct _TTWAIN_DATA__ { - /*HANDLE*/ - DSMENTRYPROC DSM_Entry; /* entry point of Data Source Manager(TWAIN.DLL)*/ - TW_INT32 hwnd32SM; /* window handle */ - /*IDENTITY*/ - TW_IDENTITY sourceId; /* source identity structure */ - TW_IDENTITY appId; /* Application Ident. for DS */ - TW_USERINTERFACE twainUI; /* */ - - int initDone; - TWAINAVAILABLE twainAvailable; - TWAINSTATE twainState; /* the current twain state */ - - struct TRANSFER_INFO transferInfo; - struct CALLBACKS callback; - TW_ARRAY *supportedCaps; /* all the (exported)supported capabilities */ - int isSupportedCapsSupported; - - int breakModalLoop; - - int UIStatus; /* Hide or Show UserInterface */ - int modalStatus; - - TW_INT16 resultCode; /* result code for LAST error */ - - TUINT32 ErrRC; /* result & condition code */ - TUINT32 ErrCC; /* for LAST RECORDED error */ -}; - -EXTERN struct _TTWAIN_DATA__ TTwainData; - -EXTERN int TTWAIN_InitVar(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/toonz/sources/common/twain/ttwain_capability.c b/toonz/sources/common/twain/ttwain_capability.c deleted file mode 100644 index ceaf31ff..00000000 --- a/toonz/sources/common/twain/ttwain_capability.c +++ /dev/null @@ -1,341 +0,0 @@ - - -/*max@home*/ -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef NOTE -ConvertOneValue2Enum() potrebbe essere fonte di errore se - DCItemSize[one_value.ItemType] > - DCItemSize[TW_INT8] e si utilizzano i bit piu significativi di one_value - .Item - ConvertEnumeration2Range() potrebbe restituire valori di StepSize non - appropriati se enumeration.ItemType e TW_FIX32 potrebbe - restituire valori MinValue non corretti se DCItemSize[xxx.ItemType] > - DCItemSize[TW_INT8] e si utilizzano i bit piu significativi di xxx.Item - ConvertEnum2OneValue ritorna(ovviamente) solo il valore corrente -#endif - -#include -#include - -#include "ttwain_capability.h" -#include "ttwain_conversion.h" -#include "ttwain_error.h" -#include "ttwain_state.h" - -#include "ttwain_global_def.h" - - /*---------------------------------------------------------------------------*/ - static const size_t DCItemSize[13] = { - sizeof(TW_INT8), sizeof(TW_INT16), sizeof(TW_INT32), sizeof(TW_UINT8), - sizeof(TW_UINT16), sizeof(TW_UINT32), sizeof(TW_BOOL), sizeof(TW_FIX32), - sizeof(TW_FRAME), sizeof(TW_STR32), sizeof(TW_STR64), sizeof(TW_STR128), - sizeof(TW_STR255), -}; /* see twain.h */ - -/*---------------------------------------------------------------------------*/ -#define TWON_TWON(TYPE1, TYPE2) (((TYPE1) << 8) | (TYPE2)) -/*---------------------------------------------------------------------------*/ -static int ConvertOneValue2Range(TW_ONEVALUE one_value, TW_RANGE *range); -static int ConvertEnumeration2Range(TW_ENUMERATION enumeration, - TW_RANGE *range); -static int ConvertOneValue2Enum(TW_ONEVALUE one_value, TW_ENUMERATION *tw_enum); -static int ConvertEnum2OneValue(TW_ENUMERATION tw_enum, TW_ONEVALUE *one_value); -static int ConvertEnum2Array(TW_ENUMERATION tw_enum, TW_ARRAY *array); - -static TUINT32 GetContainerSize(int nFormat, unsigned twty, TW_UINT32 nItems); -static int TTWAIN_GetCapability(TW_INT16 msgType, TW_UINT16 cap_id, - TW_UINT16 conType, void *data, - TUINT32 *cont_size); -/*------------------------------------------------------------------------*/ -int TTWAIN_GetCap(TW_UINT16 cap_id, TW_UINT16 conType, void *data, - TUINT32 *cont_size) { - return TTWAIN_GetCapability(MSG_GET, cap_id, conType, data, cont_size); -} -/*------------------------------------------------------------------------*/ -int TTWAIN_GetCapCurrent(TW_UINT16 cap_id, TW_UINT16 conType, void *data, - TUINT32 *cont_size) { - return TTWAIN_GetCapability(MSG_GETCURRENT, cap_id, conType, data, cont_size); -} -/*------------------------------------------------------------------------*/ -int TTWAIN_GetCapQuery(TW_UINT16 cap_id, TW_UINT16 *pattern) { - int rc; - /* GCC9 during compilation shows that this code possible call - * TTWAIN_GetCapability() with case TWON_TWON(TWON_RANGE, TWON_RANGE) - * whitch cause stack corruption, so make 'data' big enough to store - * TW_ONEVALUE. */ - TW_ONEVALUE data[1 + (sizeof(TW_RANGE) / sizeof(TW_ONEVALUE))]; - rc = TTWAIN_GetCapability(MSG_QUERYSUPPORT, cap_id, TWON_ONEVALUE, &data, 0); - if (!rc) return FALSE; - *pattern = (TW_UINT16)data[0].Item; - return TRUE; -} -/*------------------------------------------------------------------------*/ -static int TTWAIN_GetCapability(TW_INT16 msgType, TW_UINT16 cap_id, - TW_UINT16 conType, void *data, - TUINT32 *cont_size) { - TW_CAPABILITY cap; - void *pv; - TW_ENUMERATION *my_enum; - TW_ARRAY *my_array; - TW_ONEVALUE *my_one; - TW_RANGE *my_range; - TUINT32 size = 0; - - if (!data && !cont_size) return FALSE; - - if (TTWAIN_GetState() < TWAIN_SOURCE_OPEN) { - TTWAIN_ErrorBox("Attempt to get capability value below State 4."); - return FALSE; - } - /* Fill in capability structure */ - cap.Cap = cap_id; /* capability id */ - cap.ConType = - TWON_DONTCARE16; /* favorite type of container (should be ignored...) */ - cap.hContainer = NULL; - - if (TTWAIN_DS(DG_CONTROL, DAT_CAPABILITY, msgType, (TW_MEMREF)&cap) != - TWRC_SUCCESS) - return FALSE; - - if (!cap.hContainer) return FALSE; - - if (msgType == MSG_QUERYSUPPORT) { - } - - pv = GLOBAL_LOCK(cap.hContainer); - my_enum = (TW_ENUMERATION *)pv; - my_array = (TW_ARRAY *)pv; - my_one = (TW_ONEVALUE *)pv; - my_range = (TW_RANGE *)pv; - - if (cont_size) { - switch (TWON_TWON(cap.ConType, conType)) { - case TWON_TWON(TWON_ENUMERATION, TWON_ENUMERATION): - *cont_size = GetContainerSize(TWON_ENUMERATION, my_enum->ItemType, - my_enum->NumItems); - break; - case TWON_TWON(TWON_ONEVALUE, TWON_ENUMERATION): - *cont_size = GetContainerSize(TWON_ENUMERATION, my_one->ItemType, 1); - break; - case TWON_TWON(TWON_ARRAY, TWON_ARRAY): - *cont_size = - GetContainerSize(TWON_ARRAY, my_array->ItemType, my_array->NumItems); - break; - case TWON_TWON(TWON_ONEVALUE, TWON_ONEVALUE): - *cont_size = GetContainerSize(TWON_ONEVALUE, my_one->ItemType, 1); - break; - case TWON_TWON(TWON_ENUMERATION, TWON_ARRAY): - *cont_size = - GetContainerSize(TWON_ARRAY, my_enum->ItemType, my_enum->NumItems); - break; - default: - /* tmsg_error("Unable to convert type %d to %d (cap 0x%x)\n", - * cap.ConType, conType,cap_id);*/ - assert(0); - GLOBAL_UNLOCK(cap.hContainer); - GLOBAL_FREE(cap.hContainer); - return FALSE; - } - GLOBAL_UNLOCK(cap.hContainer); - GLOBAL_FREE(cap.hContainer); - return TRUE; - } - - switch (TWON_TWON(cap.ConType, conType)) { - case TWON_TWON(TWON_ENUMERATION, TWON_ENUMERATION): - size = GetContainerSize(cap.ConType, my_enum->ItemType, my_enum->NumItems); - memcpy(data, my_enum, size); - break; - case TWON_TWON(TWON_ENUMERATION, TWON_RANGE): - ConvertEnumeration2Range(*my_enum, (TW_RANGE *)data); - break; - case TWON_TWON(TWON_ENUMERATION, TWON_ONEVALUE): - ConvertEnum2OneValue(*my_enum, (TW_ONEVALUE *)data); - break; - case TWON_TWON(TWON_ARRAY, TWON_ARRAY): - size = - GetContainerSize(cap.ConType, my_array->ItemType, my_array->NumItems); - memcpy(data, my_array, size); - break; - case TWON_TWON(TWON_ONEVALUE, TWON_ONEVALUE): - memcpy(data, my_one, sizeof(TW_ONEVALUE)); - break; - case TWON_TWON(TWON_ONEVALUE, TWON_RANGE): - ConvertOneValue2Range(*my_one, (TW_RANGE *)data); - break; - case TWON_TWON(TWON_ONEVALUE, TWON_ENUMERATION): - ConvertOneValue2Enum(*my_one, (TW_ENUMERATION *)data); - break; - case TWON_TWON(TWON_RANGE, TWON_RANGE): - memcpy(data, my_range, sizeof(TW_RANGE)); - break; - case TWON_TWON(TWON_ENUMERATION, TWON_ARRAY): - ConvertEnum2Array(*my_enum, (TW_ARRAY *)data); - break; - default: - assert(0); - GLOBAL_UNLOCK(cap.hContainer); - GLOBAL_FREE(cap.hContainer); - return FALSE; - } - GLOBAL_UNLOCK(cap.hContainer); - GLOBAL_FREE(cap.hContainer); - return TRUE; -} -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ -static int ConvertOneValue2Range(TW_ONEVALUE one_value, TW_RANGE *range) { - range->ItemType = one_value.ItemType; - range->MinValue = one_value.Item; - range->MaxValue = one_value.Item; - range->StepSize = 0; - range->DefaultValue = one_value.Item; - range->CurrentValue = one_value.Item; - return TRUE; -} -/*---------------------------------------------------------------------------*/ -static int ConvertEnumeration2Range(TW_ENUMERATION enumeration, - TW_RANGE *range) { - range->ItemType = enumeration.ItemType; - range->MinValue = enumeration.ItemList[0]; - range->MaxValue = enumeration.ItemList[enumeration.NumItems - 1]; - range->StepSize = (range->MaxValue - range->MinValue) / enumeration.NumItems; - if (range->MaxValue < range->MinValue) { - range->MaxValue = range->MinValue; - range->StepSize = 0; - } - range->DefaultValue = enumeration.ItemList[enumeration.DefaultIndex]; - range->CurrentValue = enumeration.ItemList[enumeration.CurrentIndex]; - return TRUE; -} -/*---------------------------------------------------------------------------*/ -static int ConvertOneValue2Enum(TW_ONEVALUE one_value, - TW_ENUMERATION *tw_enum) { - tw_enum->ItemType = one_value.ItemType; - tw_enum->NumItems = 1; - tw_enum->CurrentIndex = 0; /* Current value is in ItemList[CurrentIndex] */ - tw_enum->DefaultIndex = 0; /* Powerup value is in ItemList[DefaultIndex] */ - tw_enum->ItemList[0] = (TW_UINT8)one_value.Item; - return TRUE; -} -/*---------------------------------------------------------------------------*/ -static int ConvertEnum2OneValue(TW_ENUMERATION tw_enum, - TW_ONEVALUE *one_value) { - unsigned char *base; - TW_UINT32 ofs; - TW_UINT32 itemSize; - - itemSize = DCItemSize[tw_enum.ItemType]; - base = tw_enum.ItemList; - ofs = tw_enum.CurrentIndex * itemSize; - - one_value->ItemType = tw_enum.ItemType; - one_value->Item = 0; - memcpy(&(one_value->Item), &(base[ofs]), itemSize); - return TRUE; -} -/*---------------------------------------------------------------------------*/ -static int ConvertEnum2Array(TW_ENUMERATION tw_enum, TW_ARRAY *array) { - TW_UINT32 itemSize; - TW_UINT32 listSize; - - itemSize = DCItemSize[tw_enum.ItemType]; - listSize = itemSize * tw_enum.NumItems; - array->ItemType = tw_enum.ItemType; - array->NumItems = tw_enum.NumItems; - memcpy(&(array->ItemList), &(tw_enum.ItemList), listSize); - return TRUE; -} -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/* SET CAP */ -/*---------------------------------------------------------------------------*/ -int TTWAIN_SetCap(TW_UINT16 cap_id, TW_UINT16 conType, TW_UINT16 itemType, - TW_UINT32 *value) { - int rc = FALSE; - TUINT32 size; - TW_CAPABILITY *capability = 0; - TW_HANDLE capabilityH = 0; - TW_ONEVALUE *container = 0; - TW_HANDLE containerH = 0; - - size = GetContainerSize(conType, itemType, 1); - containerH = GLOBAL_ALLOC(GMEM_FIXED, size); - if (!containerH) goto done; - container = (TW_ONEVALUE *)GLOBAL_LOCK(containerH); - - container->ItemType = itemType; - container->Item = *value; - capabilityH = GLOBAL_ALLOC(GMEM_FIXED, sizeof(TW_CAPABILITY)); - if (!capabilityH) { - GLOBAL_UNLOCK(containerH); - GLOBAL_FREE(containerH); - containerH = NULL; - goto done; - } - - capability = (TW_CAPABILITY *)GLOBAL_LOCK(capabilityH); - capability->ConType = conType; - capability->hContainer = containerH; - - if (TTWAIN_GetState() < TWAIN_SOURCE_OPEN) { - /*TTWAIN_ErrorBox("Setting capability in State < 4.");*/ - TTWAIN_OpenSourceManager(0); /* Bring up to state 4 */ - /*goto done;*/ - } - - capability->Cap = cap_id; /* capability id */ - - rc = (TTWAIN_DS(DG_CONTROL, DAT_CAPABILITY, MSG_SET, (TW_MEMREF)capability) == - TWRC_SUCCESS); - -done: - if (containerH) { - GLOBAL_UNLOCK(containerH); - GLOBAL_FREE(containerH); - } - - if (capabilityH) { - GLOBAL_UNLOCK(capabilityH); - GLOBAL_FREE(capabilityH); - } - return rc; -} -/*---------------------------------------------------------------------------*/ -static TUINT32 GetContainerSize(int nFormat, unsigned twty, TW_UINT32 nItems) { - TUINT32 size; - switch (nFormat) { - case TWON_ONEVALUE: - size = sizeof(TW_ONEVALUE); - if (DCItemSize[twty] > sizeof(TW_UINT32)) { - size += DCItemSize[twty] - sizeof(TW_UINT32); - } - break; - case TWON_RANGE: - size = sizeof(TW_RANGE); - break; - case TWON_ENUMERATION: - size = - sizeof(TW_ENUMERATION) + DCItemSize[twty] * nItems - sizeof(TW_UINT8); - break; - case TWON_ARRAY: - size = sizeof(TW_ARRAY) + DCItemSize[twty] * nItems - sizeof(TW_UINT8); - break; - default: - size = 0; - break; - } /* switch */ - return size; -} -/*---------------------------------------------------------------------------*/ - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_capability.h b/toonz/sources/common/twain/ttwain_capability.h deleted file mode 100644 index 13b5614b..00000000 --- a/toonz/sources/common/twain/ttwain_capability.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#ifndef __TTWAIN_CAP_H__ -#define __TTWAIN_CAP_H__ - -#include "ttwain.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/*---------------------------------------------------------------------------*/ -/* GET CAP */ -/*---------------------------------------------------------------------------*/ -int TTWAIN_GetCap(TW_UINT16 cap_id, TW_UINT16 conType, void *data, - TUINT32 *cont_size); -int TTWAIN_GetCapCurrent(TW_UINT16 cap_id, TW_UINT16 conType, void *data, - TUINT32 *cont_size); -int TTWAIN_GetCapQuery(TW_UINT16 cap_id, TW_UINT16 *pattern); -int TTWAIN_SetCap(TW_UINT16 cap_id, TW_UINT16 conType, TW_UINT16 itemType, - TW_UINT32 *value); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/toonz/sources/common/twain/ttwain_conversion.c b/toonz/sources/common/twain/ttwain_conversion.c deleted file mode 100644 index 8f6864ea..00000000 --- a/toonz/sources/common/twain/ttwain_conversion.c +++ /dev/null @@ -1,59 +0,0 @@ - - -#include -#include -#include -#include "ttwain_conversion.h" - -#ifdef __cplusplus -extern "C" { -#endif - -float TTWAIN_Fix32ToFloat(TW_FIX32 fix) { - TW_INT32 val; - val = ((TW_INT32)fix.Whole << 16) | ((TW_UINT32)fix.Frac & 0xffff); - return (float)(val / 65536.0); -} -/*---------------------------------------------------------------------------*/ -TW_FIX32 TTWAIN_FloatToFix32(float fl) { - TW_FIX32 fix; - TW_INT32 val; - assert(sizeof(TW_FIX32) == sizeof(float)); - assert(sizeof(TW_FIX32) == sizeof(long)); - - /* Note 1: This round-away-from-0 is new in TWAIN 1.7 -Note 2: ANSI C converts float to int by truncating toward 0.*/ - val = (TW_INT32)(fl * 65536.0 + (fl < 0 ? -0.5 : +0.5)); - fix.Whole = (TW_INT16)(val >> 16); /* most significant 16 bits */ - fix.Frac = (TW_UINT16)(val & 0xffff); /* least */ - - return fix; -} -/*---------------------------------------------------------------------------*/ -void TTWAIN_ConvertRevStrToRevNum(const char *rev_str, TW_UINT16 *maj_num, - TW_UINT16 *min_num) { - char *maj_str; - char *min_str; - size_t maj_size; - size_t min_size; - - *maj_num = *min_num = 0; - maj_size = strcspn(rev_str, "."); - maj_str = (char *)calloc(sizeof(char), maj_size + 1); - if (!maj_str) return; - memcpy(maj_str, rev_str, maj_size); /*already 0term*/ - *maj_num = (TW_UINT16)atoi(maj_str); - - min_size = strlen(rev_str) - maj_size + 1; - min_str = (char *)calloc(sizeof(char), min_size + 1); - if (!min_str) return; - memcpy(min_str, &(rev_str[maj_size + 1]), min_size); /*already 0term*/ - *min_num = (TW_UINT16)atoi(min_str); - if (maj_str) free(maj_str); - if (min_str) free(min_str); -} -/*---------------------------------------------------------------------------*/ - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_conversion.h b/toonz/sources/common/twain/ttwain_conversion.h deleted file mode 100644 index b58e2946..00000000 --- a/toonz/sources/common/twain/ttwain_conversion.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#ifndef __TTWAIN_CONV_H__ -#define __TTWAIN_CONV_H__ - -#include "twain.h" - -#ifdef __cplusplus -extern "C" { -#endif - -float TTWAIN_Fix32ToFloat(TW_FIX32 fix); -TW_FIX32 TTWAIN_FloatToFix32(float fl); -void TTWAIN_ConvertRevStrToRevNum(const char *rev_str, TW_UINT16 *maj_num, - TW_UINT16 *min_num); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/toonz/sources/common/twain/ttwain_error.c b/toonz/sources/common/twain/ttwain_error.c deleted file mode 100644 index e2c211f0..00000000 --- a/toonz/sources/common/twain/ttwain_error.c +++ /dev/null @@ -1,142 +0,0 @@ - - -#ifdef _MSC_VER -#pragma warning(disable : 4996) -#endif - -#include -#include -#include - -#include "ttwain_state.h" -#include "ttwain_error.h" -#include "ttwain_util.h" - -#ifdef __cplusplus -extern "C" { -#endif - -static char Msg_out[1024]; - -#define HUMAN_MESSAGES -#ifdef HUMAN_MESSAGES -const char *RC_msg[] = {"SUCCESS", - "FAILURE", - "CHECK STATUS ('tried hard')", - "CANCEL", - "DS EVENT", - "NOT DSEVENT", - "TRANSFER DONE", - "END OF LIST", - "INFO NOT SUPPORTED", - "DATA NOT AVAILABLE"}; - -const char *CC_msg[] = { - "SUCCESS", - "FAILURE DUE TO UNKNOWN CAUSES", - "LOW MEMORY", - "NO DATA SOURCE", - "DS IS CONNECTED TO MAX POSSIBLE APPS", - "OPERATION ERROR, DS/DSM REPORTED ERROR", - "UNKNOWN CAPABILITY", - "undefined", - "undefined", - "UNRECOGNIZED TRIPLET", - "DATA PARAMETER OUT OF RANGE", - "TRIPLET OUT OF SEQUENCE", - "UNKNOWN DESTINATION APP/SRC IN DSM_ESNTRY", - "CAP NOT SUPPORTED BY SOURCE", - "OPERATION NOT SUPPORTED BY CAP", - "CAP HAS DEPENDANCY ON OTHER CAP", - "FILE SYSTEM OPERATION IS DENIED (FILE IS PROTECTED)", - "OPERATION FAILED BECAUSE FILE ALREADY EXISTS", - "FILE NOT FOUND", - "OPERATION FAILED BECAUSE DIRECTORY IS NOT EMPTY", - "THE FEEDER IS JAMMED", - "THE FEEDER DETECTED MULTIPLE PAGES", - "ERROR WRITING THE FILE (MEANT FOR THINGS LIKE DISK FULL CONDITIONS)", - "THE DEVICE WENT OFFLINE PRIOR TO OR DURING THIS OPERATION"}; -#else -const char *RC_msg[] = { - "TWRC_SUCCESS", "TWRC_FAILURE", "TWRC_CHECKSTATUS ('tried hard')", - "TWRC_CANCEL", "TWRC_DSEVENT", "TWRC_NOTDSEVENT", - "TWRC_XFERDONE", "TWRC_ENDOFLIST", "TWRC_INFONOTSUPPORTED", - "TWRC_DATANOTAVAILABLE"}; - -const char *CC_msg[] = { - "TWCC_SUCCESS", "TWCC_BUMMER (Failure due to unknown causes)", - "TWCC_LOWMEMORY", "TWCC_NODS (No Data Source)", - "TWCC_MAXCONNECTIONS (DS is connected to max possible apps)", - "TWCC_OPERATIONERROR (DS/DSM reported error, app shouldn't)", - "TWCC_BADCAP (Unknown capability)", "7 (undefined)", "8 (undefined)", - "TWCC_BADPROTOCOL (Unrecognized triplet)", - "TWCC_BADVALUE (Data parameter out of range)", - "TWCC_SEQERROR (Triplet out of sequence)", - "TWCC_BADDEST (Unknown dest. App/Src in DSM_Esntry)", - "TWCC_CAPUNSUPPORTED (Cap not supported by source)", - "TWCC_CAPBADOPERATION (Operation not supported by cap)", - "TWCC_CAPSEQERROR (Cap has dependancy on other cap)", - "TWCC_DENIED (File System operation is denied (file is protected))", - "TWCC_FILEEXISTS (Operation failed because file already exists)", - "TWCC_FILENOTFOUND (File not found)", - "TWCC_NOTEMPTY (Operation failed because directory is not empty)", - "TWCC_PAPERJAM (The feeder is jammed)", - "TWCC_PAPERDOUBLEFEED (The feeder detected multiple pages)", - "TWCC_FILEWRITEERROR (Error writing the file (meant for things like disk " - "full conditions))", - "TWCC_CHECKDEVICEONLINE (The device went offline prior to or during this " - "operation)"}; - -#endif -/*---------------------------------------------------------------------------*/ -void TTWAIN_RecordError(void) { - char tmp[1024]; - TTwainData.ErrRC = TTWAIN_GetResultCode(); - if ((TTwainData.ErrRC == TWRC_FAILURE) || - (TTwainData.ErrRC == TWRC_CHECKSTATUS)) - TTwainData.ErrCC = TTWAIN_GetConditionCode(); - else - TTwainData.ErrCC = -1; - - if (TTwainData.ErrRC < (sizeof(RC_msg) / sizeof(RC_msg[0]))) { - snprintf(Msg_out, sizeof(Msg_out), "RC: %s(%d)", - RC_msg[TTwainData.ErrRC], (int)TTwainData.ErrRC); - } else { - snprintf(Msg_out, sizeof(Msg_out), "RC: %s(%d)", "unknown", - (int)TTwainData.ErrRC); - } - - if (TTwainData.ErrCC < (sizeof(CC_msg) / sizeof(CC_msg[0]))) { - snprintf(tmp, sizeof(tmp), "CC: %s(%d)", CC_msg[TTwainData.ErrCC], - (int)TTwainData.ErrCC); - strcat(Msg_out, tmp); - } else { - snprintf(tmp, sizeof(tmp), "CC: %s(%d)", "unknown", - (int)TTwainData.ErrCC); - strcat(Msg_out, tmp); - } - - if (TTwainData.ErrRC == TWRC_FAILURE && - TTwainData.ErrCC == TWCC_OPERATIONERROR) { -#ifdef _WIN32 - OutputDebugString(Msg_out); -#else -#ifdef TOONZDEBUG - printf("%s\n", Msg_out); -#endif -#endif - } - return; -} -/*---------------------------------------------------------------------------*/ -char *TTWAIN_GetLastError(TUINT32 *rc, TUINT32 *cc) { - assert(rc && cc); - *rc = TTwainData.ErrRC; - *cc = TTwainData.ErrCC; - return Msg_out; -} -/*---------------------------------------------------------------------------*/ - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_error.h b/toonz/sources/common/twain/ttwain_error.h deleted file mode 100644 index 6931695a..00000000 --- a/toonz/sources/common/twain/ttwain_error.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#ifndef __TTWAIN_ERROR_H__ -#define __TTWAIN_ERROR_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -void TTWAIN_RecordError(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/toonz/sources/common/twain/ttwain_global_def.h b/toonz/sources/common/twain/ttwain_global_def.h deleted file mode 100644 index a46c67f9..00000000 --- a/toonz/sources/common/twain/ttwain_global_def.h +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -/*max@home*/ -#ifndef __GLOBAL_DEF_H__ -#define __GLOBAL_DEF_H__ -#ifdef _WIN32 -#define GLOBAL_LOCK(P) GlobalLock(P) -#define GLOBAL_ALLOC(T, S) GlobalAlloc(T, S) -#define GLOBAL_FREE(P) GlobalFree(P) -#define GLOBAL_UNLOCK(P) GlobalUnlock(P) -#else -#ifdef __APPLE__ -/* -#define GLOBAL_LOCK(P) *(P) -//#define GLOBAL_ALLOC(T, S) NewHandle(S) -//#define GLOBAL_FREE(P) DisposeHandle( (char**)P) -#define GLOBAL_ALLOC(T, S) (TW_HANDLE)NewPtr(S) -#define GLOBAL_FREE(S) DisposePtr(S) -#define GLOBAL_UNLOCK(P) {} -*/ - -#define GLOBAL_ALLOC(T, S) NewHandle(S) -#define GLOBAL_FREE(P) DisposeHandle(P) -//#define GLOBAL_ALLOC(T, S) (TW_HANDLE)NewPtr(S) -//#define GLOBAL_FREE(S) DisposePtr((char*)S) - -#ifdef __cplusplus -extern "C" { -#endif - -TW_HANDLE GLOBAL_LOCK(TW_HANDLE S); - -#ifdef __cplusplus -} -#endif - -#define GLOBAL_UNLOCK(P) HUnlock((TW_HANDLE)P) - -#else /* UNIX */ - -#include -/* just some hack to get it built */ -typedef void *TW_HANDLE; -#define GLOBAL_LOCK(P) (P) -#define GLOBAL_ALLOC(T, S) malloc(S) -#define GLOBAL_FREE(P) free(P) -#define GLOBAL_UNLOCK(P) - -#endif -#endif -#endif /*__GLOBAL_DEF_H__*/ - -#ifdef __cplusplus -extern "C" { -#endif - -void TTWAIN_ErrorBox(const char *msg); - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_state.c b/toonz/sources/common/twain/ttwain_state.c deleted file mode 100644 index 39258669..00000000 --- a/toonz/sources/common/twain/ttwain_state.c +++ /dev/null @@ -1,1249 +0,0 @@ - - -#ifdef _MSC_VER -#pragma warning(disable : 4996) -#endif - -#define TTWAINLIB_MAIN -#include -#include -#include -#include -#include -#include "ttwain_state.h" -#include "ttwain_statePD.h" -#include "ttwain_error.h" -#include "ttwain_win.h" -#include "ttwain_winPD.h" -#include "ttwain_util.h" -#include "ttwain_utilP.h" -#include "ttwain_conversion.h" -#include "ttwainP.h" - -#include "ttwain_global_def.h" - -#ifdef __cplusplus -extern "C" { -#endif -#ifdef MACOSX -extern int exitTwainSession(void); -#endif -static void TTWAIN_FreeVar(void); - -#define RELEASE_STR "5.1" -#define TITLEBAR_STR "Toonz5.1" -#define TwProgramName "Toonz5.1" - -#define COMPANY "Digital Video" -#define PRODUCT "TOONZ" - -#ifndef min -#define min(a, b) (((a) < (b)) ? (a) : (b)) -#endif -#ifndef max -#define max(a, b) (((a) > (b)) ? (a) : (b)) -#endif - -#define CEIL(x) ((int)(x) < (x) ? (int)(x) + 1 : (int)(x)) - -#ifndef _WIN32 -#define PRINTF(args...) -#else -#define PRINTF -#endif -/*---------------------------------------------------------------------------*/ -/* LOCAL PROTOTYPES - */ -/*---------------------------------------------------------------------------*/ -static int TTWAIN_DoOneTransfer(void); -static int TTWAIN_WaitForXfer(void *hwnd); -static void *TTWAIN_WaitForNativeXfer(void *hwnd); -static int TTWAIN_WaitForMemoryXfer(void *hwnd); -static int TTWAIN_NativeXferHandler(void); -static int TTWAIN_MemoryXferHandler(void); -static int TTWAIN_AbortAllPendingXfers(void); -static void TTWAIN_ModalEventLoop(void); -static void TTWAIN_BreakModalLoop(void); -static void TTWAIN_EmptyMessageQueue(void); -/*---------------------------------------------------------------------------*/ -void TTWAIN_SetState(TWAINSTATE status); -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/* int TTWAIN_LoadSourceManager(void) <- this is in ttwain_state.h */ - -/* int TTWAIN_SelectImageSource(void* hwnd) <-\ - int TTWAIN_SelectImageSource(void* hwnd) <-|--\ - int TTWAIN_OpenDefaultSource(void) <-|-- these are in ttwain.h - int TTWAIN_CloseAll (void *hwnd) <-/ -*/ - -/* these are local */ -static int TTWAIN_EnableSource(void *hwnd); -int TTWAIN_MessageHook(void *lpmsg); -static int TTWAIN_EndXfer(void); -static int TTWAIN_DisableSource(void); -static int TTWAIN_CloseSource(void); -static int TTWAIN_CloseSourceManager(void *hwnd); - -/* int TTWAIN_UnloadSourceManager(void) <- this is in ttwain_state.h */ - -static int TTWAIN_MGR(TUINT32 dg, TUINT32 dat, TUINT32 msg, void *pd); - -#define INVERT_BYTE(START, HOWMANY) \ - { \ - UCHAR *p = (START); \ - unsigned int ijk; \ - for (ijk = 0; ijk < (HOWMANY); ijk++, p++) { \ - *p = ~*p; \ - } \ - } - -#define BB(H, L) (H << 8 | L) -/*---------------------------------------------------------------------------*/ -/* TWAIN STATE */ -/*---------------------------------------------------------------------------*/ -/*STATE 1 TO 2*/ -int TTWAIN_LoadSourceManager(void) { - TTWAIN_InitVar(); - return TTWAIN_LoadSourceManagerPD(); -} -/*---------------------------------------------------------------------------*/ -/*STATE 2 TO 3*/ -int TTWAIN_OpenSourceManager(void *hwnd) { - TTwainData.hwnd32SM = (TW_INT32)TTWAIN_GetValidHwnd(hwnd); - - if (TTWAIN_GetState() < TWAIN_SM_OPEN) { - if (TTWAIN_LoadSourceManager() && - TTWAIN_MGR(DG_CONTROL, DAT_PARENT, MSG_OPENDSM, &TTwainData.hwnd32SM)) { - assert(TTWAIN_GetState() == TWAIN_SM_OPEN); - } - } - return (TTWAIN_GetState() >= TWAIN_SM_OPEN); -} -/*---------------------------------------------------------------------------*/ -/*STATE 3*/ -static TW_IDENTITY newSourceId; -int TTWAIN_SelectImageSource(void *hwnd) { - int success = FALSE; - TWAINSTATE entryState = TTWAIN_GetState(); - - if (TTWAIN_GetState() >= TWAIN_SM_OPEN || TTWAIN_OpenSourceManager(hwnd)) { - // TW_IDENTITY newSourceId; - memset(&newSourceId, 0, sizeof newSourceId); - - TTWAIN_MGR(DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT, &newSourceId); - /* Post the Select Source dialog */ - success = - TTWAIN_MGR(DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT, &newSourceId); - } else { - char msg[2048]; - snprintf(msg, sizeof(msg), "Unable to open Source Manager (%s)", - DSM_FILENAME); - TTWAIN_ErrorBox(msg); - return FALSE; - } - - if (entryState < TWAIN_SM_OPEN) { - TTWAIN_CloseSourceManager(hwnd); - if (entryState < TWAIN_SM_LOADED) { - TTWAIN_UnloadSourceManager(); - } - } - return success; -} -/*---------------------------------------------------------------------------*/ -/*STATE 3 TO 4*/ -int TTWAIN_OpenDefaultSource(void) { - TW_IDENTITY tempId; - int rc; - static int first_time = TRUE; - - if (TTWAIN_GetState() < TWAIN_SOURCE_OPEN) { - if (TTWAIN_GetState() < TWAIN_SM_OPEN && !TTWAIN_OpenSourceManager(NULL)) - return FALSE; - - rc = TTWAIN_MGR(DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, &tempId); - while (rc && tempId.Id != 0) { - if (strcmp((char *)newSourceId.ProductName, (char *)tempId.ProductName) == - 0) { - newSourceId = tempId; - break; - } - rc = TTWAIN_MGR(DG_CONTROL, DAT_IDENTITY, MSG_GETNEXT, &tempId); - } - - if (TTWAIN_MGR(DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, &newSourceId)) { - assert(TTWAIN_GetState() == TWAIN_SOURCE_OPEN); - } - } - - if (first_time && (TTWAIN_GetState() == TWAIN_SOURCE_OPEN)) { - TTWAIN_GetSupportedCaps(); - /*first_time = FALSE;*/ - } - return (TTWAIN_GetState() == TWAIN_SOURCE_OPEN); -} -/*---------------------------------------------------------------------------*/ -/*STATE 4 TO 5*/ -static int TTWAIN_EnableSource(void *hwnd) { - if (TTWAIN_GetState() < TWAIN_SOURCE_OPEN && !TTWAIN_OpenDefaultSource()) - return FALSE; - - TTwainData.twainUI.ShowUI = TTWAIN_GetUIStatus(); - TTwainData.twainUI.ModalUI = TTWAIN_GetModalStatus(); - TTwainData.twainUI.hParent = (TW_HANDLE)TTWAIN_GetValidHwnd(hwnd); - TTWAIN_DS(DG_CONTROL, DAT_USERINTERFACE, MSG_ENABLEDS, &TTwainData.twainUI); - return (TTWAIN_GetState() == TWAIN_SOURCE_ENABLED); -} -/*---------------------------------------------------------------------------*/ -/*STATE 5 TO 6 TO 7*/ -int TTWAIN_MessageHook(void *lpmsg) -/* returns TRUE if msg processed by TWAIN (source) */ -{ - int bProcessed = FALSE; - // printf("%s\n", __PRETTY_FUNCTION__); - if (TTWAIN_GetState() >= TWAIN_SOURCE_ENABLED) { -/* source enabled */ -#ifdef _WIN32 - TW_EVENT twEvent; - twEvent.pEvent = (TW_MEMREF)lpmsg; - twEvent.TWMessage = MSG_NULL; - /* see if source wants to process (eat) the message */ - bProcessed = (TTWAIN_DS(DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT, - &twEvent) == TWRC_DSEVENT); -#else - TW_EVENT twEvent; - twEvent.pEvent = (TW_MEMREF)0; - twEvent.TWMessage = (TW_UINT32)lpmsg; -#endif - switch (twEvent.TWMessage) { - case MSG_XFERREADY: -#ifdef MACOSX - TTWAIN_SetState(TWAIN_TRANSFER_READY); -#endif - assert(TTWAIN_GetState() == TWAIN_TRANSFER_READY); - TTWAIN_DoOneTransfer(); - break; - case MSG_CLOSEDSREQ: - TTWAIN_DisableSource(); - break; - case MSG_NULL: - /* no message returned from DS */ - break; - } /* switch */ - } - return bProcessed; -} -/*---------------------------------------------------------------------------*/ -/*STATE 7 TO 6 TO 5*/ -static int TTWAIN_EndXfer(void) { - if (TTWAIN_GetState() == TWAIN_TRANSFERRING) - TTWAIN_DS(DG_CONTROL, DAT_PENDINGXFERS, MSG_ENDXFER, - &TTwainData.transferInfo.pendingXfers); - return (TTWAIN_GetState() < TWAIN_TRANSFERRING); -} -/*---------------------------------------------------------------------------*/ -/* STATE 5 TO 1 */ -/* 3 OP + 1 PD OP*/ - -/*STATE 5 TO 4*/ -static int TTWAIN_DisableSource(void) { - TTWAIN_AbortAllPendingXfers(); - - if ((TTWAIN_GetState() >= TWAIN_SOURCE_ENABLED) && - (TTWAIN_DS(DG_CONTROL, DAT_USERINTERFACE, MSG_DISABLEDS, - &TTwainData.twainUI) == TWRC_SUCCESS)) { - assert(TTWAIN_GetState() == TWAIN_SOURCE_OPEN); - return FALSE; - } - TTWAIN_EmptyMessageQueue(); - return (TTWAIN_GetState() < TWAIN_SOURCE_ENABLED); -} -/*---------------------------------------------------------------------------*/ -/*STATE 4 TO 3*/ -static int TTWAIN_CloseSource(void) { - TTwainData.resultCode = TWRC_SUCCESS; - - TTWAIN_DisableSource(); - if (TTWAIN_GetState() == TWAIN_SOURCE_OPEN && - TTWAIN_MGR(DG_CONTROL, DAT_IDENTITY, MSG_CLOSEDS, &TTwainData.sourceId)) { - assert(TTWAIN_GetState() == TWAIN_SM_OPEN); - } - return (TTWAIN_GetState() <= TWAIN_SM_OPEN); -} -/*---------------------------------------------------------------------------*/ -/*STATE 3 TO 2*/ -static int TTWAIN_CloseSourceManager(void *hwnd) { - TTWAIN_EmptyMessageQueue(); - TTwainData.hwnd32SM = (TW_INT32)TTWAIN_GetValidHwnd(hwnd); - - TTwainData.resultCode = TWRC_SUCCESS; - - if (TTWAIN_CloseSource() && - TTWAIN_MGR(DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM, &TTwainData.hwnd32SM)) { - assert(TTWAIN_GetState() == TWAIN_SM_LOADED); - } - return (TTWAIN_GetState() <= TWAIN_SM_LOADED); -} -/*---------------------------------------------------------------------------*/ -/*STATE 2 TO 1*/ -int TTWAIN_UnloadSourceManager(void) { - TTWAIN_CloseSourceManager(NULL); - return TTWAIN_UnloadSourceManagerPD(); -} -/*---------------------------------------------------------------------------*/ -int TTWAIN_CloseAll(void *hwnd) { - TTWAIN_EndXfer(); - TTWAIN_DisableSource(); - TTWAIN_CloseSource(); - TTWAIN_CloseSourceManager(hwnd); - TTWAIN_UnloadSourceManager(); - TTWAIN_FreeVar(); - return 1; -} -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/* MISC. AUX FUNCTIONS */ -/*---------------------------------------------------------------------------*/ -TWAINSTATE TTWAIN_GetState(void) { return TTwainData.twainState; } -/*---------------------------------------------------------------------------*/ -void TTWAIN_SetState(TWAINSTATE status) { TTwainData.twainState = status; } -/*---------------------------------------------------------------------------*/ -static int TTWAIN_AbortAllPendingXfers(void) { - TTWAIN_EndXfer(); - if (TTWAIN_GetState() == TWAIN_TRANSFER_READY) { - TTWAIN_DS(DG_CONTROL, DAT_PENDINGXFERS, MSG_RESET, - &TTwainData.transferInfo.pendingXfers); - } - TTWAIN_EmptyMessageQueue(); - return (TTWAIN_GetState() < TWAIN_TRANSFER_READY); -} -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/* DATA SOURCE */ -/*---------------------------------------------------------------------------*/ -TW_INT16 TTWAIN_DS(TUINT32 dg, TUINT32 dat, TUINT32 msg, - void *pd) { /* Call the current source with a triplet */ - int bOk = FALSE; - static TUINT32 nMemBuffer = 0; - - PRINTF("%s dg=0x%x dat=0x%x msg=0x%x pd=0x%x\n", __FUNCTION__, dg, dat, msg, - pd); - - assert(TTWAIN_GetState() >= TWAIN_SOURCE_OPEN); - TTwainData.resultCode = TWRC_FAILURE; - if (dg == DG_IMAGE) { - if (dat == DAT_IMAGEMEMXFER) { - if (msg == MSG_GET && pd != NULL) { - pTW_IMAGEMEMXFER pmxb = (pTW_IMAGEMEMXFER)pd; - pmxb->Compression = TWON_DONTCARE16; - pmxb->BytesPerRow = TWON_DONTCARE32; - pmxb->Columns = TWON_DONTCARE32; - pmxb->Rows = TWON_DONTCARE32; - pmxb->XOffset = TWON_DONTCARE32; - pmxb->YOffset = TWON_DONTCARE32; - pmxb->BytesWritten = TWON_DONTCARE32; - } - } - } - if (TTwainData.DSM_Entry) { - TTwainData.resultCode = (*TTwainData.DSM_Entry)( - &TTwainData.appId, &TTwainData.sourceId, (TW_UINT32)dg, (TW_UINT16)dat, - (TW_UINT16)msg, (TW_MEMREF)pd); - bOk = (TTwainData.resultCode == TWRC_SUCCESS); - - if (dg == DG_CONTROL) { - switch (dat) { - case DAT_EVENT: - if (msg == MSG_PROCESSEVENT) { - if (((pTW_EVENT)pd)->TWMessage == MSG_XFERREADY) { - TTWAIN_SetState(TWAIN_TRANSFER_READY); - } - bOk = (TTwainData.resultCode == TWRC_DSEVENT); - } - break; - - case DAT_CAPABILITY: - break; - - case DAT_PENDINGXFERS: - if (msg == MSG_ENDXFER && bOk) { - TTWAIN_SetState(((pTW_PENDINGXFERS)pd)->Count ? TWAIN_TRANSFER_READY - : TWAIN_SOURCE_ENABLED); - } - if (msg == MSG_RESET && bOk) { - TTWAIN_SetState(TWAIN_SOURCE_ENABLED); - } - break; - - case DAT_USERINTERFACE: - if (msg == MSG_ENABLEDS) { - if (TTwainData.resultCode == TWRC_FAILURE || - TTwainData.resultCode == TWRC_CANCEL) { - TTWAIN_RecordError(); - } else { - /* TTwainData.resultCode could be either SUCCESS or CHECKSTATUS */ - TTWAIN_SetState(TWAIN_SOURCE_ENABLED); - bOk = TRUE; - } - } - if (msg == MSG_DISABLEDS && bOk) { - TTWAIN_SetState(TWAIN_SOURCE_OPEN); -#ifdef MACOSX - exitTwainSession(); // exited from TwainUI using close button -#endif - } - break; - - case DAT_SETUPMEMXFER: - if (msg == MSG_GET && bOk) { - nMemBuffer = 0; - } - break; - } /* switch */ - } else if (dg == DG_IMAGE) { - if (dat == DAT_IMAGENATIVEXFER || dat == DAT_IMAGEFILEXFER) { - /* Native and File transfers work much the same way. */ - if (msg == MSG_GET) { - bOk = (TTwainData.resultCode == TWRC_XFERDONE); - switch (TTwainData.resultCode) { - case TWRC_XFERDONE: - case TWRC_CANCEL: - TTWAIN_SetState(TWAIN_TRANSFERRING); - /* Need to acknowledge end of transfer with */ - /* DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER */ - break; - - case TWRC_FAILURE: - default: - /* Transfer failed (e.g. insufficient memory, write-locked file) */ - /* check condition code for more info */ - TTWAIN_SetState(TWAIN_TRANSFER_READY); - /* The image is still pending */ - break; - } /* switch */ - } - } else if (dat == DAT_IMAGEMEMXFER) { - if (msg == MSG_GET) { - bOk = FALSE; - switch (TTwainData.resultCode) { - case TWRC_SUCCESS: - case TWRC_XFERDONE: - bOk = TRUE; - nMemBuffer++; - TTWAIN_SetState(TWAIN_TRANSFERRING); - break; - - case TWRC_FAILURE: - /* "If the failure occurred during the transfer of the first -buffer, the session is in State 6. If the failure occurred -on a subsequent buffer, the session is in State 7." -*/ - TTWAIN_SetState(nMemBuffer == 0 ? TWAIN_TRANSFER_READY - : TWAIN_TRANSFERRING); - break; - - case TWRC_CANCEL: - /* Transfer cancelled, no state change. */ - TTWAIN_BreakModalLoop(); - break; - } /* switch */ - } - } - } - } - - /* -if (!bOk) -TTWAIN_RecordError(); -*/ - return TTwainData.resultCode; -} -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/* DATA SOURCE MANAGER */ -/*---------------------------------------------------------------------------*/ -static int TTWAIN_MGR(TUINT32 dg, TUINT32 dat, TUINT32 msg, void *pd) -/* Call the Source Manager with a triplet */ -{ - int bOk = FALSE; - TTwainData.resultCode = TWRC_FAILURE; - - if (TTwainData.DSM_Entry) { - TTwainData.resultCode = - (*TTwainData.DSM_Entry)(&TTwainData.appId, NULL, (TW_UINT32)dg, - (TW_UINT16)dat, (TW_UINT16)msg, (TW_MEMREF)pd); - bOk = (TTwainData.resultCode == TWRC_SUCCESS); - if (dg == DG_CONTROL) { - if (dat == DAT_IDENTITY) { - if (msg == MSG_OPENDS) { - if (bOk) { - /* Source opened - record identity for future triplets */ - memcpy(&TTwainData.sourceId, pd, sizeof(TW_IDENTITY)); - TTWAIN_SetState(TWAIN_SOURCE_OPEN); - } else { /*RecordError(ED_DSM_FAILURE);*/ - TTWAIN_RecordError(); - } - } - if (msg == MSG_CLOSEDS && bOk) { - TTWAIN_SetState(TWAIN_SM_OPEN); - } - } - if (dat == DAT_PARENT) { - if (msg == MSG_OPENDSM && bOk) { - TTWAIN_SetState(TWAIN_SM_OPEN); - } - if (msg == MSG_CLOSEDSM && bOk) { - TTWAIN_SetState(TWAIN_SM_LOADED); - } - } - } - } - return bOk; -} -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/* ERRORS */ -/*---------------------------------------------------------------------------*/ -TUINT32 TTWAIN_GetConditionCode(void) { - TW_STATUS twStatus; - TW_INT16 rcLast = TTwainData.resultCode; - TW_INT16 rc = TWRC_FAILURE; - twStatus.ConditionCode = TWCC_BUMMER; - - if (TTWAIN_GetState() >= 4) { - /* get source status if open */ - rc = TTWAIN_DS(DG_CONTROL, DAT_STATUS, MSG_GET, (TW_MEMREF)&twStatus); - } else if (TTWAIN_GetState() == 3) { - /* otherwise get source manager status */ - rc = TTWAIN_MGR(DG_CONTROL, DAT_STATUS, MSG_GET, (TW_MEMREF)&twStatus); - } - TTwainData.resultCode = rcLast; - - if (rc != TWRC_SUCCESS) return -1; - return twStatus.ConditionCode; -} -/*---------------------------------------------------------------------------*/ -TUINT32 TTWAIN_GetResultCode(void) { return TTwainData.resultCode; } -/*---------------------------------------------------------------------------*/ -int TTWAIN_DSM_HasEntryPoint(void) { return !!(TTwainData.DSM_Entry); } -/*---------------------------------------------------------------------------*/ -static int TTWAIN_DoOneTransfer(void) { - int rc = FALSE; - switch (TTwainData.transferInfo.transferMech) { - case TTWAIN_TRANSFERMODE_NATIVE: - rc = TTWAIN_NativeXferHandler(); - break; - case TTWAIN_TRANSFERMODE_FILE: - assert(!"NOT IMPL!"); - /*TTWAIN_FileXferHandler(); */ - break; - case TTWAIN_TRANSFERMODE_MEMORY: - rc = TTWAIN_MemoryXferHandler(); - break; - } /* switch */ - - TTwainData.transferInfo.lastTransferWasOk = rc; - /* If inside ModalEventLoop, break out */ - TTWAIN_BreakModalLoop(); - - /* Acknowledge transfer */ - TTWAIN_EndXfer(); - assert(TTWAIN_GetState() == TWAIN_TRANSFER_READY || - TTWAIN_GetState() == TWAIN_SOURCE_ENABLED); - return rc; -} -/*---------------------------------------------------------------------------*/ -void TTWAIN_RegisterApp( - int majorNum, int minorNum, /* app. revision*/ - int nLanguage, /* (human) language (use TWLG_xxx from TWAIN.H) */ - int nCountry, /* country (use TWCY_xxx from TWAIN.H) */ - char *version, /* version info string */ - char *manufacter, /* name of manufacter */ - char *family, /* product family */ - char *product) /* specific product */ -{ - memset(&TTwainData.appId, 0, sizeof(TTwainData.appId)); - TTwainData.appId.Id = - 0; /* init to 0, but Source Manager will assign THE real value*/ - TTwainData.appId.Version.MajorNum = majorNum; - TTwainData.appId.Version.MinorNum = minorNum; - TTwainData.appId.Version.Language = nLanguage; - TTwainData.appId.Version.Country = nCountry; - TTwainData.appId.ProtocolMajor = TWON_PROTOCOLMAJOR; - TTwainData.appId.ProtocolMinor = TWON_PROTOCOLMINOR; - TTwainData.appId.SupportedGroups = DG_IMAGE | DG_CONTROL; - strcpy((char *)TTwainData.appId.Version.Info, version); - strcpy((char *)TTwainData.appId.Manufacturer, manufacter); - strcpy((char *)TTwainData.appId.ProductFamily, family); - strcpy((char *)TTwainData.appId.ProductName, product); -} -/*---------------------------------------------------------------------------*/ -void *TTWAIN_AcquireNative(void *hwnd) { - void *hnative = NULL; - - TTwainData.transferInfo.lastTransferWasOk = FALSE; - - if (TTwainData.transferInfo.transferMech != TTWAIN_TRANSFERMODE_NATIVE) - return 0; - - hwnd = TTWAIN_GetValidHwnd(hwnd); - if (TTWAIN_GetState() < TWAIN_SOURCE_OPEN) { - if (!TTWAIN_OpenSourceManager(hwnd)) /* Bring up to state 4 */ - { - char msg[2048]; - snprintf(msg, sizeof(msg), "Unable to open Source Manager (%s)", - DSM_FILENAME); - TTWAIN_ErrorBox(msg); - return 0; - } - if (!TTWAIN_OpenDefaultSource()) - /*TTWAIN_ReportLastError("Unable to open default Data Source.");*/ - TTWAIN_RecordError(); - else - assert(TTWAIN_GetState() == TWAIN_SOURCE_OPEN); - } - - if (TTWAIN_GetState() >= TWAIN_SOURCE_OPEN) - hnative = TTWAIN_WaitForNativeXfer(hwnd); - - if (!TTwainData.transferInfo.multiTransfer) { - /* shut everything down in the right sequence */ - TTWAIN_AbortAllPendingXfers(); /* TRANSFER_READY or TRANSFERRING -> - SOURCE_ENABLED */ - TTWAIN_UnloadSourceManager(); - } - - TTwainData.transferInfo.lastTransferWasOk = !!(hnative); - return hnative; -} -/*---------------------------------------------------------------------------*/ -#ifdef _WIN32 - -typedef void(MyFun)(HWND); - -/*it's an hack function to force bring to top the twain UI module window */ -static BOOL CALLBACK myHackEnumFunction(HWND hwnd, LPARAM lParam) { - MyFun *f = 0; - -#define TITLESIZE (1024) - char title[TITLESIZE + 1]; - int len; - - GetWindowText(hwnd, (char *)&title, TITLESIZE); - if (title[0] == 0x00) return 1; /*continue the search....*/ - - len = strlen(TTwainData.sourceId.ProductName); - if (!len) return 0; - - len--; - - while ( - len && - (isdigit(TTwainData.sourceId.ProductName[len]) /*skip digit at the end*/ - || TTwainData.sourceId.ProductName[len] == '.')) /*skip . */ - len--; - - if (len && !strncmp(title, TTwainData.sourceId.ProductName, len)) { - /* -char dbg_str[1024]; -snprintf(dbg_str, sizeof(dbg_str), "set focus on 0x%8x %s\n",hwnd, title); -OutputDebugString(dbg_str); -*/ - f = (MyFun *)lParam; - f(hwnd); - - return FALSE; /*it means stop the search...*/ - } - return 1; /*continue the search....*/ -} - -/*---------------------------------------------------------------------------*/ - -static BOOL CALLBACK myHackEnumFunction2(HWND hwnd, LPARAM lParam) { - MyFun *f = 0; - char *ptr; - -#define TITLESIZE (1024) - char title[TITLESIZE + 1]; - - GetWindowText(hwnd, (char *)&title, TITLESIZE); - if (title[0] == 0x00) return 1; /*continue the search....*/ - - ptr = strstr(title, TTwainData.sourceId.Manufacturer); - if (!ptr) return 1; /*continue the search....*/ - - f = (MyFun *)lParam; - f(hwnd); - - return FALSE; /*it means stop the search...*/ -} - -/*---------------------------------------------------------------------------*/ - -static void bringToTop(HWND hwnd) { BringWindowToTop(hwnd); } - -static void putToBottom(HWND hwnd) { - const int unused = 0; - - BOOL rc = SetWindowPos(hwnd, // handle to window - HWND_BOTTOM, // placement-order handle - unused, // horizontal position - unused, // vertical position - unused, // width - unused, // height - SWP_ASYNCWINDOWPOS | SWP_NOMOVE | - SWP_NOSIZE // window-positioning options - ); -} - -static void myHackFunction(int v) { - BOOL rc; - if (v == 1) - rc = EnumWindows((WNDENUMPROC)myHackEnumFunction, (LPARAM)&bringToTop); - else - rc = EnumWindows((WNDENUMPROC)myHackEnumFunction, (LPARAM)&putToBottom); - - if (rc) /* it means that myHackEnumFunction fails to find the proper window to - bring up or put down*/ - { - if (v == 1) - rc = EnumWindows((WNDENUMPROC)myHackEnumFunction2, (LPARAM)&bringToTop); - else - rc = EnumWindows((WNDENUMPROC)myHackEnumFunction2, (LPARAM)&putToBottom); - } -} -#else -static void myHackFunction(int v) { /*it's empty...*/ -} -#endif -/*---------------------------------------------------------------------------*/ -int TTWAIN_AcquireMemory(void *hwnd) { - int rc = FALSE; - TTwainData.transferInfo.lastTransferWasOk = FALSE; - - if (TTwainData.transferInfo.transferMech != TTWAIN_TRANSFERMODE_MEMORY) - return FALSE; - - myHackFunction(1); - - hwnd = TTWAIN_GetValidHwnd(hwnd); - if (TTWAIN_GetState() < TWAIN_SOURCE_OPEN) { - if (!TTWAIN_OpenSourceManager(hwnd)) /* Bring up to state 4 */ - { - TTWAIN_ErrorBox("Unable to open Source Manager (" DSM_FILENAME ")"); - return FALSE; - } - if (!TTWAIN_OpenDefaultSource()) - /*TTWAIN_ReportLastError("Unable to open default Data Source.");*/ - TTWAIN_RecordError(); - else - assert(TTWAIN_GetState() == TWAIN_SOURCE_OPEN); - } - - if (TTWAIN_GetState() >= TWAIN_SOURCE_OPEN) - rc = TTWAIN_WaitForMemoryXfer(hwnd); - - if (!TTwainData.transferInfo.multiTransfer) { - /* shut everything down in the right sequence */ - TTWAIN_AbortAllPendingXfers(); /* TRANSFER_READY or TRANSFERRING -> - SOURCE_ENABLED */ - TTWAIN_UnloadSourceManager(); - } - - myHackFunction(0); - - return TTwainData.transferInfo.lastTransferWasOk; -} -/*---------------------------------------------------------------------------*/ -void TTWAIN_StopAcquire(void) { TTwainData.transferInfo.oneAtLeast = FALSE; } -/*---------------------------------------------------------------------------*/ -static void *TTWAIN_WaitForNativeXfer(void *hwnd) { - TTwainData.transferInfo.hDib = NULL; - if (TTWAIN_GetState() >= TWAIN_SOURCE_OPEN) - TTWAIN_WaitForXfer(hwnd); - else - TTWAIN_ErrorBox("TWAIN_WaitForNativeXfer called in state < 4."); - return TTwainData.transferInfo.hDib; -} -/*---------------------------------------------------------------------------*/ -static int TTWAIN_WaitForMemoryXfer(void *hwnd) { - int rc = FALSE; - if (TTWAIN_GetState() >= TWAIN_SOURCE_OPEN) - rc = TTWAIN_WaitForXfer(hwnd); - else - TTWAIN_ErrorBox("TWAIN_WaitForNativeXfer called in state < 4."); - return rc; -} -/*---------------------------------------------------------------------------*/ -static int TTWAIN_WaitForXfer(void *hwnd) { - int bWasEnabled; - int rc = FALSE; - /* Make up a valid window if we weren't given one */ - hwnd = TTWAIN_GetValidHwnd(hwnd); - /* Disable the parent window during the modal acquire */ - bWasEnabled = (TTWAIN_EnableWindow(hwnd, FALSE) == 0); - - TTwainData.transferInfo.oneAtLeast = TRUE; - /* -TTWAIN_DS( DG_CONTROL,DAT_PENDINGXFERS, MSG_ENDXFER, - (TW_MEMREF)&TTwainData.transferInfo.pendingXfers); -*/ - do { - if (TTWAIN_GetState() == TWAIN_TRANSFER_READY) - rc = TTWAIN_DoOneTransfer(); - else if (TTWAIN_GetState() >= TWAIN_SOURCE_ENABLED || - TTWAIN_EnableSource(hwnd)) { - /* source is enabled, wait for transfer or source closed */ - if (TTwainData.resultCode != TWRC_CANCEL) - TTWAIN_ModalEventLoop(); - else { - TTWAIN_BreakModalLoop(); - break; - } - } else - /*TTWAIN_ReportLastError("Failed to enable Data Source.");*/ - TTWAIN_RecordError(); - } while (TTwainData.transferInfo.pendingXfers.Count && - TTwainData.transferInfo.oneAtLeast /*&& rc*/); - - /* Re-enable the parent window if it was enabled */ - TTWAIN_EnableWindow(hwnd, bWasEnabled); - return rc; -} -/*---------------------------------------------------------------------------*/ -void TTWAIN_FreeMemory(void *hMem) { - free(hMem); - /* -if (hMem) -GLOBAL_FREE(hMem); -*/ -} -/*---------------------------------------------------------------------------*/ -static void TTWAIN_ModalEventLoop(void) { TTWAIN_ModalEventLoopPD(); } -/*---------------------------------------------------------------------------*/ -static void TTWAIN_BreakModalLoop(void) { TTwainData.breakModalLoop = TRUE; } -/*---------------------------------------------------------------------------*/ -static void TTWAIN_EmptyMessageQueue(void) { TTWAIN_EmptyMessageQueuePD(); } -/*---------------------------------------------------------------------------*/ -static int TTWAIN_NativeXferHandler(void) { - TW_UINT32 hNative; - - assert(TTWAIN_GetState() == TWAIN_TRANSFER_READY); - if (TTWAIN_DS(DG_IMAGE, DAT_IMAGENATIVEXFER, MSG_GET, &hNative) == - TWRC_XFERDONE) - TTwainData.transferInfo.hDib = (void *)hNative; - else - TTwainData.transferInfo.hDib = NULL; - return (!!TTwainData.transferInfo.hDib); -} -/*---------------------------------------------------------------------------*/ -static int TTWAIN_MemoryXferHandler(void) { - TW_IMAGEMEMXFER *imageMemXfer = 0; - TW_HANDLE imageMemXferH = 0; - TW_HANDLE transferBufferH = 0; - TW_SETUPMEMXFER setup; - TW_IMAGEINFO info; - TW_IMAGELAYOUT imageLayout; - TUINT32 nTransferDone; - TW_INT16 rc1, rc2, rc3, rc4, twRC2; - int ret = FALSE; - int stopScanning = 0; - UCHAR *transferBuffer = 0; - UCHAR *sourceBuffer = 0; - UCHAR *targetBuffer = 0; - unsigned int rows; - double pixSize; - int extraX = 0; - int extraY = 0; - TW_UINT32 rowsToCopy = 0; - TW_UINT32 rowsRemaining = 0; - TW_UINT32 bytesToCopy = 0; - TW_UINT32 bytesToWrap = 0; - TW_UINT32 memorySize = 0; - int imgInfoOk; /* on Mac often (always) is impossible to get the imageinfo - about - the transfer... so no I can't prealloc memory - and - do other checks about size etc... - */ - - /*printf("%s\n", __PRETTY_FUNCTION__);*/ - - memset(&info, 0, sizeof(TW_IMAGEINFO)); - rc1 = TTWAIN_DS(DG_IMAGE, DAT_IMAGEINFO, MSG_GET, (TW_MEMREF)&info); - imgInfoOk = (rc1 == TWRC_SUCCESS); - - /*printf("get image info returns %d\n", imgInfoOk);*/ - - rc4 = TTWAIN_DS(DG_IMAGE, DAT_IMAGELAYOUT, MSG_GET, &imageLayout); - - /* determine the transfer buffer size */ - rc2 = TTWAIN_DS(DG_CONTROL, DAT_SETUPMEMXFER, MSG_GET, (TW_MEMREF)&setup); - transferBufferH = GLOBAL_ALLOC(GMEM_FIXED, setup.Preferred); - if (!transferBufferH) return FALSE; - transferBuffer = (UCHAR *)GLOBAL_LOCK(transferBufferH); - - if (imgInfoOk) { - pixSize = info.BitsPerPixel / 8.0; - memorySize = info.ImageLength * CEIL(info.ImageWidth * pixSize); - } else { - /* we need to allocate incrementally the memory needs to store the image*/ - memorySize = - setup.Preferred; /* start using the setupmemxfer.preferred size*/ - pixSize = 3; - } - - if (TTwainData.transferInfo.usageMode == TTWAIN_MODE_UNLEASHED) { - /* -TTwainData.transferInfo = GLOBAL_ALLOC(GMEM_FIXED, memorySize); -*/ - TTwainData.transferInfo.memoryBuffer = (UCHAR *)malloc(memorySize); - - if (!TTwainData.transferInfo.memoryBuffer) { - /*tmsg_error("unable to allocate memory!");*/ - return FALSE; - } - if (imgInfoOk) { - TTwainData.transferInfo.memorySize = memorySize; - TTwainData.transferInfo.preferredLx = info.ImageWidth; - TTwainData.transferInfo.preferredLy = info.ImageLength; - } else { - TTwainData.transferInfo.memorySize = setup.Preferred; - TTwainData.transferInfo.preferredLx = 0; - TTwainData.transferInfo.preferredLy = 0; - } - } - - extraX = info.ImageWidth - TTwainData.transferInfo.preferredLx; - extraY = info.ImageLength - TTwainData.transferInfo.preferredLy; - - rowsRemaining = min(TTwainData.transferInfo.preferredLy, info.ImageLength); - - targetBuffer = TTwainData.transferInfo.memoryBuffer; - - /*clean-up the buffer -memset(targetBuffer, 0xff, TTwainData.transferInfo.memorySize); -*/ - - imageMemXferH = GLOBAL_ALLOC(GMEM_FIXED, sizeof(TW_IMAGEMEMXFER)); - if (!imageMemXferH) return FALSE; - - imageMemXfer = (TW_IMAGEMEMXFER *)GLOBAL_LOCK(imageMemXferH); - - imageMemXfer->Memory.TheMem = (char *)transferBuffer; - imageMemXfer->Memory.Length = setup.Preferred; - imageMemXfer->Memory.Flags = TWMF_APPOWNS | TWMF_POINTER; - TTwainData.transferInfo.pendingXfers.Count = 0; - /* transfer the data -- loop until done or canceled */ - nTransferDone = 0; - do { - rc3 = - TTWAIN_DS(DG_IMAGE, DAT_IMAGEMEMXFER, MSG_GET, (TW_MEMREF)imageMemXfer); - nTransferDone++; - switch (rc3) { - case TWRC_SUCCESS: - PRINTF("IMAGEMEMXFER, GET, returns SUCCESS\n"); - if (imgInfoOk) { - TW_UINT32 colsToCopy; - rowsToCopy = min(imageMemXfer->Rows, rowsRemaining); - colsToCopy = min(imageMemXfer->Columns, - (unsigned long)TTwainData.transferInfo.preferredLx); - bytesToCopy = CEIL(colsToCopy * pixSize); - bytesToWrap = CEIL(TTwainData.transferInfo.preferredLx * pixSize); - } else { - TW_UINT32 newMemorySize; - rowsToCopy = imageMemXfer->Rows; - bytesToCopy = imageMemXfer->BytesPerRow; - bytesToWrap = bytesToCopy; - newMemorySize = - (TTwainData.transferInfo.preferredLy + imageMemXfer->Rows) * - imageMemXfer->BytesPerRow; - if (TTwainData.transferInfo.memorySize < newMemorySize) { - TTwainData.transferInfo.memoryBuffer = (UCHAR *)realloc( - TTwainData.transferInfo.memoryBuffer, newMemorySize); - TTwainData.transferInfo.memorySize = newMemorySize; - targetBuffer = - TTwainData.transferInfo.memoryBuffer + - (TTwainData.transferInfo.preferredLy * imageMemXfer->BytesPerRow); - } - TTwainData.transferInfo.preferredLy += rowsToCopy; - if ((int)imageMemXfer->Columns > TTwainData.transferInfo.preferredLx) - TTwainData.transferInfo.preferredLx = imageMemXfer->Columns; - } - - sourceBuffer = (UCHAR *)imageMemXfer->Memory.TheMem; - if (TTwainData.transferInfo.nextImageNeedsToBeInverted) - INVERT_BYTE(sourceBuffer, bytesToCopy) - - for (rows = 0; rows < rowsToCopy; rows++) { - memcpy(targetBuffer, sourceBuffer, bytesToCopy); - targetBuffer += bytesToWrap; - sourceBuffer += imageMemXfer->BytesPerRow; - } - rowsRemaining -= rowsToCopy; - break; - - case TWRC_XFERDONE: - PRINTF("IMAGEMEMXFER, GET, returns XFERDONE\n"); - /*copy the last transfer data*/ - if (imgInfoOk) { - TW_UINT32 colsToCopy; - rowsToCopy = min(imageMemXfer->Rows, rowsRemaining); - colsToCopy = min(imageMemXfer->Columns, - (unsigned long)TTwainData.transferInfo.preferredLx); - bytesToCopy = CEIL(colsToCopy * pixSize); - bytesToWrap = CEIL(TTwainData.transferInfo.preferredLx * pixSize); - } else { - TW_UINT32 newMemorySize; - rowsToCopy = imageMemXfer->Rows; - bytesToCopy = imageMemXfer->BytesPerRow; - bytesToWrap = bytesToCopy; - newMemorySize = - (TTwainData.transferInfo.preferredLy + imageMemXfer->Rows) * - imageMemXfer->BytesPerRow; - if (TTwainData.transferInfo.memorySize < newMemorySize) { - TTwainData.transferInfo.memoryBuffer = (UCHAR *)realloc( - TTwainData.transferInfo.memoryBuffer, newMemorySize); - TTwainData.transferInfo.memorySize = newMemorySize; - targetBuffer = - TTwainData.transferInfo.memoryBuffer + - (TTwainData.transferInfo.preferredLy * imageMemXfer->BytesPerRow); - } - TTwainData.transferInfo.preferredLy += rowsToCopy; - if ((int)imageMemXfer->Columns > TTwainData.transferInfo.preferredLx) - TTwainData.transferInfo.preferredLx = imageMemXfer->Columns; - } - sourceBuffer = (UCHAR *)imageMemXfer->Memory.TheMem; - if (TTwainData.transferInfo.nextImageNeedsToBeInverted) - INVERT_BYTE(sourceBuffer, bytesToCopy) - - for (rows = 0; rows < rowsToCopy; rows++) { - memcpy(targetBuffer, sourceBuffer, bytesToCopy); - targetBuffer += bytesToWrap; - sourceBuffer += imageMemXfer->BytesPerRow; - } - rowsRemaining -= rowsToCopy; - PRINTF("get pending xfers\n"); - twRC2 = TTWAIN_DS(DG_CONTROL, DAT_PENDINGXFERS, MSG_ENDXFER, - (TW_MEMREF)&TTwainData.transferInfo.pendingXfers); - if (twRC2 != TWRC_SUCCESS) { - printf("pending xfers != success"); - ret = FALSE; - goto done; - } - PRINTF(" pending count = %d\n", - TTwainData.transferInfo.pendingXfers.Count); - if (TTwainData.transferInfo.pendingXfers.Count == 0) { - ret = TRUE; - goto done; - } - if (TTwainData.transferInfo.pendingXfers.Count == 0xffff) { - ret = TRUE; - goto done; - } - if (TTwainData.transferInfo.pendingXfers.Count == 0xfffe) { - ret = TRUE; - goto done; - } - ret = TRUE; - goto done; - - case TWRC_CANCEL: - TTWAIN_RecordError(); - twRC2 = TTWAIN_DS(DG_CONTROL, DAT_PENDINGXFERS, MSG_ENDXFER, - (TW_MEMREF)&TTwainData.transferInfo.pendingXfers); - if (twRC2 != TWRC_SUCCESS) { - ret = FALSE; - goto done; - } - if (TTwainData.transferInfo.pendingXfers.Count == 0) { - ret = FALSE; - goto done; - } - break; - - case TWRC_FAILURE: - PRINTF("IMAGEMEMXFER, GET, returns FAILURE\n"); - TTWAIN_RecordError(); - twRC2 = TTWAIN_DS(DG_CONTROL, DAT_PENDINGXFERS, MSG_ENDXFER, - (TW_MEMREF)&TTwainData.transferInfo.pendingXfers); - if (twRC2 != TWRC_SUCCESS) { - ret = FALSE; - goto done; - } - if (TTwainData.transferInfo.pendingXfers.Count == 0) { - ret = FALSE; - goto done; - } - break; - - default: - PRINTF("IMAGEMEMXFER, GET, returns ?!? Default handler called\n"); - /* Abort the image */ - TTWAIN_RecordError(); - twRC2 = TTWAIN_DS(DG_CONTROL, DAT_PENDINGXFERS, MSG_ENDXFER, - (TW_MEMREF)&TTwainData.transferInfo.pendingXfers); - if (twRC2 != TWRC_SUCCESS) { - ret = FALSE; - goto done; - } - if (TTwainData.transferInfo.pendingXfers.Count == 0) { - ret = FALSE; - goto done; - } - } - } while (rc3 == TWRC_SUCCESS); - -done: - if (ret == TRUE) { - if (TTwainData.callback.onDoneCb) { - float xdpi, ydpi; - TTWAIN_PIXTYPE pixType; - xdpi = TTWAIN_Fix32ToFloat(info.XResolution); - ydpi = TTWAIN_Fix32ToFloat(info.YResolution); - - if (imgInfoOk) { - xdpi = TTWAIN_Fix32ToFloat(info.XResolution); - ydpi = TTWAIN_Fix32ToFloat(info.YResolution); - switch (BB(info.PixelType, info.BitsPerPixel)) { - case BB(TWPT_BW, 1): - pixType = TTWAIN_BW; - break; - case BB(TWPT_GRAY, 8): - pixType = TTWAIN_GRAY8; - break; - case BB(TWPT_RGB, 24): - pixType = TTWAIN_RGB24; - break; - default: - pixType = TTWAIN_RGB24; - break; - } - } else { - float lx = TTWAIN_Fix32ToFloat(imageLayout.Frame.Right) - - TTWAIN_Fix32ToFloat(imageLayout.Frame.Left); - float ly = TTWAIN_Fix32ToFloat(imageLayout.Frame.Bottom) - - TTWAIN_Fix32ToFloat(imageLayout.Frame.Top); - - xdpi = (float)TTwainData.transferInfo.preferredLx / lx; - ydpi = (float)TTwainData.transferInfo.preferredLy / ly; - - switch (imageMemXfer->BytesPerRow / - TTwainData.transferInfo.preferredLx) { - case 1: - pixType = TTWAIN_GRAY8; - break; - case 3: - pixType = TTWAIN_RGB24; - break; - default: { - double b = (imageMemXfer->BytesPerRow / - (double)TTwainData.transferInfo.preferredLx); - if ((b >= 0.125) && (b < 8)) - pixType = TTWAIN_BW; - else { - printf("unable to det pix type assume RGB24\n"); - pixType = TTWAIN_RGB24; - } - break; - } - } - } - stopScanning = !TTwainData.callback.onDoneCb( - TTwainData.transferInfo.memoryBuffer, pixType, - TTwainData.transferInfo.preferredLx, - TTwainData.transferInfo.preferredLy, - TTwainData.transferInfo.preferredLx, xdpi, ydpi, - TTwainData.callback.onDoneArg); -#ifdef MACOSX - PRINTF("stopScanning = %d\n", stopScanning); - exitTwainSession(); -#endif - } - } else /*ret == FALSE*/ - { - if (TTwainData.callback.onErrorCb) { - TTwainData.callback.onErrorCb(TTwainData.callback.onErrorArg, 0); - } - } - - if (imageMemXferH) { - GLOBAL_UNLOCK(imageMemXferH); - GLOBAL_FREE(imageMemXferH); - } - - if (transferBufferH) { - GLOBAL_UNLOCK(transferBuffer); - GLOBAL_FREE(transferBufferH); - } - return ret && !stopScanning; -} -/*---------------------------------------------------------------------------*/ -int TTWAIN_InitVar(void) { - char *c; - if (TTwainData.initDone) return TRUE; - - TTwainData.DSM_Entry = 0; - TTwainData.hwnd32SM = 0; - TTwainData.twainAvailable = AVAIABLE_DONTKNOW; - TTwainData.breakModalLoop = FALSE; - TTwainData.UIStatus = FALSE; - TTwainData.twainState = TWAIN_PRESESSION; - TTwainData.transferInfo.hDib = 0; - TTwainData.transferInfo.multiTransfer = TRUE; - TTwainData.supportedCaps = 0; - TTwainData.resultCode = 0; - TTwainData.ErrRC = 0; - TTwainData.ErrCC = 0; - TTwainData.modalStatus = FALSE; - TTwainData.appId.Id = 0; - TTWAIN_ConvertRevStrToRevNum(RELEASE_STR, &TTwainData.appId.Version.MajorNum, - &TTwainData.appId.Version.MinorNum); - TTwainData.appId.Version.Language = TWLG_USA; - TTwainData.appId.Version.Country = TWCY_USA; - strcpy((char *)TTwainData.appId.Version.Info, TITLEBAR_STR); - - TTwainData.appId.ProtocolMajor = TWON_PROTOCOLMAJOR; - TTwainData.appId.ProtocolMinor = TWON_PROTOCOLMINOR; - TTwainData.appId.SupportedGroups = DG_IMAGE | DG_CONTROL; - - c = (char *)TTwainData.appId.Manufacturer; -#ifdef MACOSX - *c = strlen(COMPANY); - c++; -#endif - strcpy(c, COMPANY); - - c = (char *)TTwainData.appId.ProductFamily; -#ifdef MACOSX - *c = strlen(PRODUCT); - c++; -#endif - strcpy(c, PRODUCT); - - c = (char *)TTwainData.appId.ProductName; -#ifdef MACOSX - *c = strlen(TwProgramName); - c++; -#endif - strcpy(c, TwProgramName); - - TTwainData.initDone = TRUE; - return TRUE; -} -/*---------------------------------------------------------------------------*/ -static void TTWAIN_FreeVar(void) { - if (TTwainData.supportedCaps) { - /* MEMORY LEAK ! -GLOBAL_FREE(TTwainData.supportedCaps); -*/ - TTwainData.supportedCaps = 0; - } -} -/*---------------------------------------------------------------------------*/ - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_state.h b/toonz/sources/common/twain/ttwain_state.h deleted file mode 100644 index 494205eb..00000000 --- a/toonz/sources/common/twain/ttwain_state.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#ifndef __TTWAIN_STATE_H__ -#define __TTWAIN_STATE_H__ - -#include "ttwain.h" -#include "ttwainP.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int TTWAIN_LoadSourceManager(void); -int TTWAIN_UnloadSourceManager(void); -TUINT32 TTWAIN_GetResultCode(void); -TUINT32 TTWAIN_GetConditionCode(void); -int TTWAIN_DSM_HasEntryPoint(void); -TW_INT16 TTWAIN_DS(TUINT32 dg, TUINT32 dat, TUINT32 msg, void *pd); -TWAINSTATE TTWAIN_GetState(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/toonz/sources/common/twain/ttwain_stateM.c b/toonz/sources/common/twain/ttwain_stateM.c deleted file mode 100644 index e73ac7f3..00000000 --- a/toonz/sources/common/twain/ttwain_stateM.c +++ /dev/null @@ -1,41 +0,0 @@ - - -/*max@home*/ -#include "twain.h" -#include "ttwain_state.h" -#include "ttwainP.h" -#include "ttwain_statePD.h" -#include "ttwain_util.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern void TTWAIN_SetState(TWAINSTATE status); - -int TTWAIN_LoadSourceManagerPD(void) { - if (TTWAIN_GetState() >= TWAIN_SM_LOADED) - return TRUE; /* DSM already loaded */ - TTwainData.DSM_Entry = DSM_Entry; - if (TTwainData.DSM_Entry != 0 /*kUnresolveCFragSymbolAddress*/) { - TTWAIN_SetAvailable(AVAIABLE_YES); - TTWAIN_SetState(TWAIN_SM_LOADED); - } else { - printf("DSM Entry NOT found !\n"); - return FALSE; - } - - return (TTWAIN_GetState() >= TWAIN_SM_LOADED); -} -int TTWAIN_UnloadSourceManagerPD(void) { - if (TTWAIN_GetState() == TWAIN_SM_LOADED) { - TTwainData.DSM_Entry = 0; - TTWAIN_SetState(TWAIN_PRESESSION); - } - return (TTWAIN_GetState() == TWAIN_PRESESSION); -} - -/*-----------------------------------------------------------------------------*/ -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_statePD.h b/toonz/sources/common/twain/ttwain_statePD.h deleted file mode 100644 index 78eb3c21..00000000 --- a/toonz/sources/common/twain/ttwain_statePD.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#ifndef __TTWAIN_STATE_PD_H__ -#define __TTWAIN_STATE_PD_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -int TTWAIN_LoadSourceManagerPD(void); -int TTWAIN_UnloadSourceManagerPD(void); -int TTWAIN_UnloadSourceManagerPD(void); -void TTWAIN_EmptyMessageQueuePD(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/toonz/sources/common/twain/ttwain_stateW.c b/toonz/sources/common/twain/ttwain_stateW.c deleted file mode 100644 index 95d8f4c4..00000000 --- a/toonz/sources/common/twain/ttwain_stateW.c +++ /dev/null @@ -1,77 +0,0 @@ - - -#pragma warning(disable : 4996) - -#include -#include - -#include "ttwain_state.h" -#include "ttwainP.h" -#include "ttwain_statePD.h" -#include "ttwain_util.h" - -#ifdef __cplusplus -extern "C" { -#endif - -static void *hDSMLib; /* handle of DSM */ -extern void TTWAIN_SetState(TWAINSTATE status); - -int TTWAIN_LoadSourceManagerPD(void) { - char winDir[_MAX_PATH]; - - if (TTWAIN_GetState() >= TWAIN_SM_LOADED) - return TRUE; /* DSM already loaded */ - - GetWindowsDirectory(winDir, _MAX_PATH); - if (!winDir[0]) return FALSE; - - strcat(winDir, "\\system32\\"); - // strcat(winDir, "\\"); - strcat(winDir, DSM_FILENAME); - - hDSMLib = LoadLibrary(winDir); - - /* -if (tnz_access(winDir, 0x00) != -1) -hDSMLib = LoadLibrary(winDir); -else -{ -hDSMLib = 0; -return FALSE; -} -*/ - - if (hDSMLib) { - TTwainData.DSM_Entry = - (DSMENTRYPROC)GetProcAddress(hDSMLib, DSM_ENTRYPOINT); - if (TTwainData.DSM_Entry) { - TTWAIN_SetAvailable(AVAIABLE_YES); - TTWAIN_SetState(TWAIN_SM_LOADED); - } else { - FreeLibrary(hDSMLib); - hDSMLib = NULL; - } - } else { - DWORD err = GetLastError(); - TTwainData.DSM_Entry = 0; - } - return (TTWAIN_GetState() >= TWAIN_SM_LOADED); -} -/*---------------------------------------------------------------------------*/ -int TTWAIN_UnloadSourceManagerPD(void) { - if (TTWAIN_GetState() == TWAIN_SM_LOADED) { - if (hDSMLib) { - FreeLibrary(hDSMLib); - hDSMLib = NULL; - } - TTwainData.DSM_Entry = NULL; - TTWAIN_SetState(TWAIN_PRESESSION); - } - return (TTWAIN_GetState() == TWAIN_PRESESSION); -} -/*---------------------------------------------------------------------------*/ - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_stateX.c b/toonz/sources/common/twain/ttwain_stateX.c deleted file mode 100644 index 75c820d5..00000000 --- a/toonz/sources/common/twain/ttwain_stateX.c +++ /dev/null @@ -1,14 +0,0 @@ - - -#ifdef __cplusplus -extern "C" { -#endif - -#include "ttwain_statePD.h" - -int TTWAIN_LoadSourceManagerPD(void) { return 0; } -int TTWAIN_UnloadSourceManagerPD(void) { return 1; } - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_util.c b/toonz/sources/common/twain/ttwain_util.c deleted file mode 100644 index 6982db6f..00000000 --- a/toonz/sources/common/twain/ttwain_util.c +++ /dev/null @@ -1,1302 +0,0 @@ - - -#ifdef _MSC_VER -#pragma warning(disable : 4996) -#endif - -#ifdef NOTE -here -/* -TTWAIN_Get???Value (TW_RANGE range) restituisce sempre un float e (ovviamente) -funziona solo con gli item il cui sizeof() e' <= sizeof (float) (unica eccezione -TW_FIX32) - -USA_LE_QUERY: -> non definito! -Le query dovrebbero essere un modo per capire le azioni che sono permesse -su una determinata capability, questo sta scritto in twainSpec1.8: -nessun DS ha ritornato valori sensati, per cui non vengono usate. -*/ -#endif - -#include -#include -#include - -#include - -#include "ttwain_util.h" -#include "ttwain_utilP.h" -#include "ttwain_utilPD.h" -#include "ttwainP.h" -#include "ttwain.h" -#include "ttwain_state.h" -#include "ttwain_capability.h" -#include "ttwain_conversion.h" -#include "ttwain_error.h" - -#include "ttwain_global_def.h" - -/* -Scommentare MACOSX_NO_PARAMS, per evitare che l'applicazione abbia il controllo -dei parametri (Caps supportate, ImageLayout, XferCount) -Utile sotto MACOSX per evitare che i DS della HP si aprano alla richiesta, -e rimangano li.... in attesa di una scansione (tutto continua a funzionare, -alla prima scansione il DS si chiude correttamente e l'applicazione ottiene -l'immagine) -*/ -/* -#define MACOSX_NO_PARAMS -*/ - -#ifdef __cplusplus - extern "C" { -#endif - - /*#define USA_LE_QUERY*/ - /* local */ - static int TTWAIN_GetPhysicalWidth(float *width); - static int TTWAIN_GetPhysicalHeight(float *height); - - static int TTWAIN_GetMinimumWidth(float *width); - static int TTWAIN_GetMinimumHeight(float *height); - - static int TTWAIN_IsCapSupported(void *cap); - static int TTWAIN_IsCapSupportedTW_INT16(TW_INT16 cap); - - /* MISC AUX FUNCTIONS */ - static float TTWAIN_GetMinValue(TW_RANGE range); - static float TTWAIN_GetMaxValue(TW_RANGE range); - static float TTWAIN_GetDefValue(TW_RANGE range); - static float TTWAIN_GetStepValue(TW_RANGE range); - static int TTWAIN_IsItemInList(void *list, void *item, TUINT32 list_count, - TUINT32 item_size); - - static const size_t DCItemSize[13] = { - sizeof(TW_INT8), sizeof(TW_INT16), sizeof(TW_INT32), sizeof(TW_UINT8), - sizeof(TW_UINT16), sizeof(TW_UINT32), sizeof(TW_BOOL), sizeof(TW_FIX32), - sizeof(TW_FRAME), sizeof(TW_STR32), sizeof(TW_STR64), sizeof(TW_STR128), - sizeof(TW_STR255), - }; /* see twain.h */ - -#define FLAVOR_UNUSED (0xffff) - - struct TTWAIN_PIXELTYPEP { - TW_UINT16 type; - TW_UINT16 flavor; - TW_UINT16 bitDepth; - }; - static struct TTWAIN_PIXELTYPEP PixType[TTWAIN_PIXTYPE_HOWMANY] = { - {TWPT_BW, TWPF_CHOCOLATE, 1}, /* BW */ - {TWPT_BW, TWPF_VANILLA, 1}, /* WB */ - {TWPT_GRAY, FLAVOR_UNUSED, 8}, /* GRAY8 */ - {TWPT_RGB, FLAVOR_UNUSED, 24} /* RGB24 */ - }; - /*---------------------------------------------------------------------------*/ - /* GET CAPABILITIES */ - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetResolution(float *min, float *max, float *step, float *def) { - TW_RANGE range_data; - int rc; - - if (!(min && max && step && def)) return FALSE; - rc = TTWAIN_GetCap(ICAP_XRESOLUTION, TWON_RANGE, (void *)&range_data, 0); - if (!rc) return FALSE; - *min = TTWAIN_GetMinValue(range_data); - *max = TTWAIN_GetMaxValue(range_data); - *step = TTWAIN_GetStepValue(range_data); - *def = TTWAIN_GetDefValue(range_data); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetOpticalResolution(float *min, float *max, float *step, - float *def) { - TW_RANGE range_data; - int rc; - - if (!(min && max && step && def)) return FALSE; - rc = TTWAIN_GetCap(ICAP_XNATIVERESOLUTION, TWON_RANGE, (void *)&range_data, - 0); - if (!rc) return FALSE; - *min = TTWAIN_GetMinValue(range_data); - *max = TTWAIN_GetMaxValue(range_data); - *step = TTWAIN_GetStepValue(range_data); - *def = TTWAIN_GetDefValue(range_data); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetBrightness(float *min, float *max, float *step, float *def) { - TW_RANGE range_data; - int rc; - - assert(min && max && step && def); - - rc = TTWAIN_GetCap(ICAP_BRIGHTNESS, TWON_RANGE, (void *)&range_data, 0); - if (!rc) return FALSE; - *min = TTWAIN_GetMinValue(range_data); - *max = TTWAIN_GetMaxValue(range_data); - *step = TTWAIN_GetStepValue(range_data); - *def = TTWAIN_GetDefValue(range_data); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetContrast(float *min, float *max, float *step, float *def) { - TW_RANGE range_data; - int rc; - - assert(min && max && step && def); - - rc = TTWAIN_GetCap(ICAP_CONTRAST, TWON_RANGE, (void *)&range_data, 0); - if (!rc) return FALSE; - *min = TTWAIN_GetMinValue(range_data); - *max = TTWAIN_GetMaxValue(range_data); - *step = TTWAIN_GetStepValue(range_data); - *def = TTWAIN_GetDefValue(range_data); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetThreshold(float *min, float *max, float *step, float *def) { - TW_RANGE range_data; - int rc; - - assert(min && max && step && def); - - rc = TTWAIN_GetCap(ICAP_THRESHOLD, TWON_RANGE, (void *)&range_data, 0); - if (!rc) return FALSE; - *min = TTWAIN_GetMinValue(range_data); - *max = TTWAIN_GetMaxValue(range_data); - *step = TTWAIN_GetStepValue(range_data); - *def = TTWAIN_GetDefValue(range_data); - return rc; - } - /*---------------------------------------------------------------------------*/ - static int TTWAIN_GetPhysicalWidth(float *width) { - TW_ONEVALUE width_data; - if (TTWAIN_GetCap(ICAP_PHYSICALWIDTH, TWON_ONEVALUE, (void *)&width_data, - 0)) { - *width = TTWAIN_Fix32ToFloat(*(TW_FIX32 *)&width_data.Item); - return TRUE; - } else - return FALSE; - } - /*---------------------------------------------------------------------------*/ - static int TTWAIN_GetPhysicalHeight(float *height) { - TW_ONEVALUE height_data; - if (TTWAIN_GetCap(ICAP_PHYSICALHEIGHT, TWON_ONEVALUE, (void *)&height_data, - 0)) { - *height = TTWAIN_Fix32ToFloat(*(TW_FIX32 *)&height_data.Item); - return TRUE; - } else - return FALSE; - } - /*---------------------------------------------------------------------------*/ - static int TTWAIN_GetMinimumWidth(float *width) { - TW_ONEVALUE width_data; - if (TTWAIN_GetCap(ICAP_MINIMUMWIDTH, TWON_ONEVALUE, (void *)&width_data, - 0)) { - *width = TTWAIN_Fix32ToFloat(*(TW_FIX32 *)&width_data.Item); - return TRUE; - } else - return FALSE; - } - /*---------------------------------------------------------------------------*/ - static int TTWAIN_GetMinimumHeight(float *height) { - TW_ONEVALUE height_data; - if (TTWAIN_GetCap(ICAP_MINIMUMHEIGHT, TWON_ONEVALUE, (void *)&height_data, - 0)) { - *height = TTWAIN_Fix32ToFloat(*(TW_FIX32 *)&height_data.Item); - return TRUE; - } else - return FALSE; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetPhysicalWidthWAdf(float *width) { - int rc = FALSE; - int feeder_status; - - if (TTWAIN_SupportsFeeder()) { - feeder_status = TTWAIN_GetFeeder(); - rc = TTWAIN_SetFeeder(TRUE); - if (rc) rc = TTWAIN_GetPhysicalWidth(width); - TTWAIN_SetFeeder(feeder_status); - } - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetPhysicalHeightWAdf(float *height) { - int rc = FALSE; - int feeder_status; - - if (TTWAIN_SupportsFeeder()) { - feeder_status = TTWAIN_GetFeeder(); - rc = TTWAIN_SetFeeder(TRUE); - if (rc) rc = TTWAIN_GetPhysicalHeight(height); - TTWAIN_SetFeeder(feeder_status); - } - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetMinimumWidthWAdf(float *width) { - int rc = FALSE; - int feeder_status; - - if (TTWAIN_SupportsFeeder()) { - feeder_status = TTWAIN_GetFeeder(); - rc = TTWAIN_SetFeeder(TRUE); - if (rc) rc = TTWAIN_GetMinimumWidth(width); - TTWAIN_SetFeeder(feeder_status); - } - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetMinimumHeightWAdf(float *height) { - int rc = FALSE; - int feeder_status; - - if (TTWAIN_SupportsFeeder()) { - feeder_status = TTWAIN_GetFeeder(); - rc = TTWAIN_SetFeeder(TRUE); - if (rc) rc = TTWAIN_GetMinimumHeight(height); - TTWAIN_SetFeeder(feeder_status); - } - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetPhysicalWidthWoAdf(float *width) { - int rc = FALSE; - int feeder_status = FALSE; - - if (TTWAIN_SupportsFeeder()) { - feeder_status = TTWAIN_GetFeeder(); - rc = TTWAIN_SetFeeder(FALSE); - } - rc = TTWAIN_GetPhysicalWidth(width); - if (TTWAIN_SupportsFeeder()) TTWAIN_SetFeeder(feeder_status); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetPhysicalHeightWoAdf(float *height) { - int rc = FALSE; - int feeder_status = FALSE; - - if (TTWAIN_SupportsFeeder()) { - feeder_status = TTWAIN_GetFeeder(); - rc = TTWAIN_SetFeeder(TRUE); - } - rc = TTWAIN_GetPhysicalHeight(height); - if (TTWAIN_SupportsFeeder()) TTWAIN_SetFeeder(feeder_status); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetMinimumWidthWoAdf(float *width) { - int rc = FALSE; - int feeder_status = FALSE; - - if (TTWAIN_SupportsFeeder()) { - feeder_status = TTWAIN_GetFeeder(); - rc = TTWAIN_SetFeeder(FALSE); - } - rc = TTWAIN_GetMinimumWidth(width); - if (TTWAIN_SupportsFeeder()) TTWAIN_SetFeeder(feeder_status); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetMinimumHeightWoAdf(float *height) { - int rc = FALSE; - int feeder_status = FALSE; - - if (TTWAIN_SupportsFeeder()) { - feeder_status = TTWAIN_GetFeeder(); - rc = TTWAIN_SetFeeder(TRUE); - } - rc = TTWAIN_GetMinimumHeight(height); - if (TTWAIN_SupportsFeeder()) TTWAIN_SetFeeder(feeder_status); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SupportsPixelType(TTWAIN_PIXTYPE pix_type) { - TW_HANDLE handle; - TW_ENUMERATION *container; - int rc, found = FALSE; - TUINT32 size4data; - TW_UINT16 twPix; - - twPix = PixType[pix_type].type; - rc = TTWAIN_GetCap(ICAP_PIXELTYPE, TWON_ENUMERATION, (void *)0, &size4data); - if (!rc) return FALSE; - if (!size4data) return FALSE; - handle = GLOBAL_ALLOC(GMEM_FIXED, size4data); - if (!handle) return FALSE; - - container = (TW_ENUMERATION *)GLOBAL_LOCK(handle); - rc = TTWAIN_GetCap(ICAP_PIXELTYPE, TWON_ENUMERATION, (void *)container, 0); - - if (!rc) goto done; - found = - TTWAIN_IsItemInList(container->ItemList, &twPix, container->NumItems, - DCItemSize[container->ItemType]); - - done: - GLOBAL_UNLOCK(handle); - GLOBAL_FREE(handle); - return found; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SupportsCompressionType(TW_UINT16 comprType) { - int rc; - TUINT32 size; - int found = FALSE; - TW_ENUMERATION *container = 0; - TW_HANDLE handle = 0; - - if (!TTWAIN_IsCapCompressionSupported()) return FALSE; - rc = TTWAIN_GetCap(ICAP_COMPRESSION, TWON_ENUMERATION, (void *)0, &size); - if (!rc || !size) return FALSE; - - handle = GLOBAL_ALLOC(GMEM_FIXED, size); - if (!handle) return FALSE; - - container = (TW_ENUMERATION *)GLOBAL_LOCK(handle); - - rc = - TTWAIN_GetCap(ICAP_COMPRESSION, TWON_ENUMERATION, (void *)container, 0); - - if (!rc) goto done; - found = TTWAIN_IsItemInList(container->ItemList, &comprType, - container->NumItems, - DCItemSize[container->ItemType]); - found = TRUE; - done: - if (handle) { - GLOBAL_UNLOCK(handle); - GLOBAL_FREE(handle); - } - return found; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SupportsFeeder(void) { - TW_ONEVALUE feeder; - int rc; - feeder.Item = 0; - rc = TTWAIN_GetCap(CAP_FEEDERENABLED, TWON_ONEVALUE, (void *)&feeder, 0); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetFeeder(void) /* TRUE->enabled */ - { - TW_ONEVALUE feeder; - int rc; - feeder.Item = 0; - rc = TTWAIN_GetCap(CAP_FEEDERENABLED, TWON_ONEVALUE, (void *)&feeder, 0); - return feeder.Item && rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsFeederLoaded(void) /* TRUE->loaded */ - { - TW_ONEVALUE feeder; - int rc; - -#ifdef MACOSX_NO_PARAMS - printf("%s always returns false (disabled at compile time)\n", - __FUNCTION__); - return FALSE; -#endif - - feeder.Item = 0; - rc = TTWAIN_GetCap(CAP_FEEDERLOADED, TWON_ONEVALUE, (void *)&feeder, 0); - return feeder.Item && rc; - } - /*---------------------------------------------------------------------------*/ - char *TTWAIN_GetManufacturer(void) { -#ifdef MACOSX - static char msg[1024]; - strncpy(msg, (const char *)&TTwainData.sourceId.Manufacturer[1], - *TTwainData.sourceId.Manufacturer); - return msg; -#else - return (char *)TTwainData.sourceId.Manufacturer; -#endif - } - /*---------------------------------------------------------------------------*/ - char *TTWAIN_GetProductFamily(void) { -#ifdef MACOSX - static char msg[1024]; - strncpy(msg, (const char *)&TTwainData.sourceId.ProductFamily[1], - *TTwainData.sourceId.ProductFamily); - return msg; -#else - return (char *)TTwainData.sourceId.ProductFamily; -#endif - } - /*---------------------------------------------------------------------------*/ - char *TTWAIN_GetProductName(void) { -#ifdef MACOSX - static char msg[1024]; - strncpy(msg, (const char *)&TTwainData.sourceId.ProductName[1], - *TTwainData.sourceId.ProductName); - return msg; -#else - return (char *)TTwainData.sourceId.ProductName; -#endif - } - /*---------------------------------------------------------------------------*/ - char *TTWAIN_GetVersion(void) { - static char version[5 + 1 + 5 + 1 + 32 + 1]; - snprintf(version, sizeof(version), "%d.%d %s", - TTwainData.sourceId.Version.MajorNum, - TTwainData.sourceId.Version.MinorNum, - (char *)TTwainData.sourceId.Version.Info); - return version; - } - /*---------------------------------------------------------------------------*/ - char *TTWAIN_GetTwainVersion(void) { - static char version[5 + 1 + 5 + 1]; - snprintf(version, sizeof(version), "%d.%d", - TTwainData.sourceId.ProtocolMajor, - TTwainData.sourceId.ProtocolMinor); - return version; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetSupportedCaps(void) { - TW_ARRAY *container; - TW_HANDLE handle = 0; - int rc; - TUINT32 size4data; - - TTwainData.isSupportedCapsSupported = FALSE; - -#ifdef MACOSX_NO_PARAMS - printf("%s always returns false (disabled at compile time)\n", - __FUNCTION__); - return FALSE; -/* PER ora su mac sono disabilitate! */ -/*return FALSE;*/ -#endif - - rc = TTWAIN_GetCap(CAP_SUPPORTEDCAPS, TWON_ARRAY, (void *)0, &size4data); - if (!rc) return FALSE; - if (!size4data) return FALSE; - handle = GLOBAL_ALLOC(GMEM_FIXED, size4data); - if (!handle) return FALSE; - container = (TW_ARRAY *)GLOBAL_LOCK(handle); - rc = TTWAIN_GetCap(CAP_SUPPORTEDCAPS, TWON_ARRAY, (void *)container, 0); - if (rc) { - /* -MEMORY LEAK !!! ma per ora va bene cosi'... -if (TTwainData.supportedCaps) -GLOBAL_FREE(TTwainData.supportedCaps); -*/ - TTwainData.supportedCaps = container; - } - TTwainData.isSupportedCapsSupported = TRUE; - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetCurrentPixelType(TTWAIN_PIXTYPE * pixType) { - int rc1, rc2; - TW_ONEVALUE pixelType, pixelFlavor; - int i; - rc1 = TTWAIN_GetCapCurrent(ICAP_PIXELTYPE, TWON_ONEVALUE, &pixelType, 0); - if (!rc1) return FALSE; - *pixType = TTWAIN_PIXUNKNOWN; - if (pixelType.Item == TWPT_BW) { - rc2 = TTWAIN_GetCapCurrent(ICAP_PIXELFLAVOR, TWON_ONEVALUE, &pixelFlavor, - 0); - if (!rc2) pixelFlavor.Item = TWPF_CHOCOLATE; /*this is the default */ - } else { - pixelFlavor.Item = FLAVOR_UNUSED; - } - - for (i = 0; i < TTWAIN_PIXTYPE_HOWMANY; i++) { - if ((PixType[i].type == pixelType.Item) && - (PixType[i].flavor == pixelFlavor.Item)) { - *pixType = (TTWAIN_PIXTYPE)i; - return TRUE; - } - } - return FALSE; - } - - /*---------------------------------------------------------------------------*/ - /* SUPPORTED CAPABILITIES */ - /*---------------------------------------------------------------------------*/ - static int TTWAIN_IsCapSupported(void *cap) { -#ifdef USA_LE_QUERY - int queryRc; - TW_UINT16 pattern; - int et; - queryRc = TTWAIN_GetCapQuery(*((TW_INT16 *)cap), &pattern); - - et = pattern & (TWQC_SET | TWQC_GET); - return (TTwainData.isSupportedCapsSupported && queryRc && et) || - (TTwainData.supportedCaps && - TTWAIN_IsItemInList( - TTwainData.supportedCaps, cap, - TTwainData.supportedCaps->NumItems, - DCItemSize[TTwainData.supportedCaps->ItemType])) || - (queryRc && et); -#else - return TTwainData.isSupportedCapsSupported && - (TTwainData.supportedCaps && - TTWAIN_IsItemInList(TTwainData.supportedCaps, cap, - TTwainData.supportedCaps->NumItems, - DCItemSize[TTwainData.supportedCaps->ItemType])); -#endif - } - /*---------------------------------------------------------------------------*/ - static int TTWAIN_IsCapSupportedTW_INT16(TW_INT16 cap) { - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapResolutionSupported(void) { - TW_UINT16 cap = ICAP_XRESOLUTION; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapOpticalResolutionSupported(void) { - TW_UINT16 cap = ICAP_XNATIVERESOLUTION; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapBrightnessSupported(void) { - TW_UINT16 cap = ICAP_BRIGHTNESS; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapContrastSupported(void) { - TW_UINT16 cap = ICAP_CONTRAST; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapThresholdSupported(void) { - TW_UINT16 cap = ICAP_THRESHOLD; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapPhysicalWidthSupported(void) { - TW_UINT16 cap = ICAP_PHYSICALWIDTH; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapPhysicalHeightSupported(void) { - TW_UINT16 cap = ICAP_PHYSICALHEIGHT; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapMinimumWidthSupported(void) { - TW_UINT16 cap = ICAP_MINIMUMWIDTH; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapMinimumHeightSupported(void) { - TW_UINT16 cap = ICAP_MINIMUMHEIGHT; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapPixelTypeSupported(void) { - TW_UINT16 cap = ICAP_PIXELTYPE; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapFeederSupported(void) { - TW_UINT16 cap = CAP_FEEDERENABLED; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapImageLayoutSupported(void) { - /*assert(0);*/ - return TRUE; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapOrientationSupported(void) { - TW_UINT16 cap = ICAP_ORIENTATION; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapDeviceOnLineSupported(void) { - TW_UINT16 cap = CAP_DEVICEONLINE; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapBitDepthSupported(void) { - TW_UINT16 cap = ICAP_BITDEPTH; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapBitOrderSupported(void) { - TW_UINT16 cap = ICAP_BITORDER; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsCapCompressionSupported(void) { - TW_UINT16 cap = ICAP_COMPRESSION; - return TTWAIN_IsCapSupported(&cap); - } - /*---------------------------------------------------------------------------*/ - /* SET CAPABILITIES */ - /*---------------------------------------------------------------------------*/ - int TTWAIN_SetContrast(float contrast) { - TW_FIX32 twfix = TTWAIN_FloatToFix32(contrast); - return TTWAIN_SetCap(ICAP_CONTRAST, TWON_ONEVALUE, TWTY_FIX32, - (TW_UINT32 *)&twfix); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SetBrightness(float brightness) { - TW_FIX32 twfix = TTWAIN_FloatToFix32(brightness); - return TTWAIN_SetCap(ICAP_BRIGHTNESS, TWON_ONEVALUE, TWTY_FIX32, - (TW_UINT32 *)&twfix); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SetThreshold(float threshold) { - TW_FIX32 twfix = TTWAIN_FloatToFix32(threshold); - return TTWAIN_SetCap(ICAP_THRESHOLD, TWON_ONEVALUE, TWTY_FIX32, - (TW_UINT32 *)&twfix); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SetResolution(float resolution) { - int rc1, rc2; - TW_FIX32 twfix = TTWAIN_FloatToFix32(resolution); - rc1 = TTWAIN_SetCap(ICAP_XRESOLUTION, TWON_ONEVALUE, TWTY_FIX32, - (TW_UINT32 *)&twfix); - rc2 = TTWAIN_SetCap(ICAP_YRESOLUTION, TWON_ONEVALUE, TWTY_FIX32, - (TW_UINT32 *)&twfix); - return (rc1 & rc2); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SetXScaling(float scale) { - int rc; - TW_FIX32 twfix = TTWAIN_FloatToFix32(scale); - rc = TTWAIN_SetCap(ICAP_XSCALING, TWON_ONEVALUE, TWTY_FIX32, - (TW_UINT32 *)&twfix); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SetYScaling(float scale) { - int rc; - TW_FIX32 twfix = TTWAIN_FloatToFix32(scale); - rc = TTWAIN_SetCap(ICAP_YSCALING, TWON_ONEVALUE, TWTY_FIX32, - (TW_UINT32 *)&twfix); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SetPixelType(TTWAIN_PIXTYPE pixtype) { - TUINT32 twPix; - int rc, rc2, rc3, rc4, rc5, bdRc; - TW_ENUMERATION *container = 0; - TW_HANDLE handle = 0; - - TW_UINT16 twFlavor, twBitDepth; - int found; - TUINT32 size; - - twPix = PixType[pixtype].type; - twFlavor = PixType[pixtype].flavor; - twBitDepth = PixType[pixtype].bitDepth; - /*the default in twain specs is chocolate*/ - TTwainData.transferInfo.nextImageNeedsToBeInverted = - ((twFlavor != TWPF_CHOCOLATE) && (twFlavor != FLAVOR_UNUSED)); - - rc = TTWAIN_SetCap(ICAP_PIXELTYPE, TWON_ONEVALUE, TWTY_UINT16, - (TW_UINT32 *)&twPix); - if (TTWAIN_IsCapBitDepthSupported()) bdRc = TTWAIN_SetBitDepth(twBitDepth); - - if (rc) { - if (twFlavor != FLAVOR_UNUSED) { - rc2 = - TTWAIN_GetCap(ICAP_PIXELFLAVOR, TWON_ENUMERATION, (void *)0, &size); - if (rc2 && size) { - handle = GLOBAL_ALLOC(GMEM_FIXED, size); - if (!handle) - return TRUE; /*non sono semplicamente riuscito a prendere info -riguardo -il pixelFlavor, ma setPixelType e' andato a buon fine */ -#ifdef _WIN32 - container = (TW_ENUMERATION *)handle; -#else - container = (TW_ENUMERATION *)GLOBAL_LOCK(handle); -#endif - rc3 = TTWAIN_GetCap(ICAP_PIXELFLAVOR, TWON_ENUMERATION, - (void *)container, 0); - if (rc3) { - found = TTWAIN_IsItemInList(container->ItemList, &twFlavor, - container->NumItems, - DCItemSize[container->ItemType]); - /*let's try to set....*/ - if (found) { - rc4 = TTWAIN_SetCap(ICAP_PIXELFLAVOR, TWON_ONEVALUE, TWTY_UINT16, - (TW_UINT32 *)&twFlavor); - if (rc4) { - TW_UINT16 current, *itemList; - /*check if it's properly set...*/ - rc5 = TTWAIN_GetCap(ICAP_PIXELFLAVOR, TWON_ENUMERATION, - (void *)container, 0); - if (rc5) { - itemList = (TW_UINT16 *)container->ItemList; - current = itemList[container->CurrentIndex]; - if (current == twFlavor) { - TTwainData.transferInfo.nextImageNeedsToBeInverted = FALSE; - } - } - } - } - } - } - } - } - if (handle) { - GLOBAL_UNLOCK(handle); - GLOBAL_FREE(handle); - } - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SetBitDepth(USHORT bitDepth) { - TUINT32 bd = bitDepth; - int rc; - - rc = TTWAIN_SetCap(ICAP_BITDEPTH, TWON_ONEVALUE, TWTY_UINT16, - (TW_UINT32 *)&bd); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SetBitOrder(TTWAIN_BITORDER bitOrder) { - TUINT32 bo = bitOrder; - int rc; - - rc = TTWAIN_SetCap(ICAP_BITORDER, TWON_ONEVALUE, TWTY_UINT16, - (TW_UINT32 *)&bo); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SetImageLayout(float L, float T, float R, float B) { - TW_IMAGELAYOUT layout; - TW_IMAGELAYOUT layout2; - int rc; - int rc2; - -#ifdef MACOSX_NO_PARAMS - printf("%s always returns true (disabled at compile time)\n", __FUNCTION__); - return TRUE; -#endif - /* -if (TTWAIN_GetState() != TWAIN_SOURCE_OPEN) -{ -TTWAIN_RecordError(); -return FALSE; -} -*/ - layout.Frame.Left = TTWAIN_FloatToFix32(L); - layout.Frame.Top = TTWAIN_FloatToFix32(T); - layout.Frame.Right = TTWAIN_FloatToFix32(R); - layout.Frame.Bottom = TTWAIN_FloatToFix32(B); - - layout.DocumentNumber = TWON_DONTCARE32; - layout.PageNumber = TWON_DONTCARE32; - layout.FrameNumber = TWON_DONTCARE32; - rc = (TTWAIN_DS(DG_IMAGE, DAT_IMAGELAYOUT, MSG_SET, &layout) == - TWRC_SUCCESS); - rc2 = (TTWAIN_DS(DG_IMAGE, DAT_IMAGELAYOUT, MSG_GET, &layout2) == - TWRC_SUCCESS); - return rc; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_NegotiateXferCount(TUINT32 nXfers) { -#ifdef MACOSX_NO_PARAMS - printf("%s always returns true (disabled at compile time)\n", __FUNCTION__); - return TRUE; -#endif - return TTWAIN_SetCap(CAP_XFERCOUNT, TWON_ONEVALUE, TWTY_INT16, - (TW_UINT32 *)&nXfers); - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SetXferMech(TTWAIN_TRANSFER_MECH mech, void *ptr, TUINT32 size, - int preferredLx, int preferredLy, - TUINT32 numberOfImages) { - TW_UINT32 theMech = mech; - - TTwainData.transferInfo.preferredLx = preferredLx; - TTwainData.transferInfo.preferredLy = preferredLy; - if (mech == TTWAIN_TRANSFERMODE_NATIVE) { - /*assert(!ptr);*/ - /*invalidate mem & len*/ - TTwainData.transferInfo.memorySize = -1; - TTwainData.transferInfo.memoryBuffer = 0; - } else { - /*assert(ptr);*/ - /*store*/ - assert(!ptr); /* questo va rivisto, comunque NON si puo' fornire il - buffer! */ - TTwainData.transferInfo.memorySize = size; - TTwainData.transferInfo.memoryBuffer = (UCHAR *)ptr; - } - - if (TTWAIN_SetCap(ICAP_XFERMECH, TWON_ONEVALUE, TWTY_UINT16, - (TW_UINT32 *)&theMech)) { - if (numberOfImages != -1) TTWAIN_NegotiateXferCount(numberOfImages); - TTwainData.transferInfo.transferMech = mech; - return TRUE; - } else - return FALSE; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_SetFeeder(int status) /* TRUE->enabled */ - { - int rc; - rc = TTWAIN_SetCap(CAP_FEEDERENABLED, TWON_ONEVALUE, TWTY_BOOL, - (TW_UINT32 *)&status); - /* -if (TTwainData.transferInfo.usageMode == TTWAIN_MODE_UNLEASHED) -TTwainData.transferInfo.multiTransfer = status; -*/ - return rc; - } - /*---------------------------------------------------------------------------*/ - /* USER INTERFACE */ - /*---------------------------------------------------------------------------*/ - int TTWAIN_HasControllableUI(void) { - TW_ONEVALUE onevalue_data; - int rc; - rc = TTWAIN_GetCap(CAP_UICONTROLLABLE, TWON_ONEVALUE, - (void *)&onevalue_data, 0); - if (!rc) return FALSE; - return (int)onevalue_data.Item; - } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetUIStatus(void) { return TTwainData.UIStatus; } - /*---------------------------------------------------------------------------*/ - void TTWAIN_SetUIStatus(int status) { TTwainData.UIStatus = status; } - /*---------------------------------------------------------------------------*/ - int TTWAIN_GetModalStatus(void) { return TTwainData.modalStatus; } - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsDeviceOnLine(void) /* -1 unknown, 0 no, 1 yes */ - { - TW_ONEVALUE onevalue_data; - int rc; - rc = TTWAIN_GetCap(CAP_DEVICEONLINE, TWON_ONEVALUE, (void *)&onevalue_data, - 0); - if (!rc) return -1; - return (int)onevalue_data.Item; - } - /*---------------------------------------------------------------------------*/ - /* TWAIN AVAILABILITY */ - /*---------------------------------------------------------------------------*/ - int TTWAIN_IsAvailable(void) { - TTWAIN_InitVar(); - if (TTWAIN_DSM_HasEntryPoint()) return TRUE; - - if (TTwainData.twainAvailable == AVAIABLE_DONTKNOW) { - if (TTWAIN_LoadSourceManager()) { - TTWAIN_UnloadSourceManager(); - } else { - TTwainData.twainAvailable = AVAIABLE_NO; - } - } - - return (TTwainData.twainAvailable == AVAIABLE_YES); - } - /*---------------------------------------------------------------------------*/ - void TTWAIN_SetAvailable(TWAINAVAILABLE status) { - TTwainData.twainAvailable = status; - } - /*---------------------------------------------------------------------------*/ - - /*---------------------------------------------------------------------------*/ - /* MISC AUX FUNCTIONS */ - /*---------------------------------------------------------------------------*/ - - static float TTWAIN_GetMinValue(TW_RANGE range) { - switch (range.ItemType) { - case TWTY_INT8: - case TWTY_INT16: - case TWTY_INT32: - case TWTY_UINT8: - case TWTY_UINT16: - return (float)range.MinValue; - - case TWTY_FIX32: { - TW_FIX32 *fix32 = (TW_FIX32 *)&range.MinValue; - return (float)TTWAIN_Fix32ToFloat(*fix32); - } - - default: - // TWTY_UINT32 - // TWTY_BOOL - // TWTY_FRAME - // TWTY_STR32 - // TWTY_STR64 - // TWTY_STR128 - // TWTY_STR255 - assert(!"Invalid type!!!"); - return 0; - } - return 0; - } - /*---------------------------------------------------------------------------*/ - static float TTWAIN_GetMaxValue(TW_RANGE range) { - switch (range.ItemType) { - case TWTY_INT8: - case TWTY_INT16: - case TWTY_INT32: - case TWTY_UINT8: - case TWTY_UINT16: - return (float)range.MaxValue; - - case TWTY_FIX32: { - TW_FIX32 *fix32 = (TW_FIX32 *)&range.MaxValue; - return (float)TTWAIN_Fix32ToFloat(*fix32); - } - - default: - // TWTY_UINT32 - // TWTY_BOOL - // TWTY_FRAME - // TWTY_STR32 - // TWTY_STR64 - // TWTY_STR128 - // TWTY_STR255 - assert(!"Invalid type!!"); - return 0; - } - return 0; - } - /*---------------------------------------------------------------------------*/ - static float TTWAIN_GetDefValue(TW_RANGE range) { - switch (range.ItemType) { - case TWTY_INT8: - case TWTY_INT16: - case TWTY_INT32: - case TWTY_UINT8: - case TWTY_UINT16: - return (float)range.DefaultValue; - - case TWTY_FIX32: { - TW_FIX32 *fix32 = (TW_FIX32 *)&range.DefaultValue; - return (float)TTWAIN_Fix32ToFloat(*fix32); - } - - default: - // TWTY_UINT32 - // TWTY_BOOL - // TWTY_FRAME - // TWTY_STR32 - // TWTY_STR64 - // TWTY_STR128 - // TWTY_STR255 - assert(!"Invalid type!!"); - return 0; - } - return 0; - } - /*---------------------------------------------------------------------------*/ - static float TTWAIN_GetStepValue(TW_RANGE range) { - switch (range.ItemType) { - case TWTY_INT8: - case TWTY_INT16: - case TWTY_INT32: - case TWTY_UINT8: - case TWTY_UINT16: - return (float)range.StepSize; - - case TWTY_FIX32: { - TW_FIX32 *fix32 = (TW_FIX32 *)&range.StepSize; - return (float)TTWAIN_Fix32ToFloat(*fix32); - } - - default: - // TWTY_UINT32 - // TWTY_BOOL - // TWTY_FRAME - // TWTY_STR32 - // TWTY_STR64 - // TWTY_STR128 - // TWTY_STR255 - assert(!"Invalid type!!"); - return 0; - } - return 0; - } - /*---------------------------------------------------------------------------*/ - /*---------------------------------------------------------------------------*/ - /*---------------------------------------------------------------------------*/ - int TTWAIN_Native2Raster(void *handle, void *the_ras, int *lx, int *ly) { - return TTWAIN_Native2RasterPD(handle, the_ras, lx, ly); - } - /*---------------------------------------------------------------------------*/ - static int TTWAIN_IsItemInList(void *list, void *item, TUINT32 list_count, - TUINT32 item_size) { - int found = FALSE; - TUINT32 count = list_count; - UCHAR *pList = (UCHAR *)list; - UCHAR *pItem = (UCHAR *)item; - - if (!list || !item) return FALSE; - while (count--) { - if (memcmp(pList, pItem, item_size) == 0) { - found = TRUE; - break; - } - pList += item_size; - } - return found; - } - /*---------------------------------------------------------------------------*/ - void TTWAIN_DumpCapabilities(void (*trace_fun)(const char *fmt, ...)) { - if (!trace_fun) return; - trace_fun("list of supported (exported) capabilities\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_XFERCOUNT)) - trace_fun("CAP_XFERCOUNT"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_COMPRESSION)) - trace_fun("ICAP_COMPRESSION\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_PIXELTYPE)) - trace_fun("ICAP_PIXELTYPE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_UNITS)) trace_fun("ICAP_UNITS\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_XFERMECH)) - trace_fun("ICAP_XFERMECH\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_AUTHOR)) trace_fun("CAP_AUTHOR\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_CAPTION)) trace_fun("CAP_CAPTION\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_FEEDERENABLED)) - trace_fun("CAP_FEEDERENABLED\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_FEEDERLOADED)) - trace_fun("CAP_FEEDERLOADED\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_TIMEDATE)) - trace_fun("CAP_TIMEDATE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_SUPPORTEDCAPS)) - trace_fun("CAP_SUPPORTEDCAPS\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_EXTENDEDCAPS)) - trace_fun("CAP_EXTENDEDCAPS\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_AUTOFEED)) - trace_fun("CAP_AUTOFEED\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_CLEARPAGE)) - trace_fun("CAP_CLEARPAGE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_FEEDPAGE)) - trace_fun("CAP_FEEDPAGE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_REWINDPAGE)) - trace_fun("CAP_REWINDPAGE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_INDICATORS)) - trace_fun("CAP_INDICATORS\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_SUPPORTEDCAPSEXT)) - trace_fun("CAP_SUPPORTEDCAPSEXT\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_PAPERDETECTABLE)) - trace_fun("CAP_PAPERDETECTABLE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_UICONTROLLABLE)) - trace_fun("CAP_UICONTROLLABLE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_DEVICEONLINE)) - trace_fun("CAP_DEVICEONLINE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_AUTOSCAN)) - trace_fun("CAP_AUTOSCAN\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_THUMBNAILSENABLED)) - trace_fun("CAP_THUMBNAILSENABLED\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_DUPLEX)) trace_fun("CAP_DUPLEX\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_DUPLEXENABLED)) - trace_fun("CAP_DUPLEXENABLED\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_ENABLEDSUIONLY)) - trace_fun("CAP_ENABLEDSUIONLY\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_CUSTOMDSDATA)) - trace_fun("CAP_CUSTOMDSDATA\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_ENDORSER)) - trace_fun("CAP_ENDORSER\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_JOBCONTROL)) - trace_fun("CAP_JOBCONTROL\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_ALARMS)) trace_fun("CAP_ALARMS\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_ALARMVOLUME)) - trace_fun("CAP_ALARMVOLUME\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_AUTOMATICCAPTURE)) - trace_fun("CAP_AUTOMATICCAPTURE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_TIMEBEFOREFIRSTCAPTURE)) - trace_fun("CAP_TIMEBEFOREFIRSTCAPTURE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_TIMEBETWEENCAPTURES)) - trace_fun("CAP_TIMEBETWEENCAPTURES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_CLEARBUFFERS)) - trace_fun("CAP_CLEARBUFFERS\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_MAXBATCHBUFFERS)) - trace_fun("CAP_MAXBATCHBUFFERS\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_DEVICETIMEDATE)) - trace_fun("CAP_DEVICETIMEDATE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_POWERSUPPLY)) - trace_fun("CAP_POWERSUPPLY\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_CAMERAPREVIEWUI)) - trace_fun("CAP_CAMERAPREVIEWUI\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_DEVICEEVENT)) - trace_fun("CAP_DEVICEEVENT\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_SERIALNUMBER)) - trace_fun("CAP_SERIALNUMBER\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_PRINTER)) trace_fun("CAP_PRINTER\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_PRINTERENABLED)) - trace_fun("CAP_PRINTERENABLED\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_PRINTERINDEX)) - trace_fun("CAP_PRINTERINDEX\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_PRINTERMODE)) - trace_fun("CAP_PRINTERMODE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_PRINTERSTRING)) - trace_fun("CAP_PRINTERSTRING\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_PRINTERSUFFIX)) - trace_fun("CAP_PRINTERSUFFIX\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_LANGUAGE)) - trace_fun("CAP_LANGUAGE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_FEEDERALIGNMENT)) - trace_fun("CAP_FEEDERALIGNMENT\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_FEEDERORDER)) - trace_fun("CAP_FEEDERORDER\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_REACQUIREALLOWED)) - trace_fun("CAP_REACQUIREALLOWED\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_BATTERYMINUTES)) - trace_fun("CAP_BATTERYMINUTES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(CAP_BATTERYPERCENTAGE)) - trace_fun("CAP_BATTERYPERCENTAGE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_AUTOBRIGHT)) - trace_fun("ICAP_AUTOBRIGHT\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_BRIGHTNESS)) - trace_fun("ICAP_BRIGHTNESS\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_CONTRAST)) - trace_fun("ICAP_CONTRAST\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_CUSTHALFTONE)) - trace_fun("ICAP_CUSTHALFTONE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_EXPOSURETIME)) - trace_fun("ICAP_EXPOSURETIME\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_FILTER)) trace_fun("ICAP_FILTER\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_FLASHUSED)) - trace_fun("ICAP_FLASHUSED\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_GAMMA)) trace_fun("ICAP_GAMMA\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_HALFTONES)) - trace_fun("ICAP_HALFTONES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_HIGHLIGHT)) - trace_fun("ICAP_HIGHLIGHT\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_IMAGEFILEFORMAT)) - trace_fun("ICAP_IMAGEFILEFORMAT\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_LAMPSTATE)) - trace_fun("ICAP_LAMPSTATE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_LIGHTSOURCE)) - trace_fun("ICAP_LIGHTSOURCE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_ORIENTATION)) - trace_fun("ICAP_ORIENTATION\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_PHYSICALWIDTH)) - trace_fun("ICAP_PHYSICALWIDTH\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_PHYSICALHEIGHT)) - trace_fun("ICAP_PHYSICALHEIGHT\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_SHADOW)) trace_fun("ICAP_SHADOW\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_FRAMES)) trace_fun("ICAP_FRAMES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_XNATIVERESOLUTION)) - trace_fun("ICAP_XNATIVERESOLUTION\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_YNATIVERESOLUTION)) - trace_fun("ICAP_YNATIVERESOLUTION\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_XRESOLUTION)) - trace_fun("ICAP_XRESOLUTION\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_YRESOLUTION)) - trace_fun("ICAP_YRESOLUTION\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_MAXFRAMES)) - trace_fun("ICAP_MAXFRAMES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_TILES)) trace_fun("ICAP_TILES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_BITORDER)) - trace_fun("ICAP_BITORDER\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_CCITTKFACTOR)) - trace_fun("ICAP_CCITTKFACTOR\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_LIGHTPATH)) - trace_fun("ICAP_LIGHTPATH\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_PIXELFLAVOR)) - trace_fun("ICAP_PIXELFLAVOR\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_PLANARCHUNKY)) - trace_fun("ICAP_PLANARCHUNKY\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_ROTATION)) - trace_fun("ICAP_ROTATION\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_SUPPORTEDSIZES)) - trace_fun("ICAP_SUPPORTEDSIZES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_THRESHOLD)) - trace_fun("ICAP_THRESHOLD\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_XSCALING)) - trace_fun("ICAP_XSCALING\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_YSCALING)) - trace_fun("ICAP_YSCALING\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_BITORDERCODES)) - trace_fun("ICAP_BITORDERCODES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_PIXELFLAVORCODES)) - trace_fun("ICAP_PIXELFLAVORCODES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_JPEGPIXELTYPE)) - trace_fun("ICAP_JPEGPIXELTYPE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_TIMEFILL)) - trace_fun("ICAP_TIMEFILL\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_BITDEPTH)) - trace_fun("ICAP_BITDEPTH\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_BITDEPTHREDUCTION)) - trace_fun("ICAP_BITDEPTHREDUCTION\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_UNDEFINEDIMAGESIZE)) - trace_fun("ICAP_UNDEFINEDIMAGESIZE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_IMAGEDATASET)) - trace_fun("ICAP_IMAGEDATASET\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_EXTIMAGEINFO)) - trace_fun("ICAP_EXTIMAGEINFO\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_MINIMUMHEIGHT)) - trace_fun("ICAP_MINIMUMHEIGHT\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_MINIMUMWIDTH)) - trace_fun("ICAP_MINIMUMWIDTH\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_FLIPROTATION)) - trace_fun("ICAP_FLIPROTATION\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_BARCODEDETECTIONENABLED)) - trace_fun("ICAP_BARCODEDETECTIONENABLED\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_SUPPORTEDBARCODETYPES)) - trace_fun("ICAP_SUPPORTEDBARCODETYPES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_BARCODEMAXSEARCHPRIORITIES)) - trace_fun("ICAP_BARCODEMAXSEARCHPRIORITIES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_BARCODESEARCHPRIORITIES)) - trace_fun("ICAP_BARCODESEARCHPRIORITIES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_BARCODESEARCHMODE)) - trace_fun("ICAP_BARCODESEARCHMODE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_BARCODEMAXRETRIES)) - trace_fun("ICAP_BARCODEMAXRETRIES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_BARCODETIMEOUT)) - trace_fun("ICAP_BARCODETIMEOUT\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_ZOOMFACTOR)) - trace_fun("ICAP_ZOOMFACTOR\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_PATCHCODEDETECTIONENABLED)) - trace_fun("ICAP_PATCHCODEDETECTIONENABLED\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_SUPPORTEDPATCHCODETYPES)) - trace_fun("ICAP_SUPPORTEDPATCHCODETYPES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_PATCHCODEMAXSEARCHPRIORITIES)) - trace_fun("ICAP_PATCHCODEMAXSEARCHPRIORITIES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_PATCHCODESEARCHPRIORITIES)) - trace_fun("ICAP_PATCHCODESEARCHPRIORITIES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_PATCHCODESEARCHMODE)) - trace_fun("ICAP_PATCHCODESEARCHMODE\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_PATCHCODEMAXRETRIES)) - trace_fun("ICAP_PATCHCODEMAXRETRIES\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_PATCHCODETIMEOUT)) - trace_fun("ICAP_PATCHCODETIMEOUT\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_FLASHUSED2)) - trace_fun("ICAP_FLASHUSED2\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_IMAGEFILTER)) - trace_fun("ICAP_IMAGEFILTER\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_NOISEFILTER)) - trace_fun("ICAP_NOISEFILTER\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_OVERSCAN)) - trace_fun("ICAP_OVERSCAN\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_AUTOMATICBORDERDETECTION)) - trace_fun("ICAP_AUTOMATICBORDERDETECTION\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_AUTOMATICDESKEW)) - trace_fun("ICAP_AUTOMATICDESKEW\n"); - if (TTWAIN_IsCapSupportedTW_INT16(ICAP_AUTOMATICROTATE)) - trace_fun("ICAP_AUTOMATICROTATE\n"); - trace_fun("end-of-list\n"); - } - /*---------------------------------------------------------------------------*/ - /*---------------------------------------------------------------------------*/ - void TTWAIN_SetTwainUsage(TTWAIN_USAGE_MODE um) { - TTwainData.transferInfo.usageMode = um; - } - /*---------------------------------------------------------------------------*/ - extern void registerTwainCallback(); - - void TTWAIN_SetOnDoneCallback(TTWAIN_ONDONE_CB * proc, void *arg) { - TTwainData.callback.onDoneCb = proc; - TTwainData.callback.onDoneArg = arg; -#ifdef MACOSX - registerTwainCallback(); -#endif - } - /*---------------------------------------------------------------------------*/ - void TTWAIN_SetOnErrorCallback(TTWAIN_ONERROR_CB * proc, void *arg) { - TTwainData.callback.onErrorCb = proc; - TTwainData.callback.onErrorArg = arg; - } -/*---------------------------------------------------------------------------*/ - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_util.h b/toonz/sources/common/twain/ttwain_util.h deleted file mode 100644 index a97433f7..00000000 --- a/toonz/sources/common/twain/ttwain_util.h +++ /dev/null @@ -1,134 +0,0 @@ -#pragma once - -#ifndef __TTWAIN_UTIL_H__ -#define __TTWAIN_UTIL_H__ - -#include "ttwain.h" - -#undef TNZAPI -#ifdef TNZ_IS_DEVICELIB -#define TNZ_EXPORT_API -#else -#define TNZ_IMPORT_API -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -int TTWAIN_IsAvailable(void); -void TTWAIN_SetAvailable(TWAINAVAILABLE status); -char *TTWAIN_GetLastError(TUINT32 *rc, TUINT32 *cc); - -int TTWAIN_GetResolution(float *min, float *max, float *step, float *def); -int TTWAIN_GetOpticalResolution(float *min, float *max, float *step, - float *def); - -int TTWAIN_GetBrightness(float *min, float *max, float *step, float *def); -int TTWAIN_GetContrast(float *min, float *max, float *step, float *def); -int TTWAIN_GetThreshold(float *min, float *max, float *step, float *def); - -int TTWAIN_GetPhysicalWidthWAdf(float *width); -int TTWAIN_GetPhysicalHeightWAdf(float *height); - -int TTWAIN_GetMinimumWidthWAdf(float *width); -int TTWAIN_GetMinimumHeightWAdf(float *height); - -int TTWAIN_GetPhysicalWidthWoAdf(float *width); -int TTWAIN_GetPhysicalHeightWoAdf(float *height); - -int TTWAIN_GetMinimumWidthWoAdf(float *width); -int TTWAIN_GetMinimumHeightWoAdf(float *height); - -int TTWAIN_SupportsPixelType(TTWAIN_PIXTYPE pix); -int TTWAIN_SupportsFeeder(void); -int TTWAIN_SupportsCompressionType(TW_UINT16 comprType); - -int TTWAIN_GetSupportedCaps(void); -int TTWAIN_GetFeeder(void); -int TTWAIN_IsFeederLoaded(void); -/* this function should return the current value */ -int TTWAIN_GetCurrentPixelType(TTWAIN_PIXTYPE *pixType); -/* */ - -int TTWAIN_IsCapResolutionSupported(void); -int TTWAIN_IsCapOpticalResolutionSupported(void); -int TTWAIN_IsCapBrightnessSupported(void); -int TTWAIN_IsCapContrastSupported(void); -int TTWAIN_IsCapThresholdSupported(void); -int TTWAIN_IsCapPhysicalWidthSupported(void); -int TTWAIN_IsCapPhysicalHeightSupported(void); -int TTWAIN_IsCapMinimumWidthSupported(void); -int TTWAIN_IsCapMinimumHeightSupported(void); -int TTWAIN_IsCapPixelTypeSupported(void); -int TTWAIN_IsCapFeederSupported(void); -int TTWAIN_IsCapImageLayoutSupported(void); -int TTWAIN_IsCapOrientationSupported(void); -int TTWAIN_IsCapDeviceOnLineSupported(void); -int TTWAIN_IsCapBitDepthSupported(void); -int TTWAIN_IsCapBitOrderSupported(void); -int TTWAIN_IsCapCompressionSupported(void); - -int TTWAIN_SetResolution(float resolution); -int TTWAIN_SetContrast(float contrast); -int TTWAIN_SetBrightness(float brightness); -int TTWAIN_SetThreshold(float threshold); - -int TTWAIN_SetXScaling(float scale); -int TTWAIN_SetYScaling(float scale); - -int TTWAIN_SetPixelType(TTWAIN_PIXTYPE pixtype); -int TTWAIN_SetBitDepth(USHORT bitDepth); -int TTWAIN_SetBitOrder(TTWAIN_BITORDER bitOrder); - -int TTWAIN_SetImageLayout(float L, float T, float R, float B); -int TTWAIN_SetOrientation(USHORT orientation); - -int TTWAIN_SetFeeder(int status); /* TRUE->enabled */ -int TTWAIN_SetPage(void); - -void TTWAIN_DumpCapabilities(void (*trace_fun)(const char *fmt, ...)); - -/* USER INTERFACE */ -int TTWAIN_HasControllableUI(void); -/* Return 1 if source claims UI can be hidden (see SetUIStatus above) - Return 0 if source says UI *cannot* be hidden - Return -1 if source (pre TWAIN 1.6) cannot answer the question. */ -int TTWAIN_GetUIStatus(void); -void TTWAIN_SetUIStatus(int status); - -int TTWAIN_IsDeviceOnLine(void); /* -1 unknown, 0 no, 1 yes */ -/* info about the twain driver */ -char *TTWAIN_GetManufacturer(void); /* */ -char *TTWAIN_GetProductFamily(void); /* return an internal static var*/ -char *TTWAIN_GetProductName(void); /* don't free ret. value */ -char *TTWAIN_GetVersion(void); /* */ -char *TTWAIN_GetTwainVersion(void); /* */ - -int TTWAIN_Native2Raster(void *handle, void *the_ras, int *lx, int *ly); - -int TTWAIN_SetXferMech(TTWAIN_TRANSFER_MECH mech, void *ptr, TUINT32 size, - int preferredLx, int preferredLy, - TUINT32 numberOfImages); -/* NATIVE BUFFERED FILE -mech the transfer mechanism -ptr 0 memory buffer ?Not Impl. filename ? -size 0 size of the buffer ?Not Impl.? -preferredLx lx lx ?Not Impl.? lx? -preferredLy ly ly ?Not Impl.? ly? -numberOfImages 1,2,.... or -1 for all in the ADF -*/ -#endif - -#ifdef NOTES -here -/* The XScaling cap. should be negotiated before the YScaling, this is because - some Sources may set the YScaling capability whenever XScaling capability - is set, to maintain a square aspect ratio for Applications that do not - bother to negotiate YScaling capability. (note from Twain Spec 1.9 draft) -*/ -#endif - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_utilM.c b/toonz/sources/common/twain/ttwain_utilM.c deleted file mode 100644 index 0c8febb5..00000000 --- a/toonz/sources/common/twain/ttwain_utilM.c +++ /dev/null @@ -1,21 +0,0 @@ - - -#include "ttwain_utilPD.h" -#include "ttwain.h" - -#ifdef __cplusplus -extern "C" { -#endif - -TW_HANDLE GLOBAL_LOCK(TW_HANDLE S) { - HLock(S); - return (TW_HANDLE)*S; -} - -int TTWAIN_Native2RasterPD(void *handle, void *the_ras, int *lx, int *ly) { - return 0; -} - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_utilP.h b/toonz/sources/common/twain/ttwain_utilP.h deleted file mode 100644 index 76110687..00000000 --- a/toonz/sources/common/twain/ttwain_utilP.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#ifndef __TTWAIN_UTILP_H__ -#define __TTWAIN_UTILP_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -int TTWAIN_NegotiateXferCount(TUINT32 nXfers); -int TTWAIN_InitSupportedCaps(void); -int TTWAIN_GetModalStatus(void); - -#ifdef __cplusplus -} -#endif - -#endif /*__TTWAIN_UTILP_H__*/ diff --git a/toonz/sources/common/twain/ttwain_utilPD.h b/toonz/sources/common/twain/ttwain_utilPD.h deleted file mode 100644 index 6abe2fe6..00000000 --- a/toonz/sources/common/twain/ttwain_utilPD.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#ifndef __TTWAIN_UTIL_PD_H__ -#define __TTWAIN_UTIL_PD_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -int TTWAIN_Native2RasterPD(void *handle, void *the_ras, int *lx, int *ly); - -#ifdef __cplusplus -} -#endif - -#endif /*__TTWAIN_UTIL_PD_H__*/ diff --git a/toonz/sources/common/twain/ttwain_utilW.c b/toonz/sources/common/twain/ttwain_utilW.c deleted file mode 100644 index 4c649f55..00000000 --- a/toonz/sources/common/twain/ttwain_utilW.c +++ /dev/null @@ -1,43 +0,0 @@ - - -#include -#include "assert.h" - -#include "ttwainP.h" -#include "ttwain_utilPD.h" -#include "ttwain_global_def.h" - -#ifdef __cplusplus -extern "C" { -#endif - -static int getColorCount(LPBITMAPINFOHEADER pbi) { - if (pbi->biSize == sizeof(BITMAPCOREHEADER)) { - LPBITMAPCOREHEADER lpbc = ((LPBITMAPCOREHEADER)pbi); - return 1 << lpbc->bcBitCount; - } else if (pbi->biClrUsed == 0) - return 0xFFF & (1 << pbi->biBitCount); - else - return (int)pbi->biClrUsed; -} -/*---------------------------------------------------------------------------*/ -static size_t BmiColorTableBytes(LPBITMAPINFOHEADER pbi) { - return getColorCount(pbi) * sizeof(RGBQUAD); -} -/*---------------------------------------------------------------------------*/ -static LPBYTE get_buffer(LPBITMAPINFOHEADER lpbi, int *iud) { - LPBYTE buf = (LPBYTE)lpbi + lpbi->biSize + BmiColorTableBytes(lpbi); - *iud = (lpbi->biHeight > 0); - return buf; -} -/*---------------------------------------------------------------------------*/ -#define PelsPerMeter2DPI(ppm) (((float)ppm * 2.54) / 100.0) -/*---------------------------------------------------------------------------*/ -int TTWAIN_Native2RasterPD(void *handle, void *the_ras, int *lx, int *ly) { - assert(!"DAFARE"); - return 1; -} - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_utilX.c b/toonz/sources/common/twain/ttwain_utilX.c deleted file mode 100644 index e28289dc..00000000 --- a/toonz/sources/common/twain/ttwain_utilX.c +++ /dev/null @@ -1,15 +0,0 @@ - - -#include "ttwain_utilPD.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int TTWAIN_Native2RasterPD(void *handle, void *the_ras, int *lx, int *ly) { - return 0; -} - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_win.c b/toonz/sources/common/twain/ttwain_win.c deleted file mode 100644 index 62774397..00000000 --- a/toonz/sources/common/twain/ttwain_win.c +++ /dev/null @@ -1,22 +0,0 @@ - - -#include "ttwain_win.h" -#include "ttwain_winPD.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void *TTWAIN_GetValidHwnd(void *hwnd) { return TTWAIN_GetValidHwndPD(hwnd); } - -int TTWAIN_EnableWindow(void *hwnd, int flag) { - return TTWAIN_EnableWindowPD(hwnd, flag); -} - -// static void TTWAIN_EmptyMessageQueue(void) { TTWAIN_EmptyMessageQueuePD(); } - -// static void TTWAIN_ModalEventLoop(void) { TTWAIN_ModalEventLoopPD(); } - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_win.h b/toonz/sources/common/twain/ttwain_win.h deleted file mode 100644 index 14c9bf46..00000000 --- a/toonz/sources/common/twain/ttwain_win.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#ifndef __TTWAIN_WIN_H__ -#define __TTWAIN_WIN_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -void *TTWAIN_GetValidHwnd(void *hwnd); -int TTWAIN_EnableWindow(void *hwnd, int flag); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/toonz/sources/common/twain/ttwain_winM.c b/toonz/sources/common/twain/ttwain_winM.c deleted file mode 100644 index 70ec5790..00000000 --- a/toonz/sources/common/twain/ttwain_winM.c +++ /dev/null @@ -1,225 +0,0 @@ - - -/*max@home*/ -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "ttwain_state.h" -#include "ttwainP.h" -//#define DEBUG -#ifndef _WIN32 -#define PRINTF(args...) -#else -#define PRINTF -#endif -#if 1 - -extern int TTWAIN_MessageHook(void *lpmsg); - -OSErr CPSSetProcessName(ProcessSerialNumber *psn, char *processname); -OSErr CPSEnableForegroundOperation(ProcessSerialNumber *psn, UInt32 _arg2, - UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); - -int ScanDone = 0; - -void setupUI(void); - -/*---------------------------------------------------------------------------*/ - -void *TTWAIN_GetValidHwndPD(void *hwnd) { - setupUI(); - return 0; -} - -/*---------------------------------------------------------------------------*/ - -int TTWAIN_EnableWindowPD(void *hwnd, int flag) { - printf("%s\n", __PRETTY_FUNCTION__); - return 1; -} - -/*---------------------------------------------------------------------------*/ - -static int CallbackRegistered = false; - -void unregisterTwainCallback(void) { - printf("unregistering\n"); - CallbackRegistered = 0; -} - -/*---------------------------------------------------------------------------*/ - -TW_UINT16 twainCallback(pTW_IDENTITY pOrigin, pTW_IDENTITY pDest, TW_UINT32 DG, - TW_UINT16 DAT, TW_UINT16 MSG, TW_MEMREF pData) { - PRINTF("%s msg=0x%x\n", __PRETTY_FUNCTION__, MSG); - TTWAIN_MessageHook((void *)MSG); - return TWRC_SUCCESS; -} - -/*---------------------------------------------------------------------------*/ - -int exitTwainSession(void) { -/* -EventQueueRef q = GetCurrentEventQueue(); -printf("flushing event queue\n"); -FlushEventQueue(q); -*/ -#ifdef __i386 - /*At this time the HP Scan Pro DS (OSX on i386) need at least 1 sec to process -closeUI msg -If we are too fast exiting from the application loop, the msg stay in the -queue and it will be processed the next time we open the ui !!! -Flusing the queue (see above) doesn't work, because is possible that we are -too fast purging the queue. -1 sec seems to be ok -2 sec is safe :) -*/ - sleep(2); -#endif - printf("calling QuitApplicationEventLoop\n"); - // QuitApplicationEventLoop(); - - unregisterTwainCallback(); - return 0; -} - -/*---------------------------------------------------------------------------*/ - -static void myEventLoopTimer() { - printf("my event loop timer ScanDone = %d\n", ScanDone); - // if (ScanDone) - // QuitApplicationEventLoop (); -} - -/*---------------------------------------------------------------------------*/ - -void setupUI(void) { - ProcessSerialNumber psn; - - GetCurrentProcess(&psn); - - /* Need to do some magic here to get the UI to work */ - CPSEnableForegroundOperation(&psn, 0x03, 0x3C, 0x2C, 0x1103); - - SetFrontProcess(&psn); -#ifndef HAVE_DOCK_TILE -/* We end up with the ugly console dock icon; let's override it */ -/*char *iconfile = "/tmp/image.png"; - CFURLRef url = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault, - (UInt8 *)iconfile, - strlen (iconfile), - FALSE); - - CGDataProviderRef png = CGDataProviderCreateWithURL (url); - CGImageRef icon = CGImageCreateWithPNGDataProvider (png, NULL, TRUE, - kCGRenderingIntentDefault); - - /* Voodoo magic fix inspired by java_swt launcher */ -/* Without this the icon setting doesn't work about half the time. */ -// CGrafPtr p = BeginQDContextForApplicationDockTile(); -// EndQDContextForApplicationDockTile(p); - -// SetApplicationDockTileImage (icon); -#else - int numComponents = 4; - int bitsPerPixelChannel = 8; - int totalBitsPerPixel = bitsPerPixelChannel * numComponents; - int w = 32; - int h = 32; - char *buffer[w * h * numComponents]; - CGContextRef context; - CGDataProviderRef provider; - CGColorSpaceRef colorSpace; - CGImageRef image; - int bytesPerRow = w * numComponents; - context = BeginCGContextForApplicationDockTile(); - provider = CGDataProviderCreateWithData(0, buffer, (bytesPerRow * h), 0); - colorSpace = CGColorSpaceCreateDeviceRGB(); - image = CGImageCreate(w, h, bitsPerPixelChannel, totalBitsPerPixel, - bytesPerRow, colorSpace, kCGImageAlphaFirst, provider, - 0, 0, kCGRenderingIntentDefault); - CGDataProviderRelease(provider); - CGColorSpaceRelease(colorSpace); - SetApplicationDockTileImage(image); - CGContextFlush(context); - CGImageRelease(image); - EndCGContextForApplicationDockTile(context); -#endif -} - -/*---------------------------------------------------------------------------*/ - -void registerTwainCallback(void) { - if (TTWAIN_GetState() < TWAIN_SOURCE_OPEN) { - PRINTF("%s too early!, don't register\n", __FUNCTION__); - CallbackRegistered = 0; - return; - } - - if (TTWAIN_GetState() != 4) { - PRINTF("%s state != 4, don't register\n", __FUNCTION__); - CallbackRegistered = 0; - return; - } - - if (!CallbackRegistered) { - int rc = 0; - TW_CALLBACK callback; - - PRINTF("%s registering\n", __FUNCTION__); - - /* We need to set up our callback to receive messages */ - callback.CallBackProc = (TW_MEMREF)twainCallback; - callback.RefCon = 0; /* user data */ - callback.Message = 0; - printf("registering\n"); - /* -processed = TTWAIN_DS(DG_CONTROL, DAT_CALLBACK, MSG_REGISTER_CALLBACK, -(TW_MEMREF) &callback); -*/ - - rc = TTwainData.resultCode = - (*TTwainData.DSM_Entry)(&TTwainData.appId, 0, DG_CONTROL, DAT_CALLBACK, - MSG_REGISTER_CALLBACK, (TW_MEMREF)&callback); - - // NSRunLoop* runLoop = [NSRunLoop currentRunLoop]; - - // EventLoopTimerRef timer; - /*OSStatus err; - -// Set this up to run once the event loop is started -err = InstallEventLoopTimer (GetMainEventLoop (), - 0, 0, // Immediately, once only - NewEventLoopTimerUPP (myEventLoopTimer), - 0, &timer);*/ - CallbackRegistered = 1; - } else { - PRINTF("%s already registered!, don't register\n", __FUNCTION__); - } -} - -/*---------------------------------------------------------------------------*/ - -void TTWAIN_EmptyMessageQueuePD(void) { - ScanDone = 0; - registerTwainCallback(); -} - -/*---------------------------------------------------------------------------*/ - -void TTWAIN_ModalEventLoopPD(void) { - printf("%s\n", __PRETTY_FUNCTION__); - registerTwainCallback(); - // RunApplicationEventLoop(); - return; - - TTwainData.breakModalLoop = FALSE; -} - -#endif - -#ifdef __cplusplus -} -#endif diff --git a/toonz/sources/common/twain/ttwain_winPD.h b/toonz/sources/common/twain/ttwain_winPD.h deleted file mode 100644 index 156cf49e..00000000 --- a/toonz/sources/common/twain/ttwain_winPD.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#ifndef __TTWAIN_WIN_PD_H__ -#define __TTWAIN_WIN_PD_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -void *TTWAIN_GetValidHwndPD(void *hwnd); -int TTWAIN_EnableWindowPD(void *hwnd, int flag); -void TTWAIN_EmptyMessageQueuePD(void); -void TTWAIN_ModalEventLoopPD(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/toonz/sources/common/twain/ttwain_winW.c b/toonz/sources/common/twain/ttwain_winW.c deleted file mode 100644 index ed789b02..00000000 --- a/toonz/sources/common/twain/ttwain_winW.c +++ /dev/null @@ -1,95 +0,0 @@ - - -#include -#include -#include "ttwain_win.h" -#include "ttwain_winPD.h" -#include "ttwain_state.h" -#include "ttwain_error.h" - -#define HINSTLIB0 0 -static HWND Dummy = 0; /* proxy window */ - -extern int TTWAIN_MessageHook(void *lpmsg); - -static HWND CreateDummyWindow(void) { - HWND hwnd; - hwnd = CreateWindow("STATIC", // class - "Acquire Dummy", // title - WS_POPUPWINDOW, // style - CW_USEDEFAULT, CW_USEDEFAULT, // x, y - CW_USEDEFAULT, CW_USEDEFAULT, // width, height - HWND_DESKTOP, // parent window - NULL, // hmenu - HINSTLIB0, // hinst - NULL); // lpvparam - return hwnd; -} -/*---------------------------------------------------------------------------*/ -void *TTWAIN_GetValidHwndPD(void *_hwnd) -// Returns a valid window handle as follows: -// If hwnd is a valid window handle, hwnd is returned. -// Otherwise a proxy window handle is created and returned. -// Once created, a proxy window handle is destroyed when -// the source manager is unloaded. -// If hwnd is an invalid window handle (other than NULL) -// an error box is displayed. -{ - HWND hwnd = (HWND)_hwnd; - if (!IsWindow(hwnd)) { - if (hwnd != NULL) { - assert(!"Window handle is invalid"); - hwnd = NULL; - } - if (!Dummy) { - Dummy = CreateDummyWindow(); - if (!IsWindow(Dummy)) { - assert(!"Unable to create Dummy window"); - Dummy = NULL; - } - } - hwnd = Dummy; - } - return (void *)hwnd; -} -/*---------------------------------------------------------------------------*/ -void TTWAIN_EmptyMessageQueuePD(void) { - MSG msg; -#ifdef _DEBUG - OutputDebugString("EmptyMsgQ<"); -#endif - while (PeekMessage((LPMSG)&msg, NULL, 0, 0, PM_REMOVE)) { - if (!TTWAIN_MessageHook((LPMSG)&msg)) { - TranslateMessage((LPMSG)&msg); - DispatchMessage((LPMSG)&msg); -#ifdef _DEBUG - OutputDebugString("-"); -#endif - } else { -#ifdef _DEBUG - OutputDebugString("T"); -#endif - } - } -#ifdef _DEBUG - OutputDebugString(">\n"); -#endif -} - -void TTWAIN_ModalEventLoopPD(void) { - MSG msg; - // Clear global breakout flag - TTwainData.breakModalLoop = FALSE; - - while ((TTWAIN_GetState() >= TWAIN_SOURCE_ENABLED) && - !TTwainData.breakModalLoop && GetMessage((LPMSG)&msg, NULL, 0, 0)) { - if (!TTWAIN_MessageHook((LPMSG)&msg)) { - TranslateMessage((LPMSG)&msg); - DispatchMessage((LPMSG)&msg); - } - } // while - TTwainData.breakModalLoop = FALSE; -} -int TTWAIN_EnableWindowPD(void *hwnd, int flag) { - return EnableWindow(hwnd, flag); -} diff --git a/toonz/sources/common/twain/ttwain_winX.c b/toonz/sources/common/twain/ttwain_winX.c deleted file mode 100644 index 0846559c..00000000 --- a/toonz/sources/common/twain/ttwain_winX.c +++ /dev/null @@ -1,12 +0,0 @@ - - -#include "ttwain_winPD.h" - -void *TTWAIN_GetValidHwndPD(void *hwnd) { return 0; } -/*---------------------------------------------------------------------------*/ -int TTWAIN_EnableWindowPD(void *hwnd, int flag) { return 0; } -/*---------------------------------------------------------------------------*/ -void TTWAIN_EmptyMessageQueuePD(void) { return; } -/*---------------------------------------------------------------------------*/ -void TTWAIN_ModalEventLoopPD(void) { return; } -/*---------------------------------------------------------------------------*/ diff --git a/toonz/sources/common/twain/twain.h b/toonz/sources/common/twain/twain.h deleted file mode 100644 index 1bfe9d50..00000000 --- a/toonz/sources/common/twain/twain.h +++ /dev/null @@ -1,2223 +0,0 @@ -#pragma once - -/* ======================================================================== *\ - - 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 © 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 © 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 -\* ======================================================================== */ - -#ifndef TWAIN -#define TWAIN - -/**************************************************************************** - * TWAIN Version * - ****************************************************************************/ -#define TWON_PROTOCOLMINOR 1 /* Changed for Version 2.1 */ -#define TWON_PROTOCOLMAJOR 2 - -/**************************************************************************** - * Platform Dependent Definitions and Typedefs * - ****************************************************************************/ - -#ifdef LINUX -#include -#endif - -/* 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 - -/* Apple Compiler (which is GNU now) */ -#elif defined(__APPLE__) -#define TWH_CMP_XCODE -#define TWH_32BIT - -/* 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 - -/* Win32 and Win64 systems */ -#if defined(TWH_CMP_MSC) | defined(TWH_CMP_BORLAND) -#include -typedef HANDLE TW_HANDLE; -typedef LPVOID TW_MEMREF; -typedef UINT_PTR TW_UINTPTR; - -/* MacOS/X... */ -#elif defined(TWH_CMP_XCODE) -#include -#define PASCAL pascal -#define FAR -typedef Handle TW_HANDLE; -typedef char *TW_MEMREF; - -#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) -#pragma pack(push, before_twain) -#pragma pack(2) -#elif defined(TWH_CMP_BORLAND) -#pragma option -a2 -#elif defined(TWH_CMP_XCODE) -#if PRAGMA_STRUCT_ALIGN -#pragma options align = mac68k -#elif PRAGMA_STRUCT_PACKPUSH -#pragma pack(push, 2) -#elif PRAGMA_STRUCT_PACK -#pragma pack(2) -#endif -#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. */ -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; - -/* Numeric types. */ -typedef char TW_INT8, FAR *pTW_INT8; -typedef short TW_INT16, FAR *pTW_INT16; -typedef long TW_INT32, FAR *pTW_INT32; -typedef unsigned char TW_UINT8, FAR *pTW_UINT8; -typedef unsigned short TW_UINT16, FAR *pTW_UINT16; -typedef unsigned long TW_UINT32, FAR *pTW_UINT32; -typedef unsigned short TW_BOOL, FAR *pTW_BOOL; - -/**************************************************************************** - * Structure Definitions * - ****************************************************************************/ - -/* Fixed point structure type. */ -typedef struct { - TW_INT16 Whole; /* maintains the sign */ - TW_UINT16 Frac; -} TW_FIX32, FAR *pTW_FIX32; - -/* No DAT. 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; - -/* No DAT needed. */ -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; /* if =0 use the gamma */ -} TW_DECODEFUNCTION, FAR *pTW_DECODEFUNCTION; - -/* No DAT needed. */ -typedef struct { - TW_DECODEFUNCTION Decode[3]; - TW_FIX32 Mix[3][3]; -} TW_TRANSFORMSTAGE, FAR *pTW_TRANSFORMSTAGE; - -/* TWON_ARRAY. Container for array of values (a simplified TW_ENUMERATION) */ -typedef struct { - TW_UINT16 ItemType; - TW_UINT32 NumItems; /* How many items in ItemList */ - TW_UINT8 ItemList[1]; /* Array of ItemType values starts here */ -} TW_ARRAY, FAR *pTW_ARRAY; - -/* DAT_AUDIOINFO, information about audio data */ -typedef struct { - TW_STR255 Name; /* name of audio data */ - TW_UINT32 Reserved; /* reserved space */ -} TW_AUDIOINFO, FAR *pTW_AUDIOINFO; - -/* TW_CALLBACK, used to register callbacks Added 2.0 */ -typedef struct { - TW_MEMREF CallBackProc; - TW_UINT32 RefCon; - TW_INT16 Message; -} TW_CALLBACK, FAR *pTW_CALLBACK; - -/* DAT_CAPABILITY. Used by application to get/set capability from/in a data - * source. */ -typedef struct { - TW_UINT16 Cap; /* id of capability to set or get, e.g. CAP_BRIGHTNESS */ - TW_UINT16 ConType; /* TWON_ONEVALUE, _RANGE, _ENUMERATION or _ARRAY */ - TW_HANDLE hContainer; /* Handle to container of type Dat */ -} TW_CAPABILITY, FAR *pTW_CAPABILITY; - -/* No DAT needed. */ -typedef struct { - TW_FIX32 X; - TW_FIX32 Y; - TW_FIX32 Z; -} TW_CIEPOINT, FAR *pTW_CIEPOINT; - -/* DAT_CIECOLOR. */ -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; - -typedef struct { - TW_UINT32 InfoLength; /* Length of Information in bytes. */ - TW_HANDLE hData; /* Place holder for data, DS Allocates */ -} TW_CUSTOMDSDATA, FAR *pTW_CUSTOMDSDATA; - -/* DAT_DEVICEEVENT, information about events */ -typedef struct { - TW_UINT32 Event; /* One of the TWDE_xxxx values. */ - TW_STR255 DeviceName; /* The name of the device that generated the event */ - TW_UINT32 BatteryMinutes; /* Battery Minutes Remaining */ - TW_INT16 BatteryPercentage; /* Battery Percentage Remaining */ - TW_INT32 PowerSupply; /* Power Supply */ - TW_FIX32 XResolution; /* Resolution */ - TW_FIX32 YResolution; /* Resolution */ - TW_UINT32 FlashUsed2; /* Flash Used2 */ - TW_UINT32 AutomaticCapture; /* Automatic Capture */ - TW_UINT32 TimeBeforeFirstCapture; /* Automatic Capture */ - TW_UINT32 TimeBetweenCaptures; /* Automatic Capture */ -} TW_DEVICEEVENT, FAR *pTW_DEVICEEVENT; - -/* No DAT needed. */ -typedef struct { - TW_UINT8 Index; /* Value used to index into the color table. */ - TW_UINT8 Channel1; /* First tri-stimulus value (e.g Red) */ - TW_UINT8 Channel2; /* Second tri-stimulus value (e.g Green) */ - TW_UINT8 Channel3; /* Third tri-stimulus value (e.g Blue) */ -} TW_ELEMENT8, FAR *pTW_ELEMENT8; - -/* TWON_ENUMERATION. Container for a collection of values. */ -typedef struct { - TW_UINT16 ItemType; - TW_UINT32 NumItems; /* How many items in ItemList */ - TW_UINT32 CurrentIndex; /* Current value is in ItemList[CurrentIndex] */ - TW_UINT32 DefaultIndex; /* Powerup value is in ItemList[DefaultIndex] */ - TW_UINT8 ItemList[1]; /* Array of ItemType values starts here */ -} TW_ENUMERATION, FAR *pTW_ENUMERATION; - -/* DAT_EVENT. For passing events down from the application to the DS. */ -typedef struct { - TW_MEMREF pEvent; /* Windows pMSG or Mac pEvent. */ - TW_UINT16 TWMessage; /* TW msg from data source, e.g. MSG_XFERREADY */ -} TW_EVENT, FAR *pTW_EVENT; - -typedef struct { - TW_UINT16 InfoID; - TW_UINT16 ItemType; - TW_UINT16 NumItems; - union { - TW_UINT16 CondCode; /* Depreciated, use ReturnCode. TWAIN 2.0 and older. */ - TW_UINT16 ReturnCode; /* TWAIN 2.1 and newer */ - }; - TW_UINTPTR Item; -} TW_INFO, FAR *pTW_INFO; - -typedef struct { - TW_UINT32 NumInfos; - TW_INFO Info[1]; -} TW_EXTIMAGEINFO, FAR *pTW_EXTIMAGEINFO; - -/* DAT_FILESYSTEM, information about TWAIN file system */ -typedef struct { - /* DG_CONTROL / DAT_FILESYSTEM / MSG_xxxx fields */ - TW_STR255 InputName; /* The name of the input or source file */ - TW_STR255 OutputName; /* The result of an operation or the name of a - destination file */ - TW_MEMREF - Context; /* Source specific data used to remember state information */ - /* DG_CONTROL / DAT_FILESYSTEM / MSG_DELETE field */ - int Recursive; /* recursively delete all sub-directories */ - /* DG_CONTROL / DAT_FILESYSTEM / MSG_GETINFO fields */ - TW_INT32 FileType; /* One of the TWFY_xxxx values */ - TW_UINT32 Size; /* Size of current FileType */ - TW_STR32 CreateTimeDate; /* creation date of the file */ - TW_STR32 ModifiedTimeDate; /* last date the file was modified */ - TW_UINT32 FreeSpace; /* bytes of free space on the current device */ - TW_INT32 NewImageSize; /* estimate of the amount of space a new image would - take up */ - TW_UINT32 NumberOfFiles; /* number of files, depends on FileType */ - TW_UINT32 NumberOfSnippets; /* number of audio snippets */ - TW_UINT32 DeviceGroupMask; /* used to group cameras (ex: front/rear bitonal, - front/rear grayscale...) */ - char Reserved[508]; /**/ -} TW_FILESYSTEM, FAR *pTW_FILESYSTEM; - -/* DAT_GRAYRESPONSE */ -typedef struct { - TW_ELEMENT8 Response[1]; -} TW_GRAYRESPONSE, FAR *pTW_GRAYRESPONSE; - -/* No DAT needed. Describes version of software currently running. */ -typedef struct { - TW_UINT16 MajorNum; /* Major revision number of the software. */ - TW_UINT16 MinorNum; /* Incremental revision number of the software. */ - TW_UINT16 Language; /* e.g. TWLG_SWISSFRENCH */ - TW_UINT16 Country; /* e.g. TWCY_SWITZERLAND */ - TW_STR32 Info; /* e.g. "1.0b3 Beta release" */ -} TW_VERSION, FAR *pTW_VERSION; - -/* DAT_IDENTITY. Identifies the program/library/code resource. */ -typedef struct { - TW_UINT32 Id; /* Unique number. In Windows, application hWnd */ - TW_VERSION Version; /* Identifies the piece of code */ - TW_UINT16 - ProtocolMajor; /* Application and DS must set to TWON_PROTOCOLMAJOR */ - TW_UINT16 - ProtocolMinor; /* Application and DS must set to TWON_PROTOCOLMINOR */ - TW_UINT32 SupportedGroups; /* Bit field OR combination of DG_ constants */ - TW_STR32 Manufacturer; /* Manufacturer name, e.g. "Hewlett-Packard" */ - TW_STR32 ProductFamily; /* Product family name, e.g. "ScanJet" */ - TW_STR32 ProductName; /* Product name, e.g. "ScanJet Plus" */ -} TW_IDENTITY, FAR *pTW_IDENTITY; - -/* DAT_IMAGEINFO. Application gets detailed image info from DS with this. */ -typedef struct { - TW_FIX32 XResolution; /* Resolution in the horizontal */ - TW_FIX32 YResolution; /* Resolution in the vertical */ - TW_INT32 ImageWidth; /* Columns in the image, -1 if unknown by DS*/ - TW_INT32 ImageLength; /* Rows in the image, -1 if unknown by DS */ - TW_INT16 SamplesPerPixel; /* Number of samples per pixel, 3 for RGB */ - TW_INT16 BitsPerSample[8]; /* Number of bits for each sample */ - TW_INT16 BitsPerPixel; /* Number of bits for each padded pixel */ - TW_BOOL Planar; /* True if Planar, False if chunky */ - TW_INT16 PixelType; /* How to interp data; photo interp (TWPT_) */ - TW_UINT16 Compression; /* How the data is compressed (TWCP_xxxx) */ -} TW_IMAGEINFO, FAR *pTW_IMAGEINFO; - -/* DAT_IMAGELAYOUT. Provides image layout information in current units. */ -typedef struct { - TW_FRAME Frame; /* Frame coords within larger document */ - TW_UINT32 DocumentNumber; - TW_UINT32 PageNumber; /* Reset when you go to next document */ - TW_UINT32 FrameNumber; /* Reset when you go to next page */ -} TW_IMAGELAYOUT, FAR *pTW_IMAGELAYOUT; - -/* No DAT needed. Used to manage memory buffers. */ -typedef struct { - TW_UINT32 Flags; /* Any combination of the TWMF_ constants. */ - TW_UINT32 Length; /* Number of bytes stored in buffer TheMem. */ - TW_MEMREF TheMem; /* Pointer or handle to the allocated memory buffer. */ -} TW_MEMORY, FAR *pTW_MEMORY; - -/* DAT_IMAGEMEMXFER. Used to pass image data (e.g. in strips) from DS to - * application.*/ -typedef struct { - TW_UINT16 Compression; /* How the data is compressed */ - TW_UINT32 BytesPerRow; /* Number of bytes in a row of data */ - TW_UINT32 Columns; /* How many columns */ - TW_UINT32 Rows; /* How many rows */ - TW_UINT32 XOffset; /* How far from the side of the image */ - TW_UINT32 YOffset; /* How far from the top of the image */ - TW_UINT32 BytesWritten; /* How many bytes written in Memory */ - TW_MEMORY Memory; /* Mem struct used to pass actual image data */ -} TW_IMAGEMEMXFER, FAR *pTW_IMAGEMEMXFER; - -/* Changed in 1.1: QuantTable, HuffmanDC, HuffmanAC TW_MEMREF -> TW_MEMORY */ -/* DAT_JPEGCOMPRESSION. Based on JPEG Draft International Std, ver 10918-1. */ -typedef struct { - TW_UINT16 ColorSpace; /* One of the TWPT_xxxx values */ - TW_UINT32 SubSampling; /* Two word "array" for subsampling values */ - TW_UINT16 NumComponents; /* Number of color components in image */ - TW_UINT16 RestartFrequency; /* Frequency of restart marker codes in MDU's */ - TW_UINT16 QuantMap[4]; /* Mapping of components to QuantTables */ - TW_MEMORY QuantTable[4]; /* Quantization tables */ - TW_UINT16 HuffmanMap[4]; /* Mapping of components to Huffman tables */ - TW_MEMORY HuffmanDC[2]; /* DC Huffman tables */ - TW_MEMORY HuffmanAC[2]; /* AC Huffman tables */ -} TW_JPEGCOMPRESSION, FAR *pTW_JPEGCOMPRESSION; - -/* TWON_ONEVALUE. Container for one value. */ -typedef struct { - TW_UINT16 ItemType; - TW_UINT32 Item; -} TW_ONEVALUE, FAR *pTW_ONEVALUE; - -/* DAT_PALETTE8. Color palette when TWPT_PALETTE pixels xfer'd in mem buf. */ -typedef struct { - TW_UINT16 NumColors; /* Number of colors in the color table. */ - TW_UINT16 PaletteType; /* TWPA_xxxx, specifies type of palette. */ - TW_ELEMENT8 Colors[256]; /* Array of palette values starts here. */ -} TW_PALETTE8, FAR *pTW_PALETTE8; - -/* DAT_PASSTHRU, device dependant data to pass through Data Source */ -typedef struct { - TW_MEMREF pCommand; /* Pointer to Command buffer */ - TW_UINT32 CommandBytes; /* Number of bytes in Command buffer */ - TW_INT32 Direction; /* One of the TWDR_xxxx values. Defines the direction of - data flow */ - TW_MEMREF pData; /* Pointer to Data buffer */ - TW_UINT32 DataBytes; /* Number of bytes in Data buffer */ - TW_UINT32 DataBytesXfered; /* Number of bytes successfully transferred */ -} TW_PASSTHRU, FAR *pTW_PASSTHRU; - -/* DAT_PENDINGXFERS. Used with MSG_ENDXFER to indicate additional data. */ -typedef struct { - TW_UINT16 Count; - union { - TW_UINT32 EOJ; - TW_UINT32 Reserved; - }; -} TW_PENDINGXFERS, FAR *pTW_PENDINGXFERS; - -/* TWON_RANGE. Container for a range of values. */ -typedef struct { - TW_UINT16 ItemType; - TW_UINT32 MinValue; /* Starting value in the range. */ - TW_UINT32 MaxValue; /* Final value in the range. */ - TW_UINT32 StepSize; /* Increment from MinValue to MaxValue. */ - TW_UINT32 DefaultValue; /* Power-up value. */ - TW_UINT32 CurrentValue; /* The value that is currently in effect. */ -} TW_RANGE, FAR *pTW_RANGE; - -/* DAT_RGBRESPONSE */ -typedef struct { - TW_ELEMENT8 Response[1]; -} TW_RGBRESPONSE, FAR *pTW_RGBRESPONSE; - -/* DAT_SETUPFILEXFER. Sets up DS to application data transfer via a file. */ -typedef struct { - TW_STR255 FileName; - TW_UINT16 Format; /* Any TWFF_ constant */ - TW_INT16 VRefNum; /* Used for Mac only */ -} TW_SETUPFILEXFER, FAR *pTW_SETUPFILEXFER; - -/* DAT_SETUPMEMXFER. Sets up DS to application data transfer via a memory - * buffer. */ -typedef struct { - TW_UINT32 MinBufSize; - TW_UINT32 MaxBufSize; - TW_UINT32 Preferred; -} TW_SETUPMEMXFER, FAR *pTW_SETUPMEMXFER; - -/* DAT_STATUS. Application gets detailed status info from a data source with - * this. */ -typedef struct { - TW_UINT16 ConditionCode; /* Any TWCC_ constant */ - union { - TW_UINT16 Data; /* output (TWAIN 2.1 and newer) This field contains - additional data. */ - TW_UINT16 Reserved; /* output (TWAIN 2.0 and older) */ - }; -} TW_STATUS, FAR *pTW_STATUS; - -/* DAT_STATUSUTF8. Application gets detailed UTF8 status info from a data source - * with this. Added 2.1 */ -typedef struct { - TW_STATUS Status; /* input TW_STATUS data received from a previous call to - DG_CONTROL / DAT_STATUS / MSG_GET. */ - TW_UINT32 Size; /* output Total number of bytes in the UTF8string, plus the - terminating NUL byte. This is not the same as the total - number of characters in the string. */ - TW_HANDLE - UTF8string; /* output TW_HANDLE to a UTF-8 encoded localized string (based - on TW_IDENTITY.Language or CAP_LANGUAGE). The Source - allocates it, the Application frees it. */ -} TW_STATUSUTF8, FAR *pTW_STATUSUTF8; - -/* DAT_USERINTERFACE. Coordinates UI between application and data source. */ -typedef struct { - TW_BOOL ShowUI; /* TRUE if DS should bring up its UI */ - TW_BOOL ModalUI; /* For Mac only - true if the DS's UI is modal */ - TW_HANDLE hParent; /* For windows only - Application window handle */ -} TW_USERINTERFACE, FAR *pTW_USERINTERFACE; - -/**************************************************************************** - * Generic Constants * - ****************************************************************************/ - -#define TWON_ARRAY 3 /* indicates TW_ARRAY container */ -#define TWON_ENUMERATION 4 /* indicates TW_ENUMERATION container */ -#define TWON_ONEVALUE 5 /* indicates TW_ONEVALUE container */ -#define TWON_RANGE 6 /* indicates TW_RANGE container */ - -#define TWON_ICONID 962 /* res Id of icon used in USERSELECT lbox */ -#define TWON_DSMID 461 /* res Id of the DSM version num resource */ -#define TWON_DSMCODEID 63 /* res Id of the Mac SM Code resource */ - -#define TWON_DONTCARE8 0xff -#define TWON_DONTCARE16 0xffff -#define TWON_DONTCARE32 0xffffffff - -/* Flags used in TW_MEMORY structure. */ -#define TWMF_APPOWNS 0x1 -#define TWMF_DSMOWNS 0x2 -#define TWMF_DSOWNS 0x4 -#define TWMF_POINTER 0x8 -#define TWMF_HANDLE 0x10 - -/* There are four containers used for capabilities negotiation: - * TWON_ONEVALUE, TWON_RANGE, TWON_ENUMERATION, TWON_ARRAY - * In each container structure ItemType can be TWTY_INT8, TWTY_INT16, etc. - * The kind of data stored in the container can be determined by doing - * DCItemSize[ItemType] where the following is defined in TWAIN glue code: - * DCItemSize[]= { sizeof(TW_INT8), - * sizeof(TW_INT16), - * etc. - * sizeof(TW_UINT32) }; - * - */ - -#define TWTY_INT8 0x0000 /* Means Item is a TW_INT8 */ -#define TWTY_INT16 0x0001 /* Means Item is a TW_INT16 */ -#define TWTY_INT32 0x0002 /* Means Item is a TW_INT32 */ - -#define TWTY_UINT8 0x0003 /* Means Item is a TW_UINT8 */ -#define TWTY_UINT16 0x0004 /* Means Item is a TW_UINT16 */ -#define TWTY_UINT32 0x0005 /* Means Item is a TW_UINT32 */ - -#define TWTY_BOOL 0x0006 /* Means Item is a TW_BOOL */ - -#define TWTY_FIX32 0x0007 /* Means Item is a TW_FIX32 */ - -#define TWTY_FRAME 0x0008 /* Means Item is a TW_FRAME */ - -#define TWTY_STR32 0x0009 /* Means Item is a TW_STR32 */ -#define TWTY_STR64 0x000a /* Means Item is a TW_STR64 */ -#define TWTY_STR128 0x000b /* Means Item is a TW_STR128 */ -#define TWTY_STR255 0x000c /* Means Item is a TW_STR255 */ -#define TWTY_HANDLE 0x000f /* Means Item is a TW_HANDLE */ - -/**************************************************************************** - * Capability Constants * - ****************************************************************************/ - -/* CAP_ALARMS values (AL_ means alarms) Added 1.8 */ -#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 Added 2.0 */ -#define TWAS_NONE 0 -#define TWAS_AUTO 1 -#define TWAS_CURRENT 2 - -/* TWEI_BARCODEROTATION values (BCOR_ means barcode rotation) Added 1.7 */ -#define TWBCOR_ROT0 0 -#define TWBCOR_ROT90 1 -#define TWBCOR_ROT180 2 -#define TWBCOR_ROT270 3 -#define TWBCOR_ROTX 4 - -/* ICAP_BARCODESEARCHMODE values (TWBD_ means search) */ -#define TWBD_HORZ 0 -#define TWBD_VERT 1 -#define TWBD_HORZVERT 2 -#define TWBD_VERTHORZ 3 - -/* ICAP_BITORDER values (BO_ means Bit Order) */ -#define TWBO_LSBFIRST 0 -#define TWBO_MSBFIRST 1 - -/* ICAP_AUTODISCARDBLANKPAGES values Added 2.0 */ -#define TWBP_DISABLE -2 -#define TWBP_AUTO -1 - -/* ICAP_BITDEPTHREDUCTION values (BR_ means Bitdepth Reduction) Added 1.5 */ -#define TWBR_THRESHOLD 0 -#define TWBR_HALFTONE 1 -#define TWBR_CUSTHALFTONE 2 -#define TWBR_DIFFUSION 3 - -/* ICAP_SUPPORTEDBARCODETYPES and TWEI_BARCODETYPE values Added 1.7 */ -#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 /* Added 1.8 */ -#define TWBT_2OF5MATRIX 14 /* Added 1.8 */ -#define TWBT_2OF5DATALOGIC 15 /* Added 1.8 */ -#define TWBT_2OF5IATA 16 /* Added 1.8 */ -#define TWBT_3OF9FULLASCII 17 /* Added 1.8 */ -#define TWBT_CODABARWITHSTARTSTOP 18 /* Added 1.8 */ -#define TWBT_MAXICODE 19 /* Added 1.8 */ - -/* ICAP_COMPRESSION values (CP_ means ComPression ) */ -#define TWCP_NONE 0 -#define TWCP_PACKBITS 1 -#define TWCP_GROUP31D 2 /* Follows CCITT spec (no End Of Line) */ -#define TWCP_GROUP31DEOL 3 /* Follows CCITT spec (has End Of Line) */ -#define TWCP_GROUP32D 4 /* Follows CCITT spec (use cap for K Factor) */ -#define TWCP_GROUP4 5 /* Follows CCITT spec */ -#define TWCP_JPEG 6 /* Use capability for more info */ -#define TWCP_LZW 7 /* Must license from Unisys and IBM to use */ -#define TWCP_JBIG 8 /* For Bitonal images -- Added 1.7 KHL */ -#define TWCP_PNG 9 /* Added 1.8 */ -#define TWCP_RLE4 10 /* Added 1.8 */ -#define TWCP_RLE8 11 /* Added 1.8 */ -#define TWCP_BITFIELDS 12 /* Added 1.8 */ - -/* CAP_CAMERASIDE and TWEI_PAGESIDE values (CS_ means camera side) Added 1.91 */ -#define TWCS_BOTH 0 -#define TWCS_TOP 1 -#define TWCS_BOTTOM 2 - -/* CAP_CLEARBUFFERS values (CB_ means clear buffers) */ -#define TWCB_AUTO 0 -#define TWCB_CLEAR 1 -#define TWCB_NOCLEAR 2 - -/* CAP_DEVICEEVENT values (DE_ means device event) */ -#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. Added 1.8 */ -#define TWDR_GET 1 -#define TWDR_SET 2 - -/* TWEI_DESKEWSTATUS values Added 1.7 */ -#define TWDSK_SUCCESS 0 -#define TWDSK_REPORTONLY 1 -#define TWDSK_FAIL 2 -#define TWDSK_DISABLED 3 - -/* CAP_DUPLEX values Added 1.7 */ -#define TWDX_NONE 0 -#define TWDX_1PASSDUPLEX 1 -#define TWDX_2PASSDUPLEX 2 - -/* CAP_FEEDERALIGNMENT values (FA_ means feeder alignment) */ -#define TWFA_NONE 0 -#define TWFA_LEFT 1 -#define TWFA_CENTER 2 -#define TWFA_RIGHT 3 - -/* ICAP_FEEDERTYPE */ -#define TWFE_GENERAL 0 -#define TWFE_PHOTO 1 - -/* ICAP_IMAGEFILEFORMAT values (FF_means File Format) */ -#define TWFF_TIFF 0 /* Tagged Image File Format */ -#define TWFF_PICT 1 /* Macintosh PICT */ -#define TWFF_BMP 2 /* Windows Bitmap */ -#define TWFF_XBM 3 /* X-Windows Bitmap */ -#define TWFF_JFIF 4 /* JPEG File Interchange Format */ -#define TWFF_FPX 5 /* Flash Pix */ -#define TWFF_TIFFMULTI 6 /* Multi-page tiff file */ -#define TWFF_PNG 7 -#define TWFF_SPIFF 8 -#define TWFF_EXIF 9 -#define TWFF_PDF 10 /* 1.91 NB: this is not PDF/A */ -#define TWFF_JP2 11 /* 1.91 */ -#define TWFF_JPX 13 /* 1.91 */ -#define TWFF_DEJAVU 14 /* 1.91 */ -#define TWFF_PDFA 15 /* 2.0 Adobe PDF/A, Version 1*/ -#define TWFF_PDFA2 16 /* 2.1 Adobe PDF/A, Version 2*/ - -/* ICAP_FLASHUSED2 values (FL_ means flash) */ -#define TWFL_NONE 0 -#define TWFL_OFF 1 -#define TWFL_ON 2 -#define TWFL_AUTO 3 -#define TWFL_REDEYE 4 - -/* CAP_FEEDERORDER values (FO_ means feeder order) */ -#define TWFO_FIRSTPAGEFIRST 0 -#define TWFO_LASTPAGEFIRST 1 - -/* CAP_FEEDERPOCKET */ -#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 (FR_ means flip rotation) */ -#define TWFR_BOOK 0 -#define TWFR_FANFOLD 1 - -/* ICAP_FILTER values (FT_ means Filter Type) */ -#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 (FY_ means file type) */ -#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 */ -#define TWIC_NONE 0 -#define TWIC_LINK 1 -#define TWIC_EMBED 2 - -/* ICAP_IMAGEFILTER values (IF_ means image filter) */ -#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 (IM_ means image merge) */ -#define TWIM_NONE 0 -#define TWIM_FRONTONTOP 1 -#define TWIM_FRONTONBOTTOM 2 -#define TWIM_FRONTONLEFT 3 -#define TWIM_FRONTONRIGHT 4 - -/* CAP_JOBCONTROL values Added 1.7 */ -#define TWJC_NONE 0 -#define TWJC_JSIC 1 -#define TWJC_JSIS 2 -#define TWJC_JSXC 3 -#define TWJC_JSXS 4 - -/* ICAP_JPEGQUALITY values (JQ_ means jpeg quality) */ -#define TWJQ_UNKNOWN -4 -#define TWJQ_LOW -3 -#define TWJQ_MEDIUM -2 -#define TWJQ_HIGH -1 - -/* ICAP_LIGHTPATH values (LP_ means Light Path) */ -#define TWLP_REFLECTIVE 0 -#define TWLP_TRANSMISSIVE 1 - -/* ICAP_LIGHTSOURCE values (LS_ means Light Source) */ -#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 (MD_ means Mag Type) Added 2.0 */ -#define TWMD_MICR 0 /* Added 2.0 */ -#define TWMD_RAW 1 /* added 2.1 */ -#define TWMD_INVALID 2 /* added 2.1 */ - -/* ICAP_NOISEFILTER values (NF_ means noise filter) */ -#define TWNF_NONE 0 -#define TWNF_AUTO 1 -#define TWNF_LONEPIXEL 2 -#define TWNF_MAJORITYRULE 3 - -/* ICAP_ORIENTATION values (OR_ means ORientation) */ -#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 /* 2.0 */ -#define TWOR_AUTOTEXT 5 /* 2.0 */ -#define TWOR_AUTOPICTURE 6 /* 2.0 */ - -/* ICAP_OVERSCAN values (OV_ means overscan) */ -#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 (PC_ means Planar/Chunky ) */ -#define TWPC_CHUNKY 0 -#define TWPC_PLANAR 1 - -/* TWEI_PATCHCODE values Added 1.7 */ -#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 (PF_ means Pixel Flavor) */ -#define TWPF_CHOCOLATE 0 /* zero pixel represents darkest shade */ -#define TWPF_VANILLA 1 /* zero pixel represents lightest shade */ - -/* CAP_PRINTERMODE values (PM_ means printer mode) */ -#define TWPM_SINGLESTRING 0 -#define TWPM_MULTISTRING 1 -#define TWPM_COMPOUNDSTRING 2 - -/* CAP_PRINTER values (PR_ means printer) */ -#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_POWERSUPPLY values (PS_ means power supply) */ -#define TWPS_EXTERNAL 0 -#define TWPS_BATTERY 1 - -/* ICAP_PIXELTYPE values (PT_ means Pixel Type) */ -#define TWPT_BW 0 /* Black and White */ -#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 /* 1.91 */ -#define TWPT_SCRGB 11 /* 1.91 */ -#define TWPT_INFRARED 16 /* 2.0 */ - -/* CAP_SEGMENTED values (SG_ means segmented) Added 1.91 */ -#define TWSG_NONE 0 -#define TWSG_AUTO 1 - -/* 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 -/* Added 1.5 */ -#define TWSS_A5 5 -#define TWSS_ISOB4 6 -#define TWSS_ISOB6 7 -/* Added 1.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 -/* Added 1.8 */ -#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 /* Added 2.1 */ - -/* ICAP_XFERMECH values (SX_ means Setup XFer) */ -#define TWSX_NATIVE 0 -#define TWSX_FILE 1 -#define TWSX_MEMORY 2 -#define TWSX_MEMFILE 4 /* added 1.91 */ - -/* 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 /* added 1.91 */ - -/**************************************************************************** - * Country Constants * - ****************************************************************************/ - -#define TWCY_AFGHANISTAN 1001 -#define TWCY_ALGERIA 213 -#define TWCY_AMERICANSAMOA 684 -#define TWCY_ANDORRA 033 -#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 005 -#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 -/* Added for 1.8 */ -#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 * - ****************************************************************************/ -/* Added for 1.8 */ -#define TWLG_USERLOCALE -1 -#define TWLG_DANISH 0 /* Danish */ -#define TWLG_DUTCH 1 /* Dutch */ -#define TWLG_ENGLISH 2 /* International English */ -#define TWLG_FRENCH_CANADIAN 3 /* French Canadian */ -#define TWLG_FINNISH 4 /* Finnish */ -#define TWLG_FRENCH 5 /* French */ -#define TWLG_GERMAN 6 /* German */ -#define TWLG_ICELANDIC 7 /* Icelandic */ -#define TWLG_ITALIAN 8 /* Italian */ -#define TWLG_NORWEGIAN 9 /* Norwegian */ -#define TWLG_PORTUGUESE 10 /* Portuguese */ -#define TWLG_SPANISH 11 /* Spanish */ -#define TWLG_SWEDISH 12 /* Swedish */ -#define TWLG_ENGLISH_USA 13 /* U.S. English */ -#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 /* United Arabic Emirates */ -#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 /* People's Republic of China */ -#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_DUTCH_BELGIAN 46 -#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_ESTONIAN 53 -#define TWLG_FAEROESE 54 -#define TWLG_FARSI 55 -#define TWLG_FRENCH_BELGIAN 56 -#define TWLG_FRENCH_LUXEMBOURG 57 -#define TWLG_FRENCH_SWISS 58 -#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_INDONESIAN 66 -#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_BOKMAL 73 -#define TWLG_NORWEGIAN_NYNORSK 74 -#define TWLG_POLISH 75 -#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_MEXICAN 82 -#define TWLG_SPANISH_MODERN 83 -#define TWLG_THAI 84 -#define TWLG_TURKISH 85 -#define TWLG_UKRANIAN 86 -/* More stuff added for 1.8 */ -#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 * - ****************************************************************************/ - -/* More Data Groups may be added in the future. - * Possible candidates include text, vector graphics, sound, etc. - * NOTE: Data Group constants must be powers of 2 as they are used - * as bitflags when Application asks DSM to present a list of DSs. - */ - -#define DG_CONTROL 0x0001L /* data pertaining to control */ -#define DG_IMAGE 0x0002L /* data pertaining to raster images */ -/* Added 1.8 */ -#define DG_AUDIO 0x0004L /* data pertaining to audio */ - -/* 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 /* added to the identity by the DSM */ -#define DF_APP2 \ - 0x20000000L /* Set by the App to indicate it would prefer to use DSM2 */ -#define DF_DS2 \ - 0x40000000L /* Set by the DS to indicate it would prefer to use DSM2 */ -#define DG_MASK 0xFFFFL /* all Data Groups limited to 16 bit. Added for 2.1 */ - -/**************************************************************************** - * * - ****************************************************************************/ -#define DAT_NULL 0x0000 /* No data or structure. */ -#define DAT_CUSTOMBASE 0x8000 /* Base of custom DATs. */ - -/* Data Argument Types for the DG_CONTROL Data Group. */ -#define DAT_CAPABILITY 0x0001 /* TW_CAPABILITY */ -#define DAT_EVENT 0x0002 /* TW_EVENT */ -#define DAT_IDENTITY 0x0003 /* TW_IDENTITY */ -#define DAT_PARENT 0x0004 /* TW_HANDLE, application win handle in Windows */ -#define DAT_PENDINGXFERS 0x0005 /* TW_PENDINGXFERS */ -#define DAT_SETUPMEMXFER 0x0006 /* TW_SETUPMEMXFER */ -#define DAT_SETUPFILEXFER 0x0007 /* TW_SETUPFILEXFER */ -#define DAT_STATUS 0x0008 /* TW_STATUS */ -#define DAT_USERINTERFACE 0x0009 /* TW_USERINTERFACE */ -#define DAT_XFERGROUP 0x000a /* TW_UINT32 */ -#define DAT_CUSTOMDSDATA 0x000c /* TW_CUSTOMDSDATA. */ -#define DAT_DEVICEEVENT 0x000d /* TW_DEVICEEVENT Added 1.8 */ -#define DAT_FILESYSTEM 0x000e /* TW_FILESYSTEM Added 1.8 */ -#define DAT_PASSTHRU 0x000f /* TW_PASSTHRU Added 1.8 */ -#define DAT_CALLBACK 0x0010 /* TW_CALLBACK Added 2.0 */ -#define DAT_STATUSUTF8 0x0011 /* TW_STATUSUTF8 Added 2.1 */ - -/* Data Argument Types for the DG_IMAGE Data Group. */ -#define DAT_IMAGEINFO 0x0101 /* TW_IMAGEINFO */ -#define DAT_IMAGELAYOUT 0x0102 /* TW_IMAGELAYOUT */ -#define DAT_IMAGEMEMXFER 0x0103 /* TW_IMAGEMEMXFER */ -#define DAT_IMAGENATIVEXFER 0x0104 /* TW_UINT32 loword is hDIB, PICHandle */ -#define DAT_IMAGEFILEXFER 0x0105 /* Null data */ -#define DAT_CIECOLOR 0x0106 /* TW_CIECOLOR */ -#define DAT_GRAYRESPONSE 0x0107 /* TW_GRAYRESPONSE */ -#define DAT_RGBRESPONSE 0x0108 /* TW_RGBRESPONSE */ -#define DAT_JPEGCOMPRESSION 0x0109 /* TW_JPEGCOMPRESSION */ -#define DAT_PALETTE8 0x010a /* TW_PALETTE8 */ -#define DAT_EXTIMAGEINFO 0x010b /* TW_EXTIMAGEINFO -- for 1.7 Spec. */ - -/* Data Argument Types for the DG_AUDIO Data Group. */ -#define DAT_AUDIOFILEXFER 0x0201 /* Null data Added 1.8 */ -#define DAT_AUDIOINFO 0x0202 /* TW_AUDIOINFO Added 1.8 */ -#define DAT_AUDIONATIVEXFER \ - 0x0203 /* TW_UINT32 handle to WAV, (AIFF Mac) Added 1.8 */ - -/* misplaced */ -/* TW_MEMORY Added 1.91 This Data Argument is misplaced but belongs to the - * DG_IMAGE Data Group */ -#define DAT_ICCPROFILE 0x0401 -/* TW_IMAGEMEMXFER Added 1.91 This Data Argument is misplaced but belongs to - * the DG_IMAGE Data Group */ -#define DAT_IMAGEMEMFILEXFER 0x0402 -/* TW_ENTRYPOINT Added 2.0 This Data Argument is misplaced but belongs to - * the DG_CONTROL Data Group */ -#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 /* Used in TW_EVENT structure */ -#define MSG_CUSTOMBASE 0x8000 /* Base of custom messages */ - -/* Generic messages may be used with any of several DATs. */ -#define MSG_GET 0x0001 /* Get one or more values */ -#define MSG_GETCURRENT 0x0002 /* Get current value */ -#define MSG_GETDEFAULT 0x0003 /* Get default (e.g. power up) value */ -#define MSG_GETFIRST 0x0004 /* Get first of a series of items, e.g. DSs */ -#define MSG_GETNEXT 0x0005 /* Iterate through a series of items. */ -#define MSG_SET 0x0006 /* Set one or more values */ -#define MSG_RESET 0x0007 /* Set current value to default value */ -#define MSG_QUERYSUPPORT 0x0008 /* Get supported operations on the cap. */ -#define MSG_GETHELP \ - 0x0009 /* Returns help text suitable for use in a GUI Added 2.1 */ -#define MSG_GETLABEL \ - 0x000a /* Returns a label suitable for use in a GUI Added 2.1 */ -#define MSG_GETLABELENUM \ - 0x000b /* Return all of the labels for a capability of type Added 2.1 */ - -/* Messages used with DAT_NULL */ -#define MSG_XFERREADY 0x0101 /* The data source has data ready */ -#define MSG_CLOSEDSREQ \ - 0x0102 /* Request for Application. to close DS */ -#define MSG_CLOSEDSOK \ - 0x0103 /* Tell the Application. to save the state. */ -#define MSG_DEVICEEVENT \ - 0X0104 /* Some event has taken place Added 1.8 */ - -/* Messages used with a pointer to DAT_PARENT data */ -#define MSG_OPENDSM 0x0301 /* Open the DSM */ -#define MSG_CLOSEDSM 0x0302 /* Close the DSM */ - -/* Messages used with a pointer to a DAT_IDENTITY structure */ -#define MSG_OPENDS 0x0401 /* Open a data source */ -#define MSG_CLOSEDS 0x0402 /* Close a data source */ -#define MSG_USERSELECT 0x0403 /* Put up a dialog of all DS */ - -/* Messages used with a pointer to a DAT_USERINTERFACE structure */ -#define MSG_DISABLEDS 0x0501 /* Disable data transfer in the DS */ -#define MSG_ENABLEDS 0x0502 /* Enable data transfer in the DS */ -#define MSG_ENABLEDSUIONLY 0x0503 /* Enable for saving DS state only. */ - -/* 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 /* Added 1.8 */ -#define MSG_CREATEDIRECTORY 0x0802 /* Added 1.8 */ -#define MSG_DELETE 0x0803 /* Added 1.8 */ -#define MSG_FORMATMEDIA 0x0804 /* Added 1.8 */ -#define MSG_GETCLOSE 0x0805 /* Added 1.8 */ -#define MSG_GETFIRSTFILE 0x0806 /* Added 1.8 */ -#define MSG_GETINFO 0x0807 /* Added 1.8 */ -#define MSG_GETNEXTFILE 0x0808 /* Added 1.8 */ -#define MSG_RENAME 0x0809 /* Added 1.8 */ -#define MSG_COPY 0x080A /* Added 1.8 */ -#define MSG_AUTOMATICCAPTUREDIRECTORY 0x080B /* Added 1.8 */ - -/* 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 /* Added 1.91 */ - -/**************************************************************************** - * 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 /* default is TWUN_INCHES */ -#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 /* Added 1.1 */ -#define CAP_SUPPORTEDCAPSEXT 0x100c /* Added 1.6 */ -#define CAP_PAPERDETECTABLE 0x100d /* Added 1.6 */ -#define CAP_UICONTROLLABLE 0x100e /* Added 1.6 */ -#define CAP_DEVICEONLINE 0x100f /* Added 1.6 */ -#define CAP_AUTOSCAN 0x1010 /* Added 1.6 */ -#define CAP_THUMBNAILSENABLED 0x1011 /* Added 1.7 */ -#define CAP_DUPLEX 0x1012 /* Added 1.7 */ -#define CAP_DUPLEXENABLED 0x1013 /* Added 1.7 */ -#define CAP_ENABLEDSUIONLY 0x1014 /* Added 1.7 */ -#define CAP_CUSTOMDSDATA 0x1015 /* Added 1.7 */ -#define CAP_ENDORSER 0x1016 /* Added 1.7 */ -#define CAP_JOBCONTROL 0x1017 /* Added 1.7 */ -#define CAP_ALARMS 0x1018 /* Added 1.8 */ -#define CAP_ALARMVOLUME 0x1019 /* Added 1.8 */ -#define CAP_AUTOMATICCAPTURE 0x101a /* Added 1.8 */ -#define CAP_TIMEBEFOREFIRSTCAPTURE 0x101b /* Added 1.8 */ -#define CAP_TIMEBETWEENCAPTURES 0x101c /* Added 1.8 */ -#define CAP_CLEARBUFFERS 0x101d /* Added 1.8 */ -#define CAP_MAXBATCHBUFFERS 0x101e /* Added 1.8 */ -#define CAP_DEVICETIMEDATE 0x101f /* Added 1.8 */ -#define CAP_POWERSUPPLY 0x1020 /* Added 1.8 */ -#define CAP_CAMERAPREVIEWUI 0x1021 /* Added 1.8 */ -#define CAP_DEVICEEVENT 0x1022 /* Added 1.8 */ -#define CAP_SERIALNUMBER 0x1024 /* Added 1.8 */ -#define CAP_PRINTER 0x1026 /* Added 1.8 */ -#define CAP_PRINTERENABLED 0x1027 /* Added 1.8 */ -#define CAP_PRINTERINDEX 0x1028 /* Added 1.8 */ -#define CAP_PRINTERMODE 0x1029 /* Added 1.8 */ -#define CAP_PRINTERSTRING 0x102a /* Added 1.8 */ -#define CAP_PRINTERSUFFIX 0x102b /* Added 1.8 */ -#define CAP_LANGUAGE 0x102c /* Added 1.8 */ -#define CAP_FEEDERALIGNMENT 0x102d /* Added 1.8 */ -#define CAP_FEEDERORDER 0x102e /* Added 1.8 */ -#define CAP_REACQUIREALLOWED 0x1030 /* Added 1.8 */ -#define CAP_BATTERYMINUTES 0x1032 /* Added 1.8 */ -#define CAP_BATTERYPERCENTAGE 0x1033 /* Added 1.8 */ -#define CAP_CAMERASIDE 0x1034 /* Added 1.91 */ -#define CAP_SEGMENTED 0x1035 /* Added 1.91 */ -#define CAP_CAMERAENABLED 0x1036 /* Added 2.0 */ -#define CAP_CAMERAORDER 0x1037 /* Added 2.0 */ -#define CAP_MICRENABLED 0x1038 /* Added 2.0 */ -#define CAP_FEEDERPREP 0x1039 /* Added 2.0 */ -#define CAP_FEEDERPOCKET 0x103a /* Added 2.0 */ -#define CAP_AUTOMATICSENSEMEDIUM 0x103b /* Added 2.1 */ -#define CAP_CUSTOMINTERFACEGUID 0x103c /* Added 2.1 */ - -/* 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 /* Added 1.5 */ -#define ICAP_UNDEFINEDIMAGESIZE 0x112d /* Added 1.6 */ -#define ICAP_IMAGEDATASET 0x112e /* Added 1.7 */ -#define ICAP_EXTIMAGEINFO 0x112f /* Added 1.7 */ -#define ICAP_MINIMUMHEIGHT 0x1130 /* Added 1.7 */ -#define ICAP_MINIMUMWIDTH 0x1131 /* Added 1.7 */ -#define ICAP_AUTODISCARDBLANKPAGES 0x1134 /* Added 2.0 */ -#define ICAP_FLIPROTATION 0x1136 /* Added 1.8 */ -#define ICAP_BARCODEDETECTIONENABLED 0x1137 /* Added 1.8 */ -#define ICAP_SUPPORTEDBARCODETYPES 0x1138 /* Added 1.8 */ -#define ICAP_BARCODEMAXSEARCHPRIORITIES 0x1139 /* Added 1.8 */ -#define ICAP_BARCODESEARCHPRIORITIES 0x113a /* Added 1.8 */ -#define ICAP_BARCODESEARCHMODE 0x113b /* Added 1.8 */ -#define ICAP_BARCODEMAXRETRIES 0x113c /* Added 1.8 */ -#define ICAP_BARCODETIMEOUT 0x113d /* Added 1.8 */ -#define ICAP_ZOOMFACTOR 0x113e /* Added 1.8 */ -#define ICAP_PATCHCODEDETECTIONENABLED 0x113f /* Added 1.8 */ -#define ICAP_SUPPORTEDPATCHCODETYPES 0x1140 /* Added 1.8 */ -#define ICAP_PATCHCODEMAXSEARCHPRIORITIES 0x1141 /* Added 1.8 */ -#define ICAP_PATCHCODESEARCHPRIORITIES 0x1142 /* Added 1.8 */ -#define ICAP_PATCHCODESEARCHMODE 0x1143 /* Added 1.8 */ -#define ICAP_PATCHCODEMAXRETRIES 0x1144 /* Added 1.8 */ -#define ICAP_PATCHCODETIMEOUT 0x1145 /* Added 1.8 */ -#define ICAP_FLASHUSED2 0x1146 /* Added 1.8 */ -#define ICAP_IMAGEFILTER 0x1147 /* Added 1.8 */ -#define ICAP_NOISEFILTER 0x1148 /* Added 1.8 */ -#define ICAP_OVERSCAN 0x1149 /* Added 1.8 */ -#define ICAP_AUTOMATICBORDERDETECTION 0x1150 /* Added 1.8 */ -#define ICAP_AUTOMATICDESKEW 0x1151 /* Added 1.8 */ -#define ICAP_AUTOMATICROTATE 0x1152 /* Added 1.8 */ -#define ICAP_JPEGQUALITY 0x1153 /* Added 1.9 */ -#define ICAP_FEEDERTYPE 0x1154 /* Added 1.91 */ -#define ICAP_ICCPROFILE 0x1155 /* Added 1.91 */ -#define ICAP_AUTOSIZE 0x1156 /* Added 2.0 */ -#define ICAP_AUTOMATICCROPUSESFRAME 0x1157 /* Added 2.1 */ -#define ICAP_AUTOMATICLENGTHDETECTION 0x1158 /* Added 2.1 */ -#define ICAP_AUTOMATICCOLORENABLED 0x1159 /* Added 2.1 */ -#define ICAP_AUTOMATICCOLORNONCOLORPIXELTYPE 0x115a /* Added 2.1 */ -#define ICAP_COLORMANAGEMENTENABLED 0x115b /* Added 2.1 */ -#define ICAP_IMAGEMERGE 0x115c /* Added 2.1 */ -#define ICAP_IMAGEMERGEHEIGHTTHRESHOLD 0x115d /* Added 2.1 */ -#define ICAP_SUPPORTEDEXTIMAGEINFO 0x115e /* Added 2.1 */ - -/* image data sources MAY support these audio caps */ -#define ACAP_XFERMECH 0x1202 /* Added 1.8 */ - -/*************************************************************************** - * 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 /* added 1.9 */ -#define TWEI_CHAPTERNUMBER 0x1239 /* added 1.9 */ -#define TWEI_DOCUMENTNUMBER 0x123A /* added 1.9 */ -#define TWEI_PAGENUMBER 0x123B /* added 1.9 */ -#define TWEI_CAMERA 0x123C /* added 1.9 */ -#define TWEI_FRAMENUMBER 0x123D /* added 1.9 */ -#define TWEI_FRAME 0x123E /* added 1.9 */ -#define TWEI_PIXELFLAVOR 0x123F /* added 1.9 */ -#define TWEI_ICCPROFILE 0x1240 /* added 1.91 */ -#define TWEI_LASTSEGMENT 0x1241 /* added 1.91 */ -#define TWEI_SEGMENTNUMBER 0x1242 /* added 1.91 */ -#define TWEI_MAGDATA 0x1243 /* added 2.0 */ -#define TWEI_MAGTYPE 0x1244 /* added 2.0 */ -#define TWEI_PAGESIDE 0x1245 /* added 2.0 */ -#define TWEI_FILESYSTEMSOURCE 0x1246 /* added 2.0 */ -#define TWEI_IMAGEMERGED 0x1247 /* added 2.1 */ -#define TWEI_MAGDATALENGTH 0x1248 /* added 2.1 */ - -#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 * - ***************************************************************************/ - -/* Return Codes: DSM_Entry and DS_Entry may return any one of these values. */ -#define TWRC_CUSTOMBASE 0x8000 - -#define TWRC_SUCCESS 0 -#define TWRC_FAILURE 1 /* Application may get TW_STATUS for info on failure */ -#define TWRC_CHECKSTATUS 2 /* "tried hard"; get status */ -#define TWRC_CANCEL 3 -#define TWRC_DSEVENT 4 -#define TWRC_NOTDSEVENT 5 -#define TWRC_XFERDONE 6 -#define TWRC_ENDOFLIST 7 /* After MSG_GETNEXT if nothing left */ -#define TWRC_INFONOTSUPPORTED 8 -#define TWRC_DATANOTAVAILABLE 9 - -// Condition Codes: Application gets these -// by doing DG_CONTROL DAT_STATUS MSG_GET. -#define TWCC_CUSTOMBASE 0x8000 - -// It worked! -#define TWCC_SUCCESS 0 -// Failure due to unknown causes -#define TWCC_BUMMER 1 -// Not enough memory to perform operation -#define TWCC_LOWMEMORY 2 -// No Data Source -#define TWCC_NODS 3 -// DS is connected to max possible applications -#define TWCC_MAXCONNECTIONS 4 -// DS or DSM reported error, application shouldn't -#define TWCC_OPERATIONERROR 5 -// Unknown capability -#define TWCC_BADCAP 6 -// Unrecognized MSG DG DAT combination -#define TWCC_BADPROTOCOL 9 -// Data parameter out of range -#define TWCC_BADVALUE 10 -// DG DAT MSG out of expected sequence -#define TWCC_SEQERROR 11 -// Unknown destination Application/Source in DSM_Entry -#define TWCC_BADDEST 12 -// Capability not supported by source -#define TWCC_CAPUNSUPPORTED 13 -// Operation not supported by capability -#define TWCC_CAPBADOPERATION 14 -// Capability has dependancy on other capability -#define TWCC_CAPSEQERROR 15 -// File System operation is denied (file is protected) -#define TWCC_DENIED 16 /* Added 1.8 */ -// Operation failed because file already exists. -#define TWCC_FILEEXISTS 17 /* Added 1.8 */ -// File not found -#define TWCC_FILENOTFOUND 18 /* Added 1.8 */ -// Operation failed because directory is not empty -#define TWCC_NOTEMPTY 19 /* Added 1.8 */ -// The feeder is jammed -#define TWCC_PAPERJAM 20 /* Added 1.8 */ -// The feeder detected multiple pages -#define TWCC_PAPERDOUBLEFEED 21 /* Added 1.8 */ -// Error writing the file (meant for things like disk full conditions) -#define TWCC_FILEWRITEERROR 22 /* Added 1.8 */ -// The device went offline prior to or during this operation -#define TWCC_CHECKDEVICEONLINE 23 /* Added 1.8 */ -#define TWCC_INTERLOCK 24 /* Added 2.0 */ -#define TWCC_DAMAGEDCORNER 25 /* Added 2.0 */ -#define TWCC_FOCUSERROR 26 /* Added 2.0 */ -#define TWCC_DOCTOOLIGHT 27 /* Added 2.0 */ -#define TWCC_DOCTOODARK 28 /* Added 2.0 */ -#define TWCC_NOMEDIA 29 /* Added 2.1 */ - -/* 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 */ -/* Added 1.6 */ -#define TWQC_GET 0x0001 -#define TWQC_SET 0x0002 -#define TWQC_GETDEFAULT 0x0004 -#define TWQC_GETCURRENT 0x0008 -#define TWQC_RESET 0x0010 - -/**************************************************************************** - * Depreciated Items * - ****************************************************************************/ -#ifdef _MSWIN_ -#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 void TW_HUGE *HPVOID; -#endif /* _MSWIN_ */ - -typedef unsigned char TW_STR1024[1026], FAR *pTW_STR1026; -typedef wchar_t TW_UNI512[512], FAR *pTW_UNI512; - -#define TWTY_STR1024 0x000d /* Means Item is a TW_STR1024...added 1.9 */ -#define TWTY_UNI512 0x000e /* Means Item is a TW_UNI512...added 1.9 */ - -#define TWFF_JPN 12 /* 1.91 */ - -// Additional message required for thunker to request the special identity -// information. -#define DAT_TWUNKIDENTITY 0x000b -// Data transfer via a file. deprecated - use DAT_SETUPFILEXFER instead -#define DAT_SETUPFILEXFER2 0x0301 - -#define CAP_SUPPORTEDCAPSEXT 0x100c -#define CAP_FILESYSTEM // 0x???? -#define CAP_PAGEMULTIPLEACQUIRE 0x1023 /* Added 1.8 */ -#define CAP_PAPERBINDING 0x102f /* Added 1.8 */ -#define CAP_PASSTHRU 0x1031 /* Added 1.8 */ -// 0x1034 is reused by CAP_CAMERASIDE -#define CAP_POWERDOWNTIME 0x1034 /* Added 1.8 */ -#define ACAP_AUDIOFILEFORMAT 0x1201 /* Added 1.8 */ - -// Get status information - use MSG_GET instead -#define MSG_CHECKSTATUS 0x0201 - -// Mac Only, deprecated - use DAT_NULL and MSG_xxx instead -#define MSG_INVOKE_CALLBACK 0x0903 - -#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 /* 1.91 */ -#define TWPT_BGR 12 /* 1.91 */ -#define TWPT_CIELAB 13 /* 1.91 */ -#define TWPT_CIELUV 14 /* 1.91 */ -#define TWPT_YCBCR 15 /* 1.91 */ - -/* ICAP_SUPPORTEDSIZES values (SS_ means Supported Sizes) */ -#define TWSS_B 8 -#define TWSS_A4LETTER TWSS_A4 /* use TWSS_A4 instead */ -#define TWSS_B3 TWSS_ISOB3 /* use TWSS_ISOB3 instead */ -#define TWSS_B4 TWSS_ISOB4 /* use TWSS_ISOB4 instead */ -#define TWSS_B6 TWSS_ISOB6 /* use TWSS_ISOB6 instead */ -#define TWSS_B5LETTER TWSS_JISB5 /* use TWSS_JISB5 instead */ - -/* CAP_LANGUAGE Language Constants */ -#define TWLG_DAN TWLG_DANISH /* use TWLG_DANISH instead */ -#define TWLG_DUT TWLG_DUTCH /* use TWLG_DUTCH instead */ -#define TWLG_ENG TWLG_ENGLISH /* use TWLG_ENGLISH instead */ -#define TWLG_USA TWLG_ENGLISH_USA /* use TWLG_ENGLISH_USA instead */ -#define TWLG_FIN TWLG_FINNISH /* use TWLG_FINNISH instead */ -#define TWLG_FRN TWLG_FRENCH /* use TWLG_FRENCH instead */ -#define TWLG_FCF TWLG_FRENCH_CANADIAN /* use TWLG_FRENCH_CANADIAN instead */ -#define TWLG_GER TWLG_GERMAN /* use TWLG_GERMAN instead */ -#define TWLG_ICE TWLG_ICELANDIC /* use TWLG_ICELANDIC instead */ -#define TWLG_ITN TWLG_ITALIAN /* use TWLG_ITALIAN instead */ -#define TWLG_NOR TWLG_NORWEGIAN /* use TWLG_NORWEGIAN instead */ -#define TWLG_POR TWLG_PORTUGUESE /* use TWLG_PORTUGUESE instead */ -#define TWLG_SPA TWLG_SPANISH /* use TWLG_SPANISH instead */ -#define TWLG_SWE TWLG_SWEDISH /* use TWLG_SWEDISH instead */ - -/* 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 - -/* DAT_SETUPFILEXFER2. Sets up DS to application data transfer via a file. Added - * 1.9 */ -typedef struct { - TW_MEMREF FileName; /* Pointer to file name text */ - TW_UINT16 FileNameType; /* TWTY_STR1024 or TWTY_UNI512 */ - TW_UINT16 Format; /* Any TWFF_ constant */ - TW_INT16 VRefNum; /* Used for Mac only */ - TW_UINT32 parID; /* Used for Mac only */ -} TW_SETUPFILEXFER2, FAR *pTW_SETUPFILEXFER2; - -/* SDH - 03/21/95 - TWUNK */ -/* DAT_TWUNKIDENTITY. Provides DS identity and 'other' information necessary */ -/* across thunk link. */ -typedef struct { - TW_IDENTITY identity; /* Identity of data source. */ - TW_STR255 dsPath; /* Full path and file name of data source. */ -} TW_TWUNKIDENTITY, FAR *pTW_TWUNKIDENTITY; - -/* SDH - 03/21/95 - TWUNK */ -/* Provides DS_Entry parameters over thunk link. */ -/* SDH - 03/23/95 - WATCH */ -/* The thunker requires knowledge about size of data being passed in the */ -/* lpData parameter to DS_Entry (which is not readily available due to */ -/* type LPVOID. Thus, we key off the DAT_ argument to determine the size. */ -/* This has a couple implications: */ -/* 1) Any additional DAT_ features require modifications to the thunk code */ -/* for thunker support. */ -/* 2) Any applications which use the custom capabailites are not supported */ -/* under thunking since we have no way of knowing what size data (if */ -/* any) is being passed. */ -typedef struct { - TW_INT8 destFlag; /* TRUE if dest is not NULL */ - TW_IDENTITY dest; /* Identity of data source (if used) */ - TW_INT32 dataGroup; /* DSM_Entry dataGroup parameter */ - TW_INT16 dataArgType; /* DSM_Entry dataArgType parameter */ - TW_INT16 message; /* DSM_Entry message parameter */ - TW_INT32 pDataSize; /* Size of pData (0 if NULL) */ - // TW_MEMREF pData; /* Based on implementation specifics, a */ - /* pData parameter makes no sense in this */ - /* structure, but data (if provided) will be*/ - /* appended in the data block. */ -} TW_TWUNKDSENTRYPARAMS, FAR *pTW_TWUNKDSENTRYPARAMS; - -/* SDH - 03/21/95 - TWUNK */ -/* Provides DS_Entry results over thunk link. */ -typedef struct { - TW_UINT16 returnCode; /* Thunker DsEntry return code. */ - TW_UINT16 conditionCode; /* Thunker DsEntry condition code. */ - TW_INT32 pDataSize; /* Size of pData (0 if NULL) */ - // TW_MEMREF pData; /* Based on implementation specifics, a */ - /* pData parameter makes no sense in this */ - /* structure, but data (if provided) will be*/ - /* appended in the data block. */ -} TW_TWUNKDSENTRYRETURN, FAR *pTW_TWUNKDSENTRYRETURN; - -/* WJD - 950818 */ -/* Added for 1.6 Specification */ -/* TWAIN 1.6 CAP_SUPPORTEDCAPSEXT structure */ -typedef struct { - TW_UINT16 Cap; /* Which CAP/ICAP info is relevant to */ - TW_UINT16 Properties; /* Messages this CAP/ICAP supports */ -} 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. - * - * Parameters: - * pOrigin Identifies the source module of the message. This could - * identify an Application, a Source, or the Source Manager. - * - * pDest Identifies the destination module for the message. - * This could identify an application or a data source. - * If this is NULL, the message goes to the Source Manager. - * - * DG The Data Group. - * Example: DG_IMAGE. - * - * DAT The Data Attribute Type. - * Example: DAT_IMAGEMEMXFER. - * - * MSG The message. Messages are interpreted by the destination module - * with respect to the Data Group and the Data Attribute Type. - * Example: MSG_GET. - * - * pData A pointer to the data structure or variable identified - * by the Data Attribute Type. - * Example: (TW_MEMREF)&ImageMemXfer - * where ImageMemXfer is a TW_IMAGEMEMXFER structure. - * - * Returns: - * ReturnCode - * Example: TWRC_SUCCESS. - * - ********************************************************************/ - -/* Don't mangle the name "DSM_Entry" if we're compiling in C++! */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifdef TWH_CMP_MSC - -TW_UINT16 FAR PASCAL DSM_Entry(pTW_IDENTITY pOrigin, pTW_IDENTITY pDest, - TW_UINT32 DG, TW_UINT16 DAT, TW_UINT16 MSG, - TW_MEMREF pData); - -typedef TW_UINT16(FAR PASCAL *DSMENTRYPROC)(pTW_IDENTITY pOrigin, - pTW_IDENTITY pDest, TW_UINT32 DG, - TW_UINT16 DAT, TW_UINT16 MSG, - TW_MEMREF pData); - -#else - -FAR PASCAL TW_UINT16 DSM_Entry(pTW_IDENTITY pOrigin, pTW_IDENTITY pDest, - TW_UINT32 DG, TW_UINT16 DAT, TW_UINT16 MSG, - TW_MEMREF pData); - -typedef TW_UINT16 (*DSMENTRYPROC)(pTW_IDENTITY pOrigin, pTW_IDENTITY pDest, - TW_UINT32 DG, TW_UINT16 DAT, TW_UINT16 MSG, - TW_MEMREF pData); - -#endif /* TWH_CMP_MSC */ - -#ifdef __cplusplus -} -#endif /* cplusplus */ - -/********************************************************************** - * Function: DS_Entry, the entry point provided by a Data Source. - * - * Parameters: - * pOrigin Identifies the source module of the message. This could - * identify an application or the Data Source Manager. - * - * DG The Data Group. - * Example: DG_IMAGE. - * - * DAT The Data Attribute Type. - * Example: DAT_IMAGEMEMXFER. - * - * MSG The message. Messages are interpreted by the data source - * with respect to the Data Group and the Data Attribute Type. - * Example: MSG_GET. - * - * pData A pointer to the data structure or variable identified - * by the Data Attribute Type. - * Example: (TW_MEMREF)&ImageMemXfer - * where ImageMemXfer is a TW_IMAGEMEMXFER structure. - * - * Returns: - * ReturnCode - * Example: TWRC_SUCCESS. - * - * Note: - * The DSPROC type is only used by an application when it calls - * a Data Source directly, bypassing the Data Source Manager. - * - ********************************************************************/ -/* Don't mangle the name "DS_Entry" if we're compiling in C++! */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifdef TWH_CMP_MSC - -TW_UINT16 FAR PASCAL 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); - -#else - -FAR PASCAL TW_UINT16 DS_Entry(pTW_IDENTITY pOrigin, TW_UINT32 DG, TW_UINT16 DAT, - TW_UINT16 MSG, TW_MEMREF pData); - -typedef TW_UINT16 (*DSENTRYPROC)(pTW_IDENTITY pOrigin, TW_UINT32 DG, - TW_UINT16 DAT, TW_UINT16 MSG, TW_MEMREF pData); - -#endif /* TWH_CMP_MSC */ - -typedef TW_HANDLE(PASCAL *DSM_MEMALLOCATE)(TW_UINT32 _size); -typedef void(PASCAL *DSM_MEMFREE)(TW_HANDLE _handle); -typedef TW_MEMREF(PASCAL *DSM_MEMLOCK)(TW_HANDLE _handle); -typedef void(PASCAL *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; - -/* 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) -#pragma pack(pop, before_twain) -#elif defined(TWH_CMP_BORLAND) -#pragma option -a. -#elif defined(TWH_CMP_XCODE) -#if PRAGMA_STRUCT_ALIGN -#pragma options align = reset -#elif PRAGMA_STRUCT_PACKPUSH -#pragma pack(pop) -#elif PRAGMA_STRUCT_PACK -#pragma pack() -#endif -#endif - -#endif /* TWAIN */ diff --git a/toonz/sources/include/toonz/sceneproperties.h b/toonz/sources/include/toonz/sceneproperties.h index e9f1c08e..6d7f2310 100644 --- a/toonz/sources/include/toonz/sceneproperties.h +++ b/toonz/sources/include/toonz/sceneproperties.h @@ -26,7 +26,6 @@ class TPropertyGroup; class TPalette; class TSceneProperties; class CleanupParameters; -class TScannerParameters; class TCamera; class TOutputProperties; class TStageObjectTree; @@ -60,7 +59,6 @@ private: TOutputProperties *m_outputProp, *m_previewProp; CleanupParameters *m_cleanupParameters; - TScannerParameters *m_scanParameters; VectorizerParameters *m_vectorizerParameters; CaptureParameters *m_captureParameters; @@ -85,7 +83,6 @@ public: \li a new CleanupParameters object that sets to default some basic attributes as basic transformation, rotation angle, scale factor, x-y offsets etc...; - \li a new TScannerParameters object (parameters to manage the scanner); \li a new TOutputProperties object for the output and one for the preview ; Sets internal attributes to default as background color, guides size and @@ -151,11 +148,6 @@ Returns cleanup parameters \b CleanupParameters, i.e. basic colors. CleanupParameters *getCleanupParameters() const { return m_cleanupParameters; } - /*! - Return scanner parameters as Black and white scanner , graytones - scanner or a color scanner. - */ - TScannerParameters *getScanParameters() const { return m_scanParameters; } /*! Return vectorizer parameters. diff --git a/toonz/sources/include/toonz/stage2.h b/toonz/sources/include/toonz/stage2.h index aa38bad1..eacd42bf 100644 --- a/toonz/sources/include/toonz/stage2.h +++ b/toonz/sources/include/toonz/stage2.h @@ -116,24 +116,4 @@ private: CleanupPreviewCheck(); }; -//============================================================================= - -class DVAPI SetScanCropboxCheck { - bool m_enabled; - QAction *m_toggle; - -public: - static SetScanCropboxCheck *instance(); - - void setToggle(QAction *toggle); - - bool isEnabled() const { return m_enabled; } - void setIsEnabled(bool on); - - void uncheck(); - -private: - SetScanCropboxCheck(); -}; - #endif diff --git a/toonz/sources/include/tscanner.h b/toonz/sources/include/tscanner.h deleted file mode 100644 index e56327a3..00000000 --- a/toonz/sources/include/tscanner.h +++ /dev/null @@ -1,244 +0,0 @@ -#pragma once - -#ifndef TSCANNER_H -#define TSCANNER_H - -#include "trasterimage.h" -#include -#include -#undef DVAPI -#undef DVVAR -#ifdef TNZBASE_EXPORTS -#define DVAPI DV_EXPORT_API -#define DVVAR DV_EXPORT_VAR -#else -#define DVAPI DV_IMPORT_API -#define DVVAR DV_IMPORT_VAR -#endif - -// forward declaration -class TOStream; -class TIStream; -class TFilePath; - -struct DVAPI TScanParam { - TScanParam() - : m_supported(false) - , m_min(0) - , m_max(0) - , m_def(0) - , m_step(0) - , m_value(0) {} - - TScanParam(float _min, float _max, float _def, float _step) - : m_supported(true) - , m_min(_min) - , m_max(_max) - , m_def(_def) - , m_step(1) - , m_value(_def) {} - - bool m_supported; - float m_min, m_max, m_def, m_step, - m_value; // questi sono float per seguire lo standard TWAIN ! - - void update(const TScanParam &model); - // assegna min,max,def,step e supported da model a this - // mantiene value a patto che sia contenuto nel nuovo range, diversamente ne - // fa il crop -}; - -class DVAPI TScannerParameters { -public: - enum ScanType { None, BW, GR8, RGB24 }; - -private: - // Supported scan types: Black and white, graytones, color - bool m_bw, m_gray, m_rgb; - - // Current scan type - ScanType m_scanType; - - std::string m_paperFormat; // e.g. "A4 paper" - TRectD m_scanArea; // in mm /* TWAIN preferirebbe gli inch, ma uso i mm per - // seguire tnz4.x*/ - TRectD m_cropBox; // in mm /* TWAIN preferirebbe gli inch, ma uso i mm per - // seguire tnz4.x*/ - bool m_isPreview; - TDimensionD m_maxPaperSize; // in mm /* TWAIN preferirebbe gli inch, ma uso i - // mm per seguire tnz4.x*/ - - bool m_paperOverflow; // vale true se la scanArea e' stata tagliata rispetto - // alle dimensioni della carta - // per rispettare la maxPaperSize - - bool m_validatedByCurrentScanner; - // vale false se bisogna ancora chiamare adaptToCurrentScanner() - // l'idea e' di chiamare questo metodo il meno possibile - -public: - TScanParam m_brightness; - TScanParam m_contrast; - TScanParam m_threshold; - TScanParam m_dpi; - TScanParam m_paperFeeder; // value==1.0 => use paper feeder - -private: - // other useful info ?! - std::string m_twainVersion; - std::string m_manufacturer; - std::string m_prodFamily; - std::string m_productName; - std::string m_version; - - bool m_reverseOrder; // if true then scan levels starting from last frame - - void cropScanArea(); // assicura che scanArea sia dentro maxPaperSize - -public: - TScannerParameters(); - ~TScannerParameters(); - - void setSupportedTypes(bool bw, bool gray, bool rgb); - bool isSupported(ScanType) const; - - void setMaxPaperSize(double maxWidth, - double maxHeight); // note: possibly update m_scanArea - - std::string getPaperFormat() const { return m_paperFormat; } - void setPaperFormat(std::string paperFormat); - // assert(TPaperFormatManager::instance()->isValidFormat(paperFormat)); - // updates scanArea (cropping with maxPaperSize) - - void updatePaperFormat(); - // if paperFormat=="" set default paper format; recompute (to be sure!) - // scanArea - - bool getPaperOverflow() const { - return m_paperOverflow; - } // true iff paperSize > maxPaperSize - - TRectD getScanArea() const { return m_scanArea; } - void setCropBox(const TRectD &cropBox) { m_cropBox = cropBox * m_scanArea; } - TRectD getCropBox() const { return m_cropBox; } - void setIsPreview(bool isPreview) { m_isPreview = isPreview; }; - bool isPreview() const { return m_isPreview; } - - bool isReverseOrder() const { return m_reverseOrder; } - void setReverseOrder(bool reverseOrder) { m_reverseOrder = reverseOrder; } - - bool isPaperFeederEnabled() const { return m_paperFeeder.m_value == 1.0; } - void enablePaperFeeder(bool on) { m_paperFeeder.m_value = on ? 1.0f : 0.0f; } - - void setScanType(ScanType scanType); - ScanType getScanType() const { return m_scanType; } - - // se e' stato definito uno scanner aggiorna lo stato (enabled/disabled, - // range, etc.) - // dei parametri rispetto a quest'ultimo - void adaptToCurrentScanner(); - void adaptToCurrentScannerIfNeeded() { - if (!m_validatedByCurrentScanner) adaptToCurrentScanner(); - } - - void assign(const TScannerParameters *params); - void saveData(TOStream &os) const; - void loadData(TIStream &is); -}; - -//---------------------------------------- - -class TScannerListener { -public: - virtual void onImage(const TRasterImageP &) = 0; - virtual void onError() = 0; - virtual void onNextPaper() = 0; - virtual void onAutomaticallyNextPaper() = 0; - virtual bool isCanceled() = 0; - virtual ~TScannerListener() {} -}; - -//---------------------------------------- - -class DVAPI TScanner { - std::set m_listeners; - -protected: - TScanParam m_brightness, m_contrast, m_threshold, m_dpi; - int m_paperLeft; - QString m_scannerName; - -public: - TScanner(); - virtual ~TScanner(); - - static bool m_isTwain; // brutto, brutto :( - static TScanner *instance(); - - virtual void selectDevice() = 0; - virtual bool isDeviceAvailable() = 0; - virtual bool isDeviceSelected() { return false; } - - virtual void updateParameters(TScannerParameters ¶meters) = 0; - // aggiorna i parametri 'parameters' in funzione del tipo di scanner - // selezionato - // se possibile non modifica i valori correnti, ma cambia solo quello che non - // e' piu' adatto - // abilita/disabilita i parametri "opzionali". - // n.b. i parametri opzionali che vengono disabilitati mantengono il loro - // valore - // (cosi' se fai save default settings dopo aver cambiato scanner non ti perdi - // i vecchi settaggi) - - virtual void acquire(const TScannerParameters ¶m, int paperCount) = 0; - - void addListener(TScannerListener *); - void removeListener(TScannerListener *); - - void notifyImageDone(const TRasterImageP &image); - void notifyNextPaper(); - void notifyAutomaticallyNextPaper(); - void notifyError(); - bool isScanningCanceled(); - - int getPaperLeftCount() const { return m_paperLeft; } - void setPaperLeftCount(int count) { m_paperLeft = count; } - void decrementPaperLeftCount() { --m_paperLeft; } - - QString getName() const { return m_scannerName; } - void setName(const QString &name) { m_scannerName = name; } -}; - -//--------------------------------------------------------- - -class DVAPI TPaperFormatManager { // singleton -public: - class Format { - public: - TDimensionD m_size; - Format() : m_size(0, 0) {} - Format(const TDimensionD &size) : m_size(size) {} - }; - -private: - typedef std::map FormatTable; - FormatTable m_formats; - - TPaperFormatManager(); - void readPaperFormat(const TFilePath &fp); - void readPaperFormats(); - -public: - static TPaperFormatManager *instance(); - - // resitutisce la lista dei formati - void getFormats(std::vector &names) const; - - bool isValidFormat(std::string name) const; - std::string getDefaultFormat() const; - - // nome formato --> dimensione - TDimensionD getSize(std::string name) const; -}; - -#endif diff --git a/toonz/sources/tnzbase/CMakeLists.txt b/toonz/sources/tnzbase/CMakeLists.txt index acfa5391..1c7b06d9 100644 --- a/toonz/sources/tnzbase/CMakeLists.txt +++ b/toonz/sources/tnzbase/CMakeLists.txt @@ -4,27 +4,7 @@ set(MOC_HEADERS ) set(HEADERS ${MOC_HEADERS} - ../common/twain/ttwain.h - ../common/twain/ttwain_capability.h - ../common/twain/ttwain_conversion.h - ../common/twain/ttwain_error.h - ../common/twain/ttwain_global_def.h - ../common/twain/ttwain_state.h - ../common/twain/ttwain_statePD.h - ../common/twain/ttwain_util.h - ../common/twain/ttwain_utilP.h - ../common/twain/ttwain_utilPD.h - ../common/twain/ttwain_win.h - ../common/twain/ttwain_winPD.h - ../common/twain/ttwainP.h - ../common/twain/twain.h ../include/permissionsmanager.h - ../include/tscanner.h - tscanner/tscannerutil.h - tscanner/tscannerepson.h - tscanner/tscannertwain.h - tscanner/TScannerIO/TScannerIO.h - tscanner/TScannerIO/TUSBScannerIO.h ../include/tcubicbezier.h ../include/tdoublekeyframe.h ../include/tdoubleparam.h @@ -108,51 +88,8 @@ set(SOURCES ../common/expressions/tparser.cpp ../common/expressions/ttokenizer.cpp ../common/tunit/tunit.cpp - tscanner/tscannerutil.cpp - tscanner/tscannerepson.cpp ) -if(BUILD_TARGET_WIN) - set(SOURCES ${SOURCES} - tscanner/TScannerIO/TUSBScannerIO_W.cpp - ) -else() - set(SOURCES ${SOURCES} - tscanner/TScannerIO/TUSBScannerIO_M.cpp - ) -endif() - -set(OBJCSOURCES - ../common/twain/ttwain_capability.c - ../common/twain/ttwain_conversion.c - ../common/twain/ttwain_error.c - ../common/twain/ttwain_state.c - ../common/twain/ttwain_util.c - ../common/twain/ttwain_win.c - tscanner/tscanner.cpp - tscanner/tscannertwain.cpp -) - -if(BUILD_TARGET_WIN) - set(OBJCSOURCES ${OBJCSOURCES} - ../common/twain/ttwain_stateW.c - ../common/twain/ttwain_utilW.c - ../common/twain/ttwain_winW.c - ) -elseif(BUILD_TARGET_APPLE) - set(OBJCSOURCES ${OBJCSOURCES} - ../common/twain/ttwain_stateM.c - ../common/twain/ttwain_utilM.c - ../common/twain/ttwain_winM.c - ) -elseif(BUILD_TARGET_UNIX) - set(OBJCSOURCES ${OBJCSOURCES} - ../common/twain/ttwain_stateX.c - ../common/twain/ttwain_utilX.c - ../common/twain/ttwain_winX.c - ) -endif() - if(BUILD_ENV_APPLE) #set_source_files_properties(${OBJCSOURCES} PROPERTIES LANGUAGE OBJCXX) set_source_files_properties(${OBJCSOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c++") @@ -193,14 +130,12 @@ if(BUILD_ENV_MSVC) tnzcore ) elseif(BUILD_ENV_APPLE) - find_library(TWAIN_LIB TWAIN) find_library(IOKIT_LIB IOKit) find_library(COCOA_LIB Cocoa) set(EXTRA_LIBS "$" ${USB_LIB} - ${TWAIN_LIB} ${IOKIT_LIB} ${COCOA_LIB} ) diff --git a/toonz/sources/tnzbase/tscanner/TScannerIO/TScannerIO.h b/toonz/sources/tnzbase/tscanner/TScannerIO/TScannerIO.h deleted file mode 100644 index 8ccaba40..00000000 --- a/toonz/sources/tnzbase/tscanner/TScannerIO/TScannerIO.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#ifndef TSCANNER_IO_H -#define TSCANNER_IO_H - -class TScannerIO { -public: - TScannerIO() {} - virtual bool open() = 0; - virtual void close() = 0; - virtual int receive(unsigned char *buffer, int size) = 0; - virtual int send(unsigned char *buffer, int size) = 0; - virtual void trace(bool on) = 0; - virtual ~TScannerIO() {} -}; -#endif diff --git a/toonz/sources/tnzbase/tscanner/TScannerIO/TUSBScannerIO.h b/toonz/sources/tnzbase/tscanner/TScannerIO/TUSBScannerIO.h deleted file mode 100644 index d2e34849..00000000 --- a/toonz/sources/tnzbase/tscanner/TScannerIO/TUSBScannerIO.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#ifndef TUSBSCANNER_IO_H -#define TUSBSCANNER_IO_H - -#include "TScannerIO.h" - -class TUSBScannerIOPD; - -class TUSBScannerIO final : public TScannerIO { - TUSBScannerIOPD *m_data; - -public: - TUSBScannerIO(); - bool open() override; - void close() override; - int receive(unsigned char *buffer, int size) override; - int send(unsigned char *buffer, int size) override; - void trace(bool on) override; - ~TUSBScannerIO(); -}; - -#endif diff --git a/toonz/sources/tnzbase/tscanner/TScannerIO/TUSBScannerIO_M.cpp b/toonz/sources/tnzbase/tscanner/TScannerIO/TUSBScannerIO_M.cpp deleted file mode 100644 index 0ae71b5e..00000000 --- a/toonz/sources/tnzbase/tscanner/TScannerIO/TUSBScannerIO_M.cpp +++ /dev/null @@ -1,207 +0,0 @@ - - -#include "TUSBScannerIO.h" -#include "tsystem.h" -#include -#include - -//#define HAS_LIBUSB - -#if defined(HAS_LIBUSB) -#include -#endif - -#include -using namespace std; -class TUSBScannerIOPD { -public: - TUSBScannerIOPD(); - struct usb_device *m_epson; - struct usb_dev_handle *m_handle; - int m_epR; - int m_epW; - bool m_trace; -}; - -static pthread_t T = 0; -//#define TRACE cout << __PRETTY_FUNCTION__ << endl; -#define TRACE - -TUSBScannerIOPD::TUSBScannerIOPD() - : m_epson(0), m_handle(0), m_epR(0), m_epW(0), m_trace(false) { - /*initialize libusb*/ - TRACE - - if (T == 0) T = pthread_self(); - -#if defined(HAS_LIBUSB) - usb_set_debug(9); - - usb_init(); - - usb_find_busses(); - usb_find_devices(); -#endif -} - -namespace { -void buf2printable(const unsigned char *buffer, const int size, - stringstream &os) { - int i = 0; - if ((size == 2) && (buffer[0] == 0x1b)) { - os << "ESC "; - char c = buffer[1]; - if (isprint(c)) os << c << " "; - return; - } - os << std::hex; - for (; i < std::min(size, 0x40); ++i) { - char c = buffer[i]; - os << "0x" << (unsigned int)c << " "; - } - if (i < size) os << "..."; -} -} -//----------------------------------------------------------------------------- - -TUSBScannerIO::TUSBScannerIO() : m_data(new TUSBScannerIOPD()) { TRACE } - -//----------------------------------------------------------------------------- -namespace { - -#if defined(HAS_LIBUSB) -// looking for an Epson device -struct usb_device *doCheck(struct usb_device *dev, int level) { - if (!dev) return 0; - - cout << "checking idVendor = " << std::hex << dev->descriptor.idVendor - << endl; - if (dev->descriptor.idVendor == 0x04b8) return dev; - for (int i = 0; i < dev->num_children; i++) - if (doCheck(dev->children[i], level + 1)) return dev->children[i]; - return 0; -} - -#endif -}; - -bool TUSBScannerIO::open() { -#if defined(HAS_LIBUSB) - for (struct usb_bus *bus = usb_busses; bus; bus = bus->next) { - if (bus->root_dev) { - m_data->m_epson = doCheck(bus->root_dev, 0); - if (m_data->m_epson) break; - } else { - struct usb_device *dev; - for (dev = bus->devices; dev; dev = dev->next) - m_data->m_epson = doCheck(dev, 0); - if (m_data->m_epson) break; - } - } - if (!m_data->m_epson) return false; - cout << "found" << endl; - m_data->m_handle = usb_open(m_data->m_epson); - if (!m_data->m_handle) return false; - cout << "opened" << endl; - m_data->m_epR = m_data->m_epson->config[0] - .interface[0] - .altsetting[0] - .endpoint[0] - .bEndpointAddress; - m_data->m_epW = m_data->m_epson->config[0] - .interface[0] - .altsetting[0] - .endpoint[1] - .bEndpointAddress; - - int rc; - rc = usb_set_configuration(m_data->m_handle, - m_data->m_epson->config[0].bConfigurationValue); - cout << "rc (config) = " << rc << endl; - int ifc = 0; - rc = usb_claim_interface(m_data->m_handle, ifc); - if ((rc == -EBUSY) || (rc == -ENOMEM)) return false; - cout << "rc (claim) = " << rc << endl; - cout << "gotit!" << endl; - return true; -#else - return false; -#endif -} - -//----------------------------------------------------------------------------- - -void TUSBScannerIO::close() { - TRACE -#if defined(HAS_LIBUSB) - if (m_data->m_handle) { - usb_release_interface(m_data->m_handle, 0); - usb_close(m_data->m_handle); - } - m_data->m_handle = 0; - m_data->m_epson = 0; -#endif -} - -//----------------------------------------------------------------------------- - -int TUSBScannerIO::receive(unsigned char *buffer, int size) { - TRACE - -#if defined(HAS_LIBUSB) - - int count; - count = usb_bulk_read(m_data->m_handle, m_data->m_epR, (char *)buffer, size, - 30 * 1000); - - if (m_data->m_trace) { - stringstream os; - os << "receive: size=" << size << " got = " << count << " buf="; - buf2printable(buffer, count, os); - os << '\n' << '\0'; - TSystem::outputDebug(os.str()); - } - return count; - -#else - return 0; -#endif -} - -//----------------------------------------------------------------------------- - -int TUSBScannerIO::send(unsigned char *buffer, int size) { - TRACE - -#if defined(HAS_LIBUSB) - int count; - if (T != pthread_self()) { - cout << "called from another thead" << endl; - return 0; - } - - count = usb_bulk_write(m_data->m_handle, m_data->m_epW, (char *)buffer, size, - 30 * 1000); - if (m_data->m_trace) { - stringstream os; - os << "send: size=" << size << " wrote = " << count << " buf="; - buf2printable(buffer, size, os); - os << '\n' << '\0'; - TSystem::outputDebug(os.str()); - } - return count; -#else - return 0; -#endif -} - -//----------------------------------------------------------------------------- - -void TUSBScannerIO::trace(bool on) { - TRACE - m_data->m_trace = on; -} - -//----------------------------------------------------------------------------- - -TUSBScannerIO::~TUSBScannerIO() { TRACE } diff --git a/toonz/sources/tnzbase/tscanner/TScannerIO/TUSBScannerIO_W.cpp b/toonz/sources/tnzbase/tscanner/TScannerIO/TUSBScannerIO_W.cpp deleted file mode 100644 index 45e2b715..00000000 --- a/toonz/sources/tnzbase/tscanner/TScannerIO/TUSBScannerIO_W.cpp +++ /dev/null @@ -1,133 +0,0 @@ - - -#include "TUSBScannerIO.h" -#include "tsystem.h" - -#include - -#include - -class TUSBScannerIOPD { -public: - TUSBScannerIOPD() : m_handle(INVALID_HANDLE_VALUE), m_trace(false) {} - HANDLE m_handle; - bool m_trace; -}; - -//----------------------------------------------------------------------------- -namespace { -void buf2printable(const unsigned char *buffer, const int size, - std::stringstream &os) { - int i = 0; - if ((size == 2) && (buffer[0] == 0x1b)) { - os << "ESC "; - char c = buffer[1]; - if (isprint(c)) os << c << " "; - return; - } - os << std::hex; - for (; i < std::min(size, 0x40); ++i) { - char c = buffer[i]; - os << "0x" << (unsigned int)c << " "; - } - if (i < size) os << "..."; -} -} - -//----------------------------------------------------------------------------- - -TUSBScannerIO::TUSBScannerIO() : m_data(new TUSBScannerIOPD()) {} - -//----------------------------------------------------------------------------- - -bool TUSBScannerIO::open() { - m_data->m_handle = CreateFile("\\\\.\\usbscan0", GENERIC_WRITE | GENERIC_READ, - FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, - OPEN_EXISTING, 0, NULL); - if (m_data->m_handle == INVALID_HANDLE_VALUE) return false; - return true; -} - -//----------------------------------------------------------------------------- - -void TUSBScannerIO::close() { - if (m_data->m_handle && (m_data->m_handle != INVALID_HANDLE_VALUE)) - CloseHandle(m_data->m_handle); -} - -//----------------------------------------------------------------------------- - -int TUSBScannerIO::receive(unsigned char *buffer, int size) { - int bytesLeft = size; - unsigned char *ptr = buffer; - DWORD count; - - static int m_maxReadSize = 0x10000; - - do { - int bytesToRead = bytesLeft; - notMoreThan(m_maxReadSize, bytesToRead); - - OVERLAPPED overlapped; - memset(&overlapped, 0, sizeof(OVERLAPPED)); - overlapped.hEvent = CreateEvent(NULL, // pointertosecurityattributes, - // WIN95ignoresthisparameter - FALSE, // automaticreset - FALSE, // initializetonotsignaled - NULL); // pointertotheevent-objectname - - ReadFile(m_data->m_handle, ptr, bytesToRead, &count, &overlapped); - DWORD waitRC = WaitForSingleObject(overlapped.hEvent, INFINITE); - if (m_data->m_trace) { - std::stringstream os; - os << "receive: size=" << size << " got = " << count << " buf="; - buf2printable(ptr, count, os); - os << '\n' << '\0'; - TSystem::outputDebug(os.str()); - } - - if (count != bytesToRead) return 0; - - ptr += count; - bytesLeft = bytesLeft - count; - } while (bytesLeft); - - return size; -} - -//----------------------------------------------------------------------------- - -int TUSBScannerIO::send(unsigned char *buffer, int size) { - int bytesLeft = size; - DWORD count; - static int m_maxWriteSize = 64; - // bytesLeft = 64; - do { - int bytesToWrite = bytesLeft; - notMoreThan(m_maxWriteSize, bytesToWrite); - WriteFile(m_data->m_handle, buffer, bytesToWrite, &count, 0); - - if (m_data->m_trace) { - std::stringstream os; - os << "send: size=" << size << " wrote = " << count << " buf="; - buf2printable(buffer, size, os); - os << '\n' << '\0'; - TSystem::outputDebug(os.str()); - } - - if (count != bytesToWrite) return 0; - - // ptr += count; - bytesLeft = bytesLeft - count; - } while (bytesLeft); - - return size; -} - -//----------------------------------------------------------------------------- - -void TUSBScannerIO::trace(bool on) { m_data->m_trace = on; } - -//----------------------------------------------------------------------------- - -TUSBScannerIO::~TUSBScannerIO() {} diff --git a/toonz/sources/tnzbase/tscanner/tscanner.cpp b/toonz/sources/tnzbase/tscanner/tscanner.cpp deleted file mode 100644 index 7da7f2d6..00000000 --- a/toonz/sources/tnzbase/tscanner/tscanner.cpp +++ /dev/null @@ -1,574 +0,0 @@ - - -#include "tscanner.h" -#include "tscannertwain.h" -#include "texception.h" -#include "tscannerepson.h" -#include "tstream.h" -#include "tconvert.h" -#include "tfilepath.h" -#include "tfilepath_io.h" -#include "tenv.h" -#include "tsystem.h" - -extern "C" { -#include "../common/twain/ttwain_util.h" -} - -//=================================================================== -// -// TScanParam -// -//------------------------------------------------------------------- - -void TScanParam::update(const TScanParam &model) { - m_supported = model.m_supported; - m_min = model.m_min; - m_max = model.m_max; - m_def = model.m_def; - m_step = model.m_step; - m_value = tcrop(m_value, m_min, m_max); -} - -//=================================================================== -// -// TScannerParameters -// -//------------------------------------------------------------------- - -const std::string BlackAndWhite = "Black & White"; -const std::string Graytones = "Graytones"; -const std::string Rgbcolors = "RGB Color"; - -//------------------------------------------------------------------- - -TScannerParameters::TScannerParameters() - : m_bw(false) - , m_gray(false) - , m_rgb(false) - , m_scanType(None) - , m_scanArea(TRectD()) - , m_cropBox(TRectD()) - , m_isPreview(false) - , m_maxPaperSize(TDimensionD(0, 0)) - , m_paperOverflow(false) - , m_brightness() - , m_contrast() - , m_threshold() - , m_dpi() - , m_paperFeeder() - , m_twainVersion() - , m_manufacturer() - , m_prodFamily() - , m_productName() - , m_version() - , m_reverseOrder(false) - , m_validatedByCurrentScanner(false) { - m_threshold.m_value = 127; - m_brightness.m_value = 127; -} - -//------------------------------------------------------------------------------------------------- - -TScannerParameters::~TScannerParameters() {} - -//------------------------------------------------------------------------------------------------- - -void TScannerParameters::assign(const TScannerParameters *src) { *this = *src; } - -//------------------------------------------------------------------------------------------------- - -void TScannerParameters::setSupportedTypes(bool bw, bool gray, bool rgb) { - m_bw = bw; - m_gray = gray; - m_rgb = rgb; - if (!m_bw && !m_gray && !m_rgb) { - m_scanType = None; - } else { - switch (m_scanType) { - case BW: - if (!m_bw) m_scanType = m_gray ? GR8 : RGB24; - break; - case GR8: - if (!m_gray) m_scanType = m_rgb ? RGB24 : BW; - break; - case RGB24: - if (!m_rgb) m_scanType = m_gray ? GR8 : BW; - break; - case None: - if (gray) - m_scanType = GR8; - else { - if (rgb) - m_scanType = RGB24; - else if (bw) - m_scanType = BW; - } - break; - } - } -} - -//------------------------------------------------------------------------------------------------- - -bool TScannerParameters::isSupported(ScanType scanType) const { - switch (scanType) { - case BW: - return m_bw; - case GR8: - return m_gray; - case RGB24: - return m_rgb; - default: - assert(0); - return false; - } -} - -//------------------------------------------------------------------------------------------------- - -void TScannerParameters::cropScanArea() { - m_paperOverflow = false; - if (m_maxPaperSize.lx == 0 || m_maxPaperSize.ly == 0) { - // probabilmente non e' ancora stato selezionato uno scanner e quindi non e' - // definita una maxPaperSize - return; - } - assert(m_maxPaperSize.lx > 0 && m_maxPaperSize.ly > 0); - if (m_scanArea.x1 > m_maxPaperSize.lx) { - m_paperOverflow = true; - m_scanArea.x1 = m_maxPaperSize.lx; - } - if (m_scanArea.y1 > m_maxPaperSize.ly) { - m_paperOverflow = true; - m_scanArea.y1 = m_maxPaperSize.ly; - } -} - -//------------------------------------------------------------------------------------------------- - -void TScannerParameters::setMaxPaperSize(double maxWidth, double maxHeight) { - // assert(maxWidth>0 && maxHeight>0); - m_maxPaperSize = TDimensionD(maxWidth, maxHeight); - cropScanArea(); -} - -//----------------------------------------------------------------------------- - -void TScannerParameters::setPaperFormat(std::string paperFormat) { - TPaperFormatManager *formatManager = TPaperFormatManager::instance(); - assert(formatManager->isValidFormat(paperFormat)); - if (!formatManager->isValidFormat(paperFormat)) - paperFormat = formatManager->getDefaultFormat(); - m_paperFormat = paperFormat; - TDimensionD d = TPaperFormatManager::instance()->getSize(paperFormat); - m_scanArea = TRectD(TPointD(0, 0), d); - cropScanArea(); - if (m_cropBox == TRectD()) m_cropBox = m_scanArea; -} - -//----------------------------------------------------------------------------- - -void TScannerParameters::updatePaperFormat() { - if (m_paperFormat == "") - m_paperFormat = TPaperFormatManager::instance()->getDefaultFormat(); - setPaperFormat(m_paperFormat); -} - -//----------------------------------------------------------------------------- - -void TScannerParameters::setScanType(ScanType scanType) { - assert(scanType == None || scanType == BW || scanType == GR8 || - scanType == RGB24); - m_scanType = scanType; -} - -//----------------------------------------------------------------------------- - -void TScannerParameters::adaptToCurrentScanner() { - try { - if (TScanner::instance()->isDeviceSelected()) { - TScanner::instance()->updateParameters(*this); - m_validatedByCurrentScanner = true; - } - } catch (TException &) { - // TMessage::error("%1", e.getMessage()); - } -} - -//------------------------------------------------------------------------------------------------- - -void TScannerParameters::saveData(TOStream &os) const { - std::map attr; - attr["fmt"] = m_paperFormat; - os.openCloseChild("paper", attr); - - if (m_paperFeeder.m_value == 1.0) { - attr.clear(); - os.openCloseChild("autoFeeder", attr); - } - - if (m_reverseOrder) { - attr.clear(); - os.openCloseChild("reverseOrder", attr); - } - - if (m_scanType != None) { - std::string scanTypeString = Rgbcolors; - switch (m_scanType) { - case BW: - scanTypeString = BlackAndWhite; - break; - case GR8: - scanTypeString = Graytones; - break; - case RGB24: - scanTypeString = Rgbcolors; - break; - default: - break; - } - attr.clear(); - attr["value"] = scanTypeString; - os.openCloseChild("mode", attr); - } - - if (m_dpi.m_supported) { - attr.clear(); - attr["value"] = std::to_string(m_dpi.m_value); - os.openCloseChild("dpi", attr); - } - - if (m_brightness.m_supported) { - attr.clear(); - attr["value"] = std::to_string(m_brightness.m_value); - os.openCloseChild("brightness", attr); - } - - if (m_contrast.m_supported) { - attr.clear(); - attr["value"] = std::to_string(m_contrast.m_value); - os.openCloseChild("contrast", attr); - } - - if (m_threshold.m_supported) { - attr.clear(); - attr["value"] = std::to_string(m_threshold.m_value); - os.openCloseChild("threshold", attr); - } -} - -//------------------------------------------------------------------------------------------------- - -void TScannerParameters::loadData(TIStream &is) { - std::string tagName; - while (is.matchTag(tagName)) { - if (tagName == "dpi") { - std::string s = is.getTagAttribute("value"); - if (isDouble(s)) m_dpi.m_value = std::stof(s); - } else if (tagName == "brightness") { - std::string s = is.getTagAttribute("value"); - if (isDouble(s)) m_brightness.m_value = std::stof(s); - } else if (tagName == "threshold") { - std::string s = is.getTagAttribute("value"); - if (isDouble(s)) m_threshold.m_value = std::stof(s); - } else if (tagName == "contrast") { - std::string s = is.getTagAttribute("value"); - if (isDouble(s)) m_contrast.m_value = std::stof(s); - } else if (tagName == "autoFeeder") { - m_paperFeeder.m_value = 1.0; - } else if (tagName == "reverseOrder") { - m_reverseOrder = true; - } else if (tagName == "mode") { - std::string scanTypeString = is.getTagAttribute("value"); - m_scanType = None; - if (scanTypeString == BlackAndWhite) - m_scanType = BW; - else if (scanTypeString == Graytones) - m_scanType = GR8; - else if (scanTypeString == Rgbcolors) - m_scanType = RGB24; - } else if (tagName == "paper") { - std::string paperFormat = is.getTagAttribute("fmt"); - if (paperFormat != "") setPaperFormat(paperFormat); - } - } - m_validatedByCurrentScanner = false; -} - -//=================================================================== -// -// TScanner -// -//------------------------------------------------------------------- - -namespace { -TScanner *instanceTwain = 0; -TScanner *instanceEpson = 0; -} - -//------------------------------------------------------------------- - -bool TScanner::m_isTwain = true; - -//------------------------------------------------------------------- - -namespace { -class Cleaner { -public: - bool m_activated; - Cleaner() : m_activated(false) {} - ~Cleaner() { - TScanner *scannerToDestroy = 0; - if (m_activated) scannerToDestroy = TScanner::instance(); - delete scannerToDestroy; - } -}; -Cleaner MyCleaner; -}; - -//------------------------------------------------------------------- - -// #define DUMMYSCAN -#ifdef DUMMYSCAN -class TScannerDummy final : public TScanner { -public: - TScannerDummy() {} - ~TScannerDummy() {} - void selectDevice() {} - bool isDeviceAvailable() { return true; } - void updateParameters(TScannerParameters ¶meters) { - parameters.setSupportedTypes(false, true, true); - parameters.setMaxPaperSize(1000., 1000.); - parameters.enablePaperFeeder(true); - parameters.m_brightness.update(TScanParam(0, 255, 128, 1)); - parameters.m_contrast.update(TScanParam(0, 255, 128, 1)); - parameters.m_threshold.update(TScanParam(0, 255, 128, 1)); - parameters.m_dpi.update(TScanParam(60, 1200, 100, 1)); - - setName("DummyScanner"); - } - bool isTwain() const { return true; } - void acquire(const TScannerParameters ¶m, int paperCount) { return; } - bool isAreaSupported() { return true; } -}; -#endif - -//----------------------------------------------------------------------------- - -TScanner *TScanner::instance() { - MyCleaner.m_activated = true; -#ifdef DUMMYSCAN - static TScannerDummy dummy = TScannerDummy(); - return &dummy; -#else - if (m_isTwain) { - if (instanceEpson) { - TScannerEpson *se = (TScannerEpson *)instanceEpson; - se->closeIO(); - // delete m_instanceEpson; //e' singletone, perche' buttarlo? (vinz) - // m_instanceEpson=0; - } - if (!instanceTwain) instanceTwain = new TScannerTwain(); - } else if (!m_isTwain) { - if (instanceTwain) { - // delete m_instanceTwain; //e' singletone, perche' buttarlo? (vinz) - // m_instanceTwain=0; - TTWAIN_CloseAll(0); - } - if (!instanceEpson) instanceEpson = new TScannerEpson(); - } - - return (m_isTwain ? instanceTwain : instanceEpson); -#endif -} - -//----------------------------------------------------------------------------- -TScanner::TScanner() : m_paperLeft(0) {} - -//----------------------------------------------------------------------------- - -TScanner::~TScanner() { - if (instanceEpson) { - TScannerEpson *se = (TScannerEpson *)instanceEpson; - se->closeIO(); - } -} - -//----------------------------------------------------------------------------- - -void TScanner::addListener(TScannerListener *lst) { m_listeners.insert(lst); } - -//----------------------------------------------------------------------------- - -void TScanner::removeListener(TScannerListener *lst) { m_listeners.erase(lst); } - -//----------------------------------------------------------------------------- - -void TScanner::notifyImageDone(const TRasterImageP &img) { - std::set::iterator it = m_listeners.begin(); - for (; it != m_listeners.end(); ++it) { - (*it)->onImage(img); - } -} - -//----------------------------------------------------------------------------- - -void TScanner::notifyNextPaper() { - std::set::iterator it = m_listeners.begin(); - for (; it != m_listeners.end(); ++it) { - (*it)->onNextPaper(); - } -} - -//----------------------------------------------------------------------------- - -void TScanner::notifyAutomaticallyNextPaper() { - std::set::iterator it = m_listeners.begin(); - for (; it != m_listeners.end(); ++it) { - (*it)->onAutomaticallyNextPaper(); - } -} - -//----------------------------------------------------------------------------- - -void TScanner::notifyError() { - std::set::iterator it = m_listeners.begin(); - for (; it != m_listeners.end(); ++it) { - (*it)->onError(); - } -} - -//----------------------------------------------------------------------------- -/*! If one listener is set to cancel return true. */ -bool TScanner::isScanningCanceled() { - std::set::iterator it = m_listeners.begin(); - for (; it != m_listeners.end(); ++it) { - if ((*it)->isCanceled()) return true; - } - return false; -} - -//=================================================================== -// -// TPaperFormatManager -// -//------------------------------------------------------------------- - -namespace { -const std::pair defaultPaperFormat( - "A4 paper", TDimensionD(210.00, 297.00)); -} - -//----------------------------------------------------------------------------- - -TPaperFormatManager::TPaperFormatManager() { - readPaperFormats(); - // se non c'e' aggiungo il formato di default. In questo modo e' sempre - // definito - if (!isValidFormat(defaultPaperFormat.first)) - m_formats[defaultPaperFormat.first] = Format(defaultPaperFormat.second); -} - -//----------------------------------------------------------------------------- - -TPaperFormatManager *TPaperFormatManager::instance() { - static TPaperFormatManager _instance; - return &_instance; -} - -//----------------------------------------------------------------------------- - -void TPaperFormatManager::getFormats(std::vector &names) const { - for (FormatTable::const_iterator it = m_formats.begin(); - it != m_formats.end(); ++it) - names.push_back(it->first); -} - -//----------------------------------------------------------------------------- - -TDimensionD TPaperFormatManager::getSize(std::string name) const { - FormatTable::const_iterator it = m_formats.find(name); - if (it == m_formats.end()) - return TDimensionD(0., 0.); - else - return it->second.m_size; -} - -//----------------------------------------------------------------------------- - -bool TPaperFormatManager::isValidFormat(std::string name) const { - FormatTable::const_iterator it = m_formats.find(name); - return it != m_formats.end(); -} - -//----------------------------------------------------------------------------- - -std::string TPaperFormatManager::getDefaultFormat() const { - return defaultPaperFormat.first; -} - -//----------------------------------------------------------------------------- - -void TPaperFormatManager::readPaperFormat(const TFilePath &path) { - if (path.getType() != "pap") return; - Tifstream is(path); - std::string name; - TDimensionD size(0, 0); - while (is) { - char buffer[1024]; - is.getline(buffer, sizeof buffer); - - // i e' il carattere successivo alla fine della linea - unsigned int i = 0; - for (i = 0; i < sizeof buffer && buffer[i]; i++) { - } - if (i > 0 && buffer[i - 1] == '\n') i--; - while (i > 0 && buffer[i - 1] == ' ') i--; - unsigned int j = 0; - unsigned int k = 0; - // j e' il carattere successivo alla fine del primo token - for (j = 0; j < i && buffer[j] != ' '; j++) { - } - - // k e' l'inizio del secondo token (se c'e', altrimenti == i) - for (k = j; k < i && buffer[k] == ' '; k++) { - } - - std::string value; - if (k < i) value = std::string(buffer + k, i - k); - - if (buffer[0] == '#') { - if (k < i && name == "") name = value; - } else if (std::string(buffer).find("WIDTH") == 0) { - if (isDouble(value)) size.lx = std::stod(value); - } else if (std::string(buffer).find("LENGTH") == 0) { - if (isDouble(value)) size.ly = std::stod(value); - } - } - if (name == "" || size.lx == 0 || size.ly == 0) { - // TMessage::error("Error reading paper format file : %1",path); - } else - m_formats[name] = Format(size); -} - -//----------------------------------------------------------------------------- - -void TPaperFormatManager::readPaperFormats() { - TFilePathSet fps; - TFilePath papDir = TEnv::getConfigDir() + "pap"; - if (!TFileStatus(papDir).isDirectory()) { - // TMessage::error("E_CanNotReadDirectory_%1", papDir); - return; - } - - try { - fps = TSystem::readDirectory(papDir); - } catch (TException &) { - // TMessage::error("E_CanNotReadDirectory_%1", papDir); - return; - } - - TFilePathSet::const_iterator it = fps.begin(); - for (; it != fps.end(); ++it) readPaperFormat(*it); -} diff --git a/toonz/sources/tnzbase/tscanner/tscannerepson.cpp b/toonz/sources/tnzbase/tscanner/tscannerepson.cpp deleted file mode 100644 index 8da4d152..00000000 --- a/toonz/sources/tnzbase/tscanner/tscannerepson.cpp +++ /dev/null @@ -1,984 +0,0 @@ - - -#include -#include "texception.h" -#include "tscanner.h" -#include "tscannerepson.h" -#include "tscannerutil.h" -#include "tsystem.h" -#include "tconvert.h" -#include "trop.h" - -#include "TScannerIO/TUSBScannerIO.h" - -#include -#include -#include -#include - -using namespace TScannerUtil; - -static void sense(bool) {} -static int scsi_maxlen() { - assert(0); - return 0; -} - -#define BW_USES_GRAYTONES - -#ifndef _WIN32 -#define SWAPIT -#endif - -#ifdef i386 -#undef SWAPIT -#endif -/* -Commands used to drive the scanner: - -cmd spec Level -@ Reset B2 B3 B4 B5 A5 -Q Sharpness B4 B5 A5 -B Halftoning B1 B2 B3 B4 B5 A5 -Z Gamma B2 B3 B4 B5 A5 -L Brightness B2 B3 B4 B5 A5 -t Threshold -H Zoom B2 B3 B4 B5 A5 -R Resolution B1 B2 B3 B4 B5 A5 -A Set read Area B1 B2 B3 B4 B5 A5 -C Linesequence Mode B1 B2 B3 B4 B5 A5 -d Line count B4 B5 A5 -D Dataformat B1 B2 B3 B4 B5 A5 -g Scan speed B4 B5 A5 -G Start Scan B1 B2 B3 B4 B5 - - -e Activate ADF -0x19 Load from ADF -0x0C Unload from ADF - -*/ - -/* NOTE: you can find these codes with "man ascii". */ -static unsigned char STX = 0x02; -static unsigned char ACK = 0x06; -static unsigned char NAK = 0x15; -static unsigned char CAN = 0x18; -static unsigned char ESC = 0x1B; -static unsigned char PF = 0x19; - -/* STATUS bit in readLineData */ -static unsigned char FatalError = 1 << 7; -static unsigned char NotReady = 1 << 6; - -//----------------------------------------------------------------------------- - -#define log(_str) - -class TScannerExpection final : public TException { - TString m_scannerMsg; - -public: - TScannerExpection(const std::vector ¬Fatal, - const std::string &fatal) - : TException("Scanner Expection") { - m_scannerMsg = ::to_wstring(fatal); - for (int i = notFatal.size(); i; i--) - m_scannerMsg += L"\n" + ::to_wstring(notFatal[i - 1]); - log("Exception created: " + ::to_string(m_scannerMsg)); - } - TString getMessage() const override { return m_scannerMsg; } -}; - -//----------------------------------------------------------------------------- - -namespace { -/* -void log(string s) -{ - std::ofstream os("C:\\butta.txt", std::ios::app); - os << s << std::endl; - os.flush(); -} -*/ -} - -//----------------------------------------------------------------------------- - -TScannerEpson::TScannerEpson() - : m_scannerIO(new TUSBScannerIO()), m_hasADF(false), m_isOpened(false) { - log("Created"); -} - -//----------------------------------------------------------------------------- - -void TScannerEpson::closeIO() { - log("CloseIO."); - if (m_scannerIO && m_isOpened) m_scannerIO->close(); - m_isOpened = false; -} - -//----------------------------------------------------------------------------- - -TScannerEpson::~TScannerEpson() { - closeIO(); - log("Destroyed"); -} - -//----------------------------------------------------------------------------- - -void TScannerEpson::selectDevice() { - log(std::string("selectDevice; isOpened=") + (m_isOpened ? "true" : "false")); - if (!m_scannerIO->open()) { - log("open() failed"); - throw TException("unable to get handle to scanner"); - } - m_isOpened = true; - - /* -char lev0, lev1; -unsigned short lowRes, hiRes, hMax,vMax; -collectInformation(&lev0, &lev1, &lowRes, &hiRes, &hMax, &vMax); -string version = toString(lev0) + "." + toString(lev1); -*/ - setName("Scanner EPSON (Internal driver)"); -} - -//----------------------------------------------------------------------------- - -bool TScannerEpson::isDeviceAvailable() { return true; } - -//----------------------------------------------------------------------------- - -bool TScannerEpson::isDeviceSelected() { return m_isOpened; } - -//----------------------------------------------------------------------------- - -void TScannerEpson::updateParameters(TScannerParameters ¶meters) { - log("updateParameters()"); - char lev0, lev1; - unsigned short lowRes, hiRes, hMax, vMax; - collectInformation(&lev0, &lev1, &lowRes, &hiRes, &hMax, &vMax); - log("collected info. res = " + std::to_string(lowRes) + "/" + - std::to_string(hiRes)); - - // non supportiamo black & white - parameters.setSupportedTypes(true, true, true); - - // param.m_scanArea = TRectD(0, 0, 0, 0); - parameters.setMaxPaperSize((25.4 * hMax) / (float)hiRes, - (25.4 * vMax) / (float)hiRes); - parameters.updatePaperFormat(); - - // cambio range, default, step, e supported. aggiorno, se necessario, il value - // (n.b. non dovrebbe succedere - // mai, perche' i range sono sempre gli stessi su tutti gli scanner - TScanParam defaultEpsonParam(0., 255., 128., 1.); - parameters.m_brightness.update(defaultEpsonParam); - parameters.m_contrast.update(defaultEpsonParam); - parameters.m_threshold.update(defaultEpsonParam); - - if (m_hasADF) { - TScanParam defaultPaperFeederParam(0., 1., 0., 1.); - parameters.m_paperFeeder.update(defaultPaperFeederParam); - } else - parameters.m_paperFeeder.m_supported = false; - - // cerco un default per il dpi. il piu' piccolo possibile nella forma 100+k50 - float defaultDpi = 100; - while (defaultDpi < lowRes) defaultDpi += 50; - - TScanParam defaultDpiParam(lowRes, hiRes, defaultDpi, - hiRes > lowRes ? 1.F : 0.F); - parameters.m_dpi.update(defaultDpiParam); - - // parameters.m_twainVersion = "NATIVE"; - // parameters.m_manufacturer = "EPSON"; - - // parameters.m_version = toString(lev0) + "." + toString(lev1); - - log("end updateParameters()"); -} - -//----------------------------------------------------------------------------- - -void TScannerEpson::acquire(const TScannerParameters ¶ms, int paperCount) { - log("acquire"); - TRectD scanArea = params.getScanArea(); - if (scanArea.isEmpty()) - throw TException("Scan area is empty, select a paper size"); - - /* -if ((scanArea.getSize().lx > params.m_maxPaperSize.lx) || -(scanArea.getSize().ly > params.m_maxPaperSize.ly)) -throw TException("Scan area too large, select a correct paper size"); -*/ - - for (int i = 0; i < paperCount; ++i) { - log("paper " + std::to_string(i)); -#ifdef _DEBUG - m_scannerIO->trace(true); -#endif - doSettings(params, i == 0); - unsigned int nTimes = 0; - unsigned int bytes_to_read; - bool rc; - unsigned char stx; - -#ifdef _DEBUG - m_scannerIO->trace(false); -#endif - - TRasterP ras, rasBuffer; - unsigned char *buffer = 0; - log("Scan command"); - rc = ESCI_command('G', false); /* 'SCAN' command */ - if (!rc) throw TException("Start Scan failed"); - log("Scan command OK"); - - unsigned short offsetx = 0, offsety = 0; - unsigned short dimlx = 0, dimly = 0; - - TRectD scanArea = - params.isPreview() ? params.getScanArea() : params.getCropBox(); - scanArea2pix(params, offsetx, offsety, dimlx, dimly, scanArea); - std::swap(dimlx, dimly); - - unsigned int bytes; - - switch (params.getScanType()) { - case TScannerParameters::BW: -#ifdef BW_USES_GRAYTONES - ras = TRasterGR8P(dimlx, dimly); - bytes = dimlx * dimly; - rasBuffer = TRasterGR8P(dimlx, dimly); - buffer = rasBuffer->getRawData(); - break; - break; -#else - ras = TRasterGR8P(dimlx, dimly); - bytes = tceil(dimlx / 8) * dimly; - rasBuffer = TRasterGR8P(tceil(dimlx / 8), dimly); - // bytes = (dimlx + 7) % 8 * dimly; - // rasBuffer = TRasterGR8P((dimlx + 7) % 8,dimly); - buffer = rasBuffer->getRawData(); - break; -#endif - case TScannerParameters::GR8: - -#ifdef GRAYTONES_USES_RGB - ras = TRasterGR8P(dimlx, dimly); - bytes = dimlx * dimly * 3; - rasBuffer = TRasterGR8P(dimlx * 3, dimly); - buffer = rasBuffer->getRawData(); - break; -#else - ras = TRasterGR8P(dimlx, dimly); - bytes = dimlx * dimly; - rasBuffer = TRasterGR8P(dimlx, dimly); - buffer = rasBuffer->getRawData(); - break; -#endif - - case TScannerParameters::RGB24: - ras = TRaster32P(dimlx, dimly); - bytes = dimlx * dimly * 3; - rasBuffer = TRasterGR8P(dimlx * 3, dimly); - buffer = rasBuffer->getRawData(); - break; - - default: - throw TException("Unknown scanner mode"); - break; - } - - log("sleep"); - TSystem::sleep(2000); - log("reading data"); - bool areaEnd = false; - unsigned int bytes_read = 0; - while (!areaEnd) { - unsigned short lines, counter; - unsigned char status = 0; - unsigned int retryCount = 0; - do { - ESCI_readLineData(stx, status, counter, lines, areaEnd); - if (status & FatalError) { - retryCount++; - if (retryCount == 1) throw TException("Error scanning"); - } - } while (status & FatalError); - - bytes_to_read = lines * counter; - if (stx != 0x02) { - std::stringstream os; - os << "header corrupted (" << std::hex << stx << ")" << '\0'; - throw TException(os.str()); - } - unsigned long reqBytes = bytes_to_read; - std::unique_ptr readBuffer = ESCI_read_data2(reqBytes); - if (!readBuffer) throw TException("Error reading image data"); - - log("readline: OK"); - /* -if (params.getScanType() == TScannerParameters::BW ) -{ -for (unsigned int i = 0; i< reqBytes;i++) -readBuffer[i] = ~readBuffer[i]; -} -*/ - memcpy(buffer + bytes_read, readBuffer.get(), reqBytes); - bytes_read += reqBytes; - nTimes++; - if (bytes_read == bytes) break; /* I've read enough bytes */ - if (!(stx & 0x20)) sendACK(); - } - log("read: OK"); - { /* -FILE *myFile = fopen("C:\\temp\\prova.dmp", "w+"); -fwrite(buffer, 1, bytes_to_read, myFile); -fclose(myFile);*/ - } - if (params.m_paperFeeder.m_supported && - (params.m_paperFeeder.m_value == 1.)) { - log("Advance paper"); - if (m_settingsMode == OLD_STYLE) ESCI_doADF(0); - log("Advance paper: OK"); - } - switch (params.getScanType()) { - case TScannerParameters::BW: -#ifdef BW_USES_GRAYTONES - copyGR8BufferToTRasterBW(buffer, dimlx, dimly, ras, true, - params.m_threshold.m_value); - // copyGR8BufferToTRasterGR8(buffer, dimlx, dimly, ras, true); - break; -#else - copyBWBufferToTRasterGR8(buffer, dimlx, dimly, ras, true, true); - break; -#endif - case TScannerParameters::GR8: -#ifdef GRAYTONES_USES_RGB - copyRGBBufferToTRasterGR8(buffer, dimlx, dimly, dimlx, ras); - break; -#else - copyGR8BufferToTRasterGR8(buffer, dimlx, dimly, ras, true); - break; -#endif - - case TScannerParameters::RGB24: - copyRGBBufferToTRaster32(buffer, dimlx, dimly, ras, true); - break; - - default: - throw TException("Unknown scanner mode"); - break; - } - - if (params.getCropBox() != params.getScanArea() && !params.isPreview()) { - TRect scanRect( - TPoint(offsetx, offsety), - TDimension(dimly, dimlx)); // dimLx and ly was has been swapped - scanArea2pix(params, offsetx, offsety, dimlx, dimly, - params.getScanArea()); - TRasterP app = ras->create(dimly, dimlx); - TRaster32P app32(app); - TRasterGR8P appGR8(app); - if (app32) - app32->fill(TPixel32::White); - else if (appGR8) - appGR8->fill(TPixelGR8::White); - app->copy(ras, TPoint(dimly - scanRect.y1 - 1, dimlx - scanRect.x1 - 1)); - ras = app; - } - TRasterImageP rasImg(ras); - if (ras) { - rasImg->setDpi(params.m_dpi.m_value, params.m_dpi.m_value); - rasImg->setSavebox(ras->getBounds()); - } - log("notifying"); - notifyImageDone(rasImg); - if (!(params.m_paperFeeder.m_value == 1.) || - params.isPreview()) // feeder here! - { - if ((paperCount - i) > 1) notifyNextPaper(); - } else - notifyAutomaticallyNextPaper(); - if (isScanningCanceled()) break; - } - - /*Unload Paper if need*/ - - if ((m_settingsMode == NEW_STYLE) && params.m_paperFeeder.m_supported && - (params.m_paperFeeder.m_value == 1.)) { - if (!ESCI_command_1b('e', 1, true)) { - std::vector notFatal; - throw TScannerExpection(notFatal, "Scanner error (un)loading paper"); - } - unsigned char p = 0x0C; - bool status = true; - send(&p, 1); - status = expectACK(); - } - - log("acquire OK"); -} - -//----------------------------------------------------------------------------- - -bool TScannerEpson::isAreaSupported() { return true; } - -//----------------------------------------------------------------------------- - -inline unsigned char B0(const unsigned int v) { return (v & 0x000000ff); } -inline unsigned char B1(const unsigned int v) { return (v & 0x0000ff00) >> 8; } -inline unsigned char B2(const unsigned int v) { return (v & 0x00ff0000) >> 16; } -inline unsigned char B3(const unsigned int v) { return (v & 0xff000000) >> 24; } - -void TScannerEpson::doSettings(const TScannerParameters ¶ms, - bool firstSheet) { - log("doSettings"); - int retryCount = 3; - std::vector notFatal; - - while (retryCount--) { - if (m_settingsMode == NEW_STYLE) { - if (firstSheet) - if (!resetScanner()) { - notFatal.push_back("Scanner error resetting"); - continue; - } - } else { - if (!resetScanner()) { - notFatal.push_back("Scanner error resetting"); - continue; - } - } - - unsigned char cmd[64]; - memset(&cmd, 0, 64); - - unsigned char brightness = 0x00; - float bv = params.m_brightness.m_value; - - if (bv >= 0 && bv < 43) brightness = 0xFD; - if (bv >= 43 && bv < 86) brightness = 0xFE; - if (bv >= 86 && bv < 128) brightness = 0xFF; - if (bv >= 128 && bv < 171) brightness = 0x00; - if (bv >= 171 && bv < 214) brightness = 0x01; - if (bv >= 214 && bv < 255) brightness = 0x02; - if (bv == 255) brightness = 0x03; - - unsigned short dpi = (unsigned short)params.m_dpi.m_value; - - unsigned short offsetx, offsety; - unsigned short sizelx, sizely; - TRectD scanArea = - params.isPreview() ? params.getScanArea() : params.getCropBox(); - scanArea2pix(params, offsetx, offsety, sizelx, sizely, scanArea); - - // the main scan resolution (ESC R) - cmd[0] = B0(dpi); - cmd[1] = B1(dpi); - cmd[2] = B2(dpi); - cmd[3] = B3(dpi); - - // the sub scan resolution (ESC R) - cmd[4] = B0(dpi); - cmd[5] = B1(dpi); - cmd[6] = B2(dpi); - cmd[7] = B3(dpi); - - // skipping length of main scan (ESC A) - cmd[8] = B0(offsetx); - cmd[9] = B1(offsetx); - cmd[10] = B2(offsetx); - cmd[11] = B3(offsetx); - - // skipping length of sub scan (ESC A) - cmd[12] = B0(offsety); - cmd[13] = B1(offsety); - cmd[14] = B2(offsety); - cmd[15] = B3(offsety); - - // the length of main scanning (ESC A) - cmd[16] = B0(sizelx); - cmd[17] = B1(sizelx); - cmd[18] = B2(sizelx); - cmd[19] = B3(sizelx); - - // the length of sub scanning (ESC A) - cmd[20] = B0(sizely); - cmd[21] = B1(sizely); - cmd[22] = B2(sizely); - cmd[23] = B3(sizely); - -#ifdef GRAYTONES_USES_RGB - cmd[24] = 0x13; // scanning color (ESC C) - cmd[25] = 0x08; // data format (ESC D) -#else - switch (params.getScanType()) { - case TScannerParameters::BW: - cmd[24] = 0x00; // scanning BW/Gray (ESC C) -#ifdef BW_USES_GRAYTONES - cmd[25] = 0x08; // data format (ESC D) -#else - cmd[25] = 0x01; // data format (ESC D) - break; -#endif - case TScannerParameters::GR8: - cmd[24] = 0x00; // scanning BW/Gray (ESC C) - cmd[25] = 0x08; // data format (ESC D) - break; - - case TScannerParameters::RGB24: - cmd[24] = 0x13; // scanning color (ESC C) - cmd[25] = 0x08; // data format (ESC D) - break; - - default: - throw TException("Unknown scanner mode"); - break; - } - -// cmd[24] = (params.getScanType() == TScannerParameters::RGB24)?0x13:0x00; -// //scanning color (ESC C) -// cmd[25] = (params.getScanType() == TScannerParameters::RGB24)?0x08:0x08; // -// data format (ESC D) -#endif - - if (m_settingsMode == NEW_STYLE) - cmd[26] = 0; - else - cmd[26] = (params.m_paperFeeder.m_supported && - (params.m_paperFeeder.m_value == 1.)) - ? 0x01 - : 0x00; // option control (ESC e) - cmd[27] = 0x00; // scanning mode (ESC g) - cmd[28] = 0xFF; // the number of block line (ESC d) - cmd[29] = 0x02; // gamma (ESC Z) - cmd[30] = brightness; // brightness (ESC L) - cmd[31] = 0x80; // color collection (ESC M) - cmd[32] = 0x01; // half toning processing (ESC B) - cmd[33] = (unsigned char)params.m_threshold.m_value; // threshold (ESC t) - cmd[34] = 0x00; // separate of area (ESC s) - cmd[35] = 0x01; // sharpness control (ESC Q) - cmd[36] = 0x00; // mirroring (ESC K) - cmd[37] = 0x00; // set film type (ESC N) - // other bytes should be set to 0x00 ! - - if (m_settingsMode == NEW_STYLE) - if (params.m_paperFeeder.m_supported && - (params.m_paperFeeder.m_value == 1.)) { - unsigned char v = (params.m_paperFeeder.m_value == 1.) ? 0x01 : 0x00; - if (!ESCI_command_1b('e', v, true)) - throw TScannerExpection(notFatal, "Scanner error (un)loading paper"); - if (v) { - unsigned char p = 0x19; - bool status = true; - send(&p, 1); - status = expectACK(); - } - } - - unsigned char setParamCmd[2] = {0x1C, 0x57}; - int wrote = send(&setParamCmd[0], 2); - if (wrote != 2) - throw TScannerExpection(notFatal, - "Error setting scanner parameters - W -"); - - if (!expectACK()) { - notFatal.push_back("Error setting scanner parameters - NAK on W -"); - continue; - } - wrote = send(&cmd[0], 0x40); - if (wrote != 0x40) - throw TScannerExpection(notFatal, - "Error setting scanner parameters - D -"); - - if (!expectACK()) { - notFatal.push_back("Error setting scanner parameters - NAK on D -"); - continue; - } - // if here, everything is ok, exit from loop - break; - } - if (retryCount <= 0) - throw TScannerExpection( - notFatal, "Error setting scanner parameters, too many retries"); - log("doSettings:OK"); -} - -//----------------------------------------------------------------------------- - -void TScannerEpson::collectInformation(char *lev0, char *lev1, - unsigned short *lowRes, - unsigned short *hiRes, - unsigned short *hMax, - unsigned short *vMax) { - log("collectInformation"); - unsigned char stx; - int pos = 0; - unsigned short counter; - unsigned char status; - - /* -if (!resetScanner()) -throw TException("Scanner error resetting"); -*/ - if (!ESCI_command('I', false)) - throw TException("Unable to get scanner info. Is it off ?"); - - unsigned long s = 4; // 4 bytes cfr Identity Data Block on ESCI Manual!!! - std::unique_ptr buffer2 = ESCI_read_data2(s); - if (!buffer2 || (s != 4)) throw TException("Error reading scanner info"); - - memcpy(&stx, buffer2.get(), 1); - memcpy(&counter, &(buffer2[2]), 2); - -#ifdef SWAPIT - counter = swapUshort(counter); -#endif - -#ifdef _DEBUG - memcpy(&status, &(buffer2[1]), 1); - std::stringstream os; - os << "stx = " << stx << " status = " << status << " counter=" << counter - << '\n' - << '\0'; -#endif - - s = counter; - std::unique_ptr buffer = ESCI_read_data2(s); - int len = strlen((const char *)buffer.get()); - - /*printf("Level %c%c", buffer[0], buffer[1]);*/ - if (len > 1) { - *lev0 = buffer[0]; - *lev1 = buffer[1]; - } - pos = 2; - /* buffer[pos] contains 'R' */ - if (len < 3 || buffer[pos] != 'R') { - *lev0 = '0'; - *lev1 = '0'; - *lowRes = 0; - *hiRes = 0; - *vMax = 0; - *hMax = 0; - throw TException("unable to get information from scanner"); - } - - *lowRes = (buffer[pos + 2] * 256) + buffer[pos + 1]; - *hiRes = *lowRes; - - while (buffer[pos] == 'R') { - *hiRes = (buffer[pos + 2] * 256) + buffer[pos + 1]; - /* printf("Resolution %c %d", buffer[pos], *hiRes);*/ - pos += 3; - } - - if (buffer[pos] != 'A') { - *lev0 = '0'; - *lev1 = '0'; - *lowRes = 0; - *hiRes = 0; - *vMax = 0; - *hMax = 0; - throw TException("unable to get information from scanner"); - } - - *hMax = (buffer[pos + 2] * 256) + buffer[pos + 1]; - *vMax = (buffer[pos + 4] * 256) + buffer[pos + 3]; - - ESCI_command('f', false); - - ESCI_readLineData2(stx, status, counter); - if (status & FatalError) - throw TException("Fatal error reading information from scanner"); - - s = counter; - buffer = ESCI_read_data2(s); - // name buffer+1A - const char *name = (const char *)(buffer.get() + 0x1A); - if (strncmp(name, "Perfection1640", strlen("Perfection1640"))) { - m_settingsMode = NEW_STYLE; - } else { - m_settingsMode = OLD_STYLE; - } -#if 0 -scsi_new_d("ESCI_extended_status"); -scsi_len(42); -/* main status*/ -scsi_b00(0, "push_button_supported", 0); -scsi_b11(0, "warming_up", 0); -scsi_b33(0, "adf_load_sequence", 0); /* 1 from first sheet; 0 from last or not supp */ -scsi_b44(0, "both_sides_on_adf", 0); -scsi_b55(0, "adf_installed_main_status", 0); -scsi_b66(0, "NFlatbed", 0); /*0 if scanner is flatbed else 1 */ -scsi_b77(0, "system_error", 0); -/* adf status */ -scsi_b77(1, "adf_installed",0); -/*... some other info.., refer to manual if needed*/ -/**/ -#endif - m_hasADF = !!(buffer[1] & 0x80); - log("collectInformation:OK"); -} - -//----------------------------------------------------------------------------- - -bool TScannerEpson::resetScanner() { - log("resetScanner"); - bool ret = ESCI_command('@', true); - log(std::string("resetScanner: ") + (ret ? "OK" : "FAILED")); - return ret; -} - -//----------------------------------------------------------------------------- - -int TScannerEpson::receive(unsigned char *buffer, int size) { - return m_scannerIO->receive(buffer, size); -} - -int TScannerEpson::send(unsigned char *buffer, int size) { - return m_scannerIO->send(buffer, size); -} - -int TScannerEpson::sendACK() { return send(&ACK, 1); } - -bool TScannerEpson::expectACK() { - log("expectACK"); - unsigned char ack = NAK; - int nb = receive(&ack, 1); - -#ifdef _DEBUG - if (ack != ACK) { - std::stringstream os; - os << "ack fails ret = 0x" << std::hex << (int)ack << '\n' << '\0'; - TSystem::outputDebug(os.str()); - } -#endif - log(std::string("expectACK: ") + (ack == ACK ? "ACK" : "FAILED")); - - return (ack == ACK); -} - -char *TScannerEpson::ESCI_inquiry(char cmd) /* returns 0 if failed */ -{ - assert(0); - return 0; -} - -bool TScannerEpson::ESCI_command(char cmd, bool checkACK) { - unsigned char p[2]; - p[0] = ESC; - p[1] = cmd; - bool status; - - int count = send(&(p[0]), 2); - status = count == 2; - - if (checkACK) status = expectACK(); - - return status; -} - -bool TScannerEpson::ESCI_command_1b(char cmd, unsigned char p0, bool checkACK) { - bool status = false; - if (ESCI_command(cmd, checkACK)) { - unsigned char p = p0; - status = true; - send(&p, 1); - if (checkACK) status = expectACK(); - } - - return status; -} - -bool TScannerEpson::ESCI_command_2b(char cmd, unsigned char p0, - unsigned char p1, bool checkACK) { - bool status = false; - if (ESCI_command(cmd, checkACK)) { - status = true; - unsigned char p[2]; - p[0] = p0; - p[1] = p1; - int timeout = 30000; - send(&(p[0]), 2); - if (checkACK) status = expectACK(); - } - - return status; -} - -bool TScannerEpson::ESCI_command_2w(char cmd, unsigned short p0, - unsigned short p1, bool checkACK) { - bool status = false; - if (ESCI_command(cmd, checkACK)) { - status = true; - unsigned short p[2]; - p[0] = p0; - p[1] = p1; - const int len = 1; - int timeout = 30000; - send((unsigned char *)(&(p[0])), 4); - if (checkACK) status = expectACK(); - } - - return status; -} - -bool TScannerEpson::ESCI_command_4w(char cmd, unsigned short p0, - unsigned short p1, unsigned short p2, - unsigned short p3, bool checkACK) { - bool status = false; - if (ESCI_command(cmd, checkACK)) { - status = true; - unsigned char p[8]; - p[0] = (unsigned char)p0; - p[1] = (unsigned char)(p0 >> 8); - p[2] = (unsigned char)p1; - p[3] = (unsigned char)(p1 >> 8); - p[4] = (unsigned char)p2; - p[5] = (unsigned char)(p2 >> 8); - p[6] = (unsigned char)(p3); - p[7] = (unsigned char)(p3 >> 8); - - send((unsigned char *)&(p[0]), 8); - - if (checkACK) status = expectACK(); - } - - return status; -} - -std::unique_ptr TScannerEpson::ESCI_read_data2( - unsigned long &size) { - std::unique_ptr buffer(new unsigned char[size]); - memset(buffer.get(), 0, size); - unsigned long bytesToRead = size; - size = receive(buffer.get(), bytesToRead); - return buffer; -} - -bool TScannerEpson::ESCI_doADF(bool on) { - // check ref esci documentation page 3-64 - unsigned char eject = 0x0c; - int rc = send(&eject, 1); - bool status1 = expectACK(); - return status1; - - return 1; - if (!ESCI_command_1b('e', 0x01, true)) { - if (on) - throw TException("Scanner error loading paper"); - else - throw TException("Scanner error unloading paper"); - } - - unsigned char p = on ? 0x19 : 0x0C; - - send(&p, 1); - bool status = expectACK(); - return status; -} - -void TScannerEpson::scanArea2pix(const TScannerParameters ¶ms, - unsigned short &offsetx, - unsigned short &offsety, - unsigned short &sizelx, unsigned short &sizely, - const TRectD &scanArea) { - const double f = 25.4; - offsetx = (unsigned short)((scanArea.x0 * params.m_dpi.m_value) / f); - offsety = (unsigned short)((scanArea.y0 * params.m_dpi.m_value) / f); - sizelx = - (unsigned short)(((scanArea.x1 - scanArea.x0) * params.m_dpi.m_value) / - f); - sizelx = (sizelx >> 3) << 3; // questo deve essere multiplo di 8 - sizely = - (unsigned short)(((scanArea.y1 - scanArea.y0) * params.m_dpi.m_value) / - f); -} - -void TScannerEpson::ESCI_readLineData(unsigned char &stx, unsigned char &status, - unsigned short &counter, - unsigned short &lines, bool &areaEnd) { - unsigned long s = 6; - std::unique_ptr buffer = ESCI_read_data2(s); - if (!buffer) throw TException("Error reading scanner info"); - /* PACKET DATA LEN = 6 - type offs descr - byte 0 STX - b77 1 fatal_error - b66 1 not_ready - b55 1 area_end - b44 1 option_unit - b33 1 col_attrib_bit_3 - b22 1 col_attrib_bit_2 - b11 1 extended_commands - drow 2, counter - drow 4 lines - */ - bool fatalError = !!(buffer[1] & 0x80); - bool notReady = !!(buffer[1] & 0x40); - areaEnd = !!(buffer[1] & 0x20); - - memcpy(&stx, buffer.get(), 1); - memcpy(&counter, &(buffer[2]), 2); - -#ifdef SWAPIT - counter = swapUshort(counter); -#endif - memcpy(&lines, &(buffer[4]), 2); -#ifdef SWAPIT - lines = swapUshort(lines); -#endif - - status = buffer[1]; - -#ifdef _DEBUG - std::stringstream os; - - os << "fatal=" << fatalError; - os << " notReady=" << notReady; - os << " areaEnd=" << areaEnd; - - os << " stx=" << stx; - os << " counter=" << counter; - os << " lines=" << lines; - os << '\n' << '\0'; - - TSystem::outputDebug(os.str()); -#endif -} - -void TScannerEpson::ESCI_readLineData2(unsigned char &stx, - unsigned char &status, - unsigned short &counter) { - unsigned long s = 4; - std::unique_ptr buffer = ESCI_read_data2(s); - if (!buffer) throw TException("Error reading scanner info"); - bool fatalError = !!(buffer[1] & 0x80); - bool notReady = !!(buffer[1] & 0x40); - - memcpy(&stx, buffer.get(), 1); - memcpy(&counter, &(buffer[2]), 2); -#ifdef SWAPIT - counter = swapUshort(counter); -#endif - - status = buffer[1]; - -#ifdef _DEBUG - std::stringstream os; - - os << "fatal=" << fatalError; - os << " notReady=" << notReady; - - os << " stx=" << stx; - os << " counter=" << counter; - os << '\n' << '\0'; - - TSystem::outputDebug(os.str()); -#endif -} diff --git a/toonz/sources/tnzbase/tscanner/tscannerepson.h b/toonz/sources/tnzbase/tscanner/tscannerepson.h deleted file mode 100644 index bcc036b4..00000000 --- a/toonz/sources/tnzbase/tscanner/tscannerepson.h +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#ifndef TSCANNER_EPSON_INCLUDED -#define TSCANNER_EPSON_INCLUDED - -#include "tscanner.h" -#include "TScannerIO/TScannerIO.h" - -#include - -/* -PLEASE DO NOT REMOVE unreferenced methods... they are useful for debugging :) -max -*/ - -class TScannerEpson final : public TScanner { - enum SettingsMode { OLD_STYLE, NEW_STYLE }; - - TScannerIO *m_scannerIO; - bool m_hasADF; - bool m_isOpened; - SettingsMode m_settingsMode; - -public: - TScannerEpson(); - ~TScannerEpson(); - - void selectDevice() override; - bool isDeviceAvailable() override; - bool isDeviceSelected() override; - void updateParameters(TScannerParameters ¶m) override; // vedi TScanner - void acquire(const TScannerParameters ¶ms, int paperCount) override; - bool isAreaSupported(); - void closeIO(); - -private: - void doSettings(const TScannerParameters ¶ms, bool isFirstSheet); - void collectInformation(char *lev0, char *lev1, unsigned short *lowRes, - unsigned short *hiRes, unsigned short *hMax, - unsigned short *vMax); - bool resetScanner(); - void reportError(std::string errMsg); // debug only - - char *ESCI_inquiry(char cmd); /* returns 0 if failed */ - bool ESCI_command(char cmd, bool checkACK); - bool ESCI_command_1b(char cmd, unsigned char p0, bool checkACK); - bool ESCI_command_2b(char cmd, unsigned char p0, unsigned char p1, - bool checkACK); - bool ESCI_command_2w(char cmd, unsigned short p0, unsigned short p1, - bool checkACK); - bool ESCI_command_4w(char cmd, unsigned short p0, unsigned short p1, - unsigned short p2, unsigned short p3, bool checkACK); - - std::unique_ptr ESCI_read_data2(unsigned long &size); - void ESCI_readLineData(unsigned char &stx, unsigned char &status, - unsigned short &counter, unsigned short &lines, - bool &areaEnd); - void ESCI_readLineData2(unsigned char &stx, unsigned char &status, - unsigned short &counter); - - int receive(unsigned char *buffer, int size); - int send(unsigned char *buffer, int size); - - bool ESCI_doADF(bool on); - int sendACK(); - bool expectACK(); - void scanArea2pix(const TScannerParameters ¶ms, unsigned short &offsetx, - unsigned short &offsety, unsigned short &dimlx, - unsigned short &dimly, const TRectD &scanArea); -}; - -#endif diff --git a/toonz/sources/tnzbase/tscanner/tscannertwain.cpp b/toonz/sources/tnzbase/tscanner/tscannertwain.cpp deleted file mode 100644 index d76170d2..00000000 --- a/toonz/sources/tnzbase/tscanner/tscannertwain.cpp +++ /dev/null @@ -1,339 +0,0 @@ - - -#include -#include -#include "tscannertwain.h" -#include "tscannerutil.h" - -using namespace TScannerUtil; - -extern "C" { -#include "../common/twain/ttwain_util.h" -#include "../common/twain/ttwain_global_def.h" /* forward declare functions */ -} - -/* callback used to handle TTWAIN done/error status*/ - -static void throwIT(const char *msg) { throw TException(msg); } - -extern "C" void TTWAIN_ErrorBox(const char *msg) { throwIT(msg); } - -extern "C" { -static int onDoneCB(UCHAR *buffer, TTWAIN_PIXTYPE pixelType, int lx, int ly, - int wrap, float xdpi, float ydpi, void *usrData) { - TRasterP ras; - switch (pixelType) { - case TTWAIN_BW: - case TTWAIN_WB: { - try { - TRasterGR8P ras8(lx, ly); - copy90BWBufferToRasGR8(buffer, lx, ly, wrap, (pixelType == TTWAIN_BW), - ras8, 1, 0); - ras8->xMirror(); - ras8->yMirror(); - ras = ras8; - } catch (...) { - } - } break; - - case TTWAIN_RGB24: { - try { - TRaster32P ras32(lx, ly); - copyRGBBufferToTRaster32(buffer, lx, ly, ras32, false); - ras = ras32; - } catch (...) { - } - } break; - - case TTWAIN_GRAY8: { - try { - TRasterGR8P ras8(lx, ly); - copyGR8BufferToTRasterGR8(buffer, lx, ly, ras8, false); - ras = ras8; - } catch (...) { - } - } break; - default: - break; - } - - TRasterImageP rasImg; - if (ras) { - rasImg = TRasterImageP(ras); - rasImg->setDpi(xdpi, ydpi); - // rasImg->sethPos(hpos); - rasImg->setSavebox(ras->getBounds()); - } - - TScanner *scannerDevice = reinterpret_cast(usrData); - scannerDevice->notifyImageDone(rasImg); - TTWAIN_FreeMemory(buffer); - scannerDevice->decrementPaperLeftCount(); - return scannerDevice->getPaperLeftCount(); -} -} - -//----------------------------------------------------------------------------- - -extern "C" { -static void onErrorCB(void *usrData, void *alwaysZero) { - TScanner *scannerDevice = reinterpret_cast(usrData); - scannerDevice->notifyError(); -} -} - -//----------------------------------------------------------------------------- - -TScannerTwain::TScannerTwain() {} - -//----------------------------------------------------------------------------- - -TScannerTwain::~TScannerTwain() {} - -//----------------------------------------------------------------------------- - -namespace { -bool deviceSelected = false; -} - -//----------------------------------------------------------------------------- - -void TScannerTwain::selectDevice() { - TTWAIN_SelectImageSource(0); - deviceSelected = true; - - if (TTWAIN_OpenDefaultSource()) { - QString twainVersion(TTWAIN_GetTwainVersion()); - QString manufacturer(TTWAIN_GetManufacturer()); - QString productFamily(TTWAIN_GetProductFamily()); - QString productName(TTWAIN_GetProductName()); - QString version(TTWAIN_GetVersion()); - - TTWAIN_CloseAll(0); - - if (manufacturer != "") { - // se c'e' il nome della marca lo tolgo dal productFamily e productName - productFamily.replace(manufacturer, ""); - productName.replace(manufacturer, ""); - } - setName(manufacturer + " " + productFamily + " " + productName + " (" + - version + ")"); - } -} - -//----------------------------------------------------------------------------- - -bool TScannerTwain::isDeviceSelected() { return deviceSelected; } - -//----------------------------------------------------------------------------- - -bool TScannerTwain::isDeviceAvailable() { return !!TTWAIN_IsAvailable(); } - -//----------------------------------------------------------------------------- - -// TODO!! renderla un update -void TScannerTwain::updateParameters(TScannerParameters ¶m) { - int rc = TTWAIN_OpenDefaultSource(); - if (!rc) return; - -#ifdef MACOSX -// TTWAIN_DumpCapabilities(printf); -#endif - if (isAreaSupported()) { - float w, h; - TTWAIN_GetPhysicalWidthWoAdf(&w); - TTWAIN_GetPhysicalHeightWoAdf(&h); - double width_mm = w * 25.4; - double height_mm = h * 25.4; - - param.setMaxPaperSize(width_mm, height_mm); - // sembra sbagliato: bisognerebbe comunque tenere conto del paperFormat - // selezionato - // param.m_scanArea = TRectD(0,0, width_mm,height_mm); - } - TScanParam defaultTwainParam(0., 255., 128., 1.); - if (TTWAIN_IsCapBrightnessSupported()) { - m_brightness.m_supported = true; - TTWAIN_GetBrightness(&m_brightness.m_min, &m_brightness.m_max, - &m_brightness.m_step, &m_brightness.m_def); - } else { - // m_brightness.m_def = m_brightness.m_max = m_brightness.m_min = - // m_brightness.m_step = 0.; - m_brightness.update(defaultTwainParam); - m_brightness.m_supported = false; - } - // m_brightness.m_value = m_brightness.m_def; - param.m_brightness.update(m_brightness); - - if (TTWAIN_IsCapContrastSupported()) { - m_contrast.m_supported = true; - TTWAIN_GetContrast(&m_contrast.m_min, &m_contrast.m_max, &m_contrast.m_step, - &m_contrast.m_def); - } else { - // m_contrast.m_def = m_contrast.m_max = m_contrast.m_min = - // m_contrast.m_step = 0.; - m_contrast.update(defaultTwainParam); - m_contrast.m_supported = false; - } - // m_contrast.m_value = m_contrast.m_def; - param.m_contrast.update(m_contrast); - - if (TTWAIN_IsCapThresholdSupported()) { - m_threshold.m_supported = true; - TTWAIN_GetThreshold(&m_threshold.m_min, &m_threshold.m_max, - &m_threshold.m_step, &m_threshold.m_def); - } else { - // m_threshold.m_def = m_threshold.m_max = m_threshold.m_min = - // m_threshold.m_step = 0.; - m_threshold.update(defaultTwainParam); - m_threshold.m_supported = false; - } - - // m_threshold.m_value = m_threshold.m_def; - param.m_threshold.update(m_threshold); - - if (TTWAIN_IsCapResolutionSupported()) { - m_dpi.m_supported = true; - TTWAIN_GetResolution(&m_dpi.m_min, &m_dpi.m_max, &m_dpi.m_step, - &m_dpi.m_def); - param.m_dpi.update(m_dpi); - } else { - // m_dpi.m_def = m_dpi.m_max = m_dpi.m_min = m_dpi.m_step = 0.; - param.m_dpi.m_supported = false; - } - // m_dpi.m_value = m_dpi.m_def; - - /* -param.m_twainVersion = string(TTWAIN_GetTwainVersion()); -param.m_manufacturer = string(TTWAIN_GetManufacturer ()); -param.m_prodFamily = string(TTWAIN_GetProductFamily()); -param.m_productName = string(TTWAIN_GetProductName ()); -param.m_version = string(TTWAIN_GetVersion()); -*/ - - bool bw = !!TTWAIN_SupportsPixelType(TTWAIN_BW) || - !!TTWAIN_SupportsPixelType(TTWAIN_WB); - bool gray = !!TTWAIN_SupportsPixelType(TTWAIN_GRAY8); - bool rgb = !!TTWAIN_SupportsPixelType(TTWAIN_RGB24); - - param.setSupportedTypes(bw, gray, rgb); - - TTWAIN_CloseAll(0); -} - -//----------------------------------------------------------------------------- - -static void setupParameters(const TScannerParameters ¶ms, - bool isAreaSupported) { - if (isAreaSupported) { - TRectD scanArea = params.getScanArea(); - float L = (float)(scanArea.getP00().x / 25.4); - float T = (float)(scanArea.getP00().y / 25.4); - float R = (float)(scanArea.getP11().x / 25.4); - float B = (float)(scanArea.getP11().y / 25.4); - TTWAIN_SetImageLayout(L, T, R, B); - } - - TTWAIN_PIXTYPE pt; - switch (params.getScanType()) { - case TScannerParameters::BW: - pt = TTWAIN_BW; - break; - case TScannerParameters::GR8: - pt = TTWAIN_GRAY8; - break; - case TScannerParameters::RGB24: - pt = TTWAIN_RGB24; - break; - default: - /* assert(0);*/ - pt = TTWAIN_RGB24; - break; - } - - TTWAIN_SetPixelType(pt); - if (params.m_dpi.m_supported) TTWAIN_SetResolution(params.m_dpi.m_value); - - if (params.m_brightness.m_supported) - TTWAIN_SetBrightness(params.m_brightness.m_value); - - if (params.m_contrast.m_supported) - TTWAIN_SetContrast(params.m_contrast.m_value); - - if (params.m_threshold.m_supported) - TTWAIN_SetThreshold(params.m_threshold.m_value); -} - -//----------------------------------------------------------------------------- -static void openAndSetupTwain() { - int rc = TTWAIN_OpenDefaultSource(); - if (rc) { - TTWAIN_SetTwainUsage(TTWAIN_MODE_UNLEASHED); - if (TTWAIN_IsCapDeviceOnLineSupported()) { - int status = TTWAIN_IsDeviceOnLine(); - if (status == 0) { - } - } - } - TTWAIN_SetUIStatus(TRUE); -} - -void TScannerTwain::acquire(const TScannerParameters ¶ms, int paperCount) { - openAndSetupTwain(); - - // int feeder = TTWAIN_IsFeederLoaded(); - int feeder = params.isPaperFeederEnabled(); - m_paperLeft = paperCount; - int rc; - -#ifdef MACOSX - // pezza solo HP su MACOSX per gestire la scansione di piu' frame - bool ishp = !!(strcasestr(TTWAIN_GetProductName(), "hp")); -#else - bool ishp = false; -#endif - if (ishp) { - for (int i = 0; i < paperCount; ++i) { - printf("scanning %d/%d\n", i + 1, paperCount); - if (i == 0) { - setupParameters(params, isAreaSupported()); - TTWAIN_SetOnDoneCallback(onDoneCB, this); - TTWAIN_SetOnErrorCallback(onErrorCB, this); - } else - openAndSetupTwain(); - - rc = TTWAIN_SetXferMech(TTWAIN_TRANSFERMODE_MEMORY, 0, 0, 0, 0, 1); - int acq_rc = TTWAIN_AcquireMemory(0); - - if (acq_rc == 0) break; // error, or the user has closed the TWAIN UI - if (!feeder && ((paperCount - i) > 1)) notifyNextPaper(); - TTWAIN_CloseAll(0); - } - } else { - for (int i = 0; i < (feeder ? 1 : paperCount); ++i) { - printf("scanning %d/%d\n", i + 1, paperCount); - setupParameters(params, isAreaSupported()); - - rc = TTWAIN_SetXferMech(TTWAIN_TRANSFERMODE_MEMORY, 0, 0, 0, 0, - paperCount); - - TTWAIN_SetOnDoneCallback(onDoneCB, this); - TTWAIN_SetOnErrorCallback(onErrorCB, this); - int acq_rc = TTWAIN_AcquireMemory(0); - - if (acq_rc == 0) break; // error, or the user has closed the TWAIN UI - if (!feeder && ((paperCount - i) > 1)) notifyNextPaper(); - } - TTWAIN_CloseAll(0); - } -} - -//----------------------------------------------------------------------------- - -bool TScannerTwain::isAreaSupported() { - /* -TTWAIN_IsCapPhysicalWidthSupported (void); -TTWAIN_IsCapPhysicalHeightSupported (void); -*/ - return !!TTWAIN_IsCapImageLayoutSupported(); -} diff --git a/toonz/sources/tnzbase/tscanner/tscannertwain.h b/toonz/sources/tnzbase/tscanner/tscannertwain.h deleted file mode 100644 index 8805b820..00000000 --- a/toonz/sources/tnzbase/tscanner/tscannertwain.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#ifndef SCANNER_TWAIN_INCLUDED -#define SCANNER_TWAIN_INCLUDED - -#include "tscanner.h" - -class TScannerTwain final : public TScanner { -public: - TScannerTwain(); - ~TScannerTwain(); - - bool isDeviceAvailable() override; - bool isDeviceSelected() override; - void selectDevice() override; - - void updateParameters(TScannerParameters &) override; // vedi TScanner - void acquire(const TScannerParameters ¶m, int paperCount) override; - bool isAreaSupported(); -}; - -#endif diff --git a/toonz/sources/tnzbase/tscanner/tscannerutil.cpp b/toonz/sources/tnzbase/tscanner/tscannerutil.cpp deleted file mode 100644 index 4a9d8341..00000000 --- a/toonz/sources/tnzbase/tscanner/tscannerutil.cpp +++ /dev/null @@ -1,297 +0,0 @@ - - -#include "tscannerutil.h" - -#include - -#define BUFBYTE(X, Y, BUF, BYTEWRAP, BITOFFS) \ - (((UCHAR *)(BUF))[(((X) + (BITOFFS)) >> 3) + (Y) * (BYTEWRAP)]) - -#define GET_BIT(X, Y, BUF, BYTEWRAP, BITOFFS) \ - ((BUFBYTE(X, Y, BUF, BYTEWRAP, BITOFFS) >> (7 - (((X) + (BITOFFS)) & 7))) & \ - (UCHAR)1) - -namespace TScannerUtil { - -struct EP { - unsigned char r, g, b; -}; - -//----------------------------------------------------------------------------- - -void copyRGBBufferToTRaster32(unsigned char *rgbBuffer, int rgbLx, int rgbLy, - const TRaster32P &rout, bool internal) { - if (internal) { - TPixelRGBM32 *dst = rout->pixels(); - EP *src = (EP *)(rgbBuffer + (rgbLx * rgbLy - 1) * 3); - const int w = rout->getWrap(); - - for (int x = 0; x < rout->getLx(); ++x) { - dst = rout->pixels() + x; - for (int y = 0; y < rout->getLy(); ++y) { - dst->r = src->r; - dst->g = src->g; - dst->b = src->b; - dst->m = 0xff; - dst += w; - --src; - } - } - } else { - unsigned char *index = rgbBuffer; - unsigned char *end = index + (rgbLx * rgbLy * 3); - TPixel32 *outPix = rout->pixels(); - while (index < end) { - outPix->r = (int)*index; - index++; - outPix->g = (int)*index; - index++; - outPix->b = (int)*index; - index++; - outPix->m = 255; - outPix++; - } - rout->yMirror(); - } -} - -//----------------------------------------------------------------------------- - -void copyRGBBufferToTRasterGR8(unsigned char *rgbBuffer, int rgbLx, int rgbLy, - int rgbWrap, const TRasterGR8P &rout) { - TPixelGR8 *dst = rout->pixels(); - EP *src = (EP *)(rgbBuffer + (rgbLx * rgbLy - 1) * 3); - const int w = rout->getWrap(); - - for (int x = 0; x < rout->getLx(); ++x) { - dst = rout->pixels() + x; - for (int y = 0; y < rout->getLy(); ++y) { - *dst = TPixelGR8::from(TPixelRGBM32(src->r, src->g, src->b)); - dst += w; - --src; - } - } -} - -//----------------------------------------------------------------------------- - -void copyGR8BufferToTRasterGR8(unsigned char *gr8Buffer, int rgbLx, int rgbLy, - const TRasterGR8P &rout, bool internal) { - if (internal) { - unsigned char *dst = rout->getRawData(); - unsigned char *src = (gr8Buffer + rgbLx * rgbLy - 1); - const int w = rout->getWrap(); - - for (int x = 0; x < rout->getLx(); ++x) { - dst = rout->getRawData() + x; - for (int y = 0; y < rout->getLy(); ++y) { - *dst = (*src); - dst += w; - --src; - } - } - } else { - memcpy(rout->getRawData(), gr8Buffer, rgbLx * rgbLy); - rout->yMirror(); - } -} - -//----------------------------------------------------------------------------- - -void copyGR8BufferToTRasterBW(unsigned char *gr8Buffer, int rgbLx, int rgbLy, - const TRasterGR8P &rout, bool internal, - float thres) { - if (internal) { - unsigned char *dst = rout->getRawData(); - unsigned char *src = (gr8Buffer + rgbLx * rgbLy - 1); - const int w = rout->getWrap(); - - for (int x = 0; x < rout->getLx(); ++x) { - dst = rout->getRawData() + x; - for (int y = 0; y < rout->getLy(); ++y) { - if (*src < thres) - *dst = 0; - else - *dst = 255; - dst += w; - --src; - } - } - } else { - memcpy(rout->getRawData(), gr8Buffer, rgbLx * rgbLy); - rout->yMirror(); - } -} - -//----------------------------------------------------------------------------- - -void copyBWBufferToTRasterGR8(const unsigned char *buffer, int rgbLx, int rgbLy, - const TRasterGR8P &rout, bool isBW, - bool internal) { - if (0) - assert(0); - else { - int i = 0; - UCHAR *pix = rout->getRawData(); - const unsigned char *byte; - while (i < rgbLx * rgbLy) { - int bytePos = i / 8; - int bitPos = i % 8; - byte = buffer + bytePos; - bool bit = (*byte) >> (7 - bitPos); - if (isBW) - *pix = (bit ? 255 : 0); - else - *pix = (bit ? 0 : 255); - - pix++; - i++; - } - rout->yMirror(); - } -} - -//----------------------------------------------------------------------------- - -void copy90BWBufferToRasGR8(unsigned char *bwBuffer, int bwLx, int bwLy, - int bwWrap, bool isBW, TRasterGR8P &rout, - int mirror, int ninety) { - int x1 = 0; - int y1 = 0; - int x2 = bwLx - 1; - int y2 = bwLy - 1; - int newx = 0; - int newy = 0; - - UCHAR *bufin, *bufout, /* *bytein,*/ *byteout; - int bytewrapin, bitoffsin, wrapout; - int value_for_0, value_for_1; - int u, v, lu, lv, su, sv, u00, v00, u0, v0, dudy, dvdy, dudx, dvdx; - int x, y, lx, ly; - int u1, v1, u2, v2; - - mirror &= 1; - ninety &= 3; - - if (!ninety && !mirror) { - assert(0); - return; - } - - if (isBW) { - value_for_0 = 0; - value_for_1 = 255; - } else { - value_for_0 = 255; - value_for_1 = 0; - } - - u1 = x1; - v1 = y1; - u2 = x2; - v2 = y2; - - su = u2 - u1; - sv = v2 - v1; - lu = u2 - u1 + 1; - lv = v2 - v1 + 1; - - if (ninety & 1) { - lx = lv; - ly = lu; - } else { - lx = lu; - ly = lv; - } - - bufin = bwBuffer; - bytewrapin = (bwWrap + 7) >> 3; - bitoffsin = 0; // rin->bit_offs; - bufout = rout->getRawData(); - wrapout = rout->getWrap(); - - dudx = 0; - dudy = 0; - dvdx = 0; - dvdy = 0; - - switch ((mirror << 2) + ninety) { - case (0 << 2) + 0: - u00 = u1; - v00 = v1; - dudx = 1; - dvdy = 1; - break; - case (0 << 2) + 1: - u00 = u1; - v00 = v1 + sv; - dudy = 1; - dvdx = -1; - break; - case (0 << 2) + 2: - u00 = u1 + su; - v00 = v1 + sv; - dudx = -1; - dvdy = -1; - break; - case (0 << 2) + 3: - u00 = u1 + su; - v00 = v1; - dudy = -1; - dvdx = 1; - break; - case (1 << 2) + 0: - u00 = u1 + su; - v00 = v1; - dudx = -1; - dvdy = 1; - break; - case (1 << 2) + 1: - u00 = u1 + su; - v00 = v1 + sv; - dudy = -1; - dvdx = -1; - break; - case (1 << 2) + 2: - u00 = u1; - v00 = v1 + sv; - dudx = 1; - dvdy = -1; - break; - case (1 << 2) + 3: - u00 = u1; - v00 = v1; - dudy = 1; - dvdx = 1; - break; - default: - abort(); - u00 = v00 = dudy = dvdx = 0; - } - - if (dudx) - for (u0 = u00, v0 = v00, y = newy; y < newy + ly; v0 += dvdy, y++) { - u = u0; - v = v0; - byteout = bufout + newx + y * wrapout; - for (x = newx; x < newx + lx; u += dudx, x++) { - if (GET_BIT(u, v, bufin, bytewrapin, bitoffsin)) - *byteout++ = value_for_1; - else - *byteout++ = value_for_0; - } - } - else - for (u0 = u00, v0 = v00, y = newy; y < newy + ly; u0 += dudy, y++) { - u = u0; - v = v0; - byteout = bufout + newx + y * wrapout; - for (x = newx; x < newx + lx; v += dvdx, x++) { - if (GET_BIT(u, v, bufin, bytewrapin, bitoffsin)) - *byteout++ = value_for_1; - else - *byteout++ = value_for_0; - } - } -} -}; diff --git a/toonz/sources/tnzbase/tscanner/tscannerutil.h b/toonz/sources/tnzbase/tscanner/tscannerutil.h deleted file mode 100644 index 9b04d2b2..00000000 --- a/toonz/sources/tnzbase/tscanner/tscannerutil.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include - -namespace TScannerUtil { - -/* copia un rettangolo da rin a rout, - * specchiandolo orizzontalmente se mirror e' dispari, - * e poi ruotandolo del multiplo di novanta gradi specificato - * da ninety in senso antiorario - * - */ - -void copyRGBBufferToTRaster32(unsigned char *rgbBuffer, int rgbLx, int rgbLy, - const TRaster32P &rout, bool internal); - -void copyRGBBufferToTRasterGR8(unsigned char *rgbBuffer, int rgbLx, int rgbLy, - int rgbWrap, const TRasterGR8P &rout); - -void copyGR8BufferToTRasterGR8(unsigned char *gr8Buffer, int rgbLx, int rgbLy, - const TRasterGR8P &rout, bool internal); - -void copyGR8BufferToTRasterBW(unsigned char *gr8Buffer, int rgbLx, int rgbLy, - const TRasterGR8P &rout, bool internal, - float thres); - -void copyBWBufferToTRasterGR8(const unsigned char *buffer, int rgbLx, int rgbLy, - const TRasterGR8P &rout, bool isBW, - bool internal); - -void copy90BWBufferToRasGR8(unsigned char *bwBuffer, int bwLx, int bwLy, - int bwWrap, bool isBW, TRasterGR8P &rout, - int mirror, int ninety); -}; diff --git a/toonz/sources/toonz/CMakeLists.txt b/toonz/sources/toonz/CMakeLists.txt index ab1127f4..14addb25 100644 --- a/toonz/sources/toonz/CMakeLists.txt +++ b/toonz/sources/toonz/CMakeLists.txt @@ -79,7 +79,6 @@ set(MOC_HEADERS reslist.h ruler.h savepresetpopup.h - scanpopup.h scenesettingspopup.h sceneviewer.h sceneviewercontextmenu.h @@ -260,7 +259,6 @@ set(SOURCES renumberpopup.cpp runscriptcommand.cpp savepresetpopup.cpp - scanpopup.cpp sceneviewercontextmenu.cpp scenesettingspopup.cpp scriptconsolepanel.cpp diff --git a/toonz/sources/toonz/iocommand.cpp b/toonz/sources/toonz/iocommand.cpp index ca74f1d0..b9bea06d 100644 --- a/toonz/sources/toonz/iocommand.cpp +++ b/toonz/sources/toonz/iocommand.cpp @@ -1334,7 +1334,6 @@ void IoCmd::newScene() { CleanupPreviewCheck::instance()->setIsEnabled(false); CameraTestCheck::instance()->setIsEnabled(false); - SetScanCropboxCheck::instance()->setIsEnabled(false); if (!TApp::instance()->isApplicationStarting()) QApplication::clipboard()->clear(); diff --git a/toonz/sources/toonz/levelcreatepopup.cpp b/toonz/sources/toonz/levelcreatepopup.cpp index 72484996..5f242e22 100644 --- a/toonz/sources/toonz/levelcreatepopup.cpp +++ b/toonz/sources/toonz/levelcreatepopup.cpp @@ -187,7 +187,6 @@ LevelCreatePopup::LevelCreatePopup() m_levelTypeOm->addItem(tr("Vector Level"), (int)PLI_XSHLEVEL); m_levelTypeOm->addItem(tr("Smart Raster Level"), (int)TZP_XSHLEVEL); m_levelTypeOm->addItem(tr("Raster Level"), (int)OVL_XSHLEVEL); - m_levelTypeOm->addItem(tr("Scan Level"), (int)TZI_XSHLEVEL); if (Preferences::instance()->getUnits() == "pixel") { m_widthFld->setMeasure("camera.lx"); diff --git a/toonz/sources/toonz/main.cpp b/toonz/sources/toonz/main.cpp index 06a6ace9..b86b9a24 100644 --- a/toonz/sources/toonz/main.cpp +++ b/toonz/sources/toonz/main.cpp @@ -78,6 +78,7 @@ #include #include #include +#include #ifdef _WIN32 #ifndef x64 diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp index 4c416529..8f6ccad7 100644 --- a/toonz/sources/toonz/mainwindow.cpp +++ b/toonz/sources/toonz/mainwindow.cpp @@ -1902,27 +1902,11 @@ void MainWindow::defineActions() { touchToggle->setEnabled(true); touchToggle->setIcon(QIcon(":Resources/touch.svg")); - createMenuScanCleanupAction(MI_DefineScanner, tr("&Define Scanner..."), ""); - createMenuScanCleanupAction(MI_ScanSettings, tr("&Scan Settings..."), ""); - createMenuScanCleanupAction(MI_Scan, tr("&Scan"), ""); - createMenuScanCleanupAction(MI_Autocenter, tr("&Autocenter..."), ""); - - QAction *toggle = createToggle(MI_SetScanCropbox, tr("&Set Cropbox"), "", 0, - MenuScanCleanupCommandType); - if (toggle) { - SetScanCropboxCheck::instance()->setToggle(toggle); - QString scannerType = QSettings().value("CurrentScannerType").toString(); - if (scannerType == "TWAIN") toggle->setDisabled(true); - toggle = createMenuScanCleanupAction(MI_ResetScanCropbox, - tr("&Reset Cropbox"), ""); - if (scannerType == "TWAIN") toggle->setDisabled(true); - } - createMenuScanCleanupAction(MI_CleanupSettings, tr("&Cleanup Settings..."), ""); - toggle = createToggle(MI_CleanupPreview, tr("&Preview Cleanup"), "", 0, - MenuScanCleanupCommandType); + QAction *toggle = createToggle(MI_CleanupPreview, tr("&Preview Cleanup"), "", + 0, MenuScanCleanupCommandType); CleanupPreviewCheck::instance()->setToggle(toggle); toggle = createToggle(MI_CameraTest, tr("&Camera Test"), "", 0, MenuScanCleanupCommandType); @@ -2421,7 +2405,8 @@ void MainWindow::defineActions() { createToolAction(T_Plastic, "plastic", tr("Plastic Tool"), "X", tr("Plastic Tool: Builds a mesh that allows to deform and " "animate a level")); - createToolAction(T_Ruler, "ruler", tr("Ruler Tool"), "", tr("Ruler Tool: Measure distances on the canvas")); + createToolAction(T_Ruler, "ruler", tr("Ruler Tool"), "", + tr("Ruler Tool: Measure distances on the canvas")); createToolAction(T_Finger, "finger", tr("Finger Tool"), "", tr("Finger Tool: Smudges small areas to cover with line")); @@ -3333,7 +3318,7 @@ void MainWindow::clearCacheFolder() { // 1. $CACHE/[Current ProcessID] // 2. $CACHE/temp/[Current scene folder] if the current scene is untitled - TFilePath cacheRoot = ToonzFolder::getCacheRootFolder(); + TFilePath cacheRoot = ToonzFolder::getCacheRootFolder(); if (cacheRoot.isEmpty()) cacheRoot = TEnv::getStuffDir() + "cache"; TFilePathSet filesToBeRemoved; @@ -3467,9 +3452,9 @@ RecentFiles::~RecentFiles() {} void RecentFiles::addFilePath(QString path, FileType fileType, QString projectName) { QList files = - (fileType == Scene) - ? m_recentScenes - : (fileType == Level) ? m_recentLevels : m_recentFlipbookImages; + (fileType == Scene) ? m_recentScenes : (fileType == Level) + ? m_recentLevels + : m_recentFlipbookImages; int i; for (i = 0; i < files.size(); i++) if (files.at(i) == path) { @@ -3636,9 +3621,9 @@ void RecentFiles::saveRecentFiles() { QList RecentFiles::getFilesNameList(FileType fileType) { QList files = - (fileType == Scene) - ? m_recentScenes - : (fileType == Level) ? m_recentLevels : m_recentFlipbookImages; + (fileType == Scene) ? m_recentScenes : (fileType == Level) + ? m_recentLevels + : m_recentFlipbookImages; QList names; int i; for (i = 0; i < files.size(); i++) { @@ -3665,9 +3650,9 @@ void RecentFiles::refreshRecentFilesMenu(FileType fileType) { menu->setEnabled(false); else { CommandId clearActionId = - (fileType == Scene) - ? MI_ClearRecentScene - : (fileType == Level) ? MI_ClearRecentLevel : MI_ClearRecentImage; + (fileType == Scene) ? MI_ClearRecentScene : (fileType == Level) + ? MI_ClearRecentLevel + : MI_ClearRecentImage; menu->setActions(names); menu->addSeparator(); QAction *clearAction = CommandManager::instance()->getAction(clearActionId); diff --git a/toonz/sources/toonz/menubar.cpp b/toonz/sources/toonz/menubar.cpp index 12a76068..b368e72e 100644 --- a/toonz/sources/toonz/menubar.cpp +++ b/toonz/sources/toonz/menubar.cpp @@ -453,25 +453,6 @@ QMenuBar *StackedMenuBar::createFullMenuBar() { addMenuItem(arrangeMenu, MI_SendBackward); } - // Menu' SCAN CLEANUP - QMenu *scanCleanupMenu = addMenu(tr("Scan && Cleanup"), fullMenuBar); - addMenuItem(scanCleanupMenu, MI_DefineScanner); - addMenuItem(scanCleanupMenu, MI_ScanSettings); - addMenuItem(scanCleanupMenu, MI_Scan); - addMenuItem(scanCleanupMenu, MI_SetScanCropbox); - addMenuItem(scanCleanupMenu, MI_ResetScanCropbox); - scanCleanupMenu->addSeparator(); - addMenuItem(scanCleanupMenu, MI_CleanupSettings); - addMenuItem(scanCleanupMenu, MI_CleanupPreview); - addMenuItem(scanCleanupMenu, MI_CameraTest); - addMenuItem(scanCleanupMenu, MI_Cleanup); - scanCleanupMenu->addSeparator(); - addMenuItem(scanCleanupMenu, MI_PencilTest); -#ifdef LINETEST - scanCleanupMenu->addSeparator(); - addMenuItem(scanCleanupMenu, MI_Autocenter); -#endif - // Menu' LEVEL QMenu *levelMenu = addMenu(tr("Level"), fullMenuBar); QMenu *newMenu = levelMenu->addMenu(tr("New")); @@ -645,6 +626,15 @@ QMenuBar *StackedMenuBar::createFullMenuBar() { renderMenu->addSeparator(); addMenuItem(renderMenu, MI_FastRender); + // Menu' SCAN CLEANUP + QMenu* scanCleanupMenu = addMenu(tr("Cleanup"), fullMenuBar); + addMenuItem(scanCleanupMenu, MI_CleanupSettings); + addMenuItem(scanCleanupMenu, MI_CleanupPreview); + addMenuItem(scanCleanupMenu, MI_CameraTest); + addMenuItem(scanCleanupMenu, MI_Cleanup); + scanCleanupMenu->addSeparator(); + addMenuItem(scanCleanupMenu, MI_PencilTest); + // Menu' VIEW QMenu *viewMenu = addMenu(tr("View"), fullMenuBar); addMenuItem(viewMenu, MI_ViewTable); diff --git a/toonz/sources/toonz/menubarcommandids.h b/toonz/sources/toonz/menubarcommandids.h index 2b394915..2c232d96 100644 --- a/toonz/sources/toonz/menubarcommandids.h +++ b/toonz/sources/toonz/menubarcommandids.h @@ -64,12 +64,6 @@ #define MI_Undo "MI_Undo" #define MI_Redo "MI_Redo" -#define MI_DefineScanner "MI_DefineScanner" -#define MI_ScanSettings "MI_ScanSettings" -#define MI_Scan "MI_Scan" -#define MI_Autocenter "MI_Autocenter" -#define MI_SetScanCropbox "MI_SetScanCropbox" -#define MI_ResetScanCropbox "MI_ResetScanCropbox" #define MI_CleanupSettings "MI_CleanupSettings" #define MI_CleanupPreview "MI_CleanupPreview" #define MI_CameraTest "MI_CameraTest" diff --git a/toonz/sources/toonz/scanpopup.cpp b/toonz/sources/toonz/scanpopup.cpp deleted file mode 100644 index bc40d3ae..00000000 --- a/toonz/sources/toonz/scanpopup.cpp +++ /dev/null @@ -1,1211 +0,0 @@ - - -#include "scanpopup.h" -#include "tapp.h" -#include "menubarcommandids.h" -#include "texception.h" -#include "mainwindow.h" -#include "tsystem.h" -#include "timagecache.h" -#include "tgl.h" -#include "tcurveutil.h" -#include "tpixelutils.h" -#include "trop.h" -#include "tiio.h" - -#include "toonz/tscenehandle.h" -#include "toonz/tframehandle.h" -#include "toonz/txshlevelhandle.h" -#include "toonz/toonzscene.h" -#include "toonz/observer.h" -#include "toonz/sceneproperties.h" -#include "toonz/txshsimplelevel.h" -#include "toonz/stage2.h" -#include "toonz/glrasterpainter.h" -#include "tools/toolutils.h" -#include "toonz/preferences.h" -#include "toonz/cleanupparameters.h" -#include "toonz/tcleanupper.h" - -#include "tools/toolhandle.h" -#include "tools/cursors.h" - -#include "toonzqt/menubarcommand.h" -#include "toonzqt/doublefield.h" -#include "toonzqt/checkbox.h" -#include "toonzqt/gutil.h" - -#include -#include -#include -#include -#include - -using namespace DVGui; -using namespace CleanupTypes; - -//----------------------------------------------------------------------------- -namespace { - -const double previewDPI = 64; -//----------------------------------------------------------------------------- - -const QString BlackAndWhite = "Black & White", Graytones = "Graytones", - Rgbcolors = "RGB Color"; - -bool ScannerHasBeenDefined = false; - -void checkPaperFormat(TScannerParameters *parameters) { - if (parameters->getPaperOverflow()) { - TScanner *scanner = TScanner::instance(); - QString scannerName = scanner ? scanner->getName() : "no scanner"; - DVGui::warning( - QObject::tr("The selected paper format is not available for %1.") - .arg(scannerName)); - } -} - -//----------------------------------------------------------------------------- - -bool defineScanner(const QString &scannerType) { - bool ret = false; - QApplication::setOverrideCursor(Qt::WaitCursor); - - TScanner::m_isTwain = (scannerType == "TWAIN"); - - try { - if (!TScanner::instance()->isDeviceAvailable()) { - DVGui::warning(TScanner::m_isTwain - ? QObject::tr("No TWAIN scanner is available") - : QObject::tr("No scanner is available")); - /* FIXME: try/catch からの goto -って合法じゃないだろ……。とりあえず応急処置したところ"例外ってナニ?"って感じになったのが -indent も腐っておりつらいので後で直す */ - // goto end; - QApplication::restoreOverrideCursor(); - return false; - } - TScanner::instance()->selectDevice(); - } catch (TException &e) { - DVGui::warning(QString::fromStdWString(e.getMessage())); - QApplication::restoreOverrideCursor(); - return false; - // goto end; - } - - TScannerParameters *scanParameters = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - try { - scanParameters->adaptToCurrentScanner(); - } catch (TException &e) { - DVGui::warning(QString::fromStdWString(e.getMessage())); - // goto end; - QApplication::restoreOverrideCursor(); - return false; - } - scanParameters->updatePaperFormat(); - checkPaperFormat(scanParameters); - // ScanSettingsPopup::instance()->updateUI(); - - ret = true; - - // end: - QApplication::restoreOverrideCursor(); - return ret; -} - -//----------------------------------------------------------------------------- - -bool checkScannerDefinition() { - if (!ScannerHasBeenDefined) { - QString scannerType = QSettings().value("CurrentScannerType").toString(); - if (scannerType == "") { - QSettings().setValue("CurrentScannerType", "Internal"); - scannerType = "Internal"; - } - ScannerHasBeenDefined = defineScanner(scannerType); - } - return ScannerHasBeenDefined; -} - -//----------------------------------------------------------------------------- - -void fillOutputType(QComboBox *t, TScannerParameters *params) { - while (t->count()) t->removeItem(0); - - if (params->isSupported(TScannerParameters::BW)) t->addItem(BlackAndWhite); - if (params->isSupported(TScannerParameters::GR8)) t->addItem(Graytones); - if (params->isSupported(TScannerParameters::RGB24)) t->addItem(Rgbcolors); -} - -//----------------------------------------------------------------------------- - -TPixelGR8 fromRGB(int r, int g, int b) { - return TPixelGR8( - (((UINT)(r)*19594 + (UINT)(g)*38472 + (UINT)(b)*7470 + (UINT)(1 << 15)) >> - 16)); -} - -//----------------------------------------------------------------------------- - -void makeTransparent(const TRaster32P &ras) { - if (!ras) return; - TRop::addBackground(ras, TPixel32::White); - int x, y; - for (x = 0; x < ras->getLx(); x++) { - for (y = 0; y < ras->getLy(); y++) { - TPixel32 *pix = &ras->pixels(y)[x]; - TPixelGR8 pixGR8 = fromRGB(pix->r, pix->g, pix->b); - int value = pixGR8.value; - pix->m = (UCHAR)tcrop(255 - value, 0, 255); - premult(*pix); - } - } -} - -//============================================================================= - -} // namepsapce - -//============================================================================= -/*! \class DefineScannerPopup - \brief The DefineScannerPopup class provides a modal dialog to - choose and define a scan for application. - - Inherits \b Dialog. -*/ -//----------------------------------------------------------------------------- - -DefineScannerPopup::DefineScannerPopup() - : Dialog(TApp::instance()->getMainWindow(), true, - Preferences::instance()->getCurrentLanguage() == "English", - "DefineScanner") { -#ifdef MACOSX - setModal(false); -#endif - setWindowTitle(tr("Define Scanner")); - - m_scanDriverOm = new QComboBox(); - m_scanDriverOm->setFixedSize(150, WidgetHeight); - QStringList scan; - scan << "TWAIN" - << "Internal"; - m_scanDriverOm->addItems(scan); - addWidget(tr("Scanner Driver:"), m_scanDriverOm); - - if (QSettings().value("CurrentScannerType").toString() == "Internal") - m_scanDriverOm->setCurrentIndex(1); - - QPushButton *okBtn = new QPushButton(tr("OK"), this); - okBtn->setDefault(true); - QPushButton *cancelBtn = new QPushButton(tr("Cancel"), this); - connect(okBtn, SIGNAL(clicked()), this, SLOT(accept())); - connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject())); - - addButtonBarWidget(okBtn, cancelBtn); -} - -//----------------------------------------------------------------------------- - -void DefineScannerPopup::accept() { - QString scannerType = m_scanDriverOm->currentText(); - - if (QSettings().value("CurrentScannerType").toString() != scannerType || - !ScannerHasBeenDefined) { - QSettings().setValue("CurrentScannerType", scannerType); - ScannerHasBeenDefined = defineScanner(scannerType); - QAction *setCropAction = - CommandManager::instance()->getAction("MI_SetScanCropbox"); - QAction *resetCropAction = - CommandManager::instance()->getAction("MI_ResetScanCropbox"); - if (scannerType == "TWAIN") - setCropAction->setDisabled(true); - else - setCropAction->setDisabled(false); - resetCropAction->setDisabled(true); - } - QDialog::accept(); -} - -//----------------------------------------------------------------------------- - -//============================================================================= -/*! \class ScanSettingsPopup - \brief The ScanSettingsPopup class provides a dialog to change - scan settings. - - Inherits \b Dialog. -*/ -//----------------------------------------------------------------------------- - -ScanSettingsPopup::ScanSettingsPopup() - : Dialog(TApp::instance()->getMainWindow(), false, true, "ScanSettings") { - setWindowTitle(tr("Scan Settings")); - m_scannerNameLbl = new QLabel(tr("[no scanner]")); - - addWidget(m_scannerNameLbl); - - beginVLayout(); - - m_paperFormatOm = new QComboBox(); - m_paperFormatOm->setFixedSize(150, WidgetHeight); - std::vector formats; - TPaperFormatManager::instance()->getFormats(formats); - int i; - for (i = 0; i < (int)formats.size(); i++) - m_paperFormatOm->addItem(QString(formats[i].c_str())); - addWidgets(m_formatLbl = new QLabel(tr("Paper Format:")), m_paperFormatOm); - - m_reverseOrderCB = new CheckBox(tr("Reverse Order")); - m_reverseOrderCB->setFixedSize(150, WidgetHeight); - addWidget(m_reverseOrderCB); - - m_paperFeederCB = new CheckBox(tr("Paper Feeder")); - m_paperFeederCB->setFixedSize(150, WidgetHeight); - addWidget(m_paperFeederCB); - - m_dpi = new DVGui::DoubleField(); - addWidgets(m_dpiLbl = new QLabel(tr("Dpi: ")), m_dpi); - m_dpi->hide(); - m_dpiLbl->hide(); - - m_modeOm = new QComboBox(); - m_modeOm->setMaximumHeight(WidgetHeight); - addWidgets(m_modeLbl = new QLabel(tr("Mode:")), m_modeOm); - - m_threshold = new DVGui::IntField(); - addWidgets(m_thresholdLbl = new QLabel(tr("Threshold: ")), m_threshold); - m_threshold->hide(), m_thresholdLbl->hide(); - - m_brightness = new DVGui::IntField(); - addWidgets(m_brightnessLbl = new QLabel(tr("Brightness: ")), m_brightness); - m_brightness->hide(), m_brightnessLbl->hide(); - - endVLayout(); - - connectAll(); -} - -//------------------------------------------------------------------------------ - -void ScanSettingsPopup::showEvent(QShowEvent *event) { - connectAll(); - updateUI(); -} - -//------------------------------------------------------------------------------ - -void ScanSettingsPopup::hideEvent(QHideEvent *event) { - disconnectAll(); - Dialog::hideEvent(event); -} - -//------------------------------------------------------------------------------ - -void ScanSettingsPopup::connectAll() { - bool ret = true; - ret = ret && - connect(m_paperFormatOm, SIGNAL(currentIndexChanged(const QString &)), - SLOT(onPaperChanged(const QString &))); - ret = ret && connect(m_reverseOrderCB, SIGNAL(stateChanged(int)), - SLOT(onToggle(int))); - ret = ret && connect(m_paperFeederCB, SIGNAL(stateChanged(int)), - SLOT(onToggle(int))); - ret = ret && - connect(m_dpi, SIGNAL(valueChanged(bool)), SLOT(onValueChanged(bool))); - ret = ret && connect(m_brightness, SIGNAL(valueChanged(bool)), - SLOT(onValueChanged(bool))); - ret = ret && connect(m_threshold, SIGNAL(valueChanged(bool)), - SLOT(onValueChanged(bool))); - ret = ret && connect(m_modeOm, SIGNAL(currentIndexChanged(const QString &)), - SLOT(onModeChanged(const QString &))); - ret = ret && connect(TApp::instance()->getCurrentScene(), - SIGNAL(sceneSwitched()), SLOT(updateUI())); - assert(ret); -} - -//------------------------------------------------------------------------------ - -void ScanSettingsPopup::disconnectAll() { - bool ret = true; - ret = ret && m_paperFormatOm->disconnect(); - ret = ret && m_reverseOrderCB->disconnect(); - ret = ret && m_paperFeederCB->disconnect(); - ret = ret && m_dpi->disconnect(); - ret = ret && m_threshold->disconnect(); - ret = ret && m_brightness->disconnect(); - ret = ret && m_modeOm->disconnect(); - ret = ret && disconnect(TApp::instance()->getCurrentScene(), - SIGNAL(sceneSwitched()), this, SLOT(updateUI())); - assert(ret); -} - -//------------------------------------------------------------------------------ - -void ScanSettingsPopup::onValueChanged(bool) { - TScannerParameters *params = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - params->m_dpi.m_value = m_dpi->getValue(); - params->m_threshold.m_value = m_threshold->getValue(); - params->m_brightness.m_value = m_brightness->getValue(); -} - -//------------------------------------------------------------------------------ - -void ScanSettingsPopup::onToggle(int) { - TScannerParameters *sp = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - - sp->setReverseOrder(m_reverseOrderCB->isChecked()); - sp->enablePaperFeeder(m_paperFeederCB->isChecked()); -} - -//----------------------------------------------------------------------------- - -void ScanSettingsPopup::onPaperChanged(const QString &format) { - if (!ScannerHasBeenDefined) return; - - TScannerParameters *sp = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - sp->setPaperFormat(format.toStdString()); - sp->setCropBox(sp->getScanArea()); - checkPaperFormat(sp); -} - -//------------------------------------------------------------------------------ - -void ScanSettingsPopup::onModeChanged(const QString &mode) { - if (!ScannerHasBeenDefined) return; - - TScannerParameters *sp = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - m_threshold->setVisible(false); - m_thresholdLbl->setVisible(false); - - if (mode == BlackAndWhite) { - sp->setScanType(TScannerParameters::BW); - m_threshold->setVisible(true); - m_thresholdLbl->setVisible(true); - } else if (mode == Graytones) - sp->setScanType(TScannerParameters::GR8); - else if (mode == Rgbcolors) - sp->setScanType(TScannerParameters::RGB24); - else { - // assert(0); - sp->setScanType(TScannerParameters::None); - } -} - -//------------------------------------------------------------------------------ - -void ScanSettingsPopup::updateUI() { - disconnectAll(); - checkScannerDefinition(); - TScannerParameters *params = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - QApplication::setOverrideCursor(Qt::WaitCursor); - params->adaptToCurrentScanner(); - QApplication::restoreOverrideCursor(); - - TScanner *scanner = TScanner::instance(); - m_scannerNameLbl->setText(scanner && scanner->getName() != "" - ? scanner->getName() - : "[no scanner]"); - - m_reverseOrderCB->setChecked(params->isReverseOrder()); - m_paperFeederCB->setChecked(params->m_paperFeeder.m_value == 1.0); - - if (params->m_dpi.m_supported) { - if (params->m_dpi.m_max > params->m_dpi.m_min) { - m_dpi->setRange(params->m_dpi.m_min, params->m_dpi.m_max); - m_dpi->setValue(params->m_dpi.m_value); - } - m_dpi->show(), m_dpiLbl->show(); - } else - m_dpi->hide(), m_dpiLbl->hide(); - - if (TScanner::m_isTwain) { - m_paperFeederCB->hide(); - m_modeOm->hide(), m_modeLbl->hide(); - m_paperFormatOm->hide(), m_formatLbl->hide(); - m_threshold->hide(), m_thresholdLbl->hide(); - m_brightness->hide(), m_brightnessLbl->hide(); - connectAll(); - return; - } - m_paperFeederCB->show(); - m_modeOm->show(), m_modeLbl->show(); - m_paperFormatOm->show(), m_formatLbl->show(); - - disconnect(m_modeOm); - fillOutputType(m_modeOm, params); - connect(m_modeOm, SIGNAL(currentIndexChanged(const QString &)), - SLOT(onModeChanged(const QString &))); - - m_modeOm->setEnabled(true); - switch (params->getScanType()) { - case TScannerParameters::BW: - m_modeOm->setCurrentIndex(m_modeOm->findText(BlackAndWhite)); - break; - case TScannerParameters::GR8: - m_modeOm->setCurrentIndex(m_modeOm->findText(Graytones)); - break; - case TScannerParameters::RGB24: - m_modeOm->setCurrentIndex(m_modeOm->findText(Rgbcolors)); - break; - default: - m_modeOm->setEnabled(false); - break; - } - - m_paperFormatOm->setCurrentIndex(m_paperFormatOm->findText( - QString::fromStdString(params->getPaperFormat()))); - - if (params->m_threshold.m_supported) { - m_threshold->setRange(params->m_threshold.m_min, params->m_threshold.m_max); - m_threshold->setValue(params->m_threshold.m_value); - if (params->getScanType() == TScannerParameters::BW) { - m_threshold->show(); - m_thresholdLbl->show(); - } else { - m_threshold->hide(); - m_thresholdLbl->hide(); - } - } - if (params->m_brightness.m_supported) { - if (params->m_brightness.m_max > params->m_brightness.m_min) { - m_brightness->setRange(params->m_brightness.m_min, - params->m_brightness.m_max); - m_brightness->setValue(params->m_brightness.m_value); - } - m_brightness->show(), m_brightnessLbl->show(); - } else - m_brightness->hide(), m_brightnessLbl->hide(); - - connectAll(); -} -#ifdef LINETEST -//----------------------------------------------------------------------------- - -AutocenterPopup::AutocenterPopup() : DVGui::Dialog(0, false, true) { - setWindowTitle(tr("Autocenter")); - - QGridLayout *settingsLayout = new QGridLayout(this); - settingsLayout->setSizeConstraint(QLayout::SetFixedSize); - settingsLayout->setSpacing(5); - settingsLayout->setMargin(12); - int row = 0; - - // AutoCenter - QWidget *w = new QWidget(); - w->setFixedWidth(70); - settingsLayout->addWidget(w, row, 0); - m_autocenter = new CheckBox(tr("Autocenter"), this); - m_autocenter->setFixedSize(150, WidgetHeight); - settingsLayout->addWidget(m_autocenter, row, 1, Qt::AlignLeft); - ++row; - - // Pegbar Holse - settingsLayout->addWidget(new QLabel(tr("Pegbar Holes:")), row, 0, - Qt::AlignRight); - m_pegbarHoles = new QComboBox(this); - m_pegbarHoles->setFixedHeight(WidgetHeight); - m_pegbarHoles->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Maximum); - QStringList pegbarHoles; - pegbarHoles << "Bottom" - << "Top" - << "Left" - << "Right"; - m_pegbarHoles->addItems(pegbarHoles); - settingsLayout->addWidget(m_pegbarHoles, row, 1, Qt::AlignLeft); - ++row; - - // Feld Guide - settingsLayout->addWidget(new QLabel(tr("Field Guide:")), row, 0, - Qt::AlignRight); - m_fieldGuide = new QComboBox(this); - m_fieldGuide->setFixedHeight(WidgetHeight); - m_fieldGuide->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Maximum); - std::vector fdgNames; - CleanupParameters::getFdgNames(fdgNames); - int i; - for (i = 0; i < (int)fdgNames.size(); i++) - m_fieldGuide->addItem(QString(fdgNames[i].c_str())); - settingsLayout->addWidget(m_fieldGuide, row, 1, Qt::AlignLeft); - ++row; - - beginHLayout(); - addLayout(settingsLayout, false); - endHLayout(); - - bool ret = true; - ret = ret && connect(m_autocenter, SIGNAL(toggled(bool)), this, - SLOT(onAutocenterToggled(bool))); - ret = ret && - connect(m_pegbarHoles, SIGNAL(currentIndexChanged(const QString &)), - this, SLOT(onPegbarHolesChanged(const QString &))); - ret = - ret && connect(m_fieldGuide, SIGNAL(currentIndexChanged(const QString &)), - this, SLOT(onFieldGuideChanged(const QString &))); - assert(ret); -} - -//----------------------------------------------------------------------------- - -void AutocenterPopup::showEvent(QShowEvent *e) { - CleanupParameters *cp = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getCleanupParameters(); - m_autocenter->setChecked(cp->m_autocenterType == AUTOCENTER_FDG); - - CleanupTypes::PEGS_SIDE type = cp->m_pegSide; - switch (cp->m_pegSide) { - case PEGS_BOTTOM: - m_pegbarHoles->setCurrentIndex(0); - break; - case PEGS_TOP: - m_pegbarHoles->setCurrentIndex(1); - break; - case PEGS_LEFT: - m_pegbarHoles->setCurrentIndex(2); - break; - case PEGS_RIGHT: - m_pegbarHoles->setCurrentIndex(3); - break; - default: - assert(false); - } - - QString fieldName = QString::fromStdString(cp->getFdgName()); - int index = (fieldName == "") ? 0 : m_fieldGuide->findText(fieldName); - assert(index != -1); - m_fieldGuide->setCurrentIndex(index); -} - -//----------------------------------------------------------------------------- - -void AutocenterPopup::onAutocenterToggled(bool toggled) { - CleanupParameters *cp = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getCleanupParameters(); - cp->m_autocenterType = toggled ? AUTOCENTER_FDG : AUTOCENTER_NONE; -} - -//----------------------------------------------------------------------------- - -void AutocenterPopup::onPegbarHolesChanged(const QString &pg) { - CleanupParameters *cp = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getCleanupParameters(); - CleanupTypes::PEGS_SIDE type; - if (pg == "Bottom") type = PEGS_BOTTOM; - if (pg == "Top") type = PEGS_TOP; - if (pg == "Left") type = PEGS_LEFT; - if (pg == "Right") type = PEGS_RIGHT; - if (cp->m_pegSide == type) return; - cp->m_pegSide = type; -} - -//----------------------------------------------------------------------------- - -void AutocenterPopup::onFieldGuideChanged(const QString &fg) { - CleanupParameters *cp = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getCleanupParameters(); - if (cp->getFdgName() == fg.toStdString()) return; - cp->setFdgByName(fg.toStdString()); -} - -//----------------------------------------------------------------------------- -#endif - -MyScannerListener::MyScannerListener(const ScanList &scanList) - : m_scanList(scanList) - , m_current(0) - , m_inc(+1) - , m_isCanceled(false) - , m_progressDialog(0) { - TScannerParameters *parameters = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - - m_isPreview = parameters->isPreview(); - if (m_isPreview) return; - if (parameters->isPaperFeederEnabled()) { - int frameCount = m_scanList.getFrameCount(); - ScanListFrame frame = m_scanList.getFrame(m_current); - TXshSimpleLevel *newXl = frame.getLevel(); - TFilePath levelName(newXl->getName()); - QString imageName = - toQString(levelName.withFrame(frame.getFrameId())) + QString(".tif"); - QString text = tr("Scanning in progress: ") + imageName + " 1/" + - QString::number(frameCount); - m_progressDialog = - new DVGui::ProgressDialog(text, QObject::tr("Cancel"), 0, frameCount); - connect(m_progressDialog, SIGNAL(canceled()), this, - SLOT(cancelButtonPressed())); - m_progressDialog->setWindowModality(Qt::WindowModal); - m_progressDialog->show(); - } - if (parameters->isReverseOrder()) { - m_current = m_scanList.getFrameCount() - 1; - m_inc = -1; - } -} - -//----------------------------------------------------------------------------- - -void MyScannerListener::onImage(const TRasterImageP &rasImg) { - if (!rasImg || !rasImg->getRaster()) { - DVGui::warning(tr("The pixel type is not supported.")); - m_current += m_inc; - return; - } - if (!m_isPreview && - (m_current < 0 || m_current >= m_scanList.getFrameCount())) { - DVGui::warning(tr("The scanning process is completed.")); - return; - } - if (m_isPreview) { - TImageCache::instance()->add((std::string) "setScanCropboxId", - rasImg.getPointer()); - } else { -#ifdef LINETEST - // Autocenter - CleanupParameters *cp = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getCleanupParameters(); - if (cp->m_autocenterType != AUTOCENTER_NONE) { - bool autocentered; - TCleanupper *cl = TCleanupper::instance(); - cl->setParameters(cp); - TRasterImageP outImg = cl->autocenterOnly(rasImg, false, autocentered); - if (!autocentered) - DVGui::warning( - QObject::tr("The autocentering failed on the current drawing.")); - else - rasImg->setRaster(outImg->getRaster()); - } - makeTransparent(rasImg->getRaster()); -#endif - TScannerParameters *params = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - - ScanListFrame frame = m_scanList.getFrame(m_current); - bool isBW = false; - if (params->getScanType() == TScannerParameters::BW) { - isBW = true; - rasImg->setScanBWFlag(true); - Tiio::Writer::setBlackAndWhiteThreshold(params->m_threshold.m_value); - } - frame.setRasterImage(rasImg, isBW); - - TApp::instance()->getCurrentFrame()->setFid(frame.getFrameId()); - TApp::instance()->getCurrentScene()->notifyCastChange(); - TApp::instance()->getCurrentLevel()->notifyLevelChange(); - - m_current += m_inc; - } -} - -//----------------------------------------------------------------------------- - -void MyScannerListener::onError() { - if (m_progressDialog) m_progressDialog->hide(); - DVGui::warning(tr("There was an error during the scanning process.")); -} - -//----------------------------------------------------------------------------- - -void MyScannerListener::onNextPaper() { - assert(!m_isPreview); - if (TScanner::instance()->m_isTwain) - DVGui::info( - tr("Please, place the next paper drawing on the scanner flatbed, then " - "select the relevant command in the TWAIN interface.")); - else { - QString question( - tr("Please, place the next paper drawing on the scanner flatbed, then " - "click the Scan button.")); - int ret = - DVGui::MsgBox(question, QObject::tr("Scan"), QObject::tr("Cancel"), 0); - if (ret == 2 || ret == 0) m_isCanceled = true; - } -} - -//----------------------------------------------------------------------------- - -void MyScannerListener::onAutomaticallyNextPaper() { - assert(!m_isPreview); - assert(!!m_progressDialog); - int frameCount = m_scanList.getFrameCount(); - int step = m_inc == -1 ? frameCount - m_current - 1 : m_current; - if (step < frameCount) { - ScanListFrame frame = m_scanList.getFrame(m_current); - TXshSimpleLevel *newXl = frame.getLevel(); - TFilePath levelName(newXl->getName()); - QString imageName = - toQString(levelName.withFrame(frame.getFrameId())) + QString(".tif"); - m_progressDialog->setLabelText(tr("Scanning in progress: ") + imageName + - QString::number(m_current + 1) + " /" + - QString::number(frameCount)); - } - m_progressDialog->setValue(step); - if (m_progressDialog && (step == frameCount)) m_progressDialog->hide(); -} - -//----------------------------------------------------------------------------- - -bool MyScannerListener::isCanceled() { return m_isCanceled; } - -//----------------------------------------------------------------------------- - -void MyScannerListener::cancelButtonPressed() { - assert(!!m_progressDialog); - m_isCanceled = true; -} - -//============================================================================= -// -static void doScan() { - if (!checkScannerDefinition()) return; - ScanList scanList; - if (scanList.areScannedFramesSelected()) { - int ret = DVGui::MsgBox( - QObject::tr("Some of the selected drawings were already scanned. Do " - "you want to scan them again?"), - QObject::tr("Scan"), QObject::tr("Don't Scan"), QObject::tr("Cancel")); - if (ret == 3) return; - scanList.update(ret == 1); - } else - scanList.update(true); - - if (scanList.getFrameCount() == 0) { - DVGui::warning(QObject::tr("There are no frames to scan.")); - return; - } - - try { - TScanner *scanner = TScanner::instance(); - - int rc = scanner->isDeviceAvailable(); - if (!rc) { - DVGui::warning(QObject::tr("TWAIN is not available.")); - return; - } - - MyScannerListener lst(scanList); - scanner->addListener(&lst); - - TScannerParameters *sp = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - sp->adaptToCurrentScannerIfNeeded(); - scanner->acquire(*sp, scanList.getFrameCount()); - scanner->removeListener(&lst); - - SetScanCropboxCheck *cropboxCheck = SetScanCropboxCheck::instance(); - if (cropboxCheck->isEnabled()) cropboxCheck->uncheck(); - } catch (TException &e) { - DVGui::warning(QString::fromStdWString(e.getMessage())); - } - - // If some levels were scanned successfully, their renumber table must be - // updated. - - // A level's renumber table is usually updated when it is either loaded or - // before saving - - // this is a similar case, where a level is filled with frames. - // An empty renumber table means that a renumbering operation was carried out - // with all frames - // being eradicated - which may lead to the level being saved with missing - // frames. - int i, frameCount = scanList.getFrameCount(); - TXshSimpleLevel *oldLevel = 0, *level; - for (i = 0; i < frameCount; ++i) { - level = scanList.getFrame(i).getLevel(); - if (level != oldLevel) level->setRenumberTable(); - oldLevel = level; - } -} - -//----------------------------------------------------------------------------- - -OpenPopupCommandHandler openDefineScannerPopup( - MI_DefineScanner); - -OpenPopupCommandHandler openScanSettingsPopup( - MI_ScanSettings); - -#ifdef LINETEST -OpenPopupCommandHandler openAutocenterPopup(MI_Autocenter); -#endif - -class ScanCommand final : public MenuItemHandler { -public: - ScanCommand() : MenuItemHandler("MI_Scan") {} - void execute() override { doScan(); } -} ScanCommand; - -//========================================================================================= -// -// SetCropboxCommand -// -//========================================================================================= - -class SetCropboxCommand final : public MenuItemHandler { - TTool *m_currentTool; - -public: - SetCropboxCommand() - : MenuItemHandler("MI_SetScanCropbox"), m_currentTool(0) {} - - void execute() override { - TApp *app = TApp::instance(); - SetScanCropboxCheck *cropboxCheck = SetScanCropboxCheck::instance(); - cropboxCheck->setIsEnabled(!cropboxCheck->isEnabled()); - - TScannerParameters *sp = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - QAction *resetCropAction = - CommandManager::instance()->getAction("MI_ResetScanCropbox"); - if (!cropboxCheck->isEnabled()) { - if (m_currentTool) - app->getCurrentTool()->setTool( - QString::fromStdString(m_currentTool->getName())); - return; - } - - if (!checkScannerDefinition()) return; - ScanList scanList; - scanList.update(true); - try { - TScanner *scanner = TScanner::instance(); - - int rc = scanner->isDeviceAvailable(); - if (!rc) { - DVGui::warning(QObject::tr("TWAIN is not available.")); - return; - } - - double currentDPI = sp->m_dpi.m_value; - sp->m_dpi.m_value = previewDPI; - double reverse = sp->isReverseOrder(); - sp->setReverseOrder(false); - sp->setIsPreview(true); - - MyScannerListener lst(scanList); - scanner->addListener(&lst); - - sp->adaptToCurrentScannerIfNeeded(); - scanner->acquire(*sp, 1); - scanner->removeListener(&lst); - sp->m_dpi.m_value = currentDPI; - sp->setReverseOrder(reverse); - - m_currentTool = app->getCurrentTool()->getTool(); - app->getCurrentTool()->setTool("T_SetScanCropbox"); - sp->setIsPreview(false); - if (resetCropAction) resetCropAction->setDisabled(false); - } catch (TException &e) { - DVGui::warning(QString::fromStdWString(e.getMessage())); - } - } -} setCropboxCommand; - -//========================================================================================= -// -// ResetCropboxCommand -// -//========================================================================================= - -class ResetCropboxCommand final : public MenuItemHandler { -public: - ResetCropboxCommand() : MenuItemHandler("MI_ResetScanCropbox") {} - - void execute() override { - TScannerParameters *sp = TApp::instance() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - sp->setCropBox(sp->getScanArea()); - } -} resetCropboxCommand; - -//========================================================================================= -// -// SetScanCropboxTool -// -//========================================================================================= - -class SetScanCropboxTool final : public TTool { - const std::string m_imgId; - TScannerParameters *m_parameters; - int m_scaling; - TPointD m_lastPos; - enum { eNone, eMove, e00, e01, e10, e11, eM0, e1M, eM1, e0M }; - -public: - SetScanCropboxTool() - : TTool("T_SetScanCropbox") - , m_imgId("setScanCropboxId") - , m_scaling(eNone) - , m_lastPos() { - bind(TTool::AllTargets); // Deals with tool deactivation internally - } - - //----------------------------------------------------------------------------- - - ToolType getToolType() const override { return TTool::GenericTool; } - - //----------------------------------------------------------------------------- - - void draw() override { - TRasterImageP ri = TImageCache::instance()->get(m_imgId, false); - if (ri) { - TPointD center = ri->getRaster()->getCenterD(); - GLRasterPainter::drawRaster( - TScale(Stage::inch / previewDPI, Stage::inch / previewDPI), ri, true); - } - - TRectD cropBox = rect2pix(m_parameters->getCropBox()); - double pixelSize = getPixelSize(); - - tglColor(TPixel::Red); - glLineStipple(1, 0xFFFF); - glEnable(GL_LINE_STIPPLE); - - tglDrawRect(cropBox); - - TPointD size(10, 10); - tglColor(TPixel::Red); - ToolUtils::drawSquare(cropBox.getP00(), pixelSize * 4, TPixel::Red); - ToolUtils::drawSquare(cropBox.getP01(), pixelSize * 4, TPixel::Red); - ToolUtils::drawSquare(cropBox.getP10(), pixelSize * 4, TPixel::Red); - ToolUtils::drawSquare(cropBox.getP11(), pixelSize * 4, TPixel::Red); - - TPointD center = (cropBox.getP00() + cropBox.getP11()) * 0.5; - - ToolUtils::drawSquare(TPointD(center.x, cropBox.y0), pixelSize * 4, - TPixel::Red); // draw M0 handle - ToolUtils::drawSquare(TPointD(cropBox.x1, center.y), pixelSize * 4, - TPixel::Red); // draw 1M handle - ToolUtils::drawSquare(TPointD(center.x, cropBox.y1), pixelSize * 4, - TPixel::Red); // draw M1 handle - ToolUtils::drawSquare(TPointD(cropBox.x0, center.y), pixelSize * 4, - TPixel::Red); // draw 0M handle - - glDisable(GL_LINE_STIPPLE); - } - - //----------------------------------------------------------------------------- - - void mouseMove(const TPointD &p, const TMouseEvent &e) override { - double pixelSize = getPixelSize(); - TPointD size(10 * pixelSize, 10 * pixelSize); - TRectD cropBox = rect2pix(m_parameters->getCropBox()); - - double maxDist = 5 * pixelSize; - - if (TRectD(cropBox.getP00() - size, cropBox.getP00() + size).contains(p)) - m_scaling = e00; - else if (TRectD(cropBox.getP01() - size, cropBox.getP01() + size) - .contains(p)) - m_scaling = e01; - else if (TRectD(cropBox.getP11() - size, cropBox.getP11() + size) - .contains(p)) - m_scaling = e11; - else if (TRectD(cropBox.getP10() - size, cropBox.getP10() + size) - .contains(p)) - m_scaling = e10; - else if (isCloseToSegment(p, TSegment(cropBox.getP00(), cropBox.getP10()), - maxDist)) - m_scaling = eM0; - else if (isCloseToSegment(p, TSegment(cropBox.getP10(), cropBox.getP11()), - maxDist)) - m_scaling = e1M; - else if (isCloseToSegment(p, TSegment(cropBox.getP11(), cropBox.getP01()), - maxDist)) - m_scaling = eM1; - else if (isCloseToSegment(p, TSegment(cropBox.getP01(), cropBox.getP00()), - maxDist)) - m_scaling = e0M; - else if (cropBox.contains(p)) - m_scaling = eMove; - else - m_scaling = eNone; - } - - //----------------------------------------------------------------------------- - - void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override { - m_lastPos = pos; - } - - //----------------------------------------------------------------------------- - - void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override { - TPointD dp = pos - m_lastPos; - double scaleFactor = Stage::inch / previewDPI; - dp.x = ((dp.x / scaleFactor) * 25.4) / previewDPI; - dp.y = ((dp.y / scaleFactor) * 25.4) / previewDPI; - - TRectD scanArea = m_parameters->getScanArea(); - TRectD cropBox = m_parameters->getCropBox(); - if (m_scaling != eNone && m_scaling != eMove) { - if ((m_scaling == eM1 || - ((m_scaling == e11 || m_scaling == e01) && !e.isShiftPressed())) && - cropBox.x0 - dp.y < cropBox.x1) - cropBox.x0 -= dp.y; - if ((m_scaling == eM0 || - ((m_scaling == e10 || m_scaling == e00) && !e.isShiftPressed())) && - cropBox.x1 - dp.y > cropBox.x0) - cropBox.x1 -= dp.y; - if ((m_scaling == e0M || - ((m_scaling == e00 || m_scaling == e01) && !e.isShiftPressed())) && - cropBox.y1 - dp.x > cropBox.y0) - cropBox.y1 -= dp.x; - if ((m_scaling == e1M || - ((m_scaling == e11 || m_scaling == e10) && !e.isShiftPressed())) && - cropBox.y0 - dp.x < cropBox.y1) - cropBox.y0 -= dp.x; - - if (e.isShiftPressed()) { - TPointD delta; - delta.x = (fabs(dp.x) > fabs(dp.y)) ? dp.x : dp.y; - delta.y = delta.x * scanArea.getLx() / scanArea.getLy(); - - if (m_scaling == e11) { - if (cropBox.y0 - delta.x < cropBox.y1) cropBox.y0 -= delta.x; - if (cropBox.x0 - delta.y < cropBox.x1) cropBox.x0 -= delta.y; - } else if (m_scaling == e00) { - if (cropBox.y1 - delta.x > cropBox.y0) cropBox.y1 -= delta.x; - if (cropBox.x1 - delta.y > cropBox.x0) cropBox.x1 -= delta.y; - } else if (m_scaling == e01) { - if (cropBox.y1 - delta.x > cropBox.y0) cropBox.y1 -= delta.x; - if (cropBox.x0 - delta.y < cropBox.x1) cropBox.x0 -= delta.y; - } - if (m_scaling == e10) { - if (cropBox.y0 - delta.x < cropBox.y1) cropBox.y0 -= delta.x; - if (cropBox.x1 - delta.y > cropBox.x0) cropBox.x1 -= delta.y; - } - } - cropBox *= scanArea; - if (cropBox != m_parameters->getCropBox()) { - m_parameters->setCropBox(cropBox); - m_lastPos = pos; - } - } else if (m_scaling == eMove) { - cropBox += TPointD(-dp.y, 0); - if (scanArea.contains(cropBox)) m_parameters->setCropBox(cropBox); - cropBox += TPointD(0, -dp.x); - if (scanArea.contains(cropBox)) m_parameters->setCropBox(cropBox); - m_lastPos = pos; - } - invalidate(); - } - - //----------------------------------------------------------------------------- - - int getCursorId() const override { - switch (m_scaling) { - case eNone: - return ToolCursor::StrokeSelectCursor; - case eMove: - return ToolCursor::MoveCursor; - case e11: - case e00: - return ToolCursor::ScaleCursor; - case e10: - case e01: - return ToolCursor::ScaleInvCursor; - case e1M: - case e0M: - return ToolCursor::ScaleHCursor; - case eM1: - case eM0: - return ToolCursor::ScaleVCursor; - default: - assert(false); - } - return 0; - } - - //----------------------------------------------------------------------------- - - void onActivate() override { - m_parameters = TTool::getApplication() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - } - - void onEnter() override { - m_parameters = TTool::getApplication() - ->getCurrentScene() - ->getScene() - ->getProperties() - ->getScanParameters(); - } - - //----------------------------------------------------------------------------- - -private: - TRectD rect2pix(const TRectD &rect) { - const double f = 25.4; - TRectD scanArea = m_parameters->getScanArea(); - TPointD scanAreaCenter = (scanArea.getP00() + scanArea.getP11()) * 0.5; - double scaleFactor = Stage::inch / previewDPI; - - double cbOffsetx = - (((rect.x0 - scanAreaCenter.x) * previewDPI) / f) * scaleFactor; - double cbOffsety = - (((rect.y0 - scanAreaCenter.y) * previewDPI) / f) * scaleFactor; - double cbSizelx = (((rect.x1 - rect.x0) * previewDPI) / f) * scaleFactor; - double cbSizely = (((rect.y1 - rect.y0) * previewDPI) / f) * scaleFactor; - - TRectD rectPix(TPointD(cbOffsetx, cbOffsety), - TDimensionD(cbSizelx, cbSizely)); - return TRectD(-rectPix.y1, -rectPix.x1, -rectPix.y0, -rectPix.x0); - } -} setScanCropboxTool; diff --git a/toonz/sources/toonz/scanpopup.h b/toonz/sources/toonz/scanpopup.h deleted file mode 100644 index aa133cc0..00000000 --- a/toonz/sources/toonz/scanpopup.h +++ /dev/null @@ -1,120 +0,0 @@ -#pragma once - -#ifndef SCANPOPUP_H -#define SCANPOPUP_H - -#include "toonzqt/dvdialog.h" -#include "tscanner.h" -#include "scanlist.h" - -// forward declaration -namespace DVGui { -class DoubleField; -class IntField; -class CheckBox; -} - -class QComboBox; -class ProgressDialog; - -//============================================================================= -// MyScannerListener -//----------------------------------------------------------------------------- - -class MyScannerListener final : public QObject, public TScannerListener { - Q_OBJECT - - int m_current; - int m_inc; - ScanList m_scanList; - bool m_isCanceled, m_isPreview; - DVGui::ProgressDialog *m_progressDialog; - -public: - MyScannerListener(const ScanList &scanList); - void onImage(const TRasterImageP &) override; - void onError() override; - void onNextPaper() override; - void onAutomaticallyNextPaper() override; - bool isCanceled() override; - -protected slots: - void cancelButtonPressed(); -}; - -//============================================================================= -// DefineScannerPopup -//----------------------------------------------------------------------------- - -class DefineScannerPopup final : public DVGui::Dialog { - Q_OBJECT - QComboBox *m_scanDriverOm; - -public: - DefineScannerPopup(); - -public slots: - void accept() override; -}; - -//============================================================================= -// ScanSettingsPopup -//----------------------------------------------------------------------------- - -class ScanSettingsPopup final : public DVGui::Dialog { - Q_OBJECT - QLabel *m_scannerNameLbl; - DVGui::CheckBox *m_reverseOrderCB; - DVGui::CheckBox *m_paperFeederCB; - QComboBox *m_modeOm; - DVGui::DoubleField *m_dpi; - DVGui::IntField *m_threshold; - DVGui::IntField *m_brightness; - QComboBox *m_paperFormatOm; - QLabel *m_formatLbl; - QLabel *m_modeLbl; - QLabel *m_thresholdLbl; - QLabel *m_brightnessLbl; - QLabel *m_dpiLbl; - -public: - ScanSettingsPopup(); - -protected: - void showEvent(QShowEvent *event) override; - void hideEvent(QHideEvent *event) override; - void connectAll(); - void disconnectAll(); - -public slots: - void updateUI(); - void onToggle(int); - void onPaperChanged(const QString &format); - void onValueChanged(bool); - void onModeChanged(const QString &mode); -}; - -#ifdef LINETEST -//============================================================================= -// AutocenterPopup -//----------------------------------------------------------------------------- - -class AutocenterPopup final : public DVGui::Dialog { - Q_OBJECT - DVGui::CheckBox *m_autocenter; - QComboBox *m_pegbarHoles; - QComboBox *m_fieldGuide; - -public: - AutocenterPopup(); - -protected: - void showEvent(QShowEvent *event); - -protected slots: - void onAutocenterToggled(bool); - void onPegbarHolesChanged(const QString &); - void onFieldGuideChanged(const QString &); -}; -#endif // LINETEST -#endif // SCANPOPUP_H diff --git a/toonz/sources/toonzlib/sceneproperties.cpp b/toonz/sources/toonzlib/sceneproperties.cpp index 5ff4c41f..1c432eeb 100644 --- a/toonz/sources/toonzlib/sceneproperties.cpp +++ b/toonz/sources/toonzlib/sceneproperties.cpp @@ -15,7 +15,6 @@ // TnzBase includes #include "toutputproperties.h" #include "trasterfx.h" -#include "tscanner.h" // TnzCore includes #include "tstream.h" @@ -27,7 +26,6 @@ TSceneProperties::TSceneProperties() : m_cleanupParameters(new CleanupParameters()) - , m_scanParameters(new TScannerParameters()) , m_vectorizerParameters(new VectorizerParameters()) , m_captureParameters(new CaptureParameters()) , m_outputProp(new TOutputProperties()) @@ -55,7 +53,6 @@ TSceneProperties::TSceneProperties() TSceneProperties::~TSceneProperties() { delete m_cleanupParameters; - delete m_scanParameters; delete m_vectorizerParameters; delete m_captureParameters; clearPointerContainer(m_cameras); @@ -74,7 +71,6 @@ void TSceneProperties::assign(const TSceneProperties *sprop) { *m_previewProp = *sprop->m_previewProp; m_cleanupParameters->assign(sprop->m_cleanupParameters); - m_scanParameters->assign(sprop->m_scanParameters); assert(sprop->m_vectorizerParameters); *m_vectorizerParameters = *sprop->m_vectorizerParameters; @@ -303,9 +299,6 @@ void TSceneProperties::saveData(TOStream &os) const { os.openChild("cleanupParameters"); m_cleanupParameters->saveData(os); os.closeChild(); - os.openChild("scanParameters"); - m_scanParameters->saveData(os); - os.closeChild(); os.openChild("vectorizerParameters"); m_vectorizerParameters->saveData(os); os.closeChild(); @@ -681,9 +674,6 @@ void TSceneProperties::loadData(TIStream &is, bool isLoadingProject) { m_cleanupParameters->m_cleanupPalette->loadData(is); } else if (tagName == "cleanupParameters") { m_cleanupParameters->loadData(is, !isLoadingProject); - } else if (tagName == "scanParameters") { - // m_scanParameters->adaptToCurrentScanner(); Rallenta tutto!!! - m_scanParameters->loadData(is); } else if (tagName == "vectorizerParameters") { m_vectorizerParameters->loadData(is); } else if (tagName == "captureParameters") { diff --git a/toonz/sources/toonzlib/stage2.cpp b/toonz/sources/toonzlib/stage2.cpp index 345a9f31..626bd1d5 100644 --- a/toonz/sources/toonzlib/stage2.cpp +++ b/toonz/sources/toonzlib/stage2.cpp @@ -114,39 +114,3 @@ void CleanupPreviewCheck::setIsEnabled(bool on) { //----------------------------------------------------------------------------- void CleanupPreviewCheck::setToggle(QAction *toggle) { m_toggle = toggle; } - -//============================================================================= -/*! \class SetScanCropBoxCheck - \brief The SetScanCropBoxCheck class allows visualization in - "Set Crop Box" mode, from scan menu -*/ -//============================================================================= - -SetScanCropboxCheck::SetScanCropboxCheck() : m_enabled(false), m_toggle(0) {} - -//----------------------------------------------------------------------------- - -/*! Return current \b SetScanCropBoxCheck instance. -*/ -SetScanCropboxCheck *SetScanCropboxCheck::instance() { - static SetScanCropboxCheck _instance; - return &_instance; -} - -//----------------------------------------------------------------------------- - -void SetScanCropboxCheck::setToggle(QAction *toggle) { m_toggle = toggle; } - -//----------------------------------------------------------------------------- - -void SetScanCropboxCheck::setIsEnabled(bool on) { - if (!m_toggle) return; - m_enabled = on; - m_toggle->setChecked(on); -} - -//----------------------------------------------------------------------------- - -void SetScanCropboxCheck::uncheck() { - if (isEnabled()) m_toggle->trigger(); -} diff --git a/toonz/sources/toonzqt/paramfield.cpp b/toonz/sources/toonzqt/paramfield.cpp index 754c1d24..ea129fe6 100644 --- a/toonz/sources/toonzqt/paramfield.cpp +++ b/toonz/sources/toonzqt/paramfield.cpp @@ -22,6 +22,7 @@ #include #include #include +#include using namespace DVGui;