DecodeCcittImageFrom

#include "BITIFF.H"

 

BOOL CALLBACK DecodeCcittImageFrom( int                 nFile,
long              lOffset,
UINT           wWidth,
UINT           wHeight,
DWORD      dwCompression,
int                 nFillOrder,
UINT           wByteOrder,
INT_PTR     lUserData,
FILLPROC  lpLineFn)

Description

Decompresses a monochrome image from an offset location in a file. The user can set byte order to Intel or Motorola type, and the byte fill order. The decoded image data can be retrieved through the user defined callback function line by line. 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.

long

lOffset

Image offset in the file.

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

nFillOrder

The byte fill order.

UINT

wByteOrder

The byte order.

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

The wByteOrder field may be either LH_BYTE_ORDER or HL_BYTE_ORDER. LH_BYTE_ORDER means that byte order is always from least significant to most significant, for both 16-bit and 32-bit integers. HL_BYTE_ORDER means that byte order is always from most significant to least significant. LH_BYTE_ORDER is used by computers with Intel processors (IBM compatible computers). HL_BYTE_ORDER is used with computers with Motorola processors (Macintosh computers).

Bit order defines in the "BITIFF.H" file:        NORM_BIT_ORDER // default

                                                                        REV_BIT_ORDER

 

Byte order defines in the "BITIFF.H" file:     LH_BYTE_ORDER              // default

                                                                        HL_BYTE_ORDER

Requirements

Header :     Declared in BiTiff.h; include BiTiff.h.

Library :    Use BiTIFF.lib.

DLLs :       BiTiff.dll.

References to related functions

See DecodeTiffImage(), DecodeCcittImage(), EncodeTiffImage() and EncodeCcittImage().

Code example

"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(!DecodeCcittImageFrom(

                                                                nFile,(UINT)BmInfo.bmiHeader.biWidth,

                                                                (UINT)BmInfo.bmiHeader.biHeight,dwMethod,

                                                                NORM_BIT_ORDER, LH_BYTE_ORDER,

                                                                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);

}