1 /* $Id: colortab.c,v 1.2 1999/10/08 09:27:10 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 /* $XFree86: xc/lib/GL/mesa/src/colortab.c,v 1.2 1999/04/04 00:20:21 dawes Exp $ */
36 #include "GL/xf86glx.h"
42 #include "GL/xf86glx.h"
49 * Return GL_TRUE if k is a power of two, else return GL_FALSE.
51 static GLboolean
power_of_two( GLint k
)
54 for (i
=0; i
<32; i
++) {
63 static GLint
decode_internal_format( GLint format
)
80 case GL_LUMINANCE_ALPHA
:
81 case GL_LUMINANCE4_ALPHA4
:
82 case GL_LUMINANCE6_ALPHA2
:
83 case GL_LUMINANCE8_ALPHA8
:
84 case GL_LUMINANCE12_ALPHA4
:
85 case GL_LUMINANCE12_ALPHA12
:
86 case GL_LUMINANCE16_ALPHA16
:
87 return GL_LUMINANCE_ALPHA
;
115 return -1; /* error */
120 void gl_ColorTable( GLcontext
*ctx
, GLenum target
,
121 GLenum internalFormat
, struct gl_image
*table
)
123 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
124 struct gl_texture_object
*texObj
;
125 GLboolean proxy
= GL_FALSE
;
127 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glColorTable");
129 if (decode_internal_format(internalFormat
) < 0) {
130 gl_error( ctx
, GL_INVALID_ENUM
, "glColorTable(internalFormat)" );
136 texObj
= texUnit
->CurrentD
[1];
139 texObj
= texUnit
->CurrentD
[2];
141 case GL_TEXTURE_3D_EXT
:
142 texObj
= texUnit
->CurrentD
[3];
144 case GL_PROXY_TEXTURE_1D
:
145 texObj
= ctx
->Texture
.Proxy1D
;
148 case GL_PROXY_TEXTURE_2D
:
149 texObj
= ctx
->Texture
.Proxy2D
;
152 case GL_PROXY_TEXTURE_3D_EXT
:
153 texObj
= ctx
->Texture
.Proxy3D
;
156 case GL_SHARED_TEXTURE_PALETTE_EXT
:
160 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableEXT(target)");
164 /* internalformat = just like glTexImage */
166 if (table
->Width
< 1 || table
->Width
> MAX_TEXTURE_PALETTE_SIZE
167 || !power_of_two(table
->Width
)) {
168 gl_error(ctx
, GL_INVALID_VALUE
, "glColorTableEXT(width)");
170 texObj
->PaletteSize
= 0;
171 texObj
->PaletteIntFormat
= (GLenum
) 0;
172 texObj
->PaletteFormat
= (GLenum
) 0;
178 /* per-texture object palette */
179 texObj
->PaletteSize
= table
->Width
;
180 texObj
->PaletteIntFormat
= internalFormat
;
181 texObj
->PaletteFormat
= (GLenum
) decode_internal_format(internalFormat
);
183 MEMCPY(texObj
->Palette
, table
->Data
, table
->Width
*table
->Components
);
184 if (ctx
->Driver
.UpdateTexturePalette
) {
185 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
190 /* shared texture palette */
191 ctx
->Texture
.PaletteSize
= table
->Width
;
192 ctx
->Texture
.PaletteIntFormat
= internalFormat
;
193 ctx
->Texture
.PaletteFormat
= (GLenum
) decode_internal_format(internalFormat
);
194 MEMCPY(ctx
->Texture
.Palette
, table
->Data
, table
->Width
*table
->Components
);
195 if (ctx
->Driver
.UpdateTexturePalette
) {
196 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, NULL
);
203 void gl_ColorSubTable( GLcontext
*ctx
, GLenum target
,
204 GLsizei start
, struct gl_image
*data
)
207 gl_problem(ctx
, "glColorSubTableEXT not implemented");
215 void gl_GetColorTable( GLcontext
*ctx
, GLenum target
, GLenum format
,
216 GLenum type
, GLvoid
*table
)
218 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetBooleanv");
225 case GL_TEXTURE_3D_EXT
:
227 case GL_SHARED_TEXTURE_PALETTE_EXT
:
230 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableEXT(target)");
234 gl_problem(ctx
, "glGetColorTableEXT not implemented!");
242 void gl_GetColorTableParameterfv( GLcontext
*ctx
, GLenum target
,
243 GLenum pname
, GLfloat
*params
)
247 gl_GetColorTableParameteriv( ctx
, target
, pname
, iparams
);
248 *params
= (GLfloat
) iparams
[0];
253 void gl_GetColorTableParameteriv( GLcontext
*ctx
, GLenum target
,
254 GLenum pname
, GLint
*params
)
256 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
257 struct gl_texture_object
*texObj
;
259 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetColorTableParameter");
263 texObj
= texUnit
->CurrentD
[1];
266 texObj
= texUnit
->CurrentD
[2];
268 case GL_TEXTURE_3D_EXT
:
269 texObj
= texUnit
->CurrentD
[3];
271 case GL_SHARED_TEXTURE_PALETTE_EXT
:
275 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
280 case GL_COLOR_TABLE_FORMAT_EXT
:
282 *params
= texObj
->PaletteIntFormat
;
284 *params
= ctx
->Texture
.PaletteIntFormat
;
286 case GL_COLOR_TABLE_WIDTH_EXT
:
288 *params
= texObj
->PaletteSize
;
290 *params
= ctx
->Texture
.PaletteSize
;
292 case GL_COLOR_TABLE_RED_SIZE_EXT
:
295 case GL_COLOR_TABLE_GREEN_SIZE_EXT
:
298 case GL_COLOR_TABLE_BLUE_SIZE_EXT
:
301 case GL_COLOR_TABLE_ALPHA_SIZE_EXT
:
304 case GL_COLOR_TABLE_LUMINANCE_SIZE_EXT
:
307 case GL_COLOR_TABLE_INTENSITY_SIZE_EXT
:
311 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter" );