[Bf-blender-cvs] [e49e78e] master: Fix for negative gamma correction rounding to int

Campbell Barton noreply at git.blender.org
Wed Mar 5 12:42:11 CET 2014


Commit: e49e78e414d7e7b2e18cbe3fa3f7c967a54a1af3
Author: Campbell Barton
Date:   Wed Mar 5 22:33:47 2014 +1100
https://developer.blender.org/rBe49e78e414d7e7b2e18cbe3fa3f7c967a54a1af3

Fix for negative gamma correction rounding to int

===================================================================

M	source/blender/blenkernel/intern/seqeffects.c

===================================================================

diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c
index 145b695..e491661 100644
--- a/source/blender/blenkernel/intern/seqeffects.c
+++ b/source/blender/blenkernel/intern/seqeffects.c
@@ -635,33 +635,35 @@ static void makeGammaTables(float gamma)
 static float gammaCorrect(float c)
 {
 	int i;
-	float res = 0.0;
+	float res;
 	
-	i = floor(c * inv_color_step);
+	i = floorf(c * inv_color_step);
 	/* Clip to range [0, 1]: outside, just do the complete calculation.
 	 * We may have some performance problems here. Stretching up the LUT
 	 * may help solve that, by exchanging LUT size for the interpolation.
 	 * Negative colors are explicitly handled.
 	 */
-	if (i < 0) res = -pow(abs(c), valid_gamma);
-	else if (i >= RE_GAMMA_TABLE_SIZE) res = pow(c, valid_gamma);
-	else res = gamma_range_table[i] + ( (c - color_domain_table[i]) * gamfactor_table[i]);
+	if      (UNLIKELY(i < 0))          res = -powf(-c, valid_gamma);
+	else if (i >= RE_GAMMA_TABLE_SIZE) res =  powf(c,  valid_gamma);
+	else                               res =  gamma_range_table[i] +
+	                                          ((c - color_domain_table[i]) * gamfactor_table[i]);
 	
 	return res;
 }
 
 /* ------------------------------------------------------------------------- */
 
-static float invGammaCorrect(float col)
+static float invGammaCorrect(float c)
 {
 	int i;
 	float res = 0.0;
 
-	i = floor(col * inv_color_step);
+	i = floorf(c * inv_color_step);
 	/* Negative colors are explicitly handled */
-	if (i < 0) res = -pow(abs(col), valid_inv_gamma);
-	else if (i >= RE_GAMMA_TABLE_SIZE) res = pow(col, valid_inv_gamma);
-	else res = inv_gamma_range_table[i] +  ( (col - color_domain_table[i]) * inv_gamfactor_table[i]);
+	if      (UNLIKELY(i < 0))          res = -powf(-c, valid_inv_gamma);
+	else if (i >= RE_GAMMA_TABLE_SIZE) res =  powf(c,  valid_inv_gamma);
+	else                               res = inv_gamma_range_table[i] +
+	                                         ((c - color_domain_table[i]) * inv_gamfactor_table[i]);
  
 	return res;
 }




More information about the Bf-blender-cvs mailing list