changeset 28526:21efa4282730

Create a fmt-conversion.c file so fmt-conversion.h can be included by multiple files. Also restructure the code so it provides a pixfmt2imgfmt function, too.
author reimar
date Sat, 14 Feb 2009 17:57:47 +0000
parents 1e671b7bf2e0
children 90da3cbfbdd9
files Makefile fmt-conversion.c fmt-conversion.h
diffstat 3 files changed, 98 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sat Feb 14 17:43:06 2009 +0000
+++ b/Makefile	Sat Feb 14 17:57:47 2009 +0000
@@ -38,6 +38,7 @@
               cpudetect.c \
               edl.c \
               find_sub.c \
+              fmt-conversion.c \
               get_path.c \
               m_config.c \
               m_option.c \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fmt-conversion.c	Sat Feb 14 17:57:47 2009 +0000
@@ -0,0 +1,95 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "mp_msg.h"
+#include "libavutil/avutil.h"
+#include "libmpcodecs/img_format.h"
+#include "fmt-conversion.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;
+}
--- a/fmt-conversion.h	Sat Feb 14 17:43:06 2009 +0000
+++ b/fmt-conversion.h	Sat Feb 14 17:57:47 2009 +0000
@@ -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));
-    }
-
-    return PIX_FMT_NONE;
-}
+enum PixelFormat imgfmt2pixfmt(int fmt);
+int pixfmt2imgfmt(enum PixelFormat pix_fmt);
 
 #endif /* MPLAYER_FMT_CONVERSION_H */