diff --git a/dlls/winex11.drv/Makefile.in b/dlls/winex11.drv/Makefile.in index 9af183c4078..2128fc4c73a 100644 --- a/dlls/winex11.drv/Makefile.in +++ b/dlls/winex11.drv/Makefile.in @@ -11,10 +11,6 @@ C_SRCS = \ clipboard.c \ codepage.c \ desktop.c \ - dib.c \ - dib_convert.c \ - dib_dst_swap.c \ - dib_src_swap.c \ event.c \ graphics.c \ ime.c \ diff --git a/dlls/winex11.drv/bitmap.c b/dlls/winex11.drv/bitmap.c index 2232c49a7a8..c32083a9c79 100644 --- a/dlls/winex11.drv/bitmap.c +++ b/dlls/winex11.drv/bitmap.c @@ -234,11 +234,6 @@ BOOL X11DRV_DeleteBitmap( HBITMAP hbitmap ) if (physBitmap) { - DIBSECTION dib; - - if (GetObjectW( hbitmap, sizeof(dib), &dib ) == sizeof(dib)) - X11DRV_DIB_DeleteDIBSection( physBitmap, &dib ); - if (physBitmap->glxpixmap) destroy_glxpixmap( gdi_display, physBitmap->glxpixmap ); wine_tsx11_lock(); diff --git a/dlls/winex11.drv/dib.c b/dlls/winex11.drv/dib.c deleted file mode 100644 index f2b19387723..00000000000 --- a/dlls/winex11.drv/dib.c +++ /dev/null @@ -1,3978 +0,0 @@ -/* - * X11DRV device-independent bitmaps - * - * Copyright 1993,1994 Alexandre Julliard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include "config.h" -#include "wine/port.h" - -#include -#ifdef HAVE_LIBXXSHM -#include -# ifdef HAVE_SYS_SHM_H -# include -# endif -# ifdef HAVE_SYS_IPC_H -# include -# endif -#endif /* defined(HAVE_LIBXXSHM) */ - -#include -#include -#include -#include "windef.h" -#include "winbase.h" -#include "wingdi.h" -#include "x11drv.h" -#include "wine/exception.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(bitmap); - -static struct list dibs_list = LIST_INIT(dibs_list); - -static CRITICAL_SECTION dibs_cs; -static CRITICAL_SECTION_DEBUG dibs_cs_debug = -{ - 0, 0, &dibs_cs, - { &dibs_cs_debug.ProcessLocksList, &dibs_cs_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": dibs_cs") } -}; -static CRITICAL_SECTION dibs_cs = { &dibs_cs_debug, -1, 0, 0, 0, 0 }; - -static PVOID dibs_handler; - -static int ximageDepthTable[32]; - -/* This structure holds the arguments for DIB_SetImageBits() */ -typedef struct -{ - X11DRV_PDEVICE *physDev; - LPCVOID bits; - XImage *image; - PALETTEENTRY *palentry; - int lines; - DWORD infoWidth; - WORD depth; - WORD infoBpp; - WORD compression; - ColorShifts *shifts; - RGBQUAD *colorMap; - int nColorMap; - Drawable drawable; - GC gc; - int xSrc; - int ySrc; - int xDest; - int yDest; - int width; - int height; - DWORD rMask; - DWORD gMask; - DWORD bMask; - enum x11drv_shm_mode shm_mode; - int dibpitch; - DWORD sizeImage; - X_PHYSBITMAP *physBitmap; -} X11DRV_DIB_IMAGEBITS_DESCR; - - -enum Rle_EscapeCodes -{ - RLE_EOL = 0, /* End of line */ - RLE_END = 1, /* End of bitmap */ - RLE_DELTA = 2 /* Delta */ -}; - - -static INT X11DRV_DIB_Coerce(X_PHYSBITMAP *,INT); - -/* - Some of the following helper functions are duplicated in - dlls/gdi/dib.c -*/ - -/*********************************************************************** - * DIB_DoProtectDIBSection - */ -static void X11DRV_DIB_DoProtectDIBSection( X_PHYSBITMAP *physBitmap, DWORD new_prot ) -{ - DWORD old_prot; - - VirtualProtect(physBitmap->base, physBitmap->size, new_prot, &old_prot); - TRACE("Changed protection from %d to %d\n", old_prot, new_prot); -} - -/*********************************************************************** - * X11DRV_DIB_GetXImageWidthBytes - * - * Return the width of an X image in bytes - */ -static inline int X11DRV_DIB_GetXImageWidthBytes( int width, int depth ) -{ - if (!depth || depth > 32) goto error; - - if (!ximageDepthTable[depth-1]) - { - XImage *testimage = XCreateImage( gdi_display, visual, depth, - ZPixmap, 0, NULL, 1, 1, 32, 20 ); - if (testimage) - { - ximageDepthTable[depth-1] = testimage->bits_per_pixel; - XDestroyImage( testimage ); - } - else ximageDepthTable[depth-1] = -1; - } - if (ximageDepthTable[depth-1] != -1) - return (4 * ((width * ximageDepthTable[depth-1] + 31) / 32)); - - error: - WARN( "(%d): Unsupported depth\n", depth ); - return 4 * width; -} - - -/*********************************************************************** - * X11DRV_DIB_CreateXImage - * - * Create an X image. - */ -XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth ) -{ - int width_bytes; - XImage *image = NULL; - void *data; - - wine_tsx11_lock(); - width_bytes = X11DRV_DIB_GetXImageWidthBytes( width, depth ); - data = HeapAlloc( GetProcessHeap(), 0, height * width_bytes ); - if (data) image = XCreateImage( gdi_display, visual, depth, ZPixmap, 0, - data, width, height, 32, width_bytes ); - if (!image) HeapFree( GetProcessHeap(), 0, data ); - wine_tsx11_unlock(); - return image; -} - - -/*********************************************************************** - * X11DRV_DIB_DestroyXImage - * - * Destroy an X image created with X11DRV_DIB_CreateXImage. - */ -void X11DRV_DIB_DestroyXImage( XImage *image ) -{ - HeapFree( GetProcessHeap(), 0, image->data ); - image->data = NULL; - wine_tsx11_lock(); - XDestroyImage( image ); - wine_tsx11_unlock(); -} - - -/*********************************************************************** - * 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 = min( info->bmiHeader.biClrUsed, 256 ); - if (!colors) colors = 1 << info->bmiHeader.biBitCount; - return colors; -} - - -static inline BOOL colour_is_brighter(RGBQUAD c1, RGBQUAD c2) -{ - return (c1.rgbRed * c1.rgbRed + c1.rgbGreen * c1.rgbGreen + c1.rgbBlue * c1.rgbBlue) > - (c2.rgbRed * c2.rgbRed + c2.rgbGreen * c2.rgbGreen + c2.rgbBlue * c2.rgbBlue); -} - -/*********************************************************************** - * X11DRV_DIB_GenColorMap - * - * Fills the color map of a bitmap palette. Should not be called - * for a >8-bit deep bitmap. - */ -static int *X11DRV_DIB_GenColorMap( X11DRV_PDEVICE *physDev, int *colorMapping, - WORD coloruse, WORD depth, const void *colorPtr, int start, int end ) -{ - int i; - - if (coloruse == DIB_RGB_COLORS) - { - const RGBQUAD * rgb = colorPtr; - - if (depth == 1) /* Monochrome */ - { - BOOL invert = FALSE; - RGBQUAD table[2]; - - if (GetDIBColorTable( physDev->dev.hdc, 0, 2, table ) == 2) - invert = !colour_is_brighter(table[1], table[0]); - - for (i = start; i < end; i++, rgb++) - colorMapping[i] = ((rgb->rgbRed + rgb->rgbGreen + - rgb->rgbBlue > 255*3/2 && !invert) || - (rgb->rgbRed + rgb->rgbGreen + - rgb->rgbBlue <= 255*3/2 && invert)); - } - else - for (i = start; i < end; i++, rgb++) - colorMapping[i] = X11DRV_PALETTE_LookupPixel(physDev->color_shifts, RGB(rgb->rgbRed, - rgb->rgbGreen, - rgb->rgbBlue)); - } - else /* DIB_PAL_COLORS */ - { - const WORD * index = colorPtr; - - for (i = start; i < end; i++, index++) - colorMapping[i] = X11DRV_PALETTE_ToPhysical( physDev, PALETTEINDEX(*index) ); - } - - return colorMapping; -} - -/*********************************************************************** - * X11DRV_DIB_BuildColorMap - * - * Build the color map from the bitmap palette. Should not be called - * for a >8-bit deep bitmap. - */ -static int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE *physDev, WORD coloruse, WORD depth, - const BITMAPINFO *info, int *nColors ) -{ - const void *colorPtr; - int *colorMapping; - - - *nColors = X11DRV_DIB_GetColorCount(info); - if (!*nColors) return NULL; - - colorPtr = (const BYTE*)info + (WORD)info->bmiHeader.biSize; - if (!(colorMapping = HeapAlloc(GetProcessHeap(), 0, *nColors * sizeof(int) ))) - return NULL; - - return X11DRV_DIB_GenColorMap( physDev, colorMapping, coloruse, depth, - colorPtr, 0, *nColors); -} - -/*********************************************************************** - * X11DRV_DIB_MapColor - */ -static int X11DRV_DIB_MapColor( int *physMap, int nPhysMap, int phys, int oldcol ) -{ - int color; - - if ((oldcol < nPhysMap) && (physMap[oldcol] == phys)) - return oldcol; - - for (color = 0; color < nPhysMap; color++) - if (physMap[color] == phys) - return color; - - WARN("Strange color %08x\n", phys); - return 0; -} - - -/********************************************************************* - * X11DRV_DIB_GetNearestIndex - * - * Helper for X11DRV_DIB_GetDIBits. - * Returns the nearest colour table index for a given RGB. - * Nearest is defined by minimizing the sum of the squares. - */ -static INT X11DRV_DIB_GetNearestIndex(RGBQUAD *colormap, int numColors, BYTE r, BYTE g, BYTE b) -{ - INT i, best = -1, diff, bestdiff = -1; - RGBQUAD *color; - - 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; - } - } - return best; -} -/********************************************************************* - * X11DRV_DIB_MaskToShift - * - * Helper for X11DRV_DIB_GetDIBits. - * Returns the by how many bits to shift a given color so that it is - * in the proper position. - */ -INT X11DRV_DIB_MaskToShift(DWORD mask) -{ - int shift; - - if (mask==0) - return 0; - - shift=0; - while ((mask&1)==0) { - mask>>=1; - shift++; - } - return shift; -} - -/*********************************************************************** - * X11DRV_DIB_CheckMask - * - * Check RGB mask if it is either 0 or matches visual's mask. - */ -static inline int X11DRV_DIB_CheckMask(int red_mask, int green_mask, int blue_mask) -{ - return ( red_mask == 0 && green_mask == 0 && blue_mask == 0 ) || - ( red_mask == visual->red_mask && green_mask == visual->green_mask && - blue_mask == visual->blue_mask ); -} - -/*********************************************************************** - * X11DRV_DIB_SetImageBits_1 - * - * SetDIBits for a 1-bit deep DIB. - */ -static void X11DRV_DIB_SetImageBits_1( int lines, const BYTE *srcbits, - DWORD srcwidth, DWORD dstwidth, int left, - int *colors, XImage *bmpImage, int linebytes) -{ - int h, width; - const BYTE* srcbyte; - BYTE srcval, extra; - DWORD i, x; - - if (lines < 0 ) { - lines = -lines; - srcbits = srcbits + linebytes * (lines - 1); - linebytes = -linebytes; - } - - if ((extra = (left & 7)) != 0) { - left &= ~7; - dstwidth += extra; - } - srcbits += left >> 3; - width = min(srcwidth, dstwidth); - - /* ==== pal 1 dib -> any bmp format ==== */ - for (h = lines-1; h >=0; h--) { - srcbyte=srcbits; - for (i = width/8, x = left; i > 0; i--) { - srcval=*srcbyte++; - XPutPixel( bmpImage, x++, h, colors[ srcval >> 7] ); - XPutPixel( bmpImage, x++, h, colors[(srcval >> 6) & 1] ); - XPutPixel( bmpImage, x++, h, colors[(srcval >> 5) & 1] ); - XPutPixel( bmpImage, x++, h, colors[(srcval >> 4) & 1] ); - XPutPixel( bmpImage, x++, h, colors[(srcval >> 3) & 1] ); - XPutPixel( bmpImage, x++, h, colors[(srcval >> 2) & 1] ); - XPutPixel( bmpImage, x++, h, colors[(srcval >> 1) & 1] ); - XPutPixel( bmpImage, x++, h, colors[ srcval & 1] ); - } - if (width % 8){ - srcval=*srcbyte; - switch (width & 7) - { - case 7: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1; - /* fall through */ - case 6: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1; - /* fall through */ - case 5: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1; - /* fall through */ - case 4: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1; - /* fall through */ - case 3: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1; - /* fall through */ - case 2: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); srcval<<=1; - /* fall through */ - case 1: XPutPixel(bmpImage, x++, h, colors[srcval >> 7]); - } - } - srcbits += linebytes; - } -} - -/*********************************************************************** - * X11DRV_DIB_GetImageBits_1 - * - * GetDIBits for a 1-bit deep DIB. - */ -static void X11DRV_DIB_GetImageBits_1( int lines, BYTE *dstbits, - DWORD dstwidth, DWORD srcwidth, - RGBQUAD *colors, PALETTEENTRY *srccolors, - XImage *bmpImage, int linebytes ) -{ - DWORD x; - int h, width = min(dstwidth, srcwidth); - - if (lines < 0 ) { - lines = -lines; - dstbits = dstbits + linebytes * (lines - 1); - linebytes = -linebytes; - } - - switch (bmpImage->depth) - { - case 1: - case 4: - if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask) - && srccolors) { - /* ==== pal 1 or 4 bmp -> pal 1 dib ==== */ - BYTE* dstbyte; - - for (h=lines-1; h>=0; h--) { - BYTE dstval; - dstbyte=dstbits; - dstval=0; - for (x=0; xred_mask, bmpImage->green_mask, bmpImage->blue_mask) - && srccolors) { - /* ==== pal 8 bmp -> pal 1 dib ==== */ - const void* srcbits; - const BYTE* srcpixel; - BYTE* dstbyte; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - for (h=0; hbytes_per_line; - dstbits += linebytes; - } - } else { - goto notsupported; - } - break; - - case 15: - case 16: - { - const void* srcbits; - const WORD* srcpixel; - BYTE* dstbyte; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask==0x03e0) { - if (bmpImage->red_mask==0x7c00) { - /* ==== rgb 555 bmp -> pal 1 dib ==== */ - for (h=0; h> 7) & 0xf8) | /* r */ - ((srcval >> 12) & 0x07), - ((srcval >> 2) & 0xf8) | /* g */ - ((srcval >> 7) & 0x07), - ((srcval << 3) & 0xf8) | /* b */ - ((srcval >> 2) & 0x07) ) << (7-(x&7)) ); - if ((x&7)==7) { - *dstbyte++=dstval; - dstval=0; - } - } - if ((width&7)!=0) { - *dstbyte=dstval; - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else if (bmpImage->blue_mask==0x7c00) { - /* ==== bgr 555 bmp -> pal 1 dib ==== */ - for (h=0; h> 2) & 0x07), - ((srcval >> 2) & 0xf8) | /* g */ - ((srcval >> 7) & 0x07), - ((srcval >> 7) & 0xf8) | /* b */ - ((srcval >> 12) & 0x07) ) << (7-(x&7)) ); - if ((x&7)==7) { - *dstbyte++=dstval; - dstval=0; - } - } - if ((width&7)!=0) { - *dstbyte=dstval; - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else { - goto notsupported; - } - } else if (bmpImage->green_mask==0x07e0) { - if (bmpImage->red_mask==0xf800) { - /* ==== rgb 565 bmp -> pal 1 dib ==== */ - for (h=0; h> 8) & 0xf8) | /* r */ - ((srcval >> 13) & 0x07), - ((srcval >> 3) & 0xfc) | /* g */ - ((srcval >> 9) & 0x03), - ((srcval << 3) & 0xf8) | /* b */ - ((srcval >> 2) & 0x07) ) << (7-(x&7)) ); - if ((x&7)==7) { - *dstbyte++=dstval; - dstval=0; - } - } - if ((width&7)!=0) { - *dstbyte=dstval; - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else if (bmpImage->blue_mask==0xf800) { - /* ==== bgr 565 bmp -> pal 1 dib ==== */ - for (h=0; h> 2) & 0x07), - ((srcval >> 3) & 0xfc) | /* g */ - ((srcval >> 9) & 0x03), - ((srcval >> 8) & 0xf8) | /* b */ - ((srcval >> 13) & 0x07) ) << (7-(x&7)) ); - if ((x&7)==7) { - *dstbyte++=dstval; - dstval=0; - } - } - if ((width&7)!=0) { - *dstbyte=dstval; - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else { - goto notsupported; - } - } else { - goto notsupported; - } - } - break; - - case 24: - case 32: - { - const void* srcbits; - const BYTE *srcbyte; - BYTE* dstbyte; - int bytes_per_pixel; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - bytes_per_pixel=(bmpImage->bits_per_pixel==24?3:4); - - if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - } else if (bmpImage->blue_mask==0xff) { - /* ==== rgb 888 or 0888 bmp -> pal 1 dib ==== */ - for (h=0; hbytes_per_line; - dstbits += linebytes; - } - } else { - /* ==== bgr 888 or 0888 bmp -> pal 1 dib ==== */ - for (h=0; hbytes_per_line; - dstbits += linebytes; - } - } - } - break; - - default: - notsupported: - { - BYTE* dstbyte; - BYTE neg = 0; - unsigned long white = (1 << bmpImage->bits_per_pixel) - 1; - - /* ==== any bmp format -> pal 1 dib ==== */ - if ((unsigned)colors[0].rgbRed+colors[0].rgbGreen+colors[0].rgbBlue >= - (unsigned)colors[1].rgbRed+colors[1].rgbGreen+colors[1].rgbBlue ) - neg = 1; - - WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 1 bit DIB, " - "%s color mapping\n", - bmpImage->bits_per_pixel, bmpImage->red_mask, - bmpImage->green_mask, bmpImage->blue_mask, - neg?"negative":"direct" ); - - for (h=lines-1; h>=0; h--) { - BYTE dstval; - dstbyte=dstbits; - dstval=0; - for (x=0; x= white) ^ neg) << (7 - (x&7)); - if ((x&7)==7) { - *dstbyte++=dstval; - dstval=0; - } - } - if ((width&7)!=0) { - *dstbyte=dstval; - } - dstbits += linebytes; - } - } - break; - } -} - -/*********************************************************************** - * X11DRV_DIB_SetImageBits_4 - * - * SetDIBits for a 4-bit deep DIB. - */ -static void X11DRV_DIB_SetImageBits_4( int lines, const BYTE *srcbits, - DWORD srcwidth, DWORD dstwidth, int left, - int *colors, XImage *bmpImage, int linebytes) -{ - int h, width; - const BYTE* srcbyte; - DWORD i, x; - - if (lines < 0 ) { - lines = -lines; - srcbits = srcbits + linebytes * (lines - 1); - linebytes = -linebytes; - } - - if (left & 1) { - left--; - dstwidth++; - } - srcbits += left >> 1; - width = min(srcwidth, dstwidth); - - /* ==== pal 4 dib -> any bmp format ==== */ - for (h = lines-1; h >= 0; h--) { - srcbyte=srcbits; - for (i = width/2, x = left; i > 0; i--) { - BYTE srcval=*srcbyte++; - XPutPixel( bmpImage, x++, h, colors[srcval >> 4] ); - XPutPixel( bmpImage, x++, h, colors[srcval & 0x0f] ); - } - if (width & 1) - XPutPixel( bmpImage, x, h, colors[*srcbyte >> 4] ); - srcbits += linebytes; - } -} - - - -/*********************************************************************** - * X11DRV_DIB_GetImageBits_4 - * - * GetDIBits for a 4-bit deep DIB. - */ -static void X11DRV_DIB_GetImageBits_4( int lines, BYTE *dstbits, - DWORD srcwidth, DWORD dstwidth, - RGBQUAD *colors, PALETTEENTRY *srccolors, - XImage *bmpImage, int linebytes ) -{ - DWORD x; - int h, width = min(srcwidth, dstwidth); - - if (lines < 0 ) - { - lines = -lines; - dstbits = dstbits + ( linebytes * (lines-1) ); - linebytes = -linebytes; - } - - switch (bmpImage->depth) { - case 1: - case 4: - if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask) - && srccolors) { - /* ==== pal 1 or 4 bmp -> pal 4 dib ==== */ - BYTE* dstbyte; - - for (h = lines-1; h >= 0; h--) { - BYTE dstval; - dstbyte=dstbits; - dstval=0; - for (x = 0; x < width; x++) { - PALETTEENTRY srcval; - srcval=srccolors[XGetPixel(bmpImage, x, h)]; - dstval|=(X11DRV_DIB_GetNearestIndex - (colors, 16, - srcval.peRed, - srcval.peGreen, - srcval.peBlue) << (4-((x&1)<<2))); - if ((x&1)==1) { - *dstbyte++=dstval; - dstval=0; - } - } - if ((width&1)!=0) { - *dstbyte=dstval; - } - dstbits += linebytes; - } - } else { - goto notsupported; - } - break; - - case 8: - if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask) - && srccolors) { - /* ==== pal 8 bmp -> pal 4 dib ==== */ - const void* srcbits; - const BYTE *srcpixel; - BYTE* dstbyte; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - for (h=0; hbytes_per_line; - dstbits += linebytes; - } - } else { - goto notsupported; - } - break; - - case 15: - case 16: - { - const void* srcbits; - const WORD* srcpixel; - BYTE* dstbyte; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask==0x03e0) { - if (bmpImage->red_mask==0x7c00) { - /* ==== rgb 555 bmp -> pal 4 dib ==== */ - for (h=0; h> 7) & 0xf8) | /* r */ - ((srcval >> 12) & 0x07), - ((srcval >> 2) & 0xf8) | /* g */ - ((srcval >> 7) & 0x07), - ((srcval << 3) & 0xf8) | /* b */ - ((srcval >> 2) & 0x07) ) << ((1-(x&1))<<2) ); - if ((x&1)==1) { - *dstbyte++=dstval; - dstval=0; - } - } - if ((width&1)!=0) { - *dstbyte=dstval; - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else if (bmpImage->blue_mask==0x7c00) { - /* ==== bgr 555 bmp -> pal 4 dib ==== */ - for (h=0; h> 2) & 0x07), - ((srcval >> 2) & 0xf8) | /* g */ - ((srcval >> 7) & 0x07), - ((srcval >> 7) & 0xf8) | /* b */ - ((srcval >> 12) & 0x07) ) << ((1-(x&1))<<2) ); - if ((x&1)==1) { - *dstbyte++=dstval; - dstval=0; - } - } - if ((width&1)!=0) { - *dstbyte=dstval; - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else { - goto notsupported; - } - } else if (bmpImage->green_mask==0x07e0) { - if (bmpImage->red_mask==0xf800) { - /* ==== rgb 565 bmp -> pal 4 dib ==== */ - for (h=0; h> 8) & 0xf8) | /* r */ - ((srcval >> 13) & 0x07), - ((srcval >> 3) & 0xfc) | /* g */ - ((srcval >> 9) & 0x03), - ((srcval << 3) & 0xf8) | /* b */ - ((srcval >> 2) & 0x07) ) << ((1-(x&1))<<2) ); - if ((x&1)==1) { - *dstbyte++=dstval; - dstval=0; - } - } - if ((width&1)!=0) { - *dstbyte=dstval; - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else if (bmpImage->blue_mask==0xf800) { - /* ==== bgr 565 bmp -> pal 4 dib ==== */ - for (h=0; h> 2) & 0x07), - ((srcval >> 3) & 0xfc) | /* g */ - ((srcval >> 9) & 0x03), - ((srcval >> 8) & 0xf8) | /* b */ - ((srcval >> 13) & 0x07) ) << ((1-(x&1))<<2) ); - if ((x&1)==1) { - *dstbyte++=dstval; - dstval=0; - } - } - if ((width&1)!=0) { - *dstbyte=dstval; - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else { - goto notsupported; - } - } else { - goto notsupported; - } - } - break; - - case 24: - if (bmpImage->bits_per_pixel==24) { - const void* srcbits; - const BYTE *srcbyte; - BYTE* dstbyte; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - } else if (bmpImage->blue_mask==0xff) { - /* ==== rgb 888 bmp -> pal 4 dib ==== */ - for (h=0; hbytes_per_line; - dstbits += linebytes; - } - } else { - /* ==== bgr 888 bmp -> pal 4 dib ==== */ - for (h=0; hbytes_per_line; - dstbits += linebytes; - } - } - break; - } - /* Fall through */ - - case 32: - { - const void* srcbits; - const BYTE *srcbyte; - BYTE* dstbyte; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - } else if (bmpImage->blue_mask==0xff) { - /* ==== rgb 0888 bmp -> pal 4 dib ==== */ - for (h=0; hbytes_per_line; - dstbits += linebytes; - } - } else { - /* ==== bgr 0888 bmp -> pal 4 dib ==== */ - for (h=0; hbytes_per_line; - dstbits += linebytes; - } - } - } - break; - - default: - notsupported: - { - BYTE* dstbyte; - - /* ==== any bmp format -> pal 4 dib ==== */ - WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 4 bit DIB\n", - bmpImage->bits_per_pixel, bmpImage->red_mask, - bmpImage->green_mask, bmpImage->blue_mask ); - for (h=lines-1; h>=0; h--) { - dstbyte=dstbits; - for (x=0; x<(width & ~1); x+=2) { - *dstbyte++=(X11DRV_DIB_MapColor((int*)colors, 16, XGetPixel(bmpImage, x, h), 0) << 4) | - X11DRV_DIB_MapColor((int*)colors, 16, XGetPixel(bmpImage, x+1, h), 0); - } - if (width & 1) { - *dstbyte=(X11DRV_DIB_MapColor((int *)colors, 16, XGetPixel(bmpImage, x, h), 0) << 4); - } - dstbits += linebytes; - } - } - break; - } -} - -/*********************************************************************** - * X11DRV_DIB_SetImageBits_8 - * - * SetDIBits for an 8-bit deep DIB. - */ -static void X11DRV_DIB_SetImageBits_8( int lines, const BYTE *srcbits, - DWORD srcwidth, DWORD dstwidth, int left, - const int *colors, XImage *bmpImage, - int linebytes ) -{ - DWORD x; - int h, width = min(srcwidth, dstwidth); - const BYTE* srcbyte; - BYTE* dstbits; - - if (lines < 0 ) - { - lines = -lines; - srcbits = srcbits + linebytes * (lines-1); - linebytes = -linebytes; - } - srcbits += left; - srcbyte = srcbits; - - switch (bmpImage->depth) { - case 15: - case 16: - /* Some X servers might have 32 bit/ 16bit deep pixel */ - if (lines && width && (bmpImage->bits_per_pixel == 16) && - (ImageByteOrder(gdi_display)==LSBFirst) ) - { - /* ==== pal 8 dib -> rgb or bgr 555 or 565 bmp ==== */ - dstbits=(BYTE*)bmpImage->data+left*2+(lines-1)*bmpImage->bytes_per_line; - for (h = lines ; h--; ) { - DWORD* dstpixel=(DWORD*)dstbits; - for (x=0; xbytes_per_line; - } - return; - } - break; - case 24: - case 32: - if (lines && width && (bmpImage->bits_per_pixel == 32) && - (ImageByteOrder(gdi_display)==LSBFirst) ) - { - dstbits=(BYTE*)bmpImage->data+left*4+(lines-1)*bmpImage->bytes_per_line; - /* ==== pal 8 dib -> rgb or bgr 0888 bmp ==== */ - for (h = lines ; h--; ) { - DWORD* dstpixel=(DWORD*)dstbits; - for (x=0; xbytes_per_line; - } - return; - } - break; - default: - break; /* use slow generic case below */ - } - - /* ==== pal 8 dib -> any bmp format ==== */ - for (h=lines-1; h>=0; h--) { - for (x=left; xdepth) { - case 1: - case 4: - if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask) - && srccolors) { - - /* ==== pal 1 bmp -> pal 8 dib ==== */ - /* ==== pal 4 bmp -> pal 8 dib ==== */ - for (h=lines-1; h>=0; h--) { - dstbyte=dstbits; - for (x=0; xred_mask,bmpImage->green_mask,bmpImage->blue_mask) - && srccolors) { - /* ==== pal 8 bmp -> pal 8 dib ==== */ - const void* srcbits; - const BYTE* srcpixel; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - for (h=0; hbytes_per_line; - dstbits += linebytes; - } - } else { - goto notsupported; - } - break; - - case 15: - case 16: - { - const void* srcbits; - const WORD* srcpixel; - BYTE* dstbyte; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask==0x03e0) { - if (bmpImage->red_mask==0x7c00) { - /* ==== rgb 555 bmp -> pal 8 dib ==== */ - for (h=0; h> 7) & 0xf8) | /* r */ - ((srcval >> 12) & 0x07), - ((srcval >> 2) & 0xf8) | /* g */ - ((srcval >> 7) & 0x07), - ((srcval << 3) & 0xf8) | /* b */ - ((srcval >> 2) & 0x07) ); - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else if (bmpImage->blue_mask==0x7c00) { - /* ==== bgr 555 bmp -> pal 8 dib ==== */ - for (h=0; h> 2) & 0x07), - ((srcval >> 2) & 0xf8) | /* g */ - ((srcval >> 7) & 0x07), - ((srcval >> 7) & 0xf8) | /* b */ - ((srcval >> 12) & 0x07) ); - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else { - goto notsupported; - } - } else if (bmpImage->green_mask==0x07e0) { - if (bmpImage->red_mask==0xf800) { - /* ==== rgb 565 bmp -> pal 8 dib ==== */ - for (h=0; h> 8) & 0xf8) | /* r */ - ((srcval >> 13) & 0x07), - ((srcval >> 3) & 0xfc) | /* g */ - ((srcval >> 9) & 0x03), - ((srcval << 3) & 0xf8) | /* b */ - ((srcval >> 2) & 0x07) ); - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else if (bmpImage->blue_mask==0xf800) { - /* ==== bgr 565 bmp -> pal 8 dib ==== */ - for (h=0; h> 2) & 0x07), - ((srcval >> 3) & 0xfc) | /* g */ - ((srcval >> 9) & 0x03), - ((srcval >> 8) & 0xf8) | /* b */ - ((srcval >> 13) & 0x07) ); - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else { - goto notsupported; - } - } else { - goto notsupported; - } - } - break; - - case 24: - case 32: - { - const void* srcbits; - const BYTE *srcbyte; - BYTE* dstbyte; - int bytes_per_pixel; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - bytes_per_pixel=(bmpImage->bits_per_pixel==24?3:4); - - if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - } else if (bmpImage->blue_mask==0xff) { - /* ==== rgb 888 or 0888 bmp -> pal 8 dib ==== */ - for (h=0; hbytes_per_line; - dstbits += linebytes; - } - } else { - /* ==== bgr 888 or 0888 bmp -> pal 8 dib ==== */ - for (h=0; hbytes_per_line; - dstbits += linebytes; - } - } - } - break; - - default: - notsupported: - 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; - for (x=0; xbyte_order == LSBFirst) ? &dib_normal : &dib_dst_byteswap; - - if (lines < 0 ) - { - lines = -lines; - srcbits = srcbits + ( linebytes * (lines-1)); - linebytes = -linebytes; - } - - switch (bmpImage->depth) - { - case 15: - case 16: - { - char* dstbits; - - srcbits=srcbits+left*2; - dstbits=bmpImage->data+left*2+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask==0x03e0) { - if (gSrc==bmpImage->green_mask) { - if (rSrc==bmpImage->red_mask) { - /* ==== rgb 555 dib -> rgb 555 bmp ==== */ - /* ==== bgr 555 dib -> bgr 555 bmp ==== */ - convs->Convert_5x5_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else if (rSrc==bmpImage->blue_mask) { - /* ==== rgb 555 dib -> bgr 555 bmp ==== */ - /* ==== bgr 555 dib -> rgb 555 bmp ==== */ - convs->Convert_555_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } - } else { - if (rSrc==bmpImage->red_mask || bSrc==bmpImage->blue_mask) { - /* ==== rgb 565 dib -> rgb 555 bmp ==== */ - /* ==== bgr 565 dib -> bgr 555 bmp ==== */ - convs->Convert_565_to_555_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - /* ==== rgb 565 dib -> bgr 555 bmp ==== */ - /* ==== bgr 565 dib -> rgb 555 bmp ==== */ - convs->Convert_565_to_555_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } - } - } else if (bmpImage->green_mask==0x07e0) { - if (gSrc==bmpImage->green_mask) { - if (rSrc==bmpImage->red_mask) { - /* ==== rgb 565 dib -> rgb 565 bmp ==== */ - /* ==== bgr 565 dib -> bgr 565 bmp ==== */ - convs->Convert_5x5_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - /* ==== rgb 565 dib -> bgr 565 bmp ==== */ - /* ==== bgr 565 dib -> rgb 565 bmp ==== */ - convs->Convert_565_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } - } else { - if (rSrc==bmpImage->red_mask || bSrc==bmpImage->blue_mask) { - /* ==== rgb 555 dib -> rgb 565 bmp ==== */ - /* ==== bgr 555 dib -> bgr 565 bmp ==== */ - convs->Convert_555_to_565_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - /* ==== rgb 555 dib -> bgr 565 bmp ==== */ - /* ==== bgr 555 dib -> rgb 565 bmp ==== */ - convs->Convert_555_to_565_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } - } - } else { - goto notsupported; - } - } - break; - - case 24: - if (bmpImage->bits_per_pixel==24) { - char* dstbits; - - srcbits=srcbits+left*2; - dstbits=bmpImage->data+left*3+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - } else if ((rSrc==0x1f && bmpImage->red_mask==0xff) || - (bSrc==0x1f && bmpImage->blue_mask==0xff)) { - if (gSrc==0x03e0) { - /* ==== rgb 555 dib -> rgb 888 bmp ==== */ - /* ==== bgr 555 dib -> bgr 888 bmp ==== */ - convs->Convert_555_to_888_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - /* ==== rgb 565 dib -> rgb 888 bmp ==== */ - /* ==== bgr 565 dib -> bgr 888 bmp ==== */ - convs->Convert_565_to_888_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } - } else { - if (gSrc==0x03e0) { - /* ==== rgb 555 dib -> bgr 888 bmp ==== */ - /* ==== bgr 555 dib -> rgb 888 bmp ==== */ - convs->Convert_555_to_888_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - /* ==== rgb 565 dib -> bgr 888 bmp ==== */ - /* ==== bgr 565 dib -> rgb 888 bmp ==== */ - convs->Convert_565_to_888_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } - } - break; - } - /* Fall through */ - - case 32: - { - char* dstbits; - - srcbits=srcbits+left*2; - dstbits=bmpImage->data+left*4+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - } else if ((rSrc==0x1f && bmpImage->red_mask==0xff) || - (bSrc==0x1f && bmpImage->blue_mask==0xff)) { - if (gSrc==0x03e0) { - /* ==== rgb 555 dib -> rgb 0888 bmp ==== */ - /* ==== bgr 555 dib -> bgr 0888 bmp ==== */ - convs->Convert_555_to_0888_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - /* ==== rgb 565 dib -> rgb 0888 bmp ==== */ - /* ==== bgr 565 dib -> bgr 0888 bmp ==== */ - convs->Convert_565_to_0888_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } - } else { - if (gSrc==0x03e0) { - /* ==== rgb 555 dib -> bgr 0888 bmp ==== */ - /* ==== bgr 555 dib -> rgb 0888 bmp ==== */ - convs->Convert_555_to_0888_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - /* ==== rgb 565 dib -> bgr 0888 bmp ==== */ - /* ==== bgr 565 dib -> rgb 0888 bmp ==== */ - convs->Convert_565_to_0888_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } - } - } - break; - - default: - notsupported: - WARN("from 16 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n", - rSrc, gSrc, bSrc, bmpImage->bits_per_pixel, bmpImage->red_mask, - bmpImage->green_mask, bmpImage->blue_mask ); - /* fall through */ - case 1: - case 4: - case 8: - { - /* ==== rgb or bgr 555 or 565 dib -> pal 1, 4 or 8 ==== */ - const WORD* srcpixel; - int rShift1,gShift1,bShift1; - int rShift2,gShift2,bShift2; - BYTE gMask1,gMask2; - - /* Set color scaling values */ - rShift1=16+X11DRV_DIB_MaskToShift(rSrc)-3; - gShift1=16+X11DRV_DIB_MaskToShift(gSrc)-3; - bShift1=16+X11DRV_DIB_MaskToShift(bSrc)-3; - rShift2=rShift1+5; - gShift2=gShift1+5; - bShift2=bShift1+5; - if (gSrc==0x03e0) { - /* Green has 5 bits, like the others */ - gMask1=0xf8; - gMask2=0x07; - } else { - /* Green has 6 bits, not 5. Compensate. */ - gShift1++; - gShift2+=2; - gMask1=0xfc; - gMask2=0x03; - } - - srcbits+=2*left; - - /* We could split it into four separate cases to optimize - * but it is probably not worth it. - */ - for (h=lines-1; h>=0; h--) { - srcpixel=(const WORD*)srcbits; - for (x=left; x> rShift1) & 0xf8) | - ((srcval >> rShift2) & 0x07); - green=((srcval >> gShift1) & gMask1) | - ((srcval >> gShift2) & gMask2); - blue= ((srcval >> bShift1) & 0xf8) | - ((srcval >> bShift2) & 0x07); - XPutPixel(bmpImage, x, h, - X11DRV_PALETTE_ToPhysical - (physDev, RGB(red,green,blue))); - } - srcbits += linebytes; - } - } - break; - } -} - - -/*********************************************************************** - * X11DRV_DIB_GetImageBits_16 - * - * GetDIBits for an 16-bit deep DIB. - */ -static void X11DRV_DIB_GetImageBits_16( X11DRV_PDEVICE *physDev, int lines, BYTE *dstbits, - DWORD dstwidth, DWORD srcwidth, - PALETTEENTRY *srccolors, - DWORD rDst, DWORD gDst, DWORD bDst, - XImage *bmpImage, int linebytes ) -{ - DWORD x; - int h, width = min(srcwidth, dstwidth); - const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_src_byteswap; - - if (lines < 0 ) - { - lines = -lines; - dstbits = dstbits + ( linebytes * (lines-1)); - linebytes = -linebytes; - } - - switch (bmpImage->depth) - { - case 15: - case 16: - { - const char* srcbits; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask==0x03e0) { - if (gDst==bmpImage->green_mask) { - if (rDst==bmpImage->red_mask) { - /* ==== rgb 555 bmp -> rgb 555 dib ==== */ - /* ==== bgr 555 bmp -> bgr 555 dib ==== */ - convs->Convert_5x5_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - /* ==== rgb 555 bmp -> bgr 555 dib ==== */ - /* ==== bgr 555 bmp -> rgb 555 dib ==== */ - convs->Convert_555_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } - } else { - if (rDst==bmpImage->red_mask || bDst==bmpImage->blue_mask) { - /* ==== rgb 555 bmp -> rgb 565 dib ==== */ - /* ==== bgr 555 bmp -> bgr 565 dib ==== */ - convs->Convert_555_to_565_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - /* ==== rgb 555 bmp -> bgr 565 dib ==== */ - /* ==== bgr 555 bmp -> rgb 565 dib ==== */ - convs->Convert_555_to_565_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } - } - } else if (bmpImage->green_mask==0x07e0) { - if (gDst==bmpImage->green_mask) { - if (rDst == bmpImage->red_mask) { - /* ==== rgb 565 bmp -> rgb 565 dib ==== */ - /* ==== bgr 565 bmp -> bgr 565 dib ==== */ - convs->Convert_5x5_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - /* ==== rgb 565 bmp -> bgr 565 dib ==== */ - /* ==== bgr 565 bmp -> rgb 565 dib ==== */ - convs->Convert_565_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } - } else { - if (rDst==bmpImage->red_mask || bDst==bmpImage->blue_mask) { - /* ==== rgb 565 bmp -> rgb 555 dib ==== */ - /* ==== bgr 565 bmp -> bgr 555 dib ==== */ - convs->Convert_565_to_555_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - /* ==== rgb 565 bmp -> bgr 555 dib ==== */ - /* ==== bgr 565 bmp -> rgb 555 dib ==== */ - convs->Convert_565_to_555_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } - } - } else { - goto notsupported; - } - } - break; - - case 24: - if (bmpImage->bits_per_pixel == 24) { - const char* srcbits; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - } else if ((rDst==0x1f && bmpImage->red_mask==0xff) || - (bDst==0x1f && bmpImage->blue_mask==0xff)) { - if (gDst==0x03e0) { - /* ==== rgb 888 bmp -> rgb 555 dib ==== */ - /* ==== bgr 888 bmp -> bgr 555 dib ==== */ - convs->Convert_888_to_555_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - /* ==== rgb 888 bmp -> rgb 565 dib ==== */ - /* ==== rgb 888 bmp -> rgb 565 dib ==== */ - convs->Convert_888_to_565_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } - } else { - if (gDst==0x03e0) { - /* ==== rgb 888 bmp -> bgr 555 dib ==== */ - /* ==== bgr 888 bmp -> rgb 555 dib ==== */ - convs->Convert_888_to_555_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - /* ==== rgb 888 bmp -> bgr 565 dib ==== */ - /* ==== bgr 888 bmp -> rgb 565 dib ==== */ - convs->Convert_888_to_565_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } - } - break; - } - /* Fall through */ - - case 32: - { - const char* srcbits; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - } else if ((rDst==0x1f && bmpImage->red_mask==0xff) || - (bDst==0x1f && bmpImage->blue_mask==0xff)) { - if (gDst==0x03e0) { - /* ==== rgb 0888 bmp -> rgb 555 dib ==== */ - /* ==== bgr 0888 bmp -> bgr 555 dib ==== */ - convs->Convert_0888_to_555_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - /* ==== rgb 0888 bmp -> rgb 565 dib ==== */ - /* ==== bgr 0888 bmp -> bgr 565 dib ==== */ - convs->Convert_0888_to_565_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } - } else { - if (gDst==0x03e0) { - /* ==== rgb 0888 bmp -> bgr 555 dib ==== */ - /* ==== bgr 0888 bmp -> rgb 555 dib ==== */ - convs->Convert_0888_to_555_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - /* ==== rgb 0888 bmp -> bgr 565 dib ==== */ - /* ==== bgr 0888 bmp -> rgb 565 dib ==== */ - convs->Convert_0888_to_565_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } - } - } - break; - - case 1: - case 4: - if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask) - && srccolors) { - /* ==== pal 1 or 4 bmp -> rgb or bgr 555 or 565 dib ==== */ - int rShift,gShift,bShift; - WORD* dstpixel; - - /* Shift everything 16 bits left so that all shifts are >0, - * even for BGR DIBs. Then a single >> 16 will bring everything - * back into place. - */ - rShift=16+X11DRV_DIB_MaskToShift(rDst)-3; - gShift=16+X11DRV_DIB_MaskToShift(gDst)-3; - bShift=16+X11DRV_DIB_MaskToShift(bDst)-3; - if (gDst==0x07e0) { - /* 6 bits for the green */ - gShift++; - } - rDst=rDst << 16; - gDst=gDst << 16; - bDst=bDst << 16; - for (h = lines - 1; h >= 0; h--) { - dstpixel=(LPWORD)dstbits; - for (x = 0; x < width; x++) { - PALETTEENTRY srcval; - DWORD dstval; - srcval=srccolors[XGetPixel(bmpImage, x, h)]; - dstval=((srcval.peRed << rShift) & rDst) | - ((srcval.peGreen << gShift) & gDst) | - ((srcval.peBlue << bShift) & bDst); - *dstpixel++=dstval >> 16; - } - dstbits += linebytes; - } - } else { - goto notsupported; - } - break; - - case 8: - if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask) - && srccolors) { - /* ==== pal 8 bmp -> rgb or bgr 555 or 565 dib ==== */ - int rShift,gShift,bShift; - const BYTE* srcbits; - const BYTE* srcpixel; - WORD* dstpixel; - - /* Shift everything 16 bits left so that all shifts are >0, - * even for BGR DIBs. Then a single >> 16 will bring everything - * back into place. - */ - rShift=16+X11DRV_DIB_MaskToShift(rDst)-3; - gShift=16+X11DRV_DIB_MaskToShift(gDst)-3; - bShift=16+X11DRV_DIB_MaskToShift(bDst)-3; - if (gDst==0x07e0) { - /* 6 bits for the green */ - gShift++; - } - rDst=rDst << 16; - gDst=gDst << 16; - bDst=bDst << 16; - srcbits=(BYTE*)bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - for (h=0; h> 16; - } - srcbits -= bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else { - goto notsupported; - } - break; - - default: - notsupported: - { - /* ==== any bmp format -> rgb or bgr 555 or 565 dib ==== */ - int rShift,gShift,bShift; - WORD* dstpixel; - - WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 16 bit DIB (%x,%x,%x)\n", - bmpImage->depth, bmpImage->red_mask, - bmpImage->green_mask, bmpImage->blue_mask, - rDst, gDst, bDst); - - /* Shift everything 16 bits left so that all shifts are >0, - * even for BGR DIBs. Then a single >> 16 will bring everything - * back into place. - */ - rShift=16+X11DRV_DIB_MaskToShift(rDst)-3; - gShift=16+X11DRV_DIB_MaskToShift(gDst)-3; - bShift=16+X11DRV_DIB_MaskToShift(bDst)-3; - if (gDst==0x07e0) { - /* 6 bits for the green */ - gShift++; - } - rDst=rDst << 16; - gDst=gDst << 16; - bDst=bDst << 16; - for (h = lines - 1; h >= 0; h--) { - dstpixel=(LPWORD)dstbits; - for (x = 0; x < width; x++) { - COLORREF srcval; - DWORD dstval; - srcval=X11DRV_PALETTE_ToLogical(physDev, XGetPixel(bmpImage, x, h)); - dstval=((GetRValue(srcval) << rShift) & rDst) | - ((GetGValue(srcval) << gShift) & gDst) | - ((GetBValue(srcval) << bShift) & bDst); - *dstpixel++=dstval >> 16; - } - dstbits += linebytes; - } - } - break; - } -} - - -/*********************************************************************** - * X11DRV_DIB_SetImageBits_24 - * - * SetDIBits for a 24-bit deep DIB. - */ -static void X11DRV_DIB_SetImageBits_24( int lines, const BYTE *srcbits, - DWORD srcwidth, DWORD dstwidth, int left, - X11DRV_PDEVICE *physDev, - DWORD rSrc, DWORD gSrc, DWORD bSrc, - XImage *bmpImage, DWORD linebytes ) -{ - DWORD x; - int h, width = min(srcwidth, dstwidth); - const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_dst_byteswap; - - if (lines < 0 ) - { - lines = -lines; - srcbits = srcbits + linebytes * (lines - 1); - linebytes = -linebytes; - } - - switch (bmpImage->depth) - { - case 24: - if (bmpImage->bits_per_pixel==24) { - char* dstbits; - - srcbits=srcbits+left*3; - dstbits=bmpImage->data+left*3+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - } else if (rSrc==bmpImage->red_mask) { - /* ==== rgb 888 dib -> rgb 888 bmp ==== */ - /* ==== bgr 888 dib -> bgr 888 bmp ==== */ - convs->Convert_888_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - /* ==== rgb 888 dib -> bgr 888 bmp ==== */ - /* ==== bgr 888 dib -> rgb 888 bmp ==== */ - convs->Convert_888_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } - break; - } - /* fall through */ - - case 32: - { - char* dstbits; - - srcbits=srcbits+left*3; - dstbits=bmpImage->data+left*4+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - } else if (rSrc==bmpImage->red_mask) { - /* ==== rgb 888 dib -> rgb 0888 bmp ==== */ - /* ==== bgr 888 dib -> bgr 0888 bmp ==== */ - convs->Convert_888_to_0888_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - /* ==== rgb 888 dib -> bgr 0888 bmp ==== */ - /* ==== bgr 888 dib -> rgb 0888 bmp ==== */ - convs->Convert_888_to_0888_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } - break; - } - - case 15: - case 16: - { - char* dstbits; - - srcbits=srcbits+left*3; - dstbits=bmpImage->data+left*2+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask==0x03e0) { - if ((rSrc==0xff0000 && bmpImage->red_mask==0x7f00) || - (bSrc==0xff0000 && bmpImage->blue_mask==0x7f00)) { - /* ==== rgb 888 dib -> rgb 555 bmp ==== */ - /* ==== bgr 888 dib -> bgr 555 bmp ==== */ - convs->Convert_888_to_555_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else if ((rSrc==0xff && bmpImage->red_mask==0x7f00) || - (bSrc==0xff && bmpImage->blue_mask==0x7f00)) { - /* ==== rgb 888 dib -> bgr 555 bmp ==== */ - /* ==== bgr 888 dib -> rgb 555 bmp ==== */ - convs->Convert_888_to_555_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - goto notsupported; - } - } else if (bmpImage->green_mask==0x07e0) { - if ((rSrc==0xff0000 && bmpImage->red_mask==0xf800) || - (bSrc==0xff0000 && bmpImage->blue_mask==0xf800)) { - /* ==== rgb 888 dib -> rgb 565 bmp ==== */ - /* ==== bgr 888 dib -> bgr 565 bmp ==== */ - convs->Convert_888_to_565_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else if ((rSrc==0xff && bmpImage->red_mask==0xf800) || - (bSrc==0xff && bmpImage->blue_mask==0xf800)) { - /* ==== rgb 888 dib -> bgr 565 bmp ==== */ - /* ==== bgr 888 dib -> rgb 565 bmp ==== */ - convs->Convert_888_to_565_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - goto notsupported; - } - } else { - goto notsupported; - } - } - break; - - default: - notsupported: - WARN("from 24 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n", - rSrc, gSrc, bSrc, bmpImage->bits_per_pixel, bmpImage->red_mask, - bmpImage->green_mask, bmpImage->blue_mask ); - /* fall through */ - case 1: - case 4: - case 8: - { - /* ==== rgb 888 dib -> any bmp format ==== */ - const BYTE* srcbyte; - - /* Windows only supports one 24bpp DIB format: RGB888 */ - srcbits+=left*3; - for (h = lines - 1; h >= 0; h--) { - srcbyte = srcbits; - for (x = left; x < width+left; x++) { - XPutPixel(bmpImage, x, h, - X11DRV_PALETTE_ToPhysical - (physDev, RGB(srcbyte[2], srcbyte[1], srcbyte[0]))); - srcbyte+=3; - } - srcbits += linebytes; - } - } - break; - } -} - - -/*********************************************************************** - * X11DRV_DIB_GetImageBits_24 - * - * GetDIBits for an 24-bit deep DIB. - */ -static void X11DRV_DIB_GetImageBits_24( X11DRV_PDEVICE *physDev, int lines, BYTE *dstbits, - DWORD dstwidth, DWORD srcwidth, - PALETTEENTRY *srccolors, - DWORD rDst, DWORD gDst, DWORD bDst, - XImage *bmpImage, DWORD linebytes ) -{ - DWORD x; - int h, width = min(srcwidth, dstwidth); - const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_src_byteswap; - - if (lines < 0 ) - { - lines = -lines; - dstbits = dstbits + ( linebytes * (lines-1) ); - linebytes = -linebytes; - } - - switch (bmpImage->depth) - { - case 24: - if (bmpImage->bits_per_pixel==24) { - const char* srcbits; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - } else if (rDst==bmpImage->red_mask) { - /* ==== rgb 888 bmp -> rgb 888 dib ==== */ - /* ==== bgr 888 bmp -> bgr 888 dib ==== */ - convs->Convert_888_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - /* ==== rgb 888 bmp -> bgr 888 dib ==== */ - /* ==== bgr 888 bmp -> rgb 888 dib ==== */ - convs->Convert_888_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } - break; - } - /* fall through */ - - case 32: - { - const char* srcbits; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - } else if (rDst==bmpImage->red_mask) { - /* ==== rgb 888 bmp -> rgb 0888 dib ==== */ - /* ==== bgr 888 bmp -> bgr 0888 dib ==== */ - convs->Convert_0888_to_888_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - /* ==== rgb 888 bmp -> bgr 0888 dib ==== */ - /* ==== bgr 888 bmp -> rgb 0888 dib ==== */ - convs->Convert_0888_to_888_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } - break; - } - - case 15: - case 16: - { - const char* srcbits; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (bmpImage->green_mask==0x03e0) { - if ((rDst==0xff0000 && bmpImage->red_mask==0x7f00) || - (bDst==0xff0000 && bmpImage->blue_mask==0x7f00)) { - /* ==== rgb 555 bmp -> rgb 888 dib ==== */ - /* ==== bgr 555 bmp -> bgr 888 dib ==== */ - convs->Convert_555_to_888_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else if ((rDst==0xff && bmpImage->red_mask==0x7f00) || - (bDst==0xff && bmpImage->blue_mask==0x7f00)) { - /* ==== rgb 555 bmp -> bgr 888 dib ==== */ - /* ==== bgr 555 bmp -> rgb 888 dib ==== */ - convs->Convert_555_to_888_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - goto notsupported; - } - } else if (bmpImage->green_mask==0x07e0) { - if ((rDst==0xff0000 && bmpImage->red_mask==0xf800) || - (bDst==0xff0000 && bmpImage->blue_mask==0xf800)) { - /* ==== rgb 565 bmp -> rgb 888 dib ==== */ - /* ==== bgr 565 bmp -> bgr 888 dib ==== */ - convs->Convert_565_to_888_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else if ((rDst==0xff && bmpImage->red_mask==0xf800) || - (bDst==0xff && bmpImage->blue_mask==0xf800)) { - /* ==== rgb 565 bmp -> bgr 888 dib ==== */ - /* ==== bgr 565 bmp -> rgb 888 dib ==== */ - convs->Convert_565_to_888_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - goto notsupported; - } - } else { - goto notsupported; - } - } - break; - - case 1: - case 4: - if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask) - && srccolors) { - /* ==== pal 1 or 4 bmp -> rgb 888 dib ==== */ - BYTE* dstbyte; - - /* Windows only supports one 24bpp DIB format: rgb 888 */ - for (h = lines - 1; h >= 0; h--) { - dstbyte=dstbits; - for (x = 0; x < width; x++) { - PALETTEENTRY srcval; - srcval=srccolors[XGetPixel(bmpImage, x, h)]; - dstbyte[0]=srcval.peBlue; - dstbyte[1]=srcval.peGreen; - dstbyte[2]=srcval.peRed; - dstbyte+=3; - } - dstbits += linebytes; - } - } else { - goto notsupported; - } - break; - - case 8: - if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask) - && srccolors) { - /* ==== pal 8 bmp -> rgb 888 dib ==== */ - const void* srcbits; - const BYTE* srcpixel; - BYTE* dstbyte; - - /* Windows only supports one 24bpp DIB format: rgb 888 */ - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - for (h = lines - 1; h >= 0; h--) { - srcpixel=srcbits; - dstbyte=dstbits; - for (x = 0; x < width; x++ ) { - PALETTEENTRY srcval; - srcval=srccolors[*srcpixel++]; - dstbyte[0]=srcval.peBlue; - dstbyte[1]=srcval.peGreen; - dstbyte[2]=srcval.peRed; - dstbyte+=3; - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else { - goto notsupported; - } - break; - - default: - notsupported: - { - /* ==== any bmp format -> 888 dib ==== */ - BYTE* dstbyte; - - WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 24 bit DIB (%x,%x,%x)\n", - bmpImage->depth, bmpImage->red_mask, - bmpImage->green_mask, bmpImage->blue_mask, - rDst, gDst, bDst ); - - /* Windows only supports one 24bpp DIB format: rgb 888 */ - for (h = lines - 1; h >= 0; h--) { - dstbyte=dstbits; - for (x = 0; x < width; x++) { - COLORREF srcval=X11DRV_PALETTE_ToLogical - (physDev, XGetPixel( bmpImage, x, h )); - dstbyte[0]=GetBValue(srcval); - dstbyte[1]=GetGValue(srcval); - dstbyte[2]=GetRValue(srcval); - dstbyte+=3; - } - dstbits += linebytes; - } - } - break; - } -} - - -/*********************************************************************** - * X11DRV_DIB_SetImageBits_32 - * - * SetDIBits for a 32-bit deep DIB. - */ -static void X11DRV_DIB_SetImageBits_32(int lines, const BYTE *srcbits, - DWORD srcwidth, DWORD dstwidth, int left, - X11DRV_PDEVICE *physDev, - DWORD rSrc, DWORD gSrc, DWORD bSrc, - XImage *bmpImage, - DWORD linebytes) -{ - DWORD x; - int h, width = min(srcwidth, dstwidth); - const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_dst_byteswap; - - if (lines < 0 ) - { - lines = -lines; - srcbits = srcbits + ( linebytes * (lines-1) ); - linebytes = -linebytes; - } - - switch (bmpImage->depth) - { - case 24: - if (bmpImage->bits_per_pixel==24) { - char* dstbits; - - srcbits=srcbits+left*4; - dstbits=bmpImage->data+left*3+(lines-1)*bmpImage->bytes_per_line; - - if (rSrc==bmpImage->red_mask && gSrc==bmpImage->green_mask && bSrc==bmpImage->blue_mask) { - /* ==== rgb 0888 dib -> rgb 888 bmp ==== */ - /* ==== bgr 0888 dib -> bgr 888 bmp ==== */ - convs->Convert_0888_to_888_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - /* the tests below assume sane bmpImage masks */ - } else if (rSrc==bmpImage->blue_mask && gSrc==bmpImage->green_mask && bSrc==bmpImage->red_mask) { - /* ==== rgb 0888 dib -> bgr 888 bmp ==== */ - /* ==== bgr 0888 dib -> rgb 888 bmp ==== */ - convs->Convert_0888_to_888_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else if (bmpImage->blue_mask==0xff) { - /* ==== any 0888 dib -> rgb 888 bmp ==== */ - convs->Convert_any0888_to_rgb888 - (width,lines, - srcbits,linebytes, - rSrc,gSrc,bSrc, - dstbits,-bmpImage->bytes_per_line); - } else { - /* ==== any 0888 dib -> bgr 888 bmp ==== */ - convs->Convert_any0888_to_bgr888 - (width,lines, - srcbits,linebytes, - rSrc,gSrc,bSrc, - dstbits,-bmpImage->bytes_per_line); - } - break; - } - /* fall through */ - - case 32: - { - char* dstbits; - - srcbits=srcbits+left*4; - dstbits=bmpImage->data+left*4+(lines-1)*bmpImage->bytes_per_line; - - if (gSrc==bmpImage->green_mask) { - if (rSrc==bmpImage->red_mask && bSrc==bmpImage->blue_mask) { - /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */ - /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */ - convs->Convert_0888_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - /* the tests below assume sane bmpImage masks */ - } else if (rSrc==bmpImage->blue_mask && bSrc==bmpImage->red_mask) { - /* ==== rgb 0888 dib -> bgr 0888 bmp ==== */ - /* ==== bgr 0888 dib -> rgb 0888 bmp ==== */ - convs->Convert_0888_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - /* ==== any 0888 dib -> any 0888 bmp ==== */ - convs->Convert_0888_any - (width,lines, - srcbits,linebytes, - rSrc,gSrc,bSrc, - dstbits,-bmpImage->bytes_per_line, - bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask); - } - } else if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - /* the tests below assume sane bmpImage masks */ - } else { - /* ==== any 0888 dib -> any 0888 bmp ==== */ - convs->Convert_0888_any - (width,lines, - srcbits,linebytes, - rSrc,gSrc,bSrc, - dstbits,-bmpImage->bytes_per_line, - bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask); - } - } - break; - - case 15: - case 16: - { - char* dstbits; - - srcbits=srcbits+left*4; - dstbits=bmpImage->data+left*2+(lines-1)*bmpImage->bytes_per_line; - - if (rSrc==0xff0000 && gSrc==0x00ff00 && bSrc==0x0000ff) { - if (bmpImage->green_mask==0x03e0) { - if (bmpImage->red_mask==0x7f00) { - /* ==== rgb 0888 dib -> rgb 555 bmp ==== */ - convs->Convert_0888_to_555_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else if (bmpImage->blue_mask==0x7f00) { - /* ==== rgb 0888 dib -> bgr 555 bmp ==== */ - convs->Convert_0888_to_555_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - goto notsupported; - } - } else if (bmpImage->green_mask==0x07e0) { - if (bmpImage->red_mask==0xf800) { - /* ==== rgb 0888 dib -> rgb 565 bmp ==== */ - convs->Convert_0888_to_565_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else if (bmpImage->blue_mask==0xf800) { - /* ==== rgb 0888 dib -> bgr 565 bmp ==== */ - convs->Convert_0888_to_565_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - goto notsupported; - } - } else { - goto notsupported; - } - } else if (rSrc==0x0000ff && gSrc==0x00ff00 && bSrc==0xff0000) { - if (bmpImage->green_mask==0x03e0) { - if (bmpImage->blue_mask==0x7f00) { - /* ==== bgr 0888 dib -> bgr 555 bmp ==== */ - convs->Convert_0888_to_555_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else if (bmpImage->red_mask==0x7f00) { - /* ==== bgr 0888 dib -> rgb 555 bmp ==== */ - convs->Convert_0888_to_555_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - goto notsupported; - } - } else if (bmpImage->green_mask==0x07e0) { - if (bmpImage->blue_mask==0xf800) { - /* ==== bgr 0888 dib -> bgr 565 bmp ==== */ - convs->Convert_0888_to_565_asis - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else if (bmpImage->red_mask==0xf800) { - /* ==== bgr 0888 dib -> rgb 565 bmp ==== */ - convs->Convert_0888_to_565_reverse - (width,lines, - srcbits,linebytes, - dstbits,-bmpImage->bytes_per_line); - } else { - goto notsupported; - } - } else { - goto notsupported; - } - } else { - if (bmpImage->green_mask==0x03e0 && - (bmpImage->red_mask==0x7f00 || - bmpImage->blue_mask==0x7f00)) { - /* ==== any 0888 dib -> rgb or bgr 555 bmp ==== */ - convs->Convert_any0888_to_5x5 - (width,lines, - srcbits,linebytes, - rSrc,gSrc,bSrc, - dstbits,-bmpImage->bytes_per_line, - bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask); - } else if (bmpImage->green_mask==0x07e0 && - (bmpImage->red_mask==0xf800 || - bmpImage->blue_mask==0xf800)) { - /* ==== any 0888 dib -> rgb or bgr 565 bmp ==== */ - convs->Convert_any0888_to_5x5 - (width,lines, - srcbits,linebytes, - rSrc,gSrc,bSrc, - dstbits,-bmpImage->bytes_per_line, - bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask); - } else { - goto notsupported; - } - } - } - break; - - default: - notsupported: - WARN("from 32 bit DIB (%x,%x,%x) to unknown %d bit bitmap (%lx,%lx,%lx)\n", - rSrc, gSrc, bSrc, bmpImage->bits_per_pixel, bmpImage->red_mask, - bmpImage->green_mask, bmpImage->blue_mask ); - /* fall through */ - case 1: - case 4: - case 8: - { - /* ==== any 0888 dib -> pal 1, 4 or 8 bmp ==== */ - const DWORD* srcpixel; - int rShift,gShift,bShift; - - rShift=X11DRV_DIB_MaskToShift(rSrc); - gShift=X11DRV_DIB_MaskToShift(gSrc); - bShift=X11DRV_DIB_MaskToShift(bSrc); - srcbits+=left*4; - for (h = lines - 1; h >= 0; h--) { - srcpixel=(const DWORD*)srcbits; - for (x = left; x < width+left; x++) { - DWORD srcvalue; - BYTE red,green,blue; - srcvalue=*srcpixel++; - red= (srcvalue >> rShift) & 0xff; - green=(srcvalue >> gShift) & 0xff; - blue= (srcvalue >> bShift) & 0xff; - XPutPixel(bmpImage, x, h, X11DRV_PALETTE_ToPhysical - (physDev, RGB(red,green,blue))); - } - srcbits += linebytes; - } - } - break; - } - -} - -/*********************************************************************** - * X11DRV_DIB_GetImageBits_32 - * - * GetDIBits for an 32-bit deep DIB. - */ -static void X11DRV_DIB_GetImageBits_32( X11DRV_PDEVICE *physDev, int lines, BYTE *dstbits, - DWORD dstwidth, DWORD srcwidth, - PALETTEENTRY *srccolors, - DWORD rDst, DWORD gDst, DWORD bDst, - XImage *bmpImage, int linebytes ) -{ - DWORD x; - int h, width = min(srcwidth, dstwidth); - const dib_conversions *convs = (bmpImage->byte_order == LSBFirst) ? &dib_normal : &dib_src_byteswap; - - if (lines < 0 ) - { - lines = -lines; - dstbits = dstbits + ( linebytes * (lines-1) ); - linebytes = -linebytes; - } - - switch (bmpImage->depth) - { - case 24: - if (bmpImage->bits_per_pixel==24) { - const void* srcbits; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (rDst==bmpImage->red_mask && gDst==bmpImage->green_mask && bDst==bmpImage->blue_mask) { - /* ==== rgb 888 bmp -> rgb 0888 dib ==== */ - /* ==== bgr 888 bmp -> bgr 0888 dib ==== */ - convs->Convert_888_to_0888_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - /* the tests below assume sane bmpImage masks */ - } else if (rDst==bmpImage->blue_mask && gDst==bmpImage->green_mask && bDst==bmpImage->red_mask) { - /* ==== rgb 888 bmp -> bgr 0888 dib ==== */ - /* ==== bgr 888 bmp -> rgb 0888 dib ==== */ - convs->Convert_888_to_0888_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else if (bmpImage->blue_mask==0xff) { - /* ==== rgb 888 bmp -> any 0888 dib ==== */ - convs->Convert_rgb888_to_any0888 - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes, - rDst,gDst,bDst); - } else { - /* ==== bgr 888 bmp -> any 0888 dib ==== */ - convs->Convert_bgr888_to_any0888 - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes, - rDst,gDst,bDst); - } - break; - } - /* fall through */ - - case 32: - { - const char* srcbits; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (gDst==bmpImage->green_mask) { - if (rDst==bmpImage->red_mask && bDst==bmpImage->blue_mask) { - /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */ - /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */ - convs->Convert_0888_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - /* the tests below assume sane bmpImage masks */ - } else if (rDst==bmpImage->blue_mask && bDst==bmpImage->red_mask) { - /* ==== rgb 0888 bmp -> bgr 0888 dib ==== */ - /* ==== bgr 0888 bmp -> rgb 0888 dib ==== */ - convs->Convert_0888_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - /* ==== any 0888 bmp -> any 0888 dib ==== */ - convs->Convert_0888_any - (width,lines, - srcbits,-bmpImage->bytes_per_line, - bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask, - dstbits,linebytes, - rDst,gDst,bDst); - } - } else if (bmpImage->green_mask!=0x00ff00 || - (bmpImage->red_mask|bmpImage->blue_mask)!=0xff00ff) { - goto notsupported; - /* the tests below assume sane bmpImage masks */ - } else { - /* ==== any 0888 bmp -> any 0888 dib ==== */ - convs->Convert_0888_any - (width,lines, - srcbits,-bmpImage->bytes_per_line, - bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask, - dstbits,linebytes, - rDst,gDst,bDst); - } - } - break; - - case 15: - case 16: - { - const char* srcbits; - - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - - if (rDst==0xff0000 && gDst==0x00ff00 && bDst==0x0000ff) { - if (bmpImage->green_mask==0x03e0) { - if (bmpImage->red_mask==0x7f00) { - /* ==== rgb 555 bmp -> rgb 0888 dib ==== */ - convs->Convert_555_to_0888_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else if (bmpImage->blue_mask==0x7f00) { - /* ==== bgr 555 bmp -> rgb 0888 dib ==== */ - convs->Convert_555_to_0888_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - goto notsupported; - } - } else if (bmpImage->green_mask==0x07e0) { - if (bmpImage->red_mask==0xf800) { - /* ==== rgb 565 bmp -> rgb 0888 dib ==== */ - convs->Convert_565_to_0888_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else if (bmpImage->blue_mask==0xf800) { - /* ==== bgr 565 bmp -> rgb 0888 dib ==== */ - convs->Convert_565_to_0888_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - goto notsupported; - } - } else { - goto notsupported; - } - } else if (rDst==0x0000ff && gDst==0x00ff00 && bDst==0xff0000) { - if (bmpImage->green_mask==0x03e0) { - if (bmpImage->blue_mask==0x7f00) { - /* ==== bgr 555 bmp -> bgr 0888 dib ==== */ - convs->Convert_555_to_0888_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else if (bmpImage->red_mask==0x7f00) { - /* ==== rgb 555 bmp -> bgr 0888 dib ==== */ - convs->Convert_555_to_0888_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - goto notsupported; - } - } else if (bmpImage->green_mask==0x07e0) { - if (bmpImage->blue_mask==0xf800) { - /* ==== bgr 565 bmp -> bgr 0888 dib ==== */ - convs->Convert_565_to_0888_asis - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else if (bmpImage->red_mask==0xf800) { - /* ==== rgb 565 bmp -> bgr 0888 dib ==== */ - convs->Convert_565_to_0888_reverse - (width,lines, - srcbits,-bmpImage->bytes_per_line, - dstbits,linebytes); - } else { - goto notsupported; - } - } else { - goto notsupported; - } - } else { - if (bmpImage->green_mask==0x03e0 && - (bmpImage->red_mask==0x7f00 || - bmpImage->blue_mask==0x7f00)) { - /* ==== rgb or bgr 555 bmp -> any 0888 dib ==== */ - convs->Convert_5x5_to_any0888 - (width,lines, - srcbits,-bmpImage->bytes_per_line, - bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask, - dstbits,linebytes, - rDst,gDst,bDst); - } else if (bmpImage->green_mask==0x07e0 && - (bmpImage->red_mask==0xf800 || - bmpImage->blue_mask==0xf800)) { - /* ==== rgb or bgr 565 bmp -> any 0888 dib ==== */ - convs->Convert_5x5_to_any0888 - (width,lines, - srcbits,-bmpImage->bytes_per_line, - bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask, - dstbits,linebytes, - rDst,gDst,bDst); - } else { - goto notsupported; - } - } - } - break; - - case 1: - case 4: - if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask) - && srccolors) { - /* ==== pal 1 or 4 bmp -> any 0888 dib ==== */ - int rShift,gShift,bShift; - DWORD* dstpixel; - - rShift=X11DRV_DIB_MaskToShift(rDst); - gShift=X11DRV_DIB_MaskToShift(gDst); - bShift=X11DRV_DIB_MaskToShift(bDst); - for (h = lines - 1; h >= 0; h--) { - dstpixel=(DWORD*)dstbits; - for (x = 0; x < width; x++) { - PALETTEENTRY srcval; - srcval = srccolors[XGetPixel(bmpImage, x, h)]; - *dstpixel++=(srcval.peRed << rShift) | - (srcval.peGreen << gShift) | - (srcval.peBlue << bShift); - } - dstbits += linebytes; - } - } else { - goto notsupported; - } - break; - - case 8: - if (X11DRV_DIB_CheckMask(bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask) - && srccolors) { - /* ==== pal 8 bmp -> any 0888 dib ==== */ - int rShift,gShift,bShift; - const void* srcbits; - const BYTE* srcpixel; - DWORD* dstpixel; - - rShift=X11DRV_DIB_MaskToShift(rDst); - gShift=X11DRV_DIB_MaskToShift(gDst); - bShift=X11DRV_DIB_MaskToShift(bDst); - srcbits=bmpImage->data+(lines-1)*bmpImage->bytes_per_line; - for (h = lines - 1; h >= 0; h--) { - srcpixel=srcbits; - dstpixel=(DWORD*)dstbits; - for (x = 0; x < width; x++) { - PALETTEENTRY srcval; - srcval=srccolors[*srcpixel++]; - *dstpixel++=(srcval.peRed << rShift) | - (srcval.peGreen << gShift) | - (srcval.peBlue << bShift); - } - srcbits = (const char*)srcbits - bmpImage->bytes_per_line; - dstbits += linebytes; - } - } else { - goto notsupported; - } - break; - - default: - notsupported: - { - /* ==== any bmp format -> any 0888 dib ==== */ - int rShift,gShift,bShift; - DWORD* dstpixel; - - WARN("from unknown %d bit bitmap (%lx,%lx,%lx) to 32 bit DIB (%x,%x,%x)\n", - bmpImage->depth, bmpImage->red_mask, - bmpImage->green_mask, bmpImage->blue_mask, - rDst,gDst,bDst); - - rShift=X11DRV_DIB_MaskToShift(rDst); - gShift=X11DRV_DIB_MaskToShift(gDst); - bShift=X11DRV_DIB_MaskToShift(bDst); - for (h = lines - 1; h >= 0; h--) { - dstpixel=(DWORD*)dstbits; - for (x = 0; x < width; x++) { - COLORREF srcval; - srcval=X11DRV_PALETTE_ToLogical(physDev, XGetPixel(bmpImage, x, h)); - *dstpixel++=(GetRValue(srcval) << rShift) | - (GetGValue(srcval) << gShift) | - (GetBValue(srcval) << bShift); - } - dstbits += linebytes; - } - } - break; - } -} - -/*********************************************************************** - * X11DRV_DIB_SetImageBits - * - * Transfer the bits to an X image. - * Helper function for SetDIBits() and SetDIBitsToDevice(). - */ -static int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr ) -{ - int lines = descr->lines >= 0 ? descr->lines : -descr->lines; - void *old_data = NULL; - XImage *bmpImage; - - wine_tsx11_lock(); - if (descr->image) - bmpImage = descr->image; - else { - bmpImage = XCreateImage( gdi_display, visual, descr->depth, ZPixmap, 0, NULL, - descr->infoWidth, lines, 32, 0 ); - bmpImage->data = HeapAlloc( GetProcessHeap(), 0, lines * bmpImage->bytes_per_line ); - if(bmpImage->data == NULL) { - ERR("Out of memory!\n"); - XDestroyImage( bmpImage ); - wine_tsx11_unlock(); - return 0; - } - if (descr->shifts) - { - bmpImage->red_mask = descr->shifts->physicalRed.max << descr->shifts->physicalRed.shift; - bmpImage->green_mask = descr->shifts->physicalGreen.max << descr->shifts->physicalGreen.shift; - bmpImage->blue_mask = descr->shifts->physicalBlue.max << descr->shifts->physicalBlue.shift; - } - } - wine_tsx11_unlock(); - - TRACE("Dib: depth=%d r=%x g=%x b=%x\n", - descr->infoBpp,descr->rMask,descr->gMask,descr->bMask); - TRACE("Bmp: depth=%d/%d r=%lx g=%lx b=%lx\n", - bmpImage->depth,bmpImage->bits_per_pixel, - bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask); - -#ifdef HAVE_LIBXXSHM - if (descr->shm_mode == X11DRV_SHM_PIXMAP - && descr->xSrc == 0 && descr->ySrc == 0 - && descr->xDest == 0 && descr->yDest == 0) - { - TRACE("Using the shared pixmap data.\n"); - - wine_tsx11_lock(); - XSync( gdi_display, False ); - wine_tsx11_unlock(); - - old_data = descr->image->data; - descr->image->data = descr->physBitmap->shminfo.shmaddr; - } -#endif - - /* Transfer the pixels */ - __TRY - { - switch(descr->infoBpp) - { - case 1: - X11DRV_DIB_SetImageBits_1( descr->lines, descr->bits, descr->infoWidth, - descr->width, descr->xSrc, (int *)(descr->colorMap), - bmpImage, descr->dibpitch ); - break; - case 4: - X11DRV_DIB_SetImageBits_4( descr->lines, descr->bits, - descr->infoWidth, descr->width, - descr->xSrc, (int*)(descr->colorMap), - bmpImage, descr->dibpitch ); - break; - case 8: - X11DRV_DIB_SetImageBits_8( descr->lines, descr->bits, - descr->infoWidth, descr->width, - descr->xSrc, (int *)(descr->colorMap), - bmpImage, descr->dibpitch ); - break; - case 16: - X11DRV_DIB_SetImageBits_16( descr->lines, descr->bits, - descr->infoWidth, descr->width, - descr->xSrc, descr->physDev, - descr->rMask, descr->gMask, descr->bMask, - bmpImage, descr->dibpitch); - break; - case 24: - X11DRV_DIB_SetImageBits_24( descr->lines, descr->bits, - descr->infoWidth, descr->width, - descr->xSrc, descr->physDev, - descr->rMask, descr->gMask, descr->bMask, - bmpImage, descr->dibpitch); - break; - case 32: - X11DRV_DIB_SetImageBits_32( descr->lines, descr->bits, - descr->infoWidth, descr->width, - descr->xSrc, descr->physDev, - descr->rMask, descr->gMask, descr->bMask, - bmpImage, descr->dibpitch); - break; - default: - WARN("(%d): Invalid depth\n", descr->infoBpp ); - break; - } - } - __EXCEPT_PAGE_FAULT - { - WARN( "invalid bits pointer %p\n", descr->bits ); - lines = 0; - } - __ENDTRY - - TRACE("XPutImage(%ld,%p,%p,%d,%d,%d,%d,%d,%d)\n", - descr->drawable, descr->gc, bmpImage, - descr->xSrc, descr->ySrc, descr->xDest, descr->yDest, - descr->width, descr->height); - - wine_tsx11_lock(); - if (lines) - { -#ifdef HAVE_LIBXXSHM - if (descr->shm_mode == X11DRV_SHM_PIXMAP - && descr->xSrc == 0 && descr->ySrc == 0 - && descr->xDest == 0 && descr->yDest == 0) - { - XSync( gdi_display, False ); - } - else if (descr->shm_mode == X11DRV_SHM_IMAGE && descr->image) - { - XShmPutImage( gdi_display, descr->drawable, descr->gc, bmpImage, - descr->xSrc, descr->ySrc, descr->xDest, descr->yDest, - descr->width, descr->height, FALSE ); - XSync( gdi_display, 0 ); - } - else -#endif - { - XPutImage( gdi_display, descr->drawable, descr->gc, bmpImage, - descr->xSrc, descr->ySrc, descr->xDest, descr->yDest, - descr->width, descr->height ); - } - } - - if (old_data) descr->image->data = old_data; - - if (!descr->image) X11DRV_DIB_DestroyXImage( bmpImage ); - wine_tsx11_unlock(); - return lines; -} - -/*********************************************************************** - * X11DRV_DIB_GetImageBits - * - * Transfer the bits from an X image. - */ -static int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr ) -{ - int lines = descr->lines >= 0 ? descr->lines : -descr->lines; - void *old_data = NULL; - XImage *bmpImage; - - wine_tsx11_lock(); - if (descr->image) - bmpImage = descr->image; - else { - bmpImage = XCreateImage( gdi_display, visual, descr->depth, ZPixmap, 0, NULL, - descr->infoWidth, lines, 32, 0 ); - bmpImage->data = HeapAlloc( GetProcessHeap(), 0, lines * bmpImage->bytes_per_line ); - if(bmpImage->data == NULL) { - ERR("Out of memory!\n"); - XDestroyImage( bmpImage ); - wine_tsx11_unlock(); - return 0; - } - if (descr->shifts) - { - bmpImage->red_mask = descr->shifts->physicalRed.max << descr->shifts->physicalRed.shift; - bmpImage->green_mask = descr->shifts->physicalGreen.max << descr->shifts->physicalGreen.shift; - bmpImage->blue_mask = descr->shifts->physicalBlue.max << descr->shifts->physicalBlue.shift; - } - } - -#ifdef HAVE_LIBXXSHM - - /* We must not call XShmGetImage() with a bitmap which is bigger than the available area. - If we do, XShmGetImage() will fail (X exception), as it checks for this internally. */ - if (descr->shm_mode == X11DRV_SHM_PIXMAP && descr->image - && descr->xSrc == 0 && descr->ySrc == 0 - && descr->xDest == 0 && descr->yDest == 0 - && bmpImage->width <= (descr->width - descr->xSrc) - && bmpImage->height <= (descr->height - descr->ySrc)) - { - XSync( gdi_display, False ); - old_data = bmpImage->data; - bmpImage->data = descr->physBitmap->shminfo.shmaddr; - TRACE("Using shared pixmap data.\n"); - } - else if (descr->shm_mode == X11DRV_SHM_IMAGE && descr->image - && bmpImage->width <= (descr->width - descr->xSrc) - && bmpImage->height <= (descr->height - descr->ySrc)) - { - int saveRed, saveGreen, saveBlue; - - TRACE("XShmGetImage(%p, %ld, %p, %d, %d, %ld)\n", - gdi_display, descr->drawable, bmpImage, - descr->xSrc, descr->ySrc, AllPlanes); - - /* We must save and restore the bmpImage's masks in order - * to preserve them across the call to XShmGetImage, which - * decides to eliminate them since it doesn't happen to know - * what the format of the image is supposed to be, even though - * we do. */ - saveRed = bmpImage->red_mask; - saveBlue= bmpImage->blue_mask; - saveGreen = bmpImage->green_mask; - - XShmGetImage( gdi_display, descr->drawable, bmpImage, - descr->xSrc, descr->ySrc, AllPlanes); - - bmpImage->red_mask = saveRed; - bmpImage->blue_mask = saveBlue; - bmpImage->green_mask = saveGreen; - } - else -#endif /* HAVE_LIBXXSHM */ - { - TRACE("XGetSubImage(%p,%ld,%d,%d,%d,%d,%ld,%d,%p,%d,%d)\n", - gdi_display, descr->drawable, descr->xSrc, descr->ySrc, descr->width, - lines, AllPlanes, ZPixmap, bmpImage, descr->xDest, descr->yDest); - XGetSubImage( gdi_display, descr->drawable, descr->xSrc, descr->ySrc, - descr->width, lines, AllPlanes, ZPixmap, - bmpImage, descr->xDest, descr->yDest ); - } - wine_tsx11_unlock(); - - TRACE("Dib: depth=%2d r=%x g=%x b=%x\n", - descr->infoBpp,descr->rMask,descr->gMask,descr->bMask); - TRACE("Bmp: depth=%2d/%2d r=%lx g=%lx b=%lx\n", - bmpImage->depth,bmpImage->bits_per_pixel, - bmpImage->red_mask,bmpImage->green_mask,bmpImage->blue_mask); - /* Transfer the pixels */ - switch(descr->infoBpp) - { - case 1: - X11DRV_DIB_GetImageBits_1( descr->lines,(LPVOID)descr->bits, - descr->infoWidth, descr->width, - descr->colorMap, descr->palentry, - bmpImage, descr->dibpitch ); - break; - - case 4: - X11DRV_DIB_GetImageBits_4( descr->lines,(LPVOID)descr->bits, - descr->infoWidth, descr->width, - descr->colorMap, descr->palentry, - bmpImage, descr->dibpitch ); - break; - case 8: - X11DRV_DIB_GetImageBits_8( descr->lines, (LPVOID)descr->bits, - descr->infoWidth, descr->width, - descr->colorMap, descr->palentry, - bmpImage, descr->dibpitch ); - break; - case 16: - X11DRV_DIB_GetImageBits_16( descr->physDev, descr->lines, (LPVOID)descr->bits, - descr->infoWidth,descr->width, - descr->palentry, - descr->rMask, descr->gMask, descr->bMask, - bmpImage, descr->dibpitch ); - break; - - case 24: - X11DRV_DIB_GetImageBits_24( descr->physDev, descr->lines, (LPVOID)descr->bits, - descr->infoWidth,descr->width, - descr->palentry, - descr->rMask, descr->gMask, descr->bMask, - bmpImage, descr->dibpitch); - break; - - case 32: - X11DRV_DIB_GetImageBits_32( descr->physDev, descr->lines, (LPVOID)descr->bits, - descr->infoWidth, descr->width, - descr->palentry, - descr->rMask, descr->gMask, descr->bMask, - bmpImage, descr->dibpitch); - break; - - default: - WARN("(%d): Invalid depth\n", descr->infoBpp ); - break; - } - - if (old_data) bmpImage->data = old_data; - if (!descr->image) X11DRV_DIB_DestroyXImage( bmpImage ); - return lines; -} - -/*********************************************************************** - * X11DRV_DIB_DoCopyDIBSection - */ -static void X11DRV_DIB_DoCopyDIBSection(X_PHYSBITMAP *physBitmap, BOOL toDIB, - void *colorMap, int nColorMap, - Drawable dest, GC gc, - DWORD xSrc, DWORD ySrc, - DWORD xDest, DWORD yDest, - DWORD width, DWORD height) -{ - DIBSECTION dibSection; - X11DRV_DIB_IMAGEBITS_DESCR descr; - int identity[2] = {0,1}; - - if (!GetObjectW( physBitmap->hbitmap, sizeof(dibSection), &dibSection )) return; - - descr.physDev = NULL; - descr.palentry = NULL; - descr.infoWidth = dibSection.dsBmih.biWidth; - descr.infoBpp = dibSection.dsBmih.biBitCount; - descr.lines = physBitmap->topdown ? -dibSection.dsBmih.biHeight : dibSection.dsBmih.biHeight; - descr.image = physBitmap->image; - descr.colorMap = colorMap; - descr.nColorMap = nColorMap; - descr.bits = dibSection.dsBm.bmBits; - descr.depth = physBitmap->depth; - descr.shifts = physBitmap->trueColor ? &physBitmap->color_shifts : NULL; - descr.compression = dibSection.dsBmih.biCompression; - descr.physBitmap = physBitmap; - - if(descr.infoBpp == 1) - descr.colorMap = (void*)identity; - - switch (descr.infoBpp) - { - case 1: - case 4: - case 8: - descr.rMask = descr.gMask = descr.bMask = 0; - break; - case 15: - case 16: - descr.rMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[0] : 0x7c00; - descr.gMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[1] : 0x03e0; - descr.bMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[2] : 0x001f; - break; - - case 24: - case 32: - descr.rMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[0] : 0xff0000; - descr.gMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[1] : 0x00ff00; - descr.bMask = (descr.compression == BI_BITFIELDS) ? dibSection.dsBitfields[2] : 0x0000ff; - break; - } - - /* Hack for now */ - descr.drawable = dest; - descr.gc = gc; - descr.xSrc = xSrc; - descr.ySrc = ySrc; - descr.xDest = xDest; - descr.yDest = yDest; - descr.width = width; - descr.height = height; - descr.sizeImage = 0; - - descr.shm_mode = physBitmap->shm_mode; -#ifdef HAVE_LIBXXSHM - if (physBitmap->shm_mode == X11DRV_SHM_PIXMAP && physBitmap->pixmap != dest) - { - descr.shm_mode = X11DRV_SHM_NONE; - } -#endif - descr.dibpitch = dibSection.dsBm.bmWidthBytes; - - if (toDIB) - { - TRACE("Copying from Pixmap to DIB bits\n"); - X11DRV_DIB_GetImageBits( &descr ); - } - else - { - TRACE("Copying from DIB bits to Pixmap\n"); - X11DRV_DIB_SetImageBits( &descr ); - } -} - -/*********************************************************************** - * X11DRV_DIB_DoUpdateDIBSection - */ -static void X11DRV_DIB_DoUpdateDIBSection(X_PHYSBITMAP *physBitmap, BOOL toDIB) -{ - BITMAP bitmap; - - GetObjectW( physBitmap->hbitmap, sizeof(bitmap), &bitmap ); - X11DRV_DIB_DoCopyDIBSection(physBitmap, toDIB, - physBitmap->colorMap, physBitmap->nColorMap, - physBitmap->pixmap, get_bitmap_gc(physBitmap->depth), - 0, 0, 0, 0, bitmap.bmWidth, bitmap.bmHeight); -} - -/*********************************************************************** - * X11DRV_DIB_FaultHandler - */ -static LONG CALLBACK X11DRV_DIB_FaultHandler( PEXCEPTION_POINTERS ep ) -{ - X_PHYSBITMAP *physBitmap = NULL; - BOOL found = FALSE; - BYTE *addr; - struct list *ptr; - const size_t pagemask = getpagesize() - 1; - - if (ep->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION) - return EXCEPTION_CONTINUE_SEARCH; - - addr = (BYTE *)ep->ExceptionRecord->ExceptionInformation[1]; - - EnterCriticalSection(&dibs_cs); - LIST_FOR_EACH( ptr, &dibs_list ) - { - physBitmap = LIST_ENTRY( ptr, X_PHYSBITMAP, entry ); - if ((physBitmap->base <= addr) && - (addr < physBitmap->base + ((physBitmap->size + pagemask) & ~pagemask))) - { - found = TRUE; - break; - } - } - LeaveCriticalSection(&dibs_cs); - - if (!found) return EXCEPTION_CONTINUE_SEARCH; - - if (addr >= physBitmap->base + physBitmap->size) - WARN( "%p: access to %p beyond the end of the DIB\n", physBitmap->hbitmap, addr ); - - X11DRV_DIB_Lock( physBitmap, DIB_Status_None ); - if (ep->ExceptionRecord->ExceptionInformation[0] == EXCEPTION_WRITE_FAULT) { - /* the app tried to write the DIB bits */ - X11DRV_DIB_Coerce( physBitmap, DIB_Status_AppMod); - } else { - /* the app tried to read the DIB bits */ - X11DRV_DIB_Coerce( physBitmap, DIB_Status_InSync); - } - X11DRV_DIB_Unlock( physBitmap, TRUE ); - - return EXCEPTION_CONTINUE_EXECUTION; -} - -/*********************************************************************** - * X11DRV_DIB_Coerce - */ -static INT X11DRV_DIB_Coerce(X_PHYSBITMAP *physBitmap, INT req) -{ - INT ret = DIB_Status_None; - - if (!physBitmap->image) return ret; /* not a DIB section */ - EnterCriticalSection(&physBitmap->lock); - ret = physBitmap->status; - switch (req) { - case DIB_Status_GdiMod: - /* GDI access - request to draw on pixmap */ - switch (physBitmap->status) - { - default: - case DIB_Status_None: - physBitmap->p_status = DIB_Status_GdiMod; - X11DRV_DIB_DoUpdateDIBSection( physBitmap, FALSE ); - break; - - case DIB_Status_GdiMod: - TRACE("GdiMod requested in status GdiMod\n" ); - physBitmap->p_status = DIB_Status_GdiMod; - break; - - case DIB_Status_InSync: - TRACE("GdiMod requested in status InSync\n" ); - X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_NOACCESS ); - physBitmap->status = DIB_Status_GdiMod; - physBitmap->p_status = DIB_Status_InSync; - break; - - case DIB_Status_AppMod: - TRACE("GdiMod requested in status AppMod\n" ); - /* make it readonly to avoid app changing data while we copy */ - X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READONLY ); - X11DRV_DIB_DoUpdateDIBSection( physBitmap, FALSE ); - X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_NOACCESS ); - physBitmap->p_status = DIB_Status_AppMod; - physBitmap->status = DIB_Status_GdiMod; - break; - } - break; - - case DIB_Status_InSync: - /* App access - request access to read DIB surface */ - /* (typically called from signal handler) */ - switch (physBitmap->status) - { - default: - case DIB_Status_None: - /* shouldn't happen from signal handler */ - break; - - case DIB_Status_GdiMod: - TRACE("InSync requested in status GdiMod\n" ); - X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READWRITE ); - X11DRV_DIB_DoUpdateDIBSection( physBitmap, TRUE ); - X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READONLY ); - physBitmap->status = DIB_Status_InSync; - break; - - case DIB_Status_InSync: - TRACE("InSync requested in status InSync\n" ); - /* shouldn't happen from signal handler */ - break; - - case DIB_Status_AppMod: - TRACE("InSync requested in status AppMod\n" ); - /* no reason to do anything here, and this - * shouldn't happen from signal handler */ - break; - } - break; - - case DIB_Status_AppMod: - /* App access - request access to write DIB surface */ - /* (typically called from signal handler) */ - switch (physBitmap->status) - { - default: - case DIB_Status_None: - /* shouldn't happen from signal handler */ - break; - - case DIB_Status_GdiMod: - TRACE("AppMod requested in status GdiMod\n" ); - X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READWRITE ); - X11DRV_DIB_DoUpdateDIBSection( physBitmap, TRUE ); - physBitmap->status = DIB_Status_AppMod; - break; - - case DIB_Status_InSync: - TRACE("AppMod requested in status InSync\n" ); - X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READWRITE ); - physBitmap->status = DIB_Status_AppMod; - break; - - case DIB_Status_AppMod: - TRACE("AppMod requested in status AppMod\n" ); - /* shouldn't happen from signal handler */ - break; - } - break; - - /* it is up to the caller to do the copy/conversion, probably - * using the return value to decide where to copy from */ - } - LeaveCriticalSection(&physBitmap->lock); - return ret; -} - -/*********************************************************************** - * X11DRV_DIB_Lock - */ -INT X11DRV_DIB_Lock(X_PHYSBITMAP *physBitmap, INT req) -{ - INT ret = DIB_Status_None; - - if (!physBitmap->image) return ret; /* not a DIB section */ - TRACE("Locking %p from thread %04x\n", physBitmap->hbitmap, GetCurrentThreadId()); - EnterCriticalSection(&physBitmap->lock); - ret = physBitmap->status; - if (req != DIB_Status_None) - X11DRV_DIB_Coerce(physBitmap, req); - return ret; -} - -/*********************************************************************** - * X11DRV_DIB_Unlock - */ -void X11DRV_DIB_Unlock(X_PHYSBITMAP *physBitmap, BOOL commit) -{ - if (!physBitmap->image) return; /* not a DIB section */ - switch (physBitmap->status) - { - default: - case DIB_Status_None: - /* in case anyone is wondering, this is the "signal handler doesn't - * work" case, where we always have to be ready for app access */ - if (commit) { - switch (physBitmap->p_status) - { - case DIB_Status_GdiMod: - TRACE("Unlocking and syncing from GdiMod\n" ); - X11DRV_DIB_DoUpdateDIBSection( physBitmap, TRUE ); - break; - - default: - TRACE("Unlocking without needing to sync\n" ); - break; - } - } - else TRACE("Unlocking with no changes\n"); - physBitmap->p_status = DIB_Status_None; - break; - - case DIB_Status_GdiMod: - TRACE("Unlocking in status GdiMod\n" ); - /* DIB was protected in Coerce */ - if (!commit) { - /* no commit, revert to InSync if applicable */ - if ((physBitmap->p_status == DIB_Status_InSync) || - (physBitmap->p_status == DIB_Status_AppMod)) { - X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READONLY ); - physBitmap->status = DIB_Status_InSync; - } - } - break; - - case DIB_Status_InSync: - TRACE("Unlocking in status InSync\n" ); - /* DIB was already protected in Coerce */ - break; - - case DIB_Status_AppMod: - TRACE("Unlocking in status AppMod\n" ); - /* DIB was already protected in Coerce */ - /* this case is ordinary only called from the signal handler, - * so we don't bother to check for !commit */ - break; - } - LeaveCriticalSection(&physBitmap->lock); - TRACE("Unlocked %p\n", physBitmap->hbitmap); -} - -/*********************************************************************** - * X11DRV_CoerceDIBSection - */ -INT X11DRV_CoerceDIBSection(X11DRV_PDEVICE *physDev, INT req) -{ - if (!physDev || !physDev->bitmap) return DIB_Status_None; - return X11DRV_DIB_Coerce(physDev->bitmap, req); -} - - -#ifdef HAVE_LIBXXSHM -/*********************************************************************** - * X11DRV_XShmErrorHandler - * - */ -static int XShmErrorHandler( Display *dpy, XErrorEvent *event, void *arg ) -{ - return 1; /* FIXME: should check event contents */ -} - -/*********************************************************************** - * X11DRV_XShmCreateImage - * - */ -static XImage *X11DRV_XShmCreateImage( int width, int height, int bpp, - XShmSegmentInfo* shminfo) -{ - XImage *image; - - image = XShmCreateImage(gdi_display, visual, bpp, ZPixmap, NULL, shminfo, width, height); - if (image) - { - shminfo->shmid = shmget(IPC_PRIVATE, image->bytes_per_line * height, - IPC_CREAT|0700); - if( shminfo->shmid != -1 ) - { - shminfo->shmaddr = shmat( shminfo->shmid, 0, 0 ); - if( shminfo->shmaddr != (char*)-1 ) - { - BOOL ok; - - shminfo->readOnly = FALSE; - X11DRV_expect_error( gdi_display, XShmErrorHandler, NULL ); - ok = (XShmAttach( gdi_display, shminfo ) != 0); - XSync( gdi_display, False ); - if (X11DRV_check_error()) ok = FALSE; - if (ok) - { - shmctl(shminfo->shmid, IPC_RMID, 0); - return image; /* Success! */ - } - /* An error occurred */ - shmdt(shminfo->shmaddr); - } - shmctl(shminfo->shmid, IPC_RMID, 0); - shminfo->shmid = -1; - } - XFlush(gdi_display); - XDestroyImage(image); - image = NULL; - } - return image; -} - -static Bool X11DRV_DIB_QueryXShm( Bool *pixmaps ) -{ - static Bool have_xshm, have_xshm_pixmaps; - static BOOL initialized; - - if (!initialized) - { - int major, minor; - - have_xshm = XShmQueryVersion( gdi_display, &major, &minor, &have_xshm_pixmaps ); - initialized = TRUE; - } - - *pixmaps = have_xshm_pixmaps; - return have_xshm; -} -#endif /* HAVE_LIBXXSHM */ - -/*********************************************************************** - * X11DRV_CreateDIBSection (X11DRV.@) - */ -HBITMAP X11DRV_CreateDIBSection( PHYSDEV dev, HBITMAP hbitmap, BITMAPINFO *bmi, UINT usage ) -{ - X11DRV_PDEVICE *physDev = get_x11drv_dev( dev ); - X_PHYSBITMAP *physBitmap; - DIBSECTION dib; -#ifdef HAVE_LIBXXSHM - Bool pixmaps; -#endif - - if (!(physBitmap = X11DRV_init_phys_bitmap( hbitmap ))) return 0; - physBitmap->topdown = bmi->bmiHeader.biHeight < 0; - physBitmap->status = DIB_Status_None; - - GetObjectW( hbitmap, sizeof(dib), &dib ); - - /* create color map */ - if (dib.dsBm.bmBitsPixel <= 8) - { - physBitmap->colorMap = X11DRV_DIB_BuildColorMap( physDev, - usage, dib.dsBm.bmBitsPixel, bmi, - &physBitmap->nColorMap ); - } - - if (!X11DRV_XRender_SetPhysBitmapDepth( physBitmap, dib.dsBm.bmBitsPixel, &dib )) - { - if (dib.dsBm.bmBitsPixel == 1) - { - physBitmap->depth = 1; - physBitmap->trueColor = FALSE; - } - else - { - physBitmap->depth = screen_depth; - physBitmap->color_shifts = X11DRV_PALETTE_default_shifts; - physBitmap->trueColor = (visual->class == TrueColor || visual->class == DirectColor); - } - } - - /* create pixmap and X image */ - wine_tsx11_lock(); -#ifdef HAVE_LIBXXSHM - physBitmap->shminfo.shmid = -1; - - if (X11DRV_DIB_QueryXShm( &pixmaps ) - && (physBitmap->image = X11DRV_XShmCreateImage( dib.dsBm.bmWidth, dib.dsBm.bmHeight, - physBitmap->depth, &physBitmap->shminfo ))) - { - if (pixmaps) - { - physBitmap->shm_mode = X11DRV_SHM_PIXMAP; - physBitmap->image->data = HeapAlloc( GetProcessHeap(), 0, - dib.dsBm.bmHeight * physBitmap->image->bytes_per_line ); - } - else - { - physBitmap->shm_mode = X11DRV_SHM_IMAGE; - physBitmap->image->data = physBitmap->shminfo.shmaddr; - } - } - else -#endif - { - physBitmap->shm_mode = X11DRV_SHM_NONE; - physBitmap->image = X11DRV_DIB_CreateXImage( dib.dsBm.bmWidth, dib.dsBm.bmHeight, - physBitmap->depth ); - } - -#ifdef HAVE_LIBXXSHM - if (physBitmap->shm_mode == X11DRV_SHM_PIXMAP) - { - TRACE("Creating shared pixmap for bmp %p.\n", physBitmap->hbitmap); - physBitmap->pixmap = XShmCreatePixmap( gdi_display, root_window, - physBitmap->shminfo.shmaddr, &physBitmap->shminfo, - dib.dsBm.bmWidth, dib.dsBm.bmHeight, - physBitmap->depth ); - } - else -#endif - { - physBitmap->pixmap = XCreatePixmap( gdi_display, root_window, dib.dsBm.bmWidth, - dib.dsBm.bmHeight, physBitmap->depth ); - } - - wine_tsx11_unlock(); - if (!physBitmap->pixmap || !physBitmap->image) return 0; - - if (physBitmap->trueColor) - { - ColorShifts *shifts = &physBitmap->color_shifts; - - /* When XRender is around and used, we also support dibsections in other formats like 16-bit. In these - * cases we need to override the mask of XImages. The reason is that during XImage creation the masks are - * derived from a 24-bit visual (no 16-bit ones are around when X runs at 24-bit). SetImageBits and other - * functions rely on the color masks for proper color conversion, so we need to override the masks here. */ - physBitmap->image->red_mask = shifts->physicalRed.max << shifts->physicalRed.shift; - physBitmap->image->green_mask = shifts->physicalGreen.max << shifts->physicalGreen.shift; - physBitmap->image->blue_mask = shifts->physicalBlue.max << shifts->physicalBlue.shift; - } - - /* install fault handler */ - InitializeCriticalSection( &physBitmap->lock ); - physBitmap->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": X_PHYSBITMAP.lock"); - - physBitmap->base = dib.dsBm.bmBits; - physBitmap->size = dib.dsBmih.biSizeImage; - physBitmap->status = DIB_Status_AppMod; - - if (!dibs_handler) - dibs_handler = AddVectoredExceptionHandler( TRUE, X11DRV_DIB_FaultHandler ); - EnterCriticalSection( &dibs_cs ); - list_add_head( &dibs_list, &physBitmap->entry ); - LeaveCriticalSection( &dibs_cs ); - - X11DRV_DIB_DoProtectDIBSection( physBitmap, PAGE_READWRITE ); - - return hbitmap; -} - -/*********************************************************************** - * X11DRV_DIB_DeleteDIBSection - */ -void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP *physBitmap, DIBSECTION *dib) -{ - BOOL last; - - EnterCriticalSection( &dibs_cs ); - list_remove( &physBitmap->entry ); - last = list_empty( &dibs_list ); - LeaveCriticalSection( &dibs_cs ); - - if (last) - { - RemoveVectoredExceptionHandler( dibs_handler ); - dibs_handler = NULL; - } - - if (dib->dshSection) - X11DRV_DIB_Coerce(physBitmap, DIB_Status_InSync); - - if (physBitmap->image) - { - wine_tsx11_lock(); -#ifdef HAVE_LIBXXSHM - if (physBitmap->shminfo.shmid != -1) - { - XShmDetach( gdi_display, &(physBitmap->shminfo) ); - if (physBitmap->shm_mode == X11DRV_SHM_PIXMAP) X11DRV_DIB_DestroyXImage( physBitmap->image ); - else XDestroyImage( physBitmap->image ); - shmdt( physBitmap->shminfo.shmaddr ); - physBitmap->shminfo.shmid = -1; - physBitmap->shm_mode = X11DRV_SHM_NONE; - } - else -#endif - X11DRV_DIB_DestroyXImage( physBitmap->image ); - wine_tsx11_unlock(); - } - - HeapFree(GetProcessHeap(), 0, physBitmap->colorMap); - physBitmap->lock.DebugInfo->Spare[0] = 0; - DeleteCriticalSection(&physBitmap->lock); -} diff --git a/dlls/winex11.drv/dib_convert.c b/dlls/winex11.drv/dib_convert.c deleted file mode 100644 index 0bca50d7358..00000000000 --- a/dlls/winex11.drv/dib_convert.c +++ /dev/null @@ -1,1428 +0,0 @@ -/* - * DIB conversion routines for cases where the source and destination - * have the same byte order. - * - * Copyright (C) 2001 Francois Gouget - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include "config.h" - -#include - -#include "windef.h" -#include "x11drv.h" - - -/*********************************************************************** - * X11DRV_DIB_Convert_* - * - * All X11DRV_DIB_Convert_Xxx functions take at least the following - * parameters: - * - width - * This is the width in pixel of the surface to copy. This may be less - * than the full width of the image. - * - height - * The number of lines to copy. This may be less than the full height - * of the image. This is always >0. - * - srcbits - * Points to the first byte containing data to be copied. If the source - * surface starts at coordinates (x,y) then this is: - * image_ptr+x*bytes_per_pixel+y*bytes_per_line - * (with further adjustments for top-down/bottom-up images) - * - srclinebytes - * This is the number of bytes per line. It may be >0 or <0 depending on - * whether this is a top-down or bottom-up image. - * - dstbits - * Same as srcbits but for the destination - * - dstlinebytes - * Same as srclinebytes but for the destination. - * - * Notes: - * - The supported Dib formats are: pal1, pal4, pal8, rgb555, bgr555, - * rgb565, bgr565, rgb888 and any 32bit (0888) format. - * The supported XImage (Bmp) formats are: pal1, pal4, pal8, - * rgb555, bgr555, rgb565, bgr565, rgb888, bgr888, rgb0888, bgr0888. - * - Rgb formats are those for which the masks are such that: - * red_mask > green_mask > blue_mask - * - Bgr formats are those for which the masks sort in the other direction. - * - Many conversion functions handle both rgb->bgr and bgr->rgb conversions - * so the comments use h, g, l to mean respectively the source color in the - * high bits, the green, and the source color in the low bits. - */ - - -/* - * 15 bit conversions - */ - -static void convert_5x5_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - int y; - - width *= 2; - - if (srclinebytes == dstlinebytes && srclinebytes == width) - { - memcpy(dstbits, srcbits, height * width); - return; - } - - for (y=0; y> 10) & 0x001f001f); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval << 10) & 0x7c00) | /* h */ - ( srcval & 0x03e0) | /* g */ - ((srcval >> 10) & 0x001f); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_565_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 4) & 0x00200020) | /* g - 1 bit */ - ( srcval & 0x001f001f); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval << 1) & 0xffc0) | /* h, g */ - ((srcval >> 4) & 0x0020) | /* g - 1 bit */ - (srcval & 0x001f); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_565_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 10) & 0x001f001f) | /* h */ - ((srcval << 1) & 0x07c007c0) | /* g */ - ((srcval >> 4) & 0x00200020) | /* g - 1 bit */ - ((srcval << 11) & 0xf800f800); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval >> 10) & 0x001f) | /* h */ - ((srcval << 1) & 0x07c0) | /* g */ - ((srcval >> 4) & 0x0020) | /* g - 1 bit */ - ((srcval << 11) & 0xf800); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_888_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - BYTE* dstpixel; - int x,y; - - for (y=0; y> 2) & 0x07); /* l - 3 bits */ - dstpixel[1]=((srcval >> 2) & 0xf8) | /* g */ - ((srcval >> 7) & 0x07); /* g - 3 bits */ - dstpixel[2]=((srcval >> 7) & 0xf8) | /* h */ - ((srcval >> 12) & 0x07); /* h - 3 bits */ - dstpixel+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_888_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - BYTE* dstpixel; - int x,y; - - for (y=0; y> 7) & 0xf8) | /* h */ - ((srcval >> 12) & 0x07); /* h - 3 bits */ - dstpixel[1]=((srcval >> 2) & 0xf8) | /* g */ - ((srcval >> 7) & 0x07); /* g - 3 bits */ - dstpixel[2]=((srcval << 3) & 0xf8) | /* l */ - ((srcval >> 2) & 0x07); /* l - 3 bits */ - dstpixel+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_0888_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 2) & 0x000007); /* l - 3 bits */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_0888_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 7) & 0x0000f8) | /* h */ - ((srcval >> 12) & 0x000007) | /* h - 3 bits */ - ((srcval << 6) & 0x00f800) | /* g */ - ((srcval << 1) & 0x000700) | /* g - 3 bits */ - ((srcval << 19) & 0xf80000) | /* l */ - ((srcval << 14) & 0x070000); /* l - 3 bits */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_5x5_to_any0888(int width, int height, - const void* srcbits, int srclinebytes, - WORD rsrc, WORD gsrc, WORD bsrc, - void* dstbits, int dstlinebytes, - DWORD rdst, DWORD gdst, DWORD bdst) -{ - int rRightShift1,gRightShift1,bRightShift1; - int rRightShift2,gRightShift2,bRightShift2; - BYTE gMask1,gMask2; - int rLeftShift,gLeftShift,bLeftShift; - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - /* Note, the source pixel value is shifted left by 16 bits so that - * we know we will always have to shift right to extract the components. - */ - rRightShift1=16+X11DRV_DIB_MaskToShift(rsrc)-3; - gRightShift1=16+X11DRV_DIB_MaskToShift(gsrc)-3; - bRightShift1=16+X11DRV_DIB_MaskToShift(bsrc)-3; - rRightShift2=rRightShift1+5; - gRightShift2=gRightShift1+5; - bRightShift2=bRightShift1+5; - if (gsrc==0x03e0) { - /* Green has 5 bits, like the others */ - gMask1=0xf8; - gMask2=0x07; - } else { - /* Green has 6 bits, not 5. Compensate. */ - gRightShift1++; - gRightShift2+=2; - gMask1=0xfc; - gMask2=0x03; - } - - rLeftShift=X11DRV_DIB_MaskToShift(rdst); - gLeftShift=X11DRV_DIB_MaskToShift(gdst); - bLeftShift=X11DRV_DIB_MaskToShift(bdst); - - for (y=0; y> rRightShift1) & 0xf8) | - ((srcval >> rRightShift2) & 0x07); - green=((srcval >> gRightShift1) & gMask1) | - ((srcval >> gRightShift2) & gMask2); - blue= ((srcval >> bRightShift1) & 0xf8) | - ((srcval >> bRightShift2) & 0x07); - *dstpixel++=(red << rLeftShift) | - (green << gLeftShift) | - (blue << bLeftShift); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -/* - * 16 bits conversions - */ - -static void convert_565_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 11) & 0x001f001f); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval << 11) & 0xf800) | /* h */ - ( srcval & 0x07e0) | /* g */ - ((srcval >> 11) & 0x001f); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_555_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 1) & 0x7fe07fe0) | /* h, g */ - ( srcval & 0x001f001f); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval >> 1) & 0x7fe0) | /* h, g */ - ( srcval & 0x001f); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_555_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 11) & 0x001f001f) | /* h */ - ((srcval >> 1) & 0x03e003e0) | /* g */ - ((srcval << 10) & 0x7c007c00); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval >> 11) & 0x001f) | /* h */ - ((srcval >> 1) & 0x03e0) | /* g */ - ((srcval << 10) & 0x7c00); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_888_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - BYTE* dstpixel; - int x,y; - - for (y=0; y> 2) & 0x07); /* l - 3 bits */ - dstpixel[1]=((srcval >> 3) & 0xfc) | /* g */ - ((srcval >> 9) & 0x03); /* g - 2 bits */ - dstpixel[2]=((srcval >> 8) & 0xf8) | /* h */ - ((srcval >> 13) & 0x07); /* h - 3 bits */ - dstpixel+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_888_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - BYTE* dstpixel; - int x,y; - - for (y=0; y> 8) & 0xf8) | /* h */ - ((srcval >> 13) & 0x07); /* h - 3 bits */ - dstpixel[1]=((srcval >> 3) & 0xfc) | /* g */ - ((srcval >> 9) & 0x03); /* g - 2 bits */ - dstpixel[2]=((srcval << 3) & 0xf8) | /* l */ - ((srcval >> 2) & 0x07); /* l - 3 bits */ - dstpixel+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_0888_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 1) & 0x000300) | /* g - 2 bits */ - ((srcval << 3) & 0x0000f8) | /* l */ - ((srcval >> 2) & 0x000007); /* l - 3 bits */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_0888_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 8) & 0x0000f8) | /* h */ - ((srcval >> 13) & 0x000007) | /* h - 3 bits */ - ((srcval << 5) & 0x00fc00) | /* g */ - ((srcval >> 1) & 0x000300) | /* g - 2 bits */ - ((srcval << 19) & 0xf80000) | /* l */ - ((srcval << 14) & 0x070000); /* l - 3 bits */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - - -/* - * 24 bit conversions - */ - -static void convert_888_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - int y; - - width *= 3; - - if (srclinebytes == dstlinebytes && srclinebytes == width) - { - memcpy(dstbits, srcbits, height * width); - return; - } - - for (y=0; y> 3) & 0x001f) | /* l1 */ - ((srcval1 >> 6) & 0x03e0) | /* g1 */ - ((srcval1 >> 9) & 0x7c00); /* h1 */ - srcval2=srcpixel[1]; - dstpixel[1]=((srcval1 >> 27) & 0x001f) | /* l2 */ - ((srcval2 << 2) & 0x03e0) | /* g2 */ - ((srcval2 >> 1) & 0x7c00); /* h2 */ - srcval1=srcpixel[2]; - dstpixel[2]=((srcval2 >> 19) & 0x001f) | /* l3 */ - ((srcval2 >> 22) & 0x03e0) | /* g3 */ - ((srcval1 << 7) & 0x7c00); /* h3 */ - dstpixel[3]=((srcval1 >> 11) & 0x001f) | /* l4 */ - ((srcval1 >> 14) & 0x03e0) | /* g4 */ - ((srcval1 >> 17) & 0x7c00); /* h4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - srcbyte=(const BYTE*)srcpixel; - for (x=0; x> 3) & 0x001f); /* l */ - dstval|=((srcbyte[1] << 2) & 0x03e0); /* g */ - dstval|=((srcbyte[2] << 7) & 0x7c00); /* h */ - *dstpixel++=dstval; - srcbyte+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_555_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - const BYTE* srcbyte; - WORD* dstpixel; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 6) & 0x03e0) | /* g1 */ - ((srcval1 >> 19) & 0x001f); /* h1 */ - srcval2=srcpixel[1]; - dstpixel[1]=((srcval1 >> 17) & 0x7c00) | /* l2 */ - ((srcval2 << 2) & 0x03e0) | /* g2 */ - ((srcval2 >> 11) & 0x001f); /* h2 */ - srcval1=srcpixel[2]; - dstpixel[2]=((srcval2 >> 9) & 0x7c00) | /* l3 */ - ((srcval2 >> 22) & 0x03e0) | /* g3 */ - ((srcval1 >> 3) & 0x001f); /* h3 */ - dstpixel[3]=((srcval1 >> 1) & 0x7c00) | /* l4 */ - ((srcval1 >> 14) & 0x03e0) | /* g4 */ - ((srcval1 >> 27) & 0x001f); /* h4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - srcbyte=(const BYTE*)srcpixel; - for (x=0; x> 3) & 0x001f); /* h */ - *dstpixel++=dstval; - srcbyte+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_565_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - const BYTE* srcbyte; - WORD* dstpixel; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 3) & 0x001f) | /* l1 */ - ((srcval1 >> 5) & 0x07e0) | /* g1 */ - ((srcval1 >> 8) & 0xf800); /* h1 */ - srcval2=srcpixel[1]; - dstpixel[1]=((srcval1 >> 27) & 0x001f) | /* l2 */ - ((srcval2 << 3) & 0x07e0) | /* g2 */ - ( srcval2 & 0xf800); /* h2 */ - srcval1=srcpixel[2]; - dstpixel[2]=((srcval2 >> 19) & 0x001f) | /* l3 */ - ((srcval2 >> 21) & 0x07e0) | /* g3 */ - ((srcval1 << 8) & 0xf800); /* h3 */ - dstpixel[3]=((srcval1 >> 11) & 0x001f) | /* l4 */ - ((srcval1 >> 13) & 0x07e0) | /* g4 */ - ((srcval1 >> 16) & 0xf800); /* h4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - srcbyte=(const BYTE*)srcpixel; - for (x=0; x> 3) & 0x001f); /* l */ - dstval|=((srcbyte[1] << 3) & 0x07e0); /* g */ - dstval|=((srcbyte[2] << 8) & 0xf800); /* h */ - *dstpixel++=dstval; - srcbyte+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_565_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - const BYTE* srcbyte; - WORD* dstpixel; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 5) & 0x07e0) | /* g1 */ - ((srcval1 >> 19) & 0x001f); /* h1 */ - srcval2=srcpixel[1]; - dstpixel[1]=((srcval1 >> 16) & 0xf800) | /* l2 */ - ((srcval2 << 3) & 0x07e0) | /* g2 */ - ((srcval2 >> 11) & 0x001f); /* h2 */ - srcval1=srcpixel[2]; - dstpixel[2]=((srcval2 >> 8) & 0xf800) | /* l3 */ - ((srcval2 >> 21) & 0x07e0) | /* g3 */ - ((srcval1 >> 3) & 0x001f); /* h3 */ - dstpixel[3]=(srcval1 & 0xf800) | /* l4 */ - ((srcval1 >> 13) & 0x07e0) | /* g4 */ - ((srcval1 >> 27) & 0x001f); /* h4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - srcbyte=(const BYTE*)srcpixel; - for (x=0; x> 3) & 0x001f); /* h */ - *dstpixel++=dstval; - srcbyte+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_0888_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - int w1, w2, w3; - - w1 = min( (INT_PTR)srcbits & 3, width); - w2 = ( width - w1) / 4; - w3 = ( width - w1) & 3; - for (y=0; y> 8); /* h4, g4, l4 */ - if( --x) { - dstpixel[ -2] = ( srcpixel[ -2] >> 16) | /* g3, l3 */ - ((srcpixel[ -1] << 16) & 0x00ff0000); /* h3 */ - if( --x) { - dstpixel[ -3] = ( srcpixel[ -3] >> 24) | /* l2 */ - ((srcpixel[ -2] << 8) & 0x00ffff00); /* h2, g2 */ - } - } - } - for (x=0; x < w2; x++) { - /* Do 4 pixels at a time: 3 dwords in and 4 dwords out */ - DWORD srcval1,srcval2; - srcval1=srcpixel[0]; - dstpixel[0]=( srcval1 & 0x00ffffff); /* h1, g1, l1 */ - srcval2=srcpixel[1]; - dstpixel[1]=( srcval1 >> 24) | /* l2 */ - ((srcval2 << 8) & 0x00ffff00); /* h2, g2 */ - srcval1=srcpixel[2]; - dstpixel[2]=( srcval2 >> 16) | /* g3, l3 */ - ((srcval1 << 16) & 0x00ff0000); /* h3 */ - dstpixel[3]=( srcval1 >> 8); /* h4, g4, l4 */ - srcpixel+=3; - dstpixel+=4; - } - /* do last w3 pixels */ - x = w3; - if( x) { - dstpixel[0]=( srcpixel[0] & 0x00ffffff); /* h1, g1, l1 */ - if( --x) { - dstpixel[1]=( srcpixel[0]>> 24) | /* l2 */ - ((srcpixel[1]<< 8) & 0x00ffff00); /* h2, g2 */ - if( --x) { - dstpixel[2]=( srcpixel[1]>> 16) | /* g3, l3 */ - ((srcpixel[2]<< 16) & 0x00ff0000); /* h3 */ - } - } - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_0888_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - int w1, w2, w3; - - w1 = min( (INT_PTR)srcbits & 3, width); - w2 = ( width - w1) / 4; - w3 = ( width - w1) & 3; - for (y=0; y> 24) & 0x0000ff) | /* h4 */ - ((srcpixel[ -1] >> 8) & 0x00ff00) | /* g4 */ - ((srcpixel[ -1] << 8) & 0xff0000); /* l4 */ - if( --x) { - dstpixel[ -2]=( srcpixel[ -2] & 0xff0000) | /* l3 */ - ((srcpixel[ -2] >> 16) & 0x00ff00) | /* g3 */ - ( srcpixel[ -1] & 0x0000ff); /* h3 */ - if( --x) { - dstpixel[ -3]=((srcpixel[ -3] >> 8) & 0xff0000) | /* l2 */ - ((srcpixel[ -2] << 8) & 0x00ff00) | /* g2 */ - ((srcpixel[ -2] >> 8) & 0x0000ff); /* h2 */ - } - } - } - for (x=0; x < w2; x++) { - /* Do 4 pixels at a time: 3 dwords in and 4 dwords out */ - DWORD srcval1,srcval2; - - srcval1=srcpixel[0]; - dstpixel[0]=((srcval1 >> 16) & 0x0000ff) | /* h1 */ - ( srcval1 & 0x00ff00) | /* g1 */ - ((srcval1 << 16) & 0xff0000); /* l1 */ - srcval2=srcpixel[1]; - dstpixel[1]=((srcval1 >> 8) & 0xff0000) | /* l2 */ - ((srcval2 << 8) & 0x00ff00) | /* g2 */ - ((srcval2 >> 8) & 0x0000ff); /* h2 */ - srcval1=srcpixel[2]; - dstpixel[2]=( srcval2 & 0xff0000) | /* l3 */ - ((srcval2 >> 16) & 0x00ff00) | /* g3 */ - ( srcval1 & 0x0000ff); /* h3 */ - dstpixel[3]=((srcval1 >> 24) & 0x0000ff) | /* h4 */ - ((srcval1 >> 8) & 0x00ff00) | /* g4 */ - ((srcval1 << 8) & 0xff0000); /* l4 */ - srcpixel+=3; - dstpixel+=4; - } - /* do last w3 pixels */ - x = w3; - if( x) { - dstpixel[0]=((srcpixel[0] >> 16) & 0x0000ff) | /* h1 */ - ( srcpixel[0] & 0x00ff00) | /* g1 */ - ((srcpixel[0] << 16) & 0xff0000); /* l1 */ - if( --x) { - dstpixel[1]=((srcpixel[0] >> 8) & 0xff0000) | /* l2 */ - ((srcpixel[1] << 8) & 0x00ff00) | /* g2 */ - ((srcpixel[1] >> 8) & 0x0000ff); /* h2 */ - if( --x) { - dstpixel[2]=( srcpixel[1] & 0xff0000) | /* l3 */ - ((srcpixel[1] >> 16) & 0x00ff00) | /* g3 */ - ( srcpixel[2] & 0x0000ff); /* h3 */ - } - } - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_rgb888_to_any0888(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes, - DWORD rdst, DWORD gdst, DWORD bdst) -{ - int rLeftShift,gLeftShift,bLeftShift; - const BYTE* srcpixel; - DWORD* dstpixel; - int x,y; - - rLeftShift=X11DRV_DIB_MaskToShift(rdst); - gLeftShift=X11DRV_DIB_MaskToShift(gdst); - bLeftShift=X11DRV_DIB_MaskToShift(bdst); - for (y=0; y> 16) & 0x000000ff); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_any(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes, - DWORD rdst, DWORD gdst, DWORD bdst) -{ - int rRightShift,gRightShift,bRightShift; - int rLeftShift,gLeftShift,bLeftShift; - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - rRightShift=X11DRV_DIB_MaskToShift(rsrc); - gRightShift=X11DRV_DIB_MaskToShift(gsrc); - bRightShift=X11DRV_DIB_MaskToShift(bsrc); - rLeftShift=X11DRV_DIB_MaskToShift(rdst); - gLeftShift=X11DRV_DIB_MaskToShift(gdst); - bLeftShift=X11DRV_DIB_MaskToShift(bdst); - for (y=0; y> rRightShift) & 0xff) << rLeftShift) | - (((srcval >> gRightShift) & 0xff) << gLeftShift) | - (((srcval >> bRightShift) & 0xff) << bLeftShift); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_555_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - for (y=0; y> 9) & 0x7c00) | /* h */ - ((srcval >> 6) & 0x03e0) | /* g */ - ((srcval >> 3) & 0x001f); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_555_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - for (y=0; y> 19) & 0x001f) | /* h */ - ((srcval >> 6) & 0x03e0) | /* g */ - ((srcval << 7) & 0x7c00); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_565_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - for (y=0; y> 8) & 0xf800) | /* h */ - ((srcval >> 5) & 0x07e0) | /* g */ - ((srcval >> 3) & 0x001f); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_565_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - for (y=0; y> 19) & 0x001f) | /* h */ - ((srcval >> 5) & 0x07e0) | /* g */ - ((srcval << 8) & 0xf800); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_any0888_to_5x5(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes, - WORD rdst, WORD gdst, WORD bdst) -{ - int rRightShift,gRightShift,bRightShift; - int rLeftShift,gLeftShift,bLeftShift; - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - /* Here is how we proceed. Assume we have rsrc=0x0000ff00 and our pixel - * contains 0x11223344. - * - first we shift 0x11223344 right by rRightShift to bring the most - * significant bits of the red components in the bottom 5 (or 6) bits - * -> 0x4488c - * - then we remove non red bits by anding with the modified rdst (0x1f) - * -> 0x0c - * - finally shift these bits left by rLeftShift so that they end up in - * the right place - * -> 0x3000 - */ - rRightShift=X11DRV_DIB_MaskToShift(rsrc)+3; - gRightShift=X11DRV_DIB_MaskToShift(gsrc); - gRightShift+=(gdst==0x07e0?2:3); - bRightShift=X11DRV_DIB_MaskToShift(bsrc)+3; - - rLeftShift=X11DRV_DIB_MaskToShift(rdst); - rdst=rdst >> rLeftShift; - gLeftShift=X11DRV_DIB_MaskToShift(gdst); - gdst=gdst >> gLeftShift; - bLeftShift=X11DRV_DIB_MaskToShift(bdst); - bdst=bdst >> bLeftShift; - - for (y=0; y> rRightShift) & rdst) << rLeftShift) | - (((srcval >> gRightShift) & gdst) << gLeftShift) | - (((srcval >> bRightShift) & bdst) << bLeftShift); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_888_asis(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - BYTE* dstbyte; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 8 ) & 0x0000ffff); /* g2, l2 */ - *dstpixel++=srcval | ((*srcpixel) << 16); /* h3, g3 */ - srcval=((*srcpixel++ >> 16) & 0x000000ff); /* l3 */ - *dstpixel++=srcval | ((*srcpixel++) << 8); /* h4, g4, l4 */ - } - /* And now up to 3 odd pixels */ - dstbyte=(BYTE*)dstpixel; - for (x=0; x> 16; /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_888_reverse(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - BYTE* dstbyte; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 16) & 0x000000ff) | /* h1 */ - ( srcval1 & 0x0000ff00) | /* g1 */ - ((srcval1 << 16) & 0x00ff0000); /* l1 */ - srcval1=*srcpixel++; - *dstpixel++=srcval2 | - ((srcval1 << 8) & 0xff000000); /* h2 */ - srcval2= ((srcval1 >> 8) & 0x000000ff) | /* g2 */ - ((srcval1 << 8) & 0x0000ff00); /* l2 */ - srcval1=*srcpixel++; - *dstpixel++=srcval2 | - ( srcval1 & 0x00ff0000) | /* h3 */ - ((srcval1 << 16) & 0xff000000); /* g3 */ - srcval2= ( srcval1 & 0x000000ff); /* l3 */ - srcval1=*srcpixel++; - *dstpixel++=srcval2 | - ((srcval1 >> 8) & 0x0000ff00) | /* h4 */ - ((srcval1 << 8) & 0x00ff0000) | /* g4 */ - ( srcval1 << 24); /* l4 */ - } - /* And now up to 3 odd pixels */ - dstbyte=(BYTE*)dstpixel; - for (x=0; x> 16) & 0x00ff) | /* h */ - (srcval & 0xff00); /* g */ - dstbyte += sizeof(WORD); - *dstbyte++=srcval; /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_any0888_to_rgb888(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes) -{ - int rRightShift,gRightShift,bRightShift; - const DWORD* srcpixel; - BYTE* dstpixel; - int x,y; - - rRightShift=X11DRV_DIB_MaskToShift(rsrc); - gRightShift=X11DRV_DIB_MaskToShift(gsrc); - bRightShift=X11DRV_DIB_MaskToShift(bsrc); - for (y=0; y> bRightShift); /* b */ - dstpixel[1]=(srcval >> gRightShift); /* g */ - dstpixel[2]=(srcval >> rRightShift); /* r */ - dstpixel+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_any0888_to_bgr888(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes) -{ - int rRightShift,gRightShift,bRightShift; - const DWORD* srcpixel; - BYTE* dstpixel; - int x,y; - - rRightShift=X11DRV_DIB_MaskToShift(rsrc); - gRightShift=X11DRV_DIB_MaskToShift(gsrc); - bRightShift=X11DRV_DIB_MaskToShift(bsrc); - for (y=0; y> rRightShift); /* r */ - dstpixel[1]=(srcval >> gRightShift); /* g */ - dstpixel[2]=(srcval >> bRightShift); /* b */ - dstpixel+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -const dib_conversions dib_normal = { - convert_5x5_asis, - convert_555_reverse, - convert_555_to_565_asis, - convert_555_to_565_reverse, - convert_555_to_888_asis, - convert_555_to_888_reverse, - convert_555_to_0888_asis, - convert_555_to_0888_reverse, - convert_5x5_to_any0888, - convert_565_reverse, - convert_565_to_555_asis, - convert_565_to_555_reverse, - convert_565_to_888_asis, - convert_565_to_888_reverse, - convert_565_to_0888_asis, - convert_565_to_0888_reverse, - convert_888_asis, - convert_888_reverse, - convert_888_to_555_asis, - convert_888_to_555_reverse, - convert_888_to_565_asis, - convert_888_to_565_reverse, - convert_888_to_0888_asis, - convert_888_to_0888_reverse, - convert_rgb888_to_any0888, - convert_bgr888_to_any0888, - convert_0888_asis, - convert_0888_reverse, - convert_0888_any, - convert_0888_to_555_asis, - convert_0888_to_555_reverse, - convert_0888_to_565_asis, - convert_0888_to_565_reverse, - convert_any0888_to_5x5, - convert_0888_to_888_asis, - convert_0888_to_888_reverse, - convert_any0888_to_rgb888, - convert_any0888_to_bgr888 -}; diff --git a/dlls/winex11.drv/dib_dst_swap.c b/dlls/winex11.drv/dib_dst_swap.c deleted file mode 100644 index b81f48c26d8..00000000000 --- a/dlls/winex11.drv/dib_dst_swap.c +++ /dev/null @@ -1,1569 +0,0 @@ -/* - * DIB conversion routines for cases where the destination - * has non-native byte order. - * - * Copyright (C) 2003 Huw Davies - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include "config.h" - -#include - -#include "windef.h" -#include "x11drv.h" - -#define FLIP_WORD(x) \ - ( *(x) = ( (*(x) & 0xff) << 8) | \ - ( (*(x) & 0xff00) >> 8) ) - -#define FLIP_TWO_WORDS(x) \ - ( *(x) = ( (*(x) & 0x00ff00ff) << 8) | \ - ( (*(x) & 0xff00ff00) >> 8) ) - -#define FLIP_DWORD(x) \ - ( *(x) = ( (*(x) & 0xff) << 24) | \ - ( (*(x) & 0xff00) << 8) | \ - ( (*(x) & 0xff0000) >> 8) | \ - ( (*(x) & 0xff000000) >> 24) ) - - -/* - * 15 bit conversions - */ - -static void convert_5x5_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - int x, y; - const DWORD *srcpixel; - DWORD *dstpixel; - - for (y=0; y> 8) & 0x00ff00ff); - } - if(width&1) { - /* And the odd pixel */ - WORD srcval = *(const WORD*)srcpixel; - *(WORD*)dstpixel = ((srcval << 8) & 0xff00) | - ((srcval >> 8) & 0x00ff); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 2) & 0x1f001f00) | /* h */ - ((srcval >> 8) & 0x00030003) | /* g - 2 bits */ - ((srcval << 8) & 0xe000e000) | /* g - 3 bits */ - ((srcval << 2) & 0x007c007c); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval >> 2) & 0x1f00) | /* h */ - ((srcval >> 8) & 0x0003) | /* g - 2 bits */ - ((srcval << 8) & 0xe000) | /* g - 3 bits */ - ((srcval << 2) & 0x007c); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_565_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 7) & 0x00ff00ff) | /* h, g - 3 bits */ - ((srcval << 9) & 0xc000c000) | /* g - 2 bits */ - ((srcval << 4) & 0x20002000) | /* g - 1 bits */ - ((srcval << 8) & 0x1f001f00); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval >> 7) & 0x00ff) | /* h, g - 3 bits */ - ((srcval << 9) & 0xc000) | /* g - 2 bits */ - ((srcval << 4) & 0x2000) | /* g - 1 bit */ - ((srcval << 8) & 0x1f00); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_565_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 2) & 0x1f001f00) | /* h */ - ((srcval >> 7) & 0x00070007) | /* g - 3 bits */ - ((srcval << 9) & 0xc000c000) | /* g - 2 bits */ - ((srcval << 4) & 0x20002000) | /* g - 1 bit */ - ((srcval << 3) & 0x00f800f8); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval >> 2) & 0x1f00) | /* h */ - ((srcval >> 7) & 0x0007) | /* g - 3 bits */ - ((srcval << 9) & 0xc000) | /* g - 2 bits */ - ((srcval << 4) & 0x2000) | /* g - 1 bit */ - ((srcval << 3) & 0x00f8); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_888_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 4) & 0x00070000) | /* h1 - 3 bits */ - ((srcval2 << 3) & 0x000000f8) | /* l2 */ - ((srcval2 >> 2) & 0x00000007); /* l2 - 3 bits */ - srcval1=(DWORD)*srcpixel++; - *dstpixel++= ((srcval2 << 22) & 0xf8000000) | /* g2 */ - ((srcval2 << 17) & 0x07000000) | /* g2 - 3 bits */ - ((srcval2 << 9) & 0x00f80000) | /* h2 */ - ((srcval2 << 4) & 0x00070000) | /* h2 - 3 bits */ - ((srcval1 << 11) & 0x0000f800) | /* l3 */ - ((srcval1 << 6) & 0x00000700) | /* l3 - 3 bits */ - ((srcval1 >> 2) & 0x000000f8) | /* g3 */ - ((srcval1 >> 7) & 0x00000007); /* g3 - 3 bits */ - srcval2=(DWORD)*srcpixel++; - *dstpixel++= ((srcval1 << 17) & 0xf8000000) | /* h3 */ - ((srcval1 << 12) & 0x07000000) | /* h3 - 3 bits */ - ((srcval2 << 19) & 0x00f80000) | /* l4 */ - ((srcval2 << 14) & 0x00070000) | /* l4 - 3 bits */ - ((srcval2 << 6) & 0x0000f800) | /* g4 */ - ((srcval2 << 1) & 0x00000700) | /* g4 - 3 bits */ - ((srcval2 >> 7) & 0x000000f8) | /* h4 */ - ((srcval2 >> 12) & 0x00000007); /* h4 - 3 bits */ - } - if(width&3) { - BYTE *dstbyte = (BYTE*)dstpixel; - DWORD srcval; - for(x = 0; x < (width&3); x++) { - srcval = *srcpixel++; - dstbyte[0] = ((srcval << 3) & 0xf8) | ((srcval >> 2) & 0x07); - dstbyte[1] = ((srcval >> 2) & 0xf8) | ((srcval >> 7) & 0x07); - dstbyte[2] = ((srcval >> 7) & 0xf8) | ((srcval >> 12) & 0x07); - dstbyte+=3; - if(x > 0) - FLIP_DWORD(dstpixel + x - 1); - } - FLIP_DWORD(dstpixel + x - 1); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_888_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 7) & 0x000000f8) | /* h2 */ - ((srcval2 >> 12) & 0x00000007); /* h2 - 3 bits */ - srcval1=(DWORD)*srcpixel++; - *dstpixel++= ((srcval2 << 22) & 0xf8000000) | /* g2 */ - ((srcval2 << 17) & 0x07000000) | /* g2 - 3 bits */ - ((srcval2 << 19) & 0x00f80000) | /* l2 */ - ((srcval2 << 14) & 0x00070000) | /* l2 - 3 bits */ - ((srcval1 << 1) & 0x0000f800) | /* h3 */ - ((srcval1 >> 4) & 0x00000700) | /* h3 - 3 bits */ - ((srcval1 >> 2) & 0x000000f8) | /* g3 */ - ((srcval1 >> 7) & 0x00000007); /* g3 - 3 bits */ - srcval2=(DWORD)*srcpixel++; - *dstpixel++= ((srcval1 << 27) & 0xf8000000) | /* l3 */ - ((srcval1 << 22) & 0x07000000) | /* l3 - 3 bits */ - ((srcval2 << 9) & 0x00f80000) | /* h4 */ - ((srcval2 << 4) & 0x00070000) | /* h4 - 3 bits */ - ((srcval2 << 6) & 0x0000f800) | /* g4 */ - ((srcval2 << 1) & 0x00000700) | /* g4 - 3 bits */ - ((srcval2 << 3) & 0x000000f8) | /* l4 */ - ((srcval2 >> 2) & 0x00000007); /* l4 - 3 bits */ - } - if(width&3) { - BYTE *dstbyte = (BYTE*)dstpixel; - DWORD srcval; - for(x = 0; x < (width&3); x++) { - srcval = *srcpixel++; - dstbyte[2] = ((srcval << 3) & 0xf8) | ((srcval >> 2) & 0x07); - dstbyte[1] = ((srcval >> 2) & 0xf8) | ((srcval >> 7) & 0x07); - dstbyte[0] = ((srcval >> 7) & 0xf8) | ((srcval >> 12) & 0x07); - dstbyte+=3; - if(x > 0) - FLIP_DWORD(dstpixel + x - 1); - } - FLIP_DWORD(dstpixel + x - 1); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_0888_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 4) & 0x00000700) | /* h - 3 bits */ - ((srcval << 14) & 0x00f80000) | /* g */ - ((srcval << 9) & 0x00070000) | /* g - 3 bits */ - ((srcval << 27) & 0xf8000000) | /* l */ - ((srcval << 22) & 0x07000000); /* l - 3 bits */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_0888_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> rRightShift1) & 0xf8) | - ((srcval >> rRightShift2) & 0x07); - green=((srcval >> gRightShift1) & gMask1) | - ((srcval >> gRightShift2) & gMask2); - blue= ((srcval >> bRightShift1) & 0xf8) | - ((srcval >> bRightShift2) & 0x07); - *dstpixel =(red << rLeftShift) | - (green << gLeftShift) | - (blue << bLeftShift); - FLIP_DWORD(dstpixel); - dstpixel++; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -/* - * 16 bits conversions - */ - -static void convert_565_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 3) & 0x1f001f00) | /* h */ - ((srcval >> 8) & 0x00070007) | /* g - 3 bits */ - ((srcval << 8) & 0xe000e000) | /* g - 3 bits */ - ((srcval << 3) & 0x00f800f8); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval >> 3) & 0x1f00) | /* h */ - ((srcval >> 8) & 0x0007) | /* g - 3 bits */ - ((srcval << 8) & 0xe000) | /* g - 3 bits */ - ((srcval << 3) & 0x00f8); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_555_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 9) & 0x007f007f); /* h, g - 2 bits */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval << 7) & 0xe000) | /* g - 3 bits*/ - ((srcval << 8) & 0x1f00) | /* l */ - ((srcval >> 9) & 0x007f); /* h, g - 2 bits */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_555_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 3) & 0x1f001f00) | /* l */ - ((srcval << 2) & 0x007c007c) | /* h */ - ((srcval >> 9) & 0x00030003); /* g - 2 bits */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval << 7) & 0xe000) | /* g - 3 bits */ - ((srcval >> 3) & 0x1f00) | /* l */ - ((srcval << 2) & 0x007c) | /* h */ - ((srcval >> 9) & 0x0003); /* g - 2 bits */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_888_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 5) & 0x00070000) | /* h1 - 3 bits */ - ((srcval2 << 3) & 0x000000f8) | /* l2 */ - ((srcval2 >> 2) & 0x00000007); /* l2 - 3 bits */ - srcval1=(DWORD)*srcpixel++; - *dstpixel++= ((srcval2 << 21) & 0xfc000000) | /* g2 */ - ((srcval2 << 15) & 0x03000000) | /* g2 - 2 bits */ - ((srcval2 << 8) & 0x00f80000) | /* h2 */ - ((srcval2 << 3) & 0x00070000) | /* h2 - 3 bits */ - ((srcval1 << 11) & 0x0000f800) | /* l3 */ - ((srcval1 << 6) & 0x00000700) | /* l3 - 3 bits */ - ((srcval1 >> 3) & 0x000000fc) | /* g3 */ - ((srcval1 >> 9) & 0x00000003); /* g3 - 2 bits */ - srcval2=(DWORD)*srcpixel++; - *dstpixel++= ((srcval1 << 16) & 0xf8000000) | /* h3 */ - ((srcval1 << 11) & 0x07000000) | /* h3 - 3 bits */ - ((srcval2 << 19) & 0x00f80000) | /* l4 */ - ((srcval2 << 14) & 0x00070000) | /* l4 - 3 bits */ - ((srcval2 << 5) & 0x0000fc00) | /* g4 */ - ((srcval2 >> 1) & 0x00000300) | /* g4 - 2 bits */ - ((srcval2 >> 8) & 0x000000f8) | /* h4 */ - ((srcval2 >> 13) & 0x00000007); /* h4 - 3 bits */ - } - if(width&3) { - BYTE *dstbyte = (BYTE*)dstpixel; - DWORD srcval; - for(x = 0; x < (width&3); x++) { - srcval = *srcpixel++; - dstbyte[0] = ((srcval << 3) & 0xf8) | ((srcval >> 2) & 0x07); - dstbyte[1] = ((srcval >> 3) & 0xfc) | ((srcval >> 9) & 0x03); - dstbyte[2] = ((srcval >> 8) & 0xf8) | ((srcval >> 13) & 0x07); - dstbyte+=3; - if(x > 0) - FLIP_DWORD(dstpixel + x - 1); - } - FLIP_DWORD(dstpixel + x - 1); - } - - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_888_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 8) & 0x000000f8) | /* h2 */ - ((srcval2 >> 13) & 0x00000007); /* h2 - 3 bits */ - srcval1=(DWORD)*srcpixel++; - *dstpixel++= ((srcval2 << 21) & 0xfc000000) | /* g2 */ - ((srcval2 << 15) & 0x03000000) | /* g2 - 2 bits */ - ((srcval2 << 19) & 0x00f80000) | /* l2 */ - ((srcval2 << 14) & 0x00070000) | /* l2 - 3 bits */ - ((srcval1 << 0) & 0x0000f800) | /* h3 */ - ((srcval1 >> 5) & 0x00000700) | /* h3 - 3 bits */ - ((srcval1 >> 3) & 0x000000fc) | /* g3 */ - ((srcval1 >> 9) & 0x00000003); /* g3 - 2 bits */ - srcval2=(DWORD)*srcpixel++; - *dstpixel++= ((srcval1 << 27) & 0xf8000000) | /* l3 */ - ((srcval1 << 22) & 0x07000000) | /* l3 - 3 bits */ - ((srcval2 << 8) & 0x00f80000) | /* h4 */ - ((srcval2 << 3) & 0x00070000) | /* h4 - 3 bits */ - ((srcval2 << 5) & 0x0000fc00) | /* g4 */ - ((srcval2 >> 1) & 0x00000700) | /* g4 - 2 bits */ - ((srcval2 << 3) & 0x000000f8) | /* l4 */ - ((srcval2 >> 2) & 0x00000007); /* l4 - 3 bits */ - } - if(width&3) { - BYTE *dstbyte = (BYTE*)dstpixel; - DWORD srcval; - for(x = 0; x < (width&3); x++) { - srcval = *srcpixel++; - dstbyte[2] = ((srcval << 3) & 0xf8) | ((srcval >> 2) & 0x07); - dstbyte[1] = ((srcval >> 3) & 0xfc) | ((srcval >> 9) & 0x03); - dstbyte[0] = ((srcval >> 8) & 0xf8) | ((srcval >> 13) & 0x07); - dstbyte+=3; - if(x > 0) - FLIP_DWORD(dstpixel + x - 1); - } - FLIP_DWORD(dstpixel + x - 1); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_0888_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 5) & 0x00000700) | /* h - 3 bits */ - ((srcval << 13) & 0x00fc0000) | /* g */ - ((srcval << 7) & 0x00030000) | /* g - 2 bits */ - ((srcval << 27) & 0xf8000000) | /* l */ - ((srcval << 22) & 0x07000000); /* l - 3 bits */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_0888_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 8) & 0x0000ff00) | - ((srcval >> 24) & 0x000000ff); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 8) & 0x000000ff); /* h2 */ - *dstpixel++=((srcpixel[1] << 24) & 0xff000000) | /* g2 */ - ((srcpixel[0] >> 8) & 0x00ff0000) | /* l2 */ - ((srcpixel[2] << 8) & 0x0000ff00) | /* h3 */ - ((srcpixel[0] >> 24) & 0x000000ff); /* g3 */ - *dstpixel++=((srcpixel[1] << 8) & 0xff000000) | /* l3 */ - ((srcpixel[2] >> 8) & 0x00ffffff); /* h4, g4, l4 */ - srcpixel+=3; - } - if(width&3) { - BYTE *dstbyte = (BYTE*)dstpixel; - const BYTE *srcbyte = (const BYTE*)srcpixel; - for(x = 0; x < (width&3); x++) { - dstbyte[2] = srcbyte[0]; - dstbyte[1] = srcbyte[1]; - dstbyte[0] = srcbyte[2]; - dstbyte+=3; - srcbyte+=3; - if(x > 0) - FLIP_DWORD(dstpixel + x - 1); - } - FLIP_DWORD(dstpixel + x - 1); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_555_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - const BYTE* srcbyte; - WORD* dstpixel; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 14) & 0x0003) | /* g1 - 2 bits */ - ((srcval1 << 2) & 0xe000) | /* g1 - 3 bits */ - ((srcval1 >> 17) & 0x007c); /* h1 */ - srcval2=srcpixel[1]; - dstpixel[1]=((srcval1 >> 19) & 0x1f00) | /* l2 */ - ((srcval2 >> 6) & 0x0003) | /* g2 - 2 bits */ - ((srcval2 << 10) & 0xe000) | /* g2 - 3 bits */ - ((srcval2 >> 9) & 0x007c); /* h2 */ - srcval1=srcpixel[2]; - dstpixel[2]=((srcval2 >> 11) & 0x1f00) | /* l3 */ - ((srcval2 >> 30) & 0x0003) | /* g3 - 2 bits */ - ((srcval2 >> 14) & 0xe000) | /* g3 - 3 bits */ - ((srcval1 >> 1) & 0x007c); /* h3 */ - dstpixel[3]=((srcval1 >> 3) & 0x1f00) | /* l4 */ - ((srcval1 >> 22) & 0x0003) | /* g4 - 2 bits */ - ((srcval1 >> 6) & 0xe000) | /* g4 - 3 bits */ - ((srcval1 >> 17) & 0x007c); /* h4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - srcbyte=(const BYTE*)srcpixel; - for (x=0; x> 6) & 0x0003); /* g - 2 bits */ - dstval|=((srcbyte[1] << 10) & 0xe000); /* g - 3 bits */ - dstval|=((srcbyte[2] >> 1) & 0x007c); /* h */ - *dstpixel++=dstval; - srcbyte+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_555_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - const BYTE* srcbyte; - WORD* dstpixel; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 1) & 0x007c) | /* l1 */ - ((srcval1 >> 14) & 0x0003) | /* g1 - 2 bits */ - ((srcval1 << 2) & 0xe000) | /* g1 - 3 bits */ - ((srcval1 >> 11) & 0x1f00); /* h1 */ - srcval2=srcpixel[1]; - dstpixel[1]=((srcval1 >> 25) & 0x007c) | /* l2 */ - ((srcval2 >> 6) & 0x0003) | /* g2 - 2 bits */ - ((srcval2 << 10) & 0xe000) | /* g2 - 3 bits */ - ((srcval2 >> 3) & 0x1f00); /* h2 */ - srcval1=srcpixel[2]; - dstpixel[2]=((srcval2 >> 17) & 0x007c) | /* l3 */ - ((srcval2 >> 30) & 0x0003) | /* g3 - 2 bits */ - ((srcval2 >> 14) & 0xe000) | /* g3 - 3 bits */ - ((srcval1 << 5) & 0x1f00); /* h3 */ - dstpixel[3]=((srcval1 >> 9) & 0x007c) | /* l4 */ - ((srcval1 >> 22) & 0x0003) | /* g4 - 2 bits */ - ((srcval1 >> 6) & 0xe000) | /* g4 - 3 bits */ - ((srcval1 >> 19) & 0x1f00); /* h4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - srcbyte=(const BYTE*)srcpixel; - for (x=0; x> 1) & 0x007c); /* l */ - dstval|=((srcbyte[1] >> 6) & 0x0003); /* g - 2 bits */ - dstval|=((srcbyte[1] << 10) & 0xe000); /* g - 3 bits */ - dstval|=((srcbyte[2] << 5) & 0x1f00); /* h */ - FLIP_WORD(&dstval); - *dstpixel++=dstval; - srcbyte+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_565_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - const BYTE* srcbyte; - WORD* dstpixel; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 13) & 0x0007) | /* g1 - 3 bits */ - ((srcval1 << 3) & 0xe000) | /* g1 - 3 bits */ - ((srcval1 >> 16) & 0x00f8); /* h1 */ - srcval2=srcpixel[1]; - dstpixel[1]=((srcval1 >> 19) & 0x1f00) | /* l2 */ - ((srcval2 >> 5) & 0x0007) | /* g2 - 3 bits */ - ((srcval2 << 11) & 0xe000) | /* g2 - 3 bits */ - ((srcval2 >> 8) & 0x00f8); /* h2 */ - srcval1=srcpixel[2]; - dstpixel[2]=((srcval2 >> 11) & 0x1f00) | /* l3 */ - ((srcval2 >> 29) & 0x0007) | /* g3 - 3 bits */ - ((srcval2 >> 13) & 0xe000) | /* g3 - 3 bits */ - ((srcval1 << 0) & 0x00f8); /* h3 */ - dstpixel[3]=((srcval1 >> 3) & 0x1f00) | /* l4 */ - ((srcval1 >> 21) & 0x0007) | /* g4 - 3 bits */ - ((srcval1 >> 5) & 0xe000) | /* g4 - 3 bits */ - ((srcval1 >> 24) & 0x00f8); /* h4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - srcbyte=(const BYTE*)srcpixel; - for (x=0; x> 5) & 0x0007); /* g - 3 bits */ - dstval|=((srcbyte[1] << 11) & 0xe000); /* g - 3 bits */ - dstval|=((srcbyte[2] << 0) & 0x00f8); /* h */ - *dstpixel++=dstval; - srcbyte+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_565_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - const BYTE* srcbyte; - WORD* dstpixel; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 0) & 0x00f8) | /* l1 */ - ((srcval1 >> 13) & 0x0007) | /* g1 - 3 bits */ - ((srcval1 << 3) & 0xe000) | /* g1 - 3 bits */ - ((srcval1 >> 11) & 0x1f00); /* h1 */ - srcval2=srcpixel[1]; - dstpixel[1]=((srcval1 >> 24) & 0x00f8) | /* l2 */ - ((srcval2 >> 5) & 0x0007) | /* g2 - 3 bits */ - ((srcval2 << 11) & 0xe000) | /* g2 - 3 bits */ - ((srcval2 >> 3) & 0x1f00); /* h2 */ - srcval1=srcpixel[2]; - dstpixel[2]=((srcval2 >> 16) & 0x00f8) | /* l3 */ - ((srcval2 >> 29) & 0x0007) | /* g3 - 3 bits */ - ((srcval2 >> 13) & 0xe000) | /* g3 - 3 bits */ - ((srcval1 << 5) & 0x1f00); /* h3 */ - dstpixel[3]=((srcval1 >> 8) & 0x00f8) | /* l4 */ - ((srcval1 >> 21) & 0x0007) | /* g4 - 3 bits */ - ((srcval1 >> 5) & 0xe000) | /* g4 - 3 bits */ - ((srcval1 >> 19) & 0x1f00); /* h4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - srcbyte=(const BYTE*)srcpixel; - for (x=0; x> 5) & 0x0007); /* g - 3 bits */ - dstval|=((srcbyte[1] << 11) & 0xe000); /* g - 3 bits */ - dstval|=((srcbyte[2] << 5) & 0x1f00); /* h */ - *dstpixel++=dstval; - srcbyte+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_0888_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 8) & 0x0000ff00); /* h1 */ - srcval2=*srcpixel++; - *dstpixel++=((srcval1 << 0) & 0xff000000) | /* l2 */ - ((srcval2 << 16) & 0x00ff0000) | /* g2 */ - ((srcval2 << 0) & 0x0000ff00); /* h2 */ - srcval1=*srcpixel++; - *dstpixel++=((srcval2 << 8) & 0xff000000) | /* l3 */ - ((srcval2 >> 8) & 0x00ff0000) | /* g3 */ - ((srcval1 << 8) & 0x0000ff00); /* h3 */ - *dstpixel++=((srcval1 << 16) & 0xff000000) | /* l4 */ - ((srcval1 << 0) & 0x00ff0000) | /* g4 */ - ((srcval1 >> 16) & 0x0000ff00); /* h4 */ - } - /* And now up to 3 odd pixels */ - for (x=0; x> 8) & 0x0000ff00); /* h */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_0888_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 16) & 0x0000ff00); /* l2 */ - srcval1=*srcpixel++; - *dstpixel++=((srcval1 << 24) & 0xff000000) | /* h3 */ - ((srcval2 >> 8) & 0x00ffff00); /* g3, l3 */ - *dstpixel++=((srcval1 >> 0) & 0xffffff00); /* h4, g4, l4 */ - } - /* And now up to 3 odd pixels */ - for (x=0; x> 8) & 0x0000ff00) | - ((srcval >> 24) & 0x000000ff); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - - -static void convert_0888_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> rRightShift) & 0xff) << rLeftShift) | - (((srcval >> gRightShift) & 0xff) << gLeftShift) | - (((srcval >> bRightShift) & 0xff) << bLeftShift); - FLIP_DWORD(dstpixel); - dstpixel++; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_555_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - for (y=0; y> 17) & 0x007c) | /* h */ - ((srcval >> 14) & 0x0003) | /* g - 2 bits */ - ((srcval << 2) & 0xe000) | /* g - 3 bits */ - ((srcval << 5) & 0x1f00); /* l */ - dstpixel++; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_555_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - for (y=0; y> 11) & 0x1f00) | /* h */ - ((srcval >> 6) & 0x0003) | /* g - 2 bits */ - ((srcval << 2) & 0xe000) | /* g - 3 bits */ - ((srcval >> 1) & 0x7c00); /* l */ - dstpixel++; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_565_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - for (y=0; y> 16) & 0x00f8) | /* h */ - ((srcval >> 13) & 0x0007) | /* g - 3 bits */ - ((srcval << 3) & 0xe000) | /* g - 3 bits */ - ((srcval << 5) & 0x1f00); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_565_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - for (y=0; y> 11) & 0x1f00) | /* h */ - ((srcval >> 13) & 0x0007) | /* g - 3 bits */ - ((srcval << 3) & 0xe000) | /* g - 3 bits */ - ((srcval << 0) & 0x00f8); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_any0888_to_5x5_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes, - WORD rdst, WORD gdst, WORD bdst) -{ - int rRightShift,gRightShift,bRightShift; - int rLeftShift,gLeftShift,bLeftShift; - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - /* Here is how we proceed. Assume we have rsrc=0x0000ff00 and our pixel - * contains 0x11223344. - * - first we shift 0x11223344 right by rRightShift to bring the most - * significant bits of the red components in the bottom 5 (or 6) bits - * -> 0x4488c - * - then we remove non red bits by anding with the modified rdst (0x1f) - * -> 0x0c - * - finally shift these bits left by rLeftShift so that they end up in - * the right place - * -> 0x3000 - */ - rRightShift=X11DRV_DIB_MaskToShift(rsrc)+3; - gRightShift=X11DRV_DIB_MaskToShift(gsrc); - gRightShift+=(gdst==0x07e0?2:3); - bRightShift=X11DRV_DIB_MaskToShift(bsrc)+3; - - rLeftShift=X11DRV_DIB_MaskToShift(rdst); - rdst=rdst >> rLeftShift; - gLeftShift=X11DRV_DIB_MaskToShift(gdst); - gdst=gdst >> gLeftShift; - bLeftShift=X11DRV_DIB_MaskToShift(bdst); - bdst=bdst >> bLeftShift; - - for (y=0; y> rRightShift) & rdst) << rLeftShift) | - (((srcval >> gRightShift) & gdst) << gLeftShift) | - (((srcval >> bRightShift) & bdst) << bLeftShift); - FLIP_WORD(dstpixel); - dstpixel++; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_888_asis_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - width=width/4; - for (y=0; y> 8) & 0x0000ff00) | /* h1 */ - ((srcval2 >> 0) & 0x000000ff); /* l2 */ - srcval1=*srcpixel++; - *dstpixel++=((srcval2 << 16) & 0xff000000) | /* g2 */ - ((srcval2 << 0) & 0x00ff0000) | /* h2 */ - ((srcval1 << 8) & 0x0000ff00) | /* l3 */ - ((srcval1 >> 8) & 0x000000ff); /* g3 */ - srcval2=*srcpixel++; - *dstpixel++=((srcval1 << 8) & 0xff000000) | /* h3 */ - ((srcval2 << 16) & 0x00ff0000) | /* l4 */ - ((srcval2 << 0) & 0x0000ff00) | /* g4 */ - ((srcval2 >> 16) & 0x000000ff); /* h4 */ - } - /* And now up to 3 odd pixels */ - if(width&3) { - BYTE *dstbyte = (BYTE*)dstpixel; - const BYTE *srcbyte = (const BYTE*)srcpixel; - for(x = 0; x < (width&3); x++) { - dstbyte[0] = srcbyte[0]; - dstbyte[1] = srcbyte[1]; - dstbyte[2] = srcbyte[2]; - dstbyte+=3; - srcbyte+=4; - if(x > 0) - FLIP_DWORD(dstpixel + x - 1); - } - FLIP_DWORD(dstpixel + x - 1); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_888_reverse_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - width=width/4; - for (y=0; y> 16) & 0x000000ff); /* h2 */ - srcval1=*srcpixel++; - *dstpixel++=((srcval2 << 16) & 0xffff0000) | /* g2, l2 */ - ((srcval1 >> 8) & 0x0000ffff); /* h3, g3 */ - srcval2=*srcpixel++; - *dstpixel++=((srcval1 << 24) & 0xff000000) | /* l3 */ - ((srcval2 << 0) & 0x00ffffff); /* h4, g4, l4 */ - } - /* And now up to 3 odd pixels */ - if(width&3) { - BYTE *dstbyte = (BYTE*)dstpixel; - const BYTE *srcbyte = (const BYTE*)srcpixel; - for(x = 0; x < (width&3); x++) { - dstbyte[2] = srcbyte[0]; - dstbyte[1] = srcbyte[1]; - dstbyte[0] = srcbyte[2]; - dstbyte+=3; - srcbyte+=4; - if(x > 0) - FLIP_DWORD(dstpixel + x - 1); - } - FLIP_DWORD(dstpixel + x - 1); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_any0888_to_rgb888_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes) -{ - int rRightShift,gRightShift,bRightShift; - const DWORD* srcpixel; - BYTE* dstpixel; - int x,y; - - rRightShift=X11DRV_DIB_MaskToShift(rsrc); - gRightShift=X11DRV_DIB_MaskToShift(gsrc); - bRightShift=X11DRV_DIB_MaskToShift(bsrc); - for (y=0; y> bRightShift); /* b */ - dstpixel[1]=(srcval >> gRightShift); /* g */ - dstpixel[2]=(srcval >> rRightShift); /* r */ - if(x&3) - FLIP_DWORD((DWORD*)(dstpixel + x - 4)); - dstpixel+=3; - } - if(x&3) - FLIP_DWORD((DWORD*)(dstpixel + x - 4)); - - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_any0888_to_bgr888_dst_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes) -{ - int rRightShift,gRightShift,bRightShift; - const DWORD* srcpixel; - BYTE* dstpixel; - int x,y; - - rRightShift=X11DRV_DIB_MaskToShift(rsrc); - gRightShift=X11DRV_DIB_MaskToShift(gsrc); - bRightShift=X11DRV_DIB_MaskToShift(bsrc); - for (y=0; y> rRightShift); /* r */ - dstpixel[1]=(srcval >> gRightShift); /* g */ - dstpixel[2]=(srcval >> bRightShift); /* b */ - if(x&3) - FLIP_DWORD((DWORD*)(dstpixel + x - 4)); - dstpixel+=3; - } - if(x&3) - FLIP_DWORD((DWORD*)(dstpixel + x - 4)); - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -const dib_conversions dib_dst_byteswap = { - convert_5x5_asis_dst_byteswap, - convert_555_reverse_dst_byteswap, - convert_555_to_565_asis_dst_byteswap, - convert_555_to_565_reverse_dst_byteswap, - convert_555_to_888_asis_dst_byteswap, - convert_555_to_888_reverse_dst_byteswap, - convert_555_to_0888_asis_dst_byteswap, - convert_555_to_0888_reverse_dst_byteswap, - convert_5x5_to_any0888_dst_byteswap, - convert_565_reverse_dst_byteswap, - convert_565_to_555_asis_dst_byteswap, - convert_565_to_555_reverse_dst_byteswap, - convert_565_to_888_asis_dst_byteswap, - convert_565_to_888_reverse_dst_byteswap, - convert_565_to_0888_asis_dst_byteswap, - convert_565_to_0888_reverse_dst_byteswap, - convert_888_asis_dst_byteswap, - convert_888_reverse_dst_byteswap, - convert_888_to_555_asis_dst_byteswap, - convert_888_to_555_reverse_dst_byteswap, - convert_888_to_565_asis_dst_byteswap, - convert_888_to_565_reverse_dst_byteswap, - convert_888_to_0888_asis_dst_byteswap, - convert_888_to_0888_reverse_dst_byteswap, - convert_rgb888_to_any0888_dst_byteswap, - convert_bgr888_to_any0888_dst_byteswap, - convert_0888_asis_dst_byteswap, - convert_0888_reverse_dst_byteswap, - convert_0888_any_dst_byteswap, - convert_0888_to_555_asis_dst_byteswap, - convert_0888_to_555_reverse_dst_byteswap, - convert_0888_to_565_asis_dst_byteswap, - convert_0888_to_565_reverse_dst_byteswap, - convert_any0888_to_5x5_dst_byteswap, - convert_0888_to_888_asis_dst_byteswap, - convert_0888_to_888_reverse_dst_byteswap, - convert_any0888_to_rgb888_dst_byteswap, - convert_any0888_to_bgr888_dst_byteswap -}; diff --git a/dlls/winex11.drv/dib_src_swap.c b/dlls/winex11.drv/dib_src_swap.c deleted file mode 100644 index d260f98b5df..00000000000 --- a/dlls/winex11.drv/dib_src_swap.c +++ /dev/null @@ -1,1518 +0,0 @@ -/* - * DIB conversion routines for cases where the source - * has non-native byte order. - * - * Copyright (C) 2003 Huw Davies - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include "config.h" - -#include - -#include "windef.h" -#include "x11drv.h" - - -#define FLIP_WORD(x) \ - ( *(x) = ( (*(x) & 0xff) << 8) | \ - ( (*(x) & 0xff00) >> 8) ) - -#define FLIP_TWO_WORDS(x) \ - ( *(x) = ( (*(x) & 0x00ff00ff) << 8) | \ - ( (*(x) & 0xff00ff00) >> 8) ) - -#define FLIP_DWORD(x) \ - ( *(x) = ( (*(x) & 0xff) << 24) | \ - ( (*(x) & 0xff00) << 8) | \ - ( (*(x) & 0xff0000) >> 8) | \ - ( (*(x) & 0xff000000) >> 24) ) - - - -/* - * 15 bit conversions - */ - -static void convert_5x5_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - int x, y; - const DWORD *srcpixel; - DWORD *dstpixel; - - for (y=0; y> 8) & 0x00ff00ff); - } - if(width&1) { - /* And the odd pixel */ - WORD srcval = *(const WORD*)srcpixel; - *(WORD*)dstpixel = ((srcval << 8) & 0xff00) | - ((srcval >> 8) & 0x00ff); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 2) & 0x001f001f) | /* h */ - ((srcval << 8) & 0x03000300) | /* g - 2 bits */ - ((srcval >> 8) & 0x00e000e0) | /* g - 3 bits */ - ((srcval << 2) & 0x7c007c00); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval >> 2) & 0x001f) | /* h */ - ((srcval << 8) & 0x0300) | /* g - 2 bits */ - ((srcval >> 8) & 0x00e0) | /* g - 3 bits */ - ((srcval << 2) & 0x7c00); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_565_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 7) & 0x01c001c0) | /* g - 3 bits */ - ((srcval << 4) & 0x00200020) | /* g - 1 bit */ - ((srcval >> 8) & 0x001f001f); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval << 9) & 0xfe00) | /* h, g - 2bits*/ - ((srcval >> 7) & 0x01c0) | /* g - 3 bits */ - ((srcval << 4) & 0x0020) | /* g - 1 bit */ - ((srcval >> 8) & 0x001f); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_565_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 2) & 0x001f001f) | /* h */ - ((srcval << 9) & 0x06000600) | /* g - 2 bits*/ - ((srcval >> 7) & 0x01c001c0) | /* g - 3 bits */ - ((srcval << 4) & 0x00200020) | /* g - 1 bits */ - ((srcval << 3) & 0xf800f800); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval >> 2) & 0x001f) | /* h */ - ((srcval << 9) & 0x0600) | /* g - 2 bits */ - ((srcval >> 7) & 0x01c0) | /* g - 3 bits */ - ((srcval << 4) & 0x0020) | /* g - 1 bit */ - ((srcval << 3) & 0xf800); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_888_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - BYTE* dstpixel; - int x,y; - - for (y=0; y> 5) & 0xf8) | /* l */ - ((srcval >> 10) & 0x07); /* l - 3 bits */ - dstpixel[1]=((srcval << 6) & 0xc0) | /* g - 2 bits */ - ((srcval >> 10) & 0x38) | /* g - 3 bits */ - ((srcval << 1) & 0x06) | /* g - 2 bits */ - ((srcval >> 15) & 0x01); /* g - 1 bit */ - dstpixel[2]=((srcval << 1) & 0xf8) | /* h */ - ((srcval >> 4) & 0x07); /* h - 3 bits */ - dstpixel+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_888_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - BYTE* dstpixel; - int x,y; - - for (y=0; y> 4) & 0x07); /* h - 3 bits */ - dstpixel[1]=((srcval << 6) & 0xc0) | /* g - 2 bits */ - ((srcval >> 10) & 0x38) | /* g - 3 bits */ - ((srcval << 1) & 0x06) | /* g - 2 bits */ - ((srcval >> 15) & 0x01); /* g - 1 bits */ - dstpixel[2]=((srcval >> 5) & 0xf8) | /* l */ - ((srcval >> 10) & 0x07); /* l - 3 bits */ - dstpixel+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_0888_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 2) & 0x003800) | /* g - 3 bits */ - ((srcval << 9) & 0x000600) | /* g - 2 bits */ - ((srcval >> 7) & 0x000100) | /* g - 1 bit */ - ((srcval >> 5) & 0x0000f8) | /* l */ - ((srcval >> 10) & 0x000007); /* l - 3 bits */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_555_to_0888_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 4) & 0x000007) | /* h - 3 bits */ - ((srcval << 14) & 0x00c000) | /* g - 2 bits */ - ((srcval >> 2) & 0x003800) | /* g - 3 bits */ - ((srcval << 9) & 0x000600) | /* g - 2 bits */ - ((srcval >> 7) & 0x000100) | /* g - 1 bit */ - ((srcval << 11) & 0xf80000) | /* l */ - ((srcval << 6) & 0x070000); /* l - 3 bits */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_5x5_to_any0888_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - WORD rsrc, WORD gsrc, WORD bsrc, - void* dstbits, int dstlinebytes, - DWORD rdst, DWORD gdst, DWORD bdst) -{ - int rRightShift1,gRightShift1,bRightShift1; - int rRightShift2,gRightShift2,bRightShift2; - BYTE gMask1,gMask2; - int rLeftShift,gLeftShift,bLeftShift; - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - /* Note, the source pixel value is shifted left by 16 bits so that - * we know we will always have to shift right to extract the components. - */ - rRightShift1=16+X11DRV_DIB_MaskToShift(rsrc)-3; - gRightShift1=16+X11DRV_DIB_MaskToShift(gsrc)-3; - bRightShift1=16+X11DRV_DIB_MaskToShift(bsrc)-3; - rRightShift2=rRightShift1+5; - gRightShift2=gRightShift1+5; - bRightShift2=bRightShift1+5; - if (gsrc==0x03e0) { - /* Green has 5 bits, like the others */ - gMask1=0xf8; - gMask2=0x07; - } else { - /* Green has 6 bits, not 5. Compensate. */ - gRightShift1++; - gRightShift2+=2; - gMask1=0xfc; - gMask2=0x03; - } - - rLeftShift=X11DRV_DIB_MaskToShift(rdst); - gLeftShift=X11DRV_DIB_MaskToShift(gdst); - bLeftShift=X11DRV_DIB_MaskToShift(bdst); - - for (y=0; y> rRightShift1) & 0xf8) | - ((srcval >> rRightShift2) & 0x07); - green=((srcval >> gRightShift1) & gMask1) | - ((srcval >> gRightShift2) & gMask2); - blue= ((srcval >> bRightShift1) & 0xf8) | - ((srcval >> bRightShift2) & 0x07); - *dstpixel++=(red << rLeftShift) | - (green << gLeftShift) | - (blue << bLeftShift); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -/* - * 16 bits conversions - */ - -static void convert_565_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 8) & 0x00e000e0) | /* g - 3 bits */ - ((srcval >> 3) & 0x001f001f); /* h */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval << 3) & 0xf800) | /* l */ - ((srcval << 8) & 0x0700) | /* g - 3 bits */ - ((srcval >> 8) & 0x00e0) | /* g - 3 bits */ - ((srcval >> 3) & 0x001f); /* h */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_555_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 9) & 0x00600060) | /* g - 2 bits */ - ((srcval >> 8) & 0x001f001f); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval << 7) & 0x7f80) | /* h, g - 3 bits */ - ((srcval >> 9) & 0x0060) | /* g - 2 bits */ - ((srcval >> 8) & 0x001f); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_555_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 3) & 0x001f001f) | /* h */ - ((srcval >> 9) & 0x00600060) | /* g - 2 bits */ - ((srcval << 7) & 0x03800380) | /* g - 3 bits */ - ((srcval << 2) & 0x7c007c00); /* l */ - } - if (width&1) { - /* And then the odd pixel */ - WORD srcval; - srcval=*((const WORD*)srcpixel); - *((WORD*)dstpixel)=((srcval >> 3) & 0x001f) | /* h */ - ((srcval >> 9) & 0x0060) | /* g - 2 bits */ - ((srcval << 7) & 0x0380) | /* g - 3 bits */ - ((srcval << 2) & 0x7c00); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_888_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - BYTE* dstpixel; - int x,y; - - for (y=0; y> 5) & 0xf8) | /* l */ - ((srcval >> 10) & 0x07); /* l - 3 bits */ - dstpixel[1]=((srcval << 5) & 0xe0) | /* g - 3 bits */ - ((srcval >> 11) & 0x1c) | /* g - 3 bits */ - ((srcval >> 1) & 0x03); /* g - 2 bits */ - dstpixel[2]=((srcval >> 0) & 0xf8) | /* h */ - ((srcval >> 5) & 0x07); /* h - 3 bits */ - dstpixel+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_888_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - BYTE* dstpixel; - int x,y; - - for (y=0; y> 0) & 0xf8) | /* h */ - ((srcval >> 5) & 0x07); /* h - 3 bits */ - dstpixel[1]=((srcval << 5) & 0xe0) | /* g - 3 bits */ - ((srcval >> 11) & 0x1c) | /* g - 3 bits */ - ((srcval >> 1) & 0x03); /* g - 2 bits */ - dstpixel[2]=((srcval >> 5) & 0xf8) | /* l */ - ((srcval >> 10) & 0x07); /* l - 3 bits */ - dstpixel+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_0888_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 3) & 0x001c00) | /* g - 3 bits */ - ((srcval << 7) & 0x000300) | /* g - 2 bits */ - ((srcval >> 5) & 0x0000f8) | /* l */ - ((srcval >> 10) & 0x000007); /* l - 3 bits */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_565_to_0888_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const WORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 0) & 0x0000f8) | /* h */ - ((srcval >> 5) & 0x000007) | /* h - 3 bits */ - ((srcval << 13) & 0x00e000) | /* g - 3 bits */ - ((srcval >> 3) & 0x001c00) | /* g - 3 bits */ - ((srcval << 7) & 0x000300) | /* g - 2 bits */ - ((srcval << 11) & 0xf80000) | /* l */ - ((srcval << 6) & 0x070000); /* l - 3 bits */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -/* - * 24 bit conversions - */ - -static void convert_888_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - int x, y; - - for (y=0; y> 8) & 0x0000ff00) | - ((srcval >> 24) & 0x000000ff); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - DWORD srcarray[3]; - int x,y; - int oddwidth = width & 3; - - width = width/4; - - for (y=0; y> 8) & 0x00ffffff) | /* l1, g1, h1 */ - ((srcpixel[1] << 8) & 0xff000000); /* h2 */ - *dstpixel++= ((srcpixel[1] >> 24) & 0x000000ff) | /* g2 */ - ((srcpixel[0] << 8) & 0x0000ff00) | /* l2 */ - ((srcpixel[2] >> 8) & 0x00ff0000) | /* h3 */ - ((srcpixel[1] << 24) & 0xff000000); /* g3 */ - *dstpixel++= ((srcpixel[1] >> 8) & 0x000000ff) | /* l3 */ - ((srcpixel[2] << 8) & 0xffffff00); /* l4, g4, h4 */ - srcpixel+=3; - } - /* And now up to 3 odd pixels */ - if(oddwidth) { - BYTE *dstbyte, *srcbyte; - memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD)); - dstbyte = (LPBYTE)dstpixel; - srcbyte = (LPBYTE)srcarray; - for (x=0; x> 3) & 0x001f) | /* l1 */ - ((srcval1 >> 6) & 0x03e0) | /* g1 */ - ((srcval1 >> 9) & 0x7c00); /* h1 */ - srcval2=srcpixel[1]; - FLIP_DWORD(&srcval2); - dstpixel[1]=((srcval1 >> 27) & 0x001f) | /* l2 */ - ((srcval2 << 2) & 0x03e0) | /* g2 */ - ((srcval2 >> 1) & 0x7c00); /* h2 */ - srcval1=srcpixel[2]; - FLIP_DWORD(&srcval1); - dstpixel[2]=((srcval2 >> 19) & 0x001f) | /* l3 */ - ((srcval2 >> 22) & 0x03e0) | /* g3 */ - ((srcval1 << 7) & 0x7c00); /* h3 */ - dstpixel[3]=((srcval1 >> 11) & 0x001f) | /* l4 */ - ((srcval1 >> 14) & 0x03e0) | /* g4 */ - ((srcval1 >> 17) & 0x7c00); /* h4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - if(oddwidth) { - memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD)); - srcbyte = (LPBYTE)srcarray; - for (x=0; x> 3) & 0x001f); /* l */ - dstval|=((srcbyte[1] << 2) & 0x03e0); /* g */ - dstval|=((srcbyte[2] << 7) & 0x7c00); /* h */ - *dstpixel++=dstval; - srcbyte+=3; - } - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_555_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - const BYTE* srcbyte; - WORD* dstpixel; - DWORD srcarray[3]; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 6) & 0x03e0) | /* g1 */ - ((srcval1 >> 19) & 0x001f); /* h1 */ - srcval2=srcpixel[1]; - FLIP_DWORD(&srcval2); - dstpixel[1]=((srcval1 >> 17) & 0x7c00) | /* l2 */ - ((srcval2 << 2) & 0x03e0) | /* g2 */ - ((srcval2 >> 11) & 0x001f); /* h2 */ - srcval1=srcpixel[2]; - FLIP_DWORD(&srcval1); - dstpixel[2]=((srcval2 >> 9) & 0x7c00) | /* l3 */ - ((srcval2 >> 22) & 0x03e0) | /* g3 */ - ((srcval1 >> 3) & 0x001f); /* h3 */ - dstpixel[3]=((srcval1 >> 1) & 0x7c00) | /* l4 */ - ((srcval1 >> 14) & 0x03e0) | /* g4 */ - ((srcval1 >> 27) & 0x001f); /* h4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - if(oddwidth) { - memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD)); - srcbyte = (LPBYTE)srcarray; - for (x=0; x> 3) & 0x001f); /* h */ - *dstpixel++=dstval; - srcbyte+=3; - } - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_565_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - const BYTE* srcbyte; - WORD* dstpixel; - DWORD srcarray[3]; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 3) & 0x001f) | /* l1 */ - ((srcval1 >> 5) & 0x07e0) | /* g1 */ - ((srcval1 >> 8) & 0xf800); /* h1 */ - srcval2=srcpixel[1]; - FLIP_DWORD(&srcval2); - dstpixel[1]=((srcval1 >> 27) & 0x001f) | /* l2 */ - ((srcval2 << 3) & 0x07e0) | /* g2 */ - ( srcval2 & 0xf800); /* h2 */ - srcval1=srcpixel[2]; - FLIP_DWORD(&srcval1); - dstpixel[2]=((srcval2 >> 19) & 0x001f) | /* l3 */ - ((srcval2 >> 21) & 0x07e0) | /* g3 */ - ((srcval1 << 8) & 0xf800); /* h3 */ - dstpixel[3]=((srcval1 >> 11) & 0x001f) | /* l4 */ - ((srcval1 >> 13) & 0x07e0) | /* g4 */ - ((srcval1 >> 16) & 0xf800); /* h4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - if(oddwidth) { - memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD)); - srcbyte = (LPBYTE)srcarray; - for (x=0; x> 3) & 0x001f); /* l */ - dstval|=((srcbyte[1] << 3) & 0x07e0); /* g */ - dstval|=((srcbyte[2] << 8) & 0xf800); /* h */ - *dstpixel++=dstval; - srcbyte+=3; - } - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_565_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - const BYTE* srcbyte; - WORD* dstpixel; - DWORD srcarray[3]; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 5) & 0x07e0) | /* g1 */ - ((srcval1 >> 19) & 0x001f); /* h1 */ - srcval2=srcpixel[1]; - FLIP_DWORD(&srcval2); - dstpixel[1]=((srcval1 >> 16) & 0xf800) | /* l2 */ - ((srcval2 << 3) & 0x07e0) | /* g2 */ - ((srcval2 >> 11) & 0x001f); /* h2 */ - srcval1=srcpixel[2]; - FLIP_DWORD(&srcval1); - dstpixel[2]=((srcval2 >> 8) & 0xf800) | /* l3 */ - ((srcval2 >> 21) & 0x07e0) | /* g3 */ - ((srcval1 >> 3) & 0x001f); /* h3 */ - dstpixel[3]=(srcval1 & 0xf800) | /* l4 */ - ((srcval1 >> 13) & 0x07e0) | /* g4 */ - ((srcval1 >> 27) & 0x001f); /* h4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - if(oddwidth) { - memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD)); - srcbyte = (LPBYTE)srcarray; - for (x=0; x> 3) & 0x001f); /* h */ - *dstpixel++=dstval; - srcbyte+=3; - } - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_888_to_0888_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - DWORD srcarray[3]; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 24) | /* l2 */ - ((srcval2 << 8) & 0x00ffff00); /* h2, g2 */ - srcval1=srcpixel[2]; - FLIP_DWORD(&srcval1); - dstpixel[2]=( srcval2 >> 16) | /* g3, l3 */ - ((srcval1 << 16) & 0x00ff0000); /* h3 */ - dstpixel[3]=( srcval1 >> 8); /* h4, g4, l4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - if(oddwidth) { - memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD)); - srcpixel = srcarray; - for (x=0; x> 16) & 0x0000ff) | /* h1 */ - ( srcval1 & 0x00ff00) | /* g1 */ - ((srcval1 << 16) & 0xff0000); /* l1 */ - srcval2=srcpixel[1]; - FLIP_DWORD(&srcval2); - dstpixel[1]=((srcval1 >> 8) & 0xff0000) | /* l2 */ - ((srcval2 << 8) & 0x00ff00) | /* g2 */ - ((srcval2 >> 8) & 0x0000ff); /* h2 */ - srcval1=srcpixel[2]; - FLIP_DWORD(&srcval1); - dstpixel[2]=( srcval2 & 0xff0000) | /* l3 */ - ((srcval2 >> 16) & 0x00ff00) | /* g3 */ - ( srcval1 & 0x0000ff); /* h3 */ - dstpixel[3]=((srcval1 >> 24) & 0x0000ff) | /* h4 */ - ((srcval1 >> 8) & 0x00ff00) | /* g4 */ - ((srcval1 << 8) & 0xff0000); /* l4 */ - srcpixel+=3; - dstpixel+=4; - } - /* And now up to 3 odd pixels */ - if(oddwidth) { - memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD)); - srcpixel = srcarray; - for (x=0; x> 16) & 0x0000ff) | /* h */ - ( srcval & 0x00ff00) | /* g */ - ((srcval << 16) & 0xff0000); /* l */ - } - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_rgb888_to_any0888_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes, - DWORD rdst, DWORD gdst, DWORD bdst) -{ - int rLeftShift,gLeftShift,bLeftShift; - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - DWORD srcarray[3]; - - rLeftShift=X11DRV_DIB_MaskToShift(rdst); - gLeftShift=X11DRV_DIB_MaskToShift(gdst); - bLeftShift=X11DRV_DIB_MaskToShift(bdst); - for (y=0; y> 24) & 0xff) << bLeftShift) | /* b1 */ - (((srcval1 >> 16) & 0xff) << gLeftShift) | /* g1 */ - (((srcval1 >> 8) & 0xff) << rLeftShift); /* r1 */ - srcval2=*srcpixel++; - *dstpixel++=(((srcval1 >> 0) & 0xff) << bLeftShift) | /* b2 */ - (((srcval2 >> 24) & 0xff) << gLeftShift) | /* g2 */ - (((srcval2 >> 16) & 0xff) << rLeftShift); /* r2 */ - srcval1=*srcpixel++; - *dstpixel++=(((srcval2 >> 8) & 0xff) << bLeftShift) | /* b3 */ - (((srcval2 >> 0) & 0xff) << gLeftShift) | /* g3 */ - (((srcval1 >> 24) & 0xff) << rLeftShift); /* r3 */ - *dstpixel++=(((srcval1 >> 16) & 0xff) << bLeftShift) | /* b4 */ - (((srcval1 >> 8) & 0xff) << gLeftShift) | /* g4 */ - (((srcval1 >> 0) & 0xff) << rLeftShift); /* r4 */ - } - /* And now up to 3 odd pixels */ - if(width&3) { - memcpy(srcarray,srcpixel,width&3*sizeof(DWORD)); - srcpixel = srcarray; - for (x=0; x < (width&3); x++) { - DWORD srcval; - FLIP_DWORD(srcarray+x); - srcval=*srcpixel; - srcpixel=(const DWORD*)(((const char*)srcpixel)+3); - *dstpixel++=(((srcval >> 0) & 0xff) << bLeftShift) | /* b */ - (((srcval >> 8) & 0xff) << gLeftShift) | /* g */ - (((srcval >> 16) & 0xff) << rLeftShift); /* r */ - } - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_bgr888_to_any0888_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes, - DWORD rdst, DWORD gdst, DWORD bdst) -{ - int rLeftShift,gLeftShift,bLeftShift; - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - DWORD srcarray[3]; - - rLeftShift=X11DRV_DIB_MaskToShift(rdst); - gLeftShift=X11DRV_DIB_MaskToShift(gdst); - bLeftShift=X11DRV_DIB_MaskToShift(bdst); - for (y=0; y> 24) & 0xff) << rLeftShift) | /* r1 */ - (((srcval1 >> 16) & 0xff) << gLeftShift) | /* g1 */ - (((srcval1 >> 8) & 0xff) << bLeftShift); /* b1 */ - srcval2=*srcpixel++; - *dstpixel++=(((srcval1 >> 0) & 0xff) << rLeftShift) | /* r2 */ - (((srcval2 >> 24) & 0xff) << gLeftShift) | /* g2 */ - (((srcval2 >> 16) & 0xff) << bLeftShift); /* b2 */ - srcval1=*srcpixel++; - *dstpixel++=(((srcval2 >> 8) & 0xff) << rLeftShift) | /* r3 */ - (((srcval2 >> 0) & 0xff) << gLeftShift) | /* g3 */ - (((srcval1 >> 24) & 0xff) << bLeftShift); /* b3 */ - *dstpixel++=(((srcval1 >> 16) & 0xff) << rLeftShift) | /* r4 */ - (((srcval1 >> 8) & 0xff) << gLeftShift) | /* g4 */ - (((srcval1 >> 0) & 0xff) << bLeftShift); /* b4 */ - } - /* And now up to 3 odd pixels */ - if(width&3) { - memcpy(srcarray,srcpixel,width&3*sizeof(DWORD)); - srcpixel = srcarray; - for (x=0; x < (width&3); x++) { - DWORD srcval; - FLIP_DWORD(srcarray+x); - srcval=*srcpixel; - srcpixel=(const DWORD*)(((const char*)srcpixel)+3); - *dstpixel++=(((srcval >> 0) & 0xff) << rLeftShift) | /* r */ - (((srcval >> 8) & 0xff) << gLeftShift) | /* g */ - (((srcval >> 16) & 0xff) << bLeftShift); /* b */ - } - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - - -/* - * 32 bit conversions - */ - -static void convert_0888_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - int x, y; - - for (y=0; y> 8) & 0x0000ff00) | - ((srcval >> 24) & 0x000000ff); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - for (y=0; y> 8) & 0x00ffffff); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_any_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes, - DWORD rdst, DWORD gdst, DWORD bdst) -{ - int rRightShift,gRightShift,bRightShift; - int rLeftShift,gLeftShift,bLeftShift; - const DWORD* srcpixel; - DWORD* dstpixel; - int x,y; - - rRightShift=X11DRV_DIB_MaskToShift(rsrc); - gRightShift=X11DRV_DIB_MaskToShift(gsrc); - bRightShift=X11DRV_DIB_MaskToShift(bsrc); - rLeftShift=X11DRV_DIB_MaskToShift(rdst); - gLeftShift=X11DRV_DIB_MaskToShift(gdst); - bLeftShift=X11DRV_DIB_MaskToShift(bdst); - for (y=0; y> rRightShift) & 0xff) << rLeftShift) | - (((srcval >> gRightShift) & 0xff) << gLeftShift) | - (((srcval >> bRightShift) & 0xff) << bLeftShift); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_555_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - for (y=0; y> 1) & 0x7c00) | /* h */ - ((srcval >> 14) & 0x03e0) | /* g */ - ((srcval >> 27) & 0x001f); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_555_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - for (y=0; y> 11) & 0x001f) | /* h */ - ((srcval >> 14) & 0x03e0) | /* g */ - ((srcval >> 17) & 0x7c00); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_565_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - for (y=0; y> 0) & 0xf800) | /* h */ - ((srcval >> 13) & 0x07e0) | /* g */ - ((srcval >> 27) & 0x001f); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_565_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - for (y=0; y> 11) & 0x001f) | /* h */ - ((srcval >> 13) & 0x07e0) | /* g */ - ((srcval >> 16) & 0xf800); /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_any0888_to_5x5_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes, - WORD rdst, WORD gdst, WORD bdst) -{ - int rRightShift,gRightShift,bRightShift; - int rLeftShift,gLeftShift,bLeftShift; - const DWORD* srcpixel; - WORD* dstpixel; - int x,y; - - /* Here is how we proceed. Assume we have rsrc=0x0000ff00 and our pixel - * contains 0x11223344. - * - first we shift 0x11223344 right by rRightShift to bring the most - * significant bits of the red components in the bottom 5 (or 6) bits - * -> 0x4488c - * - then we remove non red bits by anding with the modified rdst (0x1f) - * -> 0x0c - * - finally shift these bits left by rLeftShift so that they end up in - * the right place - * -> 0x3000 - */ - rRightShift=X11DRV_DIB_MaskToShift(rsrc)+3; - gRightShift=X11DRV_DIB_MaskToShift(gsrc); - gRightShift+=(gdst==0x07e0?2:3); - bRightShift=X11DRV_DIB_MaskToShift(bsrc)+3; - - rLeftShift=X11DRV_DIB_MaskToShift(rdst); - rdst=rdst >> rLeftShift; - gLeftShift=X11DRV_DIB_MaskToShift(gdst); - gdst=gdst >> gLeftShift; - bLeftShift=X11DRV_DIB_MaskToShift(bdst); - bdst=bdst >> bLeftShift; - - for (y=0; y> rRightShift) & rdst) << rLeftShift) | - (((srcval >> gRightShift) & gdst) << gLeftShift) | - (((srcval >> bRightShift) & bdst) << bLeftShift); - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_888_asis_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - BYTE* dstbyte; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 24) & 0x000000ff) | /* l1 */ - ((srcval1 >> 8) & 0x0000ff00) | /* g1 */ - ((srcval1 << 8) & 0x00ff0000) | /* h1 */ - ( srcval2 & 0xff000000); /* l2 */ - srcval1 = *srcpixel++; - *dstpixel++= ((srcval2 >> 16) & 0x000000ff) | /* g2 */ - ( srcval2 & 0x0000ff00) | /* h2 */ - ((srcval1 >> 8) & 0x00ff0000) | /* l3 */ - ((srcval1 << 8) & 0xff000000); /* g3 */ - srcval2 = *srcpixel++; - *dstpixel++= ((srcval1 >> 8) & 0x000000ff) | /* h3 */ - ((srcval2 >> 16) & 0x0000ff00) | /* l4 */ - ( srcval2 & 0x00ff0000) | /* g4 */ - ((srcval2 << 16) & 0xff000000); /* h4 */ - } - /* And now up to 3 odd pixels */ - dstbyte=(BYTE*)dstpixel; - for (x=0; x> 16; /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_0888_to_888_reverse_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes) -{ - const DWORD* srcpixel; - DWORD* dstpixel; - BYTE* dstbyte; - int x,y; - int oddwidth; - - oddwidth=width & 3; - width=width/4; - for (y=0; y> 8 ) & 0x00ffffff); /* l1, g1, h1 */ - srcval1=*srcpixel++; - *dstpixel++=srcval2 | - ((srcval1 << 16) & 0xff000000); /* h2 */ - srcval2= ((srcval1 >> 16) & 0x0000ffff); /* l2, g2 */ - srcval1=*srcpixel++; - *dstpixel++=srcval2 | - ((srcval1 << 8) & 0xffff0000); /* g3, h3 */ - srcval2= ((srcval1 >> 24) & 0x000000ff); /* l3 */ - srcval1=*srcpixel++; - *dstpixel++=srcval2 | - srcval1; /* l4, g4, h4 */ - } - /* And now up to 3 odd pixels */ - dstbyte=(BYTE*)dstpixel; - for (x=0; x> 8) & 0xffff); /* g, h */ - dstbyte+=sizeof(WORD); - *dstbyte++= srcval >> 24; /* l */ - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_any0888_to_rgb888_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes) -{ - int rRightShift,gRightShift,bRightShift; - const DWORD* srcpixel; - BYTE* dstpixel; - int x,y; - - rRightShift=X11DRV_DIB_MaskToShift(rsrc); - gRightShift=X11DRV_DIB_MaskToShift(gsrc); - bRightShift=X11DRV_DIB_MaskToShift(bsrc); - for (y=0; y> bRightShift); /* b */ - dstpixel[1]=(srcval >> gRightShift); /* g */ - dstpixel[2]=(srcval >> rRightShift); /* r */ - dstpixel+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - -static void convert_any0888_to_bgr888_src_byteswap(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes) -{ - int rRightShift,gRightShift,bRightShift; - const DWORD* srcpixel; - BYTE* dstpixel; - int x,y; - - rRightShift=X11DRV_DIB_MaskToShift(rsrc); - gRightShift=X11DRV_DIB_MaskToShift(gsrc); - bRightShift=X11DRV_DIB_MaskToShift(bsrc); - for (y=0; y> rRightShift); /* r */ - dstpixel[1]=(srcval >> gRightShift); /* g */ - dstpixel[2]=(srcval >> bRightShift); /* b */ - dstpixel+=3; - } - srcbits = (const char*)srcbits + srclinebytes; - dstbits = (char*)dstbits + dstlinebytes; - } -} - - -const dib_conversions dib_src_byteswap = { - convert_5x5_asis_src_byteswap, - convert_555_reverse_src_byteswap, - convert_555_to_565_asis_src_byteswap, - convert_555_to_565_reverse_src_byteswap, - convert_555_to_888_asis_src_byteswap, - convert_555_to_888_reverse_src_byteswap, - convert_555_to_0888_asis_src_byteswap, - convert_555_to_0888_reverse_src_byteswap, - convert_5x5_to_any0888_src_byteswap, - convert_565_reverse_src_byteswap, - convert_565_to_555_asis_src_byteswap, - convert_565_to_555_reverse_src_byteswap, - convert_565_to_888_asis_src_byteswap, - convert_565_to_888_reverse_src_byteswap, - convert_565_to_0888_asis_src_byteswap, - convert_565_to_0888_reverse_src_byteswap, - convert_888_asis_src_byteswap, - convert_888_reverse_src_byteswap, - convert_888_to_555_asis_src_byteswap, - convert_888_to_555_reverse_src_byteswap, - convert_888_to_565_asis_src_byteswap, - convert_888_to_565_reverse_src_byteswap, - convert_888_to_0888_asis_src_byteswap, - convert_888_to_0888_reverse_src_byteswap, - convert_rgb888_to_any0888_src_byteswap, - convert_bgr888_to_any0888_src_byteswap, - convert_0888_asis_src_byteswap, - convert_0888_reverse_src_byteswap, - convert_0888_any_src_byteswap, - convert_0888_to_555_asis_src_byteswap, - convert_0888_to_555_reverse_src_byteswap, - convert_0888_to_565_asis_src_byteswap, - convert_0888_to_565_reverse_src_byteswap, - convert_any0888_to_5x5_src_byteswap, - convert_0888_to_888_asis_src_byteswap, - convert_0888_to_888_reverse_src_byteswap, - convert_any0888_to_rgb888_src_byteswap, - convert_any0888_to_bgr888_src_byteswap -}; diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index e7c0d0cd19b..fd0a5291ea5 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -120,21 +120,7 @@ typedef struct XID glxpixmap; int depth; /* depth of the X pixmap */ ColorShifts color_shifts; /* color shifts of the X pixmap */ - /* the following fields are only used for DIB section bitmaps */ - int status, p_status; /* mapping status */ - XImage *image; /* cached XImage */ - int *colorMap; /* color map info */ - int nColorMap; BOOL trueColor; - BOOL topdown; - CRITICAL_SECTION lock; /* GDI access lock */ - enum x11drv_shm_mode shm_mode; -#ifdef HAVE_LIBXXSHM - XShmSegmentInfo shminfo; /* shared memory segment info */ -#endif - struct list entry; /* Entry in global DIB list */ - BYTE *base; /* Base address */ - SIZE_T size; /* Size in bytes */ } X_PHYSBITMAP; /* X physical font */ @@ -183,8 +169,6 @@ extern BOOL X11DRV_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom, INT xstart, INT ystart, INT xend, INT yend ) DECLSPEC_HIDDEN; extern BOOL X11DRV_CopyBitmap( HBITMAP src, HBITMAP dst ) DECLSPEC_HIDDEN; extern BOOL X11DRV_CreateBitmap( PHYSDEV dev, HBITMAP hbitmap ) DECLSPEC_HIDDEN; -extern HBITMAP X11DRV_CreateDIBSection( PHYSDEV dev, HBITMAP hbitmap, - BITMAPINFO *bmi, UINT usage ) DECLSPEC_HIDDEN; extern BOOL X11DRV_DeleteBitmap( HBITMAP hbitmap ) DECLSPEC_HIDDEN; extern BOOL X11DRV_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom ) DECLSPEC_HIDDEN; extern BOOL X11DRV_EnumFonts( PHYSDEV dev, LPLOGFONTW plf, FONTENUMPROCW dfeproc, LPARAM lp ) DECLSPEC_HIDDEN; @@ -267,8 +251,6 @@ extern void X11DRV_FONT_Init( int log_pixels_x, int log_pixels_y ) DECLSPEC_HIDD extern void X11DRV_XInput2_Init(void) DECLSPEC_HIDDEN; extern HBITMAP create_brush_bitmap( X11DRV_PDEVICE *physDev, const struct brush_pattern *pattern ) DECLSPEC_HIDDEN; -extern XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth ) DECLSPEC_HIDDEN; -extern void X11DRV_DIB_DestroyXImage( XImage *image ) DECLSPEC_HIDDEN; extern X_PHYSBITMAP *X11DRV_get_phys_bitmap( HBITMAP hbitmap ) DECLSPEC_HIDDEN; extern X_PHYSBITMAP *X11DRV_init_phys_bitmap( HBITMAP hbitmap ) DECLSPEC_HIDDEN; extern BOOL X11DRV_create_phys_bitmap( HBITMAP hbitmap, const BITMAP *bitmap, int depth, @@ -301,7 +283,6 @@ extern int client_side_antialias_with_render DECLSPEC_HIDDEN; extern int using_client_side_fonts DECLSPEC_HIDDEN; extern const struct gdi_dc_funcs *X11DRV_XRender_Init(void) DECLSPEC_HIDDEN; extern void X11DRV_XRender_Finalize(void) DECLSPEC_HIDDEN; -extern BOOL X11DRV_XRender_SetPhysBitmapDepth(X_PHYSBITMAP *physBitmap, int bits_pixel, const DIBSECTION *dib) DECLSPEC_HIDDEN; extern Drawable get_glxdrawable(X11DRV_PDEVICE *physDev) DECLSPEC_HIDDEN; extern BOOL destroy_glxpixmap(Display *display, XID glxpixmap) DECLSPEC_HIDDEN; @@ -322,147 +303,6 @@ extern void X11DRV_XDND_PositionEvent( HWND hWnd, XClientMessageEvent *event ) D extern void X11DRV_XDND_DropEvent( HWND hWnd, XClientMessageEvent *event ) DECLSPEC_HIDDEN; extern void X11DRV_XDND_LeaveEvent( HWND hWnd, XClientMessageEvent *event ) DECLSPEC_HIDDEN; -/* exported dib functions for now */ - -/* DIB Section sync state */ -enum { DIB_Status_None, DIB_Status_InSync, DIB_Status_GdiMod, DIB_Status_AppMod }; - -typedef struct { - void (*Convert_5x5_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_555_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_555_to_565_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_555_to_565_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_555_to_888_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_555_to_888_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_555_to_0888_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_555_to_0888_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_5x5_to_any0888)(int width, int height, - const void* srcbits, int srclinebytes, - WORD rsrc, WORD gsrc, WORD bsrc, - void* dstbits, int dstlinebytes, - DWORD rdst, DWORD gdst, DWORD bdst); - void (*Convert_565_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_565_to_555_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_565_to_555_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_565_to_888_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_565_to_888_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_565_to_0888_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_565_to_0888_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_888_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_888_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_888_to_555_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_888_to_555_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_888_to_565_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_888_to_565_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_888_to_0888_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_888_to_0888_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_rgb888_to_any0888)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes, - DWORD rdst, DWORD gdst, DWORD bdst); - void (*Convert_bgr888_to_any0888)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes, - DWORD rdst, DWORD gdst, DWORD bdst); - void (*Convert_0888_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_0888_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_0888_any)(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes, - DWORD rdst, DWORD gdst, DWORD bdst); - void (*Convert_0888_to_555_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_0888_to_555_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_0888_to_565_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_0888_to_565_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_any0888_to_5x5)(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes, - WORD rdst, WORD gdst, WORD bdst); - void (*Convert_0888_to_888_asis)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_0888_to_888_reverse)(int width, int height, - const void* srcbits, int srclinebytes, - void* dstbits, int dstlinebytes); - void (*Convert_any0888_to_rgb888)(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes); - void (*Convert_any0888_to_bgr888)(int width, int height, - const void* srcbits, int srclinebytes, - DWORD rsrc, DWORD gsrc, DWORD bsrc, - void* dstbits, int dstlinebytes); -} dib_conversions; - -extern const dib_conversions dib_normal DECLSPEC_HIDDEN, dib_src_byteswap DECLSPEC_HIDDEN, dib_dst_byteswap DECLSPEC_HIDDEN; - -extern INT X11DRV_DIB_MaskToShift(DWORD mask) DECLSPEC_HIDDEN; -extern INT X11DRV_CoerceDIBSection(X11DRV_PDEVICE *physDev,INT) DECLSPEC_HIDDEN; -extern INT X11DRV_DIB_Lock(X_PHYSBITMAP *,INT) DECLSPEC_HIDDEN; -extern void X11DRV_DIB_Unlock(X_PHYSBITMAP *,BOOL) DECLSPEC_HIDDEN; - -extern void X11DRV_DIB_DeleteDIBSection(X_PHYSBITMAP *physBitmap, DIBSECTION *dib) DECLSPEC_HIDDEN; - /************************************************************************** * X11 GDI driver */ diff --git a/dlls/winex11.drv/xrender.c b/dlls/winex11.drv/xrender.c index feb85231cff..eec15250ade 100644 --- a/dlls/winex11.drv/xrender.c +++ b/dlls/winex11.drv/xrender.c @@ -1366,45 +1366,6 @@ static void xrenderdrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn ) } -BOOL X11DRV_XRender_SetPhysBitmapDepth(X_PHYSBITMAP *physBitmap, int bits_pixel, const DIBSECTION *dib) -{ - XRenderPictFormat *pict_format; - ColorShifts shifts; - const DWORD *bitfields; - static const DWORD bitfields_32[3] = {0xff0000, 0x00ff00, 0x0000ff}; - static const DWORD bitfields_16[3] = {0x7c00, 0x03e0, 0x001f}; - - - /* When XRender is not around we can only use the screen_depth and when needed we perform depth conversion - * in software. Further we also return the screen depth for paletted formats or TrueColor formats with a low - * number of bits because XRender can't handle paletted formats and 8-bit TrueColor does not exist for XRender. */ - if (!X11DRV_XRender_Installed || bits_pixel <= 8) - return FALSE; - - if(dib->dsBmih.biCompression == BI_BITFIELDS) - bitfields = dib->dsBitfields; - else if(bits_pixel == 24 || bits_pixel == 32) - bitfields = bitfields_32; - else - bitfields = bitfields_16; - - X11DRV_PALETTE_ComputeColorShifts(&shifts, bitfields[0], bitfields[1], bitfields[2]); - pict_format = pict_formats[get_xrender_format_from_color_shifts(dib->dsBm.bmBitsPixel, &shifts)]; - - /* Common formats should be in our picture format table. */ - if (!pict_format) - { - TRACE("Unhandled dibsection format bpp=%d, redMask=%x, greenMask=%x, blueMask=%x\n", - dib->dsBm.bmBitsPixel, bitfields[0], bitfields[1], bitfields[2]); - return FALSE; - } - - physBitmap->depth = pict_format->depth; - physBitmap->trueColor = TRUE; - physBitmap->color_shifts = shifts; - return TRUE; -} - /************************************************************************ * UploadGlyph * @@ -2816,9 +2777,4 @@ void X11DRV_XRender_Finalize(void) { } -BOOL X11DRV_XRender_SetPhysBitmapDepth(X_PHYSBITMAP *physBitmap, int bits_pixel, const DIBSECTION *dib) -{ - return FALSE; -} - #endif /* SONAME_LIBXRENDER */