1 /* $Id: colortab.c,v 1.33 2000/12/26 05:09:27 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 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.
39 #include "swrast/s_span.h" /* XXX SWRAST hack */
45 * Given an internalFormat token passed to glColorTable,
46 * return the corresponding base format.
47 * Return -1 if invalid token.
50 base_colortab_format( GLenum format
)
65 case GL_LUMINANCE_ALPHA
:
66 case GL_LUMINANCE4_ALPHA4
:
67 case GL_LUMINANCE6_ALPHA2
:
68 case GL_LUMINANCE8_ALPHA8
:
69 case GL_LUMINANCE12_ALPHA4
:
70 case GL_LUMINANCE12_ALPHA12
:
71 case GL_LUMINANCE16_ALPHA16
:
72 return GL_LUMINANCE_ALPHA
;
98 return -1; /* error */
104 _mesa_init_colortable( struct gl_color_table
*p
)
106 p
->FloatTable
= GL_FALSE
;
107 /* allocate a width=1 table by default */
108 p
->Table
= CALLOC(4 * sizeof(GLchan
));
110 GLchan
*t
= (GLchan
*) p
->Table
;
117 p
->IntFormat
= GL_RGBA
;
119 p
->RedSize
= CHAN_BITS
;
120 p
->GreenSize
= CHAN_BITS
;
121 p
->BlueSize
= CHAN_BITS
;
122 p
->AlphaSize
= CHAN_BITS
;
123 p
->IntensitySize
= 0;
124 p
->LuminanceSize
= 0;
130 _mesa_free_colortable_data( struct gl_color_table
*p
)
140 * Examine table's format and set the component sizes accordingly.
143 set_component_sizes( struct gl_color_table
*table
)
145 switch (table
->Format
) {
148 table
->GreenSize
= 0;
150 table
->AlphaSize
= CHAN_BITS
;
151 table
->IntensitySize
= 0;
152 table
->LuminanceSize
= 0;
156 table
->GreenSize
= 0;
158 table
->AlphaSize
= 0;
159 table
->IntensitySize
= 0;
160 table
->LuminanceSize
= CHAN_BITS
;
162 case GL_LUMINANCE_ALPHA
:
164 table
->GreenSize
= 0;
166 table
->AlphaSize
= CHAN_BITS
;
167 table
->IntensitySize
= 0;
168 table
->LuminanceSize
= CHAN_BITS
;
172 table
->GreenSize
= 0;
174 table
->AlphaSize
= 0;
175 table
->IntensitySize
= CHAN_BITS
;
176 table
->LuminanceSize
= 0;
179 table
->RedSize
= CHAN_BITS
;
180 table
->GreenSize
= CHAN_BITS
;
181 table
->BlueSize
= CHAN_BITS
;
182 table
->AlphaSize
= 0;
183 table
->IntensitySize
= 0;
184 table
->LuminanceSize
= 0;
187 table
->RedSize
= CHAN_BITS
;
188 table
->GreenSize
= CHAN_BITS
;
189 table
->BlueSize
= CHAN_BITS
;
190 table
->AlphaSize
= CHAN_BITS
;
191 table
->IntensitySize
= 0;
192 table
->LuminanceSize
= 0;
195 gl_problem(NULL
, "unexpected format in set_component_sizes");
202 _mesa_ColorTable( GLenum target
, GLenum internalFormat
,
203 GLsizei width
, GLenum format
, GLenum type
,
206 GET_CURRENT_CONTEXT(ctx
);
207 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
208 struct gl_texture_object
*texObj
= NULL
;
209 struct gl_color_table
*table
= NULL
;
210 GLboolean proxy
= GL_FALSE
;
212 GLfloat rScale
= 1.0, gScale
= 1.0, bScale
= 1.0, aScale
= 1.0;
213 GLfloat rBias
= 0.0, gBias
= 0.0, bBias
= 0.0, aBias
= 0.0;
214 GLboolean floatTable
= GL_FALSE
;
216 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* too complex */
220 texObj
= texUnit
->Current1D
;
221 table
= &texObj
->Palette
;
224 texObj
= texUnit
->Current2D
;
225 table
= &texObj
->Palette
;
228 texObj
= texUnit
->Current3D
;
229 table
= &texObj
->Palette
;
231 case GL_PROXY_TEXTURE_1D
:
232 texObj
= ctx
->Texture
.Proxy1D
;
233 table
= &texObj
->Palette
;
236 case GL_PROXY_TEXTURE_2D
:
237 texObj
= ctx
->Texture
.Proxy2D
;
238 table
= &texObj
->Palette
;
241 case GL_PROXY_TEXTURE_3D
:
242 texObj
= ctx
->Texture
.Proxy3D
;
243 table
= &texObj
->Palette
;
246 case GL_SHARED_TEXTURE_PALETTE_EXT
:
247 table
= &ctx
->Texture
.Palette
;
250 table
= &ctx
->ColorTable
;
251 floatTable
= GL_TRUE
;
252 rScale
= ctx
->Pixel
.ColorTableScale
[0];
253 gScale
= ctx
->Pixel
.ColorTableScale
[1];
254 bScale
= ctx
->Pixel
.ColorTableScale
[2];
255 aScale
= ctx
->Pixel
.ColorTableScale
[3];
256 rBias
= ctx
->Pixel
.ColorTableBias
[0];
257 gBias
= ctx
->Pixel
.ColorTableBias
[1];
258 bBias
= ctx
->Pixel
.ColorTableBias
[2];
259 aBias
= ctx
->Pixel
.ColorTableBias
[3];
261 case GL_PROXY_COLOR_TABLE
:
262 table
= &ctx
->ProxyColorTable
;
265 case GL_POST_CONVOLUTION_COLOR_TABLE
:
266 table
= &ctx
->PostConvolutionColorTable
;
267 floatTable
= GL_TRUE
;
268 rScale
= ctx
->Pixel
.PCCTscale
[0];
269 gScale
= ctx
->Pixel
.PCCTscale
[1];
270 bScale
= ctx
->Pixel
.PCCTscale
[2];
271 aScale
= ctx
->Pixel
.PCCTscale
[3];
272 rBias
= ctx
->Pixel
.PCCTbias
[0];
273 gBias
= ctx
->Pixel
.PCCTbias
[1];
274 bBias
= ctx
->Pixel
.PCCTbias
[2];
275 aBias
= ctx
->Pixel
.PCCTbias
[3];
277 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
278 table
= &ctx
->ProxyPostConvolutionColorTable
;
281 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
282 table
= &ctx
->PostColorMatrixColorTable
;
283 floatTable
= GL_TRUE
;
284 rScale
= ctx
->Pixel
.PCMCTscale
[0];
285 gScale
= ctx
->Pixel
.PCMCTscale
[1];
286 bScale
= ctx
->Pixel
.PCMCTscale
[2];
287 aScale
= ctx
->Pixel
.PCMCTscale
[3];
288 rBias
= ctx
->Pixel
.PCMCTbias
[0];
289 gBias
= ctx
->Pixel
.PCMCTbias
[1];
290 bBias
= ctx
->Pixel
.PCMCTbias
[2];
291 aBias
= ctx
->Pixel
.PCMCTbias
[3];
293 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
294 table
= &ctx
->ProxyPostColorMatrixColorTable
;
298 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
304 if (!_mesa_is_legal_format_and_type(format
, type
) ||
305 format
== GL_INTENSITY
) {
306 gl_error(ctx
, GL_INVALID_OPERATION
, "glColorTable(format or type)");
310 baseFormat
= base_colortab_format(internalFormat
);
311 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
312 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTable(internalFormat)");
316 if (width
< 0 || (width
!= 0 && _mesa_bitcount(width
) != 1)) {
320 table
->IntFormat
= (GLenum
) 0;
321 table
->Format
= (GLenum
) 0;
325 sprintf(msg
, "glColorTable(width=%d)", width
);
326 gl_error(ctx
, GL_INVALID_VALUE
, msg
);
331 if (width
> ctx
->Const
.MaxColorTableSize
) {
334 table
->IntFormat
= (GLenum
) 0;
335 table
->Format
= (GLenum
) 0;
338 if (width
> ctx
->Const
.MaxColorTableSize
)
339 gl_error(ctx
, GL_TABLE_TOO_LARGE
, "glColorTable(width)");
342 sprintf(msg
, "glColorTable(width=%d)", width
);
343 gl_error(ctx
, GL_INVALID_VALUE
, msg
);
350 table
->IntFormat
= internalFormat
;
351 table
->Format
= (GLenum
) baseFormat
;
352 set_component_sizes(table
);
354 comps
= _mesa_components_in_format(table
->Format
);
355 assert(comps
> 0); /* error should have been caught sooner */
358 /* free old table, if any */
363 GLfloat tempTab
[MAX_COLOR_TABLE_SIZE
* 4];
367 _mesa_unpack_float_color_span(ctx
, width
, table
->Format
,
369 format
, type
, data
, &ctx
->Unpack
,
372 table
->FloatTable
= GL_TRUE
;
373 table
->Table
= MALLOC(comps
* width
* sizeof(GLfloat
));
375 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
379 tableF
= (GLfloat
*) table
->Table
;
381 switch (table
->Format
) {
383 for (i
= 0; i
< width
; i
++) {
384 tableF
[i
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
388 for (i
= 0; i
< width
; i
++) {
389 tableF
[i
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
393 for (i
= 0; i
< width
; i
++) {
394 tableF
[i
] = CLAMP(tempTab
[i
] * aScale
+ aBias
, 0.0F
, 1.0F
);
397 case GL_LUMINANCE_ALPHA
:
398 for (i
= 0; i
< width
; i
++) {
399 tableF
[i
*2+0] = CLAMP(tempTab
[i
*2+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
400 tableF
[i
*2+1] = CLAMP(tempTab
[i
*2+1] * aScale
+ aBias
, 0.0F
, 1.0F
);
404 for (i
= 0; i
< width
; i
++) {
405 tableF
[i
*3+0] = CLAMP(tempTab
[i
*3+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
406 tableF
[i
*3+1] = CLAMP(tempTab
[i
*3+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
407 tableF
[i
*3+2] = CLAMP(tempTab
[i
*3+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
411 for (i
= 0; i
< width
; i
++) {
412 tableF
[i
*4+0] = CLAMP(tempTab
[i
*4+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
413 tableF
[i
*4+1] = CLAMP(tempTab
[i
*4+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
414 tableF
[i
*4+2] = CLAMP(tempTab
[i
*4+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
415 tableF
[i
*4+3] = CLAMP(tempTab
[i
*4+3] * aScale
+ aBias
, 0.0F
, 1.0F
);
419 gl_problem(ctx
, "Bad format in _mesa_ColorTable");
424 /* store GLchan table */
425 table
->FloatTable
= GL_FALSE
;
426 table
->Table
= MALLOC(comps
* width
* sizeof(GLchan
));
428 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
431 _mesa_unpack_chan_color_span(ctx
, width
, table
->Format
,
432 table
->Table
, /* dest */
438 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
439 /* texture object palette, texObj==NULL means the shared palette */
440 if (ctx
->Driver
.UpdateTexturePalette
) {
441 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
445 ctx
->NewState
|= _NEW_PIXEL
;
451 _mesa_ColorSubTable( GLenum target
, GLsizei start
,
452 GLsizei count
, GLenum format
, GLenum type
,
455 GET_CURRENT_CONTEXT(ctx
);
456 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
457 struct gl_texture_object
*texObj
= NULL
;
458 struct gl_color_table
*table
= NULL
;
459 GLfloat rScale
= 1.0, gScale
= 1.0, bScale
= 1.0, aScale
= 1.0;
460 GLfloat rBias
= 0.0, gBias
= 0.0, bBias
= 0.0, aBias
= 0.0;
462 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
466 texObj
= texUnit
->Current1D
;
467 table
= &texObj
->Palette
;
470 texObj
= texUnit
->Current2D
;
471 table
= &texObj
->Palette
;
474 texObj
= texUnit
->Current3D
;
475 table
= &texObj
->Palette
;
477 case GL_SHARED_TEXTURE_PALETTE_EXT
:
478 table
= &ctx
->Texture
.Palette
;
481 table
= &ctx
->ColorTable
;
482 rScale
= ctx
->Pixel
.ColorTableScale
[0];
483 gScale
= ctx
->Pixel
.ColorTableScale
[1];
484 bScale
= ctx
->Pixel
.ColorTableScale
[2];
485 aScale
= ctx
->Pixel
.ColorTableScale
[3];
486 rBias
= ctx
->Pixel
.ColorTableBias
[0];
487 gBias
= ctx
->Pixel
.ColorTableBias
[1];
488 bBias
= ctx
->Pixel
.ColorTableBias
[2];
489 aBias
= ctx
->Pixel
.ColorTableBias
[3];
491 case GL_POST_CONVOLUTION_COLOR_TABLE
:
492 table
= &ctx
->PostConvolutionColorTable
;
493 rScale
= ctx
->Pixel
.PCCTscale
[0];
494 gScale
= ctx
->Pixel
.PCCTscale
[1];
495 bScale
= ctx
->Pixel
.PCCTscale
[2];
496 aScale
= ctx
->Pixel
.PCCTscale
[3];
497 rBias
= ctx
->Pixel
.PCCTbias
[0];
498 gBias
= ctx
->Pixel
.PCCTbias
[1];
499 bBias
= ctx
->Pixel
.PCCTbias
[2];
500 aBias
= ctx
->Pixel
.PCCTbias
[3];
502 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
503 table
= &ctx
->PostColorMatrixColorTable
;
504 rScale
= ctx
->Pixel
.PCMCTscale
[0];
505 gScale
= ctx
->Pixel
.PCMCTscale
[1];
506 bScale
= ctx
->Pixel
.PCMCTscale
[2];
507 aScale
= ctx
->Pixel
.PCMCTscale
[3];
508 rBias
= ctx
->Pixel
.PCMCTbias
[0];
509 gBias
= ctx
->Pixel
.PCMCTbias
[1];
510 bBias
= ctx
->Pixel
.PCMCTbias
[2];
511 aBias
= ctx
->Pixel
.PCMCTbias
[3];
514 gl_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
520 if (!_mesa_is_legal_format_and_type(format
, type
) ||
521 format
== GL_INTENSITY
) {
522 gl_error(ctx
, GL_INVALID_OPERATION
, "glColorSubTable(format or type)");
527 gl_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
531 comps
= _mesa_components_in_format(table
->Format
);
532 assert(comps
> 0); /* error should have been caught sooner */
534 if (start
+ count
> table
->Size
) {
535 gl_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
540 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glColorSubTable");
544 if (!table
->FloatTable
) {
545 GLchan
*dest
= (GLchan
*) table
->Table
+ start
* comps
* sizeof(GLchan
);
546 _mesa_unpack_chan_color_span(ctx
, count
, table
->Format
, dest
,
547 format
, type
, data
, &ctx
->Unpack
, 0);
550 GLfloat tempTab
[MAX_COLOR_TABLE_SIZE
* 4];
554 ASSERT(table
->FloatTable
);
556 _mesa_unpack_float_color_span(ctx
, count
, table
->Format
,
558 format
, type
, data
, &ctx
->Unpack
,
561 tableF
= (GLfloat
*) table
->Table
;
563 switch (table
->Format
) {
565 for (i
= 0; i
< count
; i
++) {
566 GLuint j
= start
+ i
;
567 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
571 for (i
= 0; i
< count
; i
++) {
572 GLuint j
= start
+ i
;
573 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
577 for (i
= 0; i
< count
; i
++) {
578 GLuint j
= start
+ i
;
579 tableF
[j
] = CLAMP(tempTab
[i
] * aScale
+ aBias
, 0.0F
, 1.0F
);
582 case GL_LUMINANCE_ALPHA
:
583 for (i
= 0; i
< count
; i
++) {
584 GLuint j
= start
+ i
;
585 tableF
[j
*2+0] = CLAMP(tempTab
[i
*2+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
586 tableF
[j
*2+1] = CLAMP(tempTab
[i
*2+1] * aScale
+ aBias
, 0.0F
, 1.0F
);
590 for (i
= 0; i
< count
; i
++) {
591 GLuint j
= start
+ i
;
592 tableF
[j
*3+0] = CLAMP(tempTab
[i
*3+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
593 tableF
[j
*3+1] = CLAMP(tempTab
[i
*3+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
594 tableF
[j
*3+2] = CLAMP(tempTab
[i
*3+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
598 for (i
= 0; i
< count
; i
++) {
599 GLuint j
= start
+ i
;
600 tableF
[j
*4+0] = CLAMP(tempTab
[i
*4+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
601 tableF
[j
*4+1] = CLAMP(tempTab
[i
*4+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
602 tableF
[j
*4+2] = CLAMP(tempTab
[i
*4+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
603 tableF
[j
*4+3] = CLAMP(tempTab
[i
*4+3] * aScale
+ aBias
, 0.0F
, 1.0F
);
607 gl_problem(ctx
, "Bad format in _mesa_ColorSubTable");
612 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
613 /* per-texture object palette */
614 if (ctx
->Driver
.UpdateTexturePalette
) {
615 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
619 ctx
->NewState
|= _NEW_PIXEL
;
626 _mesa_CopyColorTable(GLenum target
, GLenum internalformat
,
627 GLint x
, GLint y
, GLsizei width
)
629 GLchan data
[MAX_WIDTH
][4];
630 GET_CURRENT_CONTEXT(ctx
);
631 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
633 /* Select buffer to read from */
634 (*ctx
->Driver
.SetReadBuffer
)( ctx
, ctx
->ReadBuffer
,
635 ctx
->Pixel
.DriverReadBuffer
);
637 if (width
> MAX_WIDTH
)
640 /* read the data from framebuffer */
642 gl_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
, data
);
645 /* Restore reading from draw buffer (the default) */
646 (*ctx
->Driver
.SetReadBuffer
)( ctx
, ctx
->DrawBuffer
,
647 ctx
->Color
.DriverDrawBuffer
);
649 _mesa_ColorTable(target
, internalformat
, width
,
650 GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
657 _mesa_CopyColorSubTable(GLenum target
, GLsizei start
,
658 GLint x
, GLint y
, GLsizei width
)
660 GLchan data
[MAX_WIDTH
][4];
661 GET_CURRENT_CONTEXT(ctx
);
662 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
664 /* Select buffer to read from */
665 (*ctx
->Driver
.SetReadBuffer
)( ctx
, ctx
->ReadBuffer
,
666 ctx
->Pixel
.DriverReadBuffer
);
668 if (width
> MAX_WIDTH
)
671 /* read the data from framebuffer */
673 gl_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
, data
);
676 /* Restore reading from draw buffer (the default) */
677 (*ctx
->Driver
.SetReadBuffer
)( ctx
, ctx
->DrawBuffer
,
678 ctx
->Color
.DriverDrawBuffer
);
680 _mesa_ColorSubTable(target
, start
, width
, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
686 _mesa_GetColorTable( GLenum target
, GLenum format
,
687 GLenum type
, GLvoid
*data
)
689 GET_CURRENT_CONTEXT(ctx
);
690 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
691 struct gl_color_table
*table
= NULL
;
692 GLchan rgba
[MAX_COLOR_TABLE_SIZE
][4];
694 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
697 gl_update_state(ctx
);
702 table
= &texUnit
->Current1D
->Palette
;
705 table
= &texUnit
->Current2D
->Palette
;
708 table
= &texUnit
->Current3D
->Palette
;
710 case GL_SHARED_TEXTURE_PALETTE_EXT
:
711 table
= &ctx
->Texture
.Palette
;
714 table
= &ctx
->ColorTable
;
716 case GL_POST_CONVOLUTION_COLOR_TABLE
:
717 table
= &ctx
->PostConvolutionColorTable
;
719 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
720 table
= &ctx
->PostColorMatrixColorTable
;
723 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
729 switch (table
->Format
) {
731 if (table
->FloatTable
) {
732 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
733 for (i
= 0; i
< table
->Size
; i
++) {
737 rgba
[i
][ACOMP
] = (GLint
) (tableF
[i
] * CHAN_MAXF
);
741 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
742 for (i
= 0; i
< table
->Size
; i
++) {
746 rgba
[i
][ACOMP
] = tableUB
[i
];
751 if (table
->FloatTable
) {
752 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
753 for (i
= 0; i
< table
->Size
; i
++) {
754 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
] * CHAN_MAXF
);
755 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
] * CHAN_MAXF
);
756 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
] * CHAN_MAXF
);
757 rgba
[i
][ACOMP
] = CHAN_MAX
;
761 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
762 for (i
= 0; i
< table
->Size
; i
++) {
763 rgba
[i
][RCOMP
] = tableUB
[i
];
764 rgba
[i
][GCOMP
] = tableUB
[i
];
765 rgba
[i
][BCOMP
] = tableUB
[i
];
766 rgba
[i
][ACOMP
] = CHAN_MAX
;
770 case GL_LUMINANCE_ALPHA
:
771 if (table
->FloatTable
) {
772 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
773 for (i
= 0; i
< table
->Size
; i
++) {
774 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
*2+0] * CHAN_MAXF
);
775 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
*2+0] * CHAN_MAXF
);
776 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
*2+0] * CHAN_MAXF
);
777 rgba
[i
][ACOMP
] = (GLint
) (tableF
[i
*2+1] * CHAN_MAXF
);
781 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
782 for (i
= 0; i
< table
->Size
; i
++) {
783 rgba
[i
][RCOMP
] = tableUB
[i
*2+0];
784 rgba
[i
][GCOMP
] = tableUB
[i
*2+0];
785 rgba
[i
][BCOMP
] = tableUB
[i
*2+0];
786 rgba
[i
][ACOMP
] = tableUB
[i
*2+1];
791 if (table
->FloatTable
) {
792 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
793 for (i
= 0; i
< table
->Size
; i
++) {
794 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
] * CHAN_MAXF
);
795 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
] * CHAN_MAXF
);
796 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
] * CHAN_MAXF
);
797 rgba
[i
][ACOMP
] = (GLint
) (tableF
[i
] * CHAN_MAXF
);
801 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
802 for (i
= 0; i
< table
->Size
; i
++) {
803 rgba
[i
][RCOMP
] = tableUB
[i
];
804 rgba
[i
][GCOMP
] = tableUB
[i
];
805 rgba
[i
][BCOMP
] = tableUB
[i
];
806 rgba
[i
][ACOMP
] = tableUB
[i
];
811 if (table
->FloatTable
) {
812 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
813 for (i
= 0; i
< table
->Size
; i
++) {
814 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
*3+0] * CHAN_MAXF
);
815 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
*3+1] * CHAN_MAXF
);
816 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
*3+2] * CHAN_MAXF
);
817 rgba
[i
][ACOMP
] = CHAN_MAX
;
821 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
822 for (i
= 0; i
< table
->Size
; i
++) {
823 rgba
[i
][RCOMP
] = tableUB
[i
*3+0];
824 rgba
[i
][GCOMP
] = tableUB
[i
*3+1];
825 rgba
[i
][BCOMP
] = tableUB
[i
*3+2];
826 rgba
[i
][ACOMP
] = CHAN_MAX
;
831 if (table
->FloatTable
) {
832 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
833 for (i
= 0; i
< table
->Size
; i
++) {
834 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
*4+0] * CHAN_MAXF
+ 0.5F
);
835 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
*4+1] * CHAN_MAXF
+ 0.5F
);
836 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
*4+2] * CHAN_MAXF
+ 0.5F
);
837 rgba
[i
][ACOMP
] = (GLint
) (tableF
[i
*4+3] * CHAN_MAXF
+ 0.5F
);
841 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
842 for (i
= 0; i
< table
->Size
; i
++) {
843 rgba
[i
][RCOMP
] = tableUB
[i
*4+0];
844 rgba
[i
][GCOMP
] = tableUB
[i
*4+1];
845 rgba
[i
][BCOMP
] = tableUB
[i
*4+2];
846 rgba
[i
][ACOMP
] = tableUB
[i
*4+3];
851 gl_problem(ctx
, "bad table format in glGetColorTable");
855 _mesa_pack_rgba_span(ctx
, table
->Size
, (const GLchan (*)[]) rgba
,
856 format
, type
, data
, &ctx
->Pack
, GL_FALSE
);
862 _mesa_ColorTableParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
864 GET_CURRENT_CONTEXT(ctx
);
865 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
868 case GL_COLOR_TABLE_SGI
:
869 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
870 ctx
->Pixel
.ColorTableScale
[0] = params
[0];
871 ctx
->Pixel
.ColorTableScale
[1] = params
[1];
872 ctx
->Pixel
.ColorTableScale
[2] = params
[2];
873 ctx
->Pixel
.ColorTableScale
[3] = params
[3];
875 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
876 ctx
->Pixel
.ColorTableBias
[0] = params
[0];
877 ctx
->Pixel
.ColorTableBias
[1] = params
[1];
878 ctx
->Pixel
.ColorTableBias
[2] = params
[2];
879 ctx
->Pixel
.ColorTableBias
[3] = params
[3];
882 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
886 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI
:
887 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
888 ctx
->Pixel
.PCCTscale
[0] = params
[0];
889 ctx
->Pixel
.PCCTscale
[1] = params
[1];
890 ctx
->Pixel
.PCCTscale
[2] = params
[2];
891 ctx
->Pixel
.PCCTscale
[3] = params
[3];
893 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
894 ctx
->Pixel
.PCCTbias
[0] = params
[0];
895 ctx
->Pixel
.PCCTbias
[1] = params
[1];
896 ctx
->Pixel
.PCCTbias
[2] = params
[2];
897 ctx
->Pixel
.PCCTbias
[3] = params
[3];
900 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
904 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
:
905 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
906 ctx
->Pixel
.PCMCTscale
[0] = params
[0];
907 ctx
->Pixel
.PCMCTscale
[1] = params
[1];
908 ctx
->Pixel
.PCMCTscale
[2] = params
[2];
909 ctx
->Pixel
.PCMCTscale
[3] = params
[3];
911 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
912 ctx
->Pixel
.PCMCTbias
[0] = params
[0];
913 ctx
->Pixel
.PCMCTbias
[1] = params
[1];
914 ctx
->Pixel
.PCMCTbias
[2] = params
[2];
915 ctx
->Pixel
.PCMCTbias
[3] = params
[3];
918 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
923 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameter(target)");
927 ctx
->NewState
|= _NEW_PIXEL
;
933 _mesa_ColorTableParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
936 if (pname
== GL_COLOR_TABLE_SGI
||
937 pname
== GL_POST_CONVOLUTION_COLOR_TABLE_SGI
||
938 pname
== GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
) {
940 fparams
[0] = (GLfloat
) params
[0];
941 fparams
[1] = (GLfloat
) params
[1];
942 fparams
[2] = (GLfloat
) params
[2];
943 fparams
[3] = (GLfloat
) params
[3];
947 fparams
[0] = (GLfloat
) params
[0];
949 _mesa_ColorTableParameterfv(target
, pname
, fparams
);
955 _mesa_GetColorTableParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
957 GET_CURRENT_CONTEXT(ctx
);
958 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
959 struct gl_color_table
*table
= NULL
;
960 ASSERT_OUTSIDE_BEGIN_END(ctx
);
964 table
= &texUnit
->Current1D
->Palette
;
967 table
= &texUnit
->Current2D
->Palette
;
970 table
= &texUnit
->Current3D
->Palette
;
972 case GL_PROXY_TEXTURE_1D
:
973 table
= &ctx
->Texture
.Proxy1D
->Palette
;
975 case GL_PROXY_TEXTURE_2D
:
976 table
= &ctx
->Texture
.Proxy2D
->Palette
;
978 case GL_PROXY_TEXTURE_3D
:
979 table
= &ctx
->Texture
.Proxy3D
->Palette
;
981 case GL_SHARED_TEXTURE_PALETTE_EXT
:
982 table
= &ctx
->Texture
.Palette
;
985 table
= &ctx
->ColorTable
;
986 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
987 params
[0] = ctx
->Pixel
.ColorTableScale
[0];
988 params
[1] = ctx
->Pixel
.ColorTableScale
[1];
989 params
[2] = ctx
->Pixel
.ColorTableScale
[2];
990 params
[3] = ctx
->Pixel
.ColorTableScale
[3];
993 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
994 params
[0] = ctx
->Pixel
.ColorTableBias
[0];
995 params
[1] = ctx
->Pixel
.ColorTableBias
[1];
996 params
[2] = ctx
->Pixel
.ColorTableBias
[2];
997 params
[3] = ctx
->Pixel
.ColorTableBias
[3];
1001 case GL_PROXY_COLOR_TABLE
:
1002 table
= &ctx
->ProxyColorTable
;
1004 case GL_POST_CONVOLUTION_COLOR_TABLE
:
1005 table
= &ctx
->PostConvolutionColorTable
;
1006 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1007 params
[0] = ctx
->Pixel
.PCCTscale
[0];
1008 params
[1] = ctx
->Pixel
.PCCTscale
[1];
1009 params
[2] = ctx
->Pixel
.PCCTscale
[2];
1010 params
[3] = ctx
->Pixel
.PCCTscale
[3];
1013 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1014 params
[0] = ctx
->Pixel
.PCCTbias
[0];
1015 params
[1] = ctx
->Pixel
.PCCTbias
[1];
1016 params
[2] = ctx
->Pixel
.PCCTbias
[2];
1017 params
[3] = ctx
->Pixel
.PCCTbias
[3];
1021 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
1022 table
= &ctx
->ProxyPostConvolutionColorTable
;
1024 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
1025 table
= &ctx
->PostColorMatrixColorTable
;
1026 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1027 params
[0] = ctx
->Pixel
.PCMCTscale
[0];
1028 params
[1] = ctx
->Pixel
.PCMCTscale
[1];
1029 params
[2] = ctx
->Pixel
.PCMCTscale
[2];
1030 params
[3] = ctx
->Pixel
.PCMCTscale
[3];
1033 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1034 params
[0] = ctx
->Pixel
.PCMCTbias
[0];
1035 params
[1] = ctx
->Pixel
.PCMCTbias
[1];
1036 params
[2] = ctx
->Pixel
.PCMCTbias
[2];
1037 params
[3] = ctx
->Pixel
.PCMCTbias
[3];
1041 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
1042 table
= &ctx
->ProxyPostColorMatrixColorTable
;
1045 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(target)");
1052 case GL_COLOR_TABLE_FORMAT
:
1053 *params
= table
->IntFormat
;
1055 case GL_COLOR_TABLE_WIDTH
:
1056 *params
= table
->Size
;
1058 case GL_COLOR_TABLE_RED_SIZE
:
1059 *params
= table
->RedSize
;
1061 case GL_COLOR_TABLE_GREEN_SIZE
:
1062 *params
= table
->GreenSize
;
1064 case GL_COLOR_TABLE_BLUE_SIZE
:
1065 *params
= table
->BlueSize
;
1067 case GL_COLOR_TABLE_ALPHA_SIZE
:
1068 *params
= table
->AlphaSize
;
1070 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1071 *params
= table
->LuminanceSize
;
1073 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1074 *params
= table
->IntensitySize
;
1077 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(pname)" );
1085 _mesa_GetColorTableParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1087 GET_CURRENT_CONTEXT(ctx
);
1088 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1089 struct gl_color_table
*table
= NULL
;
1090 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1094 table
= &texUnit
->Current1D
->Palette
;
1097 table
= &texUnit
->Current2D
->Palette
;
1100 table
= &texUnit
->Current3D
->Palette
;
1102 case GL_PROXY_TEXTURE_1D
:
1103 table
= &ctx
->Texture
.Proxy1D
->Palette
;
1105 case GL_PROXY_TEXTURE_2D
:
1106 table
= &ctx
->Texture
.Proxy2D
->Palette
;
1108 case GL_PROXY_TEXTURE_3D
:
1109 table
= &ctx
->Texture
.Proxy3D
->Palette
;
1111 case GL_SHARED_TEXTURE_PALETTE_EXT
:
1112 table
= &ctx
->Texture
.Palette
;
1114 case GL_COLOR_TABLE
:
1115 table
= &ctx
->ColorTable
;
1116 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1117 params
[0] = (GLint
) ctx
->Pixel
.ColorTableScale
[0];
1118 params
[1] = (GLint
) ctx
->Pixel
.ColorTableScale
[1];
1119 params
[2] = (GLint
) ctx
->Pixel
.ColorTableScale
[2];
1120 params
[3] = (GLint
) ctx
->Pixel
.ColorTableScale
[3];
1123 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1124 params
[0] = (GLint
) ctx
->Pixel
.ColorTableBias
[0];
1125 params
[1] = (GLint
) ctx
->Pixel
.ColorTableBias
[1];
1126 params
[2] = (GLint
) ctx
->Pixel
.ColorTableBias
[2];
1127 params
[3] = (GLint
) ctx
->Pixel
.ColorTableBias
[3];
1131 case GL_PROXY_COLOR_TABLE
:
1132 table
= &ctx
->ProxyColorTable
;
1134 case GL_POST_CONVOLUTION_COLOR_TABLE
:
1135 table
= &ctx
->PostConvolutionColorTable
;
1136 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1137 params
[0] = (GLint
) ctx
->Pixel
.PCCTscale
[0];
1138 params
[1] = (GLint
) ctx
->Pixel
.PCCTscale
[1];
1139 params
[2] = (GLint
) ctx
->Pixel
.PCCTscale
[2];
1140 params
[3] = (GLint
) ctx
->Pixel
.PCCTscale
[3];
1143 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1144 params
[0] = (GLint
) ctx
->Pixel
.PCCTbias
[0];
1145 params
[1] = (GLint
) ctx
->Pixel
.PCCTbias
[1];
1146 params
[2] = (GLint
) ctx
->Pixel
.PCCTbias
[2];
1147 params
[3] = (GLint
) ctx
->Pixel
.PCCTbias
[3];
1151 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
1152 table
= &ctx
->ProxyPostConvolutionColorTable
;
1154 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
1155 table
= &ctx
->PostColorMatrixColorTable
;
1156 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1157 params
[0] = (GLint
) ctx
->Pixel
.PCMCTscale
[0];
1158 params
[1] = (GLint
) ctx
->Pixel
.PCMCTscale
[1];
1159 params
[2] = (GLint
) ctx
->Pixel
.PCMCTscale
[2];
1160 params
[3] = (GLint
) ctx
->Pixel
.PCMCTscale
[3];
1163 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1164 params
[0] = (GLint
) ctx
->Pixel
.PCMCTbias
[0];
1165 params
[1] = (GLint
) ctx
->Pixel
.PCMCTbias
[1];
1166 params
[2] = (GLint
) ctx
->Pixel
.PCMCTbias
[2];
1167 params
[3] = (GLint
) ctx
->Pixel
.PCMCTbias
[3];
1171 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
1172 table
= &ctx
->ProxyPostColorMatrixColorTable
;
1175 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(target)");
1182 case GL_COLOR_TABLE_FORMAT
:
1183 *params
= table
->IntFormat
;
1185 case GL_COLOR_TABLE_WIDTH
:
1186 *params
= table
->Size
;
1188 case GL_COLOR_TABLE_RED_SIZE
:
1189 *params
= table
->RedSize
;
1191 case GL_COLOR_TABLE_GREEN_SIZE
:
1192 *params
= table
->GreenSize
;
1194 case GL_COLOR_TABLE_BLUE_SIZE
:
1195 *params
= table
->BlueSize
;
1197 case GL_COLOR_TABLE_ALPHA_SIZE
:
1198 *params
= table
->AlphaSize
;
1200 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1201 *params
= table
->LuminanceSize
;
1203 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1204 *params
= table
->IntensitySize
;
1207 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(pname)" );