uyvy output support in swscaler
authorAlex Beregszaszi <alex@rtfs.hu>
Thu, 9 Oct 2003 22:25:53 +0000 (22:25 +0000)
committerAlex Beregszaszi <alex@rtfs.hu>
Thu, 9 Oct 2003 22:25:53 +0000 (22:25 +0000)
Originally committed as revision 11069 to svn://svn.mplayerhq.hu/mplayer/trunk/postproc

postproc/rgb2rgb.c
postproc/rgb2rgb_template.c
postproc/swscale.c

index d12b421..770827c 100644 (file)
@@ -41,6 +41,9 @@ void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, unsigned src_size);
 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 @@ void sws_rgb2rgb_init(int flags){
                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 @@ void sws_rgb2rgb_init(int flags){
                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 @@ void sws_rgb2rgb_init(int flags){
                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 @@ void sws_rgb2rgb_init(int flags){
                rgb32tobgr16= rgb32tobgr16_C;
                rgb32tobgr15= rgb32tobgr15_C;
                yv12toyuy2= yv12toyuy2_C;
+               yv12touyvy= yv12touyvy_C;
                yuv422ptoyuy2= yuv422ptoyuy2_C;
                yuy2toyv12= yuy2toyv12_C;
 //             uyvytoyv12= uyvytoyv12_C;
index 85c8f44..acb53ea 100644 (file)
@@ -1568,6 +1568,64 @@ static inline void RENAME(yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc,
        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
index 4d24115..1685c69 100644 (file)
@@ -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 @@ untested special converters
                        || (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 @@ static inline void yuv2yuvXinC(int16_t *lumFilter, int16_t **lumSrc, int lumFilt
                        ((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 @@ static inline void yuv2packedXinC(SwsContext *c, int16_t *lumFilter, int16_t **l
                        ((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 @@ static int PlanarToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], i
        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 @@ SwsContext *sws_getContext(int srcW, int srcH, int origSrcFormat, int dstW, int
                                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;
                        }
                }