[MPlayer-dev-eng] [PATCH] restructure fmt-conversion.h and use it in vd_ffmpeg.c

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat Feb 14 10:24:41 CET 2009


Hello,
seems obvious to me that it is better not to duplicate the PixelFormat
-> IMGFMT mapping...

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpcodecs/vd_ffmpeg.c
===================================================================
--- libmpcodecs/vd_ffmpeg.c	(revision 28546)
+++ libmpcodecs/vd_ffmpeg.c	(working copy)
@@ -11,6 +11,7 @@
 #include "libavutil/common.h"
 #include "libavutil/intreadwrite.h"
 #include "mpbswap.h"
+#include "fmt-conversion.h"
 
 #include "vd_internal.h"
 
@@ -498,33 +499,7 @@
         sh->disp_w = width;
         sh->disp_h = height;
         ctx->pix_fmt = pix_fmt;
-        switch(pix_fmt){
-        // YUVJ are YUV formats that use the full Y range and not just
-        // 16 - 235 (see colorspaces.txt).
-        // Currently they are all treated the same way.
-        case PIX_FMT_YUV410P: ctx->best_csp=IMGFMT_YVU9;break; //svq1
-        case PIX_FMT_YUVJ420P:
-        case PIX_FMT_YUV420P: ctx->best_csp=IMGFMT_YV12;break; //mpegs
-        case PIX_FMT_YUVJ422P:
-        case PIX_FMT_YUV422P: ctx->best_csp=IMGFMT_422P;break; //mjpeg / huffyuv
-        case PIX_FMT_YUVJ444P:
-        case PIX_FMT_YUV444P: ctx->best_csp=IMGFMT_444P;break; //photo jpeg
-        case PIX_FMT_YUV411P: ctx->best_csp=IMGFMT_411P;break; //dv ntsc
-        case PIX_FMT_YUYV422: ctx->best_csp=IMGFMT_YUY2;break; //huffyuv perhaps in the future
-        case PIX_FMT_RGB24 :  ctx->best_csp=IMGFMT_RGB24;break; //qtrle
-        case PIX_FMT_RGB32:   ctx->best_csp=IMGFMT_BGR32;break; //huffyuv / mjpeg
-        case PIX_FMT_BGR24 :  ctx->best_csp=IMGFMT_BGR24;break; //8bps
-        case PIX_FMT_RGB555:  ctx->best_csp=IMGFMT_BGR15;break; //rpza,cram
-        case PIX_FMT_RGB565:  ctx->best_csp=IMGFMT_BGR16;break; //4xm
-        case PIX_FMT_GRAY8:   ctx->best_csp=IMGFMT_Y800;break; // gray jpeg
-        case PIX_FMT_PAL8:    ctx->best_csp=IMGFMT_BGR8;break; //8bps,mrle,cram
-#if CONFIG_XVMC
-        case PIX_FMT_XVMC_MPEG2_MC:ctx->best_csp=IMGFMT_XVMC_MOCO_MPEG2;break;
-        case PIX_FMT_XVMC_MPEG2_IDCT:ctx->best_csp=IMGFMT_XVMC_IDCT_MPEG2;break;
-#endif
-        default:
-            ctx->best_csp=0;
-        }
+        ctx->best_csp = pixfmt2imgfmt(pix_fmt);
             if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h, ctx->best_csp))
                     return -1;
         ctx->vo_initialized = 1;
