changeset 11068:f33f908ae085

uyvy output support in swscaler
author alex
date Thu, 09 Oct 2003 22:25:53 +0000
parents 2340e006992f
children 71d1a2815e16
files libmpcodecs/vf_scale.c postproc/rgb2rgb.c postproc/rgb2rgb_template.c postproc/swscale.c
diffstat 4 files changed, 99 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/vf_scale.c	Thu Oct 09 22:24:07 2003 +0000
+++ b/libmpcodecs/vf_scale.c	Thu Oct 09 22:25:53 2003 +0000
@@ -71,6 +71,7 @@
     IMGFMT_Y800,
     IMGFMT_Y8,
     IMGFMT_YUY2,
+    IMGFMT_UYVY,
     0
 };
 
--- a/postproc/rgb2rgb.c	Thu Oct 09 22:24:07 2003 +0000
+++ b/postproc/rgb2rgb.c	Thu Oct 09 22:25:53 2003 +0000
@@ -41,6 +41,9 @@
 void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
 	unsigned int width, unsigned int height,
 	int lumStride, int chromStride, int dstStride);
+void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+	unsigned int width, unsigned int height,
+	int lumStride, int chromStride, int dstStride);
 void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
 	unsigned int width, unsigned int height,
 	int lumStride, int chromStride, int dstStride);
@@ -213,6 +216,7 @@
 		rgb32tobgr16= rgb32tobgr16_MMX2;
 		rgb32tobgr15= rgb32tobgr15_MMX2;
 		yv12toyuy2= yv12toyuy2_MMX2;
+		yv12touyvy= yv12touyvy_MMX2;
 		yuv422ptoyuy2= yuv422ptoyuy2_MMX2;
 		yuy2toyv12= yuy2toyv12_MMX2;
 		uyvytoyv12= uyvytoyv12_MMX2;
@@ -242,6 +246,7 @@
 		rgb32tobgr16= rgb32tobgr16_3DNOW;
 		rgb32tobgr15= rgb32tobgr15_3DNOW;
 		yv12toyuy2= yv12toyuy2_3DNOW;
+		yv12touyvy= yv12touyvy_3DNOW;
 		yuv422ptoyuy2= yuv422ptoyuy2_3DNOW;
 		yuy2toyv12= yuy2toyv12_3DNOW;
 		uyvytoyv12= uyvytoyv12_3DNOW;
@@ -271,6 +276,7 @@
 		rgb32tobgr16= rgb32tobgr16_MMX;
 		rgb32tobgr15= rgb32tobgr15_MMX;
 		yv12toyuy2= yv12toyuy2_MMX;
+		yv12touyvy= yv12touyvy_MMX;
 		yuv422ptoyuy2= yuv422ptoyuy2_MMX;
 		yuy2toyv12= yuy2toyv12_MMX;
 		uyvytoyv12= uyvytoyv12_MMX;
@@ -302,6 +308,7 @@
 		rgb32tobgr16= rgb32tobgr16_C;
 		rgb32tobgr15= rgb32tobgr15_C;
 		yv12toyuy2= yv12toyuy2_C;
+		yv12touyvy= yv12touyvy_C;
 		yuv422ptoyuy2= yuv422ptoyuy2_C;
 		yuy2toyv12= yuy2toyv12_C;
 //		uyvytoyv12= uyvytoyv12_C;
--- a/postproc/rgb2rgb_template.c	Thu Oct 09 22:24:07 2003 +0000
+++ b/postproc/rgb2rgb_template.c	Thu Oct 09 22:25:53 2003 +0000
@@ -1568,6 +1568,64 @@
 	RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2);
 }
 
