winex11.drv: Remove the coloruse == -1 special case. Add X11DRV_DIB_GetColorCount() for computing a bitmap's number of colors.
Francois Gouget
fgouget at codeweavers.com
Thu Oct 18 10:10:06 CDT 2007
---
coloruse is supposed to be either DIB_RGB_COLORS or DIB_PAL_COLORS.
X11DRV_DIB_CopyDIBSection() was using -1 in order to bypass all the
normal processing in X11DRV_DIB_GenColorMap() and build its own special
color palette. But it's just a few lines anyway so it's just as simple
to build that color palette directly in X11DRV_DIB_CopyDIBSection()
itself.
dlls/winex11.drv/dib.c | 102 +++++++++++++++++++++++++++--------------------
1 files changed, 59 insertions(+), 43 deletions(-)
diff --git a/dlls/winex11.drv/dib.c b/dlls/winex11.drv/dib.c
index 4c28928..e24bd96 100644
--- a/dlls/winex11.drv/dib.c
+++ b/dlls/winex11.drv/dib.c
@@ -257,6 +257,34 @@ static int DIB_GetBitmapInfoEx( const BITMAPINFOHEADER *header, LONG *width,
/***********************************************************************
+ * X11DRV_DIB_GetColorCount
+ *
+ * Computes the number of colors for the bitmap palette.
+ * Should not be called for a >8-bit deep bitmap.
+ */
+static unsigned int X11DRV_DIB_GetColorCount(const BITMAPINFO *info)
+{
+ unsigned int colors;
+ BOOL core_info = info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER);
+
+ if (core_info)
+ {
+ colors = 1 << ((const BITMAPCOREINFO*)info)->bmciHeader.bcBitCount;
+ }
+ else
+ {
+ colors = info->bmiHeader.biClrUsed;
+ if (!colors) colors = 1 << info->bmiHeader.biBitCount;
+ }
+ if (colors > 256)
+ {
+ ERR("called with >256 colors!\n");
+ colors = 0;
+ }
+ return colors;
+}
+
+/***********************************************************************
* DIB_GetBitmapInfo
*
* Get the info from a bitmap header.
@@ -343,15 +371,10 @@ static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE *physDev, int *colorMapping,
}
else /* DIB_PAL_COLORS */
{
- if (colorPtr) {
- const WORD * index = (const WORD *)colorPtr;
+ const WORD * index = (const WORD *)colorPtr;
- for (i = start; i < end; i++, index++)
- colorMapping[i] = X11DRV_PALETTE_ToPhysical( physDev, PALETTEINDEX(*index) );
- } else {
- for (i = start; i < end; i++)
- colorMapping[i] = X11DRV_PALETTE_ToPhysical( physDev, PALETTEINDEX(i) );
- }
+ for (i = start; i < end; i++, index++)
+ colorMapping[i] = X11DRV_PALETTE_ToPhysical( physDev, PALETTEINDEX(*index) );
}
return colorMapping;
@@ -366,40 +389,21 @@ static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE *physDev, int *colorMapping,
static int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE *physDev, WORD coloruse, WORD depth,
const BITMAPINFO *info, int *nColors )
{
- unsigned int colors;
BOOL isInfo;
const void *colorPtr;
int *colorMapping;
- isInfo = info->bmiHeader.biSize != sizeof(BITMAPCOREHEADER);
- if (isInfo)
- {
- colors = info->bmiHeader.biClrUsed;
- if (!colors) colors = 1 << info->bmiHeader.biBitCount;
- }
- else
- {
- colors = 1 << ((const BITMAPCOREHEADER *)info)->bcBitCount;
- }
+ *nColors = X11DRV_DIB_GetColorCount(info);
+ if (!*nColors) return NULL;
- colorPtr = (const BYTE*) info + (WORD) info->bmiHeader.biSize;
-
- if (colors > 256)
- {
- ERR("called with >256 colors!\n");
- return NULL;
- }
-
- /* just so CopyDIBSection doesn't have to create an identity palette */
- if (coloruse == (WORD)-1) colorPtr = NULL;
-
- if (!(colorMapping = HeapAlloc(GetProcessHeap(), 0, colors * sizeof(int) )))
+ isInfo = info->bmiHeader.biSize != sizeof(BITMAPCOREHEADER);
+ colorPtr = (const BYTE*)info + (WORD)info->bmiHeader.biSize;
+ if (!(colorMapping = HeapAlloc(GetProcessHeap(), 0, *nColors * sizeof(int) )))
return NULL;
- *nColors = colors;
return X11DRV_DIB_GenColorMap( physDev, colorMapping, coloruse, depth,
- isInfo, colorPtr, 0, colors);
+ isInfo, colorPtr, 0, *nColors);
}
/***********************************************************************
@@ -4199,7 +4203,9 @@ void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE *physDevSrc, X11DRV_PDEVICE *physD
{
DIBSECTION dib;
X_PHYSBITMAP *physBitmap;
- int nColorMap = 0, *colorMap = NULL, aColorMap = FALSE;
+ unsigned int nColorMap;
+ int* x11ColorMap;
+ int freeColorMap;
TRACE("(%p,%p,%d,%d,%d,%d,%d,%d)\n", physDevSrc->hdc, physDevDst->hdc,
xSrc, ySrc, xDest, yDest, width, height);
@@ -4228,24 +4234,34 @@ void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE *physDevSrc, X11DRV_PDEVICE *physD
* use the DIB colormap instead - this is necessary in some
* cases since we need to do depth conversion in some places
* where real Windows can just copy data straight over */
- colorMap = physBitmap->colorMap;
+ x11ColorMap = physBitmap->colorMap;
nColorMap = physBitmap->nColorMap;
+ freeColorMap = FALSE;
} else {
- colorMap = X11DRV_DIB_BuildColorMap( physDevSrc, (WORD)-1,
- dib.dsBm.bmBitsPixel,
- (BITMAPINFO*)&dib.dsBmih,
- &nColorMap );
- if (colorMap) aColorMap = TRUE;
+ const BITMAPINFO* info = (BITMAPINFO*)&dib.dsBmih;
+ int i;
+
+ nColorMap = X11DRV_DIB_GetColorCount(info);
+ x11ColorMap = HeapAlloc(GetProcessHeap(), 0, nColorMap * sizeof(int));
+ for (i = 0; i < nColorMap; i++)
+ x11ColorMap[i] = X11DRV_PALETTE_ToPhysical(physDevSrc, PALETTEINDEX(i));
+ freeColorMap = TRUE;
}
}
+ else
+ {
+ nColorMap = 0;
+ x11ColorMap = NULL;
+ freeColorMap = FALSE;
+ }
/* perform the copy */
- X11DRV_DIB_DoCopyDIBSection(physBitmap, FALSE, colorMap, nColorMap,
+ X11DRV_DIB_DoCopyDIBSection(physBitmap, FALSE, x11ColorMap, nColorMap,
physDevDst->drawable, physDevDst->gc, xSrc, ySrc,
physDevDst->dc_rect.left + xDest, physDevDst->dc_rect.top + yDest,
width, height);
/* free color mapping */
- if (aColorMap)
- HeapFree(GetProcessHeap(), 0, colorMap);
+ if (freeColorMap)
+ HeapFree(GetProcessHeap(), 0, x11ColorMap);
}
}
--
1.5.3.4
More information about the wine-patches
mailing list