changeset 35049:a0ff4fde7a48

Add helper function to reduce code duplication for selecting correct OSD drawing function.
author reimar
date Sun, 02 Sep 2012 21:17:03 +0000
parents 638d1f3bd87f
children b291f44d864a
files sub/osd.c sub/osd.h
diffstat 2 files changed, 36 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sub/osd.c	Sat Sep 01 16:54:53 2012 +0000
+++ b/sub/osd.c	Sun Sep 02 21:17:03 2012 +0000
@@ -27,6 +27,8 @@
 #include "osd.h"
 #include "mp_msg.h"
 #include <inttypes.h>
+#include <stdlib.h>
+#include "libmpcodecs/img_format.h"
 #include "cpudetect.h"
 
 #if ARCH_X86
@@ -426,3 +428,34 @@
     }
     return;
 }
+
+vo_draw_alpha_func vo_get_draw_alpha(unsigned fmt) {
+    if (IMGFMT_IS_RGB(fmt) || IMGFMT_IS_BGR(fmt)) {
+        switch (IMGFMT_RGB_DEPTH(fmt))
+        {
+        case 12:
+            return vo_draw_alpha_rgb12;
+        case 15:
+            return vo_draw_alpha_rgb15;
+        case 16:
+            return vo_draw_alpha_rgb16;
+        case 24:
+            return vo_draw_alpha_rgb24;
+        case 32:
+            return vo_draw_alpha_rgb32;
+        }
+        return NULL;
+    }
+    switch (fmt) {
+    case IMGFMT_YV12:
+    case IMGFMT_I420:
+    case IMGFMT_IYUV:
+        return vo_draw_alpha_yv12;
+    case IMGFMT_YUY2:
+    case IMGFMT_YVYU:
+        return vo_draw_alpha_yuy2;
+    case IMGFMT_UYVY:
+        return vo_draw_alpha_uyvy;
+    }
+    return NULL;
+}
--- a/sub/osd.h	Sat Sep 01 16:54:53 2012 +0000
+++ b/sub/osd.h	Sun Sep 02 21:17:03 2012 +0000
@@ -24,6 +24,9 @@
 
 void vo_draw_alpha_init(void); // build tables
 
+typedef void (*vo_draw_alpha_func)(int, int, unsigned char *, unsigned char *, int, unsigned char *, int);
+vo_draw_alpha_func vo_get_draw_alpha(unsigned fmt);
+
 void vo_draw_alpha_yv12(int w,  int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase, int dststride);
 void vo_draw_alpha_yuy2(int w,  int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase, int dststride);
 void vo_draw_alpha_uyvy(int w,  int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase, int dststride);