Fix ImageList_Read - the root cause of ugly toolbar icons.
This commit is contained in:
parent
462172a3d6
commit
1420acef09
|
@ -1894,15 +1894,14 @@ static int may_use_dibsection(HDC hdc) {
|
||||||
|
|
||||||
/* helper for ImageList_Read, see comments below */
|
/* helper for ImageList_Read, see comments below */
|
||||||
static HBITMAP _read_bitmap(LPSTREAM pstm,int ilcFlag,int cx,int cy) {
|
static HBITMAP _read_bitmap(LPSTREAM pstm,int ilcFlag,int cx,int cy) {
|
||||||
HDC xdc = 0;
|
HDC xdc = 0, hBitmapDC =0;
|
||||||
BITMAPFILEHEADER bmfh;
|
BITMAPFILEHEADER bmfh;
|
||||||
BITMAPINFOHEADER bmih;
|
BITMAPINFOHEADER bmih;
|
||||||
int bitsperpixel,palspace,longsperline,width,height;
|
int bitsperpixel,palspace,longsperline,width,height;
|
||||||
LPBITMAPINFOHEADER bmihc = NULL;
|
LPBITMAPINFOHEADER bmihc = NULL;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
HBITMAP hbitmap = 0;
|
HBITMAP hbitmap = 0, hDIB = 0;
|
||||||
LPBYTE bits = NULL,nbits = NULL;
|
LPBYTE bits = NULL;
|
||||||
int nbytesperline,bytesperline;
|
|
||||||
|
|
||||||
if (!SUCCEEDED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL)) ||
|
if (!SUCCEEDED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL)) ||
|
||||||
(bmfh.bfType != (('M'<<8)|'B')) ||
|
(bmfh.bfType != (('M'<<8)|'B')) ||
|
||||||
|
@ -1942,44 +1941,41 @@ static HBITMAP _read_bitmap(LPSTREAM pstm,int ilcFlag,int cx,int cy) {
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
int i,nwidth,nheight;
|
int i,nwidth,nheight,nRows;
|
||||||
|
|
||||||
nwidth = width*(height/cy);
|
nwidth = width*(height/cy);
|
||||||
nheight = cy;
|
nheight = cy;
|
||||||
|
nRows = (height/cy);
|
||||||
|
|
||||||
if (bitsperpixel==1)
|
if (bitsperpixel==1)
|
||||||
hbitmap = CreateBitmap(nwidth,nheight,1,1,NULL);
|
hbitmap = CreateBitmap(nwidth,nheight,1,1,NULL);
|
||||||
else
|
else
|
||||||
hbitmap = CreateCompatibleBitmap(xdc,nwidth,nheight);
|
hbitmap = CreateCompatibleBitmap(xdc,nwidth,nheight);
|
||||||
|
|
||||||
/* Might be a bit excessive memory use here */
|
hDIB = CreateDIBSection(xdc,(BITMAPINFO*)bmihc,0,(LPVOID*)&bits,0,0);
|
||||||
bits = (LPBYTE)LocalAlloc(LMEM_ZEROINIT,bmihc->biSizeImage);
|
if (!hDIB)
|
||||||
nbits = (LPBYTE)LocalAlloc(LMEM_ZEROINIT,bmihc->biSizeImage);
|
goto ret1;
|
||||||
if (!SUCCEEDED(IStream_Read( pstm, bits, bmihc->biSizeImage, NULL)))
|
if (!SUCCEEDED(IStream_Read( pstm, bits, bmihc->biSizeImage, NULL)))
|
||||||
goto ret1;
|
goto ret1;
|
||||||
|
|
||||||
|
hBitmapDC = CreateCompatibleDC(0);
|
||||||
|
SelectObject(hBitmapDC, hbitmap);
|
||||||
|
|
||||||
/* Copy the NxM bitmap into a 1x(N*M) bitmap we need, linewise */
|
/* Copy the NxM bitmap into a 1x(N*M) bitmap we need, linewise */
|
||||||
/* Do not forget that windows bitmaps are bottom->top */
|
/* Do not forget that windows bitmaps are bottom->top */
|
||||||
bytesperline = longsperline*4;
|
TRACE("nRows=%d\n", nRows);
|
||||||
nbytesperline = (height/cy)*bytesperline;
|
for (i=0; i < nRows; i++){
|
||||||
for (i=0;i<height;i++) {
|
StretchDIBits(hBitmapDC, width*i, 0, width, cy, 0, cy*(nRows-1-i), width, cy, bits,
|
||||||
memcpy(
|
(BITMAPINFO*)bmihc, DIB_RGB_COLORS, SRCCOPY);
|
||||||
nbits+((height-1-i)%cy)*nbytesperline+(i/cy)*bytesperline,
|
|
||||||
bits+bytesperline*(height-1-i),
|
|
||||||
bytesperline
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
bmihc->biWidth = nwidth;
|
|
||||||
bmihc->biHeight = nheight;
|
|
||||||
if (!SetDIBits(xdc,hbitmap,0,nheight,nbits,(BITMAPINFO*)bmihc,0))
|
|
||||||
goto ret1;
|
|
||||||
LocalFree((HLOCAL)nbits);
|
|
||||||
LocalFree((HLOCAL)bits);
|
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
ret1:
|
ret1:
|
||||||
if (xdc) ReleaseDC(0,xdc);
|
if (xdc) ReleaseDC(0,xdc);
|
||||||
if (bmihc) LocalFree((HLOCAL)bmihc);
|
if (bmihc) LocalFree((HLOCAL)bmihc);
|
||||||
|
if (hDIB) DeleteObject(hDIB);
|
||||||
|
if (hBitmapDC) DeleteDC(hBitmapDC);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
if (hbitmap) {
|
if (hbitmap) {
|
||||||
DeleteObject(hbitmap);
|
DeleteObject(hbitmap);
|
||||||
|
|
Loading…
Reference in New Issue