changeset 9697:5025150738eb

10000l (YUV vs. YVU swscale fix/cleanup)
author michael
date Thu, 27 Mar 2003 16:04:53 +0000
parents 26d4db9a1ac8
children d42a1886f54b
files libmpcodecs/vf_scale.c libvo/vo_aa.c libvo/vo_x11.c postproc/swscale.c postproc/swscale.h postproc/swscale_internal.h
diffstat 6 files changed, 55 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/vf_scale.c	Wed Mar 26 23:59:07 2003 +0000
+++ b/libmpcodecs/vf_scale.c	Thu Mar 27 16:04:53 2003 +0000
@@ -166,9 +166,9 @@
     int_sws_flags|= vf->priv->v_chr_drop << SWS_SRC_V_CHR_DROP_SHIFT;
     int_sws_flags|= vf->priv->param      << SWS_PARAM_SHIFT;
     vf->priv->ctx=sws_getContext(width,height,
-	    (outfmt==IMGFMT_I420 || outfmt==IMGFMT_IYUV)?IMGFMT_YV12:outfmt,
+	    outfmt,
 		  vf->priv->w,vf->priv->h,
-	    (best==IMGFMT_I420 || best==IMGFMT_IYUV)?IMGFMT_YV12:best,
+	    best,
 	    int_sws_flags, srcFilter, dstFilter);
     if(!vf->priv->ctx){
 	// error...
@@ -229,7 +229,7 @@
 	return;
     }
 //    printf("vf_scale::draw_slice() y=%d h=%d\n",y,h);
-    sws_scale(vf->priv->ctx,src,stride,y,h,dmpi->planes,dmpi->stride);
+    sws_scale_ordered(vf->priv->ctx,src,stride,y,h,dmpi->planes,dmpi->stride);
 }
 
 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
@@ -244,7 +244,7 @@
     dmpi=vf_get_image(vf->next,vf->priv->fmt,
 	MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
 	vf->priv->w, vf->priv->h);
-    sws_scale(vf->priv->ctx,mpi->planes,mpi->stride,0,mpi->h,dmpi->planes,dmpi->stride);
+    sws_scale_ordered(vf->priv->ctx,mpi->planes,mpi->stride,0,mpi->h,dmpi->planes,dmpi->stride);
 
   }
 
--- a/libvo/vo_aa.c	Wed Mar 26 23:59:07 2003 +0000
+++ b/libvo/vo_aa.c	Thu Mar 27 16:04:53 2003 +0000
@@ -360,7 +360,7 @@
     break;
   }
 
-  sws_scale(sws,src,stride,0,src_height,image,image_stride);
+  sws_scale_ordered(sws,src,stride,0,src_height,image,image_stride);
 
    /* Now 'ASCIInate' the image */ 
   if (fast)
@@ -380,7 +380,7 @@
   int dx2 = screen_x + ((x+w) * screen_w / src_width);
   int dy2 = screen_y + ((y+h) * screen_h / src_height);
 
-  sws_scale(sws,src,stride,y,h,image,image_stride);
+  sws_scale_ordered(sws,src,stride,y,h,image,image_stride);
 
   /* Now 'ASCIInate' the image */ 
   if (fast)
--- a/libvo/vo_x11.c	Wed Mar 26 23:59:07 2003 +0000
+++ b/libvo/vo_x11.c	Thu Mar 27 16:04:53 2003 +0000
@@ -241,7 +241,6 @@
     title = strdup("MPlayer X11 (XImage/Shm) render");
 
  in_format=format;
- if(in_format==IMGFMT_I420 || in_format==IMGFMT_IYUV) in_format=IMGFMT_YV12;
  srcW= width;
  srcH= height;
  vo_dx=( vo_screenwidth - d_width ) / 2; vo_dy=( vo_screenheight - d_height ) / 2;
@@ -508,13 +507,13 @@
   {
 	dstStride[0]= -image_width*((bpp+7)/8);
 	dst[0]=ImageData - dstStride[0]*(image_height-1);
-	sws_scale(swsContext,src,stride,y,h,dst, dstStride);
+	sws_scale_ordered(swsContext,src,stride,y,h,dst, dstStride);
   }
   else
   {
 	dstStride[0]=image_width*((bpp+7)/8);
 	dst[0]=ImageData;
-	sws_scale(swsContext,src,stride,y,h,dst, dstStride);
+	sws_scale_ordered(swsContext,src,stride,y,h,dst, dstStride);
   }
   return 0;
 }
