|
In the process of developing the AxTiff32.DLL, it became clear that CreateBitmapIndirect and other GDI function calls do not work the same way in Windows 95 as they do on Windows 3.1. No tests were performed on Windows NT. In short, someone introduced a bug into these functions by making the following assumption: bmWidthBytes = bmWidth * bmBitsPerPixel / 8;
Of course, this is only true if the bmWidth is a multiple of 32 and there is no padding to fill the buffer to an even doubleword boundary. In order to circumvent this problem, all Axtel DLL's and applications use the following sequence when creating a bitmap from a buffer:
/* // There is a bug in MFC's 32-bit CreateBitmapIndirect. // They seem to use bmWidth to calculate bmWidthBytes. // Therefore, we must do the reverse. // We will calculate BmWidth from bmWidthBytes. // In other words, we will make our buffer appear to have no padding. */
dwLineLengthSave = m_sAxImage.dwLineLength; #if defined(WIN32) m_sAxImage.dwLineLength = MulDiv(m_sAxImage.dwBuffWidth,8,m_sAxImage.wBitsPerPixel); #endif
m_Bitmap.CreateBitmapIndirect((LPBITMAP)&m_sAxImage); m_sAxImage.dwLineLength = dwLineLengthSave;
/* // Free the buffer. */ GlobalUnlock(m_sAxImage.hBits); GlobalFree(m_sAxImage.hBits); m_sAxImage.hBits = 0; m_sAxImage.pBits = NULL;
The conditionals may be removed when operating on a 32bit platform only.
|