From fd23cb8c2fae1b2b162e288df5a562a13dd8203b Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Thu, 27 Jan 2022 22:10:34 +0000 Subject: [PATCH] enc-util: Round up division in calc_bytes_per_cpixel Otherwise 10 bit formats will be mistaken for 8 bit formats. --- src/enc-util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/enc-util.c b/src/enc-util.c index 10e163c..4845940 100644 --- a/src/enc-util.c +++ b/src/enc-util.c @@ -20,6 +20,8 @@ #include +#define UDIV_UP(a, b) (((a) + (b) - 1) / (b)) + int encode_rect_head(struct vec* dst, enum rfb_encodings encoding, uint32_t x, uint32_t y, uint32_t width, uint32_t height) { @@ -36,6 +38,6 @@ int encode_rect_head(struct vec* dst, enum rfb_encodings encoding, uint32_t calc_bytes_per_cpixel(const struct rfb_pixel_format* fmt) { - return fmt->bits_per_pixel == 32 ? fmt->depth / 8 - : fmt->bits_per_pixel / 8; + return fmt->bits_per_pixel == 32 ? UDIV_UP(fmt->depth, 8) + : UDIV_UP(fmt->bits_per_pixel, 8); }