Commit 5b11c96f authored by Alexandre Julliard's avatar Alexandre Julliard

winex11: Get rid of the DIB section support.

parent 978c42fe
......@@ -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 \
......
......@@ -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();
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* 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 <stdlib.h>
#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<height; y++) {
memcpy(dstbits, srcbits, width);
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
static void convert_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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 10) & 0x7c007c00) | /* h */
( srcval & 0x03e003e0) | /* g */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 1) & 0xffc0ffc0) | /* h, g */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
dstpixel[0]=((srcval << 3) & 0xf8) | /* l */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
dstpixel[0]=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 9) & 0xf80000) | /* h */
((srcval << 4) & 0x070000) | /* h - 3 bits */
((srcval << 6) & 0x00f800) | /* g */
((srcval << 1) & 0x000700) | /* g - 3 bits */
((srcval << 3) & 0x0000f8) | /* l */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
BYTE red,green,blue;
srcval=*srcpixel++ << 16;
red= ((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 11) & 0xf800f800) | /* h */
( srcval & 0x07e007e0) | /* g */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
dstpixel[0]=((srcval << 3) & 0xf8) | /* l */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
dstpixel[0]=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 8) & 0xf80000) | /* h */
((srcval << 3) & 0x070000) | /* h - 3 bits */
((srcval << 5) & 0x00fc00) | /* g */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
memcpy(dstbits, srcbits, width);
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
static void convert_888_reverse(int width, int height,
const void* srcbits, int srclinebytes,
void* dstbits, int dstlinebytes)
{
const BYTE* srcpixel;
BYTE* dstpixel;
int x,y;
for (y=0; y<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
dstpixel[0]=srcpixel[2];
dstpixel[1]=srcpixel[1];
dstpixel[2]=srcpixel[0];
srcpixel+=3;
dstpixel+=3;
}
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
static void convert_888_to_555_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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 words out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
dstpixel[0]=((srcval1 >> 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<oddwidth; x++) {
WORD dstval;
dstval =((srcbyte[0] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 words out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
dstpixel[0]=((srcval1 << 7) & 0x7c00) | /* l1 */
((srcval1 >> 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<oddwidth; x++) {
WORD dstval;
dstval =((srcbyte[0] << 7) & 0x7c00); /* l */
dstval|=((srcbyte[1] << 2) & 0x03e0); /* g */
dstval|=((srcbyte[2] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 words out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
dstpixel[0]=((srcval1 >> 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<oddwidth; x++) {
WORD dstval;
dstval =((srcbyte[0] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 words out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
dstpixel[0]=((srcval1 << 8) & 0xf800) | /* l1 */
((srcval1 >> 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<oddwidth; x++) {
WORD dstval;
dstval =((srcbyte[0] << 8) & 0xf800); /* l */
dstval|=((srcbyte[1] << 3) & 0x07e0); /* g */
dstval|=((srcbyte[2] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
/* advance w1 pixels to make srcpixel 32 bit aligned */
srcpixel = (const DWORD*)((INT_PTR)srcpixel & ~3);
srcpixel += w1;
dstpixel += w1;
/* and do the w1 pixels */
x = w1;
if( x) {
dstpixel[ -1] = ( srcpixel[ -1] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
/* advance w1 pixels to make srcpixel 32 bit aligned */
srcpixel = (const DWORD*)((INT_PTR)srcpixel & ~3);
srcpixel += w1;
dstpixel += w1;
/* and do the w1 pixels */
x = w1;
if( x) {
dstpixel[ -1]=((srcpixel[ -1] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
*dstpixel++=(srcpixel[0] << bLeftShift) | /* b */
(srcpixel[1] << gLeftShift) | /* g */
(srcpixel[2] << rLeftShift); /* r */
srcpixel+=3;
}
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
static void convert_bgr888_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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
*dstpixel++=(srcpixel[0] << rLeftShift) | /* r */
(srcpixel[1] << gLeftShift) | /* g */
(srcpixel[2] << bLeftShift); /* b */
srcpixel+=3;
}
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
/*
* 32 bit conversions
*/
static void convert_0888_asis(int width, int height,
const void* srcbits, int srclinebytes,
void* dstbits, int dstlinebytes)
{
int y;
width *= 4;
if (srclinebytes == dstlinebytes && srclinebytes == width)
{
memcpy(dstbits, srcbits, height * width);
return;
}
for (y=0; y<height; y++) {
memcpy(dstbits, srcbits, width);
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
static void convert_0888_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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 16) & 0x00ff0000) | /* h */
( srcval & 0x0000ff00) | /* g */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=(((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=(((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 4 dwords in and 3 dwords out */
DWORD srcval;
srcval=((*srcpixel++) & 0x00ffffff); /* h1, g1, l1*/
*dstpixel++=srcval | ((*srcpixel) << 24); /* h2 */
srcval=((*srcpixel++ >> 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<oddwidth; x++) {
DWORD srcval;
srcval=*srcpixel++;
*((WORD*)dstbyte) = srcval; /* h, g */
dstbyte+=sizeof(WORD);
*dstbyte++=srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 4 dwords in and 3 dwords out */
DWORD srcval1,srcval2;
srcval1=*srcpixel++;
srcval2= ((srcval1 >> 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<oddwidth; x++) {
DWORD srcval;
srcval=*srcpixel++;
*((WORD*)dstbyte)=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
dstpixel[0]=(srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
dstpixel[0]=(srcval >> 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
};
/*
* 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 <stdlib.h>
#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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for(x = 0; x < width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval = *srcpixel++;
*dstpixel++=((srcval << 8) & 0xff00ff00) |
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/4; x++) {
/* Do 4 pixels at a time. 4 words in 3 dwords out */
DWORD srcval1, srcval2;
srcval1=(DWORD)*srcpixel++;
srcval2=(DWORD)*srcpixel++;
*dstpixel++= ((srcval1 << 27) & 0xf8000000) | /* l1 */
((srcval1 << 22) & 0x07000000) | /* l1 - 3 bits */
((srcval1 << 14) & 0x00f80000) | /* g1 */
((srcval1 << 9) & 0x00070000) | /* g1 - 3 bits */
((srcval1 << 1) & 0x0000f800) | /* h1 */
((srcval1 >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/4; x++) {
/* Do 4 pixels at a time. 4 words in 3 dwords out */
DWORD srcval1, srcval2;
srcval1=(DWORD)*srcpixel++;
srcval2=(DWORD)*srcpixel++;
*dstpixel++= ((srcval1 << 17) & 0xf8000000) | /* h1 */
((srcval1 << 12) & 0x07000000) | /* h1 - 3 bits */
((srcval1 << 14) & 0x00f80000) | /* g1 */
((srcval1 << 9) & 0x00070000) | /* g1 - 3 bits */
((srcval1 << 11) & 0x0000f800) | /* l1 */
((srcval1 << 6) & 0x00070000) | /* l1 - 3 bits */
((srcval2 >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 1) & 0x0000f800) | /* h */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 17) & 0xf8000000) | /* h */
((srcval << 12) & 0x07000000) | /* h - 3 bits */
((srcval << 14) & 0x00f80000) | /* g */
((srcval << 9) & 0x00070000) | /* g - 3 bits */
((srcval << 11) & 0x0000f800) | /* l */
((srcval << 6) & 0x00000700); /* l - 3 bits */
}
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
static void convert_5x5_to_any0888_dst_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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
BYTE red,green,blue;
srcval=*srcpixel++ << 16;
red= ((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 7) & 0xe000e000) | /* g - 3 bits */
((srcval << 8) & 0x1f001f00) | /* l */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 7) & 0xe000e000) | /* g - 3 bits */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/4; x++) {
/* Do 4 pixels at a time. 4 words in 3 dwords out */
DWORD srcval1, srcval2;
srcval1=(DWORD)*srcpixel++;
srcval2=(DWORD)*srcpixel++;
*dstpixel++= ((srcval1 << 27) & 0xf8000000) | /* l1 */
((srcval1 << 22) & 0x07000000) | /* l1 - 3 bits */
((srcval1 << 13) & 0x00fc0000) | /* g1 */
((srcval1 << 7) & 0x00030000) | /* g1 - 2 bits */
((srcval1 << 0) & 0x0000f800) | /* h1 */
((srcval1 >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/4; x++) {
/* Do 4 pixels at a time. 4 words in 3 dwords out */
DWORD srcval1, srcval2;
srcval1=(DWORD)*srcpixel++;
srcval2=(DWORD)*srcpixel++;
*dstpixel++= ((srcval1 << 16) & 0xf8000000) | /* h1 */
((srcval1 << 11) & 0x07000000) | /* h1 - 3 bits */
((srcval1 << 13) & 0x00fc0000) | /* g1 */
((srcval1 << 7) & 0x00030000) | /* g1 - 2 bits */
((srcval1 << 11) & 0x0000f800) | /* l1 */
((srcval1 << 6) & 0x00070000) | /* l1 - 3 bits */
((srcval2 >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 0) & 0x0000f800) | /* h */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 16) & 0xf8000000) | /* h */
((srcval << 11) & 0x07000000) | /* h - 3 bits */
((srcval << 13) & 0x00fc0000) | /* g */
((srcval << 7) & 0x00030000) | /* g - 2 bits */
((srcval << 11) & 0x0000f800) | /* l */
((srcval << 6) & 0x00000700); /* l - 3 bits */
}
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
/*
* 24 bit conversions
*/
static void convert_888_asis_dst_byteswap(int width, int height,
const void* srcbits, int srclinebytes,
void* dstbits, int dstlinebytes)
{
int x, y;
for (y=0; y<height; y++) {
for(x = 0; x < ((width+1)*3/4); x++) {
DWORD srcval = *((const DWORD*)srcbits + x);
*((DWORD*)dstbits + x) = ((srcval << 24) & 0xff000000) |
((srcval << 8) & 0x00ff0000) |
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/4; x++) {
/* Do 4 pixels at a time. 3 dwords in 3 dwords out */
*dstpixel++=((srcpixel[0] << 8) & 0xffffff00) | /* h1, g1, l1 */
((srcpixel[1] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 words out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
dstpixel[0]=((srcval1 << 5) & 0x1f00) | /* l1 */
((srcval1 >> 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<oddwidth; x++) {
WORD dstval;
dstval =((srcbyte[0] << 5) & 0x1f00); /* l */
dstval|=((srcbyte[1] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 words out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
dstpixel[0]=((srcval1 >> 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<oddwidth; x++) {
WORD dstval;
dstval =((srcbyte[0] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 words out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
dstpixel[0]=((srcval1 << 5) & 0x1f00) | /* l1 */
((srcval1 >> 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<oddwidth; x++) {
WORD dstval;
dstval =((srcbyte[0] << 5) & 0x1f00); /* l */
dstval|=((srcbyte[1] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 words out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
dstpixel[0]=((srcval1 >> 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<oddwidth; x++) {
WORD dstval;
dstval =((srcbyte[0] << 0) & 0x00f8); /* l */
dstval|=((srcbyte[1] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 dwords out */
DWORD srcval1,srcval2;
srcval1=*srcpixel++;
*dstpixel++=((srcval1 << 24) & 0xff000000) | /* l1 */
((srcval1 << 8) & 0x00ff0000) | /* g1 */
((srcval1 >> 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<oddwidth; x++) {
DWORD srcval;
srcval=*srcpixel;
srcpixel=(const DWORD*)(((const char*)srcpixel)+3);
*dstpixel++=((srcval << 24) & 0xff000000) | /* l */
((srcval << 8) & 0x00ff0000) | /* g */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 dwords out */
DWORD srcval1,srcval2;
srcval1=*srcpixel++;
*dstpixel++=((srcval1 << 8) & 0xffffff00); /* h1, g1, l1 */
srcval2=*srcpixel++;
*dstpixel++=((srcval2 << 16) & 0xffff0000) | /* h2, g2 */
((srcval1 >> 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<oddwidth; x++) {
DWORD srcval;
srcval=*srcpixel;
srcpixel=(const DWORD*)(((const char*)srcpixel)+3);
*dstpixel++=((srcval << 8) & 0xffffff00);
}
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
static void convert_rgb888_to_any0888_dst_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 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
*dstpixel =(srcpixel[0] << bLeftShift) | /* b */
(srcpixel[1] << gLeftShift) | /* g */
(srcpixel[2] << rLeftShift); /* r */
FLIP_DWORD(dstpixel);
dstpixel++;
srcpixel+=3;
}
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
static void convert_bgr888_to_any0888_dst_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 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
*dstpixel =(srcpixel[0] << rLeftShift) | /* r */
(srcpixel[1] << gLeftShift) | /* g */
(srcpixel[2] << bLeftShift); /* b */
FLIP_DWORD(dstpixel);
dstpixel++;
srcpixel+=3;
}
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
/*
* 32 bit conversions
*/
static void convert_0888_asis_dst_byteswap(int width, int height,
const void* srcbits, int srclinebytes,
void* dstbits, int dstlinebytes)
{
int x, y;
for (y=0; y<height; y++) {
for(x = 0; x < width; x++) {
DWORD srcval = *((const DWORD*)srcbits + x);
*((DWORD*)dstbits + x) = ((srcval << 24) & 0xff000000) |
((srcval << 8) & 0x00ff0000) |
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 8) & 0xffffff00);
}
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
static void convert_0888_any_dst_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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel =(((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel =((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel =((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel =(((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 4 dwords in and 3 dwords out */
DWORD srcval1, srcval2;
srcval1=*srcpixel++;
srcval2=*srcpixel++;
*dstpixel++=((srcval1 << 24) & 0xff000000) | /* l1 */
((srcval1 << 8) & 0x00ff0000) | /* g1 */
((srcval1 >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 4 dwords in and 3 dwords out */
DWORD srcval1,srcval2;
srcval1=*srcpixel++;
srcval2=*srcpixel++;
*dstpixel++=((srcval1 << 8) & 0xffffff00) | /* h1, g1, l1 */
((srcval2 >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
dstpixel[0]=(srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
dstpixel[0]=(srcval >> 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
};
/*
* 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 <stdlib.h>
#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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for(x = 0; x < width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval = *srcpixel++;
*dstpixel++=((srcval << 8) & 0xff00ff00) |
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 9) & 0xfe00fe00) | /* h, g - 2 bits*/
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
dstpixel[0]=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
dstpixel[0]=((srcval << 1) & 0xf8) | /* h */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 17) & 0xf80000) | /* h */
((srcval << 12) & 0x070000) | /* 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 >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 1) & 0x0000f8) | /* h */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
BYTE red,green,blue;
srcval=*srcpixel++ << 16;
FLIP_TWO_WORDS(&srcval);
red= ((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 3) & 0xf800f800) | /* l */
((srcval << 8) & 0x07000700) | /* g - 3 bits */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 7) & 0x7f807f80) | /* h, g - 3 bits */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/2; x++) {
/* Do 2 pixels at a time */
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
dstpixel[0]=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
dstpixel[0]=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval << 16) & 0xf80000) | /* h */
((srcval << 11) & 0x070000) | /* h - 3 bits */
((srcval << 13) & 0x00e000) | /* g - 3 bits */
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
WORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
for(x = 0; x < ((width+1)*3/4); x++) {
DWORD srcval = *((const DWORD*)srcbits + x);
*((DWORD*)dstbits + x) = ((srcval << 24) & 0xff000000) |
((srcval << 8) & 0x00ff0000) |
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 3 dwords out */
*dstpixel++= ((srcpixel[0] >> 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<oddwidth; x++) {
FLIP_DWORD(srcarray+x);
dstbyte[0] = srcbyte[2];
dstbyte[1] = srcbyte[1];
dstbyte[2] = srcbyte[0];
srcbyte+=3;
dstbyte+=3;
}
}
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
static void convert_888_to_555_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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 words out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
FLIP_DWORD(&srcval1);
dstpixel[0]=((srcval1 >> 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<oddwidth; x++) {
WORD dstval;
FLIP_DWORD(srcarray+x);
dstval =((srcbyte[0] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 words out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
FLIP_DWORD(&srcval1);
dstpixel[0]=((srcval1 << 7) & 0x7c00) | /* l1 */
((srcval1 >> 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<oddwidth; x++) {
WORD dstval;
FLIP_DWORD(srcarray+x);
dstval =((srcbyte[0] << 7) & 0x7c00); /* l */
dstval|=((srcbyte[1] << 2) & 0x03e0); /* g */
dstval|=((srcbyte[2] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 words out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
FLIP_DWORD(&srcval1);
dstpixel[0]=((srcval1 >> 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<oddwidth; x++) {
WORD dstval;
FLIP_DWORD(srcarray+x);
dstval =((srcbyte[0] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 words out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
FLIP_DWORD(&srcval1);
dstpixel[0]=((srcval1 << 8) & 0xf800) | /* l1 */
((srcval1 >> 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<oddwidth; x++) {
WORD dstval;
FLIP_DWORD(srcarray+x);
dstval =((srcbyte[0] << 8) & 0xf800); /* l */
dstval|=((srcbyte[1] << 3) & 0x07e0); /* g */
dstval|=((srcbyte[2] >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 dwords out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
FLIP_DWORD(&srcval1);
dstpixel[0]=( srcval1 & 0x00ffffff); /* h1, g1, l1 */
srcval2=srcpixel[1];
FLIP_DWORD(&srcval2);
dstpixel[1]=( srcval1 >> 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<oddwidth; x++) {
DWORD srcval;
FLIP_DWORD(srcarray+x);
srcval=*srcpixel;
srcpixel=(const DWORD*)(((const char*)srcpixel)+3);
*dstpixel++=( srcval & 0x00ffffff); /* h, g, l */
}
}
srcbits = (const char*)srcbits + srclinebytes;
dstbits = (char*)dstbits + dstlinebytes;
}
}
static void convert_888_to_0888_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;
oddwidth=width & 3;
width=width/4;
for (y=0; y<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 dwords out */
DWORD srcval1,srcval2;
srcval1=srcpixel[0];
FLIP_DWORD(&srcval1);
dstpixel[0]=((srcval1 >> 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<oddwidth; x++) {
DWORD srcval;
FLIP_DWORD(srcarray+x);
srcval=*srcpixel;
srcpixel=(const DWORD*)(((const char*)srcpixel)+3);
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/4; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 dwords out */
DWORD srcval1, srcval2;
srcval1=*srcpixel++;
*dstpixel++=(((srcval1 >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width/4; x++) {
/* Do 4 pixels at a time: 3 dwords in and 4 dwords out */
DWORD srcval1, srcval2;
srcval1=*srcpixel++;
*dstpixel++=(((srcval1 >> 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<height; y++) {
for(x = 0; x < width; x++) {
DWORD srcval = *((const DWORD*)srcbits + x);
*((DWORD*)dstbits + x) = ((srcval << 24) & 0xff000000) |
((srcval << 8) & 0x00ff0000) |
((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
FLIP_DWORD(&srcval);
*dstpixel++=(((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
*dstpixel++=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
FLIP_DWORD(&srcval);
*dstpixel++=(((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 4 dwords in and 3 dwords out */
DWORD srcval1, srcval2;
srcval1 = *srcpixel++;
srcval2 = *srcpixel++;
*dstpixel++= ((srcval1 >> 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<oddwidth; x++) {
DWORD srcval;
srcval=*srcpixel++;
FLIP_DWORD(&srcval);
*((WORD*)dstbyte)=srcval; /* h, g */
dstbyte+=sizeof(WORD);
*dstbyte++=srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
/* Do 4 pixels at a time: 4 dwords in and 3 dwords out */
DWORD srcval1,srcval2;
srcval1=*srcpixel++;
srcval2= ((srcval1 >> 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<oddwidth; x++) {
DWORD srcval;
srcval=*srcpixel++;
*((WORD*)dstbyte)=((srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
FLIP_DWORD(&srcval);
dstpixel[0]=(srcval >> 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<height; y++) {
srcpixel=srcbits;
dstpixel=dstbits;
for (x=0; x<width; x++) {
DWORD srcval;
srcval=*srcpixel++;
FLIP_DWORD(&srcval);
dstpixel[0]=(srcval >> 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
};
......@@ -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
*/
......
......@@ -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 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment