The next example below demonstrates the decoding into a file:
int CALLBACK CopyLineToFile(LPSTR lpLineBuff, int nLine, LONG lParam)
{
int nBytesWritten, nBytesPerLine, nFile;
// Retrieves some variables from the user defined parameter.
nBytesPerLine = (int) HIWORD(lParam);
nFile = (int) LOWORD(lParam);
// Writes data into file.
nBytesWritten = _lwrite(nFileHndl,lpLineBuff,nBytesPerLine);
// Returns the error status.
return((nBytesPerLine == nBytesWritten) ? TOK : TFILEIOERROR);
}
The file handle and the bytes per line value was passed to DecodeTiffImage() as the lParam parameter using the predefined Windows macro:
lParam = MAKELONG(nFile,nBytesPerLine);
Assuming integer arithmetic the bytes per line parameter can be calculated as:
nBytesPerLine = (BmIH.biBitCount * BmIH.biWidth + 31) / 8
...where BmIH is a BITMAPINFOHEADER structure. Each line is aligned at a LONG boundary according to the rules of bitmap files.