diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2020-12-02 12:39:57 +0200 |
---|---|---|
committer | avih <avih@users.noreply.github.com> | 2020-12-02 17:06:11 +0200 |
commit | 84d0930fa1489868ef3034b5ae18ba760b1a2db9 (patch) | |
tree | dbc4b6c61fd8a9574cc604a9501cbd65a68c7900 | |
parent | da48bb6709b83b2cc7ba4aa370fb4ef0daf24ae7 (diff) | |
download | mpv-84d0930fa1489868ef3034b5ae18ba760b1a2db9.tar.bz2 mpv-84d0930fa1489868ef3034b5ae18ba760b1a2db9.tar.xz |
vo_sixel: don't divide by zero on small terminal
Our canvas size calculation is affected by few factors, and rounded
down more than once - which can result in 0 width or (more typically)
height - e.g. when terminal height is one row.
If the width or height are 0 then all bets are off, so simply skip
the setups and rendering on this case. We can still recover
automatically if the terminal is resized to become bigger.
-rw-r--r-- | video/out/vo_sixel.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/video/out/vo_sixel.c b/video/out/vo_sixel.c index 627e69f81a..c9cc1573cb 100644 --- a/video/out/vo_sixel.c +++ b/video/out/vo_sixel.c @@ -72,14 +72,10 @@ struct priv { uint8_t *buffer; bool skip_frame_draw; - // The dimensions that will be actually - // be used after processing user inputs - int top; - int left; - int width; - int height; - int num_rows; - int num_cols; + int left, top; // image origin cell (1 based) + int width, height; // actual image px size - always reflects dst_rect. + int num_cols, num_rows; // terminal size in cells + int canvas_ok; // whether canvas vo->dwidth and vo->dheight are positive int previous_histgram_colors; @@ -262,6 +258,8 @@ static void update_canvas_dimensions(struct vo *vo) priv->num_rows = num_rows; priv->num_cols = num_cols; + + priv->canvas_ok = vo->dwidth > 0 && vo->dheight > 0; } static void set_sixel_output_parameters(struct vo *vo) @@ -330,9 +328,13 @@ static int update_sixel_swscaler(struct vo *vo, struct mp_image_params *params) static int reconfig(struct vo *vo, struct mp_image_params *params) { + struct priv *priv = vo->priv; + int ret = 0; update_canvas_dimensions(vo); - set_sixel_output_parameters(vo); - int ret = update_sixel_swscaler(vo, params); + if (priv->canvas_ok) { // if too small - succeed but skip the rendering + set_sixel_output_parameters(vo); + ret = update_sixel_swscaler(vo, params); + } printf(ESC_CLEAR_SCREEN); vo->want_redraw = true; @@ -352,6 +354,8 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame) int prev_width = vo->dwidth; bool resized = false; update_canvas_dimensions(vo); + if (!priv->canvas_ok) + return; if (prev_rows != priv->num_rows || prev_cols != priv->num_cols || prev_width != vo->dwidth || prev_height != vo->dheight) @@ -426,6 +430,8 @@ static int sixel_write(char *data, int size, void *priv) static void flip_page(struct vo *vo) { struct priv* priv = vo->priv; + if (!priv->canvas_ok) + return; // If frame is repeated and no update required, then we skip encoding if (priv->skip_frame_draw) |