diff options
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/format_unpack.c | 26 | ||||
-rw-r--r-- | src/mesa/main/format_unpack.h | 3 | ||||
-rw-r--r-- | src/mesa/main/texcompress_s3tc.c | 52 |
3 files changed, 29 insertions, 52 deletions
diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c index 7bbdebb3aa4..d34a27b8273 100644 --- a/src/mesa/main/format_unpack.c +++ b/src/mesa/main/format_unpack.c @@ -57,8 +57,8 @@ struct z32f_x24s8 * linear RGB value in [0, 1]. * Implemented with a 256-entry lookup table. */ -static inline GLfloat -nonlinear_to_linear(GLubyte cs8) +GLfloat +_mesa_nonlinear_to_linear(GLubyte cs8) { static GLfloat table[256]; static GLboolean tableReady = GL_FALSE; @@ -742,9 +742,9 @@ unpack_SRGB8(const void *src, GLfloat dst[][4], GLuint n) const GLubyte *s = (const GLubyte *) src; GLuint i; for (i = 0; i < n; i++) { - dst[i][RCOMP] = nonlinear_to_linear(s[i*3+2]); - dst[i][GCOMP] = nonlinear_to_linear(s[i*3+1]); - dst[i][BCOMP] = nonlinear_to_linear(s[i*3+0]); + dst[i][RCOMP] = _mesa_nonlinear_to_linear(s[i*3+2]); + dst[i][GCOMP] = _mesa_nonlinear_to_linear(s[i*3+1]); + dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i*3+0]); dst[i][ACOMP] = 1.0F; } } @@ -755,9 +755,9 @@ unpack_SRGBA8(const void *src, GLfloat dst[][4], GLuint n) const GLuint *s = ((const GLuint *) src); GLuint i; for (i = 0; i < n; i++) { - dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 24) ); - dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff ); - dst[i][BCOMP] = nonlinear_to_linear( (s[i] >> 8) & 0xff ); + dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 24) ); + dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff ); + dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff ); dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */ } } @@ -768,9 +768,9 @@ unpack_SARGB8(const void *src, GLfloat dst[][4], GLuint n) const GLuint *s = ((const GLuint *) src); GLuint i; for (i = 0; i < n; i++) { - dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff ); - dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 8) & 0xff ); - dst[i][BCOMP] = nonlinear_to_linear( (s[i] ) & 0xff ); + dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff ); + dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff ); + dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff ); dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */ } } @@ -783,7 +783,7 @@ unpack_SL8(const void *src, GLfloat dst[][4], GLuint n) for (i = 0; i < n; i++) { dst[i][RCOMP] = dst[i][GCOMP] = - dst[i][BCOMP] = nonlinear_to_linear(s[i]); + dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i]); dst[i][ACOMP] = 1.0F; } } @@ -796,7 +796,7 @@ unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n) for (i = 0; i < n; i++) { dst[i][RCOMP] = dst[i][GCOMP] = - dst[i][BCOMP] = nonlinear_to_linear(s[i] & 0xff); + dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i] & 0xff); dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */ } } diff --git a/src/mesa/main/format_unpack.h b/src/mesa/main/format_unpack.h index aad800dd15a..29c526319bc 100644 --- a/src/mesa/main/format_unpack.h +++ b/src/mesa/main/format_unpack.h @@ -24,6 +24,9 @@ #ifndef FORMAT_UNPACK_H #define FORMAT_UNPACK_H +extern GLfloat +_mesa_nonlinear_to_linear(GLubyte 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_s3tc.c b/src/mesa/main/texcompress_s3tc.c index da772596488..476b998e078 100644 --- a/src/mesa/main/texcompress_s3tc.c +++ b/src/mesa/main/texcompress_s3tc.c @@ -45,6 +45,7 @@ #include "texcompress_s3tc.h" #include "texstore.h" #include "swrast/s_context.h" +#include "format_unpack.h" #if defined(_WIN32) || defined(WIN32) @@ -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; @@ -476,9 +450,9 @@ _mesa_fetch_texel_srgb_dxt1(const struct swrast_texture_image *texImage, /* just sample as GLubyte and convert to float here */ GLubyte rgba[4]; fetch_texel_2d_rgb_dxt1(texImage, i, j, k, rgba); - texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]); - texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]); - texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]); + texel[RCOMP] = _mesa_nonlinear_to_linear(rgba[RCOMP]); + texel[GCOMP] = _mesa_nonlinear_to_linear(rgba[GCOMP]); + texel[BCOMP] = _mesa_nonlinear_to_linear(rgba[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]); } @@ -489,9 +463,9 @@ _mesa_fetch_texel_srgba_dxt1(const struct swrast_texture_image *texImage, /* just sample as GLubyte and convert to float here */ GLubyte rgba[4]; fetch_texel_2d_rgba_dxt1(texImage, i, j, k, rgba); - texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]); - texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]); - texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]); + texel[RCOMP] = _mesa_nonlinear_to_linear(rgba[RCOMP]); + texel[GCOMP] = _mesa_nonlinear_to_linear(rgba[GCOMP]); + texel[BCOMP] = _mesa_nonlinear_to_linear(rgba[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]); } @@ -502,9 +476,9 @@ _mesa_fetch_texel_srgba_dxt3(const struct swrast_texture_image *texImage, /* just sample as GLubyte and convert to float here */ GLubyte rgba[4]; fetch_texel_2d_rgba_dxt3(texImage, i, j, k, rgba); - texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]); - texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]); - texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]); + texel[RCOMP] = _mesa_nonlinear_to_linear(rgba[RCOMP]); + texel[GCOMP] = _mesa_nonlinear_to_linear(rgba[GCOMP]); + texel[BCOMP] = _mesa_nonlinear_to_linear(rgba[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]); } @@ -515,8 +489,8 @@ _mesa_fetch_texel_srgba_dxt5(const struct swrast_texture_image *texImage, /* just sample as GLubyte and convert to float here */ GLubyte rgba[4]; fetch_texel_2d_rgba_dxt5(texImage, i, j, k, rgba); - texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]); - texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]); - texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]); + texel[RCOMP] = _mesa_nonlinear_to_linear(rgba[RCOMP]); + texel[GCOMP] = _mesa_nonlinear_to_linear(rgba[GCOMP]); + texel[BCOMP] = _mesa_nonlinear_to_linear(rgba[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]); } |