enc-util: Add function to calculate region area
parent
3647457f6d
commit
f31ddf7fe9
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2019 - 2020 Andri Yngvason
|
* Copyright (c) 2019 - 2022 Andri Yngvason
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -21,7 +21,9 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct vec;
|
struct vec;
|
||||||
|
struct pixman_region16;
|
||||||
|
|
||||||
int encode_rect_head(struct vec* dst, enum rfb_encodings encoding,
|
int encode_rect_head(struct vec* dst, enum rfb_encodings encoding,
|
||||||
uint32_t x, uint32_t y, uint32_t width, uint32_t height);
|
uint32_t x, uint32_t y, uint32_t width, uint32_t height);
|
||||||
uint32_t calc_bytes_per_cpixel(const struct rfb_pixel_format* fmt);
|
uint32_t calc_bytes_per_cpixel(const struct rfb_pixel_format* fmt);
|
||||||
|
uint32_t calculate_region_area(struct pixman_region16* region);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2019 - 2020 Andri Yngvason
|
* Copyright (c) 2019 - 2022 Andri Yngvason
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -19,6 +19,8 @@
|
||||||
#include "vec.h"
|
#include "vec.h"
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <pixman.h>
|
||||||
|
|
||||||
#define UDIV_UP(a, b) (((a) + (b) - 1) / (b))
|
#define UDIV_UP(a, b) (((a) + (b) - 1) / (b))
|
||||||
|
|
||||||
|
@ -41,3 +43,20 @@ uint32_t calc_bytes_per_cpixel(const struct rfb_pixel_format* fmt)
|
||||||
return fmt->bits_per_pixel == 32 ? UDIV_UP(fmt->depth, 8)
|
return fmt->bits_per_pixel == 32 ? UDIV_UP(fmt->depth, 8)
|
||||||
: UDIV_UP(fmt->bits_per_pixel, 8);
|
: UDIV_UP(fmt->bits_per_pixel, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t calculate_region_area(struct pixman_region16* region)
|
||||||
|
{
|
||||||
|
uint32_t area = 0;
|
||||||
|
|
||||||
|
int n_rects = 0;
|
||||||
|
struct pixman_box16* rects = pixman_region_rectangles(region,
|
||||||
|
&n_rects);
|
||||||
|
|
||||||
|
for (int i = 0; i < n_rects; ++i) {
|
||||||
|
int width = rects[i].x2 - rects[i].x1;
|
||||||
|
int height = rects[i].y2 - rects[i].y1;
|
||||||
|
area += width * height;
|
||||||
|
}
|
||||||
|
|
||||||
|
return area;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue