Index: win32ss/gdi/ntgdi/dibobj.c =================================================================== --- win32ss/gdi/ntgdi/dibobj.c (revision 73995) +++ win32ss/gdi/ntgdi/dibobj.c (working copy) @@ -719,6 +719,21 @@ if ((Usage && Usage != DIB_PAL_COLORS) || !Info || !hBitmap) return 0; + pDC = DC_LockDc(hDC); + if (pDC == NULL || pDC->dctype == DC_TYPE_INFO) + { + ScanLines = 0; + goto done; + } + + /* Get a pointer to the source bitmap object */ + psurf = SURFACE_ShareLockSurface(hBitmap); + if (psurf == NULL) + { + ScanLines = 0; + goto done; + } + colorPtr = (LPBYTE)Info + Info->bmiHeader.biSize; rgbQuads = colorPtr; @@ -733,7 +748,8 @@ { DPRINT("Wrong bitmap format\n"); EngSetLastError(ERROR_INVALID_PARAMETER); - return 0; + ScanLines = 0; + goto done; } else if(bitmap_type == 0) { @@ -740,30 +756,18 @@ /* We need a BITMAPINFO to create a DIB, but we have to fill * the BITMAPCOREINFO we're provided */ pbmci = (BITMAPCOREINFO*)Info; + /* fill in the the bit count, so we can calculate the right ColorsSize during the conversion */ + pbmci->bmciHeader.bcBitCount = BitsPerFormat(psurf->SurfObj.iBitmapFormat); Info = DIB_ConvertBitmapInfo((BITMAPINFO*)pbmci, Usage); if(Info == NULL) { DPRINT1("Error, could not convert the BITMAPCOREINFO!\n"); - return 0; + ScanLines = 0; + goto done; } rgbQuads = Info->bmiColors; } - pDC = DC_LockDc(hDC); - if (pDC == NULL || pDC->dctype == DC_TYPE_INFO) - { - ScanLines = 0; - goto done; - } - - /* Get a pointer to the source bitmap object */ - psurf = SURFACE_ShareLockSurface(hBitmap); - if (psurf == NULL) - { - ScanLines = 0; - goto done; - } - /* Fill in the structure */ switch(bpp) { @@ -789,15 +793,21 @@ } Info->bmiHeader.biXPelsPerMeter = 0; Info->bmiHeader.biYPelsPerMeter = 0; - Info->bmiHeader.biClrUsed = 0; - Info->bmiHeader.biClrImportant = 0; - ScanLines = abs(Info->bmiHeader.biHeight); + if(Info->bmiHeader.biBitCount <= 8 && Info->bmiHeader.biClrUsed == 0) + { + Info->bmiHeader.biClrUsed = 1 << Info->bmiHeader.biBitCount; + } + else + { + Info->bmiHeader.biClrUsed = 0; + } + ScanLines = Bits ? abs(Info->bmiHeader.biHeight) : 1; goto done; case 1: case 4: case 8: - Info->bmiHeader.biClrUsed = 0; + Info->bmiHeader.biClrUsed = 1 << bpp; /* If the bitmap is a DIB section and has the same format as what * is requested, go ahead! */ @@ -1019,7 +1029,7 @@ GreDeleteObject(hBmpDest); EXLATEOBJ_vCleanup(&exlo); } - else ScanLines = abs(height); + else ScanLines = 1; done: @@ -2075,6 +2085,8 @@ pNewBmi->bmiHeader.biHeight, pNewBmi->bmiHeader.biBitCount); + pNewBmi->bmiHeader.biClrUsed = numColors; + if(Usage == DIB_PAL_COLORS) { RtlCopyMemory(pNewBmi->bmiColors, pbmci->bmciColors, ColorsSize);