--- a/postproc/swscale.c	Wed Mar 26 23:59:07 2003 +0000
+++ b/postproc/swscale.c	Thu Mar 27 16:04:53 2003 +0000
@@ -104,18 +104,18 @@
 #endif
 
 //FIXME replace this with something faster
-#define isPlanarYUV(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_I420 || (x)==IMGFMT_YVU9 \
+#define isPlanarYUV(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_YVU9 \
 			|| (x)==IMGFMT_444P || (x)==IMGFMT_422P || (x)==IMGFMT_411P)
 #define isYUV(x)       ((x)==IMGFMT_UYVY || (x)==IMGFMT_YUY2 || isPlanarYUV(x))
 #define isGray(x)      ((x)==IMGFMT_Y800)
 #define isRGB(x)       (((x)&IMGFMT_RGB_MASK)==IMGFMT_RGB)
 #define isBGR(x)       (((x)&IMGFMT_BGR_MASK)==IMGFMT_BGR)
-#define isSupportedIn(x)  ((x)==IMGFMT_YV12 || (x)==IMGFMT_I420 || (x)==IMGFMT_YUY2 || (x)==IMGFMT_UYVY\
+#define isSupportedIn(x)  ((x)==IMGFMT_YV12 || (x)==IMGFMT_YUY2 || (x)==IMGFMT_UYVY\
 			|| (x)==IMGFMT_BGR32|| (x)==IMGFMT_BGR24|| (x)==IMGFMT_BGR16|| (x)==IMGFMT_BGR15\
 			|| (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_I420 || (x)==IMGFMT_YUY2\
+#define isSupportedOut(x) ((x)==IMGFMT_YV12 || (x)==IMGFMT_YUY2\
 			|| (x)==IMGFMT_444P || (x)==IMGFMT_422P || (x)==IMGFMT_411P\
 			|| isRGB(x) || isBGR(x)\
 			|| (x)==IMGFMT_Y800 || (x)==IMGFMT_YVU9)
@@ -1626,10 +1626,8 @@
 		}
 	}
 	dst = dstParam[1] + dstStride[1]*srcSliceY;
-	if(c->srcFormat==IMGFMT_YV12)
-		interleaveBytes( src[1],src[2],dst,c->srcW,srcSliceH,srcStride[1],srcStride[2],dstStride[0] );
-	else /* I420 & IYUV */
-		interleaveBytes( src[2],src[1],dst,c->srcW,srcSliceH,srcStride[2],srcStride[1],dstStride[0] );
+	interleaveBytes( src[1],src[2],dst,c->srcW,srcSliceH,srcStride[1],srcStride[2],dstStride[0] );
+
 	return srcSliceH;
 }
 
@@ -1637,10 +1635,8 @@
              int srcSliceH, uint8_t* dstParam[], int dstStride[]){
 	uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY;
 
-	if(c->srcFormat==IMGFMT_YV12)
-		yv12toyuy2( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] );
-	else /* I420 & IYUV */
-		yv12toyuy2( src[0],src[2],src[1],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] );
+	yv12toyuy2( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] );
+
 	return srcSliceH;
 }
 
@@ -1764,15 +1760,15 @@
 /**
  * bring pointers in YUV order instead of YVU
  */
-inline static void sws_orderYUV(int format, uint8_t * sortedP[], int sortedStride[], uint8_t * p[], int stride[]){
-	if(format == IMGFMT_YV12 || format == IMGFMT_YVU9 
+static inline void sws_orderYUV(int format, uint8_t * sortedP[], int sortedStride[], uint8_t * p[], int stride[]){
+	if(format == IMGFMT_YV12 || format == IMGFMT_YVU9
            || format == IMGFMT_444P || format == IMGFMT_422P || format == IMGFMT_411P){
 		sortedP[0]= p[0];
-		sortedP[1]= p[1];
-		sortedP[2]= p[2];
+		sortedP[1]= p[2];
+		sortedP[2]= p[1];
 		sortedStride[0]= stride[0];
-		sortedStride[1]= stride[1];
-		sortedStride[2]= stride[2];
+		sortedStride[1]= stride[2];
+		sortedStride[2]= stride[1];
 	}
 	else if(isPacked(format) || isGray(format))
 	{
@@ -1783,14 +1779,14 @@
 		sortedStride[1]= 
 		sortedStride[2]= 0;
 	}
-	else if(format == IMGFMT_I420)
+	else if(format == IMGFMT_I420 || format == IMGFMT_IYUV)
 	{
 		sortedP[0]= p[0];
-		sortedP[1]= p[2];
-		sortedP[2]= p[1];
+		sortedP[1]= p[1];
+		sortedP[2]= p[2];
 		sortedStride[0]= stride[0];
-		sortedStride[1]= stride[2];
-		sortedStride[2]= stride[1];
+		sortedStride[1]= stride[1];
+		sortedStride[2]= stride[2];
 	}else{
 		MSG_ERR("internal error in orderYUV\n");
 	}
@@ -1864,7 +1860,8 @@
 {
 	switch(fourcc)
 	{
-	    case IMGFMT_IYUV: return IMGFMT_I420;
+	    case IMGFMT_I420:
+	    case IMGFMT_IYUV: return IMGFMT_YV12;
 	    case IMGFMT_Y8  : return IMGFMT_Y800;
 	    case IMGFMT_IF09: return IMGFMT_YVU9;
 	    default: return fourcc;
@@ -1879,7 +1876,6 @@
 		*v=0;
 		break;
 	case IMGFMT_YV12:
-	case IMGFMT_I420:
 	case IMGFMT_Y800: //FIXME remove after different subsamplings are fully implemented
 		*h=1;
 		*v=1;
@@ -1983,24 +1979,24 @@
 	return 0;	
 }
 
-SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags,
+SwsContext *sws_getContext(int srcW, int srcH, int origSrcFormat, int dstW, int dstH, int origDstFormat, int flags,
                          SwsFilter *srcFilter, SwsFilter *dstFilter){
 
 	SwsContext *c;
 	int i;
 	int usesFilter;
 	int unscaled, needsDither;
+	int srcFormat, dstFormat;
 	SwsFilter dummyFilter= {NULL, NULL, NULL, NULL};
 #ifdef ARCH_X86
 	if(gCpuCaps.hasMMX)
 		asm volatile("emms\n\t"::: "memory");
 #endif
 	if(swScale==NULL) globalInit();
-//srcFormat= IMGFMT_Y800;
-//dstFormat= IMGFMT_Y800;
+
 	/* avoid dupplicate Formats, so we dont need to check to much */
-	srcFormat = remove_dup_fourcc(srcFormat);
-	dstFormat = remove_dup_fourcc(dstFormat);
+	srcFormat = remove_dup_fourcc(origSrcFormat);
+	dstFormat = remove_dup_fourcc(origDstFormat);
 
 	unscaled = (srcW == dstW && srcH == dstH);
 	needsDither= (isBGR(dstFormat) || isRGB(dstFormat)) 
@@ -2041,6 +2037,8 @@
 	c->flags= flags;
 	c->dstFormat= dstFormat;
 	c->srcFormat= srcFormat;
+	c->origDstFormat= origDstFormat;
+	c->origSrcFormat= origSrcFormat;
 
 	usesFilter=0;
 	if(dstFilter->lumV!=NULL && dstFilter->lumV->length>1) usesFilter=1;
@@ -2081,17 +2079,17 @@
 	if(unscaled && !usesFilter)
 	{
 		/* yv12_to_nv12 */
-		if((srcFormat == IMGFMT_YV12||srcFormat==IMGFMT_I420)&&dstFormat == IMGFMT_NV12)
+		if(srcFormat == IMGFMT_YV12 && dstFormat == IMGFMT_NV12)
 		{
 			c->swScale= PlanarToNV12Wrapper;
 		}
 		/* yuv2bgr */
-		if((srcFormat==IMGFMT_YV12 || srcFormat==IMGFMT_I420 || srcFormat==IMGFMT_422P) && (isBGR(dstFormat) || isRGB(dstFormat)))
+		if((srcFormat==IMGFMT_YV12 || srcFormat==IMGFMT_422P) && (isBGR(dstFormat) || isRGB(dstFormat)))
 		{
 			c->swScale= yuv2rgb_get_func_ptr(c);
 		}
 		
-		if( srcFormat==IMGFMT_YVU9 && (dstFormat==IMGFMT_YV12 || dstFormat==IMGFMT_I420) )
+		if( srcFormat==IMGFMT_YVU9 && dstFormat==IMGFMT_YV12 )
 		{
 			c->swScale= yvu9toyv12Wrapper;
 		}
@@ -2115,7 +2113,7 @@
 				c->swScale= rgb2rgbWrapper;
 
 			/* yv12_to_yuy2 */
-			if((srcFormat == IMGFMT_YV12||srcFormat==IMGFMT_I420)&&dstFormat == IMGFMT_YUY2)
+			if(srcFormat == IMGFMT_YV12 && dstFormat == IMGFMT_YUY2)
 			{
 				c->swScale= PlanarToYuy2Wrapper;
 			}
@@ -2123,8 +2121,6 @@
 
 		/* simple copy */
 		if(   srcFormat == dstFormat
-		   || (srcFormat==IMGFMT_YV12 && dstFormat==IMGFMT_I420)
-		   || (srcFormat==IMGFMT_I420 && dstFormat==IMGFMT_YV12)
 		   || (isPlanarYUV(srcFormat) && isGray(dstFormat))
 		   || (isPlanarYUV(dstFormat) && isGray(srcFormat))
 		  )
@@ -2372,6 +2368,15 @@
 }
 
 /**
+ * swscale warper, so we dont need to export the SwsContext.
+ * assumes planar YUV to be in YUV order instead of YVU
+ */
+int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
+                           int srcSliceH, uint8_t* dst[], int dstStride[]){
+	c->swScale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride);
+}
+
+/**
  * swscale warper, so we dont need to export the SwsContext
  */
 int sws_scale(SwsContext *c, uint8_t* srcParam[], int srcStrideParam[], int srcSliceY,
@@ -2380,11 +2385,10 @@
 	int dstStride[3];
 	uint8_t *src[3];
 	uint8_t *dst[3];
-
-	sws_orderYUV(c->srcFormat, src, srcStride, srcParam, srcStrideParam);
-	sws_orderYUV(c->dstFormat, dst, dstStride, dstParam, dstStrideParam);
+	sws_orderYUV(c->origSrcFormat, src, srcStride, srcParam, srcStrideParam);
+	sws_orderYUV(c->origDstFormat, dst, dstStride, dstParam, dstStrideParam);
 //printf("sws: slice %d %d\n", srcSliceY, srcSliceH);
-	return c->swScale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride);
+	c->swScale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride);
 }
 
 /**
--- a/postproc/swscale.h	Wed Mar 26 23:59:07 2003 +0000
+++ b/postproc/swscale.h	Thu Mar 27 16:04:53 2003 +0000
@@ -104,6 +104,8 @@
 			 SwsFilter *srcFilter, SwsFilter *dstFilter);
 int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
                            int srcSliceH, uint8_t* dst[], int dstStride[]);
+int sws_scale_ordered(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,
+                           int srcSliceH, uint8_t* dst[], int dstStride[]);
 
 void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam); //FIXME try to seperate this 
 
--- a/postproc/swscale_internal.h	Wed Mar 26 23:59:07 2003 +0000
+++ b/postproc/swscale_internal.h	Thu Mar 27 16:04:53 2003 +0000
@@ -35,7 +35,8 @@
 	int chrSrcW, chrSrcH, chrDstW, chrDstH;
 	int lumXInc, chrXInc;
 	int lumYInc, chrYInc;
-	int dstFormat, srcFormat;
+	int dstFormat, srcFormat;               ///< format 4:2:0 type is allways YV12
+	int origDstFormat, origSrcFormat;       ///< format
 	int chrSrcHSubSample, chrSrcVSubSample;
 	int chrIntHSubSample, chrIntVSubSample;
 	int chrDstHSubSample, chrDstVSubSample;