diff options
Diffstat (limited to 'src/mesa/swrast')
-rw-r--r-- | src/mesa/swrast/s_texfetch.c | 30 | ||||
-rw-r--r-- | src/mesa/swrast/s_texfetch_tmp.h | 34 |
2 files changed, 18 insertions, 46 deletions
diff --git a/src/mesa/swrast/s_texfetch.c b/src/mesa/swrast/s_texfetch.c index e508368c8dc..aef02321764 100644 --- a/src/mesa/swrast/s_texfetch.c +++ b/src/mesa/swrast/s_texfetch.c @@ -46,35 +46,7 @@ #include "s_texfetch.h" #include "../../gallium/auxiliary/util/u_format_rgb9e5.h" #include "../../gallium/auxiliary/util/u_format_r11g11b10f.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]; -} - +#include "util/format_srgb.h" /* Texel fetch routines for all supported formats diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h index deda59246c0..72037ec0020 100644 --- a/src/mesa/swrast/s_texfetch_tmp.h +++ b/src/mesa/swrast/s_texfetch_tmp.h @@ -737,9 +737,9 @@ FETCH(BGR_SRGB8)(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3); - texel[RCOMP] = nonlinear_to_linear(src[2]); - texel[GCOMP] = nonlinear_to_linear(src[1]); - texel[BCOMP] = nonlinear_to_linear(src[0]); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(src[2]); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(src[1]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(src[0]); texel[ACOMP] = 1.0F; } @@ -749,9 +749,9 @@ FETCH(A8B8G8R8_SRGB)(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1); - texel[RCOMP] = nonlinear_to_linear( (s >> 24) ); - texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff ); - texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff ); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 24) ); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff ); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff ); texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */ } @@ -761,9 +761,9 @@ FETCH(B8G8R8A8_SRGB)(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1); - texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff ); - texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff ); - texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff ); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff ); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff ); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s ) & 0xff ); texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */ } @@ -773,9 +773,9 @@ FETCH(R8G8B8A8_SRGB)(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1); - texel[RCOMP] = nonlinear_to_linear( (s ) & 0xff ); - texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff ); - texel[BCOMP] = nonlinear_to_linear( (s >> 16) & 0xff ); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float( (s ) & 0xff ); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff ); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff ); texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */ } @@ -785,9 +785,9 @@ FETCH(R8G8B8X8_SRGB)(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) { const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1); - texel[RCOMP] = nonlinear_to_linear( (s ) & 0xff ); - texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff ); - texel[BCOMP] = nonlinear_to_linear( (s >> 16) & 0xff ); + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float( (s ) & 0xff ); + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff ); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff ); texel[ACOMP] = 1.0f; } @@ -799,7 +799,7 @@ FETCH(L_SRGB8)(const struct swrast_texture_image *texImage, const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1); texel[RCOMP] = texel[GCOMP] = - texel[BCOMP] = nonlinear_to_linear(src[0]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(src[0]); texel[ACOMP] = 1.0F; } @@ -811,7 +811,7 @@ FETCH(L8A8_SRGB)(const struct swrast_texture_image *texImage, const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2); texel[RCOMP] = texel[GCOMP] = - texel[BCOMP] = nonlinear_to_linear(src[0]); + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(src[0]); texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */ } |