L_ISISAcquireMulti

#include "l_bitmap.h"
#include "ltisi.h"

L_INT EXT_FUNCTION L_ISISAcquireMulti(hWnd, pszBaseFileName, uFlags, nFormat, bMultiPageFile, pnPagesDiscarded, pfnCallback, pUserData)

HWND hWnd;

/* window handle */

L_CHAR L_FAR * pszBaseFileName;

/* base string */

L_UINT32 uFlags;

/* option flags */

L_INT nFormat;

/* format type */

L_BOOL bMultiPageFile;

/* flag */

L_INT L_FAR *pnPagesDiscarded;

/* pointer to an integer */

ISISCALLBACK pfnCallback;

/* pointer to a callback function */

L_VOID L_FAR * pUserData;

/* pointer to more parameters for the callback */

Starts a multi-page ISIS scan. Each page will be saved in the specified format in either a multi-page file, or as individual files. This function is available in the Document/Medical Toolkits.

Parameter

Description

hWnd

Handle of the parent window.

pszBaseFileName

Character string containing the base string from which page names will be generated.

uFlags

Option flags. Valid values are:

 

Value

Meaning

 

ISIS_SHOWUI

[0x0001] Shows the ISIS UI.

 

ISIS_MULTI_NOSAVE

[0x0002] Do not save data to file.

 

NULL

[0x0000] Do not show user interface.

nFormat

Value indicating the format to use when saving one or more images to one or more files. The available formats depend on whether or not the data is acquired in compressed form or in uncompressed form. If the data is uncompressed, that is if the ISIS short tag TAG_COMPRESSION has been set to TAG_COMPRESSION_NONE, any format supported by LEADTOOLS is valid. For a list of these formats, refer to Formats of Output Files.

 

If the data is compressed, the type of compression will determine the output format. If a format that is incompatible with the current compression is passed, an error will occur. Possible valid format values and the corresponding compressions are:

 

Value

Meaning

 

FILE_CCITT

[25] Tiff, compressed using CCITT. A file is saved in this format when TAG_COMPRESSION is set to TAG_COMPRESSION_MG3 and nFormat is set to either FILE_CCITT or FILE_FASTEST.

 

FILE_CCITT_GROUP3_1DIM

[27] TIFF, compressed using CCITT, group 3, 1 dimension. A file is saved in this format when TAG_COMPRESSION is set to TAG_COMPRESSION_G3 and nFormat is set to either FILE_CCITT_GROUP3_1DIM or FILE_FASTEST.

 

FILE_CCITT_GROUP4

[29] TIFF, compressed using CCITT, group 4. A file is saved in this format when TAG_COMPRESSION is set to TAG_COMPRESSION_G4 and nFormat is set to either FILE_CCITT_GROUP4 or FILE_FASTEST.

 

FILE_TIFLZW

[17] TIFF, compressed using LZW. A file is saved in this format when TAG_COMPRESSION is set to TAG_COMPRESSION_LZW and nFormat is set to either FILE_TIFLZW or FILE_FASTEST.

 

FILE_TIF_PACKBITS

[87] TIFF, compressed using Packed Bits. A file is saved in this format when TAG_COMPRESSION is set to TAG_COMPRESSION_32771 and nFormat is set to either FILE_TIF_PACKBITS or FILE_FASTEST.

 

FILE_FASTEST

[105] Saves the file as a TIFF using the current compression from the scanner.

bMultiPageFile

Flag that indicates whether to save as a multi-page file, or as individual files for each page.

pnPagesDiscarded

Pointer to an integer that holds the number of pages discarded if scanning were canceled while ScanAhead was enabled.

pfnCallback

Optional callback function for additional processing.

 

image\sqrblit.gif If you do not provide a callback function, use NULL as the value of this parameter.

 

image\sqrblit.gif 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 ISISCALLBACK 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 L_FAR *. 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.

< 1

An error occurred. Refer to Return Codes.

Comments

If bMultiPageFile is TRUE, the scanned pages will be saved as pages in a multi-page file. If bMultiPageFile is FALSE, each scanned page will be saved to an individual file. Filenames are created by concatenating the string in pszBaseFileName with the page number. By default, the numbering will begin with "0001" and will be incremented with each page scanned ("0002", "0003", ... ). Each file will be saved according to the format indicated in nFormat. If a file already exists, for example "Page0002", it will be overwritten. The user can control the number of digits used in numbering the filenames by including asterisks '*' in the filename, before the extension. For example, passing "c:\temp\isis\test**.tif" for pszBaseFileName indicates to use only two digits in the filenames (test04.tif), while passing "c:\temp\isis\test*****.tif" for pszBaseFileName indicates to use only five digits in the filenames (test00001.tif). If no asterisks are included, the default of four digits will be used (test0003.tif).

You must supply a callback function in pfnCallback in order to process the images as they are scanned, instead of, or in addition to, saving them to file(s).

Required DLLs and Libraries

LTISI

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 95 / 98 / Me, Windows 2000 / XP.

See Also

Functions:

L_ISISAcquire

Topics:

Raster Image Functions: Scanning Images using ISIS

 

Using ISIS to Scan Images

Example

For complete sample code, refer to the FRAME.C module of the DEMO example.

/* global variables */
L_BOOL fKillProgress;
L_BOOL fInTwain;
HINSTANCE hInst;
HWND hWndFrame;

/* ISISCALLBACK function declaration */
L_INT L_EXPORT ISISCallBack( pBITMAPHANDLE pBitmap, L_INT32 nPage, L_CHAR L_FAR* pszFilename, L_VOID L_FAR * pUserData );

