[gegl] gamma: handle negative input values



commit c7cb28200474795d4650bacee7b4cbeb25994a7d
Author: Ell <ell_se yahoo com>
Date:   Wed Sep 25 14:15:10 2019 +0300

    gamma: handle negative input values
    
    In gegl:gamma, use an odd power function, so that negative input
    values yield meaningful results, instead of NaN, for non-integer
    gamma values.
    
    In particular, this fixes issue #192.

 operations/generated/gamma.c | 6 +++---
 operations/generated/math.rb | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/operations/generated/gamma.c b/operations/generated/gamma.c
index 3ca7544f2..101efab93 100644
--- a/operations/generated/gamma.c
+++ b/operations/generated/gamma.c
@@ -83,7 +83,7 @@ process (GeglOperation       *op,
             {
               gfloat result;
               gfloat input=in[j];
-              result = powf (input, value);
+              result = (input >= 0.0f ? powf (input, value) : -powf (-input, value));
               out[j]=result;
             }
           if (alpha)
@@ -103,7 +103,7 @@ process (GeglOperation       *op,
               gfloat input =in[j];
               gfloat result;
               value=aux[j];
-              result = powf (input, value);
+              result = (input >= 0.0f ? powf (input, value) : -powf (-input, value));
               out[j]=result;
             }
           if (alpha)
@@ -135,7 +135,7 @@ gegl_op_class_init (GeglOpClass *klass)
   "categories"  , "compositors:math",
   "reference-hash"  , "2687ab0395fe31ccc25e2901a43a9c03",
   "description" ,
-       _("Math operation gamma, performs the operation per pixel, using either the constant provided in 
'value' or the corresponding pixel from the buffer on aux as operands. The result is the evaluation of the 
expression result = powf (input, value)"),
+       _("Math operation gamma, performs the operation per pixel, using either the constant provided in 
'value' or the corresponding pixel from the buffer on aux as operands. The result is the evaluation of the 
expression result = (input >= 0.0f ? powf (input, value) : -powf (-input, value))"),
        NULL);
 }
 #endif
diff --git a/operations/generated/math.rb b/operations/generated/math.rb
index 31218536e..0cb7837c1 100755
--- a/operations/generated/math.rb
+++ b/operations/generated/math.rb
@@ -29,7 +29,7 @@ a = [
       ['subtract',  'result = input - value', 0.0, '964b3d0b0afea081c157fe0251600ba3'],
       ['multiply',  'result = input * value', 1.0, 'c80bb8504f405bb0a5ce2be4fad6af69'],
       ['divide',    'result = value==0.0f?0.0f:input/value', 1.0, 'c3bd84f8a6b2c03a239f3f832597592c'],
-      ['gamma',     'result = powf (input, value)', 1.0, '2687ab0395fe31ccc25e2901a43a9c03'],
+      ['gamma',     'result = (input >= 0.0f ? powf (input, value) : -powf (-input, value))', 1.0, 
'2687ab0395fe31ccc25e2901a43a9c03'],
 #     ['threshold', 'result = c>=value?1.0f:0.0f', 0.5],
 #     ['invert',    'result = 1.0-c']
     ]


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