vo_tct: reduce lut_item size and generate it without snprintf

This commit is contained in:
Kacper Michajłow 2024-03-21 17:51:27 +01:00
parent 7d2b7fa019
commit 2d4fae4f70
1 changed files with 11 additions and 6 deletions

View File

@ -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);