changeset 32442:bf593e3827d9

EOSD: overlay_add: use read_pnm instead of the internal reimplementation. Add the b flag to fopen. Separate the fopen and the if to make it more readable.
author cigaes
date Fri, 22 Oct 2010 20:39:43 +0000
parents 1a9b4cb4ba01
children 5aae26f4bb59
files Makefile command.c
diffstat 2 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Fri Oct 22 17:46:12 2010 +0000
+++ b/Makefile	Fri Oct 22 20:39:43 2010 +0000
@@ -550,8 +550,7 @@
 SRCS_MPLAYER-$(GGI)          += libvo/vo_ggi.c
 SRCS_MPLAYER-$(GIF)          += libvo/vo_gif89a.c
 SRCS_MPLAYER-$(GL)           += libvo/gl_common.c libvo/vo_gl.c \
-                                libvo/vo_gl2.c libvo/csputils.c \
-                                pnm_loader.c
+                                libvo/vo_gl2.c libvo/csputils.c
 SRCS_MPLAYER-$(GL_SDL)       += libvo/sdl_common.c
 SRCS_MPLAYER-$(GL_WIN32)     += libvo/w32_common.c
 SRCS_MPLAYER-$(GL_X11)       += libvo/x11_common.c
@@ -675,6 +674,7 @@
                mp_fifo.c \
                mplayer.c \
                parser-mpcmd.c \
+               pnm_loader.c \
                input/input.c \
                libao2/ao_mpegpes.c \
                libao2/ao_null.c \
--- a/command.c	Fri Oct 22 17:46:12 2010 +0000
+++ b/command.c	Fri Oct 22 20:39:43 2010 +0000
@@ -63,6 +63,7 @@
 #include "libmenu/menu.h"
 #include "gui/interface.h"
 #include "eosd.h"
+#include "pnm_loader.h"
 
 #include "mp_core.h"
 #include "mp_fifo.h"
@@ -2546,23 +2547,24 @@
 static void overlay_add(char *file, int id, int x, int y, unsigned col)
 {
     FILE *f;
-    unsigned w, h, nc;
-    unsigned char *data;
+    unsigned w, h, bpp, maxval;
+    uint8_t *data;
     struct mp_eosd_image *img;
 
-    if (!(f = fopen(file, "r"))) {
+    f = fopen(file, "rb");
+    if (!f) {
         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);
+    data = read_pnm(f, &w, &h, &bpp, &maxval);
+    fclose(f);
+    if (!data) {
+        mp_msg(MSGT_CPLAYER, MSGL_ERR, "overlay_add: unable to load file.\n");
         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);
+    if (bpp != 1 || maxval != 255) {
+        mp_msg(MSGT_CPLAYER, MSGL_ERR,
+               "overlay_add: file format not supported.\n");
         return;
     }
     if (!overlay_source_registered) {
@@ -2570,7 +2572,6 @@
         eosd_image_remove_all(&overlay_source);
         overlay_source_registered = 1;
     }
-    fclose(f);
     img = eosd_image_alloc();
     img->w      = w;
     img->h      = h;