and handle ABGR ordering in 24/32bpp

SVN revision: 1091
This commit is contained in:
Carsten Haitzler 1999-10-31 23:08:18 +00:00
parent bcbd64b680
commit da9869d97d
4 changed files with 245 additions and 98 deletions

143
grab.c
View File

@ -32,6 +32,7 @@ __imlib_GrabDrawableToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
XShmSegmentInfo shminfo, mshminfo;
XImage *xim = NULL, *mxim = NULL;
static char x_does_shm = -1;
char bgr = 0;
DATA32 *ptr;
DATA8 rtab[256], gtab[256], btab[256];
XColor cols[256];
@ -349,6 +350,8 @@ __imlib_GrabDrawableToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
btab[i] = cols[i].blue >> 8;
}
}
if (v->blue_mask > v->red_mask)
bgr = 1;
if (data)
{
DATA32 *src;
@ -541,61 +544,141 @@ __imlib_GrabDrawableToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
}
break;
case 24:
if (mxim)
if (bgr)
{
for (y = 0; y < h; y++)
if (mxim)
{
ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++)
for (y = 0; y < h; y++)
{
pixel = XGetPixel(xim, x, y);
mpixel = XGetPixel(mxim, x, y);
*ptr++ = (0xff000000 >> (mpixel << 31)) |
(pixel & 0x00ffffff);
ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++)
{
pixel = XGetPixel(xim, x, y);
pixel =
((pixel << 16) & 0xff0000) |
((pixel) & 0x00ff00) |
((pixel >> 16) & 0x0000ff);
mpixel = XGetPixel(mxim, x, y);
*ptr++ = (0xff000000 >> (mpixel << 31)) |
(pixel & 0x00ffffff);
}
}
}
else
{
for (y = 0; y < h; y++)
{
ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++)
{
pixel = XGetPixel(xim, x, y);
*ptr++ = 0xff000000 |
((pixel << 16) & 0xff0000) |
((pixel) & 0x00ff00) |
((pixel >> 16) & 0x0000ff);
}
}
}
}
else
{
for (y = 0; y < h; y++)
if (mxim)
{
ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++)
for (y = 0; y < h; y++)
{
pixel = XGetPixel(xim, x, y);
*ptr++ = 0xff000000 |
(pixel & 0x00ffffff);
ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++)
{
pixel = XGetPixel(xim, x, y);
mpixel = XGetPixel(mxim, x, y);
*ptr++ = (0xff000000 >> (mpixel << 31)) |
(pixel & 0x00ffffff);
}
}
}
else
{
for (y = 0; y < h; y++)
{
ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++)
{
pixel = XGetPixel(xim, x, y);
*ptr++ = 0xff000000 |
(pixel & 0x00ffffff);
}
}
}
}
break;
case 32:
if (mxim)
if (bgr)
{
for (y = 0; y < h; y++)
if (mxim)
{
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++)
for (y = 0; y < h; y++)
{
mpixel = XGetPixel(mxim, x, y);
*ptr++ = (0xff000000 >> (mpixel << 31)) |
((*src) & 0x00ffffff);
src++;
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++)
{
mpixel = XGetPixel(mxim, x, y);
pixel =
((*src << 16) & 0xff0000) |
((*src) & 0x00ff00) |
((*src >> 16) & 0x0000ff);
*ptr++ = (0xff000000 >> (mpixel << 31)) |
((pixel) & 0x00ffffff);
src++;
}
}
}
else
{
for (y = 0; y < h; y++)
{
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++)
{
*ptr++ = 0xff000000 |
((*src << 16) & 0xff0000) |
((*src) & 0x00ff00) |
((*src >> 16) & 0x0000ff);
src++;
}
}
}
}
else
{
for (y = 0; y < h; y++)
if (mxim)
{
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++)
for (y = 0; y < h; y++)
{
*ptr++ = 0xff000000 |
((*src) & 0x00ffffff);
src++;
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++)
{
mpixel = XGetPixel(mxim, x, y);
*ptr++ = (0xff000000 >> (mpixel << 31)) |
((*src) & 0x00ffffff);
src++;
}
}
}
else
{
for (y = 0; y < h; y++)
{
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++)
{
*ptr++ = 0xff000000 |
((*src) & 0x00ffffff);
src++;
}
}
}
}

33
rend.c
View File

