From 02d2c2cc9722dbda832917118bd4190a38e70f5a Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Sat, 22 Oct 2016 02:38:32 +0300 Subject: vo_tct: optional custom size, support non-posix with 80x25 default Also, replace the UTF8 half block char at the source code with C escape. --- DOCS/man/vo.rst | 6 +++++- video/out/vo.c | 2 -- video/out/vo_tct.c | 36 +++++++++++++++++++++++++++++++----- wscript_build.py | 2 +- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/DOCS/man/vo.rst b/DOCS/man/vo.rst index 039411a40c..9575948eea 100644 --- a/DOCS/man/vo.rst +++ b/DOCS/man/vo.rst @@ -390,7 +390,7 @@ Available video output drivers are: ``tct`` Color Unicode art video output driver that works on a text console. Depends on support of true color by modern terminals to display the images - at full color range. + at full color range. On Windows it requires an ansi terminal such as mintty. ``--vo-tct-algo=`` Select how to write the pixels to the terminal. @@ -402,6 +402,10 @@ Available video output drivers are: Uses spaces. Causes vertical resolution to drop twofolds, but in theory works in more places. + ``--vo-tct-width=`` ``--vo-tct-height=`` + Assume the terminal has the specified character width and/or height. + These default to 80x25 if the terminal size cannot be determined. + ``image`` Output each frame into an image file in the current directory. Each file takes the frame number padded with leading zeros as name. diff --git a/video/out/vo.c b/video/out/vo.c index 142f549aa0..46908d2d59 100644 --- a/video/out/vo.c +++ b/video/out/vo.c @@ -90,9 +90,7 @@ const struct vo_driver *const video_out_drivers[] = &video_out_null, // should not be auto-selected &video_out_image, -#if HAVE_POSIX &video_out_tct, -#endif #if HAVE_CACA &video_out_caca, #endif diff --git a/video/out/vo_tct.c b/video/out/vo_tct.c index 22354c5283..c72a66e940 100644 --- a/video/out/vo_tct.c +++ b/video/out/vo_tct.c @@ -17,7 +17,12 @@ #include #include +#include + +#if HAVE_POSIX #include +#endif + #include #include "options/m_config.h" @@ -38,9 +43,13 @@ #define ESC_GOTOXY "\e[%d;%df" #define ESC_COLOR_BACKGROUND "\e[48;2;%d;%d;%dm" #define ESC_COLOR_FOREGROUND "\e[38;2;%d;%d;%dm" +#define DEFAULT_WIDTH 80 +#define DEFAULT_HEIGHT 25 struct vo_tct_opts { int algo; + int width; // 0 -> default + int height; // 0 -> default }; #define OPT_BASE_STRUCT struct vo_tct_opts @@ -49,6 +58,8 @@ static const struct m_sub_options vo_tct_conf = { OPT_CHOICE("vo-tct-algo", algo, 0, ({"plain", ALGO_PLAIN}, {"half-blocks", ALGO_HALF_BLOCKS})), + OPT_INT("vo-tct-width", width, 0), + OPT_INT("vo-tct-height", height, 0), {0} }, .defaults = &(const struct vo_tct_opts) { @@ -113,21 +124,36 @@ static void write_half_blocks( unsigned char r_down = *row_down++; printf(ESC_COLOR_BACKGROUND, r_up, g_up, b_up); printf(ESC_COLOR_FOREGROUND, r_down, g_down, b_down); - printf("▄"); + printf("\xe2\x96\x84"); // UTF8 bytes of U+2584 (lower half block) } printf(ESC_CLEAR_COLORS); } printf("\n"); } +static void get_win_size(struct vo *vo, int *out_width, int *out_height) { + struct priv *p = vo->priv; +#if HAVE_POSIX + struct winsize winsize; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize); + *out_width = winsize.ws_col; + *out_height = winsize.ws_row; +#else + *out_width = DEFAULT_WIDTH; + *out_height = DEFAULT_HEIGHT; +#endif + + if (p->opts->width > 0) + *out_width = p->opts->width; + if (p->opts->height > 0) + *out_height = p->opts->height; +} + static int reconfig(struct vo *vo, struct mp_image_params *params) { struct priv *p = vo->priv; - struct winsize winsize; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize); - vo->dwidth = winsize.ws_col; - vo->dheight = winsize.ws_row; + get_win_size(vo, &vo->dwidth, &vo->dheight); struct mp_osd_res osd; vo_get_src_dst_rects(vo, &p->src, &p->dst, &osd); diff --git a/wscript_build.py b/wscript_build.py index e05bbe8d11..ceea5be6f4 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -375,7 +375,7 @@ def build(ctx): ( "video/out/vo_opengl.c", "gl" ), ( "video/out/vo_opengl_cb.c", "gl" ), ( "video/out/vo_sdl.c", "sdl2" ), - ( "video/out/vo_tct.c", "posix" ), + ( "video/out/vo_tct.c" ), ( "video/out/vo_vaapi.c", "vaapi-x11" ), ( "video/out/vo_vdpau.c", "vdpau" ), ( "video/out/vo_wayland.c", "wayland" ), -- cgit v1.2.3