[Mesa-dev] [PATCH 21/22] mesa: Move nonlinear_to_linear() function to format_unpack.h
Eric Anholt
eric at anholt.net
Sat Nov 10 12:47:13 PST 2012
Anuj Phogat <anuj.phogat at gmail.com> writes:
> 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.
> +#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];
> +}
Given that this function has a static stable that it initializes, it
really doesn't want to be an inline function in a header file. Make it
a non-inline function in the original file, imo, or at least make the
table static in the original file.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20121110/f81d9ce6/attachment.pgp>
More information about the mesa-dev
mailing list