1998.02.19 03:05 "tifflib bug? Help!!!", by ZhuBin


I created the *.lib by using the *.mak file I found in the \contrib\Win95 folder. (Windows95 and VC++5.0) And then call the function in tif2dib.c:

        HDIB LoadTIFFinDIB(LPSTR lpFileName)

to display the Tiff file in my application, there are two problems about the use:

Image Samples in v3_4pics_tar.Z

1. Open some tiff files the application will down at

        memcpy(lpBits, &buf[(int) (l*LineSize)]...)
 in function LoadTIFFinDIB(..).

2. When I display the image using the HDIB the function returns, just like this:

   ASBool DrawTiffImageInRect(CDC* pDC, CString filename,CRect& rt)
        int BitsPerSample = 8;
        HDIB hDib=LoadTIFFinDIB((char*)(const char*)filename);  
                return false;   


        HPALETTE            hPal, hOldPal;
        LPLOGPALETTE        pLogPal;
        LPBITMAPINFO        lpBMI;
        int                 nEntries;
        BOOL                bSuccess;

        nEntries = 1<<BitsPerSample;
        pLogPal = (LPLOGPALETTE)new char [sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * nEntries];
        pLogPal->palVersion = 0x300;
        pLogPal->palNumEntries = nEntries;

        lpBMI = (LPBITMAPINFO)lpDIB;

        for (int i=nEntries-1; i>=0; i--) {
                pLogPal->palPalEntry[i].peRed = lpBMI->bmiColors[i].rgbRed;
                pLogPal->palPalEntry[i].peGreen = lpBMI->bmiColors[i].rgbGreen;
                pLogPal->palPalEntry[i].peBlue = lpBMI->bmiColors[i].rgbBlue;
                pLogPal->palPalEntry[i].peFlags = 0;

        HDC hDC=pDC->m_hDC;
        hPal = CreatePalette(pLogPal);
        hOldPal = SelectPalette(hDC, hPal, TRUE);
        delete pLogPal;

#if 1   
        bSuccess = StretchDIBits(hDC,
                rt.Width(),rt.Height(), //Dest
        bSuccess = SetDIBitsToDevice(hDC,            // hDC
                0,         // DestX
                0,        // DestY
                lpDIB->biWidth,       // nDestWidth
                lpDIB->biHeight,    // nDestHeight
                0,         // SrcX
                0,         // SrcY
                0,                // nStartScan
                lpDIB->biHeight,  // nNumScans
                FindDIBBits((LPSTR) lpDIB),   // lpBits
                (LPBITMAPINFO)lpDIB,          // lpBitsInfo
                DIB_RGB_COLORS);              // wUsage

        return true;

When display in 1:1(Using SetDIBtsToDevice)t, the image dispaly well, but using stretch, there should be some rubbish in the image, what's the reason? Have I created the wrong Palette?

Can you help me?

Thanks for help!