summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShreesh Adiga <16567adigashreesh@gmail.com>2020-11-11 16:19:13 +0530
committeravih <avih@users.noreply.github.com>2020-11-22 13:34:25 +0200
commit71b21b93399692ed4184fb673aa53d26357dba6e (patch)
treedac538aa7918619be7363bcefa9473b542867a59
parent670f23f1698bb19ea2869e8f82198b2f9083ef88 (diff)
downloadmpv-71b21b93399692ed4184fb673aa53d26357dba6e.tar.bz2
mpv-71b21b93399692ed4184fb673aa53d26357dba6e.tar.xz
vo_sixel: set output resolution based on terminal_get_size2
-rw-r--r--video/out/vo_sixel.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/video/out/vo_sixel.c b/video/out/vo_sixel.c
index 1f9dd1e072..74f4d5dfd8 100644
--- a/video/out/vo_sixel.c
+++ b/video/out/vo_sixel.c
@@ -40,6 +40,8 @@
#define TERMINAL_FALLBACK_DEFAULT_WIDTH 80
#define TERMINAL_FALLBACK_DEFAULT_HEIGHT 25
+#define IMG_FALLBACK_DEFAULT_WIDTH 320
+#define IMG_FALLBACK_DEFAULT_HEIGHT 240
#define ESC_HIDE_CURSOR "\033[?25l"
#define ESC_RESTORE_CURSOR "\033[?25h"
@@ -103,6 +105,37 @@ static void validate_offset_values(struct vo* vo)
priv->left = 1;
}
+static void set_output_resolution(struct vo* vo)
+{
+ struct priv *priv = vo->priv;
+
+ // If both dimensions are set, then no need to calculate
+ if (priv->height && priv->width)
+ return;
+
+ int num_rows = TERMINAL_FALLBACK_DEFAULT_WIDTH;
+ int num_cols = TERMINAL_FALLBACK_DEFAULT_HEIGHT;
+ int total_px_width = IMG_FALLBACK_DEFAULT_WIDTH;
+ int total_px_height = IMG_FALLBACK_DEFAULT_HEIGHT;
+
+ terminal_get_size2(&num_rows, &num_cols, &total_px_width, &total_px_height);
+
+ // The maximum width is the full terminal width
+ int available_px_width = total_px_width;
+
+ // The maximum height is the amount of pixels
+ // comprising n-1 rows worth pixels.
+ // This is because sixel dump after sixel_encode adds a newline
+ // which can't be used for image display.
+ int available_px_height = (total_px_height * (num_rows - 1)) / num_rows;
+
+ if (priv->width == 0)
+ priv->width = available_px_width;
+
+ if (priv->height == 0)
+ priv->height = available_px_height;
+}
+
static int detect_scene_change(struct vo* vo)
{
struct priv* priv = vo->priv;
@@ -250,6 +283,8 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
priv->image_width = params->w;
priv->image_format = params->imgfmt;
+ set_output_resolution(vo);
+
priv->sws->src = *params;
priv->sws->dst = (struct mp_image_params) {
.imgfmt = IMGFMT,
@@ -399,8 +434,8 @@ const struct vo_driver video_out_sixel = {
.priv_size = sizeof(struct priv),
.priv_defaults = &(const struct priv) {
.diffuse = DIFFUSE_ATKINSON,
- .width = 320,
- .height = 240,
+ .width = 0,
+ .height = 0,
.reqcolors = 256,
.fixedpal = 0,
.threshold = 0,