Index: fmt-conversion.c
===================================================================
--- fmt-conversion.c	(revision 0)
+++ fmt-conversion.c	(revision 0)
@@ -0,0 +1,76 @@
+#include "mp_msg.h"
+#include "libavutil/avutil.h"
+#include "libmpcodecs/img_format.h"
+
+static const struct {
+    int fmt;
+    enum PixelFormat pix_fmt;
+} conversion_map[] = {
+    {IMGFMT_BGR32, PIX_FMT_RGB32},
+    {IMGFMT_BGR24, PIX_FMT_BGR24},
+    {IMGFMT_BGR16, PIX_FMT_RGB565},
+    {IMGFMT_BGR8,  PIX_FMT_RGB8},
+    {IMGFMT_BGR4,  PIX_FMT_RGB4},
+    {IMGFMT_BGR1,  PIX_FMT_MONOBLACK},
+    {IMGFMT_RGB1,  PIX_FMT_MONOBLACK},
+    {IMGFMT_RG4B,  PIX_FMT_BGR4_BYTE},
+    {IMGFMT_BG4B,  PIX_FMT_RGB4_BYTE},
+    {IMGFMT_RGB32, PIX_FMT_BGR32},
+    {IMGFMT_RGB24, PIX_FMT_RGB24},
+    {IMGFMT_RGB16, PIX_FMT_BGR565},
+    {IMGFMT_RGB15, PIX_FMT_BGR555},
+    {IMGFMT_RGB8,  PIX_FMT_BGR8},
+    {IMGFMT_RGB4,  PIX_FMT_BGR4},
+    {IMGFMT_BGR8,  PIX_FMT_PAL8},
+    {IMGFMT_YUY2,  PIX_FMT_YUYV422},
+    {IMGFMT_UYVY,  PIX_FMT_UYVY422},
+    {IMGFMT_NV12,  PIX_FMT_NV12},
+    {IMGFMT_NV21,  PIX_FMT_NV21},
+    {IMGFMT_Y800,  PIX_FMT_GRAY8},
+    {IMGFMT_Y8,    PIX_FMT_GRAY8},
+    {IMGFMT_YVU9,  PIX_FMT_YUV410P},
+    {IMGFMT_IF09,  PIX_FMT_YUV410P},
+    {IMGFMT_YV12,  PIX_FMT_YUV420P},
+    {IMGFMT_YV12,  PIX_FMT_YUVJ420P},
+    {IMGFMT_I420,  PIX_FMT_YUV420P},
+    {IMGFMT_IYUV,  PIX_FMT_YUV420P},
+    {IMGFMT_411P,  PIX_FMT_YUV411P},
+    {IMGFMT_422P,  PIX_FMT_YUV422P},
+    {IMGFMT_422P,  PIX_FMT_YUVJ422P},
+    {IMGFMT_444P,  PIX_FMT_YUV444P},
+    {IMGFMT_444P,  PIX_FMT_YUVJ444P},
+    {IMGFMT_XVMC_MOCO_MPEG2, PIX_FMT_XVMC_MPEG2_MC},
+    {IMGFMT_XVMC_IDCT_MPEG2, PIX_FMT_XVMC_MPEG2_IDCT},
+    {IMGFMT_VDPAU_MPEG1,     PIX_FMT_VDPAU_MPEG1},
+    {IMGFMT_VDPAU_MPEG2,     PIX_FMT_VDPAU_MPEG2},
+    {IMGFMT_VDPAU_H264,      PIX_FMT_VDPAU_H264},
+    {IMGFMT_VDPAU_WMV3,      PIX_FMT_VDPAU_WMV3},
+    {IMGFMT_VDPAU_VC1,       PIX_FMT_VDPAU_VC1},
+    {0, PIX_FMT_NONE}
+};
+
+enum PixelFormat imgfmt2pixfmt(int fmt)
+{
+    int i;
+    enum PixelFormat pix_fmt;
+    for (i = 0; conversion_map[i].fmt; i++)
+        if (conversion_map[i].fmt == fmt)
+            break;
+    pix_fmt = conversion_map[i].pix_fmt;
+    if (pix_fmt == PIX_FMT_NONE)
+        mp_msg(MSGT_GLOBAL, MSGL_ERR, "Unsupported format %s\n", vo_format_name(fmt));
+    return pix_fmt;
+}
+
+int pixfmt2imgfmt(enum PixelFormat pix_fmt)
+{
+    int i;
+    int fmt;
+    for (i = 0; conversion_map[i].pix_fmt != PIX_FMT_NONE; i++)
+        if (conversion_map[i].pix_fmt == pix_fmt)
+            break;
+    fmt = conversion_map[i].fmt;
+    if (!fmt)
+        mp_msg(MSGT_GLOBAL, MSGL_ERR, "Unsupported PixelFormat %i\n", pix_fmt);
+    return fmt;
+}
Index: fmt-conversion.h
===================================================================
--- fmt-conversion.h	(revision 28546)
+++ fmt-conversion.h	(working copy)
@@ -1,73 +1,9 @@
 #ifndef MPLAYER_FMT_CONVERSION_H
 #define MPLAYER_FMT_CONVERSION_H
 
