Bug 679527 - Use floorf/ceilf in qcms transform function. r=jrmuizel
authorBenoit Girard <b56girard@gmail.com>
Fri, 19 Oct 2012 16:35:36 -0400
changeset 112331 017a34f07d4aec06bdd9078643e1f1b2fd3558c2
parent 112330 cf7582f6cde94b531148c75c933c4dcf91eebb95
child 112332 5511e214fed369b3373eefa6168b5076a8b69244
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjrmuizel
bugs679527
milestone19.0a1
Bug 679527 - Use floorf/ceilf in qcms transform function. r=jrmuizel
gfx/qcms/chain.c
gfx/qcms/transform.c
gfx/qcms/transform_util.c
--- a/gfx/qcms/chain.c
+++ b/gfx/qcms/chain.c
@@ -133,22 +133,22 @@ static void qcms_transform_module_clut_o
 	float* g_table = transform->g_clut;
 	float* b_table = transform->b_clut;
 
 	for (i = 0; i < length; i++) {
 		float linear_r = *src++;
 		float linear_g = *src++;
 		float linear_b = *src++;
 
-		int x = floor(linear_r * (transform->grid_size-1));
-		int y = floor(linear_g * (transform->grid_size-1));
-		int z = floor(linear_b * (transform->grid_size-1));
-		int x_n = ceil(linear_r * (transform->grid_size-1));
-		int y_n = ceil(linear_g * (transform->grid_size-1));
-		int z_n = ceil(linear_b * (transform->grid_size-1));
+		int x = floorf(linear_r * (transform->grid_size-1));
+		int y = floorf(linear_g * (transform->grid_size-1));
+		int z = floorf(linear_b * (transform->grid_size-1));
+		int x_n = ceilf(linear_r * (transform->grid_size-1));
+		int y_n = ceilf(linear_g * (transform->grid_size-1));
+		int z_n = ceilf(linear_b * (transform->grid_size-1));
 		float x_d = linear_r * (transform->grid_size-1) - x;
 		float y_d = linear_g * (transform->grid_size-1) - y;
 		float z_d = linear_b * (transform->grid_size-1) - z;
 
 		float r_x1 = lerp(CLU(r_table,x,y,z), CLU(r_table,x_n,y,z), x_d);
 		float r_x2 = lerp(CLU(r_table,x,y_n,z), CLU(r_table,x_n,y_n,z), x_d);
 		float r_y1 = lerp(r_x1, r_x2, y_d);
 		float r_x3 = lerp(CLU(r_table,x,y,z_n), CLU(r_table,x_n,y,z_n), x_d);
@@ -193,22 +193,22 @@ static void qcms_transform_module_clut(s
 		float device_b = *src++;
 		float linear_r = lut_interp_linear_float(device_r,
 				transform->input_clut_table_r, transform->input_clut_table_length);
 		float linear_g = lut_interp_linear_float(device_g,
 				transform->input_clut_table_g, transform->input_clut_table_length);
 		float linear_b = lut_interp_linear_float(device_b,
 				transform->input_clut_table_b, transform->input_clut_table_length);
 
-		int x = floor(linear_r * (transform->grid_size-1));
-		int y = floor(linear_g * (transform->grid_size-1));
-		int z = floor(linear_b * (transform->grid_size-1));
-		int x_n = ceil(linear_r * (transform->grid_size-1));
-		int y_n = ceil(linear_g * (transform->grid_size-1));
-		int z_n = ceil(linear_b * (transform->grid_size-1));
+		int x = floorf(linear_r * (transform->grid_size-1));
+		int y = floorf(linear_g * (transform->grid_size-1));
+		int z = floorf(linear_b * (transform->grid_size-1));
+		int x_n = ceilf(linear_r * (transform->grid_size-1));
+		int y_n = ceilf(linear_g * (transform->grid_size-1));
+		int z_n = ceilf(linear_b * (transform->grid_size-1));
 		float x_d = linear_r * (transform->grid_size-1) - x;
 		float y_d = linear_g * (transform->grid_size-1) - y;
 		float z_d = linear_b * (transform->grid_size-1) - z;
 
 		float r_x1 = lerp(CLU(r_table,x,y,z), CLU(r_table,x_n,y,z), x_d);
 		float r_x2 = lerp(CLU(r_table,x,y_n,z), CLU(r_table,x_n,y_n,z), x_d);
 		float r_y1 = lerp(r_x1, r_x2, y_d);
 		float r_x3 = lerp(CLU(r_table,x,y,z_n), CLU(r_table,x_n,y,z_n), x_d);
@@ -266,22 +266,22 @@ static void qcms_transform_module_tetra_
 		float device_b = *src++;
 		float linear_r = lut_interp_linear_float(device_r,
 				transform->input_clut_table_r, transform->input_clut_table_length);
 		float linear_g = lut_interp_linear_float(device_g,
 				transform->input_clut_table_g, transform->input_clut_table_length);
 		float linear_b = lut_interp_linear_float(device_b,
 				transform->input_clut_table_b, transform->input_clut_table_length);
 
-		int x = floor(linear_r * (transform->grid_size-1));
-		int y = floor(linear_g * (transform->grid_size-1));
-		int z = floor(linear_b * (transform->grid_size-1));
-		int x_n = ceil(linear_r * (transform->grid_size-1));
-		int y_n = ceil(linear_g * (transform->grid_size-1));
-		int z_n = ceil(linear_b * (transform->grid_size-1));
+		int x = floorf(linear_r * (transform->grid_size-1));
+		int y = floorf(linear_g * (transform->grid_size-1));
+		int z = floorf(linear_b * (transform->grid_size-1));
+		int x_n = ceilf(linear_r * (transform->grid_size-1));
+		int y_n = ceilf(linear_g * (transform->grid_size-1));
+		int z_n = ceilf(linear_b * (transform->grid_size-1));
 		float rx = linear_r * (transform->grid_size-1) - x;
 		float ry = linear_g * (transform->grid_size-1) - y;
 		float rz = linear_b * (transform->grid_size-1) - z;
 
 		c0_r = CLU(r_table, x, y, z);
 		c0_g = CLU(g_table, x, y, z);
 		c0_b = CLU(b_table, x, y, z);
 		if( rx >= ry ) {
--- a/gfx/qcms/transform.c
+++ b/gfx/qcms/transform.c
@@ -430,22 +430,22 @@ static void qcms_transform_data_clut(qcm
 	float* b_table = transform->b_clut;
   
 	for (i = 0; i < length; i++) {
 		unsigned char in_r = *src++;
 		unsigned char in_g = *src++;
 		unsigned char in_b = *src++;
 		float linear_r = in_r/255.0f, linear_g=in_g/255.0f, linear_b = in_b/255.0f;
 
-		int x = floor(linear_r * (transform->grid_size-1));
-		int y = floor(linear_g * (transform->grid_size-1));
-		int z = floor(linear_b * (transform->grid_size-1));
-		int x_n = ceil(linear_r * (transform->grid_size-1));
-		int y_n = ceil(linear_g * (transform->grid_size-1));
-		int z_n = ceil(linear_b * (transform->grid_size-1));
+		int x = floorf(linear_r * (transform->grid_size-1));
+		int y = floorf(linear_g * (transform->grid_size-1));
+		int z = floorf(linear_b * (transform->grid_size-1));
+		int x_n = ceilf(linear_r * (transform->grid_size-1));
+		int y_n = ceilf(linear_g * (transform->grid_size-1));
+		int z_n = ceilf(linear_b * (transform->grid_size-1));
 		float x_d = linear_r * (transform->grid_size-1) - x; 
 		float y_d = linear_g * (transform->grid_size-1) - y;
 		float z_d = linear_b * (transform->grid_size-1) - z; 
 
 		float r_x1 = lerp(CLU(r_table,x,y,z), CLU(r_table,x_n,y,z), x_d);
 		float r_x2 = lerp(CLU(r_table,x,y_n,z), CLU(r_table,x_n,y_n,z), x_d);
 		float r_y1 = lerp(r_x1, r_x2, y_d);
 		float r_x3 = lerp(CLU(r_table,x,y,z_n), CLU(r_table,x_n,y,z_n), x_d);
@@ -491,22 +491,22 @@ static void qcms_transform_data_tetra_cl
 	float clut_r, clut_g, clut_b;
 	for (i = 0; i < length; i++) {
 		unsigned char in_r = *src++;
 		unsigned char in_g = *src++;
 		unsigned char in_b = *src++;
 		unsigned char in_a = *src++;
 		float linear_r = in_r/255.0f, linear_g=in_g/255.0f, linear_b = in_b/255.0f;
 
-		int x = floor(linear_r * (transform->grid_size-1));
-		int y = floor(linear_g * (transform->grid_size-1));
-		int z = floor(linear_b * (transform->grid_size-1));
-		int x_n = ceil(linear_r * (transform->grid_size-1));
-		int y_n = ceil(linear_g * (transform->grid_size-1));
-		int z_n = ceil(linear_b * (transform->grid_size-1));
+		int x = floorf(linear_r * (transform->grid_size-1));
+		int y = floorf(linear_g * (transform->grid_size-1));
+		int z = floorf(linear_b * (transform->grid_size-1));
+		int x_n = ceilf(linear_r * (transform->grid_size-1));
+		int y_n = ceilf(linear_g * (transform->grid_size-1));
+		int z_n = ceilf(linear_b * (transform->grid_size-1));
 		float rx = linear_r * (transform->grid_size-1) - x; 
 		float ry = linear_g * (transform->grid_size-1) - y;
 		float rz = linear_b * (transform->grid_size-1) - z; 
 
 		c0_r = CLU(r_table, x, y, z);
 		c0_g = CLU(g_table, x, y, z);
 		c0_b = CLU(b_table, x, y, z);
 
@@ -606,22 +606,22 @@ static void qcms_transform_data_tetra_cl
 	float c0_b, c1_b, c2_b, c3_b;
 	float clut_r, clut_g, clut_b;
 	for (i = 0; i < length; i++) {
 		unsigned char in_r = *src++;
 		unsigned char in_g = *src++;
 		unsigned char in_b = *src++;
 		float linear_r = in_r/255.0f, linear_g=in_g/255.0f, linear_b = in_b/255.0f;
 
-		int x = floor(linear_r * (transform->grid_size-1));
-		int y = floor(linear_g * (transform->grid_size-1));
-		int z = floor(linear_b * (transform->grid_size-1));
-		int x_n = ceil(linear_r * (transform->grid_size-1));
-		int y_n = ceil(linear_g * (transform->grid_size-1));
-		int z_n = ceil(linear_b * (transform->grid_size-1));
+		int x = floorf(linear_r * (transform->grid_size-1));
+		int y = floorf(linear_g * (transform->grid_size-1));
+		int z = floorf(linear_b * (transform->grid_size-1));
+		int x_n = ceilf(linear_r * (transform->grid_size-1));
+		int y_n = ceilf(linear_g * (transform->grid_size-1));
+		int z_n = ceilf(linear_b * (transform->grid_size-1));
 		float rx = linear_r * (transform->grid_size-1) - x; 
 		float ry = linear_g * (transform->grid_size-1) - y;
 		float rz = linear_b * (transform->grid_size-1) - z; 
 
 		c0_r = CLU(r_table, x, y, z);
 		c0_g = CLU(g_table, x, y, z);
 		c0_b = CLU(b_table, x, y, z);
 
--- a/gfx/qcms/transform_util.c
+++ b/gfx/qcms/transform_util.c
@@ -71,18 +71,18 @@ uint8_t lut_interp_linear_precache_outpu
 }
 
 /* value must be a value between 0 and 1 */
 //XXX: is the above a good restriction to have?
 float lut_interp_linear_float(float value, float *table, int length)
 {
         int upper, lower;
         value = value * (length - 1);
-        upper = ceil(value);
-        lower = floor(value);
+        upper = ceilf(value);
+        lower = floorf(value);
         //XXX: can we be more performant here?
         value = table[upper]*(1. - (upper - value)) + table[lower]*(upper - value);
         /* scale the value */
         return value;
 }
 
 #if 0
 /* if we use a different representation i.e. one that goes from 0 to 0x1000 we can be more efficient