diff command.c @ 32392:7fd2de8d6f32

Add the overlay_add and overlay_remove commands.
author cigaes
date Sun, 10 Oct 2010 09:30:42 +0000
parents 76f94c00a69f
children ad86352b7c6b
line wrap: on
line diff
--- a/command.c	Sun Oct 10 09:27:11 2010 +0000
+++ b/command.c	Sun Oct 10 09:30:42 2010 +0000
@@ -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 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 @@
                                  &(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) {