-#include <stdio.h>
 #include "libavutil/avutil.h"
-#include "libmpcodecs/img_format.h"
 
-enum PixelFormat imgfmt2pixfmt(int fmt)
-{
-    switch (fmt) {
-        case IMGFMT_BGR32:
-            return PIX_FMT_RGB32;
-        case IMGFMT_BGR24:
-            return PIX_FMT_BGR24;
-        case IMGFMT_BGR16:
-            return PIX_FMT_RGB565;
-        case IMGFMT_BGR15:
-            return PIX_FMT_RGB555;
-        case IMGFMT_BGR8:
-            return PIX_FMT_RGB8;
-        case IMGFMT_BGR4:
-            return PIX_FMT_RGB4;
-        case IMGFMT_BGR1:
-        case IMGFMT_RGB1:
-            return PIX_FMT_MONOBLACK;
-        case IMGFMT_RG4B:
-            return PIX_FMT_BGR4_BYTE;
-        case IMGFMT_BG4B:
-            return PIX_FMT_RGB4_BYTE;
-        case IMGFMT_RGB32:
-            return PIX_FMT_BGR32;
-        case IMGFMT_RGB24:
-            return PIX_FMT_RGB24;
-        case IMGFMT_RGB16:
-            return PIX_FMT_BGR565;
-        case IMGFMT_RGB15:
-            return PIX_FMT_BGR555;
-        case IMGFMT_RGB8:
-            return PIX_FMT_BGR8;
-        case IMGFMT_RGB4:
-            return PIX_FMT_BGR4;
-        case IMGFMT_YUY2:
-            return PIX_FMT_YUYV422;
-        case IMGFMT_UYVY:
-            return PIX_FMT_UYVY422;
-        case IMGFMT_NV12:
-            return PIX_FMT_NV12;
-        case IMGFMT_NV21:
-            return PIX_FMT_NV21;
-        case IMGFMT_Y800:
-        case IMGFMT_Y8:
-            return PIX_FMT_GRAY8;
-        case IMGFMT_IF09:
-        case IMGFMT_YVU9:
-            return PIX_FMT_YUV410P;
-        case IMGFMT_I420:
-        case IMGFMT_IYUV:
-        case IMGFMT_YV12:
-            return PIX_FMT_YUV420P;
-        case IMGFMT_411P:
-            return PIX_FMT_YUV411P;
-        case IMGFMT_422P:
-            return PIX_FMT_YUV422P;
-        case IMGFMT_444P:
-            return PIX_FMT_YUV444P;
-        default:
-            fprintf(stderr, "Unsupported format %s\n", vo_format_name(fmt));
-    }
+enum PixelFormat imgfmt2pixfmt(int fmt);
+int imgfmt2pixfmt(enum PixelFormat pix_fmt);
 
-    return PIX_FMT_NONE;
-}
-
 #endif /* MPLAYER_FMT_CONVERSION_H */
Index: Makefile
===================================================================
--- Makefile	(revision 28546)
+++ Makefile	(working copy)
@@ -38,6 +38,7 @@
               cpudetect.c \
               edl.c \
               find_sub.c \
+              fmt-conversion.c \
               get_path.c \
               m_config.c \
               m_option.c \


More information about the MPlayer-dev-eng mailing list