/*
- * $Id$
- *
* ReactOS W32 Subsystem
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
*
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <w32k.h>
PDC dc;
PSURFACE psurf;
PPALETTE PalGDI;
- UINT Index;
+ UINT Index, Count = 0;
ULONG biBitCount;
if (!(dc = DC_LockDc(hDC))) return 0;
Colors[Index - StartIndex].rgbGreen = PalGDI->IndexedColors[Index].peGreen;
Colors[Index - StartIndex].rgbBlue = PalGDI->IndexedColors[Index].peBlue;
Colors[Index - StartIndex].rgbReserved = 0;
+ Count++;
}
PALETTE_UnlockPalette(PalGDI);
}
- else
- Entries = 0;
DC_UnlockDc(dc);
- return Entries;
+ return Count;
}
// Converts a DIB to a device-dependent bitmap
else
{
// Destination palette obtained from the hDC
- DDB_Palette = DC->ppdev->DevInfo.hpalDefault;
+ DDB_Palette = DC->ppdev->devinfo.hpalDefault;
}
ppalDDB = PALETTE_LockPalette(DDB_Palette);
SIZEL SourceSize;
EXLATEOBJ exlo;
PPALETTE ppalDDB = NULL, ppalDIB = NULL;
- HPALETTE DDBPalette, DIBPalette = NULL;
+ HPALETTE hpalDDB, hpalDIB = NULL;
ULONG DIBPaletteType;
if (!Bits) return 0;
}
/* Use destination palette obtained from the DC by default */
- DDBPalette = pDC->ppdev->DevInfo.hpalDefault;
+ hpalDDB = pDC->ppdev->devinfo.hpalDefault;
/* Try to use hDIBPalette if it exists */
pSurf = pDC->dclevel.pSurface;
if (pSurf && pSurf->hDIBPalette)
{
- DDBPalette = pSurf->hDIBPalette;
+ hpalDDB = pSurf->hDIBPalette;
}
pDestSurf = pSurf ? &pSurf->SurfObj : NULL;
+ ScanLines = min(ScanLines, abs(bmi->bmiHeader.biHeight) - StartScan);
+
rcDest.left = XDest;
rcDest.top = YDest;
if (bTransformCoordinates)
rcDest.top += pDC->ptlDCOrig.y;
rcDest.right = rcDest.left + Width;
rcDest.bottom = rcDest.top + Height;
+ rcDest.top += StartScan;
+
ptSource.x = XSrc;
ptSource.y = YSrc;
SourceSize.cx = bmi->bmiHeader.biWidth;
- SourceSize.cy = ScanLines; // this one --> abs(bmi->bmiHeader.biHeight) - StartScan
+ SourceSize.cy = ScanLines;
+
DIBWidth = DIB_GetDIBWidthBytes(SourceSize.cx, bmi->bmiHeader.biBitCount);
hSourceBitmap = EngCreateBitmap(SourceSize,
}
/* Obtain destination palette */
- ppalDDB = PALETTE_LockPalette(DDBPalette);
+ ppalDDB = PALETTE_LockPalette(hpalDDB);
if (!ppalDDB)
{
SetLastWin32Error(ERROR_INVALID_HANDLE);
goto Exit;
}
- DIBPalette = BuildDIBPalette(bmi, (PINT)&DIBPaletteType);
- if (!DIBPalette)
+ /* Create a palette for the DIB */
+ hpalDIB = BuildDIBPalette(bmi, (PINT)&DIBPaletteType);
+ if (!hpalDIB)
{
SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
Status = STATUS_NO_MEMORY;
goto Exit;
}
+ /* Lock the DIB palette */
+ ppalDIB = PALETTE_LockPalette(hpalDIB);
+ if (!ppalDDB)
+ {
+ SetLastWin32Error(ERROR_INVALID_HANDLE);
+ Status = STATUS_UNSUCCESSFUL;
+ goto Exit;
+ }
+
/* Initialize EXLATEOBJ */
EXLATEOBJ_vInitialize(&exlo, ppalDIB, ppalDDB, 0, 0, 0);
/* Copy the bits */
+ DPRINT("BitsToDev with dstsurf=(%d|%d) (%d|%d), src=(%d|%d) w=%d h=%d\n",
+ rcDest.left, rcDest.top, rcDest.right, rcDest.bottom,
+ ptSource.x, ptSource.y, SourceSize.cx, SourceSize.cy);
Status = IntEngBitBlt(pDestSurf,
pSourceSurf,
NULL,
Exit:
if (NT_SUCCESS(Status))
{
- /* FIXME: Should probably be only the number of lines actually copied */
- ret = ScanLines; // this one --> abs(Info->bmiHeader.biHeight) - StartScan;
+ ret = ScanLines;
}
if (ppalDIB) PALETTE_UnlockPalette(ppalDIB);
if (pSourceSurf) EngUnlockSurface(pSourceSurf);
if (hSourceBitmap) EngDeleteSurface((HSURF)hSourceBitmap);
- if (DIBPalette) PALETTE_FreePaletteByHandle(DIBPalette);
+ if (hpalDIB) PALETTE_FreePaletteByHandle(hpalDIB);
DC_UnlockDc(pDC);
return ret;
hSourcePalette = psurf->hDIBPalette;
if (!hSourcePalette)
{
- hSourcePalette = pPrimarySurface->DevInfo.hpalDefault;
+ hSourcePalette = pPrimarySurface->devinfo.hpalDefault;
}
ColorPtr = ((PBYTE)Info + Info->bmiHeader.biSize);
RGBQUAD *lpRGB;
HANDLE hSecure;
DWORD dsBitfields[3] = {0};
+ ULONG ColorCount;
DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
bi->biWidth, bi->biHeight, bi->biPlanes, bi->biBitCount,
hSecure = (HANDLE)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
if (usage == DIB_PAL_COLORS)
+ {
lpRGB = DIB_MapPaletteColors(dc, bmi);
+ }
else
+ {
lpRGB = bmi->bmiColors;
+ }
+ ColorCount = bi->biClrUsed;
+ if (ColorCount == 0)
+ {
+ ColorCount = 1 << bi->biBitCount;
+ }
/* Set dsBitfields values */
if (usage == DIB_PAL_COLORS || bi->biBitCount <= 8)
table between the DIB and the X physical device. Obviously,
this is left out of the ReactOS implementation. Instead,
we call NtGdiSetDIBColorTable. */
- bi->biClrUsed = 0;
- /* set number of entries in bmi.bmiColors table */
- if (bi->biBitCount == 1) {
- bi->biClrUsed = 2;
- } else
- if (bi->biBitCount == 4) {
- bi->biClrUsed = 16;
- } else
- if (bi->biBitCount == 8) {
- bi->biClrUsed = 256;
- }
+ if (bi->biBitCount <= 8)
+ {
+ bi->biClrUsed = 1 << bi->biBitCount;
+ }
+ else
+ {
+ bi->biClrUsed = 0;
+ }
bmp->hDIBSection = section;
bmp->hSecure = hSecure;
bmp->biClrImportant = bi->biClrImportant;
if (bi->biClrUsed != 0)
- bmp->hDIBPalette = PALETTE_AllocPaletteIndexedRGB(bi->biClrUsed, lpRGB);
+ {
+ bmp->hDIBPalette = PALETTE_AllocPaletteIndexedRGB(ColorCount, lpRGB);
+ }
else
+ {
bmp->hDIBPalette = PALETTE_AllocPalette(PAL_BITFIELDS, 0, NULL,
dsBitfields[0],
dsBitfields[1],
dsBitfields[2]);
+ }
// Clean up in case of errors
if (!res || !bmp || !bm.bmBits)
for (i = 0; i < nNumColors; i++)
{
- lpRGB[i].rgbRed = palGDI->IndexedColors[*lpIndex].peRed;
- lpRGB[i].rgbGreen = palGDI->IndexedColors[*lpIndex].peGreen;
- lpRGB[i].rgbBlue = palGDI->IndexedColors[*lpIndex].peBlue;
+ if (*lpIndex < palGDI->NumColors)
+ {
+ lpRGB[i].rgbRed = palGDI->IndexedColors[*lpIndex].peRed;
+ lpRGB[i].rgbGreen = palGDI->IndexedColors[*lpIndex].peGreen;
+ lpRGB[i].rgbBlue = palGDI->IndexedColors[*lpIndex].peBlue;
+ }
+ else
+ {
+ lpRGB[i].rgbRed = 0;
+ lpRGB[i].rgbGreen = 0;
+ lpRGB[i].rgbBlue = 0;
+ }
lpRGB[i].rgbReserved = 0;
lpIndex++;
}