From 29cbfdf30a19cfbaa282991d3bbead45c892e3e4 Mon Sep 17 00:00:00 2001 From: Benoit Girard Date: Fri, 19 Oct 2012 18:23:07 -0400 Subject: [PATCH] Bug 679527 - Avoid float operation in qcms transforms. r=jrmuizel --- gfx/qcms/transform.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/gfx/qcms/transform.c b/gfx/qcms/transform.c index 103b65bb8ef..fc9541fbdfc 100644 --- a/gfx/qcms/transform.c +++ b/gfx/qcms/transform.c @@ -476,6 +476,10 @@ static void qcms_transform_data_clut(qcms_transform *transform, unsigned char *s } */ +static int int_div_ceil(int value, int div) { + return ((value + div - 1) / div); +} + // Using lcms' tetra interpolation algorithm. static void qcms_transform_data_tetra_clut_rgba(qcms_transform *transform, unsigned char *src, unsigned char *dest, size_t length) { unsigned int i; @@ -496,12 +500,12 @@ static void qcms_transform_data_tetra_clut_rgba(qcms_transform *transform, unsig 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 = 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)); + int x = in_r * (transform->grid_size-1) / 255; + int y = in_g * (transform->grid_size-1) / 255; + int z = in_b * (transform->grid_size-1) / 255; + int x_n = int_div_ceil(in_r * (transform->grid_size-1), 255); + int y_n = int_div_ceil(in_g * (transform->grid_size-1), 255); + int z_n = int_div_ceil(in_b * (transform->grid_size-1), 255); 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; @@ -611,15 +615,15 @@ static void qcms_transform_data_tetra_clut(qcms_transform *transform, unsigned c 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 = 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; + int x = in_r * (transform->grid_size-1) / 255; + int y = in_g * (transform->grid_size-1) / 255; + int z = in_b * (transform->grid_size-1) / 255; + int x_n = int_div_ceil(in_r * (transform->grid_size-1), 255); + int y_n = int_div_ceil(in_g * (transform->grid_size-1), 255); + int z_n = int_div_ceil(in_b * (transform->grid_size-1), 255); + 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; + 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);