@ -47,7 +47,7 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
int psx, psy, psw, psh;
int actual_depth = 0;
char xup = 0, yup = 0;
char shm = 0;
char shm = 0, bgr = 0;
/* dont do anything if we have a 0 widht or height image to render */
if ((dw <= 0) || (dh <= 0))
@ -123,7 +123,8 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
actual_depth = depth;
if (depth == 16)
actual_depth = __imlib_XActualDepth(d, v);
if (v->blue_mask > v->red_mask)
bgr = 1;
__imlib_RGBASetupContext(ct);
if ((blend) && (IMAGE_HAS_ALPHA(im)))
{
@ -281,17 +282,29 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
/* FIXME: need to handle different RGB ordering */
else if (actual_depth == 24)
{
__imlib_RGBA_to_RGB888_fast(pointer, jump,
((DATA8 *)xim->data) + (y * xim->bytes_per_line),
xim->bytes_per_line - (dw * 3),
dw, hh, dx, dy + y);
if (bgr)
__imlib_RGBA_to_BGR888_fast(pointer, jump,
((DATA8 *)xim->data) + (y * xim->bytes_per_line),
xim->bytes_per_line - (dw * 3),
dw, hh, dx, dy + y);
else
__imlib_RGBA_to_RGB888_fast(pointer, jump,
((DATA8 *)xim->data) + (y * xim->bytes_per_line),
xim->bytes_per_line - (dw * 3),
dw, hh, dx, dy + y);
}
else if (actual_depth == 32)
{
__imlib_RGBA_to_RGB8888_fast(pointer, jump,
((DATA32 *)xim->data) + (y * (xim->bytes_per_line / sizeof(DATA32))),
(xim->bytes_per_line / sizeof(DATA32)) - dw,
dw, hh, dx, dy + y);
if (bgr)
__imlib_RGBA_to_BGR8888_fast(pointer, jump,
((DATA32 *)xim->data) + (y * (xim->bytes_per_line / sizeof(DATA32))),
(xim->bytes_per_line / sizeof(DATA32)) - dw,
dw, hh, dx, dy + y);
else
__imlib_RGBA_to_RGB8888_fast(pointer, jump,
((DATA32 *)xim->data) + (y * (xim->bytes_per_line / sizeof(DATA32))),
(xim->bytes_per_line / sizeof(DATA32)) - dw,
dw, hh, dx, dy + y);
}
else if (actual_depth == 8)
{

73
rgba.c
View File

@ -1078,6 +1078,10 @@ src++;
/* MACROS for plain RGBA -> RGB8888 conversion */
#define WRITE1_RGBA_RGB8888(src, dest) \
*dest = *src; dest++; src++;
# define WRITE1_RGBA_BGR8888(src, dest) \
*dest = (((*src) >> 16) & 0x0000ff) | \
(((*src) ) & 0x00ff00) | \
(((*src) << 16) & 0xff0000); dest++; src++;
/*****************************************************************************/
/* Actual rendering routines */
@ -1087,9 +1091,13 @@ src++;
/*****************************************************************************/
/* MACROS for plain RGBA -> RGB888 conversion */
#define WRITE1_RGBA_RGB888(src, dest) \
*dest = ((*src >> 0) & 0xff); dest++; \
*dest = ((*src >> 8) & 0xff); dest++; \
*dest = ((*src >> 0) & 0xff); dest++; \
*dest = ((*src >> 8) & 0xff); dest++; \
*dest = ((*src >> 16) & 0xff); dest++; src++;
#define WRITE1_RGBA_BGR888(src, dest) \
*dest = ((*src >> 16) & 0xff); dest++; \
*dest = ((*src >> 8) & 0xff); dest++; \
*dest = ((*src >> 0) & 0xff); dest++; src++;
void
__imlib_RGBASetupContext(Context *ct)
@ -2846,22 +2854,11 @@ __imlib_RGBA_to_RGB8888_fast(DATA32 *src , int src_jump,
DATA32 *dest, int dest_jump,
int width, int height, int dx, int dy)
{
int /* x,*/ y, w, h;
int y, w, h;
w = width;
h = height;
#if 0
for (y = 0; y < h; y++)
{
for (x = 0; x < w; x++)
{
WRITE1_RGBA_RGB8888(src, dest);
}
src += src_jump;
dest += dest_jump;
}
#endif
if ((src_jump > 0) || (dest_jump > 0))
{
for (y = h; y > 0; y--)
@ -2878,6 +2875,30 @@ __imlib_RGBA_to_RGB8888_fast(DATA32 *src , int src_jump,
dy = 0;
}
void
__imlib_RGBA_to_BGR8888_fast(DATA32 *src , int src_jump,
DATA32 *dest, int dest_jump,
int width, int height, int dx, int dy)
{
int x, y, w, h;
w = width;
h = height;
for (y = 0; y < h; y++)
{
for (x = 0; x < w; x++)
{
WRITE1_RGBA_BGR8888(src, dest);
}
src += src_jump;
dest += dest_jump;
}
return;
dx = 0;
dy = 0;
}
void
__imlib_RGBA_to_RGB888_fast(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
@ -2901,4 +2922,28 @@ __imlib_RGBA_to_RGB888_fast(DATA32 *src , int src_jump,
dx = 0;
dy = 0;
}
void
__imlib_RGBA_to_BGR888_fast(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy)
{
int x, y, w, h;
w = width;
h = height;
for (y = 0; y < h; y++)
{
for (x = 0; x < w; x++)
{
WRITE1_RGBA_BGR888(src, dest);
}
src += src_jump;
dest += dest_jump;
}
return;
dx = 0;
dy = 0;
}

94
rgba.h
View File

@ -5,69 +5,75 @@ void __imlib_RGBASetupContext(Context *ct);
void __imlib_RGBA_init(void *rd, void *gd, void *bd, int depth,
DATA8 palette_type);
void __imlib_RGBA_to_RGB565_fast(DATA32 *src , int src_jump,
DATA16 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA16 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB565_dither(DATA32 *src , int src_jump,
DATA16 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA16 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB555_fast(DATA32 *src , int src_jump,
DATA16 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA16 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB555_dither(DATA32 *src , int src_jump,
DATA16 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA16 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB332_fast(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB332_dither(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB232_fast(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB232_dither(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB222_fast(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB222_dither(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB221_fast(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB221_dither(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB121_fast(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB121_dither(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB111_fast(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB111_dither(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB1_fast(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB1_dither(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_A1_fast(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_A1_dither(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB8888_fast(DATA32 *src , int src_jump,
DATA32 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA32 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_BGR8888_fast(DATA32 *src , int src_jump,
DATA32 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_RGB888_fast(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
void __imlib_RGBA_to_BGR888_fast(DATA32 *src , int src_jump,
DATA8 *dest, int dest_jump,
int width, int height, int dx, int dy);
#endif