[Mesa-dev] [PATCH 21/22] mesa: Move nonlinear_to_linear() function to format_unpack.h

Anuj Phogat anuj.phogat at gmail.com
Fri Nov 9 23:30:08 PST 2012


This patch moves nonlinear_to_linear() function from format_unpack.c
to format_unpack.h and removes the duplicate copies of this function
in other files.

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
 src/mesa/main/format_unpack.c    |   29 -----------------------------
 src/mesa/main/format_unpack.h    |   29 +++++++++++++++++++++++++++++
 src/mesa/main/texcompress_etc.c  |   28 +---------------------------
 src/mesa/main/texcompress_s3tc.c |   28 +---------------------------
 4 files changed, 31 insertions(+), 83 deletions(-)

diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
index d31d2fa..6fd1b02 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -24,7 +24,6 @@
 
 #include "colormac.h"
 #include "format_unpack.h"
-#include "macros.h"
 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
 
@@ -52,34 +51,6 @@ struct z32f_x24s8
 #define EXPAND_6_8(X)  ( ((X) << 2) | ((X) >> 4) )
 
 
-/**
- * Convert an 8-bit sRGB value from non-linear space to a
- * linear RGB value in [0, 1].
- * Implemented with a 256-entry lookup table.
- */
-static inline GLfloat
-nonlinear_to_linear(GLubyte cs8)
-{
-   static GLfloat table[256];
-   static GLboolean tableReady = GL_FALSE;
-   if (!tableReady) {
-      /* compute lookup table now */
-      GLuint i;
-      for (i = 0; i < 256; i++) {
-         const GLfloat cs = UBYTE_TO_FLOAT(i);
-         if (cs <= 0.04045) {
-            table[i] = cs / 12.92f;
-         }
-         else {
-            table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
-         }
-      }
-      tableReady = GL_TRUE;
-   }
-   return table[cs8];
-}
-
-
 /**********************************************************************/
 /*  Unpack, returning GLfloat colors                                  */
 /**********************************************************************/
diff --git a/src/mesa/main/format_unpack.h b/src/mesa/main/format_unpack.h
index aad800d..8a3e9ac 100644
--- a/src/mesa/main/format_unpack.h
+++ b/src/mesa/main/format_unpack.h
@@ -24,6 +24,35 @@
 #ifndef FORMAT_UNPACK_H
 #define FORMAT_UNPACK_H
 
+#include "macros.h"
+
+/**
+ * Convert an 8-bit sRGB value from non-linear space to a
+ * linear RGB value in [0, 1].
+ * Implemented with a 256-entry lookup table.
+ */
+static inline GLfloat
+nonlinear_to_linear(GLubyte cs8)
+{
+   static GLfloat table[256];
+   static GLboolean tableReady = GL_FALSE;
+   if (!tableReady) {
+      /* compute lookup table now */
+      GLuint i;
+      for (i = 0; i < 256; i++) {
+         const GLfloat cs = UBYTE_TO_FLOAT(i);
+         if (cs <= 0.04045) {
+            table[i] = cs / 12.92f;
+         }
+         else {
+            table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
+         }
+      }
+      tableReady = GL_TRUE;
+   }
+   return table[cs8];
+}
+
 extern void
 _mesa_unpack_rgba_row(gl_format format, GLuint n,
                       const void *src, GLfloat dst[][4]);
diff --git a/src/mesa/main/texcompress_etc.c b/src/mesa/main/texcompress_etc.c
index ff7d505..fc9493b 100644
--- a/src/mesa/main/texcompress_etc.c
+++ b/src/mesa/main/texcompress_etc.c
@@ -44,6 +44,7 @@
 #include "texstore.h"
 #include "macros.h"
 #include "swrast/s_context.h"
+#include "format_unpack.h"
 
 struct etc2_block {
    int flipped;
@@ -681,33 +682,6 @@ etc2_r11_parse_block(struct etc2_block *block, const GLubyte *src)
     etc2_alpha8_parse_block(block, src);
 }
 
-/**
- * Convert an 8-bit sRGB value from non-linear space to a
- * linear RGB value in [0, 1].
- * Implemented with a 256-entry lookup table.
- */
-static inline GLfloat
-nonlinear_to_linear(GLubyte cs8)
-{
-   static GLfloat table[256];
-   static GLboolean tableReady = GL_FALSE;
-   if (!tableReady) {
-      /* compute lookup table now */
-      GLuint i;
-      for (i = 0; i < 256; i++) {
-         const GLfloat cs = UBYTE_TO_FLOAT(i);
-         if (cs <= 0.04045) {
-            table[i] = cs / 12.92f;
-         }
-         else {
-            table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
-         }
-      }
-      tableReady = GL_TRUE;
-   }
-   return table[cs8];
-}
-
 static void
 etc2_unpack_rgb8(uint8_t *dst_row,
                  unsigned dst_stride,
diff --git a/src/mesa/main/texcompress_s3tc.c b/src/mesa/main/texcompress_s3tc.c
index 6476f11..8b15774 100644
--- a/src/mesa/main/texcompress_s3tc.c
+++ b/src/mesa/main/texcompress_s3tc.c
@@ -37,6 +37,7 @@
 #include "imports.h"
 #include "colormac.h"
 #include "dlopen.h"
+#include "format_unpack.h"
 #include "image.h"
 #include "macros.h"
 #include "mfeatures.h"
@@ -57,33 +58,6 @@
 #define DXTN_LIBNAME "libtxc_dxtn.so"
 #endif
 
-/**
- * Convert an 8-bit sRGB value from non-linear space to a
- * linear RGB value in [0, 1].
- * Implemented with a 256-entry lookup table.
- */
-static inline GLfloat
-nonlinear_to_linear(GLubyte cs8)
-{
-   static GLfloat table[256];
-   static GLboolean tableReady = GL_FALSE;
-   if (!tableReady) {
-      /* compute lookup table now */
-      GLuint i;
-      for (i = 0; i < 256; i++) {
-         const GLfloat cs = UBYTE_TO_FLOAT(i);
-         if (cs <= 0.04045) {
-            table[i] = cs / 12.92f;
-         }
-         else {
-            table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
-         }
-      }
-      tableReady = GL_TRUE;
-   }
-   return table[cs8];
-}
-
 typedef void (*dxtFetchTexelFuncExt)( GLint srcRowstride, GLubyte *pixdata, GLint col, GLint row, GLvoid *texelOut );
 
 static dxtFetchTexelFuncExt fetch_ext_rgb_dxt1 = NULL;
-- 
1.7.7.6



More information about the mesa-dev mailing list