-/* $Id: colortab.c,v 1.15 2000/04/17 17:57:04 brianp Exp $ */
+/* $Id: colortab.c,v 1.18 2000/05/24 14:03:04 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "mem.h"
#include "mmath.h"
#include "span.h"
-#include "teximage.h"
#endif
+/*
+ * Given an internalFormat token passed to glColorTable,
+ * return the corresponding base format.
+ * Return -1 if invalid token.
+ */
+static GLint
+base_colortab_format( GLenum format )
+{
+ switch (format) {
+ case GL_ALPHA:
+ case GL_ALPHA4:
+ case GL_ALPHA8:
+ case GL_ALPHA12:
+ case GL_ALPHA16:
+ return GL_ALPHA;
+ case GL_LUMINANCE:
+ case GL_LUMINANCE4:
+ case GL_LUMINANCE8:
+ case GL_LUMINANCE12:
+ case GL_LUMINANCE16:
+ return GL_LUMINANCE;
+ case GL_LUMINANCE_ALPHA:
+ case GL_LUMINANCE4_ALPHA4:
+ case GL_LUMINANCE6_ALPHA2:
+ case GL_LUMINANCE8_ALPHA8:
+ case GL_LUMINANCE12_ALPHA4:
+ case GL_LUMINANCE12_ALPHA12:
+ case GL_LUMINANCE16_ALPHA16:
+ return GL_LUMINANCE_ALPHA;
+ case GL_INTENSITY:
+ case GL_INTENSITY4:
+ case GL_INTENSITY8:
+ case GL_INTENSITY12:
+ case GL_INTENSITY16:
+ return GL_INTENSITY;
+ case GL_RGB:
+ case GL_R3_G3_B2:
+ case GL_RGB4:
+ case GL_RGB5:
+ case GL_RGB8:
+ case GL_RGB10:
+ case GL_RGB12:
+ case GL_RGB16:
+ return GL_RGB;
+ case GL_RGBA:
+ case GL_RGBA2:
+ case GL_RGBA4:
+ case GL_RGB5_A1:
+ case GL_RGBA8:
+ case GL_RGB10_A2:
+ case GL_RGBA12:
+ case GL_RGBA16:
+ return GL_RGBA;
+ default:
+ return -1; /* error */
+ }
+}
+
+
void
_mesa_init_colortable( struct gl_color_table *p )
{
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;
+ GLint comps;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glColorTable");
return;
}
- baseFormat = _mesa_base_tex_format(internalFormat);
+ baseFormat = base_colortab_format(internalFormat);
if (baseFormat < 0 || baseFormat == GL_COLOR_INDEX) {
gl_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)");
return;
return;
}
-
table->Size = width;
table->IntFormat = internalFormat;
table->Format = (GLenum) baseFormat;
set_component_sizes(table);
+ comps = _mesa_components_in_format(table->Format);
+ assert(comps > 0); /* error should have been caught sooner */
+
if (!proxy) {
/* free old table, if any */
if (table->Table) {
&ctx->Unpack, GL_TRUE);
table->TableType = GL_FLOAT;
- table->Table = MALLOC(4 * width * sizeof(GLfloat));
+ table->Table = MALLOC(comps * width * sizeof(GLfloat));
if (!table->Table) {
gl_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
return;
else {
/* store GLubyte table */
table->TableType = GL_UNSIGNED_BYTE;
- table->Table = MALLOC(4 * width * sizeof(GLubyte));
+ table->Table = MALLOC(comps * width * sizeof(GLubyte));
if (!table->Table) {
gl_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
return;
(*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
}
}
-
}
struct gl_texture_object *texObj = NULL;
struct gl_color_table *table = NULL;
GLint comps;
- GLubyte *dest;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glColorSubTable");
}
if (table->TableType == GL_UNSIGNED_BYTE) {
- dest = (GLubyte *) table->Table + start * comps * sizeof(GLubyte);
+ GLubyte *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);
+ format, type, data, &ctx->Unpack, GL_TRUE);
}
else {
+ GLfloat *dest = (GLfloat *) table->Table + start * comps * sizeof(GLfloat);
ASSERT(table->TableType == GL_FLOAT);
- /* XXX todo */
+ _mesa_unpack_float_color_span(ctx, count, table->Format, dest,
+ format, type, data, &ctx->Unpack,
+ GL_FALSE, GL_TRUE);
}
-
if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
/* per-texture object palette */
if (ctx->Driver.UpdateTexturePalette) {