#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 */
const GLfloat src[][4], void *dst);
-
-static inline GLfloat
-linear_to_srgb(GLfloat cl)
-{
- if (cl < 0.0f)
- return 0.0f;
- else if (cl < 0.0031308f)
- return 12.92f * cl;
- else if (cl < 1.0f)
- return 1.055f * powf(cl, 0.41666f) - 0.055f;
- else
- return 1.0f;
-}
-
-
-static inline GLubyte
-linear_float_to_srgb_ubyte(GLfloat cl)
-{
- GLubyte res = FLOAT_TO_UBYTE(linear_to_srgb(cl));
- return res;
-}
-
-
-static inline GLubyte
-linear_ubyte_to_srgb_ubyte(GLubyte cl)
-{
- GLubyte res = FLOAT_TO_UBYTE(linear_to_srgb(cl / 255.0f));
- return res;
-}
-
-
-
-
/*
* MESA_FORMAT_A8B8G8R8_UNORM
*/
pack_ubyte_BGR_SRGB8(const GLubyte src[4], void *dst)
{
GLubyte *d = ((GLubyte *) dst);
- d[2] = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
- d[1] = linear_ubyte_to_srgb_ubyte(src[GCOMP]);
- d[0] = linear_ubyte_to_srgb_ubyte(src[BCOMP]);
+ d[2] = util_format_linear_to_srgb_8unorm(src[RCOMP]);
+ d[1] = util_format_linear_to_srgb_8unorm(src[GCOMP]);
+ d[0] = util_format_linear_to_srgb_8unorm(src[BCOMP]);
}
static void
pack_float_BGR_SRGB8(const GLfloat src[4], void *dst)
{
GLubyte *d = ((GLubyte *) dst);
- d[2] = linear_float_to_srgb_ubyte(src[RCOMP]);
- d[1] = linear_float_to_srgb_ubyte(src[GCOMP]);
- d[0] = linear_float_to_srgb_ubyte(src[BCOMP]);
+ d[2] = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
+ d[1] = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
+ d[0] = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
}
pack_ubyte_A8B8G8R8_SRGB(const GLubyte src[4], void *dst)
{
GLuint *d = ((GLuint *) dst);
- GLubyte r = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
- GLubyte g = linear_ubyte_to_srgb_ubyte(src[GCOMP]);
- GLubyte b = linear_ubyte_to_srgb_ubyte(src[BCOMP]);
+ GLubyte r = util_format_linear_to_srgb_8unorm(src[RCOMP]);
+ GLubyte g = util_format_linear_to_srgb_8unorm(src[GCOMP]);
+ GLubyte b = util_format_linear_to_srgb_8unorm(src[BCOMP]);
*d = PACK_COLOR_8888(r, g, b, src[ACOMP]);
}
{
GLuint *d = ((GLuint *) dst);
GLubyte r, g, b, a;
- r = linear_float_to_srgb_ubyte(src[RCOMP]);
- g = linear_float_to_srgb_ubyte(src[GCOMP]);
- b = linear_float_to_srgb_ubyte(src[BCOMP]);
+ r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
+ g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
+ b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
UNCLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]);
*d = PACK_COLOR_8888(r, g, b, a);
}
pack_ubyte_B8G8R8A8_SRGB(const GLubyte src[4], void *dst)
{
GLuint *d = ((GLuint *) dst);
- GLubyte r = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
- GLubyte g = linear_ubyte_to_srgb_ubyte(src[GCOMP]);
- GLubyte b = linear_ubyte_to_srgb_ubyte(src[BCOMP]);
+ GLubyte r = util_format_linear_to_srgb_8unorm(src[RCOMP]);
+ GLubyte g = util_format_linear_to_srgb_8unorm(src[GCOMP]);
+ GLubyte b = util_format_linear_to_srgb_8unorm(src[BCOMP]);
*d = PACK_COLOR_8888(src[ACOMP], r, g, b);
}
{
GLuint *d = ((GLuint *) dst);
GLubyte r, g, b, a;
- r = linear_float_to_srgb_ubyte(src[RCOMP]);
- g = linear_float_to_srgb_ubyte(src[GCOMP]);
- b = linear_float_to_srgb_ubyte(src[BCOMP]);
+ r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
+ g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
+ b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
UNCLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]);
*d = PACK_COLOR_8888(a, r, g, b);
}
pack_ubyte_R8G8B8A8_SRGB(const GLubyte src[4], void *dst)
{
GLuint *d = ((GLuint *) dst);
- GLubyte r = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
- GLubyte g = linear_ubyte_to_srgb_ubyte(src[GCOMP]);
- GLubyte b = linear_ubyte_to_srgb_ubyte(src[BCOMP]);
+ GLubyte r = util_format_linear_to_srgb_8unorm(src[RCOMP]);
+ GLubyte g = util_format_linear_to_srgb_8unorm(src[GCOMP]);
+ GLubyte b = util_format_linear_to_srgb_8unorm(src[BCOMP]);
*d = PACK_COLOR_8888(src[ACOMP], b, g, r);
}
{
GLuint *d = ((GLuint *) dst);
GLubyte r, g, b, a;
- r = linear_float_to_srgb_ubyte(src[RCOMP]);
- g = linear_float_to_srgb_ubyte(src[GCOMP]);
- b = linear_float_to_srgb_ubyte(src[BCOMP]);
+ r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
+ g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
+ b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
UNCLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]);
*d = PACK_COLOR_8888(a, b, g, r);
}
pack_ubyte_L_SRGB8(const GLubyte src[4], void *dst)
{
GLubyte *d = ((GLubyte *) dst);
- *d = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
+ *d = util_format_linear_to_srgb_8unorm(src[RCOMP]);
}
static void
pack_float_L_SRGB8(const GLfloat src[4], void *dst)
{
GLubyte *d = ((GLubyte *) dst);
- GLubyte l = linear_float_to_srgb_ubyte(src[RCOMP]);
+ GLubyte l = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
*d = l;
}
pack_ubyte_L8A8_SRGB(const GLubyte src[4], void *dst)
{
GLushort *d = ((GLushort *) dst);
- GLubyte l = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
+ GLubyte l = util_format_linear_to_srgb_8unorm(src[RCOMP]);
*d = PACK_COLOR_88(src[ACOMP], l);
}
pack_float_L8A8_SRGB(const GLfloat src[4], void *dst)
{
GLushort *d = ((GLushort *) dst);
- GLubyte a, l = linear_float_to_srgb_ubyte(src[RCOMP]);
+ GLubyte a, l = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
CLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]);
*d = PACK_COLOR_88(a, l);
}
pack_float_R8G8B8X8_SRGB(const GLfloat src[4], void *dst)
{
GLuint *d = (GLuint *) dst;
- GLubyte r = linear_float_to_srgb_ubyte(src[RCOMP]);
- GLubyte g = linear_float_to_srgb_ubyte(src[GCOMP]);
- GLubyte b = linear_float_to_srgb_ubyte(src[BCOMP]);
+ GLubyte r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
+ GLubyte g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
+ GLubyte b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
*d = PACK_COLOR_8888(127, b, g, r);
}
pack_float_B8G8R8X8_SRGB(const GLfloat src[4], void *dst)
{
GLuint *d = (GLuint *) dst;
- GLubyte r = linear_float_to_srgb_ubyte(src[RCOMP]);
- GLubyte g = linear_float_to_srgb_ubyte(src[GCOMP]);
- GLubyte b = linear_float_to_srgb_ubyte(src[BCOMP]);
+ GLubyte r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
+ GLubyte g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
+ GLubyte b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
*d = PACK_COLOR_8888(127, r, g, b);
}
#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 */
#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 */
/**********************************************************************/
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;
}
}
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! */
}
}
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! */
}
}
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! */
}
}
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;
}
}
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! */
}
}
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! */
}
}
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;
}
}
#ifndef FORMAT_UNPACK_H
#define FORMAT_UNPACK_H
-extern GLfloat
-_mesa_nonlinear_to_linear(GLubyte cs8);
-
extern void
_mesa_unpack_rgba_row(mesa_format format, GLuint n,
const void *src, GLfloat dst[][4]);
#include "texstore.h"
#include "macros.h"
#include "format_unpack.h"
+#include "util/format_srgb.h"
struct etc2_block {
etc2_rgb8_fetch_texel(&block, i % 4, j % 4, dst,
false /* punchthrough_alpha */);
- texel[RCOMP] = _mesa_nonlinear_to_linear(dst[0]);
- texel[GCOMP] = _mesa_nonlinear_to_linear(dst[1]);
- texel[BCOMP] = _mesa_nonlinear_to_linear(dst[2]);
+ texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(dst[0]);
+ texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(dst[1]);
+ texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(dst[2]);
texel[ACOMP] = 1.0f;
}
etc2_rgba8_parse_block(&block, src);
etc2_rgba8_fetch_texel(&block, i % 4, j % 4, dst);
- texel[RCOMP] = _mesa_nonlinear_to_linear(dst[0]);
- texel[GCOMP] = _mesa_nonlinear_to_linear(dst[1]);
- texel[BCOMP] = _mesa_nonlinear_to_linear(dst[2]);
+ texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(dst[0]);
+ texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(dst[1]);
+ texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(dst[2]);
texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]);
}
true /* punchthrough alpha */);
etc2_rgb8_fetch_texel(&block, i % 4, j % 4, dst,
true /* punchthrough alpha */);
- texel[RCOMP] = _mesa_nonlinear_to_linear(dst[0]);
- texel[GCOMP] = _mesa_nonlinear_to_linear(dst[1]);
- texel[BCOMP] = _mesa_nonlinear_to_linear(dst[2]);
+ texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(dst[0]);
+ texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(dst[1]);
+ texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(dst[2]);
texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]);
}
#include "texcompress_s3tc.h"
#include "texstore.h"
#include "format_unpack.h"
+#include "util/format_srgb.h"
#if defined(_WIN32) || defined(WIN32)
if (fetch_ext_rgb_dxt1) {
GLubyte tex[4];
fetch_ext_rgb_dxt1(rowStride, map, i, j, tex);
- texel[RCOMP] = _mesa_nonlinear_to_linear(tex[RCOMP]);
- texel[GCOMP] = _mesa_nonlinear_to_linear(tex[GCOMP]);
- texel[BCOMP] = _mesa_nonlinear_to_linear(tex[BCOMP]);
+ texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]);
+ texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]);
+ texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]);
texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
}
else {
if (fetch_ext_rgba_dxt1) {
GLubyte tex[4];
fetch_ext_rgba_dxt1(rowStride, map, i, j, tex);
- texel[RCOMP] = _mesa_nonlinear_to_linear(tex[RCOMP]);
- texel[GCOMP] = _mesa_nonlinear_to_linear(tex[GCOMP]);
- texel[BCOMP] = _mesa_nonlinear_to_linear(tex[BCOMP]);
+ texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]);
+ texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]);
+ texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]);
texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
}
else {
if (fetch_ext_rgba_dxt3) {
GLubyte tex[4];
fetch_ext_rgba_dxt3(rowStride, map, i, j, tex);
- texel[RCOMP] = _mesa_nonlinear_to_linear(tex[RCOMP]);
- texel[GCOMP] = _mesa_nonlinear_to_linear(tex[GCOMP]);
- texel[BCOMP] = _mesa_nonlinear_to_linear(tex[BCOMP]);
+ texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]);
+ texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]);
+ texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]);
texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
}
else {
if (fetch_ext_rgba_dxt5) {
GLubyte tex[4];
fetch_ext_rgba_dxt5(rowStride, map, i, j, tex);
- texel[RCOMP] = _mesa_nonlinear_to_linear(tex[RCOMP]);
- texel[GCOMP] = _mesa_nonlinear_to_linear(tex[GCOMP]);
- texel[BCOMP] = _mesa_nonlinear_to_linear(tex[BCOMP]);
+ texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]);
+ texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]);
+ texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]);
texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
}
else {
#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
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;
}
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! */
}
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! */
}
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! */
}
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;
}
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;
}
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 */
}
#define U_FORMAT_SRGB_H_
#include <stdint.h>
+#include <math.h>
extern const float
util_format_srgb_8unorm_to_linear_float_table[256];
util_format_linear_to_srgb_helper_table[104];
+static inline float
+util_format_linear_to_srgb_float(float cl)
+{
+ if (cl < 0.0f)
+ return 0.0f;
+ else if (cl < 0.0031308f)
+ return 12.92f * cl;
+ else if (cl < 1.0f)
+ return 1.055f * powf(cl, 0.41666f) - 0.055f;
+ else
+ return 1.0f;
+}
+
+
/**
* Convert a unclamped linear float to srgb value in the [0,255].
*/