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.
This commit is contained in:
Avi Halachmi (:avih) 2016-10-22 02:38:32 +03:00 committed by James Ross-Gowan
parent 6e143ffec3
commit 02d2c2cc97
4 changed files with 37 additions and 9 deletions

View File

@ -390,7 +390,7 @@ Available video output drivers are:
``tct`` ``tct``
Color Unicode art video output driver that works on a text console. 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 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=<algo>`` ``--vo-tct-algo=<algo>``
Select how to write the pixels to the terminal. 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 Uses spaces. Causes vertical resolution to drop twofolds, but in
theory works in more places. theory works in more places.
``--vo-tct-width=<width>`` ``--vo-tct-height=<height>``
Assume the terminal has the specified character width and/or height.
These default to 80x25 if the terminal size cannot be determined.
``image`` ``image``
Output each frame into an image file in the current directory. Each file Output each frame into an image file in the current directory. Each file
takes the frame number padded with leading zeros as name. takes the frame number padded with leading zeros as name.

View File

@ -90,9 +90,7 @@ const struct vo_driver *const video_out_drivers[] =
&video_out_null, &video_out_null,
// should not be auto-selected // should not be auto-selected
&video_out_image, &video_out_image,
#if HAVE_POSIX
&video_out_tct, &video_out_tct,
#endif
#if HAVE_CACA #if HAVE_CACA
&video_out_caca, &video_out_caca,
#endif #endif

View File

@ -17,7 +17,12 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <config.h>
#if HAVE_POSIX
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif
#include <libswscale/swscale.h> #include <libswscale/swscale.h>
#include "options/m_config.h" #include "options/m_config.h"
@ -38,9 +43,13 @@
#define ESC_GOTOXY "\e[%d;%df" #define ESC_GOTOXY "\e[%d;%df"
#define ESC_COLOR_BACKGROUND "\e[48;2;%d;%d;%dm" #define ESC_COLOR_BACKGROUND "\e[48;2;%d;%d;%dm"
#define ESC_COLOR_FOREGROUND "\e[38;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 { struct vo_tct_opts {
int algo; int algo;
int width; // 0 -> default
int height; // 0 -> default
}; };
#define OPT_BASE_STRUCT struct vo_tct_opts #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, OPT_CHOICE("vo-tct-algo", algo, 0,
({"plain", ALGO_PLAIN}, ({"plain", ALGO_PLAIN},
{"half-blocks", ALGO_HALF_BLOCKS})), {"half-blocks", ALGO_HALF_BLOCKS})),
OPT_INT("vo-tct-width", width, 0),
OPT_INT("vo-tct-height", height, 0),
{0} {0}
}, },
.defaults = &(const struct vo_tct_opts) { .defaults = &(const struct vo_tct_opts) {
@ -113,21 +124,36 @@ static void write_half_blocks(
unsigned char r_down = *row_down++; unsigned char r_down = *row_down++;
printf(ESC_COLOR_BACKGROUND, r_up, g_up, b_up); printf(ESC_COLOR_BACKGROUND, r_up, g_up, b_up);
printf(ESC_COLOR_FOREGROUND, r_down, g_down, b_down); 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(ESC_CLEAR_COLORS);
} }
printf("\n"); 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) static int reconfig(struct vo *vo, struct mp_image_params *params)
{ {
struct priv *p = vo->priv; struct priv *p = vo->priv;
struct winsize winsize; get_win_size(vo, &vo->dwidth, &vo->dheight);
ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize);
vo->dwidth = winsize.ws_col;
vo->dheight = winsize.ws_row;
struct mp_osd_res osd; struct mp_osd_res osd;
vo_get_src_dst_rects(vo, &p->src, &p->dst, &osd); vo_get_src_dst_rects(vo, &p->src, &p->dst, &osd);

View File

@ -375,7 +375,7 @@ def build(ctx):
( "video/out/vo_opengl.c", "gl" ), ( "video/out/vo_opengl.c", "gl" ),
( "video/out/vo_opengl_cb.c", "gl" ), ( "video/out/vo_opengl_cb.c", "gl" ),
( "video/out/vo_sdl.c", "sdl2" ), ( "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_vaapi.c", "vaapi-x11" ),
( "video/out/vo_vdpau.c", "vdpau" ), ( "video/out/vo_vdpau.c", "vdpau" ),
( "video/out/vo_wayland.c", "wayland" ), ( "video/out/vo_wayland.c", "wayland" ),