LEADTOOLS TWAIN C DLL Help > Function References > L_TwainFindFastConfig |
#include "lttwn.h"
L_LTTWN_API L_INT L_TwainFindFastConfig(hSession, pszWorkingFolder, uFlags, nBitsPerPixel, nBufferIteration, pInFastConfigs, nInFastConfigsCount, ppTestConfigs, pnTestConfigsCount, pOutBestConfig, uStructSize, pfnCallBack, pUserData)
HTWAINSESSION hSession; |
/* handle to an existing TWAIN session */ |
L_TCHAR * pszWorkingFolder; |
/* working folder path */ |
L_UINT uFlags; |
/* option flags */ |
L_INT nBitsPerPixel; |
/* bits per pixel */ |
L_INT nBufferIteration; |
/* buffer iteration count */ |
pFASTCONFIG pInFastConfigs; |
/* pointer to a structure */ |
L_INT nInFastConfigsCount; |
/* number of array elements */ |
pFASTCONFIG *ppTestConfigs; |
/* pointer to a pointer to a structure */ |
L_INT *pnTestConfigsCount; |
/* number of scan configurations tested */ |
pFASTCONFIG pOutBestConfig; |
/* pointer to a structure */ |
L_UINT uStructSize; |
/* size in bytes, of the structure pointed to by pltProperties */ |
LTWAINFINDFASTCONFIG pfnCallBack; |
/* optional callback function */ |
L_VOID *pUserData; |
/* pointer to more parameters for the callback */ |
Determines the best scanner configuration.
Parameter |
Description |
|
hSession |
Handle to an existing TWAIN session. This handle is obtained by calling the L_TwainInitSession function. |
|
pszWorkingFolder |
Character string containing the path to the working folder in which to save the tested images. |
|
uFlags |
Flags that control the display of the user interface and the actions of the function. Possible values are: |
|
|
Value |
Meaning |
|
LTWAIN_SHOW_USER_INTERFACE |
[0x0001] Shows the manufacturer's user interface as modeless. |
|
LTWAIN_MODAL_USER_INTERFACE |
[0x0002] Shows the manufacturer's user interface as a modal dialog. Works only if the LTWAIN_SHOW_USER_INTERFACE flag is set. |
|
LTWAIN_USE_THREAD_MODE |
[0x0008] Use the fast Thread mode. |
|
LTWAIN_CHECK_ALL_DEFAULT_BPP |
[0x0010] Test all supported BPP. |
|
LTWAIN_KEEPOPEN |
[0x0020] Keep the TWAIN data source open after scanning. |
nBitsPerPixel |
Resulting file's pixel depth. Note that not all bits per pixel are available to all file formats. For valid values, refer to Formats of Output Files. If nBitsPerPixel is 0, the file will be stored using the closest BitsPerPixel value supported by that format. |
|
nBufferIteration |
This value is used to determine the number of memory configurations that will be tested. The maximum value for this parameter is 10. |
|
pInFastConfigs |
Pointer to a FASTCONFIG structure that contains an array of scan configurations to be tested. Pass NULL to test the default scan configurations |
|
nInFastConfigsCount |
Number of scan configurations referenced in pInFastConfigs. Pass 0 to test the default scan configurations. |
|
ppTestConfigs |
Address of a pointer to a FASTCONFIG structure. The function will automatically allocate an array of FASTCONFIG structures using the total number of tested configurations. |
|
pnTestConfigsCount |
Pointer to an integer variable to be updated with number of tested configurations. |
|
pOutBestConfig |
Pointer to a FASTCONFIG structure to be updated with the best configuration for the scanner. |
|
uStructSize |
Size in bytes, of the structure pointed to by pltProperties, for versioning. Use sizeof(FASTCONFIG). |
|
pfnCallBack |
Optional callback function, called for each scan configuration as it is tested. |
|
|
If you do not provide a callback function, use NULL as the value of this parameter. No error reporting will occur. |
|
|
If you do provide a callback function, use the function pointer as the value of this parameter. |
|
|
The callback function must adhere to the function prototype described in the LTWAINFINDFASTCONFIG function. |
|
pUserData |
Void pointer that you can use to pass one or more additional parameters that the callback function needs. |
|
|
To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure. |
|
|
If the additional parameters are not needed, you can pass NULL in this parameter. |
Returns
SUCCESS |
The function was successful. |
! = SUCCESS |
An error occurred. Refer to Return Codes. |
Comments
This function will test scan configurations for the scanner selected by calling L_TwainSelectSource. It will update the pOutBestConfig parameter with the best scan configuration tested. Once the best scan configuration has been determined, the scan configuration's values for the transfer mode, bits per pixel, format and buffer size can be passed to L_TwainAcquireMulti so the images can be scanned as fast as possible.
To test user-defined/custom configurations, pass these configurations in pInFastConfigs and the number of configurations in nInFastConfigsCount.
To test the default configurations available for the Twain driver, pass NULL for pInFastConfigs and 0 for nInFastConfigsCount. In this case, the function will test scan configurations based the values passed in the nBitsPerPixel and nBufferIteration parameters.
The list of default scan configurations to test can be shortened by using the L_TwainGetScanConfigs function to get a list of default scan configurations based on transfer mode, bits per pixel and number of buffers. This list can then be passed to L_TwainFindFastConfig function to determine the best and fastest scan configuration.
If LTWAIN_CHECK_ALL_DEFAULT_BPP is set in uFlags then the function will test all supported bits per pixel for the selected scanner. If this flag is not set in uFlags, then the function will use the iBitsPerPixel parameter value.
If LTWAIN_USE_THREAD_MODE is set in uFlags, then the image acquisition process will run in thread mode. In some scanners, acquiring images in thread will improve the speed at which the image(s) is(are) acquired. In other scanners, high-speed scanners, for example, acquiring the image(s) in thread mode will provide little to no improvement in the speed at which the image(s) is(are) acquired.
The nBitsPerPixel parameter and LTWAIN_CHECK_ALL_DEFAULT_BPP flag will be used only if the transfer mode for the scan configuration being tested is LTWAIN_BUFFER_MODE or LTWAIN_NATIVE_MODE.
The nBufferIteration parameter will be used only if the transfer mode for the scan configuration being tested is LTWAIN_BUFFER_MODE.
If a valid callback function is passed for pfnCallBack, the scan configuration testing process can be stopped by returning any value other than SUCCESS for the callback function. The testing process is continued by returning SUCCESS for the callback function.
This function allocates storage for the array of scan configurations in ppTestConfigs. When this storage is no longer needed, you must free the storage by calling L_TwainFreeScanConfig.
The LTWAIN_KEEPOPEN flag works only in the following cases:
1. |
Passed with LTWAIN_SHOW_USER_INTERFACE flag to make the TWAIN user-interface appears as a modeless dialog. The TWAIN data source remains open after scanning until the user closes it. |
2. |
Passed with LTWAIN_SHOW_USER_INTERFACE and LTWAIN_MODAL_USER_INTERFACE flags to make the TWAIN user-interface appears as a modal dialog. The TWAIN data source remains open after scanning until the user closes it. |
Required DLLs and Libraries
LTTWN For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application. |
See Also
Example
For complete sample, refer to TWNCONFIG demo.
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName L_INT EXT_CALLBACK TwnScanConfig(HTWAINSESSION hSession, pFASTCONFIG pResConfig, L_VOID * pUserData) { UNREFERENCED_PARAMETER(hSession); UNREFERENCED_PARAMETER(pResConfig); UNREFERENCED_PARAMETER(pUserData); L_TCHAR szBuffer[MAX_PATH]; if (pResConfig->bSuccess) { memset(szBuffer, 0, sizeof(szBuffer)); wsprintf(szBuffer, TEXT("Transfer Mode = %d\nFile Format = %d\nBuffer Size = %d\nRequired Time = %d\n"), pResConfig->uTransferMode, pResConfig->nFileFormat, pResConfig->ulBufferSize, pResConfig->uTime); MessageBox(NULL, szBuffer, TEXT("Result Scan Configuration..."), MB_OK); } else MessageBox(NULL, TEXT("The tested configuration failed…"), TEXT("Error!"), MB_OK); return SUCCESS; } L_INT TwainFindFastConfigExample(HWND hWnd,HTWAINSESSION hSession) { L_INT nRet; pFASTCONFIG pTestConfigs = NULL; L_INT nTestConfigsCount = 0; pFASTCONFIG pFastConfig=NULL; L_INT nFastConfigCount; FASTCONFIG BestConfig; L_TCHAR szBuffer[MAX_PATH]; nRet = L_TwainGetScanConfigs (hSession, 1, LTWAIN_BUFFER_MODE, 5, &pFastConfig, sizeof(FASTCONFIG), &nFastConfigCount); if (nRet != SUCCESS) { MessageBox(hWnd, TEXT("Error occurred while getting the scan configurations for the Memory transfer mode!!!"), TEXT("Error!!!"), MB_OK); return nRet; } memset(&BestConfig, 0, sizeof(FASTCONFIG)); nRet = L_TwainFindFastConfig(hSession, MAKE_IMAGE_PATH(TEXT("")), LTWAIN_SHOW_USER_INTERFACE, 1, 5, pFastConfig, nFastConfigCount, &pTestConfigs, &nTestConfigsCount, &BestConfig, sizeof(FASTCONFIG), TwnScanConfig, NULL); if (nRet == SUCCESS) { MessageBox(hWnd, TEXT("L_TwainFindFastConfig function was successful."), TEXT( "Notice"), MB_OK); memset(szBuffer, 0, sizeof(szBuffer)); wsprintf(szBuffer, TEXT("Transfer Mode = %d\nFile Format = %d\nBuffer Size = %d\nRequired Time = %d\n"), BestConfig.uTransferMode, BestConfig.nFileFormat, BestConfig.ulBufferSize, BestConfig.uTime); MessageBox(hWnd, szBuffer, TEXT("Best Scan Configuration..."), MB_OK); L_TwainFreeScanConfig (hSession, &pTestConfigs, nTestConfigsCount); } else { MessageBox(hWnd, TEXT("Error occurred in the L_TwainFindFastConfig function!!!"), TEXT("Error!!!"), MB_OK); return nRet; } nRet = L_TwainFreeScanConfig(hSession, &pFastConfig, nFastConfigCount); if(nRet != SUCCESS) return nRet; return SUCCESS; }