[MPlayer-dev-eng] [PATCH] vidix ckey support & cvidix aspect

Jake Page jake at CS.Stanford.EDU
Thu Oct 16 01:26:15 CEST 2003


Hey,

Included is a patch to add -colorkey support for several of the 
vidix ([fbdev,vesa,svga]:vidix, cvidix) output drivers.

The only slightly non-standard part of it is that I allowed disabling 
colorkey support entirely by setting the MSbyte to a non-zero value, ie:

"mplayer -colorkey 0x01000000" will disable colorkeying so the video will 
always show through.  I think this is important when using vidix on
the console since often you want the overlay to be 100% visible over the 
contents of the framebuffer.

I'm wondering if it would be better to turn off colorkeying by default on 
these?  One implementation could be to use above method, set vo_colorkey = 
0x0100FF00 as default, then have drivers that always use ckeying 
(vo_xvidix for example) ignore/discard the MSB, if necessary.

This patch also has aspect/fullscreen support added to the cvidix driver.
The code is almost identical to the fbdev:vidix aspect code.
Since cvidix doesn't know anything about the screen resolution, I added
parameters to the -vo line to allow for example:

"mplayer -vo cvidix:width=1024:height=768"

The default is 640x480 (same as it was previously).

-Jake
-------------- next part --------------
Index: libvo/vo_cvidix.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_cvidix.c,v
retrieving revision 1.3
diff -u -r1.3 vo_cvidix.c
--- libvo/vo_cvidix.c	5 Oct 2003 15:39:00 -0000	1.3
+++ libvo/vo_cvidix.c	15 Oct 2003 22:59:27 -0000
@@ -18,6 +18,7 @@
 #include "video_out.h"
 #include "video_out_internal.h"
 
+#include "aspect.h"
 #include "mp_msg.h"
 
 #include "vosub_vidix.h"
@@ -38,18 +39,64 @@
 /* VIDIX related */
 static char *vidix_name;
 
