[FFmpeg-devel] [RFC] provide public interface to rgb2rgb.c

Reinhard Tartler siretart
Wed Jun 2 16:11:29 CEST 2010


Hi,

We all agree that mplayer shouldn't be using swscale internals, right?
This patch provides a public interface to the rgb2rgb functions. In
order to show how its supposed to be used, I've also adapted the parts
of mplayer that currently uses sws internals.

Is this the right approach? I know that I'm bad at finding names, so
feel free to suggest better names for the public typedefs and function
names.

Index: libswscale/swscale.h
===================================================================
--- libswscale/swscale.h	(revision 31303)
+++ libswscale/swscale.h	(working copy)
@@ -327,5 +327,70 @@
  */
 void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
 
+typedef void (*SWSrgbConverter) (const uint8_t *src, uint8_t *dst, long src_size);
 
+enum SWSrgbConverter {
+    sws_rgb24tobgr32,
+    sws_rgb24tobgr16,
+    sws_rgb24tobgr15,
+    sws_rgb32tobgr24,
+    sws_rgb32to16,
+    sws_rgb32to15,
+    sws_rgb15to16,
+    sws_rgb15tobgr24,
+    sws_rgb15to32,
+    sws_rgb16to15,
+    sws_rgb16tobgr24,
+    sws_rgb16to32,
+    sws_rgb24tobgr24,
+    sws_rgb24to16,
+    sws_rgb24to15,
+    sws_rgb32tobgr32,
+    sws_rgb32tobgr16,
+    sws_rgb32tobgr15,
+};
+
+typedef void (*SWSscaledYuvConverter) (const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
+                                       long width, long height,
+                                       long lumStride, long chromStride, long dstStride);
+
+enum SWSScaledConverter {
+    sws_yv12toyuy2,    //< Height should be a multiple of 2 and width should be a multiple of 16.
+    sws_yuv422ptoyuy2, //< Width should be a multiple of 16.
+    sws_yuy2toyv12,    //< Height should be a multiple of 2 and width should be a multiple of 16.
+    sws_yv12touyvy,    //< Height should be a multiple of 2 and width should be a multiple of 16.
+    sws_yuv422ptouyvy, //< Width should be a multiple of 16.
+    sws_rgb24toyv12,   //< Height should be a multiple of 2 and width should be a multiple of 2.
+//    sws_uyvytoyv12,    //< Height should be a multiple of 2 and width should be a multiple of 16.
+};
+
+
+typedef void (*SWSunscaledYuvConverter) (uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
+                     long width, long height,
+                     long lumStride, long chromStride, long srcStride);
+enum SWSUnscaledConverter {
+    sws_uyvytoyuv420,
+    sws_uyvytoyuv422,
+    sws_yuyvtoyuv420,
+    sws_yuyvtoyuv422,
+};
+
+/**
+ * @brief Initializes rgb2rgb functions.
+ *
+ * The caller is responsible to autodect the require cpu capabilities.
+ *
+ * @param flags   available CPU capabilites
+ */
+void sws_rgb2rgb_init(int flags);
+
+SWSrgbConverter* sws_getRgbConverter(enum SWSrgbConverter s);
+
+
+//< initilize with sws_rgb2rgb_init first
+SWSscaledYuvConverter* sws_getScaledYuvConverter(enum SWSScaledConverter s);
+
+//< initilize with sws_rgb2rgb_init first
+SWSunscaledYuvConverter* sws_getUnScaledYuvConverter(enum SWSScaledConverter s);
+
 #endif /* SWSCALE_SWSCALE_H */
Index: libmpcodecs/vf_rgb2bgr.c
===================================================================
--- libmpcodecs/vf_rgb2bgr.c	(revision 31303)
+++ libmpcodecs/vf_rgb2bgr.c	(working copy)
@@ -28,13 +28,16 @@
 #include "mp_image.h"
 #include "vf.h"
 
-#include "libswscale/rgb2rgb.h"
+#include "libswscale/swscale.h"
 
 //===========================================================================//
 
 struct vf_priv_s {
     unsigned int fmt;
     int forced;
+    SWSrgbConverter rgb24tobgr24;
+    SWSrgbConverter rgb32tobgr24;
+    SWSrgbConverter rgb32tobgr32;
 };
 
 static unsigned int getfmt(unsigned int outfmt,int forced){
@@ -76,17 +79,17 @@
 	int srcsize=mpi->w*mpi->bpp/8;
 	for(y=0;y<mpi->h;y++){
 	    if(mpi->bpp==32)
-		rgb32tobgr32(src,dst,srcsize);
+		vf->priv->rgb32tobgr32(src,dst,srcsize);
 	    else
-		rgb24tobgr24(src,dst,srcsize);
+		vf->priv->rgb24tobgr24(src,dst,srcsize);
 	    src+=mpi->stride[0];
 	    dst+=dmpi->stride[0];
 	}
     } else {
 	if(mpi->bpp==32)
-	    rgb32tobgr32(mpi->planes[0],dmpi->planes[0],mpi->w*mpi->h*4);
+	    vf->priv->rgb32tobgr32(mpi->planes[0],dmpi->planes[0],mpi->w*mpi->h*4);
 	else
-	    rgb24tobgr24(mpi->planes[0],dmpi->planes[0],mpi->w*mpi->h*3);
+	    vf->priv->rgb24tobgr24(mpi->planes[0],dmpi->planes[0],mpi->w*mpi->h*3);
     }
 
     return vf_next_put_image(vf,dmpi, pts);
