aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/format_unpack.c
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/mesa/main/format_unpack.c')
-rw-r--r--mesalib/src/mesa/main/format_unpack.c69
1 files changed, 21 insertions, 48 deletions
diff --git a/mesalib/src/mesa/main/format_unpack.c b/mesalib/src/mesa/main/format_unpack.c
index ad5ea4cd1..b84ed0248 100644
--- a/mesalib/src/mesa/main/format_unpack.c
+++ b/mesalib/src/mesa/main/format_unpack.c
@@ -28,6 +28,7 @@
#include "macros.h"
#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
+#include "util/format_srgb.h"
/** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
@@ -53,34 +54,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.
- */
-GLfloat
-_mesa_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 */
/**********************************************************************/
@@ -763,9 +736,9 @@ unpack_BGR_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] = _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][RCOMP] = util_format_srgb_8unorm_to_linear_float(s[i*3+2]);
+ dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float(s[i*3+1]);
+ dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i*3+0]);
dst[i][ACOMP] = 1.0F;
}
}
@@ -776,9 +749,9 @@ unpack_A8B8G8R8_SRGB(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] = _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][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 24) );
+ dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
+ dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff );
dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
}
}
@@ -789,9 +762,9 @@ unpack_B8G8R8A8_SRGB(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] = _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][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
+ dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff );
+ dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff );
dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
}
}
@@ -802,9 +775,9 @@ unpack_R8G8B8A8_SRGB(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] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff );
- dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff );
- dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
+ dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff );
+ dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff );
+ dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
}
}
@@ -817,7 +790,7 @@ unpack_L_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
for (i = 0; i < n; i++) {
dst[i][RCOMP] =
dst[i][GCOMP] =
- dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i]);
+ dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i]);
dst[i][ACOMP] = 1.0F;
}
}
@@ -830,7 +803,7 @@ unpack_L8A8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
for (i = 0; i < n; i++) {
dst[i][RCOMP] =
dst[i][GCOMP] =
- dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i] & 0xff);
+ dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i] & 0xff);
dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
}
}
@@ -2124,9 +2097,9 @@ unpack_R8G8B8X8_SRGB(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] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff );
- dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff );
- dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
+ dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff );
+ dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff );
+ dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
}
}
@@ -2319,9 +2292,9 @@ unpack_B8G8R8X8_SRGB(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] = _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][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
+ dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff );
+ dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff );
dst[i][ACOMP] = 1.0F;
}
}