[igt-dev] [PATCH i-g-t 1/8] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion

Ville Syrjala ville.syrjala at linux.intel.com
Tue Feb 27 21:21:13 UTC 2018


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 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 43dd15fe3b32..7f61fc5a458b 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 ecd73053f16f..9af600896e50 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -30,6 +30,7 @@
 #include <inttypes.h>
 
 #include "drmtest.h"
+#include "igt_aux.h"
 #include "igt_fb.h"
 #include "igt_kms.h"
 #include "ioctl_wrappers.h"
@@ -1318,13 +1319,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)
-- 
2.13.6



More information about the igt-dev mailing list