[MPlayer-cvslog] r32478 - in trunk: DOCS/tech/slave.txt command.c input/input.c input/input.h

cigaes subversion at mplayerhq.hu
Sun Oct 10 11:30:42 CEST 2010


Author: cigaes
Date: Sun Oct 10 11:30:42 2010
New Revision: 32478

Log:
Add the overlay_add and overlay_remove commands.

Modified:
   trunk/DOCS/tech/slave.txt
   trunk/command.c
   trunk/input/input.c
   trunk/input/input.h

Modified: trunk/DOCS/tech/slave.txt
==============================================================================
--- trunk/DOCS/tech/slave.txt	Sun Oct 10 11:27:11 2010	(r32477)
+++ trunk/DOCS/tech/slave.txt	Sun Oct 10 11:30:42 2010	(r32478)
@@ -472,6 +472,13 @@ vo_rootwin [value]
 volume <value> [abs]
     Increase/decrease volume or set it to <value> if [abs] is nonzero.
 
+overlay_add <file> <id> <x> <y> <color>
+    Add an overlay bitmap. <file> must be a PGM file without comments.
+    <id> is an arbitrary integer used to identify the overlay.
+
+overlay_remove <id>
+    Remove all overlays identified by <id>.
+
 
 The following commands are really only useful for OSD menu console mode:
 

Modified: trunk/command.c
==============================================================================
--- trunk/command.c	Sun Oct 10 11:27:11 2010	(r32477)
+++ trunk/command.c	Sun Oct 10 11:30:42 2010	(r32478)
@@ -62,6 +62,7 @@
 #include "m_struct.h"
 #include "libmenu/menu.h"
 #include "gui/interface.h"
+#include "eosd.h"
 
 #include "mp_core.h"
 #include "mp_fifo.h"
@@ -2492,6 +2493,70 @@ static void remove_subtitle_range(MPCont
     }
 }
 
+static int overlay_source_registered = 0;
+static struct mp_eosd_source overlay_source = {
+    .z_index = 5,
+};
+
+static void overlay_add(char *file, int id, int x, int y, unsigned col)
+{
+    FILE *f;
+    unsigned w, h, nc;
+    unsigned char *data;
+    struct mp_eosd_image *img;
+
+    if (!(f = fopen(file, "r"))) {
+        mp_msg(MSGT_CPLAYER, MSGL_ERR, "overlay_add: unable to open file.\n");
+        return;
+    }
+    if (fscanf(f, "P5\n%d %d\n%d\n", &w, &h, &nc) != 3 || nc != 255) {
+        mp_msg(MSGT_CPLAYER, MSGL_ERR, "overlay_add: unable to parse file.\n");
+        fclose(f);
+        return;
+    }
+    data = malloc(w * h);
+    if (fread(data, 1, w * h, f) != w * h) {
+        mp_msg(MSGT_CPLAYER, MSGL_ERR, "overlay_add: unable to read file.\n");
+        fclose(f);
+        return;
+    }
+    if (!overlay_source_registered) {
+        eosd_register(&overlay_source);
+        eosd_image_remove_all(&overlay_source);
+        overlay_source_registered = 1;
+    }
+    fclose(f);
+    img = eosd_image_alloc();
+    img->w      = w;
+    img->h      = h;
+    img->stride = w;
+    img->bitmap = data;
+    img->color  = col ^ 0xFF; /* col is RGBA, img->color is RGBT */
+    img->dst_x  = x;
+    img->dst_y  = y;
+    img->opaque = (void *)id;
+    eosd_image_append(&overlay_source, img);
+    overlay_source.changed = EOSD_CHANGED_BITMAP;
+}
+
+static void overlay_remove(int id)
+{
+    struct mp_eosd_image *img, **prev, *next;
+    prev = &overlay_source.images;
+    img  = overlay_source.images;
+    while (img) {
+        next = img->next;
+        if ((int)img->opaque == id) {
+            free(img->bitmap);
+            eosd_image_remove(&overlay_source, img, prev);
+            overlay_source.changed = EOSD_CHANGED_BITMAP;
+        } else {
+            prev = &img->next;
+        }
+        img  = next;
+    }
+}
+
 int run_command(MPContext *mpctx, mp_cmd_t *cmd)
 {
     sh_audio_t * const sh_audio = mpctx->sh_audio;
@@ -3060,6 +3125,17 @@ int run_command(MPContext *mpctx, mp_cmd
                                  &(cmd->args[0].v.i));
             break;
         }
+        case MP_CMD_OVERLAY_ADD:
+        {
+            overlay_add(cmd->args[0].v.s, cmd->args[1].v.i,
+                        cmd->args[2].v.i, cmd->args[3].v.i, cmd->args[4].v.i);
+            break;
+        }
+        case MP_CMD_OVERLAY_REMOVE:
+        {
+            overlay_remove(cmd->args[0].v.i);
+            break;
+        }
 
         case MP_CMD_SUB_LOAD:
             if (sh_video) {

Modified: trunk/input/input.c
==============================================================================
--- trunk/input/input.c	Sun Oct 10 11:27:11 2010	(r32477)
+++ trunk/input/input.c	Sun Oct 10 11:30:42 2010	(r32478)
@@ -176,6 +176,8 @@ static const mp_cmd_t mp_cmds[] = {
   { MP_CMD_VF_CHANGE_RECTANGLE, "change_rectangle", 2, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}}}},
   { MP_CMD_TV_TELETEXT_ADD_DEC, "teletext_add_dec", 1, { {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } },
   { MP_CMD_TV_TELETEXT_GO_LINK, "teletext_go_link", 1, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
+  { MP_CMD_OVERLAY_ADD, "overlay_add", 5, { {MP_CMD_ARG_STRING,{0}}, {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
+  { MP_CMD_OVERLAY_REMOVE, "overlay_remove", 1, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
 
 #ifdef CONFIG_DVDNAV
   { MP_CMD_DVDNAV, "dvdnav", 1, { {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } },

Modified: trunk/input/input.h
==============================================================================
--- trunk/input/input.h	Sun Oct 10 11:27:11 2010	(r32477)
+++ trunk/input/input.h	Sun Oct 10 11:30:42 2010	(r32478)
@@ -133,6 +133,8 @@ typedef enum {
   MP_CMD_ASS_USE_MARGINS,
   MP_CMD_SWITCH_TITLE,
   MP_CMD_STOP,
+  MP_CMD_OVERLAY_ADD,
+  MP_CMD_OVERLAY_REMOVE,
 
   /// DVDNAV commands
   MP_CMD_DVDNAV_UP = 1000,


More information about the MPlayer-cvslog mailing list