diff options
author | Brian Paul <[email protected]> | 2004-02-28 20:12:33 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2004-02-28 20:12:33 +0000 |
commit | d0582776a619cc0633a0cbeea010a0db5e3e210f (patch) | |
tree | 8ab6cc164d5b168715169f9d185f4095956d21f9 /src/mesa/swrast/s_texture.c | |
parent | 456734aa0a6da47ad586f2ec021a429526e3152a (diff) |
move _swrast_texture_table_lookup() to _mesa_lookup_rgba_chan()
Diffstat (limited to 'src/mesa/swrast/s_texture.c')
-rw-r--r-- | src/mesa/swrast/s_texture.c | 274 |
1 files changed, 2 insertions, 272 deletions
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c index 5dff9874d52..22d193381ba 100644 --- a/src/mesa/swrast/s_texture.c +++ b/src/mesa/swrast/s_texture.c @@ -28,6 +28,7 @@ #include "colormac.h" #include "macros.h" #include "imports.h" +#include "pixel.h" #include "texformat.h" #include "teximage.h" @@ -344,277 +345,6 @@ repeat_remainder(GLint a, GLint b) #define K1BIT 32 -/* - * Do the lookup for GL_SGI_texture_color_table. - * XXX merge with _mesa_lookup_rgba in pixel.c - */ -void -_swrast_texture_table_lookup(const struct gl_color_table *table, - GLuint n, GLchan rgba[][4]) -{ - if (!table->Table || table->Size == 0) - return; - - switch (table->Format) { - case GL_INTENSITY: - /* replace RGBA with I */ - if (table->Type == GL_FLOAT) { - const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF; - const GLfloat *lut = (const GLfloat *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLint j = IROUND((GLfloat) rgba[i][RCOMP] * scale); - GLchan c; - CLAMPED_FLOAT_TO_CHAN(c, lut[j]); - rgba[i][RCOMP] = rgba[i][GCOMP] = - rgba[i][BCOMP] = rgba[i][ACOMP] = c; - } - } - else { -#if CHAN_TYPE == GL_UNSIGNED_BYTE - if (table->Size == 256) { - /* common case */ - const GLchan *lut = (const GLchan *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - const GLchan c = lut[rgba[i][RCOMP]]; - rgba[i][RCOMP] = rgba[i][GCOMP] = - rgba[i][BCOMP] = rgba[i][ACOMP] = c; - } - } - else -#endif - { - const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF; - const GLchan *lut = (const GLchan *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLint j = IROUND((GLfloat) rgba[i][RCOMP] * scale); - rgba[i][RCOMP] = rgba[i][GCOMP] = - rgba[i][BCOMP] = rgba[i][ACOMP] = lut[j]; - } - } - } - break; - case GL_LUMINANCE: - /* replace RGB with L */ - if (table->Type == GL_FLOAT) { - const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF; - const GLfloat *lut = (const GLfloat *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLint j = IROUND((GLfloat) rgba[i][RCOMP] * scale); - GLchan c; - CLAMPED_FLOAT_TO_CHAN(c, lut[j]); - rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c; - } - } - else { -#if CHAN_TYPE == GL_UNSIGNED_BYTE - if (table->Size == 256) { - /* common case */ - const GLchan *lut = (const GLchan *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - const GLchan c = lut[rgba[i][RCOMP]]; - rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c; - } - } - else -#endif - { - const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF; - const GLchan *lut = (const GLchan *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLint j = IROUND((GLfloat) rgba[i][RCOMP] * scale); - rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = lut[j]; - } - } - } - break; - case GL_ALPHA: - /* replace A with A */ - if (table->Type == GL_FLOAT) { - const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF; - const GLfloat *lut = (const GLfloat *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLint j = IROUND((GLfloat) rgba[i][ACOMP] * scale); - GLchan c; - CLAMPED_FLOAT_TO_CHAN(c, lut[j]); - rgba[i][ACOMP] = c; - } - } - else { -#if CHAN_TYPE == GL_UNSIGNED_BYTE - if (table->Size == 256) { - /* common case */ - const GLchan *lut = (const GLchan *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - rgba[i][ACOMP] = lut[rgba[i][ACOMP]]; - } - } - else -#endif - { - const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF; - const GLchan *lut = (const GLchan *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLint j = IROUND((GLfloat) rgba[i][ACOMP] * scale); - rgba[i][ACOMP] = lut[j]; - } - } - } - break; - case GL_LUMINANCE_ALPHA: - /* replace RGBA with LLLA */ - if (table->Type == GL_FLOAT) { - const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF; - const GLfloat *lut = (const GLfloat *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLint jL = IROUND((GLfloat) rgba[i][RCOMP] * scale); - GLint jA = IROUND((GLfloat) rgba[i][ACOMP] * scale); - GLchan luminance, alpha; - CLAMPED_FLOAT_TO_CHAN(luminance, lut[jL * 2 + 0]); - CLAMPED_FLOAT_TO_CHAN(alpha, lut[jA * 2 + 1]); - rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance; - rgba[i][ACOMP] = alpha;; - } - } - else { -#if CHAN_TYPE == GL_UNSIGNED_BYTE - if (table->Size == 256) { - /* common case */ - const GLchan *lut = (const GLchan *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLchan l = lut[rgba[i][RCOMP] * 2 + 0]; - GLchan a = lut[rgba[i][ACOMP] * 2 + 1];; - rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = l; - rgba[i][ACOMP] = a; - } - } - else -#endif - { - const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF; - const GLchan *lut = (const GLchan *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLint jL = IROUND((GLfloat) rgba[i][RCOMP] * scale); - GLint jA = IROUND((GLfloat) rgba[i][ACOMP] * scale); - GLchan luminance = lut[jL * 2 + 0]; - GLchan alpha = lut[jA * 2 + 1]; - rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance; - rgba[i][ACOMP] = alpha; - } - } - } - break; - case GL_RGB: - /* replace RGB with RGB */ - if (table->Type == GL_FLOAT) { - const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF; - const GLfloat *lut = (const GLfloat *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLint jR = IROUND((GLfloat) rgba[i][RCOMP] * scale); - GLint jG = IROUND((GLfloat) rgba[i][GCOMP] * scale); - GLint jB = IROUND((GLfloat) rgba[i][BCOMP] * scale); - CLAMPED_FLOAT_TO_CHAN(rgba[i][RCOMP], lut[jR * 3 + 0]); - CLAMPED_FLOAT_TO_CHAN(rgba[i][GCOMP], lut[jG * 3 + 1]); - CLAMPED_FLOAT_TO_CHAN(rgba[i][BCOMP], lut[jB * 3 + 2]); - } - } - else { -#if CHAN_TYPE == GL_UNSIGNED_BYTE - if (table->Size == 256) { - /* common case */ - const GLchan *lut = (const GLchan *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - rgba[i][RCOMP] = lut[rgba[i][RCOMP] * 3 + 0]; - rgba[i][GCOMP] = lut[rgba[i][GCOMP] * 3 + 1]; - rgba[i][BCOMP] = lut[rgba[i][BCOMP] * 3 + 2]; - } - } - else -#endif - { - const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF; - const GLchan *lut = (const GLchan *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLint jR = IROUND((GLfloat) rgba[i][RCOMP] * scale); - GLint jG = IROUND((GLfloat) rgba[i][GCOMP] * scale); - GLint jB = IROUND((GLfloat) rgba[i][BCOMP] * scale); - rgba[i][RCOMP] = lut[jR * 3 + 0]; - rgba[i][GCOMP] = lut[jG * 3 + 1]; - rgba[i][BCOMP] = lut[jB * 3 + 2]; - } - } - } - break; - case GL_RGBA: - /* replace RGBA with RGBA */ - if (table->Type == GL_FLOAT) { - const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF; - const GLfloat *lut = (const GLfloat *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLint jR = IROUND((GLfloat) rgba[i][RCOMP] * scale); - GLint jG = IROUND((GLfloat) rgba[i][GCOMP] * scale); - GLint jB = IROUND((GLfloat) rgba[i][BCOMP] * scale); - GLint jA = IROUND((GLfloat) rgba[i][ACOMP] * scale); - CLAMPED_FLOAT_TO_CHAN(rgba[i][RCOMP], lut[jR * 4 + 0]); - CLAMPED_FLOAT_TO_CHAN(rgba[i][GCOMP], lut[jG * 4 + 1]); - CLAMPED_FLOAT_TO_CHAN(rgba[i][BCOMP], lut[jB * 4 + 2]); - CLAMPED_FLOAT_TO_CHAN(rgba[i][ACOMP], lut[jA * 4 + 3]); - } - } - else { -#if CHAN_TYPE == GL_UNSIGNED_BYTE - if (table->Size == 256) { - /* common case */ - const GLchan *lut = (const GLchan *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - rgba[i][RCOMP] = lut[rgba[i][RCOMP] * 4 + 0]; - rgba[i][GCOMP] = lut[rgba[i][GCOMP] * 4 + 1]; - rgba[i][BCOMP] = lut[rgba[i][BCOMP] * 4 + 2]; - rgba[i][ACOMP] = lut[rgba[i][ACOMP] * 4 + 3]; - } - } - else -#endif - { - const GLfloat scale = (GLfloat) (table->Size - 1) / CHAN_MAXF; - const GLfloat *lut = (const GLfloat *) table->Table; - GLuint i; - for (i = 0; i < n; i++) { - GLint jR = IROUND((GLfloat) rgba[i][RCOMP] * scale); - GLint jG = IROUND((GLfloat) rgba[i][GCOMP] * scale); - GLint jB = IROUND((GLfloat) rgba[i][BCOMP] * scale); - GLint jA = IROUND((GLfloat) rgba[i][ACOMP] * scale); - CLAMPED_FLOAT_TO_CHAN(rgba[i][RCOMP], lut[jR * 4 + 0]); - CLAMPED_FLOAT_TO_CHAN(rgba[i][GCOMP], lut[jG * 4 + 1]); - CLAMPED_FLOAT_TO_CHAN(rgba[i][BCOMP], lut[jB * 4 + 2]); - CLAMPED_FLOAT_TO_CHAN(rgba[i][ACOMP], lut[jA * 4 + 3]); - } - } - } - break; - default: - _mesa_problem(NULL, "Bad format in _swrast_texture_table_lookup"); - return; - } -} - - /* * Get texture palette entry. @@ -4208,7 +3938,7 @@ _swrast_texture_span( GLcontext *ctx, struct sw_span *span ) /* GL_SGI_texture_color_table */ if (texUnit->ColorTableEnabled) { - _swrast_texture_table_lookup(&texUnit->ColorTable, span->end, texels); + _mesa_lookup_rgba_chan(&texUnit->ColorTable, span->end, texels); } } } |