Removed space optimalization of XLATEGDI that caused some problems.

svn path=/trunk/; revision=7133
This commit is contained in:
Filip Navara 2003-12-20 14:51:41 +00:00
parent 6594b15c96
commit 705104e713
3 changed files with 400 additions and 87 deletions

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: objects.h,v 1.22 2003/12/19 22:58:47 navaraf Exp $ /* $Id: objects.h,v 1.23 2003/12/20 14:51:41 navaraf Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -209,22 +209,22 @@ typedef struct _XLATEGDI {
HPALETTE SourcePal; HPALETTE SourcePal;
BOOL UseShiftAndMask; BOOL UseShiftAndMask;
union { // union {
struct { /* For Shift Translations */ // struct { /* For Shift Translations */
ULONG RedMask; ULONG RedMask;
ULONG GreenMask; ULONG GreenMask;
ULONG BlueMask; ULONG BlueMask;
INT RedShift; INT RedShift;
INT GreenShift; INT GreenShift;
INT BlueShift; INT BlueShift;
}; // };
struct { /* For Table Translations */ // struct { /* For Table Translations */
ULONG *translationTable; ULONG *translationTable;
}; // };
struct { /* For Color -> Mono Translations */ // struct { /* For Color -> Mono Translations */
ULONG BackgroundColor; ULONG BackgroundColor;
}; // };
}; // };
} XLATEGDI; } XLATEGDI;
// List of GDI objects // List of GDI objects

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: xlate.c,v 1.28 2003/12/20 14:19:47 navaraf Exp $ /* $Id: xlate.c,v 1.29 2003/12/20 14:51:41 navaraf Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -43,16 +43,6 @@
ULONG CCMLastSourceColor = 0, CCMLastColorMatch = 0; ULONG CCMLastSourceColor = 0, CCMLastColorMatch = 0;
ULONG STDCALL RGBtoULONG(BYTE Red, BYTE Green, BYTE Blue)
{
return ((Red & 0xff) << 16) | ((Green & 0xff) << 8) | (Blue & 0xff);
}
ULONG STDCALL BGRtoULONG(BYTE Blue, BYTE Green, BYTE Red)
{
return ((Blue & 0xff) << 16) | ((Green & 0xff) << 8) | (Red & 0xff);
}
static ULONG FASTCALL ShiftAndMask(XLATEGDI *XlateGDI, ULONG Color) static ULONG FASTCALL ShiftAndMask(XLATEGDI *XlateGDI, ULONG Color)
{ {
ULONG TranslatedColor; ULONG TranslatedColor;
@ -470,65 +460,65 @@ XLATEOBJ * STDCALL IntEngCreateMonoXlate(
/* /*
* @implemented * @implemented
*/ */
ULONG * STDCALL PULONG STDCALL
XLATEOBJ_piVector(XLATEOBJ *XlateObj) XLATEOBJ_piVector(XLATEOBJ *XlateObj)
{ {
XLATEGDI *XlateGDI = (XLATEGDI*)AccessInternalObjectFromUserObject(XlateObj); XLATEGDI *XlateGDI = (XLATEGDI*)AccessInternalObjectFromUserObject(XlateObj);
if(XlateObj->iSrcType == PAL_INDEXED) if (XlateObj->iSrcType == PAL_INDEXED)
{ {
return XlateGDI->translationTable; return XlateGDI->translationTable;
} }
return NULL; return NULL;
} }
/* /*
* @unimplemented * @implemented
*/ */
ULONG STDCALL ULONG STDCALL
XLATEOBJ_iXlate(XLATEOBJ *XlateObj, XLATEOBJ_iXlate(XLATEOBJ *XlateObj, ULONG Color)
ULONG Color)
{ {
PALGDI *PalGDI; PALGDI *PalGDI;
ULONG Closest; ULONG Closest;
// Return the original color if there's no color translation object /* Return the original color if there's no color translation object. */
if(!XlateObj) return Color; if (!XlateObj)
return Color;
if(XlateObj->flXlate & XO_TRIVIAL) if (XlateObj->flXlate & XO_TRIVIAL)
{ {
return Color; return Color;
} else } else
{ {
XLATEGDI *XlateGDI = (XLATEGDI*)AccessInternalObjectFromUserObject(XlateObj); XLATEGDI *XlateGDI = (XLATEGDI *)AccessInternalObjectFromUserObject(XlateObj);
if(XlateObj->flXlate & XO_TO_MONO) if (XlateObj->flXlate & XO_TO_MONO)
{ {
return Color == XlateGDI->BackgroundColor; return Color == XlateGDI->BackgroundColor;
} else } else
if(XlateGDI->UseShiftAndMask) if (XlateGDI->UseShiftAndMask)
{ {
return ShiftAndMask(XlateGDI, Color); return ShiftAndMask(XlateGDI, Color);
} else } else
if (PAL_RGB == XlateObj->iSrcType || PAL_BGR == XlateObj->iSrcType if (XlateObj->iSrcType == PAL_RGB || XlateObj->iSrcType == PAL_BGR ||
|| PAL_BITFIELDS == XlateObj->iSrcType) XlateObj->iSrcType == PAL_BITFIELDS)
{ {
// FIXME: should we cache colors used often? /* FIXME: should we cache colors used often? *
// FIXME: won't work if destination isn't indexed /* FIXME: won't work if destination isn't indexed */
// Extract the destination palette /* Extract the destination palette. */
PalGDI = PALETTE_LockPalette(XlateGDI->DestPal); PalGDI = PALETTE_LockPalette(XlateGDI->DestPal);
// Return closest match for the given color /* Return closest match for the given color. */
Closest = ClosestColorMatch(XlateGDI, Color, PalGDI->IndexedColors, PalGDI->NumColors); Closest = ClosestColorMatch(XlateGDI, Color, PalGDI->IndexedColors, PalGDI->NumColors);
PALETTE_UnlockPalette(XlateGDI->DestPal); PALETTE_UnlockPalette(XlateGDI->DestPal);
return Closest; return Closest;
} else } else
if(XlateObj->iSrcType == PAL_INDEXED) if (XlateObj->iSrcType == PAL_INDEXED)
{ {
return XlateGDI->translationTable[Color]; return XlateGDI->translationTable[Color];
} }
} }
return 0; return 0;
@ -538,32 +528,27 @@ XLATEOBJ_iXlate(XLATEOBJ *XlateObj,
* @implemented * @implemented
*/ */
ULONG STDCALL ULONG STDCALL
XLATEOBJ_cGetPalette(XLATEOBJ *XlateObj, XLATEOBJ_cGetPalette(XLATEOBJ *XlateObj, ULONG PalOutType, ULONG cPal,
ULONG PalOutType, ULONG *OutPal)
ULONG cPal,
ULONG *OutPal)
{ {
ULONG i; HPALETTE hPalette;
HPALETTE HPal; XLATEGDI *XlateGDI;
XLATEGDI *XlateGDI; PALGDI *PalGDI;
PALGDI *PalGDI; ULONG i;
XlateGDI = (XLATEGDI*)AccessInternalObjectFromUserObject(XlateObj); XlateGDI = (XLATEGDI*)AccessInternalObjectFromUserObject(XlateObj);
if (PalOutType == XO_SRCPALETTE)
hPalette = XlateGDI->SourcePal;
else if (PalOutType == XO_DESTPALETTE)
hPalette = XlateGDI->DestPal;
else
UNIMPLEMENTED;
if(PalOutType == XO_SRCPALETTE) PalGDI = PALETTE_LockPalette(hPalette);
{ RtlCopyMemory(OutPal, PalGDI->IndexedColors, sizeof(ULONG) * cPal);
HPal = XlateGDI->SourcePal; PALETTE_UnlockPalette(hPalette);
} else
if(PalOutType == XO_DESTPALETTE)
{
HPal = XlateGDI->DestPal;
}
PalGDI = PALETTE_LockPalette(HPal); return cPal;
RtlCopyMemory(OutPal, PalGDI->IndexedColors, sizeof(ULONG)*cPal);
PALETTE_UnlockPalette(HPal);
return i;
} }
/* EOF */ /* EOF */

View file

@ -1,5 +1,5 @@
/* /*
* $Id: dib.c,v 1.38 2003/12/20 10:31:32 navaraf Exp $ * $Id: dib.c,v 1.39 2003/12/20 14:51:41 navaraf Exp $
* *
* ReactOS W32 Subsystem * ReactOS W32 Subsystem
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
@ -30,6 +30,7 @@
#include <include/inteng.h> #include <include/inteng.h>
#include <include/eng.h> #include <include/eng.h>
#include <include/dib.h> #include <include/dib.h>
#include <include/color.h>
#include <internal/safe.h> #include <internal/safe.h>
#include <include/surface.h> #include <include/surface.h>
#include <include/palette.h> #include <include/palette.h>
@ -257,6 +258,7 @@ UINT STDCALL NtGdiGetDIBColorTable(HDC hDC,
} }
// Converts a device-dependent bitmap to a DIB // Converts a device-dependent bitmap to a DIB
#if 0
INT STDCALL NtGdiGetDIBits(HDC hDC, INT STDCALL NtGdiGetDIBits(HDC hDC,
HBITMAP hBitmap, HBITMAP hBitmap,
UINT StartScan, UINT StartScan,
@ -264,7 +266,18 @@ INT STDCALL NtGdiGetDIBits(HDC hDC,
LPVOID Bits, LPVOID Bits,
LPBITMAPINFO UnsafeInfo, LPBITMAPINFO UnsafeInfo,
UINT Usage) UINT Usage)
#else
INT STDCALL NtGdiGetDIBits(
HDC hdc, /* [in] Handle to device context */
HBITMAP hbitmap, /* [in] Handle to bitmap */
UINT startscan, /* [in] First scan line to set in dest bitmap */
UINT lines, /* [in] Number of scan lines to copy */
LPVOID bits, /* [out] Address of array for bitmap bits */
BITMAPINFO * info, /* [out] Address of structure with bitmap data */
UINT coloruse) /* [in] RGB or palette index */
#endif
{ {
#if 0
BITMAPINFO Info; BITMAPINFO Info;
BITMAPCOREHEADER *Core; BITMAPCOREHEADER *Core;
PBITMAPOBJ BitmapObj; PBITMAPOBJ BitmapObj;
@ -414,6 +427,321 @@ INT STDCALL NtGdiGetDIBits(HDC hDC,
BITMAPOBJ_UnlockBitmap(hBitmap); BITMAPOBJ_UnlockBitmap(hBitmap);
return Result; return Result;
#else
PDC dc;
PBITMAPOBJ bmp;
int i;
if (!info) return 0;
if (!(dc = DC_LockDc( hdc ))) return 0;
if (!(bmp = BITMAPOBJ_LockBitmap(hbitmap)))
{
DC_UnlockDc( hdc );
return 0;
}
/* Transfer color info */
if (info->bmiHeader.biBitCount <= 8 && info->bmiHeader.biBitCount > 0 ) {
info->bmiHeader.biClrUsed = 0;
/* If the bitmap object already has a dib section at the
same color depth then get the color map from it */
if (bmp->dib && bmp->dib->dsBm.bmBitsPixel == info->bmiHeader.biBitCount) {
NtGdiGetDIBColorTable(hdc, 0, 1 << info->bmiHeader.biBitCount, info->bmiColors);
}
else {
if(info->bmiHeader.biBitCount >= bmp->bitmap.bmBitsPixel) {
/* Generate the color map from the selected palette */
PALETTEENTRY * palEntry;
PPALGDI palette;
if (!(palette = PALETTE_LockPalette(dc->w.hPalette))) {
DC_UnlockDc( hdc );
BITMAPOBJ_UnlockBitmap( hbitmap );
return 0;
}
palEntry = palette->IndexedColors;
for (i = 0; i < (1 << bmp->bitmap.bmBitsPixel); i++, palEntry++) {
if (coloruse == DIB_RGB_COLORS) {
info->bmiColors[i].rgbRed = palEntry->peRed;
info->bmiColors[i].rgbGreen = palEntry->peGreen;
info->bmiColors[i].rgbBlue = palEntry->peBlue;
info->bmiColors[i].rgbReserved = 0;
}
else ((WORD *)info->bmiColors)[i] = (WORD)i;
}
PALETTE_UnlockPalette( dc->w.hPalette );
} else {
switch (info->bmiHeader.biBitCount) {
case 1:
info->bmiColors[0].rgbRed = info->bmiColors[0].rgbGreen =
info->bmiColors[0].rgbBlue = 0;
info->bmiColors[0].rgbReserved = 0;
info->bmiColors[1].rgbRed = info->bmiColors[1].rgbGreen =
info->bmiColors[1].rgbBlue = 0xff;
info->bmiColors[1].rgbReserved = 0;
break;
case 4:
memcpy(info->bmiColors, COLOR_GetSystemPaletteTemplate(), NB_RESERVED_COLORS * sizeof(PALETTEENTRY));
break;
case 8:
{
INT r, g, b;
RGBQUAD *color;
memcpy(info->bmiColors, COLOR_GetSystemPaletteTemplate(),
10 * sizeof(RGBQUAD));
memcpy(info->bmiColors + 246, COLOR_GetSystemPaletteTemplate() + 10,
10 * sizeof(RGBQUAD));
color = info->bmiColors + 10;
for(r = 0; r <= 5; r++) /* FIXME */
for(g = 0; g <= 5; g++)
for(b = 0; b <= 5; b++) {
color->rgbRed = (r * 0xff) / 5;
color->rgbGreen = (g * 0xff) / 5;
color->rgbBlue = (b * 0xff) / 5;
color->rgbReserved = 0;
color++;
}
}
}
}
}
}
if (bits && lines)
{
/* If the bitmap object already have a dib section that contains image data, get the bits from it */
if(bmp->dib && bmp->dib->dsBm.bmBitsPixel >= 15 && info->bmiHeader.biBitCount >= 15)
{
/*FIXME: Only RGB dibs supported for now */
unsigned int srcwidth = bmp->dib->dsBm.bmWidth, srcwidthb = bmp->dib->dsBm.bmWidthBytes;
int dstwidthb = DIB_GetDIBWidthBytes( info->bmiHeader.biWidth, info->bmiHeader.biBitCount );
LPBYTE dbits = bits, sbits = (LPBYTE) bmp->dib->dsBm.bmBits + (startscan * srcwidthb);
unsigned int x, y;
if ((info->bmiHeader.biHeight < 0) ^ (bmp->dib->dsBmih.biHeight < 0))
{
dbits = (LPBYTE)bits + (dstwidthb * (lines-1));
dstwidthb = -dstwidthb;
}
switch( info->bmiHeader.biBitCount ) {
case 15:
case 16: /* 16 bpp dstDIB */
{
LPWORD dstbits = (LPWORD)dbits;
WORD rmask = 0x7c00, gmask= 0x03e0, bmask = 0x001f;
/* FIXME: BI_BITFIELDS not supported yet */
switch(bmp->dib->dsBm.bmBitsPixel) {
case 16: /* 16 bpp srcDIB -> 16 bpp dstDIB */
{
/* FIXME: BI_BITFIELDS not supported yet */
for (y = 0; y < lines; y++, dbits+=dstwidthb, sbits+=srcwidthb)
memcpy(dbits, sbits, srcwidthb);
}
break;
case 24: /* 24 bpp srcDIB -> 16 bpp dstDIB */
{
LPBYTE srcbits = sbits;
for( y = 0; y < lines; y++) {
for( x = 0; x < srcwidth; x++, srcbits += 3)
*dstbits++ = ((srcbits[0] >> 3) & bmask) |
(((WORD)srcbits[1] << 2) & gmask) |
(((WORD)srcbits[2] << 7) & rmask);
dstbits = (LPWORD)(dbits+=dstwidthb);
srcbits = (sbits += srcwidthb);
}
}
break;
case 32: /* 32 bpp srcDIB -> 16 bpp dstDIB */
{
LPDWORD srcbits = (LPDWORD)sbits;
DWORD val;
for( y = 0; y < lines; y++) {
for( x = 0; x < srcwidth; x++ ) {
val = *srcbits++;
*dstbits++ = (WORD)(((val >> 3) & bmask) | ((val >> 6) & gmask) |
((val >> 9) & rmask));
}
dstbits = (LPWORD)(dbits+=dstwidthb);
srcbits = (LPDWORD)(sbits+=srcwidthb);
}
}
break;
default: /* ? bit bmp -> 16 bit DIB */
DPRINT1("FIXME: 15/16 bit DIB %d bit bitmap\n",
bmp->bitmap.bmBitsPixel);
break;
}
}
break;
case 24: /* 24 bpp dstDIB */
{
LPBYTE dstbits = dbits;
switch(bmp->dib->dsBm.bmBitsPixel) {
case 16: /* 16 bpp srcDIB -> 24 bpp dstDIB */
{
LPWORD srcbits = (LPWORD)sbits;
WORD val;
/* FIXME: BI_BITFIELDS not supported yet */
for( y = 0; y < lines; y++) {
for( x = 0; x < srcwidth; x++ ) {
val = *srcbits++;
*dstbits++ = (BYTE)(((val << 3) & 0xf8) | ((val >> 2) & 0x07));
*dstbits++ = (BYTE)(((val >> 2) & 0xf8) | ((val >> 7) & 0x07));
*dstbits++ = (BYTE)(((val >> 7) & 0xf8) | ((val >> 12) & 0x07));
}
dstbits = (LPBYTE)(dbits+=dstwidthb);
srcbits = (LPWORD)(sbits+=srcwidthb);
}
}
break;
case 24: /* 24 bpp srcDIB -> 24 bpp dstDIB */
{
for (y = 0; y < lines; y++, dbits+=dstwidthb, sbits+=srcwidthb)
memcpy(dbits, sbits, srcwidthb);
}
break;
case 32: /* 32 bpp srcDIB -> 24 bpp dstDIB */
{
LPBYTE srcbits = (LPBYTE)sbits;
for( y = 0; y < lines; y++) {
for( x = 0; x < srcwidth; x++, srcbits++ ) {
*dstbits++ = *srcbits++;
*dstbits++ = *srcbits++;
*dstbits++ = *srcbits++;
}
dstbits=(LPBYTE)(dbits+=dstwidthb);
srcbits = (LPBYTE)(sbits+=srcwidthb);
}
}
break;
default: /* ? bit bmp -> 24 bit DIB */
DPRINT1("FIXME: 24 bit DIB %d bit bitmap\n",
bmp->bitmap.bmBitsPixel);
break;
}
}
break;
case 32: /* 32 bpp dstDIB */
{
LPDWORD dstbits = (LPDWORD)dbits;
/* FIXME: BI_BITFIELDS not supported yet */
switch(bmp->dib->dsBm.bmBitsPixel) {
case 16: /* 16 bpp srcDIB -> 32 bpp dstDIB */
{
LPWORD srcbits = (LPWORD)sbits;
DWORD val;
/* FIXME: BI_BITFIELDS not supported yet */
for( y = 0; y < lines; y++) {
for( x = 0; x < srcwidth; x++ ) {
val = (DWORD)*srcbits++;
*dstbits++ = ((val << 3) & 0xf8) | ((val >> 2) & 0x07) |
((val << 6) & 0xf800) | ((val << 1) & 0x0700) |
((val << 9) & 0xf80000) | ((val << 4) & 0x070000);
}
dstbits=(LPDWORD)(dbits+=dstwidthb);
srcbits=(LPWORD)(sbits+=srcwidthb);
}
}
break;
case 24: /* 24 bpp srcDIB -> 32 bpp dstDIB */
{
LPBYTE srcbits = sbits;
for( y = 0; y < lines; y++) {
for( x = 0; x < srcwidth; x++, srcbits+=3 )
*dstbits++ = ((DWORD)*srcbits) & 0x00ffffff;
dstbits=(LPDWORD)(dbits+=dstwidthb);
srcbits=(sbits+=srcwidthb);
}
}
break;
case 32: /* 32 bpp srcDIB -> 16 bpp dstDIB */
{
/* FIXME: BI_BITFIELDS not supported yet */
for (y = 0; y < lines; y++, dbits+=dstwidthb, sbits+=srcwidthb)
memcpy(dbits, sbits, srcwidthb);
}
break;
default: /* ? bit bmp -> 32 bit DIB */
DPRINT1("FIXME: 32 bit DIB %d bit bitmap\n",
bmp->bitmap.bmBitsPixel);
break;
}
}
break;
default: /* ? bit DIB */
DPRINT1("FIXME: Unsupported DIB depth %d\n", info->bmiHeader.biBitCount);
break;
}
}
/* Otherwise, get bits from the XImage */
else
{
UNIMPLEMENTED;
}
}
else if( info->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER) )
{
/* fill in struct members */
if( info->bmiHeader.biBitCount == 0)
{
info->bmiHeader.biWidth = bmp->bitmap.bmWidth;
info->bmiHeader.biHeight = bmp->bitmap.bmHeight;
info->bmiHeader.biPlanes = 1;
info->bmiHeader.biBitCount = bmp->bitmap.bmBitsPixel;
info->bmiHeader.biSizeImage =
DIB_GetDIBImageBytes( bmp->bitmap.bmWidth,
bmp->bitmap.bmHeight,
bmp->bitmap.bmBitsPixel );
info->bmiHeader.biCompression = 0;
}
else
{
info->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(
info->bmiHeader.biWidth,
info->bmiHeader.biHeight,
info->bmiHeader.biBitCount );
}
}
DC_UnlockDc( hdc );
BITMAPOBJ_UnlockBitmap( hbitmap );
return lines;
#endif
} }
INT STDCALL NtGdiStretchDIBits(HDC hDC, INT STDCALL NtGdiStretchDIBits(HDC hDC,