enc-util: Round up division in calc_bytes_per_cpixel

Otherwise 10 bit formats will be mistaken for 8 bit formats.
pull/63/head
Andri Yngvason 2022-01-27 22:10:34 +00:00
parent 5dc6a28828
commit fd23cb8c2f
1 changed files with 4 additions and 2 deletions

View File

@ -20,6 +20,8 @@
#include <arpa/inet.h>
#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);
}