1 /* $Id: colortab.c,v 1.3 1999/11/08 07:36:43 brianp 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"
46 * Return GL_TRUE if k is a power of two, else return GL_FALSE.
48 static GLboolean
power_of_two( GLint k
)
51 for (i
=0; i
<32; i
++) {
60 static GLint
decode_internal_format( GLint format
)
77 case GL_LUMINANCE_ALPHA
:
78 case GL_LUMINANCE4_ALPHA4
:
79 case GL_LUMINANCE6_ALPHA2
:
80 case GL_LUMINANCE8_ALPHA8
:
81 case GL_LUMINANCE12_ALPHA4
:
82 case GL_LUMINANCE12_ALPHA12
:
83 case GL_LUMINANCE16_ALPHA16
:
84 return GL_LUMINANCE_ALPHA
;
112 return -1; /* error */
117 void gl_ColorTable( GLcontext
*ctx
, GLenum target
,
118 GLenum internalFormat
, struct gl_image
*table
)
120 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
121 struct gl_texture_object
*texObj
;
122 GLboolean proxy
= GL_FALSE
;
124 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glColorTable");
126 if (decode_internal_format(internalFormat
) < 0) {
127 gl_error( ctx
, GL_INVALID_ENUM
, "glColorTable(internalFormat)" );
133 texObj
= texUnit
->CurrentD
[1];
136 texObj
= texUnit
->CurrentD
[2];
138 case GL_TEXTURE_3D_EXT
:
139 texObj
= texUnit
->CurrentD
[3];
141 case GL_PROXY_TEXTURE_1D
:
142 texObj
= ctx
->Texture
.Proxy1D
;
145 case GL_PROXY_TEXTURE_2D
:
146 texObj
= ctx
->Texture
.Proxy2D
;
149 case GL_PROXY_TEXTURE_3D_EXT
:
150 texObj
= ctx
->Texture
.Proxy3D
;
153 case GL_SHARED_TEXTURE_PALETTE_EXT
:
157 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableEXT(target)");
161 /* internalformat = just like glTexImage */
163 if (table
->Width
< 1 || table
->Width
> MAX_TEXTURE_PALETTE_SIZE
164 || !power_of_two(table
->Width
)) {
165 gl_error(ctx
, GL_INVALID_VALUE
, "glColorTableEXT(width)");
167 texObj
->PaletteSize
= 0;
168 texObj
->PaletteIntFormat
= (GLenum
) 0;
169 texObj
->PaletteFormat
= (GLenum
) 0;
175 /* per-texture object palette */
176 texObj
->PaletteSize
= table
->Width
;
177 texObj
->PaletteIntFormat
= internalFormat
;
178 texObj
->PaletteFormat
= (GLenum
) decode_internal_format(internalFormat
);
180 MEMCPY(texObj
->Palette
, table
->Data
, table
->Width
*table
->Components
);
181 if (ctx
->Driver
.UpdateTexturePalette
) {
182 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
187 /* shared texture palette */
188 ctx
->Texture
.PaletteSize
= table
->Width
;
189 ctx
->Texture
.PaletteIntFormat
= internalFormat
;
190 ctx
->Texture
.PaletteFormat
= (GLenum
) decode_internal_format(internalFormat
);
191 MEMCPY(ctx
->Texture
.Palette
, table
->Data
, table
->Width
*table
->Components
);
192 if (ctx
->Driver
.UpdateTexturePalette
) {
193 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, NULL
);
200 void gl_ColorSubTable( GLcontext
*ctx
, GLenum target
,
201 GLsizei start
, struct gl_image
*data
)
204 gl_problem(ctx
, "glColorSubTableEXT not implemented");
212 void gl_GetColorTable( GLcontext
*ctx
, GLenum target
, GLenum format
,
213 GLenum type
, GLvoid
*table
)
215 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetBooleanv");
222 case GL_TEXTURE_3D_EXT
:
224 case GL_SHARED_TEXTURE_PALETTE_EXT
:
227 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableEXT(target)");
231 gl_problem(ctx
, "glGetColorTableEXT not implemented!");
239 void gl_GetColorTableParameterfv( GLcontext
*ctx
, GLenum target
,
240 GLenum pname
, GLfloat
*params
)
244 gl_GetColorTableParameteriv( ctx
, target
, pname
, iparams
);
245 *params
= (GLfloat
) iparams
[0];
250 void gl_GetColorTableParameteriv( GLcontext
*ctx
, GLenum target
,
251 GLenum pname
, GLint
*params
)
253 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
254 struct gl_texture_object
*texObj
;
256 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetColorTableParameter");
260 texObj
= texUnit
->CurrentD
[1];
263 texObj
= texUnit
->CurrentD
[2];
265 case GL_TEXTURE_3D_EXT
:
266 texObj
= texUnit
->CurrentD
[3];
268 case GL_SHARED_TEXTURE_PALETTE_EXT
:
272 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
277 case GL_COLOR_TABLE_FORMAT_EXT
:
279 *params
= texObj
->PaletteIntFormat
;
281 *params
= ctx
->Texture
.PaletteIntFormat
;
283 case GL_COLOR_TABLE_WIDTH_EXT
:
285 *params
= texObj
->PaletteSize
;
287 *params
= ctx
->Texture
.PaletteSize
;
289 case GL_COLOR_TABLE_RED_SIZE_EXT
:
292 case GL_COLOR_TABLE_GREEN_SIZE_EXT
:
295 case GL_COLOR_TABLE_BLUE_SIZE_EXT
:
298 case GL_COLOR_TABLE_ALPHA_SIZE_EXT
:
301 case GL_COLOR_TABLE_LUMINANCE_SIZE_EXT
:
304 case GL_COLOR_TABLE_INTENSITY_SIZE_EXT
:
308 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter" );