static L_VOID ISISAcquireMulti(L_VOID)
{
   L_CHAR buf[2*_MAX_PATH];
   HCURSOR hCursor;
   HMENU hMenu;
   L_INT nRet;
   L_INT nSaveFormat;
   static OPENFILENAME OpenFileName;
   static L_CHAR szFileName[_MAX_PATH] = "";
   static L_BOOL bSaveMulti = TRUE;
   FILESAVEPARM ISISFSParm;
   L_INT nMaxPages=1;
   L_INT nPagesDiscarded;
   FILESAVEFORMAT Formats[1];

   OpenFileName.lStructSize       = sizeof(OPENFILENAME);
   OpenFileName.lpstrInitialDir   = NULL;
   OpenFileName.lpstrTitle        = "Select Base Filename";
   OpenFileName.nFilterIndex      = 0;

   OpenFileName.lpstrFile         = szFileName;
   OpenFileName.nMaxFile          = sizeof(szFileName);
   OpenFileName.lpstrFileTitle    = ISISFSParm.szFileName;
   OpenFileName.nMaxFileTitle     = sizeof(ISISFSParm.szFileName);

   OpenFileName.Flags             = 0;

   ISISFSParm.uSaveMulti = bSaveMulti;

   /* add some formats */
   Formats[0].nFormat     = FS_LEAD24;
   Formats[0].uSubFormats = 0;   /* get the name of the file(s) to save */

   nRet = L_DlgSave( hWndFrame,
                         &OpenFileName,
                         &ISISFSParm,
                         DLG_FS_MULTIPAGE,
                          (FILESAVEFORMAT L_FAR*)&Formats,
                         nSaveFormat,
                         NULL, NULL );

   if(nRet != SUCCESS)
      return;

   bSaveMulti = ISISFSParm.uSaveMulti;
   nSaveFormat = ISISFSParm.nFormat;

   hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT));
   hMenu = GetSystemMenu (hWndFrame, FALSE);
   EnableMenuItem (hMenu, SC_CLOSE, FALSE);
   fInTwain = TRUE;

   nRet = L_ISISLoadDriver(NULL);

   if(nRet == SUCCESS)
   {
      /* let's set the ScanAhead to 1/2 the max. # of pages the ADF can hold for SPEED */
      nRet = L_ISISSetTagShort(TAG_SCANAHEAD, TAG_SCANAHEAD_YES);
      if(nRet == SUCCESS)
      {
         nRet=L_ISISGetTagShort(TAG_MAXPAGES, &nMaxPages);
         nRet=L_ISISSetTagShort(TAG_SCANAHEAD_MAXPAGES, (L_INT)(nMaxPages/2));
      }

      /* try setting scanner compression to match file output type */
      switch(nSaveFormat)
      {
         case FILE_CCITT:
            nRet=L_ISISSetTagShort (TAG_COMPRESSION, TAG_COMPRESSION_MG3);
            break;
         case FILE_CCITT_GROUP3_1DIM:
            nRet=L_ISISSetTagShort(TAG_COMPRESSION, TAG_COMPRESSION_G3);
            break;
         case FILE_CCITT_GROUP4:
            nRet=L_ISISSetTagShort(TAG_COMPRESSION, TAG_COMPRESSION_G4);
            break;
         case FILE_TIFLZW:
            nRet=L_ISISSetTagShort(TAG_COMPRESSION, TAG_COMPRESSION_LZW);
            break;
         case FILE_TIF_PACKBITS:
            nRet=L_ISISSetTagShort(TAG_COMPRESSION, TAG_COMPRESSION_32771);
            break;
         default:
            nRet=L_ISISSetTagShort(TAG_COMPRESSION, TAG_COMPRESSION_NONE);
            break;
      }

      nRet = L_ISISAcquireMulti (hWndFrame,
                                 szFileName,
                                 ISIS_SHOWUI,
                                 nSaveFormat,
                                 bSaveMulti,
                                 &nPagesDiscarded,
                                 ISISCallBack,
                                 NULL);
      L_ISISUnloadDriver();
   }
   EnableMenuItem (hMenu, SC_CLOSE, TRUE);
   fInTwain = FALSE;
   SetCursor (hCursor);
   if (nRet == ERROR_USER_ABORT)
   {
      wsprintf(buf, "Scanning canceled; %d pages ScannedAhead but aborted!", nPagesDiscarded );
      MessageBox(hWndFrame, buf, "ISIS Acquire Multi", MB_OK);
      wsprintf(buf, "Image(s) acquired to file(s): %s", szFileName);
      MessageBox(hWndFrame, buf, "ISIS Acquire Multi", MB_OK);
   }
   else if (nRet != SUCCESS)
      L_FileError (hWndFrame, nRet, "ISIS Acquire Multi", "");
   else
   {
      wsprintf(buf, "Image(s) acquired to file(s): %s", szFileName);
      MessageBox(hWndFrame, buf, "ISIS Acquire Multi", MB_OK);
   }
   return;
}

L_INT L_EXPORT ISISCallBack( pBITMAPHANDLE pBitmap, L_INT32 nPage, L_CHAR L_FAR* pszFilename, L_VOID L_FAR * pUserData ) 
{
   UNREFERENCED_PARAMETER(pBitmap);
   MSG msg;

   while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
   {
      if(msg.message == WM_KEYDOWN)
      {
         if(msg.wParam == VK_ESCAPE)
         {
            fKillProgress = TRUE;
            MessageBox(NULL, "ISIS Scanning Canceled!", "Stop", MB_OK);
         }
      }
      TranslateMessage (&msg);
      DispatchMessage (&msg);
   }

   if (fKillProgress)
      return (ERROR_USER_ABORT);
   else
      return (SUCCESS);
}