changeset 9171:898e5270a46e

fixing rgb4 & bgr4 (2 pixels per byte) adding bg4b & rg4b (1 pixel per byte)
author michael
date Thu, 30 Jan 2003 09:15:09 +0000
parents bcf4bf10f9c7
children 8c2830239a14
files libmpcodecs/img_format.c libmpcodecs/img_format.h libmpcodecs/mp_image.h libmpcodecs/vf_format.c libmpcodecs/vf_scale.c libvo/vo_svga.c postproc/swscale.c postproc/yuv2rgb.c
diffstat 8 files changed, 169 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/img_format.c	Wed Jan 29 23:28:55 2003 +0000
+++ b/libmpcodecs/img_format.c	Thu Jan 30 09:15:09 2003 +0000
@@ -6,6 +6,7 @@
     {
 	case IMGFMT_RGB1: return("RGB 1-bit");
 	case IMGFMT_RGB4: return("RGB 4-bit");
+	case IMGFMT_RG4B: return("RGB 4-bit per byte");
 	case IMGFMT_RGB8: return("RGB 8-bit");
 	case IMGFMT_RGB15: return("RGB 15-bit");
 	case IMGFMT_RGB16: return("RGB 16-bit");
@@ -13,6 +14,7 @@
 	case IMGFMT_RGB32: return("RGB 32-bit");
 	case IMGFMT_BGR1: return("BGR 1-bit");
 	case IMGFMT_BGR4: return("BGR 4-bit");
+	case IMGFMT_BG4B: return("BGR 4-bit per byte");
 	case IMGFMT_BGR8: return("BGR 8-bit");
 	case IMGFMT_BGR15: return("BGR 15-bit");
 	case IMGFMT_BGR16: return("BGR 16-bit");
--- a/libmpcodecs/img_format.h	Wed Jan 29 23:28:55 2003 +0000
+++ b/libmpcodecs/img_format.h	Thu Jan 30 09:15:09 2003 +0000
@@ -8,6 +8,7 @@
 #define IMGFMT_RGB (('R'<<24)|('G'<<16)|('B'<<8))
 #define IMGFMT_RGB1  (IMGFMT_RGB|1)
 #define IMGFMT_RGB4  (IMGFMT_RGB|4)
+#define IMGFMT_RG4B  (IMGFMT_RGB|4|128) // RGB4 with 1 pixel per byte
 #define IMGFMT_RGB8  (IMGFMT_RGB|8)
 #define IMGFMT_RGB15 (IMGFMT_RGB|15)
 #define IMGFMT_RGB16 (IMGFMT_RGB|16)
@@ -18,6 +19,7 @@
 #define IMGFMT_BGR (('B'<<24)|('G'<<16)|('R'<<8))
 #define IMGFMT_BGR1 (IMGFMT_BGR|1)
 #define IMGFMT_BGR4 (IMGFMT_BGR|4)
+#define IMGFMT_BG4B (IMGFMT_BGR|4|128) // BGR4 with 1 pixel per byte
 #define IMGFMT_BGR8 (IMGFMT_BGR|8)
 #define IMGFMT_BGR15 (IMGFMT_BGR|15)
 #define IMGFMT_BGR16 (IMGFMT_BGR|16)
@@ -27,8 +29,8 @@
 #define IMGFMT_IS_RGB(fmt) (((fmt)&IMGFMT_RGB_MASK)==IMGFMT_RGB)
 #define IMGFMT_IS_BGR(fmt) (((fmt)&IMGFMT_BGR_MASK)==IMGFMT_BGR)
 
-#define IMGFMT_RGB_DEPTH(fmt) ((fmt)&~IMGFMT_RGB_MASK)
-#define IMGFMT_BGR_DEPTH(fmt) ((fmt)&~IMGFMT_BGR_MASK)
+#define IMGFMT_RGB_DEPTH(fmt) ((fmt)&0x3F)
+#define IMGFMT_BGR_DEPTH(fmt) ((fmt)&0x3F)
 
 
 /* Planar YUV Formats */
--- a/libmpcodecs/mp_image.h	Wed Jan 29 23:28:55 2003 +0000
+++ b/libmpcodecs/mp_image.h	Thu Jan 30 09:15:09 2003 +0000
@@ -96,14 +96,14 @@
     }
     mpi->num_planes=1;
     if (IMGFMT_IS_RGB(out_fmt)) {
-	if (IMGFMT_RGB_DEPTH(out_fmt) < 8)
+	if (IMGFMT_RGB_DEPTH(out_fmt) < 8 && !(out_fmt&128))
 	    mpi->bpp = IMGFMT_RGB_DEPTH(out_fmt);
 	else
 	    mpi->bpp=(IMGFMT_RGB_DEPTH(out_fmt)+7)&(~7);
 	return;
     }
     if (IMGFMT_IS_BGR(out_fmt)) {
-	if (IMGFMT_BGR_DEPTH(out_fmt) < 8)
+	if (IMGFMT_BGR_DEPTH(out_fmt) < 8 && !(out_fmt&128))
 	    mpi->bpp = IMGFMT_BGR_DEPTH(out_fmt);
 	else
 	    mpi->bpp=(IMGFMT_BGR_DEPTH(out_fmt)+7)&(~7);
--- a/libmpcodecs/vf_format.c	Wed Jan 29 23:28:55 2003 +0000
+++ b/libmpcodecs/vf_format.c	Thu Jan 30 09:15:09 2003 +0000
@@ -44,6 +44,7 @@
 	if(!strcasecmp(args,"bgr15")) vf->priv->fmt=IMGFMT_BGR15; else
 	if(!strcasecmp(args,"bgr8")) vf->priv->fmt=IMGFMT_BGR8; else
 	if(!strcasecmp(args,"bgr4")) vf->priv->fmt=IMGFMT_BGR4; else
+	if(!strcasecmp(args,"bg4b")) vf->priv->fmt=IMGFMT_BG4B; else
 	if(!strcasecmp(args,"bgr1")) vf->priv->fmt=IMGFMT_BGR1; else
 	if(!strcasecmp(args,"rgb24")) vf->priv->fmt=IMGFMT_RGB24; else
 	if(!strcasecmp(args,"rgb32")) vf->priv->fmt=IMGFMT_RGB32; else
@@ -51,6 +52,7 @@
 	if(!strcasecmp(args,"rgb15")) vf->priv->fmt=IMGFMT_RGB15; else
 	if(!strcasecmp(args,"rgb8")) vf->priv->fmt=IMGFMT_RGB8; else
 	if(!strcasecmp(args,"rgb4")) vf->priv->fmt=IMGFMT_RGB4; else
+	if(!strcasecmp(args,"rg4b")) vf->priv->fmt=IMGFMT_RG4B; else
 	if(!strcasecmp(args,"rgb1")) vf->priv->fmt=IMGFMT_RGB1; else
 	{ printf("Unknown format name: '%s'\n",args);return 0;}
     } else