@@ -106,6 +109,9 @@
     vf->query_format=query_format;
     vf->priv=malloc(sizeof(struct vf_priv_s));
     vf->priv->forced=args && !strcasecmp(args,"swap");
+    vf->priv->rgb32tobgr32 = sws_getRgbConverter(sws_rgb32tobgr32);
+    vf->priv->rgb32tobgr24 = sws_getRgbConverter(sws_rgb32tobgr24);
+    vf->priv->rgb32tobgr24 = sws_getRgbConverter(sws_rgb24tobgr24);
     return 1;
 }
 
Index: libvo/vo_yuv4mpeg.c
===================================================================
--- libvo/vo_yuv4mpeg.c	(revision 31303)
+++ libvo/vo_yuv4mpeg.c	(working copy)
@@ -56,7 +56,6 @@
 
 #include "fastmemcpy.h"
 #include "libswscale/swscale.h"
-#include "libswscale/rgb2rgb.h"
 #include "libmpcodecs/vf_scale.h"
 #include "libavutil/rational.h"
 
@@ -88,6 +87,8 @@
 static FILE *yuv_out;
 static int write_bytes;
 
+static SWSscaledYuvConverter rgb24toyv12;
+
 #define Y4M_ILACE_NONE         'p'  /* non-interlaced, progressive frame */
 #define Y4M_ILACE_TOP_FIRST    't'  /* interlaced, top-field first       */
 #define Y4M_ILACE_BOTTOM_FIRST 'b'  /* interlaced, bottom-field first    */
@@ -528,6 +529,8 @@
     return -1;
   }
 
+  rgb24toyv12 = sws_getRgbConverter(sws_rgb24toyv12);
+
   config_interlace = Y4M_ILACE_NONE;
   if (il)
     config_interlace = Y4M_ILACE_TOP_FIRST;
Index: libswscale/swscale.c
===================================================================
--- libswscale/swscale.c	(revision 31303)
+++ libswscale/swscale.c	(working copy)
@@ -1980,3 +1980,45 @@
         dst+= 3;
     }
 }
+
+#define CHECK_CONVERTER(x) if (s == sws_##x) return x
+SWSrgbConverter* sws_getRgbConverter(enum SWSrgbConverter s) {
+    CHECK_CONVERTER(rgb24tobgr32);
+    CHECK_CONVERTER(rgb24tobgr16);
+    CHECK_CONVERTER(rgb24tobgr15);
+    CHECK_CONVERTER(rgb32tobgr24);
+    CHECK_CONVERTER(rgb32to16);
+    CHECK_CONVERTER(rgb32to15);
+    CHECK_CONVERTER(rgb15to16);
+    CHECK_CONVERTER(rgb15tobgr24);
+    CHECK_CONVERTER(rgb15to32);
+    CHECK_CONVERTER(rgb16to15);
+    CHECK_CONVERTER(rgb16tobgr24);
+    CHECK_CONVERTER(rgb16to32);
+    CHECK_CONVERTER(rgb24tobgr24);
+    CHECK_CONVERTER(rgb24to16);
+    CHECK_CONVERTER(rgb24to15);
+    CHECK_CONVERTER(rgb32tobgr32);
+    CHECK_CONVERTER(rgb32tobgr16);
+    CHECK_CONVERTER(rgb32tobgr15);
+    return NULL;
+};
+
+SWSscaledYuvConverter* sws_getScaledYuvConverter(enum SWSScaledConverter s) {
+    CHECK_CONVERTER(yv12toyuy2);
+    CHECK_CONVERTER(yuv422ptoyuy2);
+    CHECK_CONVERTER(yuy2toyv12);
+    CHECK_CONVERTER(yv12touyvy);
+    CHECK_CONVERTER(yuv422ptouyvy);
+    CHECK_CONVERTER(rgb24toyv12);
+    //     CHECK_CONVERTER(uyvytoyv12);
+    return NULL;
+};
+
+SWSunscaledYuvConverter* sws_getUnScaledYuvConverter(enum SWSScaledConverter s) {
+    CHECK_CONVERTER(uyvytoyuv420);
+    CHECK_CONVERTER(uyvytoyuv422);
+    CHECK_CONVERTER(yuyvtoyuv420);
+    CHECK_CONVERTER(yuyvtoyuv422);
+    return NULL;
+};
Index: libswscale/rgb2rgb.h
===================================================================
--- libswscale/rgb2rgb.h	(revision 31303)
+++ libswscale/rgb2rgb.h	(working copy)
@@ -167,6 +167,5 @@
                             long width, long height,
                             long lumStride, long chromStride, long srcStride);
 
-void sws_rgb2rgb_init(int flags);
 
 #endif /* SWSCALE_RGB2RGB_H */


-- 
Gruesse/greetings,
Reinhard Tartler, KeyID 945348A4




More information about the ffmpeg-devel mailing list