Decode an RGB 24-bit Image - Example 2

Same as Example 1. but the callback function is different to build a bitmap from RGB TIFF file and to copy the DIB lines into a bitmap:

int CALLBACK FlushTiffLine24(LPSTR lpLineBuff, int nLine, LONG lParam)

{

LPBITMAPINFO lpBmI;

TIFFLINEDATA far * lpTiffLineData = (TIFFLINEDATA far *)lParam;

HPSTR hpSrcLine = (HPSTR)lpLineBuff;

HPSTR hpDstLine = (HPSTR)lpLineBuff;

WORD  wByteCnt = lpTiffLineData->wWidthBytes;

BYTE  bBlue;

    //  The TIFF DLL returns RGB sequence but MS Windows stores it

    //  in BGR format. Why, ask Silly Bill G.!

 

    for(;wByteCnt>2;wByteCnt-=3) {

          bBlue                          = *(hpSrcLine+2);

          *(hpDstLine+2)         = *hpSrcLine;

          *hpDstLine               = bBlue;

          hpSrcLine+=3;

          hpDstLine+=3;

    }

 

    lpBmI = (LPBITMAPINFO) GlobalLock(lpTiffLineData->hBitmapInfo);

 

    // Writes data into bitmap. wUsage is not used in this version !!!

    SetDIBits(lpTiffLineData->hDC,lpTiffLineData->hBitmap,

              (int)lpBmI->bmiHeader.biHeight - ++nLine,1,

              lpLineBuff, (LPBITMAPINFO)lpBmI, DIB_RGB_COLORS);

 

    GlobalUnlock(lpTiffLineData->hBitmapInfo);

 

    return(TOK);

}

In this example, hBitmapInfo, hDC and hBitmap passed as user defined data in the lParam variable and they must be initialized before calling DecodeTiffImage(). The variable hBitmapInfo can be created by calling GetTiffRGBQuad() which allocates a BITMAPINFO structure on the far heap, and fills its fields based on the tags of the image. The variable hBitmap must not be selected into hDC.