--- a/libmpcodecs/vf_scale.c	Wed Jan 29 23:28:55 2003 +0000
+++ b/libmpcodecs/vf_scale.c	Thu Jan 30 09:15:09 2003 +0000
@@ -41,6 +41,8 @@
     IMGFMT_RGB8,
     IMGFMT_BGR4,
     IMGFMT_RGB4,
+    IMGFMT_BG4B,
+    IMGFMT_RG4B,
     IMGFMT_BGR1,
     IMGFMT_RGB1,
 // YUV:
@@ -178,7 +180,8 @@
 	    vf->priv->palette[4*i+2]=4*((i>>5)&7)*9;
 	}
 	break; }
-    case IMGFMT_BGR4: {
+    case IMGFMT_BGR4: 
+    case IMGFMT_BG4B: {
 	int i;
 	vf->priv->palette=malloc(4*16);
 	for(i=0; i<16; i++){
--- a/libvo/vo_svga.c	Wed Jan 29 23:28:55 2003 +0000
+++ b/libvo/vo_svga.c	Thu Jan 30 09:15:09 2003 +0000
@@ -517,7 +517,10 @@
   }	
 #endif
   if (pformat == IMGFMT_YV12) {
-    yuv2rgb_init(bpp, MODE_RGB);
+    if(bpp==4)
+        yuv2rgb_init(bpp|128, MODE_RGB);
+    else
+        yuv2rgb_init(bpp, MODE_RGB);
   }
 
   x_pos = (WIDTH - maxw) / 2;
@@ -748,7 +751,7 @@
       case 8 : if ((format == IMGFMT_RGB8 ) || (format == IMGFMT_BGR8))
                  return ((bpp_avail & BPP_8 ) ? 1 : 0);
 	       break;
-      case 4 : if ((format == IMGFMT_RGB4 ) || (format == IMGFMT_BGR4))
+      case 4 : if ((format == IMGFMT_RG4B ) || (format == IMGFMT_BG4B))
                  return ((bpp_avail & BPP_4 ) ? 1 : 0);
 	       break;
       case 1 : if ((format == IMGFMT_RGB1 ) || (format == IMGFMT_BGR1))
--- a/postproc/swscale.c	Wed Jan 29 23:28:55 2003 +0000
+++ b/postproc/swscale.c	Thu Jan 30 09:15:09 2003 +0000
@@ -587,6 +587,17 @@
 			const uint8_t * const d64= dither_8x8_73 [y&7];\
 			const uint8_t * const d128=dither_8x8_220[y&7];\
 			func(uint8_t)\
+				((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];\
+				                 + ((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4);\
+			}\
+		}\
+		break;\
+	case IMGFMT_RG4B:\
+	case IMGFMT_BG4B:\
+		{\
+			const uint8_t * const d64= dither_8x8_73 [y&7];\
+			const uint8_t * const d128=dither_8x8_220[y&7];\
+			func(uint8_t)\
 				((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];\
 				((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]];\
 			}\
@@ -751,6 +762,17 @@
 			const uint8_t * const d64= dither_8x8_73 [y&7];
 			const uint8_t * const d128=dither_8x8_220[y&7];
 			YSCALE_YUV_2_RGBX_C(uint8_t)
+				((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];
+				                  +((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4);
+			}
+		}
+		break;
+	case IMGFMT_RG4B:
+	case IMGFMT_BG4B:
+		{
+			const uint8_t * const d64= dither_8x8_73 [y&7];
+			const uint8_t * const d128=dither_8x8_220[y&7];
+			YSCALE_YUV_2_RGBX_C(uint8_t)
 				((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];
 				((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]];
 			}
--- a/postproc/yuv2rgb.c	Wed Jan 29 23:28:55 2003 +0000
+++ b/postproc/yuv2rgb.c	Thu Jan 30 09:15:09 2003 +0000
@@ -609,6 +609,118 @@
     dst_2 = _dst_2;
 
     while (h_size--) {
+        int acc;
+#define DST1_4(i)					\
+	Y = py_1[2*i];				\
+	acc = r[Y] + g[Y] + b[Y];	\
+	Y = py_1[2*i+1];			\
+        acc |= (r[Y] + g[Y] + b[Y])<<4;\
+	dst_1[i] = acc; 
+
+#define DST2_4(i)					\
+	Y = py_2[2*i];				\
+	acc = r[Y] + g[Y] + b[Y];	\
+	Y = py_2[2*i+1];			\
+	acc |= (r[Y] + g[Y] + b[Y])<<4;\
+	dst_2[i] = acc; 
+	
+        RGB(0);
+	DST1_4(0);
+	DST2_4(0);
+
+	RGB(1);
+	DST2_4(1);
+	DST1_4(1);
+
+	RGB(2);
+	DST1_4(2);
+	DST2_4(2);
+
+	RGB(3);
+	DST2_4(3);
+	DST1_4(3);
+
+	pu += 4;
+	pv += 4;
+	py_1 += 8;
+	py_2 += 8;
+	dst_1 += 4;
+	dst_2 += 4;
+    }
+}
+
+static void yuv2rgb_c_4_ordered_dither  (uint8_t * py_1, uint8_t * py_2,
+			  uint8_t * pu, uint8_t * pv,
+			  void * _dst_1, void * _dst_2, int h_size, int v_pos)
+{
+    int U, V, Y;
+    uint8_t * r, * g, * b;
+    uint8_t * dst_1, * dst_2;
+
+    h_size >>= 3;
+    dst_1 = _dst_1;
+    dst_2 = _dst_2;
+
+    while (h_size--) {
+	const uint8_t *d64= dither_8x8_73[v_pos&7];
+	const uint8_t *d128=dither_8x8_220[v_pos&7];
+        int acc;
+
+#define DST1bpp4(i,o)					\
+	Y = py_1[2*i];				\
+	acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]];	\
+	Y = py_1[2*i+1];			\
+	acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4;\
+        dst_1[i]= acc;
+
+#define DST2bpp4(i,o)					\
+	Y = py_2[2*i];				\
+	acc =  r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]];	\
+	Y = py_2[2*i+1];			\
+	acc |=  (r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]])<<4;\
+        dst_2[i]= acc;
+
+
+	RGB(0);
+	DST1bpp4(0,0);
+	DST2bpp4(0,0);
+
+	RGB(1);
+	DST2bpp4(1,2);
+	DST1bpp4(1,2);
+
+	RGB(2);
+	DST1bpp4(2,4);
+	DST2bpp4(2,4);
+
+	RGB(3);
+	DST2bpp4(3,6);
+	DST1bpp4(3,6);
+
+	pu += 4;
+	pv += 4;
+	py_1 += 8;
+	py_2 += 8;
+	dst_1 += 4;
+	dst_2 += 4;
+    }
+}
+
+// This is exactly the same code as yuv2rgb_c_32 except for the types of
+// r, g, b, dst_1, dst_2
+static void yuv2rgb_c_4b  (uint8_t * py_1, uint8_t * py_2,
+			  uint8_t * pu, uint8_t * pv,
+			  void * _dst_1, void * _dst_2, int h_size, int v_pos)
+{
+    int U, V, Y;
+    uint8_t * r, * g, * b;
+    uint8_t * dst_1, * dst_2;
+
+    h_size >>= 3;
+    dst_1 = _dst_1;
+    dst_2 = _dst_2;
+
+    while (h_size--) {
 	RGB(0);
 	DST1(0);
 	DST2(0);
@@ -634,7 +746,7 @@
     }
 }
 
