[babl/wip/poly: 5/5] tools: add BablPolynomial test to trc-validator.c



commit 1d4c81dd0b7a5b68204efaf7000bf2802304a4a4
Author: Ell <ell_se yahoo com>
Date:   Sun Sep 10 13:33:41 2017 -0400

    tools: add BablPolynomial test to trc-validator.c

 tools/trc-validator.c |   41 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 40 insertions(+), 1 deletions(-)
---
diff --git a/tools/trc-validator.c b/tools/trc-validator.c
index c8663a9..14e1509 100644
--- a/tools/trc-validator.c
+++ b/tools/trc-validator.c
@@ -2,12 +2,14 @@
 // the currently used apprimxations for 1.8 and 2.2 gamma pow functions are
 // validated to be loss-less when coded for 8bit.
 
+#include "config.h"
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <math.h>
+#include "babl-internal.h"
 
-#if 1
+#if 0
 
 #define GAMMA 2.2
 
@@ -130,6 +132,43 @@ static inline float to_linear (float x)
 }
 #endif
 
+#if 1
+
+#define GAMMA  2.2
+#define X0     (  0.5f / 255.0f)
+#define X1     (254.5f / 255.0f)
+#define DEGREE 6
+#define SCALE  2
+
+static inline float from_linear (float x)
+{
+  if (x >= X0 && x <= X1)
+  {
+    BablPolynomial poly;
+
+    babl_polynomial_approximate_gamma (&poly,
+                                       1.0 / GAMMA, X0, X1, DEGREE, SCALE);
+
+    return babl_polynomial_eval (&poly, x);
+  }
+  return powf (x, 1.0f/GAMMA);
+}
+
+static inline float to_linear (float x)
+{
+  if (x >= X0 && x <= X1)
+  {
+    BablPolynomial poly;
+
+    babl_polynomial_approximate_gamma (&poly,
+                                       GAMMA, X0, X1, DEGREE, SCALE);
+
+    return babl_polynomial_eval (&poly, x);
+  }
+  return powf (x, GAMMA);
+}
+#endif
+
 static inline float from_linear_ref (float x)
 {
   return powf (x, 1.0/GAMMA);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]