[babl] use optimized powf for x^(1.0/2.4)



commit fe553b82d2bf2ce5a76a571cedb4b1e0389cfc99
Author: Ãyvind KolÃs <pippin gimp org>
Date:   Sat Mar 31 03:47:06 2012 +0100

    use optimized powf for x^(1.0/2.4)

 babl/base/util.h |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/babl/base/util.h b/babl/base/util.h
index 7ccaf8f..bca25eb 100644
--- a/babl/base/util.h
+++ b/babl/base/util.h
@@ -56,12 +56,29 @@
 
 #ifdef BABL_USE_SRGB_GAMMA
 
+/*  fast approximation of x ^ (5/12) from a response by David Hammen at
+ *  http://stackoverflow.com/questions/6475373/optimizations-for-pow-with-const-non-integer-exponent/6475516#6475516
+ *
+ */
+static inline double xpow512 (double x)
+{
+  double cbrtx = cbrt(x);
+  return cbrtx*sqrt(sqrt(cbrtx));
+}
+
+
 static inline double
 linear_to_gamma_2_2 (double value)
 {
+#if 0
   if (value > 0.0030402477F)
     return 1.055F * pow (value, (1.0F/2.4F)) - 0.055F;
   return 12.92F * value;
+#else
+  if (value > 0.0030402477F)
+    return 1.055F * xpow512 (value) - 0.055F;
+  return 12.92F * value;
+#endif
 }
 
 static inline double



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