Initialize 3D lookup table (LUT) via preprocessor?
<p>I am using a lookup table to convert raw pixel data between color spaces and coding variants. This is the definition of my LUT:</p>

<pre><code>typedef struct
{
    unsigned char data[3];
} rgb;

rgb LUTYUVTORGB[256][256][256];
</code></pre>

<p>It is initialized like this:</p>

<pre><code>// loop through all possible values
for (int in_1 = 0; in_1 &lt; 256; in_1++) {
    for (int in_2 = 0; in_2 &lt; 256; in_2++) {
        for (int in_3 = 0; in_3 &lt; 256; in_3++) {

            int out_1, out_2, out_3;

            // LUT YUV -&gt; RGB
            // convert to rgb (http://softpixel.com/~cwright/programming/colorspace/yuv/)
            out_1 = (int)(in_1 + 1.4075 * (in_3 - 128));
            out_2 = (int)(in_1 - 0.3455 * (in_2 - 128) - (0.7169 * (in_3 - 128)));
            out_3 = (int)(in_1 + 1.7790 * (in_2 - 128));

            // clamp values
            if (out_1 &lt; 0) { out_1 = 0; } else if (out_1 &gt; 255) { out_1 = 255; }
            if (out_2 &lt; 0) { out_2 = 0; } else if (out_2 &gt; 255) { out_2 = 255; }
            if (out_3 &lt; 0) { out_3 = 0; } else if (out_3 &gt; 255) { out_3 = 255; }

            // set values in LUT
            LUTYUVTORGB[in_1][in_2][in_3].data[0] = (unsigned char)out_1;
            LUTYUVTORGB[in_1][in_2][in_3].data[1] = (unsigned char)out_2;
            LUTYUVTORGB[in_1][in_2][in_3].data[2] = (unsigned char)out_3;
        }
    }
}
</code></pre>

<p>The LUT is then applied to copy the raw pixel data to a QImage():</p>

<pre><code>for (int y = 0; y &lt; h; y++) {
    for (int x = 0; x &lt; w; x++) {
        xpos = (y*w + x); // don't calculate 3 times
        buff[x * 3 + 0] = psImage-&gt;comps[0].data[xpos];
        buff[x * 3 + 1] = psImage-&gt;comps[1].data[xpos];
        buff[x * 3 + 2] = psImage-&gt;comps[2].data[xpos];
    }
    memcpy(image.scanLine(y), buff, bytes_per_line);
}
</code></pre>

<p>The values of the LUT are static, and have to be initialized every time the programm starts. Is there any way to initialize it via the preprocessor? Or would it be recommendable to save it in a file?</p>

<p>EDIT: The conversion is used in a time critical video application where every frame has to be processed individually.</p>

<p>Thanks very much in advance!</p>