+static inline void RENAME(yuvPlanartouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+	unsigned int width, unsigned int height,
+	int lumStride, int chromStride, int dstStride, int vertLumPerChroma)
+{
+	unsigned y;
+	const unsigned chromWidth= width>>1;
+	for(y=0; y<height; y++)
+	{
+#if __WORDSIZE >= 64
+		int i;
+		uint64_t *ldst = (uint64_t *) dst;
+		const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
+		for(i = 0; i < chromWidth; i += 2){
+			uint64_t k, l;
+			k = uc[0] + (yc[0] << 8) +
+			    (vc[0] << 16) + (yc[1] << 24);
+			l = uc[1] + (yc[2] << 8) +
+			    (vc[1] << 16) + (yc[3] << 24);
+			*ldst++ = k + (l << 32);
+			yc += 4;
+			uc += 2;
+			vc += 2;
+		}
+
+#else
+		int i, *idst = (int32_t *) dst;
+		const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc;
+		for(i = 0; i < chromWidth; i++){
+			*idst++ = uc[0] + (yc[0] << 8) +
+			    (vc[0] << 16) + (yc[1] << 24);
+			yc += 2;
+			uc++;
+			vc++;
+		}
+#endif
+		if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) )
+		{
+			usrc += chromStride;
+			vsrc += chromStride;
+		}
+		ysrc += lumStride;
+		dst += dstStride;
+	}
+}
+
+/**
+ *
+ * height should be a multiple of 2 and width should be a multiple of 16 (if this is a
+ * problem for anyone then tell me, and ill fix it)
+ */
+static inline void RENAME(yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+	unsigned int width, unsigned int height,
+	int lumStride, int chromStride, int dstStride)
+{
+	//FIXME interpolate chroma
+	RENAME(yuvPlanartouyvy)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2);
+}
+
 /**
  *
  * width should be a multiple of 16
--- a/postproc/swscale.c	Thu Oct 09 22:24:07 2003 +0000
+++ b/postproc/swscale.c	Thu Oct 09 22:25:53 2003 +0000
@@ -18,7 +18,7 @@
 
 /*
   supported Input formats: YV12, I420/IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8/Y800, YVU9/IF09
-  supported output formats: YV12, I420/IYUV, YUY2, {BGR,RGB}{1,4,8,15,16,24,32}, Y8/Y800, YVU9/IF09
+  supported output formats: YV12, I420/IYUV, YUY2, UYVY, {BGR,RGB}{1,4,8,15,16,24,32}, Y8/Y800, YVU9/IF09
   {BGR,RGB}{1,4,8,15,16} support dithering
   
   unscaled special converters (YV12=I420=IYUV, Y800=Y8)
@@ -107,7 +107,7 @@
 			|| (x)==IMGFMT_RGB32|| (x)==IMGFMT_RGB24\
 			|| (x)==IMGFMT_Y800 || (x)==IMGFMT_YVU9\
 			|| (x)==IMGFMT_444P || (x)==IMGFMT_422P || (x)==IMGFMT_411P)
-#define isSupportedOut(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_YUY2\
+#define isSupportedOut(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_YUY2 || (x)==IMGFMT_UYVY\
 			|| (x)==IMGFMT_444P || (x)==IMGFMT_422P || (x)==IMGFMT_411P\
 			|| isRGB(x) || isBGR(x)\
 			|| (x)==IMGFMT_Y800 || (x)==IMGFMT_YVU9)
@@ -503,6 +503,14 @@
 			((uint8_t*)dest)[2*i2+3]= V;\
 		}		\
 		break;\
+	case IMGFMT_UYVY:\
+		func2\
+			((uint8_t*)dest)[2*i2+0]= U;\
+			((uint8_t*)dest)[2*i2+1]= Y1;\
+			((uint8_t*)dest)[2*i2+2]= V;\
+			((uint8_t*)dest)[2*i2+3]= Y2;\
+		}		\
+		break;\
 	}\
 
 
@@ -647,6 +655,14 @@
 			((uint8_t*)dest)[2*i2+3]= V;
 		}
                 break;
+	case IMGFMT_UYVY:
+		YSCALE_YUV_2_PACKEDX_C(void)
+			((uint8_t*)dest)[2*i2+0]= U;
+			((uint8_t*)dest)[2*i2+1]= Y1;
+			((uint8_t*)dest)[2*i2+2]= V;
+			((uint8_t*)dest)[2*i2+3]= Y2;
+		}
+                break;
 	}
 }
 
@@ -1336,6 +1352,15 @@
 	return srcSliceH;
 }
 
+static int PlanarToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+             int srcSliceH, uint8_t* dstParam[], int dstStride[]){
+	uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
+
+	yv12touyvy( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] );
+
+	return srcSliceH;
+}
+
 /* {RGB,BGR}{15,16,24,32} -> {RGB,BGR}{15,16,24,32} */
 static int rgb2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
 			   int srcSliceH, uint8_t* dst[], int dstStride[]){
@@ -1821,9 +1846,13 @@
 				c->swScale= rgb2rgbWrapper;
 
 			/* yv12_to_yuy2 */
-			if(srcFormat == IMGFMT_YV12 && dstFormat == IMGFMT_YUY2)
+			if(srcFormat == IMGFMT_YV12 && 
+			    (dstFormat == IMGFMT_YUY2 || dstFormat == IMGFMT_UYVY))
 			{
-				c->swScale= PlanarToYuy2Wrapper;
+				if (dstFormat == IMGFMT_YUY2)
+				    c->swScale= PlanarToYuy2Wrapper;
+				else
+				    c->swScale= PlanarToUyvyWrapper;
 			}
 		}