[Mesa-dev] [PATCH 21/22] mesa: Move nonlinear_to_linear() function to format_unpack.h
Anuj Phogat
anuj.phogat at gmail.com
Mon Nov 12 10:24:54 PST 2012
On Sat, Nov 10, 2012 at 12:47 PM, Eric Anholt <eric at anholt.net> wrote:
> 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.
oops. I'll fix it.
More information about the mesa-dev
mailing list