From ee26fef07ec4a74c3bf06f6480f34bb23c453624 Mon Sep 17 00:00:00 2001 From: Ville Syrjälä Date: Tue, 27 Feb 2018 22:38:05 +0200 Subject: lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ville Syrjälä Reviewed-by: Chris Wilson --- lib/igt_aux.h | 7 +++++++ lib/igt_fb.c | 11 ++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/igt_aux.h b/lib/igt_aux.h index 9bb03b77..0eb96e44 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -228,6 +228,13 @@ void intel_require_files(uint64_t count); _a > _b ? _a : _b; \ }) +#define clamp(x, min, max) ({ \ + typeof(min) _min = (min); \ + typeof(max) _max = (max); \ + typeof(x) _x = (x); \ + _x < _min ? _min : _x > _max ? _max : _x; \ +}) + #define igt_swap(a, b) do { \ typeof(a) _tmp = (a); \ (a) = (b); \ diff --git a/lib/igt_fb.c b/lib/igt_fb.c index 9308ade0..a926a08d 100644 --- a/lib/igt_fb.c +++ b/lib/igt_fb.c @@ -30,6 +30,7 @@ #include #include "drmtest.h" +#include "igt_aux.h" #include "igt_fb.h" #include "igt_kms.h" #include "igt_x86.h" @@ -1320,13 +1321,9 @@ struct fb_convert_blit_upload { struct fb_blit_linear linear; }; -static uint8_t clamprgb(float val) { - if (val < 0) - return 0; - if (val > 255) - return 255; - - return (uint8_t)val; +static uint8_t clamprgb(float val) +{ + return clamp(val, 0.0f, 255.0f); } static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_upload *blit) -- cgit v1.2.3