[babl] add simple test for float->u8 conversion
- From: Simon Budig <simon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] add simple test for float->u8 conversion
- Date: Tue, 1 May 2012 11:36:23 +0000 (UTC)
commit 5bcbc7a3949443ca7a76f9a16c26db3bb9d1b922
Author: Simon Budig <simon budig de>
Date: Tue May 1 13:35:58 2012 +0200
add simple test for float->u8 conversion
tests/Makefile.am | 1 +
tests/floatclamp.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 469a819..b48aee5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -10,6 +10,7 @@ TESTS = \
sanity \
babl_class_name \
extract \
+ floatclamp \
types \
palette \
extract \
diff --git a/tests/floatclamp.c b/tests/floatclamp.c
new file mode 100644
index 0000000..953b701
--- /dev/null
+++ b/tests/floatclamp.c
@@ -0,0 +1,70 @@
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Ãyvind KolÃs.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include "babl.h"
+
+
+#define CHECK_CONV(test_name, componenttype, src_fmt, dst_fmt, src_pix, expected_pix) \
+ { \
+ const Babl *fish; \
+ int i; \
+ fish = babl_fish (src_fmt, dst_fmt); \
+ if (!fish) \
+ { \
+ printf (" %s failed to make fish\n", test_name); \
+ OK = 0; \
+ } \
+ for (i = 0; i < sizeof(src_pix)/sizeof(src_pix[0]); i ++) \
+ { \
+ int c;\
+ componenttype result[10]; \
+ babl_process (fish, src_pix[i], result, 1); \
+ for (c = 0; c < sizeof(expected_pix[i])/sizeof(expected_pix[i][0]); c++) \
+ if (result[c] != expected_pix[i][c]) \
+ { \
+ printf (" %s failed #%i[%i] got %i expected %i\n", test_name, i, c, result[c], expected_pix[i][c]); \
+ OK = 0; \
+ } \
+ } \
+ }
+
+#include <assert.h>
+
+int
+main (int argc,
+ char **argv)
+{
+ int OK = 1;
+ babl_init ();
+ {
+ float in[][4] = {{ 0.21582, -0.55, -0.14, 1.0 }};
+ unsigned char out[][4] = {{ 55, 0, 0, 255 }};
+
+ CHECK_CONV("float -> u8", unsigned char,
+ babl_format("R'G'B'A float"),
+ babl_format("R'G'B'A u8"),
+ in, out);
+ }
+
+ babl_exit ();
+ return !OK;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]