Mercurial > mplayer.hg
diff command.c @ 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 | faefba58f413 |
children | 5aae26f4bb59 |
line wrap: on
line diff
--- 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;