diff options
author | Graham Booker <gbooker@plexapp.com> | 2022-10-03 13:58:45 -0500 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2023-12-08 13:37:26 +0100 |
commit | 4754bd54c7ab22c6c98283d81e22d219b3b64ade (patch) | |
tree | ec1fcd96a9337905c64defcb3e02af3bef937f21 | |
parent | f886eb5678d0ed7eea196e577e04525248963f28 (diff) | |
download | mpv-4754bd54c7ab22c6c98283d81e22d219b3b64ade.tar.bz2 mpv-4754bd54c7ab22c6c98283d81e22d219b3b64ade.tar.xz |
player/command: add ability to scale overlay
-rw-r--r-- | DOCS/man/input.rst | 7 | ||||
-rw-r--r-- | input/cmd.h | 2 | ||||
-rw-r--r-- | player/command.c | 16 |
3 files changed, 20 insertions, 5 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index a314bfb5ed..babffdaf89 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -1033,7 +1033,7 @@ Input Commands that are Possibly Subject to Change information about the key state. The special key name ``unmapped`` can be used to match any unmapped key. -``overlay-add <id> <x> <y> <file> <offset> <fmt> <w> <h> <stride>`` +``overlay-add <id> <x> <y> <file> <offset> <fmt> <w> <h> <stride> <dw> <dh>`` Add an OSD overlay sourced from raw data. This might be useful for scripts and applications controlling mpv, and which want to display things on top of the video window. @@ -1091,6 +1091,11 @@ Input Commands that are Possibly Subject to Change (Technically, the minimum size would be ``stride * (h - 1) + w * 4``, but for simplicity, the player will access all ``stride * h`` bytes.) + ``dw`` and ``dh`` specify the (optional) display size of the overlay. + The overlay visible portion of the overlay (``w`` and ``h``) is scaled to + in display to ``dw`` and ``dh``. If parameters are not present, the + values for ``w`` and ``h`` are used. + .. note:: Before mpv 0.18.1, you had to do manual "double buffering" when updating diff --git a/input/cmd.h b/input/cmd.h index 1c9fb3e815..3d4b15fcc3 100644 --- a/input/cmd.h +++ b/input/cmd.h @@ -23,7 +23,7 @@ #include "misc/bstr.h" #include "options/m_option.h" -#define MP_CMD_DEF_MAX_ARGS 9 +#define MP_CMD_DEF_MAX_ARGS 11 #define MP_CMD_OPT_ARG M_OPT_OPTIONAL_PARAM struct mp_log; diff --git a/player/command.c b/player/command.c index 1e4b355aed..4197748ac1 100644 --- a/player/command.c +++ b/player/command.c @@ -124,6 +124,7 @@ static const struct m_option udata_type = { struct overlay { struct mp_image *source; int x, y; + int dw, dh; }; struct hook_handler { @@ -4450,8 +4451,8 @@ static void recreate_overlays(struct MPContext *mpctx) struct sub_bitmap b = { .bitmap = s->planes[0], .stride = s->stride[0], - .w = s->w, .dw = s->w, - .h = s->h, .dh = s->h, + .w = s->w, .dw = o->dw, + .h = s->h, .dh = o->dh, .x = o->x, .y = o->y, }; @@ -4548,7 +4549,12 @@ static void cmd_overlay_add(void *pcmd) int offset = cmd->args[4].v.i; char *fmt = cmd->args[5].v.s; int w = cmd->args[6].v.i, h = cmd->args[7].v.i, stride = cmd->args[8].v.i; + int dw = cmd->args[9].v.i, dh = cmd->args[10].v.i; + if (dw <= 0) + dw = w; + if (dh <= 0) + dh = h; if (strcmp(fmt, "bgra") != 0) { MP_ERR(mpctx, "overlay-add: unsupported OSD format '%s'\n", fmt); goto error; @@ -4565,6 +4571,8 @@ static void cmd_overlay_add(void *pcmd) .source = mp_image_alloc(IMGFMT_BGRA, w, h), .x = x, .y = y, + .dw = dw, + .dh = dh, }; if (!overlay.source) goto error; @@ -6719,7 +6727,9 @@ const struct mp_cmd_def mp_cmds[] = { {"fmt", OPT_STRING(v.s)}, {"w", OPT_INT(v.i)}, {"h", OPT_INT(v.i)}, - {"stride", OPT_INT(v.i)}, }}, + {"stride", OPT_INT(v.i)}, + {"dw", OPT_INT(v.i)}, + {"dh", OPT_INT(v.i)}, }}, { "overlay-remove", cmd_overlay_remove, { {"id", OPT_INT(v.i)} } }, { "osd-overlay", cmd_osd_overlay, |