-static void yuv2rgb_c_4_ordered_dither  (uint8_t * py_1, uint8_t * py_2,
+static void yuv2rgb_c_4b_ordered_dither  (uint8_t * py_1, uint8_t * py_2,
 			  uint8_t * pu, uint8_t * pv,
 			  void * _dst_1, void * _dst_2, int h_size, int v_pos)
 {
@@ -650,13 +762,13 @@
 	const uint8_t *d64= dither_8x8_73[v_pos&7];
 	const uint8_t *d128=dither_8x8_220[v_pos&7];
 
-#define DST1bpp4(i,o)					\
+#define DST1bpp4b(i,o)					\
 	Y = py_1[2*i];				\
 	dst_1[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]];	\
 	Y = py_1[2*i+1];			\
 	dst_1[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];
 
-#define DST2bpp4(i,o)					\
+#define DST2bpp4b(i,o)					\
 	Y = py_2[2*i];				\
 	dst_2[2*i] =  r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]];	\
 	Y = py_2[2*i+1];			\
@@ -664,20 +776,20 @@
 
 
 	RGB(0);
-	DST1bpp4(0,0);
-	DST2bpp4(0,0);
+	DST1bpp4b(0,0);
+	DST2bpp4b(0,0);
 
 	RGB(1);
-	DST2bpp4(1,2);
-	DST1bpp4(1,2);
+	DST2bpp4b(1,2);
+	DST1bpp4b(1,2);
 
 	RGB(2);
-	DST1bpp4(2,4);
-	DST2bpp4(2,4);
+	DST1bpp4b(2,4);
+	DST2bpp4b(2,4);
 
 	RGB(3);
-	DST2bpp4(3,6);
-	DST1bpp4(3,6);
+	DST2bpp4b(3,6);
+	DST1bpp4b(3,6);
 
 	pu += 4;
 	pv += 4;
@@ -879,7 +991,11 @@
 	}
 	break;
     case 4:
-	yuv2rgb_c_internal = yuv2rgb_c_4_ordered_dither; //yuv2rgb_c_4;
+    case 4|128:
+        if(bpp==4)
+	    yuv2rgb_c_internal = yuv2rgb_c_4_ordered_dither; //yuv2rgb_c_4;
+        else
+	    yuv2rgb_c_internal = yuv2rgb_c_4b_ordered_dither; //yuv2rgb_c_4;
 
 	table_start= table_121 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));