+/* "screen" dimensions */
+static int screen_xres = 640;
+static int screen_yres = 480;
+
+static int fs;
 
 static vidix_grkey_t gr_key;
     
 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width,uint32_t d_height, uint32_t flags, char *title, uint32_t format){
-  if(vidix_init(width, height, 0, 0, d_width, d_height, format, 32, 640, 480))mp_msg(MSGT_VO, MSGL_FATAL, "Can't initialize VIDIX driver: %s\n", strerror(errno));
-  /*set colorkey*/       
+
+  int image_width,image_height,x_offset,y_offset;
+  int zoom = flags & 0x04;
+
+  fs = flags & 0x01;
+
+  if (zoom || fs) {
+      aspect_save_orig(width,height);
+      aspect_save_prescale(d_width,d_height);
+      aspect_save_screenres(screen_xres,screen_yres);
+      aspect(&image_width,&image_height,fs ? A_ZOOM : A_NOZOOM);    
+  } else {
+      image_width = width;
+      image_height = height;
+  }
+
+  if(screen_xres > image_width)
+      x_offset = (screen_xres - image_width) / 2;
+  else x_offset = 0;
+  if(screen_yres > image_height)
+      y_offset = (screen_yres - image_height) / 2;
+  else y_offset = 0;
+
+  if(vidix_init(width, height, x_offset, y_offset, image_width,
+		image_height, format, 32, screen_xres, screen_yres)) {
+      mp_msg(MSGT_VO, MSGL_FATAL, "Can't initialize VIDIX driver: %s\n",
+	     strerror(errno));
+      return -1;
+  }
+
   vidix_start();
-  if(vidix_grkey_support()){
+
+  /*set colorkey*/       
+  if(vidix_grkey_support()) {
     vidix_grkey_get(&gr_key);
-    gr_key.key_op = KEYS_PUT;
-    gr_key.ckey.op = CKEY_TRUE;
-    gr_key.ckey.red = gr_key.ckey.green = gr_key.ckey.blue = 0;
+    if (!(vo_colorkey & 0xFF000000)) {
+	gr_key.key_op = KEYS_PUT;
+	gr_key.ckey.op = CKEY_TRUE;
+	gr_key.ckey.red = (vo_colorkey & 0x00FF0000) >> 16;
+	gr_key.ckey.green = (vo_colorkey & 0x0000FF00) >> 8;
+	gr_key.ckey.blue = vo_colorkey & 0x000000FF;
+	mp_msg(MSGT_VO, MSGL_DBG2, "using colorkey 0x%X\n", vo_colorkey);
+    } else {
+	gr_key.key_op = KEYS_PUT;
+	gr_key.ckey.op = CKEY_FALSE;
+	gr_key.ckey.red = 0x00;
+	gr_key.ckey.green = 0x00;
+	gr_key.ckey.blue = 0x00;
+    }
     vidix_grkey_set(&gr_key);
   }         
   return 0;
@@ -101,10 +148,38 @@
 }
 
 static uint32_t preinit(const char *arg){
-  if(arg)vidix_name = strdup(arg);
-  else {
+  int i;
+  char* endptr = NULL;
+
+  vidix_name = NULL;
+  if(arg) {
+    while(*arg) {
+      if (!strncmp(arg, "width=", 6)) {
+	arg += 6;
+	screen_xres = strtoul(arg, &endptr, 10);
+	if (arg == endptr) {
+	  screen_xres = 640;
+	}
+	arg = endptr;
+      } else if (!strncmp(arg, "height=", 7)) {
+	arg += 7;
+	screen_yres = strtoul(arg, &endptr, 10);
+	if (arg == endptr) {
+	  screen_yres = 480;
+	}
+	arg = endptr;
+      } else {
+	i = 0;
+	while(arg[i] && arg[i] != ':') i++;
+	if (i > 0)
+	  vidix_name = strndup(arg, i);
+	arg += i;
+      }
+      if (*arg == ':')
+	arg++;
+    }
+  } else {
     mp_msg(MSGT_VO, MSGL_INFO, "vo_cvidix: No vidix driver name provided, probing available ones!\n");
-	vidix_name = NULL;
   }
   if(vidix_preinit(vidix_name, &video_out_cvidix))return 1;
   return 0;
Index: libvo/vo_fbdev.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_fbdev.c,v
retrieving revision 1.85
diff -u -r1.85 vo_fbdev.c
--- libvo/vo_fbdev.c	8 Oct 2003 10:58:44 -0000	1.85
+++ libvo/vo_fbdev.c	15 Oct 2003 22:59:28 -0000
@@ -42,6 +42,7 @@
 #ifdef CONFIG_VIDIX
 /* Name of VIDIX driver */
 static const char *vidix_name = NULL;
+static vidix_grkey_t gr_key;
 #endif
 static signed int pre_init_err = -2;
 /******************************
@@ -568,6 +569,7 @@
 static uint32_t pixel_format;
 static int fs;
 
+
 /*
  * Note: this function is completely cut'n'pasted from
  * Chris Lawrence's code.
@@ -958,24 +960,46 @@
 		image_height=height;
 	    }
 
-		if(fb_xres > image_width)
-		    x_offset = (fb_xres - image_width) / 2;
-		else x_offset = 0;
-		if(fb_yres > image_height)
-		    y_offset = (fb_yres - image_height) / 2;
-		else y_offset = 0;
-
-		if(vidix_init(width,height,x_offset,y_offset,image_width,
-			    image_height,format,fb_bpp,
-			    fb_xres,fb_yres) != 0)
+	    if(fb_xres > image_width)
+		x_offset = (fb_xres - image_width) / 2;
+	    else x_offset = 0;
+	    if(fb_yres > image_height)
+		y_offset = (fb_yres - image_height) / 2;
+	    else y_offset = 0;
+	    
+	    if(vidix_init(width,height,x_offset,y_offset,image_width,
+			  image_height,format,fb_bpp,
+			  fb_xres,fb_yres) != 0)
 		{
 		    mp_msg(MSGT_VO, MSGL_ERR, "Can't initialize VIDIX driver\n");
 		    vidix_name = NULL;
 		    vidix_term();
 		    return -1;
 		}
-		else mp_msg(MSGT_VO, MSGL_V, "Using VIDIX\n");
-		vidix_start();
+	    else mp_msg(MSGT_VO, MSGL_V, "Using VIDIX\n");
+	    vidix_start();
+	    
+	    /*set colorkey*/       
+	    if(vidix_grkey_support()) {
+		vidix_grkey_get(&gr_key);
+		if (!(vo_colorkey & 0xFF000000)) {
+		    gr_key.key_op = KEYS_PUT;
+		    gr_key.ckey.op = CKEY_TRUE;
+		    gr_key.ckey.red = (vo_colorkey & 0x00FF0000) >> 16;
+		    gr_key.ckey.green = (vo_colorkey & 0x0000FF00) >> 8;
+		    gr_key.ckey.blue = vo_colorkey & 0x000000FF;
+		    mp_msg(MSGT_VO, MSGL_DBG2, "using colorkey 0x%X\n",
+			   vo_colorkey);
+		} else {
+		    gr_key.key_op = KEYS_PUT;
+		    gr_key.ckey.op = CKEY_FALSE;
+		    gr_key.ckey.red = 0x00;
+		    gr_key.ckey.green = 0x00;
+		    gr_key.ckey.blue = 0x00;
+		}
+		vidix_grkey_set(&gr_key);
+	    }
+
 	}
 	else
 #endif
Index: libvo/vo_svga.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_svga.c,v
retrieving revision 1.71
diff -u -r1.71 vo_svga.c
--- libvo/vo_svga.c	4 Oct 2003 17:29:04 -0000	1.71
+++ libvo/vo_svga.c	15 Oct 2003 22:59:28 -0000
@@ -105,6 +105,7 @@
 
 #ifdef CONFIG_VIDIX

 static char vidix_name[32] = "";

+static vidix_grkey_t gr_key;
 #endif

 

 LIBVO_EXTERN(svga)
@@ -526,6 +527,25 @@
     printf("vo_svga: Using VIDIX. w=%i h=%i  mw=%i mh=%i\n",width,height,
            modeinfo->width,modeinfo->height);

     vidix_start();

+    /*set colorkey*/       
+    if(vidix_grkey_support()) {
+      vidix_grkey_get(&gr_key);
+      if (!(vo_colorkey & 0xFF000000)) {
+	gr_key.key_op = KEYS_PUT;
+	gr_key.ckey.op = CKEY_TRUE;
+	gr_key.ckey.red = (vo_colorkey & 0x00FF0000) >> 16;
+	gr_key.ckey.green = (vo_colorkey & 0x0000FF00) >> 8;
+	gr_key.ckey.blue = vo_colorkey & 0x000000FF;
+	mp_msg(MSGT_VO, MSGL_DBG2, "using colorkey 0x%X\n", vo_colorkey);
+      } else {
+	gr_key.key_op = KEYS_PUT;
+	gr_key.ckey.op = CKEY_FALSE;
+	gr_key.ckey.red = 0x00;
+	gr_key.ckey.green = 0x00;
+	gr_key.ckey.blue = 0x00;
+      }
+      vidix_grkey_set(&gr_key);
+    }         
   }

 #endif    

 
Index: libvo/vo_vesa.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_vesa.c,v
retrieving revision 1.95
diff -u -r1.95 vo_vesa.c
--- libvo/vo_vesa.c	31 Aug 2003 18:33:02 -0000	1.95
+++ libvo/vo_vesa.c	15 Oct 2003 22:59:29 -0000
@@ -120,6 +120,7 @@
 #ifdef CONFIG_VIDIX
 static const char *vidix_name = NULL;
 static int vidix_opened = 0;
+static vidix_grkey_t gr_key;
 #endif
 
 #define HAS_DGA()  (win.idx == -1)
@@ -958,6 +959,25 @@
 		  }
 		  else printf("vo_vesa: Using VIDIX\n");
 		  vidix_start();
+
+		  /* set colorkey */       
+		  if(vidix_grkey_support()) {
+		      vidix_grkey_get(&gr_key);
+		      if (!(vo_colorkey & 0xFF000000)) {
+			  gr_key.key_op = KEYS_PUT;
+			  gr_key.ckey.op = CKEY_TRUE;
+			  gr_key.ckey.red = (vo_colorkey & 0x00FF0000) >> 16;
+			  gr_key.ckey.green = (vo_colorkey & 0x0000FF00) >> 8;
+			  gr_key.ckey.blue = vo_colorkey & 0x000000FF;
+		      } else {
+			  gr_key.key_op = KEYS_PUT;
+			  gr_key.ckey.op = CKEY_FALSE;
+			  gr_key.ckey.red = 0x00;
+			  gr_key.ckey.green = 0x00;
+			  gr_key.ckey.blue = 0x00;
+		      }
+		      vidix_grkey_set(&gr_key);
+		  }         
 		  vidix_opened = 1;
 		}
 #endif


More information about the MPlayer-dev-eng mailing list