#include "BITIFF.H"
BOOL CALLBACK DecodeCcittImage( int nFile,
UINT wWidth,
UINT wHeight,
DWORD dwCompression,
INT_PTR lUserData,
FILLPROC lpLineFn)
Description
Uncompresses a monochrome image from a file. The decoded image data can be retrieved through the user defined callback function line by line. The file pointer must be positioned to the first byte of the image in the file. The function supports all the standard CCITT compression types and can process uncompressed monochrome images as well.
Following Compression types are defined in the "BITIFF.H" file:
TIFF_CCITT
CCITT_GROUP3
CCITT_GROUP4
Additional compression modifiers can be OR-ed to the DWORD compression value as the high word:
CCITT_1D
CCITT_2D
CCITT_UNCOMP
CCITT_FILLBITS
Parameters
|
int |
nFile |
Image file handle. |
|
UINT |
wWidth |
Width of the image in pixels. |
|
UINT |
wHeight |
Height of the image in pixels. |
|
DWORD |
dwCompression |
Compression type. The low order word contains the main type and the high order word contains the additional info. |
|
INT_PTR |
lUserData |
User defined info. It is passed to the callback function as a third parameter unchanged. |
|
FILLPROC |
lpLineFn |
Callback function that will get the decoded DIB lines. |
Return values
TRUE on success, FALSE if failed. Error flag set to TUNKNOWNCOMPRESSION if the image compression type is not supported, or TCOMPRESSIONFAILED if the decompression has failed.
Programming notes
See the notes at DecodeTiffImage().
Requirements
Header : Declared in BiTiff.h; include BiTiff.h.
Library : Use BiTIFF.lib.
DLLs : BiTiff.dll.
References to related functions
See DecodeTiffImage(), EncodeTiffImage() and EncodeCcittImage().
Code example
#include "BITIFF.H"
/* BmInfo is a global BITMAPINFO structure. It must be prepared for a monochrome bitmap. */
/* hDC is global variable. */
// Determines the compression algorithm. Let's say 2 dimensional CCITT, Group3.
dwMethod = MAKELONG(CCITT_GROUP3,CCITT_2D);
// Opens the image file.
nFile = _lopen(lpszFileName,READ);
if (nFile > 0) // Opening OK.
{
// Gets a DC to be used later in the call back function.
hDC = GetDC(hWnd);
if (hDC != NULL)
{
hBitmap = CreateBitmap((int)BmInfo.bmiHeader.biWidth,
(int)BmInfo.bmiHeader.biHeight,1,1,(LPSTR)NULL);
if (hBitmap != NULL)
{
// Fills the image in the bitmap.
if(!DecodeCcittImage(nFile,(UINT)BmInfo.bmiHeader.biWidth,
(UINT)BmInfo.bmiHeader.biHeight,dwMethod,
(LONG)hBitmap, FlushCcittLine))
{
// Error occurred during decompression.
DeleteObject(hBitmap);
hBitmap = NULL; // To sign the failure.
}
} // Endif bitmap creation OK.
ReleaseDC(hWnd,hDC);
} // Endif retrieving DC OK.
// Closes image file.
_lclose(nFile);
}
....
The callback function may be similar to this:
int CALLBACK FlushCcittLine(LPSTR lpLineBuff, int nLine, LONG lParam)
{
// Writes data into bitmap.
SetDIBits( hDC,
(HBITMAP)lParam,
(int)BmInfo.bmiHeader.biHeight-nLine-1,
1,
lpLineBuff,
(LPBITMAPINFO)&BmInfo,
DIB_RGB_COLORS);
return(TOK);
}