From b05791db4a93df98fd0f1d815ff60d5c28eff657 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Mon, 9 Sep 2019 19:09:40 +0000 Subject: [PATCH] zrle: Define tile side length in a macro --- src/zrle.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/zrle.c b/src/zrle.c index e2f7024..1a2fd57 100644 --- a/src/zrle.c +++ b/src/zrle.c @@ -30,6 +30,8 @@ #include #include +#define TILE_LENGTH 64 + #define POPCOUNT(x) __builtin_popcount(x) #define UDIV_UP(a, b) (((a) + (b) - 1) / (b)) @@ -337,14 +339,14 @@ int zrle_encode_box(struct vec* out, const struct rfb_pixel_format *dst_fmt, { int r = -1; int bytes_per_cpixel = dst_fmt->depth / 8; - int chunk_size = 1 + bytes_per_cpixel * 64 * 64; + int chunk_size = 1 + bytes_per_cpixel * TILE_LENGTH * TILE_LENGTH; struct vec in; - uint32_t *tile = malloc(64 * 64 * 4); + uint32_t *tile = malloc(TILE_LENGTH * TILE_LENGTH * 4); if (!tile) goto failure; - if (vec_init(&in, 1 + bytes_per_cpixel * 64 * 64) < 0) + if (vec_init(&in, 1 + bytes_per_cpixel * TILE_LENGTH * TILE_LENGTH) < 0) goto failure; struct rfb_server_fb_rect rect = { @@ -363,14 +365,15 @@ int zrle_encode_box(struct vec* out, const struct rfb_pixel_format *dst_fmt, size_t size_index = out->len; vec_append_zero(out, 4); - int n_tiles = UDIV_UP(width, 64) * UDIV_UP(height, 64); + int n_tiles = + UDIV_UP(width, TILE_LENGTH) * UDIV_UP(height, TILE_LENGTH); for (int i = 0; i < n_tiles; ++i) { - int tile_x = (i % UDIV_UP(width, 64)) * 64; - int tile_y = (i / UDIV_UP(width, 64)) * 64; + int tile_x = (i % UDIV_UP(width, TILE_LENGTH)) * TILE_LENGTH; + int tile_y = (i / UDIV_UP(width, TILE_LENGTH)) * TILE_LENGTH; - int tile_width = width - tile_x >= 64 ? 64 : width - tile_x; - int tile_height = height - tile_y >= 64 ? 64 : height - tile_y; + int tile_width = width - tile_x >= TILE_LENGTH ? TILE_LENGTH : width - tile_x; + int tile_height = height - tile_y >= TILE_LENGTH ? TILE_LENGTH : height - tile_y; int y_off = !(fb->nvnc_modifier & NVNC_MOD_Y_INVERT) ? y + tile_y