summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2024-03-21 17:51:27 +0100
committerKacper Michajłow <kasper93@gmail.com>2024-04-07 20:23:04 +0200
commit2d4fae4f706c5c400acbc8a27d7819b4d539a315 (patch)
tree0707eca2db855d866bfb7c0d6bbb45cff770c1ea /video/out
parent7d2b7fa019c8c15b17dd0f48629e3ab8f00c8263 (diff)
downloadmpv-2d4fae4f706c5c400acbc8a27d7819b4d539a315.tar.bz2
mpv-2d4fae4f706c5c400acbc8a27d7819b4d539a315.tar.xz
vo_tct: reduce lut_item size and generate it without snprintf
Diffstat (limited to 'video/out')
-rw-r--r--video/out/vo_tct.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/video/out/vo_tct.c b/video/out/vo_tct.c
index 1b130d0100..ca13cf04cf 100644
--- a/video/out/vo_tct.c
+++ b/video/out/vo_tct.c
@@ -68,7 +68,7 @@ struct vo_tct_opts {
struct lut_item {
char str[4];
- int width;
+ uint8_t width;
};
struct priv {
@@ -80,8 +80,8 @@ struct priv {
struct mp_rect src;
struct mp_rect dst;
struct mp_sws_context *sws;
- struct lut_item lut[256];
bstr frame_buf;
+ struct lut_item lut[256];
};
// Convert RGB24 to xterm-256 8-bit value
@@ -316,10 +316,15 @@ static int preinit(struct vo *vo)
p->sws->log = vo->log;
mp_sws_enable_cmdline_opts(p->sws, vo->global);
- for (int i = 0; i < 256; ++i) {
- char buff[8];
- p->lut[i].width = snprintf(buff, sizeof(buff), ";%d", i);
- memcpy(p->lut[i].str, buff, 4); // some strings may not end on a null byte, but that's ok.
+ for (int i = 0; i < MP_ARRAY_SIZE(p->lut); ++i) {
+ char* out = p->lut[i].str;
+ *out++ = ';';
+ if (i >= 100)
+ *out++ = '0' + (i / 100);
+ if (i >= 10)
+ *out++ = '0' + ((i / 10) % 10);
+ *out++ = '0' + (i % 10);
+ p->lut[i].width = out - p->lut[i].str;
}
WRITE_STR(TERM_ESC_HIDE_CURSOR);