diff options
Diffstat (limited to 'src/mesa/swrast')
-rw-r--r-- | src/mesa/swrast/s_texture.c | 252 |
1 files changed, 251 insertions, 1 deletions
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c index cd86c76bd3d..bc1e14d9672 100644 --- a/src/mesa/swrast/s_texture.c +++ b/src/mesa/swrast/s_texture.c @@ -1,4 +1,4 @@ -/* $Id: s_texture.c,v 1.76 2003/01/21 15:49:19 brianp Exp $ */ +/* $Id: s_texture.c,v 1.77 2003/01/21 21:47:53 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -296,6 +296,198 @@ #define K1BIT 32 +static void texture_table_lookup(const struct gl_color_table *table, + GLuint n, GLchan rgba[][4]) +{ + ASSERT(table->FloatTable); + if (!table->Table || table->Size == 0) + return; + + switch (table->Format) { + case GL_INTENSITY: + /* replace RGBA with I */ + if (!table->FloatTable) { + const GLint max = table->Size - 1; + const GLfloat scale = (GLfloat) max; + const GLchan *lut = (const GLchan *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = CHAN_TO_FLOAT(rgba[i][RCOMP])*scale; + GLchan c = lut[CLAMP(j, 0, 1)]; + rgba[i][RCOMP] = rgba[i][GCOMP] = + rgba[i][BCOMP] = rgba[i][ACOMP] = c; + } + + } + else { + const GLint max = table->Size - 1; + const GLfloat scale = (GLfloat) max; + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = CHAN_TO_FLOAT(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; + } + } + break; + case GL_LUMINANCE: + /* replace RGB with L */ + if (!table->FloatTable) { + const GLint max = table->Size - 1; + const GLfloat scale = (GLfloat) max; + const GLchan *lut = (const GLchan *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = CHAN_TO_FLOAT(rgba[i][RCOMP])*scale; + GLchan c = lut[j]; + rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c; + } + } + else { + const GLint max = table->Size - 1; + const GLfloat scale = (GLfloat) max; + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = CHAN_TO_FLOAT(rgba[i][RCOMP])*scale; + GLchan c; + CLAMPED_FLOAT_TO_CHAN(c, lut[j]); + rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c; + } + } + break; + case GL_ALPHA: + /* replace A with A */ + if (!table->FloatTable) { + const GLint max = table->Size - 1; + const GLfloat scale = (GLfloat) max; + const GLchan *lut = (const GLchan *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = CHAN_TO_FLOAT(rgba[i][ACOMP])*scale; + rgba[i][ACOMP] = lut[j]; + } + } + else { + const GLint max = table->Size - 1; + const GLfloat scale = (GLfloat) max; + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = CHAN_TO_FLOAT(rgba[i][ACOMP])*scale; + CLAMPED_FLOAT_TO_CHAN(rgba[i][ACOMP], lut[j]); + } + } + break; + case GL_LUMINANCE_ALPHA: + /* replace RGBA with LLLA */ + if (!table->FloatTable) { + const GLint max = table->Size - 1; + const GLfloat scale = (GLfloat) max; + const GLchan *lut = (const GLchan *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jL = CHAN_TO_FLOAT(rgba[i][RCOMP])*scale; + GLint jA = CHAN_TO_FLOAT(rgba[i][ACOMP])*scale; + GLchan luminance, alpha; + luminance = lut[jL * 2 + 0]; + alpha = lut[jA * 2 + 1]; + rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance; + rgba[i][ACOMP] = alpha;; + } + } + else { + const GLint max = table->Size - 1; + const GLfloat scale = (GLfloat) max; + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jL = CHAN_TO_FLOAT(rgba[i][RCOMP])*scale; + GLint jA = CHAN_TO_FLOAT(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;; + } + } + break; + case GL_RGB: + /* replace RGB with RGB */ + if (!table->FloatTable) { + const GLint max = table->Size - 1; + const GLfloat scale = (GLfloat) max; + const GLchan *lut = (const GLchan *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jR = CHAN_TO_FLOAT(rgba[i][RCOMP])*scale; + GLint jG = CHAN_TO_FLOAT(rgba[i][GCOMP])*scale; + GLint jB = CHAN_TO_FLOAT(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]; + } + } + else { + const GLint max = table->Size - 1; + const GLfloat scale = (GLfloat) max; + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jR = CHAN_TO_FLOAT(rgba[i][RCOMP])*scale; + GLint jG = CHAN_TO_FLOAT(rgba[i][GCOMP])*scale; + GLint jB = CHAN_TO_FLOAT(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]); + } + } + break; + case GL_RGBA: + /* replace RGBA with RGBA */ + if (!table->FloatTable) { + const GLint max = table->Size - 1; + const GLfloat scale = (GLfloat) max; + const GLchan *lut = (const GLchan *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jR = CHAN_TO_FLOAT(rgba[i][RCOMP])*scale; + GLint jG = CHAN_TO_FLOAT(rgba[i][GCOMP])*scale; + GLint jB = CHAN_TO_FLOAT(rgba[i][BCOMP])*scale; + GLint jA = CHAN_TO_FLOAT(rgba[i][ACOMP])*scale; + rgba[i][RCOMP] = lut[jR * 4 + 0]; + rgba[i][GCOMP] = lut[jG * 4 + 1]; + rgba[i][BCOMP] = lut[jB * 4 + 2]; + rgba[i][ACOMP] = lut[jA * 4 + 3]; + } + } + else { + const GLint max = table->Size - 1; + const GLfloat scale = (GLfloat) max; + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jR = CHAN_TO_FLOAT(rgba[i][RCOMP])*scale; + GLint jG = CHAN_TO_FLOAT(rgba[i][GCOMP])*scale; + GLint jB = CHAN_TO_FLOAT(rgba[i][BCOMP])*scale; + GLint jA = CHAN_TO_FLOAT(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 _mesa_lookup_rgba"); + return; + } +} + + /* * Get texture palette entry. @@ -672,6 +864,10 @@ sample_nearest_1d( GLcontext *ctx, GLuint texUnit, for (i=0;i<n;i++) { sample_1d_nearest(ctx, tObj, image, texcoords[i], rgba[i]); } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } + } @@ -688,6 +884,9 @@ sample_linear_1d( GLcontext *ctx, GLuint texUnit, for (i=0;i<n;i++) { sample_1d_linear(ctx, tObj, image, texcoords[i], rgba[i]); } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -764,6 +963,9 @@ sample_lambda_1d( GLcontext *ctx, GLuint texUnit, return; } } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -1145,6 +1347,9 @@ sample_nearest_2d( GLcontext *ctx, GLuint texUnit, for (i=0;i<n;i++) { sample_2d_nearest(ctx, tObj, image, texcoords[i], rgba[i]); } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -1161,6 +1366,9 @@ sample_linear_2d( GLcontext *ctx, GLuint texUnit, for (i=0;i<n;i++) { sample_2d_linear(ctx, tObj, image, texcoords[i], rgba[i]); } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -1352,6 +1560,9 @@ sample_lambda_2d( GLcontext *ctx, GLuint texUnit, _mesa_problem(ctx, "Bad mag filter in sample_lambda_2d"); } } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -1690,6 +1901,9 @@ sample_nearest_3d(GLcontext *ctx, GLuint texUnit, for (i=0;i<n;i++) { sample_3d_nearest(ctx, tObj, image, texcoords[i], rgba[i]); } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -1706,6 +1920,9 @@ sample_linear_3d( GLcontext *ctx, GLuint texUnit, for (i=0;i<n;i++) { sample_3d_linear(ctx, tObj, image, texcoords[i], rgba[i]); } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -1781,6 +1998,9 @@ sample_lambda_3d( GLcontext *ctx, GLuint texUnit, return; } } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -1879,6 +2099,9 @@ sample_nearest_cube(GLcontext *ctx, GLuint texUnit, sample_2d_nearest(ctx, tObj, images[tObj->BaseLevel], newCoord, rgba[i]); } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -1897,6 +2120,9 @@ sample_linear_cube(GLcontext *ctx, GLuint texUnit, sample_2d_linear(ctx, tObj, images[tObj->BaseLevel], newCoord, rgba[i]); } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -1916,6 +2142,9 @@ sample_cube_nearest_mipmap_nearest(GLcontext *ctx, images = choose_cube_face(tObj, texcoord[i], newCoord); sample_2d_nearest(ctx, tObj, images[level], newCoord, rgba[i]); } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -1935,6 +2164,9 @@ sample_cube_linear_mipmap_nearest(GLcontext *ctx, images = choose_cube_face(tObj, texcoord[i], newCoord); sample_2d_linear(ctx, tObj, images[level], newCoord, rgba[i]); } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -1967,6 +2199,9 @@ sample_cube_nearest_mipmap_linear(GLcontext *ctx, rgba[i][ACOMP] = CHAN_CAST ((1.0F-f) * t0[ACOMP] + f * t1[ACOMP]); } } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -1999,6 +2234,9 @@ sample_cube_linear_mipmap_linear(GLcontext *ctx, rgba[i][ACOMP] = CHAN_CAST ((1.0F-f) * t0[ACOMP] + f * t1[ACOMP]); } } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -2064,6 +2302,9 @@ sample_lambda_cube( GLcontext *ctx, GLuint texUnit, _mesa_problem(ctx, "Bad mag filter in sample_lambda_cube"); } } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -2123,6 +2364,9 @@ sample_nearest_rect(GLcontext *ctx, GLuint texUnit, (*img->FetchTexel)(img, col, row, 0, (GLvoid *) rgba[i]); } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -2211,6 +2455,9 @@ sample_linear_rect(GLcontext *ctx, GLuint texUnit, rgba[i][3] = (GLchan) (w00 * t00[3] + w10 * t10[3] + w01 * t01[3] + w11 * t11[3]); } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } @@ -2248,6 +2495,9 @@ sample_lambda_rect( GLcontext *ctx, GLuint texUnit, texcoords + magStart, NULL, rgba + magStart); } } + if (ctx->Texture.ColorTableEnabled) { + texture_table_lookup(&ctx->TextureColorTable, n, rgba); + } } |