summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/macros.h
diff options
context:
space:
mode:
authorVinson Lee <[email protected]>2010-07-09 15:06:19 -0700
committerVinson Lee <[email protected]>2010-07-09 15:06:19 -0700
commit343b38a692a43f091117e05287748d9b2f093aee (patch)
tree886efd59d93be497c76c5906d39310eb739fa1eb /src/mesa/main/macros.h
parent347c00c46e9ecf858a8c21abf58a706b658b5b37 (diff)
mesa: Move [UN]CLAMPED_FLOAT_TO_UBYTE from imports.h to macros.h.
The other similar integer/float conversion macros are in macros.h.
Diffstat (limited to 'src/mesa/main/macros.h')
-rw-r--r--src/mesa/main/macros.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h
index 40e17e53d6c..b2ec0ba9b73 100644
--- a/src/mesa/main/macros.h
+++ b/src/mesa/main/macros.h
@@ -130,6 +130,41 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256];
#define UNCLAMPED_FLOAT_TO_SHORT(s, f) \
s = ( (GLshort) IROUND( CLAMP((f), -1.0F, 1.0F) * 32767.0F) )
+/***
+ *** UNCLAMPED_FLOAT_TO_UBYTE: clamp float to [0,1] and map to ubyte in [0,255]
+ *** CLAMPED_FLOAT_TO_UBYTE: map float known to be in [0,1] to ubyte in [0,255]
+ ***/
+#if defined(USE_IEEE) && !defined(DEBUG)
+#define IEEE_0996 0x3f7f0000 /* 0.996 or so */
+/* This function/macro is sensitive to precision. Test very carefully
+ * if you change it!
+ */
+#define UNCLAMPED_FLOAT_TO_UBYTE(UB, F) \
+ do { \
+ fi_type __tmp; \
+ __tmp.f = (F); \
+ if (__tmp.i < 0) \
+ UB = (GLubyte) 0; \
+ else if (__tmp.i >= IEEE_0996) \
+ UB = (GLubyte) 255; \
+ else { \
+ __tmp.f = __tmp.f * (255.0F/256.0F) + 32768.0F; \
+ UB = (GLubyte) __tmp.i; \
+ } \
+ } while (0)
+#define CLAMPED_FLOAT_TO_UBYTE(UB, F) \
+ do { \
+ fi_type __tmp; \
+ __tmp.f = (F) * (255.0F/256.0F) + 32768.0F; \
+ UB = (GLubyte) __tmp.i; \
+ } while (0)
+#else
+#define UNCLAMPED_FLOAT_TO_UBYTE(ub, f) \
+ ub = ((GLubyte) IROUND(CLAMP((f), 0.0F, 1.0F) * 255.0F))
+#define CLAMPED_FLOAT_TO_UBYTE(ub, f) \
+ ub = ((GLubyte) IROUND((f) * 255.0F))
+#endif
+
/*@}*/