////////////////////////////////////////////////////////////////////// // PUT THE FOLLOWING DECLARATIONS IN THE HEADER FILE ////////////////////////////////////////////////////////////////////// HINSTANCE FFLibDllHandle; int ( __stdcall *pfnFFTiffServices )( int, HANDLE, void*, int, int ); int ( __stdcall *pfnFFDec )( HANDLE, int, void*, int, int, int ); int ( __stdcall *pfnFFOMR )( int, int, int, int, int, int, int, int, int, int, int, void*, char* ); int ( __stdcall *pfnFFView )( HWND, void*, int, int, void*, void* ); ////////////////////////////////////////////////////////////////////// // SECTION ONE --- PRELIMINARY OPERATIONS ////////////////////////////////////////////////////////////////////// // load the DLL FFLibDllHandle = 0; FFLibDllHandle = LoadLibrary ( "FFLIB.DLL" ); if ( FFLibDllHandle == 0 ) { MessageBox ( NULL, "LoadLibrary:\nFFLIB.DLL not found.", "Error FS 001", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // load the address of FFTiffServices pfnFFTiffServices = ( int ( __stdcall *)( int, HANDLE, void*, int, int ) ) GetProcAddress ( FFLibDllHandle, "FFTiffServices" ); if ( pfnFFTiffServices == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFTiffServices not found.", "Errore FS 003", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // load the address of FFDec (group IV-2d CCITT decompressor) pfnFFDec = ( int ( __stdcall *)( HANDLE, int, void*, int, int, int ) ) GetProcAddress ( FFLibDllHandle, "FFDec" ); if ( pfnFFDec == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFDec not found.", "Errore FS 003", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // load the address of FFOMR pfnFFOMR = ( int ( __stdcall *)( int, int, int, int, int, int, int, int, int, int, int, void*, char* ) ) GetProcAddress ( FFLibDllHandle, "FFOMR" ); if ( pfnFFOMR == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFOMR not found.", "Errore FS 003", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // load the address of FFView pfnFFView = ( int ( __stdcall *)( HWND, void*, int, int, void*, void* ) ) GetProcAddress ( FFLibDllHandle, "FFView" ); if ( pfnFFView == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFView not found.", "Errore FS 003", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } ////////////////////////////////////////////////////////////////////// // SECTION TWO --- OPEN, DECOMPRESS, AND CLOSE THE TIFF FILE ////////////////////////////////////////////////////////////////////// // set the name of the image to be recognized and open the file char filePathAndName [ 256 ]; strcpy ( filePathAndName, "C:\\Lavori\\Sito2\\TESTIMG.TIF" ); HANDLE handle = CreateFileA ( filePathAndName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if ( handle == INVALID_HANDLE_VALUE ) { MessageBox ( NULL, filePathAndName, "TIFF file doesn't open, or doesn't exist:", MB_SYSTEMMODAL ); return; // file TIFF doesn't open } // check whether it is a true TIFF file (rc==1) int rc = pfnFFTiffServices ( 1, handle, NULL, NULL, NULL ); // get the width and the height of the image int width = pfnFFTiffServices ( 2, NULL, NULL, NULL, NULL ); int height = pfnFFTiffServices ( 3, NULL, NULL, NULL, NULL ); // get the comment, if any char* comment; (int) comment = pfnFFTiffServices ( 4, handle, NULL, NULL, NULL ); // then position file pointer to the beginning of the compressed data rc = pfnFFTiffServices ( 5, handle, NULL, NULL, NULL ); // allocate a buffer for the image according to its size int frameSize = width * height; HGLOBAL pFrame = GlobalAlloc ( GMEM_FIXED, frameSize ); // decompress the image and close the file rc = pfnFFDec ( handle, 1, pFrame, width/8, 0, height ); CloseHandle ( handle ); ////////////////////////////////////////////////////////////////////// // SECTION THREE --- RECOGNIZE THE MARKS ////////////////////////////////////////////////////////////////////// // NOTE: the recognition area is a 18 by 3 matrix; the width is 240 pixels, and // the height is 1604 pixels; the horizontal displacement of the matrix from the // top left positioning mark is 1196 pixels, and the vertical displacement is // 426 lines; // YOU MUST experimentally find these values, but it is not that difficult; // initially measure the positions on the paper sheet form (1 inch = 200 pixels); // then adjust the values with repetitive calls to pfnFFOMR with the "mode" parameter // (the 3rd parameter) set to 2: this will show you the position of the matrix; // ONCE YOU HAVE SET these values, they will reliably work forever // there are 18 rows and 3 columns of potential marks in the sample test image // provided in my web page, hence allocate the proper buffer (a byte more is // required for the terminating ASCIIZ null character) char szResult [ ( 18 * 3 ) + 1 ]; // call the recognition function (if rc != 0 the recognition has gone wrong) rc = pfnFFOMR ( 1664/8, 2336, 1, 18, 3, 1196, 426, 240, 1604, 6, 20, pFrame, szResult ); // REMEMBER to examine the string szResult to get the recognized marks: it is a // series of ASCII 1s and 0s, respectively meaning mark found and not found. Think // of the recognition grid (see above) as a matrix: each byte in the string is a // potential mark position, top to down, left to right. In this example the matrix // is 18 rows by 3 columns, hence szResult will contain 18*3 bytes (plus the // final ASCIIZ zero byte, of course) ////////////////////////////////////////////////////////////////////// // SECTION FOUR --- DISPLAY THE IMAGE AND THE RECOGNIZED MARKS ////////////////////////////////////////////////////////////////////// // call the image display function to see the results Form1 -> WindowState = wsMinimized; pfnFFView ( Application -> Handle, pFrame, width/8, height, 0, 0 ); Form1 -> WindowState = wsNormal; ////////////////////////////////////////////////////////////////////// // SECTION FIVE --- FINAL OPERATIONS ////////////////////////////////////////////////////////////////////// // free the memory GlobalFree ( pFrame ); // free the library if ( FFLibDllHandle != 0 ) FreeLibrary ( FFLibDllHandle );