summaryrefslogtreecommitdiff
path: root/src/mesa/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/colortab.c234
-rw-r--r--src/mesa/main/colortab.h9
-rw-r--r--src/mesa/main/context.c43
-rw-r--r--src/mesa/main/pixel.c122
-rw-r--r--src/mesa/main/texobj.c13
5 files changed, 288 insertions, 133 deletions
diff --git a/src/mesa/main/colortab.c b/src/mesa/main/colortab.c
index 98c8bde3f9..634b5c2524 100644
--- a/src/mesa/main/colortab.c
+++ b/src/mesa/main/colortab.c
@@ -1,4 +1,4 @@
-/* $Id: colortab.c,v 1.14 2000/04/17 15:13:53 brianp Exp $ */
+/* $Id: colortab.c,v 1.15 2000/04/17 17:57:04 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -33,6 +33,7 @@
#include "context.h"
#include "image.h"
#include "macros.h"
+#include "mem.h"
#include "mmath.h"
#include "span.h"
#include "teximage.h"
@@ -40,6 +41,42 @@
+void
+_mesa_init_colortable( struct gl_color_table *p )
+{
+ p->TableType = GL_UNSIGNED_BYTE;
+ /* allocate a width=1 table by default */
+ p->Table = CALLOC(4 * sizeof(GLubyte));
+ if (p->Table) {
+ GLubyte *t = (GLubyte *) p->Table;
+ t[0] = 255;
+ t[1] = 255;
+ t[2] = 255;
+ t[3] = 255;
+ }
+ p->Size = 1;
+ p->IntFormat = GL_RGBA;
+ p->Format = GL_RGBA;
+ p->RedSize = 8;
+ p->GreenSize = 8;
+ p->BlueSize = 8;
+ p->AlphaSize = 8;
+ p->IntensitySize = 0;
+ p->LuminanceSize = 0;
+}
+
+
+
+void
+_mesa_free_colortable_data( struct gl_color_table *p )
+{
+ if (p->Table) {
+ FREE(p->Table);
+ p->Table = NULL;
+ }
+}
+
+
/*
* Examine table's format and set the component sizes accordingly.
*/
@@ -216,9 +253,9 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
return;
}
- if (width < 1 || width > MAX_COLOR_TABLE_SIZE
+ if (width < 1 || width > ctx->Const.MaxColorTableSize
|| _mesa_bitcount(width) != 1) {
- if (width > MAX_COLOR_TABLE_SIZE)
+ if (width > ctx->Const.MaxColorTableSize)
gl_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)");
else
gl_error(ctx, GL_INVALID_VALUE, "glColorTable(width)");
@@ -237,55 +274,71 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
set_component_sizes(table);
if (!proxy) {
- _mesa_unpack_ubyte_color_span(ctx, width, table->Format,
- table->Table, /* dest */
- format, type, data,
- &ctx->Unpack, GL_TRUE);
-
+ /* free old table, if any */
+ if (table->Table) {
+ FREE(table->Table);
+ }
if (floatTable) {
+ GLubyte tableUB[MAX_COLOR_TABLE_SIZE * 4];
+ GLfloat *tableF;
+ GLuint i;
+
+ _mesa_unpack_ubyte_color_span(ctx, width, table->Format,
+ tableUB, /* dest */
+ format, type, data,
+ &ctx->Unpack, GL_TRUE);
+
+ table->TableType = GL_FLOAT;
+ table->Table = MALLOC(4 * width * sizeof(GLfloat));
+ if (!table->Table) {
+ gl_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
+ return;
+ }
+
/* 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;
+ tableF = (GLfloat *) table->Table;
+
switch (table->Format) {
case GL_INTENSITY:
for (i = 0; i < width; i++) {
- table->TableF[i] = table->Table[i] * rScale + rBias;
+ tableF[i] = tableUB[i] * rScale + rBias;
}
break;
case GL_LUMINANCE:
for (i = 0; i < width; i++) {
- table->TableF[i] = table->Table[i] * rScale + rBias;
+ tableF[i] = tableUB[i] * rScale + rBias;
}
break;
case GL_ALPHA:
for (i = 0; i < width; i++) {
- table->TableF[i] = table->Table[i] * aScale + aBias;
+ tableF[i] = tableUB[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;
+ tableF[i*2+0] = tableUB[i*2+0] * rScale + rBias;
+ tableF[i*2+1] = tableUB[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;
+ tableF[i*3+0] = tableUB[i*3+0] * rScale + rBias;
+ tableF[i*3+1] = tableUB[i*3+1] * gScale + gBias;
+ tableF[i*3+2] = tableUB[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;
+ tableF[i*4+0] = tableUB[i*4+0] * rScale + rBias;
+ tableF[i*4+1] = tableUB[i*4+1] * gScale + gBias;
+ tableF[i*4+2] = tableUB[i*4+2] * bScale + bBias;
+ tableF[i*4+3] = tableUB[i*4+3] * aScale + aBias;
}
break;
default:
@@ -293,7 +346,20 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
return;
}
}
- }
+ else {
+ /* store GLubyte table */
+ table->TableType = GL_UNSIGNED_BYTE;
+ table->Table = MALLOC(4 * width * sizeof(GLubyte));
+ if (!table->Table) {
+ gl_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
+ return;
+ }
+ _mesa_unpack_ubyte_color_span(ctx, width, table->Format,
+ table->Table, /* dest */
+ format, type, data,
+ &ctx->Unpack, GL_TRUE);
+ } /* floatTable */
+ } /* proxy */
if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
/* texture object palette, texObj==NULL means the shared palette */
@@ -370,10 +436,22 @@ _mesa_ColorSubTable( GLenum target, GLsizei start,
return;
}
- dest = table->Table + start * comps * sizeof(GLubyte);
- _mesa_unpack_ubyte_color_span(ctx, count, table->Format, dest,
- format, type, data,
- &ctx->Unpack, GL_TRUE);
+ if (!table->Table) {
+ gl_error(ctx, GL_OUT_OF_MEMORY, "glColorSubTable");
+ return;
+ }
+
+ if (table->TableType == GL_UNSIGNED_BYTE) {
+ dest = (GLubyte *) table->Table + start * comps * sizeof(GLubyte);
+ _mesa_unpack_ubyte_color_span(ctx, count, table->Format, dest,
+ format, type, data,
+ &ctx->Unpack, GL_TRUE);
+ }
+ else {
+ ASSERT(table->TableType == GL_FLOAT);
+ /* XXX todo */
+ }
+
if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
/* per-texture object palette */
@@ -450,7 +528,6 @@ _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");
@@ -470,15 +547,12 @@ _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)");
@@ -489,110 +563,122 @@ _mesa_GetColorTable( GLenum target, GLenum format,
switch (table->Format) {
case GL_ALPHA:
- if (floatTable) {
+ if (table->TableType == GL_FLOAT) {
+ const GLfloat *tableF = (const GLfloat *) table->Table;
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);
+ rgba[i][ACOMP] = (GLint) (tableF[i] * 255.0F);
}
}
else {
+ const GLubyte *tableUB = (const GLubyte *) table->Table;
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];
+ rgba[i][ACOMP] = tableUB[i];
}
}
break;
case GL_LUMINANCE:
- if (floatTable) {
+ if (table->TableType == GL_FLOAT) {
+ const GLfloat *tableF = (const GLfloat *) table->Table;
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][RCOMP] = (GLint) (tableF[i] * 255.0F);
+ rgba[i][GCOMP] = (GLint) (tableF[i] * 255.0F);
+ rgba[i][BCOMP] = (GLint) (tableF[i] * 255.0F);
rgba[i][ACOMP] = 255;
}
}
else {
+ const GLubyte *tableUB = (const GLubyte *) table->Table;
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][RCOMP] = tableUB[i];
+ rgba[i][GCOMP] = tableUB[i];
+ rgba[i][BCOMP] = tableUB[i];
rgba[i][ACOMP] = 255;
}
}
break;
case GL_LUMINANCE_ALPHA:
- if (floatTable) {
+ if (table->TableType == GL_FLOAT) {
+ const GLfloat *tableF = (const GLfloat *) table->Table;
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);
+ rgba[i][RCOMP] = (GLint) (tableF[i*2+0] * 255.0F);
+ rgba[i][GCOMP] = (GLint) (tableF[i*2+0] * 255.0F);
+ rgba[i][BCOMP] = (GLint) (tableF[i*2+0] * 255.0F);
+ rgba[i][ACOMP] = (GLint) (tableF[i*2+1] * 255.0F);
}
}
else {
+ const GLubyte *tableUB = (const GLubyte *) table->Table;
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];
+ rgba[i][RCOMP] = tableUB[i*2+0];
+ rgba[i][GCOMP] = tableUB[i*2+0];
+ rgba[i][BCOMP] = tableUB[i*2+0];
+ rgba[i][ACOMP] = tableUB[i*2+1];
}
}
break;
case GL_INTENSITY:
- if (floatTable) {
+ if (table->TableType == GL_FLOAT) {
+ const GLfloat *tableF = (const GLfloat *) table->Table;
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;
+ rgba[i][RCOMP] = (GLint) (tableF[i] * 255.0F);
+ rgba[i][GCOMP] = (GLint) (tableF[i] * 255.0F);
+ rgba[i][BCOMP] = (GLint) (tableF[i] * 255.0F);
+ rgba[i][ACOMP] = (GLint) (tableF[i] * 255.0F);
}
}
else {
+ const GLubyte *tableUB = (const GLubyte *) table->Table;
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;
+ rgba[i][RCOMP] = tableUB[i];
+ rgba[i][GCOMP] = tableUB[i];
+ rgba[i][BCOMP] = tableUB[i];
+ rgba[i][ACOMP] = tableUB[i];
}
}
break;
case GL_RGB:
- if (floatTable) {
+ if (table->TableType == GL_FLOAT) {
+ const GLfloat *tableF = (const GLfloat *) table->Table;
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][RCOMP] = (GLint) (tableF[i*3+0] * 255.0F);
+ rgba[i][GCOMP] = (GLint) (tableF[i*3+1] * 255.0F);
+ rgba[i][BCOMP] = (GLint) (tableF[i*3+2] * 255.0F);
rgba[i][ACOMP] = 255;
}
}
else {
+ const GLubyte *tableUB = (const GLubyte *) table->Table;
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][RCOMP] = tableUB[i*3+0];
+ rgba[i][GCOMP] = tableUB[i*3+1];
+ rgba[i][BCOMP] = tableUB[i*3+2];
rgba[i][ACOMP] = 255;
}
}
break;
case GL_RGBA:
- if (floatTable) {
+ if (table->TableType == GL_FLOAT) {
+ const GLfloat *tableF = (const GLfloat *) table->Table;
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);
+ rgba[i][RCOMP] = (GLint) (tableF[i*4+0] * 255.0F);
+ rgba[i][GCOMP] = (GLint) (tableF[i*4+1] * 255.0F);
+ rgba[i][BCOMP] = (GLint) (tableF[i*4+2] * 255.0F);
+ rgba[i][ACOMP] = (GLint) (tableF[i*4+3] * 255.0F);
}
}
else {
+ const GLubyte *tableUB = (const GLubyte *) table->Table;
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];
+ rgba[i][RCOMP] = tableUB[i*4+0];
+ rgba[i][GCOMP] = tableUB[i*4+1];
+ rgba[i][BCOMP] = tableUB[i*4+2];
+ rgba[i][ACOMP] = tableUB[i*4+3];
}
}
break;
diff --git a/src/mesa/main/colortab.h b/src/mesa/main/colortab.h
index c707b978f5..9e976e0a26 100644
--- a/src/mesa/main/colortab.h
+++ b/src/mesa/main/colortab.h
@@ -1,4 +1,4 @@
-/* $Id: colortab.h,v 1.6 2000/04/12 00:27:37 brianp Exp $ */
+/* $Id: colortab.h,v 1.7 2000/04/17 17:57:04 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -33,6 +33,13 @@
extern void
+_mesa_init_colortable( struct gl_color_table *p );
+
+extern void
+_mesa_free_colortable_data( struct gl_color_table *p );
+
+
+extern void
_mesa_ColorTable( GLenum target, GLenum internalformat,
GLsizei width, GLenum format, GLenum type,
const GLvoid *table );
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 9ff18aca60..2e14e79aa6 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1,4 +1,4 @@
-/* $Id: context.c,v 1.59 2000/04/12 00:27:37 brianp Exp $ */
+/* $Id: context.c,v 1.60 2000/04/17 17:57:04 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -32,6 +32,7 @@
#include "accum.h"
#include "alphabuf.h"
#include "clip.h"
+#include "colortab.h"
#include "context.h"
#include "cva.h"
#include "depth.h"
@@ -778,24 +779,6 @@ static void init_2d_map( struct gl_2d_map *map, int n, const float *initial )
}
-static void init_color_table( struct gl_color_table *p )
-{
- p->Table[0] = 255;
- p->Table[1] = 255;
- p->Table[2] = 255;
- p->Table[3] = 255;
- p->Size = 1;
- p->IntFormat = GL_RGBA;
- p->Format = GL_RGBA;
- p->RedSize = 8;
- p->GreenSize = 8;
- p->BlueSize = 8;
- p->AlphaSize = 8;
- p->IntensitySize = 0;
- p->LuminanceSize = 0;
-}
-
-
/*
* Initialize the attribute groups in a GLcontext.
*/
@@ -822,6 +805,7 @@ static void init_attrib_groups( GLcontext *ctx )
ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
+ ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
/* Modelview matrix */
gl_matrix_ctr( &ctx->ModelView );
@@ -1207,7 +1191,7 @@ static void init_attrib_groups( GLcontext *ctx )
ctx->Texture.Enabled = 0;
for (i=0; i<MAX_TEXTURE_UNITS; i++)
init_texture_unit( ctx, i );
- init_color_table(&ctx->Texture.Palette);
+ _mesa_init_colortable(&ctx->Texture.Palette);
/* Transformation group */
ctx->Transform.MatrixMode = GL_MODELVIEW;
@@ -1325,12 +1309,12 @@ static void init_attrib_groups( GLcontext *ctx )
ctx->CurrentPos = 0;
/* Color tables */
- init_color_table(&ctx->ColorTable);
- init_color_table(&ctx->ProxyColorTable);
- init_color_table(&ctx->PostConvolutionColorTable);
- init_color_table(&ctx->ProxyPostConvolutionColorTable);
- init_color_table(&ctx->PostColorMatrixColorTable);
- init_color_table(&ctx->ProxyPostColorMatrixColorTable);
+ _mesa_init_colortable(&ctx->ColorTable);
+ _mesa_init_colortable(&ctx->ProxyColorTable);
+ _mesa_init_colortable(&ctx->PostConvolutionColorTable);
+ _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
+ _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
+ _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
/* Miscellaneous */
ctx->NewState = NEW_ALL;
@@ -1598,7 +1582,7 @@ void gl_free_context_data( GLcontext *ctx )
FREE( ctx->PB );
- if(ctx->input != ctx->VB->IM)
+ if (ctx->input != ctx->VB->IM)
gl_immediate_free( ctx->input );
gl_vb_free( ctx->VB );
@@ -1661,6 +1645,11 @@ void gl_free_context_data( GLcontext *ctx )
if (ctx->EvalMap.Map2Texture4.Points)
FREE( ctx->EvalMap.Map2Texture4.Points );
+ _mesa_free_colortable_data( &ctx->ColorTable );
+ _mesa_free_colortable_data( &ctx->PostConvolutionColorTable );
+ _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable );
+ _mesa_free_colortable_data( &ctx->Texture.Palette );
+
/* Free cache of immediate buffers. */
while (ctx->nr_im_queued-- > 0) {
struct immediate * next = ctx->freed_im_queue->next;
diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c
index 0735331218..ec64446214 100644
--- a/src/mesa/main/pixel.c
+++ b/src/mesa/main/pixel.c
@@ -1,4 +1,4 @@
-/* $Id: pixel.c,v 1.8 2000/04/17 15:13:53 brianp Exp $ */
+/* $Id: pixel.c,v 1.9 2000/04/17 17:57:04 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -726,40 +726,75 @@ void
_mesa_lookup_rgba(const struct gl_color_table *table,
GLuint n, GLfloat rgba[][4])
{
+ ASSERT(table->TableType == GL_FLOAT);
+ if (!table->Table)
+ return;
+
switch (table->Format) {
case GL_INTENSITY:
- {
+ /* replace RGBA with I */
+ if (table->TableType == GL_UNSIGNED_BYTE) {
const GLfloat scale = (GLfloat) (table->Size - 1);
- const GLfloat *lut = table->TableF;
+ const GLubyte *lut = (const GLubyte *) table->Table;
GLuint i;
- /* replace RGBA with I */
for (i = 0; i < n; i++) {
GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
- GLubyte c = lut[j];
+ GLfloat c = lut[j] * (1.0F / 255.0F);
+ rgba[i][RCOMP] = rgba[i][GCOMP] =
+ rgba[i][BCOMP] = rgba[i][ACOMP] = c;
+ }
+
+ }
+ else {
+ const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLfloat *lut = (const GLfloat *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
+ GLfloat 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->TableType == GL_UNSIGNED_BYTE) {
const GLfloat scale = (GLfloat) (table->Size - 1);
- const GLfloat *lut = table->TableF;
+ const GLubyte *lut = (const GLubyte *) table->Table;
GLuint i;
- /* replace RGB with L */
for (i = 0; i < n; i++) {
GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
- GLubyte c = lut[j];
+ GLfloat c = lut[j] * (1.0F / 255.0F);
+ rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c;
+ }
+ }
+ else {
+ const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLfloat *lut = (const GLfloat *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
+ GLfloat c = lut[j];
rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c;
}
}
break;
case GL_ALPHA:
- {
+ /* replace A with A */
+ if (table->TableType == GL_UNSIGNED_BYTE) {
+ const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLubyte *lut = (const GLubyte *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint j = (GLint) (rgba[i][ACOMP] * scale + 0.5F);
+ rgba[i][ACOMP] = lut[j] * (1.0F / 255.0F);
+ }
+ }
+ else {
const GLfloat scale = (GLfloat) (table->Size - 1);
- const GLfloat *lut = table->TableF;
+ const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
- /* replace A with A */
for (i = 0; i < n; i++) {
GLint j = (GLint) (rgba[i][ACOMP] * scale + 0.5F);
rgba[i][ACOMP] = lut[j];
@@ -767,27 +802,53 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
}
break;
case GL_LUMINANCE_ALPHA:
- {
+ /* replace RGBA with LLLA */
+ if (table->TableType == GL_UNSIGNED_BYTE) {
+ const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLubyte *lut = (const GLubyte *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint jL = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
+ GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F);
+ GLfloat luminance = lut[jL * 2 + 0] * (1.0F / 255.0F);
+ GLfloat alpha = lut[jA * 2 + 1] * (1.0F / 255.0F);
+ rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance;
+ rgba[i][ACOMP] = alpha;;
+ }
+ }
+ else {
const GLfloat scale = (GLfloat) (table->Size - 1);
- const GLfloat *lut = table->TableF;
+ const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
- /* replace RGBA with LLLA */
for (i = 0; i < n; i++) {
GLint jL = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F);
- GLubyte luminance = lut[jL * 2 + 0];
- GLubyte alpha = lut[jA * 2 + 1];
+ GLfloat luminance = lut[jL * 2 + 0];
+ GLfloat 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->TableType == GL_UNSIGNED_BYTE) {
const GLfloat scale = (GLfloat) (table->Size - 1);
- const GLfloat *lut = table->TableF;
+ const GLubyte *lut = (const GLubyte *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
+ GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F);
+ GLint jB = (GLint) (rgba[i][BCOMP] * scale + 0.5F);
+ rgba[i][RCOMP] = lut[jR * 3 + 0] * (1.0F / 255.0F);
+ rgba[i][GCOMP] = lut[jG * 3 + 1] * (1.0F / 255.0F);
+ rgba[i][BCOMP] = lut[jB * 3 + 2] * (1.0F / 255.0F);
+ }
+ }
+ else {
+ const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
- /* replace RGB with RGB */
for (i = 0; i < n; i++) {
GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F);
@@ -799,11 +860,26 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
}
break;
case GL_RGBA:
- {
+ /* replace RGBA with RGBA */
+ if (table->TableType == GL_UNSIGNED_BYTE) {
+ const GLfloat scale = (GLfloat) (table->Size - 1);
+ const GLubyte *lut = (const GLubyte *) table->Table;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
+ GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F);
+ GLint jB = (GLint) (rgba[i][BCOMP] * scale + 0.5F);
+ GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F);
+ rgba[i][RCOMP] = lut[jR * 4 + 0] * (1.0F / 255.0F);
+ rgba[i][GCOMP] = lut[jG * 4 + 1] * (1.0F / 255.0F);
+ rgba[i][BCOMP] = lut[jB * 4 + 2] * (1.0F / 255.0F);
+ rgba[i][ACOMP] = lut[jA * 4 + 3] * (1.0F / 255.0F);
+ }
+ }
+ else {
const GLfloat scale = (GLfloat) (table->Size - 1);
- const GLfloat *lut = table->TableF;
+ const GLfloat *lut = (const GLfloat *) table->Table;
GLuint i;
- /* replace RGBA with RGBA */
for (i = 0; i < n; i++) {
GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F);
GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F);
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index bafac922aa..330943b579 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -28,6 +28,7 @@
#include "all.h"
#else
#include "glheader.h"
+#include "colortab.h"
#include "context.h"
#include "enums.h"
#include "hash.h"
@@ -73,13 +74,7 @@ gl_alloc_texture_object( struct gl_shared_state *shared, GLuint name,
obj->BaseLevel = 0;
obj->MaxLevel = 1000;
obj->MinMagThresh = 0.0F;
- obj->Palette.Table[0] = 255;
- obj->Palette.Table[1] = 255;
- obj->Palette.Table[2] = 255;
- obj->Palette.Table[3] = 255;
- obj->Palette.Size = 1;
- obj->Palette.IntFormat = GL_RGBA;
- obj->Palette.Format = GL_RGBA;
+ _mesa_init_colortable(&obj->Palette);
/* insert into linked list */
if (shared) {
@@ -143,7 +138,9 @@ void gl_free_texture_object( struct gl_shared_state *shared,
_mesa_HashRemove(shared->TexObjects, t->Name);
}
- /* free texture image */
+ _mesa_free_colortable_data(&t->Palette);
+
+ /* free texture images */
{
GLuint i;
for (i=0;i<MAX_TEXTURE_LEVELS;i++) {