[babl] tools: add BablPolynomial test to trc-validator.c
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] tools: add BablPolynomial test to trc-validator.c
- Date: Mon, 11 Sep 2017 11:38:21 +0000 (UTC)
commit fd7e3020d2744cf1669a18b421e8c2daef45ab35
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 | 44 ++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/tools/trc-validator.c b/tools/trc-validator.c
index c8663a9..fffbe94 100644
--- a/tools/trc-validator.c
+++ b/tools/trc-validator.c
@@ -1,13 +1,16 @@
-// utility program for validating lolremez approximation constants for TRCs
+// utility program for validating lolremez approximation constants, and
+// BablPolynomial based approximations, for TRCs
// 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 +133,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]