From 76beec64154e8ee5b3ddc5ea7f1e697c16c5c867 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 19 Jul 2020 16:57:44 +0000 Subject: [PATCH] tight: Add method to resize encoder grid --- include/tight.h | 3 +++ src/tight.c | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/tight.h b/include/tight.h index fdeb62f..3e8dfd7 100644 --- a/include/tight.h +++ b/include/tight.h @@ -61,6 +61,9 @@ int tight_encoder_init(struct tight_encoder* self, uint32_t width, uint32_t height); void tight_encoder_destroy(struct tight_encoder* self); +int tight_encoder_resize(struct tight_encoder* self, uint32_t width, + uint32_t height); + int tight_encode_frame(struct tight_encoder* self, struct vec* dst, const struct rfb_pixel_format* dfmt, const struct nvnc_fb* src, diff --git a/src/tight.c b/src/tight.c index 952b892..ff9ea43 100644 --- a/src/tight.c +++ b/src/tight.c @@ -123,20 +123,28 @@ failure: return -1; } -int tight_encoder_init(struct tight_encoder* self, uint32_t width, +int tight_encoder_resize(struct tight_encoder* self, uint32_t width, uint32_t height) { - memset(self, 0, sizeof(*self)); - self->width = width; self->height = height; self->grid_width = UDIV_UP(width, 64); self->grid_height = UDIV_UP(height, 64); + if (self->grid) + free(self->grid); + self->grid = calloc(self->grid_width * self->grid_height, sizeof(*self->grid)); - if (!self->grid) + return self->grid ? 0 : -1; +} + +int tight_encoder_init(struct tight_encoder* self, uint32_t width, + uint32_t height) +{ + memset(self, 0, sizeof(*self)); + if (tight_encoder_resize(self, width, height) < 0) return -1; tight_encoder_init_stream(&self->zs[0]);