[Mesa-dev] [PATCH] gallivm/util: implement requested ubyte to float lookup function
Maxence Le Doré
maxence.ledore at gmail.com
Sun Mar 10 10:30:51 PDT 2013
This was a suggested rework as a todo. The only thing that annoy me is
that the table is initialized in math init function with logarithm and
exponential tables. And ubyte_to_float is not a math function in a way
comparable to exp and log. Feel free to suggest me or do by yourself a
modification that could place this init in a more appropriate place.
From d04055ee06f2c21747607d865dce086e705babcf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maxence=20Le=20Dor=C3=A9?= <maxence.ledore at gmail.com>
Date: Sun, 10 Mar 2013 18:15:47 +0100
Subject: [PATCH] util: implement ubyte to float lookup function
---
src/gallium/auxiliary/util/u_math.c | 10 ++++++++++
src/gallium/auxiliary/util/u_math.h | 9 +++++++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_math.c
b/src/gallium/auxiliary/util/u_math.c
index 2811475..87d42e4 100644
--- a/src/gallium/auxiliary/util/u_math.c
+++ b/src/gallium/auxiliary/util/u_math.c
@@ -56,6 +56,15 @@ init_log2_table(void)
}
+static void
+init_ubyte_to_float_table(void)
+{
+ int i;
+ for (i = 0; i < UBYTE_TO_FLOAT_TABLE_SIZE; i++)
+ ubyte_to_float_table[i] = (float) i * (1.0f / 255.0f);
+}
+
+
/**
* One time init for math utilities.
*/
@@ -66,6 +75,7 @@ util_init_math(void)
if (!initialized) {
init_pow2_table();
init_log2_table();
+ init_ubyte_to_float_table();
initialized = TRUE;
}
}
diff --git a/src/gallium/auxiliary/util/u_math.h
b/src/gallium/auxiliary/util/u_math.h
index 607fbec..6795a54 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -523,14 +523,19 @@ fui( float f )
}
+#define UBYTE_TO_FLOAT_TABLE_SIZE 256
+extern float ubyte_to_float_table[UBYTE_TO_FLOAT_TABLE_SIZE];
+
+
/**
* Convert ubyte to float in [0, 1].
- * XXX a 256-entry lookup table would be slightly faster.
*/
+
+
static INLINE float
ubyte_to_float(ubyte ub)
{
- return (float) ub * (1.0f / 255.0f);
+ return ubyte_to_float_table[ub];
}
--
1.7.9.5
More information about the mesa-dev
mailing list