[PATCH] Enable X11DRV_DIB_GetImageBits_8 in all cases and optimize X11DRV_DIB_GetNearestIndex to fix bug 2666 and other strange behavior
Alex Henrie
alexhenrie24 at gmail.com
Wed Sep 28 14:07:17 CDT 2011
---
dlls/winex11.drv/dib.c | 39 +++++++++++++++++----------------------
1 files changed, 17 insertions(+), 22 deletions(-)
diff --git a/dlls/winex11.drv/dib.c b/dlls/winex11.drv/dib.c
index 4593d9a..6535ea8 100644
--- a/dlls/winex11.drv/dib.c
+++ b/dlls/winex11.drv/dib.c
@@ -32,6 +32,7 @@
# endif
#endif /* defined(HAVE_LIBXXSHM) */
+#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
@@ -341,19 +342,25 @@ static int X11DRV_DIB_MapColor( int *physMap, int nPhysMap, int phys, int oldcol
*/
static INT X11DRV_DIB_GetNearestIndex(RGBQUAD *colormap, int numColors, BYTE r, BYTE g, BYTE b)
{
- INT i, best = -1, diff, bestdiff = -1;
+ INT i, best, diff, bestdiff;
RGBQUAD *color;
+ /* most likely, one of the colors in the color map is an exact match of the color we're looking for */
+ for(color = colormap, i = 0; i < numColors; color++, i++)
+ if(r == color->rgbRed && g == color->rgbGreen && b == color->rgbBlue)
+ return i;
+
+ /* but if it's not, sum the squares to find the color with the smallest difference */
+ best = 0;
+ bestdiff = INT_MAX;
for(color = colormap, i = 0; i < numColors; color++, i++) {
diff = (r - color->rgbRed) * (r - color->rgbRed) +
- (g - color->rgbGreen) * (g - color->rgbGreen) +
- (b - color->rgbBlue) * (b - color->rgbBlue);
- if(diff == 0)
- return i;
- if(best == -1 || diff < bestdiff) {
- best = i;
- bestdiff = diff;
- }
+ (g - color->rgbGreen) * (g - color->rgbGreen) +
+ (b - color->rgbBlue) * (b - color->rgbBlue);
+ if(diff < bestdiff) {
+ best = i;
+ bestdiff = diff;
+ }
}
return best;
}
@@ -1344,15 +1351,6 @@ static void X11DRV_DIB_GetImageBits_8( int lines, BYTE *dstbits,
linebytes = -linebytes;
}
- /*
- * Hack for now
- * This condition is true when GetImageBits has been called by
- * UpdateDIBSection. For now, GetNearestIndex is too slow to support
- * 256 colormaps, so we'll just use it for GetDIBits calls.
- * (In some cases, in an updateDIBSection, the returned colors are bad too)
- */
- if (!srccolors) goto updatesection;
-
switch (bmpImage->depth) {
case 1:
case 4:
@@ -1563,7 +1561,6 @@ static void X11DRV_DIB_GetImageBits_8( int lines, BYTE *dstbits,
WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 8 bit DIB\n",
bmpImage->depth, bmpImage->red_mask,
bmpImage->green_mask, bmpImage->blue_mask );
- updatesection:
/* ==== any bmp format -> pal 8 dib ==== */
for (h=lines-1; h>=0; h--) {
dstbyte=dstbits;
@@ -3456,12 +3453,10 @@ static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP *physBitmap, BOOL toDIB,
descr.compression = dibSection.dsBmih.biCompression;
descr.physBitmap = physBitmap;
- if(descr.infoBpp == 1)
- descr.colorMap = (void*)identity;
-
switch (descr.infoBpp)
{
case 1:
+ descr.colorMap = (void*)identity;
case 4:
case 8:
descr.rMask = descr.gMask = descr.bMask = 0;
--
1.7.4.1
More information about the wine-patches
mailing list