summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuergen Keil <jkeil@users.sourceforge.net>2001-08-23 11:27:35 +0000
committerJuergen Keil <jkeil@users.sourceforge.net>2001-08-23 11:27:35 +0000
commit8df246ca0cf9876e3865f021668f39da761526fa (patch)
tree81d5f8ab8e26ef2edc2e1d96ec02d43aaaee04d7 /src
parent9ca652b0a712f562419b9bc9e6135e640355d7e2 (diff)
downloadxine-lib-8df246ca0cf9876e3865f021668f39da761526fa.tar.gz
xine-lib-8df246ca0cf9876e3865f021668f39da761526fa.tar.bz2
Handle different byte order between X11 client <-> X11 server in yuv2rgb.
CVS patchset: 467 CVS date: 2001/08/23 11:27:35
Diffstat (limited to 'src')
-rw-r--r--src/video_out/video_out_xshm.c20
-rw-r--r--src/video_out/yuv2rgb.c95
-rw-r--r--src/video_out/yuv2rgb.h8
-rw-r--r--src/video_out/yuv2rgb_mlib.c4
-rw-r--r--src/video_out/yuv2rgb_mmx.c8
5 files changed, 85 insertions, 50 deletions
diff --git a/src/video_out/video_out_xshm.c b/src/video_out/video_out_xshm.c
index a14945968..f55f7a39c 100644
--- a/src/video_out/video_out_xshm.c
+++ b/src/video_out/video_out_xshm.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: video_out_xshm.c,v 1.26 2001/08/18 23:30:51 guenter Exp $
+ * $Id: video_out_xshm.c,v 1.27 2001/08/23 11:27:35 jkeil Exp $
*
* video_out_xshm.c, X11 shared memory extension interface for xine
*
@@ -92,7 +92,7 @@ typedef struct xshm_driver_s {
XColor black;
int use_shm;
int zoom_mpeg1;
- int depth, bpp, bytes_per_pixel;
+ int depth, bpp, bytes_per_pixel, byte_order;
int expecting_event;
yuv2rgb_t *yuv2rgb;
@@ -220,6 +220,7 @@ static XImage *create_ximage (xshm_driver_t *this, XShmSegmentInfo *shminfo,
this->bpp = myimage->bits_per_pixel;
this->bytes_per_pixel = this->bpp / 8;
+ this->byte_order = myimage->byte_order;
shminfo->shmid=shmget(IPC_PRIVATE,
myimage->bytes_per_line * myimage->height,
@@ -291,6 +292,7 @@ static XImage *create_ximage (xshm_driver_t *this, XShmSegmentInfo *shminfo,
this->bpp = myimage->bits_per_pixel;
this->bytes_per_pixel = this->bpp / 8;
+ this->byte_order = myimage->byte_order;
myimage->data = xmalloc (width * this->bytes_per_pixel * height);
}
@@ -913,6 +915,8 @@ vo_driver_t *init_video_out_plugin (config_values_t *config, void *visual_gen) {
XImage *myimage;
XShmSegmentInfo myshminfo;
int mode;
+ int swapped;
+ int cpu_byte_order;
visual = (x11_visual_t *) visual_gen;
display = visual->display;
@@ -1029,9 +1033,13 @@ vo_driver_t *init_video_out_plugin (config_values_t *config, void *visual_gen) {
mode = 0;
- printf ("video_out_xshm: video mode is %d depth (%d bpp), red: %08lx, green: %08lx, blue: %08lx\n",
- this->depth, this->bpp, this->vinfo.red_mask, this->vinfo.green_mask,
- this->vinfo.blue_mask);
+ cpu_byte_order = htonl(1) == 1 ? MSBFirst : LSBFirst;
+ swapped = cpu_byte_order != this->byte_order;
+
+ printf ("video_out_xshm: video mode is %d depth (%d bpp), %sswapped, red: %08lx, green: %08lx, blue: %08lx\n",
+ this->depth, this->bpp,
+ swapped ? "" : "not ",
+ this->vinfo.red_mask, this->vinfo.green_mask, this->vinfo.blue_mask);
switch (this->depth) {
case 24:
@@ -1070,7 +1078,7 @@ vo_driver_t *init_video_out_plugin (config_values_t *config, void *visual_gen) {
return NULL;
}
- this->yuv2rgb = yuv2rgb_init (mode);
+ this->yuv2rgb = yuv2rgb_init (mode, swapped);
return &this->vo_driver;
}
diff --git a/src/video_out/yuv2rgb.c b/src/video_out/yuv2rgb.c
index f8a43cf2e..2b582485d 100644
--- a/src/video_out/yuv2rgb.c
+++ b/src/video_out/yuv2rgb.c
@@ -22,7 +22,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: yuv2rgb.c,v 1.12 2001/08/18 23:30:51 guenter Exp $
+ * $Id: yuv2rgb.c,v 1.13 2001/08/23 11:27:35 jkeil Exp $
*/
#include "config.h"
@@ -898,7 +898,7 @@ static int div_round (int dividend, int divisor)
return -((-dividend + (divisor>>1)) / divisor);
}
-static void yuv2rgb_setup_tables (yuv2rgb_t *this, int mode)
+static void yuv2rgb_setup_tables (yuv2rgb_t *this, int mode, int swapped)
{
int i;
uint8_t table_Y[1024];
@@ -907,6 +907,7 @@ static void yuv2rgb_setup_tables (yuv2rgb_t *this, int mode)
uint8_t * table_8 = 0;
int entry_size = 0;
void *table_r = 0, *table_g = 0, *table_b = 0;
+ int shift_r = 0, shift_g = 0, shift_b = 0;
int crv = Inverse_Table_6_9[this->matrix_coefficients][0];
int cbu = Inverse_Table_6_9[this->matrix_coefficients][1];
@@ -931,14 +932,24 @@ static void yuv2rgb_setup_tables (yuv2rgb_t *this, int mode)
table_b = table_32 + 197 + 685;
table_g = table_32 + 197 + 2*682;
+ if (swapped) {
+ switch (mode) {
+ case MODE_32_RGB: shift_r = 8; shift_g = 16; shift_b = 24; break;
+ case MODE_32_BGR: shift_r = 24; shift_g = 16; shift_b = 8; break;
+ }
+ } else {
+ switch (mode) {
+ case MODE_32_RGB: shift_r = 16; shift_g = 8; shift_b = 0; break;
+ case MODE_32_BGR: shift_r = 0; shift_g = 8; shift_b = 16; break;
+ }
+ }
+
for (i = -197; i < 256+197; i++)
- ((uint32_t *) table_r)[i] =
- table_Y[i+384] << ((mode==MODE_32_RGB) ? 16 : 0);
+ ((uint32_t *) table_r)[i] = table_Y[i+384] << shift_r;
for (i = -132; i < 256+132; i++)
- ((uint32_t *) table_g)[i] = table_Y[i+384] << 8;
+ ((uint32_t *) table_g)[i] = table_Y[i+384] << shift_g;
for (i = -232; i < 256+232; i++)
- ((uint32_t *) table_b)[i] =
- table_Y[i+384] << ((mode==MODE_32_RGB) ? 0 : 16);
+ ((uint32_t *) table_b)[i] = table_Y[i+384] << shift_b;
break;
case MODE_24_RGB:
@@ -963,31 +974,35 @@ static void yuv2rgb_setup_tables (yuv2rgb_t *this, int mode)
table_b = table_16 + 197 + 685;
table_g = table_16 + 197 + 2*682;
- for (i = -197; i < 256+197; i++) {
- int j = table_Y[i+384] >> 3;
+ if (swapped) {
+ switch (mode) {
+ case MODE_15_BGR: shift_r = 8; shift_g = 5; shift_b = 2; break;
+ case MODE_16_BGR: shift_r = 8; shift_g = 5; shift_b = 3; break;
+ case MODE_15_RGB: shift_r = 2; shift_g = 5; shift_b = 8; break;
+ case MODE_16_RGB: shift_r = 3; shift_g = 5; shift_b = 8; break;
+ }
+ } else {
+ switch (mode) {
+ case MODE_15_BGR: shift_r = 0; shift_g = 5; shift_b = 10; break;
+ case MODE_16_BGR: shift_r = 0; shift_g = 5; shift_b = 11; break;
+ case MODE_15_RGB: shift_r = 10; shift_g = 5; shift_b = 0; break;
+ case MODE_16_RGB: shift_r = 11; shift_g = 5; shift_b = 0; break;
+ }
+ }
- if (mode == MODE_16_RGB)
- j <<= 11;
- else if (mode == MODE_15_RGB)
- j <<= 10;
+ for (i = -197; i < 256+197; i++)
+ ((uint16_t *)table_r)[i] = (table_Y[i+384] >> 3) << shift_r;
- ((uint16_t *)table_r)[i] = j;
- }
for (i = -132; i < 256+132; i++) {
int j = table_Y[i+384] >> (((mode==MODE_16_RGB) || (mode==MODE_16_BGR)) ? 2 : 3);
-
- ((uint16_t *)table_g)[i] = j << 5;
+ if (swapped)
+ ((uint16_t *)table_g)[i] = (j&7) << 13 | (j>>3);
+ else
+ ((uint16_t *)table_g)[i] = j << 5;
}
- for (i = -232; i < 256+232; i++) {
- int j = table_Y[i+384] >> 3;
-
- if (mode == MODE_16_BGR)
- j <<= 11;
- if (mode == MODE_15_BGR)
- j <<= 10;
+ for (i = -232; i < 256+232; i++)
+ ((uint16_t *)table_b)[i] = (table_Y[i+384] >> 3) << shift_b;
- ((uint16_t *)table_b)[i] = j;
- }
break;
case MODE_PALETTE:
@@ -1012,7 +1027,7 @@ static void yuv2rgb_setup_tables (yuv2rgb_t *this, int mode)
}
}
-static void yuv2rgb_c_init (yuv2rgb_t *this, int mode)
+static void yuv2rgb_c_init (yuv2rgb_t *this, int mode, int swapped)
{
switch (mode) {
case MODE_32_RGB:
@@ -1022,7 +1037,10 @@ static void yuv2rgb_c_init (yuv2rgb_t *this, int mode)
case MODE_24_RGB:
case MODE_24_BGR:
- this->yuv2rgb_fun = (mode==MODE_24_RGB) ? yuv2rgb_c_24_rgb : yuv2rgb_c_24_bgr;
+ this->yuv2rgb_fun =
+ (mode==MODE_24_RGB && !swapped) || (mode==MODE_24_BGR && swapped)
+ ? yuv2rgb_c_24_rgb
+ : yuv2rgb_c_24_bgr;
break;
case MODE_15_BGR:
@@ -1345,7 +1363,7 @@ static void yuy22rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
}
}
-static void yuy22rgb_c_init (yuv2rgb_t *this, int mode)
+static void yuy22rgb_c_init (yuv2rgb_t *this, int mode, int swapped)
{
switch (mode) {
case MODE_32_RGB:
@@ -1355,7 +1373,10 @@ static void yuy22rgb_c_init (yuv2rgb_t *this, int mode)
case MODE_24_RGB:
case MODE_24_BGR:
- this->yuy22rgb_fun = (mode==MODE_24_RGB) ? yuy22rgb_c_24_rgb : yuy22rgb_c_24_bgr;
+ this->yuy22rgb_fun =
+ (mode==MODE_24_RGB && !swapped) || (mode==MODE_24_BGR && swapped)
+ ? yuy22rgb_c_24_rgb
+ : yuy22rgb_c_24_bgr;
break;
case MODE_15_BGR:
case MODE_16_BGR:
@@ -1369,7 +1390,7 @@ static void yuy22rgb_c_init (yuv2rgb_t *this, int mode)
}
}
-yuv2rgb_t *yuv2rgb_init (int mode) {
+yuv2rgb_t *yuv2rgb_init (int mode, int swapped) {
#ifdef ARCH_X86
uint32_t mm = mm_accel();
@@ -1383,7 +1404,7 @@ yuv2rgb_t *yuv2rgb_init (int mode) {
this->u_chunk = this->u_buffer = NULL;
this->v_chunk = this->v_buffer = NULL;
- yuv2rgb_setup_tables(this, mode);
+ yuv2rgb_setup_tables(this, mode, swapped);
/*
* auto-probe for the best yuv2rgb function
@@ -1392,26 +1413,26 @@ yuv2rgb_t *yuv2rgb_init (int mode) {
this->yuv2rgb_fun = NULL;
#ifdef ARCH_X86
if ((this->yuv2rgb_fun == NULL) && (mm & MM_ACCEL_X86_MMXEXT)) {
- yuv2rgb_init_mmxext (this, mode);
+ yuv2rgb_init_mmxext (this, mode, swapped);
if (this->yuv2rgb_fun != NULL)
printf ("yuv2rgb: using MMXEXT for colorspace transform\n");
}
if ((this->yuv2rgb_fun == NULL) && (mm & MM_ACCEL_X86_MMX)) {
- yuv2rgb_init_mmx (this, mode);
+ yuv2rgb_init_mmx (this, mode, swapped);
if (this->yuv2rgb_fun != NULL)
printf ("yuv2rgb: using MMX for colorspace transform\n");
}
#endif
#if HAVE_MLIB
if (this->yuv2rgb_fun == NULL) {
- yuv2rgb_init_mlib (this, mode);
+ yuv2rgb_init_mlib (this, mode, swapped);
if (this->yuv2rgb_fun != NULL)
printf ("yuv2rgb: using medialib for colorspace transform\n");
}
#endif
if (this->yuv2rgb_fun == NULL) {
printf ("yuv2rgb: no accelerated colorspace conversion found\n");
- yuv2rgb_c_init (this, mode);
+ yuv2rgb_c_init (this, mode, swapped);
}
/*
@@ -1419,7 +1440,7 @@ yuv2rgb_t *yuv2rgb_init (int mode) {
*/
/* FIXME: implement mmx/mlib functions */
- yuy22rgb_c_init (this, mode);
+ yuy22rgb_c_init (this, mode, swapped);
return this;
}
diff --git a/src/video_out/yuv2rgb.h b/src/video_out/yuv2rgb.h
index 8efbbfbd9..6cf7e0e5c 100644
--- a/src/video_out/yuv2rgb.h
+++ b/src/video_out/yuv2rgb.h
@@ -57,7 +57,7 @@ struct yuv2rgb_s {
/* call once on startup */
-yuv2rgb_t *yuv2rgb_init (int mode);
+yuv2rgb_t *yuv2rgb_init (int mode, int swapped);
/*
* set up yuv2rgb function, determine scaling parameters if necessary
@@ -73,9 +73,9 @@ int yuv2rgb_setup (yuv2rgb_t *this,
* internal stuff below this line
*/
-void yuv2rgb_init_mmxext (yuv2rgb_t *this, int mode);
-void yuv2rgb_init_mmx (yuv2rgb_t *this, int mode);
-void yuv2rgb_init_mlib (yuv2rgb_t *this, int mode);
+void yuv2rgb_init_mmxext (yuv2rgb_t *this, int mode, int swapped);
+void yuv2rgb_init_mmx (yuv2rgb_t *this, int mode, int swapped);
+void yuv2rgb_init_mlib (yuv2rgb_t *this, int mode, int swapped);
/*
void Color565DitherYV12MMX1X(unsigned char *lum, unsigned char *cr,
diff --git a/src/video_out/yuv2rgb_mlib.c b/src/video_out/yuv2rgb_mlib.c
index 7d0b56fa7..34bb582b6 100644
--- a/src/video_out/yuv2rgb_mlib.c
+++ b/src/video_out/yuv2rgb_mlib.c
@@ -269,8 +269,10 @@ static void mlib_yuv420_abgr32 (yuv2rgb_t *this,
}
-void yuv2rgb_init_mlib (yuv2rgb_t *this, int mode)
+void yuv2rgb_init_mlib (yuv2rgb_t *this, int mode, int swapped)
{
+ if (swapped) return; /*no swapped pixel output upto now*/
+
switch (mode) {
case MODE_24_RGB:
this->yuv2rgb_fun = mlib_yuv420_rgb24;
diff --git a/src/video_out/yuv2rgb_mmx.c b/src/video_out/yuv2rgb_mmx.c
index 855e6cecc..76a8588b2 100644
--- a/src/video_out/yuv2rgb_mmx.c
+++ b/src/video_out/yuv2rgb_mmx.c
@@ -984,8 +984,10 @@ static void mmx_abgr32 (yuv2rgb_t *this, uint8_t * image,
emms(); /* re-initialize x86 FPU after MMX use */
}
-void yuv2rgb_init_mmxext (yuv2rgb_t *this, int mode)
+void yuv2rgb_init_mmxext (yuv2rgb_t *this, int mode, int swapped)
{
+ if (swapped) return; /*no swapped pixel output upto now*/
+
switch (mode) {
case MODE_15_RGB:
this->yuv2rgb_fun = mmxext_rgb15;
@@ -1005,8 +1007,10 @@ void yuv2rgb_init_mmxext (yuv2rgb_t *this, int mode)
}
}
-void yuv2rgb_init_mmx (yuv2rgb_t *this, int mode)
+void yuv2rgb_init_mmx (yuv2rgb_t *this, int mode, int swapped)
{
+ if (swapped) return; /*no swapped pixel output upto now*/
+
switch (mode) {
case MODE_15_RGB:
this->yuv2rgb_fun = mmx_rgb15;