work on GL_SGI_color_table

This commit is contained in:
Brian Paul 2000-04-17 15:13:53 +00:00
parent 0c12733fb7
commit a5f4cae20a
4 changed files with 187 additions and 53 deletions

View File

@ -1,4 +1,4 @@
/* $Id: colortab.c,v 1.13 2000/04/12 00:27:37 brianp Exp $ */
/* $Id: colortab.c,v 1.14 2000/04/17 15:13:53 brianp Exp $ */
/*
* Mesa 3-D graphics library
@ -115,6 +115,7 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
GLint baseFormat;
GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0;
GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0;
GLboolean floatTable = GL_FALSE;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glColorTable");
@ -151,6 +152,7 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
break;
case GL_COLOR_TABLE:
table = &ctx->ColorTable;
floatTable = GL_TRUE;
rScale = ctx->Pixel.ColorTableScale[0];
gScale = ctx->Pixel.ColorTableScale[1];
bScale = ctx->Pixel.ColorTableScale[2];
@ -166,6 +168,7 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
break;
case GL_POST_CONVOLUTION_COLOR_TABLE:
table = &ctx->PostConvolutionColorTable;
floatTable = GL_TRUE;
rScale = ctx->Pixel.PCCTscale[0];
gScale = ctx->Pixel.PCCTscale[1];
bScale = ctx->Pixel.PCCTscale[2];
@ -181,6 +184,7 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
break;
case GL_POST_COLOR_MATRIX_COLOR_TABLE:
table = &ctx->PostColorMatrixColorTable;
floatTable = GL_TRUE;
rScale = ctx->Pixel.PCMCTscale[0];
gScale = ctx->Pixel.PCMCTscale[1];
bScale = ctx->Pixel.PCMCTscale[2];
@ -237,10 +241,57 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
table->Table, /* dest */
format, type, data,
&ctx->Unpack, GL_TRUE);
if (rScale != 1.0 || gScale != 1.0 || bScale != 1.0 || aScale != 1.0 ||
rBias != 0.0 || gBias != 0.0 || bBias != 0.0 || aBias != 0.0) {
/* XXX apply scale and bias */
if (floatTable) {
/* Apply scale and bias and convert GLubyte values to GLfloats
* in [0, 1]. Store results in the tableF[].
*/
GLuint i;
rScale /= 255.0;
gScale /= 255.0;
bScale /= 255.0;
aScale /= 255.0;
switch (table->Format) {
case GL_INTENSITY:
for (i = 0; i < width; i++) {
table->TableF[i] = table->Table[i] * rScale + rBias;
}
break;
case GL_LUMINANCE:
for (i = 0; i < width; i++) {
table->TableF[i] = table->Table[i] * rScale + rBias;
}
break;
case GL_ALPHA:
for (i = 0; i < width; i++) {
table->TableF[i] = table->Table[i] * aScale + aBias;
}
break;
case GL_LUMINANCE_ALPHA:
for (i = 0; i < width; i++) {
table->TableF[i*2+0] = table->Table[i*2+0] * rScale + rBias;
table->TableF[i*2+1] = table->Table[i*2+1] * aScale + aBias;
}
break;
case GL_RGB:
for (i = 0; i < width; i++) {
table->TableF[i*3+0] = table->Table[i*3+0] * rScale + rBias;
table->TableF[i*3+1] = table->Table[i*3+1] * gScale + gBias;
table->TableF[i*3+2] = table->Table[i*3+2] * bScale + bBias;
}
break;
case GL_RGBA:
for (i = 0; i < width; i++) {
table->TableF[i*4+0] = table->Table[i*4+0] * rScale + rBias;
table->TableF[i*4+1] = table->Table[i*4+1] * gScale + gBias;
table->TableF[i*4+2] = table->Table[i*4+2] * bScale + bBias;
table->TableF[i*4+3] = table->Table[i*4+3] * aScale + aBias;
}
break;
default:
gl_problem(ctx, "Bad format in _mesa_ColorTable");
return;
}
}
}
@ -399,6 +450,7 @@ _mesa_GetColorTable( GLenum target, GLenum format,
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
struct gl_color_table *table = NULL;
GLubyte rgba[MAX_COLOR_TABLE_SIZE][4];
GLboolean floatTable = GL_FALSE;
GLint i;
ASSERT_OUTSIDE_BEGIN_END(ctx, "glGetColorTable");
@ -418,12 +470,15 @@ _mesa_GetColorTable( GLenum target, GLenum format,
break;
case GL_COLOR_TABLE:
table = &ctx->ColorTable;
floatTable = GL_TRUE;
break;
case GL_POST_CONVOLUTION_COLOR_TABLE:
table = &ctx->PostConvolutionColorTable;
floatTable = GL_TRUE;
break;
case GL_POST_COLOR_MATRIX_COLOR_TABLE:
table = &ctx->PostColorMatrixColorTable;
floatTable = GL_TRUE;
break;
default:
gl_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
@ -434,51 +489,111 @@ _mesa_GetColorTable( GLenum target, GLenum format,
switch (table->Format) {
case GL_ALPHA:
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = 0;
rgba[i][GCOMP] = 0;
rgba[i][BCOMP] = 0;
rgba[i][ACOMP] = table->Table[i];
if (floatTable) {
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = 0;
rgba[i][GCOMP] = 0;
rgba[i][BCOMP] = 0;
rgba[i][ACOMP] = (GLint) (table->TableF[i] * 255.0F);
}
}
else {
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = 0;
rgba[i][GCOMP] = 0;
rgba[i][BCOMP] = 0;
rgba[i][ACOMP] = table->Table[i];
}
}
break;
case GL_LUMINANCE:
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = table->Table[i];
rgba[i][GCOMP] = table->Table[i];
rgba[i][BCOMP] = table->Table[i];
rgba[i][ACOMP] = 255;
if (floatTable) {
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = (GLint) (table->Table[i] * 255.0F);
rgba[i][GCOMP] = (GLint) (table->Table[i] * 255.0F);
rgba[i][BCOMP] = (GLint) (table->Table[i] * 255.0F);
rgba[i][ACOMP] = 255;
}
}
else {
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = table->Table[i];
rgba[i][GCOMP] = table->Table[i];
rgba[i][BCOMP] = table->Table[i];
rgba[i][ACOMP] = 255;
}
}
break;
case GL_LUMINANCE_ALPHA:
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = table->Table[i*2+0];
rgba[i][GCOMP] = table->Table[i*2+0];
rgba[i][BCOMP] = table->Table[i*2+0];
rgba[i][ACOMP] = table->Table[i*2+1];
if (floatTable) {
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = (GLint) (table->Table[i*2+0] * 255.0F);
rgba[i][GCOMP] = (GLint) (table->Table[i*2+0] * 255.0F);
rgba[i][BCOMP] = (GLint) (table->Table[i*2+0] * 255.0F);
rgba[i][ACOMP] = (GLint) (table->Table[i*2+1] * 255.0F);
}
}
else {
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = table->Table[i*2+0];
rgba[i][GCOMP] = table->Table[i*2+0];
rgba[i][BCOMP] = table->Table[i*2+0];
rgba[i][ACOMP] = table->Table[i*2+1];
}
}
break;
case GL_INTENSITY:
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = table->Table[i];
rgba[i][GCOMP] = table->Table[i];
rgba[i][BCOMP] = table->Table[i];
rgba[i][ACOMP] = 255;
if (floatTable) {
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = (GLint) (table->Table[i] * 255.0F);
rgba[i][GCOMP] = (GLint) (table->Table[i] * 255.0F);
rgba[i][BCOMP] = (GLint) (table->Table[i] * 255.0F);
rgba[i][ACOMP] = 255;
}
}
else {
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = table->Table[i];
rgba[i][GCOMP] = table->Table[i];
rgba[i][BCOMP] = table->Table[i];
rgba[i][ACOMP] = 255;
}
}
break;
case GL_RGB:
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = table->Table[i*3+0];
rgba[i][GCOMP] = table->Table[i*3+1];
rgba[i][BCOMP] = table->Table[i*3+2];
rgba[i][ACOMP] = 255;
if (floatTable) {
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = (GLint) (table->Table[i*3+0] * 255.0F);
rgba[i][GCOMP] = (GLint) (table->Table[i*3+1] * 255.0F);
rgba[i][BCOMP] = (GLint) (table->Table[i*3+2] * 255.0F);
rgba[i][ACOMP] = 255;
}
}
else {
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = table->Table[i*3+0];
rgba[i][GCOMP] = table->Table[i*3+1];
rgba[i][BCOMP] = table->Table[i*3+2];
rgba[i][ACOMP] = 255;
}
}
break;
case GL_RGBA:
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = table->Table[i*4+0];
rgba[i][GCOMP] = table->Table[i*4+1];
rgba[i][BCOMP] = table->Table[i*4+2];
rgba[i][ACOMP] = table->Table[i*4+3];
if (floatTable) {
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = (GLint) (table->Table[i*4+0] * 255.0F);
rgba[i][GCOMP] = (GLint) (table->Table[i*4+1] * 255.0F);
rgba[i][BCOMP] = (GLint) (table->Table[i*4+2] * 255.0F);
rgba[i][ACOMP] = (GLint) (table->Table[i*4+3] * 255.0F);
}
}
else {
for (i = 0; i < table->Size; i++) {
rgba[i][RCOMP] = table->Table[i*4+0];
rgba[i][GCOMP] = table->Table[i*4+1];
rgba[i][BCOMP] = table->Table[i*4+2];
rgba[i][ACOMP] = table->Table[i*4+3];
}
}
break;
default:

View File

@ -1,4 +1,4 @@
/* $Id: extensions.c,v 1.23 2000/04/08 18:57:45 brianp Exp $ */
/* $Id: extensions.c,v 1.24 2000/04/17 15:13:53 brianp Exp $ */
/*
* Mesa 3-D graphics library
@ -79,6 +79,7 @@ static struct { int enabled; const char *name; } default_extensions[] = {
{ ALWAYS_ENABLED, "GL_NV_texgen_reflection" },
{ DEFAULT_ON, "GL_PGI_misc_hints" },
{ DEFAULT_ON, "GL_SGI_color_matrix" },
{ DEFAULT_ON, "GL_SGI_color_table" },
{ DEFAULT_ON, "GL_SGIS_pixel_texture" },
{ DEFAULT_ON, "GL_SGIS_texture_edge_clamp" },
{ DEFAULT_ON, "GL_SGIX_pixel_texture" }

View File

@ -1,4 +1,4 @@
/* $Id: image.c,v 1.27 2000/04/15 23:05:39 brianp Exp $ */
/* $Id: image.c,v 1.28 2000/04/17 15:13:53 brianp Exp $ */
/*
* Mesa 3-D graphics library
@ -612,7 +612,8 @@ _mesa_pack_rgba_span( const GLcontext *ctx,
ctx->Pixel.MapColorFlag ||
ctx->ColorMatrix.type != MATRIX_IDENTITY ||
ctx->Pixel.ScaleOrBiasRGBApcm ||
ctx->Pixel.ColorTableEnabled);
ctx->Pixel.ColorTableEnabled ||
ctx->Pixel.PostColorMatrixColorTableEnabled);
/* Test for optimized case first */
if (!applyTransferOps && format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
@ -658,19 +659,27 @@ _mesa_pack_rgba_span( const GLcontext *ctx,
if (ctx->Pixel.ScaleOrBiasRGBA) {
_mesa_scale_and_bias_rgba( ctx, n, rgba );
}
/* color table lookup */
/* color map lookup */
if (ctx->Pixel.MapColorFlag) {
_mesa_map_rgba( ctx, n, rgba );
}
/* GL_COLOR_TABLE lookup */
if (ctx->Pixel.ColorTableEnabled) {
_mesa_lookup_rgba(&ctx->ColorTable, n, rgba);
}
/* XXX convolution here */
/* XXX post-convolution color table look-up here */
/* color matrix */
if (ctx->ColorMatrix.type != MATRIX_IDENTITY ||
ctx->Pixel.ScaleOrBiasRGBApcm) {
_mesa_transform_rgba(ctx, n, rgba);
}
/* GL_SGI_color_table lookup */
if (ctx->Pixel.ColorTableEnabled) {
_mesa_lookup_rgba(&ctx->ColorTable, n, rgba);
/* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
if (ctx->Pixel.PostColorMatrixColorTableEnabled) {
_mesa_lookup_rgba(&ctx->PostColorMatrixColorTable, n, rgba);
}
/* XXX histogram here */
/* XXX min/max here */
}
if (format==GL_LUMINANCE || format==GL_LUMINANCE_ALPHA) {
@ -2176,7 +2185,8 @@ _mesa_unpack_ubyte_color_span( const GLcontext *ctx,
ctx->Pixel.MapColorFlag ||
ctx->ColorMatrix.type != MATRIX_IDENTITY ||
ctx->Pixel.ScaleOrBiasRGBApcm ||
ctx->Pixel.ColorTableEnabled);
ctx->Pixel.ColorTableEnabled ||
ctx->Pixel.PostColorMatrixColorTableEnabled);
/* Try simple cases first */
if (!applyTransferOps && srcType == GL_UNSIGNED_BYTE) {
@ -2281,19 +2291,27 @@ _mesa_unpack_ubyte_color_span( const GLcontext *ctx,
if (applyTransferOps) {
/* scale and bias colors */
_mesa_scale_and_bias_rgba(ctx, n, rgba);
/* color table lookup */
/* color map lookup */
if (ctx->Pixel.MapColorFlag) {
_mesa_map_rgba(ctx, n, rgba);
}
/* GL_COLOR_TABLE lookup */
if (ctx->Pixel.ColorTableEnabled) {
_mesa_lookup_rgba(&ctx->ColorTable, n, rgba);
}
/* XXX convolution here */
/* XXX post-convolution color table look-up here */
/* color matrix transform */
if (ctx->ColorMatrix.type != MATRIX_IDENTITY ||
ctx->Pixel.ScaleOrBiasRGBApcm) {
_mesa_transform_rgba(ctx, n, rgba);
}
/* GL_SGI_color_table lookup */
if (ctx->Pixel.ColorTableEnabled) {
_mesa_lookup_rgba(&ctx->ColorTable, n, rgba);
/* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
if (ctx->Pixel.PostColorMatrixColorTableEnabled) {
_mesa_lookup_rgba(&ctx->PostColorMatrixColorTable, n, rgba);
}
/* XXX histogram here */
/* XXX min/max here */
}
}

View File

@ -1,4 +1,4 @@
/* $Id: pixel.c,v 1.7 2000/04/12 18:54:48 brianp Exp $ */
/* $Id: pixel.c,v 1.8 2000/04/17 15:13:53 brianp Exp $ */
/*
* Mesa 3-D graphics library
@ -730,7 +730,7 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
case GL_INTENSITY:
{
const GLfloat scale = (GLfloat) (table->Size - 1);
const GLubyte *lut = table->Table;
const GLfloat *lut = table->TableF;
GLuint i;
/* replace RGBA with I */
for (i = 0; i < n; i++) {
@ -744,7 +744,7 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
case GL_LUMINANCE:
{
const GLfloat scale = (GLfloat) (table->Size - 1);
const GLubyte *lut = table->Table;
const GLfloat *lut = table->TableF;
GLuint i;
/* replace RGB with L */
for (i = 0; i < n; i++) {
@ -757,7 +757,7 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
case GL_ALPHA:
{
const GLfloat scale = (GLfloat) (table->Size - 1);
const GLubyte *lut = table->Table;
const GLfloat *lut = table->TableF;
GLuint i;
/* replace A with A */
for (i = 0; i < n; i++) {
@ -769,7 +769,7 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
case GL_LUMINANCE_ALPHA:
{
const GLfloat scale = (GLfloat) (table->Size - 1);
const GLubyte *lut = table->Table;
const GLfloat *lut = table->TableF;
GLuint i;
/* replace RGBA with LLLA */
for (i = 0; i < n; i++) {
@ -785,7 +785,7 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
case GL_RGB:
{
const GLfloat scale = (GLfloat) (table->Size - 1);
const GLubyte *lut = table->Table;
const GLfloat *lut = table->TableF;
GLuint i;
/* replace RGB with RGB */
for (i = 0; i < n; i++) {
@ -801,7 +801,7 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
case GL_RGBA:
{
const GLfloat scale = (GLfloat) (table->Size - 1);
const GLubyte *lut = table->Table;
const GLfloat *lut = table->TableF;
GLuint i;
/* replace RGBA with RGBA */
for (i = 0; i < n; i++) {