You can detect the format of an image file before and after loading it in the HIGEAR handle using functions IG_fltr_detect_...():
- IG_fltr_detect_FD(INT fd, LONG lOffset, LPATE_MODE lFileType) detects the format by scanning its File Descriptor fd starting from the lOffset position in the file.
- IG_fltr_detect_file(const LPSTR lpszFileName, LPATE_MODE lFileType) determines the format of the image located in the specified file by the given file name.
- IG_fltr_detect_mem(void FAR lpImage, DWORD dwSize, LPATE_MODE lFileType) determines the format of image located in the memory buffer.
All three functions return the type of image format as an IG_FORMAT_ constant, as delineated in the accucnst.h file. See enumIGFormats.
The code fragment below allows you to sort image files by their formats and then choose how to use them:
C and C++ |
Copy Code
|
AT_ERRCOUNT nErrCount = IGE_SUCCESS;/* will hold returned error count */
AT_MODE nFormatID;
...
nErrCount = IG_fltr_detect_file( "image.tiff", &nFormatID );
if( nFormatID==IG_FORMAT_TIF )
{
...
}
|
For better performance or for some other purposes, use the special functions IG_fltr_load_file_format() and IG_fltr_pagecount_file_format() if the image format is known. Those functions accept the first parameter as the format ID and do not perform detect operations like IG_fltr_load_file() does, but immediately start to operate with the data, assuming the specified format. If the data is invalid or the image format is different, then an error is placed in the error stack.