1 /* $Id: colortab.c,v 1.18 2000/05/24 14:03:04 brianp 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.
44 * Given an internalFormat token passed to glColorTable,
45 * return the corresponding base format.
46 * Return -1 if invalid token.
49 base_colortab_format( GLenum format
)
64 case GL_LUMINANCE_ALPHA
:
65 case GL_LUMINANCE4_ALPHA4
:
66 case GL_LUMINANCE6_ALPHA2
:
67 case GL_LUMINANCE8_ALPHA8
:
68 case GL_LUMINANCE12_ALPHA4
:
69 case GL_LUMINANCE12_ALPHA12
:
70 case GL_LUMINANCE16_ALPHA16
:
71 return GL_LUMINANCE_ALPHA
;
97 return -1; /* error */
103 _mesa_init_colortable( struct gl_color_table
*p
)
105 p
->TableType
= GL_UNSIGNED_BYTE
;
106 /* allocate a width=1 table by default */
107 p
->Table
= CALLOC(4 * sizeof(GLubyte
));
109 GLubyte
*t
= (GLubyte
*) p
->Table
;
116 p
->IntFormat
= GL_RGBA
;
122 p
->IntensitySize
= 0;
123 p
->LuminanceSize
= 0;
129 _mesa_free_colortable_data( struct gl_color_table
*p
)
139 * Examine table's format and set the component sizes accordingly.
142 set_component_sizes( struct gl_color_table
*table
)
144 switch (table
->Format
) {
147 table
->GreenSize
= 0;
149 table
->AlphaSize
= 8;
150 table
->IntensitySize
= 0;
151 table
->LuminanceSize
= 0;
155 table
->GreenSize
= 0;
157 table
->AlphaSize
= 0;
158 table
->IntensitySize
= 0;
159 table
->LuminanceSize
= 8;
161 case GL_LUMINANCE_ALPHA
:
163 table
->GreenSize
= 0;
165 table
->AlphaSize
= 8;
166 table
->IntensitySize
= 0;
167 table
->LuminanceSize
= 8;
171 table
->GreenSize
= 0;
173 table
->AlphaSize
= 0;
174 table
->IntensitySize
= 8;
175 table
->LuminanceSize
= 0;
179 table
->GreenSize
= 8;
181 table
->AlphaSize
= 0;
182 table
->IntensitySize
= 0;
183 table
->LuminanceSize
= 0;
187 table
->GreenSize
= 8;
189 table
->AlphaSize
= 8;
190 table
->IntensitySize
= 0;
191 table
->LuminanceSize
= 0;
194 gl_problem(NULL
, "unexpected format in set_component_sizes");
201 _mesa_ColorTable( GLenum target
, GLenum internalFormat
,
202 GLsizei width
, GLenum format
, GLenum type
,
205 GET_CURRENT_CONTEXT(ctx
);
206 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
207 struct gl_texture_object
*texObj
= NULL
;
208 struct gl_color_table
*table
= NULL
;
209 GLboolean proxy
= GL_FALSE
;
211 GLfloat rScale
= 1.0, gScale
= 1.0, bScale
= 1.0, aScale
= 1.0;
212 GLfloat rBias
= 0.0, gBias
= 0.0, bBias
= 0.0, aBias
= 0.0;
213 GLboolean floatTable
= GL_FALSE
;
216 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glColorTable");
220 texObj
= texUnit
->CurrentD
[1];
221 table
= &texObj
->Palette
;
224 texObj
= texUnit
->CurrentD
[2];
225 table
= &texObj
->Palette
;
228 texObj
= texUnit
->CurrentD
[3];
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 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTable(format or type)");
309 baseFormat
= base_colortab_format(internalFormat
);
310 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
311 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTable(internalFormat)");
315 if (width
< 1 || width
> ctx
->Const
.MaxColorTableSize
316 || _mesa_bitcount(width
) != 1) {
317 if (width
> ctx
->Const
.MaxColorTableSize
)
318 gl_error(ctx
, GL_TABLE_TOO_LARGE
, "glColorTable(width)");
320 gl_error(ctx
, GL_INVALID_VALUE
, "glColorTable(width)");
323 table
->IntFormat
= (GLenum
) 0;
324 table
->Format
= (GLenum
) 0;
330 table
->IntFormat
= internalFormat
;
331 table
->Format
= (GLenum
) baseFormat
;
332 set_component_sizes(table
);
334 comps
= _mesa_components_in_format(table
->Format
);
335 assert(comps
> 0); /* error should have been caught sooner */
338 /* free old table, if any */
343 GLubyte tableUB
[MAX_COLOR_TABLE_SIZE
* 4];
347 _mesa_unpack_ubyte_color_span(ctx
, width
, table
->Format
,
350 &ctx
->Unpack
, GL_TRUE
);
352 table
->TableType
= GL_FLOAT
;
353 table
->Table
= MALLOC(comps
* width
* sizeof(GLfloat
));
355 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
359 /* Apply scale and bias and convert GLubyte values to GLfloats
360 * in [0, 1]. Store results in the tableF[].
366 tableF
= (GLfloat
*) table
->Table
;
368 switch (table
->Format
) {
370 for (i
= 0; i
< width
; i
++) {
371 tableF
[i
] = tableUB
[i
] * rScale
+ rBias
;
375 for (i
= 0; i
< width
; i
++) {
376 tableF
[i
] = tableUB
[i
] * rScale
+ rBias
;
380 for (i
= 0; i
< width
; i
++) {
381 tableF
[i
] = tableUB
[i
] * aScale
+ aBias
;
384 case GL_LUMINANCE_ALPHA
:
385 for (i
= 0; i
< width
; i
++) {
386 tableF
[i
*2+0] = tableUB
[i
*2+0] * rScale
+ rBias
;
387 tableF
[i
*2+1] = tableUB
[i
*2+1] * aScale
+ aBias
;
391 for (i
= 0; i
< width
; i
++) {
392 tableF
[i
*3+0] = tableUB
[i
*3+0] * rScale
+ rBias
;
393 tableF
[i
*3+1] = tableUB
[i
*3+1] * gScale
+ gBias
;
394 tableF
[i
*3+2] = tableUB
[i
*3+2] * bScale
+ bBias
;
398 for (i
= 0; i
< width
; i
++) {
399 tableF
[i
*4+0] = tableUB
[i
*4+0] * rScale
+ rBias
;
400 tableF
[i
*4+1] = tableUB
[i
*4+1] * gScale
+ gBias
;
401 tableF
[i
*4+2] = tableUB
[i
*4+2] * bScale
+ bBias
;
402 tableF
[i
*4+3] = tableUB
[i
*4+3] * aScale
+ aBias
;
406 gl_problem(ctx
, "Bad format in _mesa_ColorTable");
411 /* store GLubyte table */
412 table
->TableType
= GL_UNSIGNED_BYTE
;
413 table
->Table
= MALLOC(comps
* width
* sizeof(GLubyte
));
415 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
418 _mesa_unpack_ubyte_color_span(ctx
, width
, table
->Format
,
419 table
->Table
, /* dest */
421 &ctx
->Unpack
, GL_TRUE
);
425 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
426 /* texture object palette, texObj==NULL means the shared palette */
427 if (ctx
->Driver
.UpdateTexturePalette
) {
428 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
436 _mesa_ColorSubTable( GLenum target
, GLsizei start
,
437 GLsizei count
, GLenum format
, GLenum type
,
440 GET_CURRENT_CONTEXT(ctx
);
441 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
442 struct gl_texture_object
*texObj
= NULL
;
443 struct gl_color_table
*table
= NULL
;
446 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glColorSubTable");
450 texObj
= texUnit
->CurrentD
[1];
451 table
= &texObj
->Palette
;
454 texObj
= texUnit
->CurrentD
[2];
455 table
= &texObj
->Palette
;
458 texObj
= texUnit
->CurrentD
[3];
459 table
= &texObj
->Palette
;
461 case GL_SHARED_TEXTURE_PALETTE_EXT
:
462 table
= &ctx
->Texture
.Palette
;
465 table
= &ctx
->ColorTable
;
467 case GL_POST_CONVOLUTION_COLOR_TABLE
:
468 table
= &ctx
->PostConvolutionColorTable
;
470 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
471 table
= &ctx
->PostColorMatrixColorTable
;
474 gl_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
480 if (!_mesa_is_legal_format_and_type(format
, type
)) {
481 gl_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(format or type)");
486 gl_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
490 comps
= _mesa_components_in_format(table
->Format
);
491 assert(comps
> 0); /* error should have been caught sooner */
493 if (start
+ count
> table
->Size
) {
494 gl_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
499 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glColorSubTable");
503 if (table
->TableType
== GL_UNSIGNED_BYTE
) {
504 GLubyte
*dest
= (GLubyte
*) table
->Table
+ start
* comps
* sizeof(GLubyte
);
505 _mesa_unpack_ubyte_color_span(ctx
, count
, table
->Format
, dest
,
506 format
, type
, data
, &ctx
->Unpack
, GL_TRUE
);
509 GLfloat
*dest
= (GLfloat
*) table
->Table
+ start
* comps
* sizeof(GLfloat
);
510 ASSERT(table
->TableType
== GL_FLOAT
);
511 _mesa_unpack_float_color_span(ctx
, count
, table
->Format
, dest
,
512 format
, type
, data
, &ctx
->Unpack
,
516 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
517 /* per-texture object palette */
518 if (ctx
->Driver
.UpdateTexturePalette
) {
519 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
528 _mesa_CopyColorTable(GLenum target
, GLenum internalformat
,
529 GLint x
, GLint y
, GLsizei width
)
531 GLubyte data
[MAX_WIDTH
][4];
532 GET_CURRENT_CONTEXT(ctx
);
533 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glCopyColorTable");
535 /* Select buffer to read from */
536 (*ctx
->Driver
.SetReadBuffer
)( ctx
, ctx
->ReadBuffer
,
537 ctx
->Pixel
.DriverReadBuffer
);
539 if (width
> MAX_WIDTH
)
542 /* read the data from framebuffer */
543 gl_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
, data
);
545 /* Restore reading from draw buffer (the default) */
546 (*ctx
->Driver
.SetReadBuffer
)( ctx
, ctx
->DrawBuffer
,
547 ctx
->Color
.DriverDrawBuffer
);
549 _mesa_ColorTable(target
, internalformat
, width
,
550 GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
557 _mesa_CopyColorSubTable(GLenum target
, GLsizei start
,
558 GLint x
, GLint y
, GLsizei width
)
560 GLubyte data
[MAX_WIDTH
][4];
561 GET_CURRENT_CONTEXT(ctx
);
562 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glCopyColorSubTable");
564 /* Select buffer to read from */
565 (*ctx
->Driver
.SetReadBuffer
)( ctx
, ctx
->ReadBuffer
,
566 ctx
->Pixel
.DriverReadBuffer
);
568 if (width
> MAX_WIDTH
)
571 /* read the data from framebuffer */
572 gl_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
, data
);
574 /* Restore reading from draw buffer (the default) */
575 (*ctx
->Driver
.SetReadBuffer
)( ctx
, ctx
->DrawBuffer
,
576 ctx
->Color
.DriverDrawBuffer
);
578 _mesa_ColorSubTable(target
, start
, width
, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
584 _mesa_GetColorTable( GLenum target
, GLenum format
,
585 GLenum type
, GLvoid
*data
)
587 GET_CURRENT_CONTEXT(ctx
);
588 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
589 struct gl_color_table
*table
= NULL
;
590 GLubyte rgba
[MAX_COLOR_TABLE_SIZE
][4];
593 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetColorTable");
597 table
= &texUnit
->CurrentD
[1]->Palette
;
600 table
= &texUnit
->CurrentD
[2]->Palette
;
603 table
= &texUnit
->CurrentD
[3]->Palette
;
605 case GL_SHARED_TEXTURE_PALETTE_EXT
:
606 table
= &ctx
->Texture
.Palette
;
609 table
= &ctx
->ColorTable
;
611 case GL_POST_CONVOLUTION_COLOR_TABLE
:
612 table
= &ctx
->PostConvolutionColorTable
;
614 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
615 table
= &ctx
->PostColorMatrixColorTable
;
618 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
624 switch (table
->Format
) {
626 if (table
->TableType
== GL_FLOAT
) {
627 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
628 for (i
= 0; i
< table
->Size
; i
++) {
632 rgba
[i
][ACOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
636 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
637 for (i
= 0; i
< table
->Size
; i
++) {
641 rgba
[i
][ACOMP
] = tableUB
[i
];
646 if (table
->TableType
== GL_FLOAT
) {
647 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
648 for (i
= 0; i
< table
->Size
; i
++) {
649 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
650 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
651 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
652 rgba
[i
][ACOMP
] = 255;
656 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
657 for (i
= 0; i
< table
->Size
; i
++) {
658 rgba
[i
][RCOMP
] = tableUB
[i
];
659 rgba
[i
][GCOMP
] = tableUB
[i
];
660 rgba
[i
][BCOMP
] = tableUB
[i
];
661 rgba
[i
][ACOMP
] = 255;
665 case GL_LUMINANCE_ALPHA
:
666 if (table
->TableType
== GL_FLOAT
) {
667 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
668 for (i
= 0; i
< table
->Size
; i
++) {
669 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
*2+0] * 255.0F
);
670 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
*2+0] * 255.0F
);
671 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
*2+0] * 255.0F
);
672 rgba
[i
][ACOMP
] = (GLint
) (tableF
[i
*2+1] * 255.0F
);
676 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
677 for (i
= 0; i
< table
->Size
; i
++) {
678 rgba
[i
][RCOMP
] = tableUB
[i
*2+0];
679 rgba
[i
][GCOMP
] = tableUB
[i
*2+0];
680 rgba
[i
][BCOMP
] = tableUB
[i
*2+0];
681 rgba
[i
][ACOMP
] = tableUB
[i
*2+1];
686 if (table
->TableType
== GL_FLOAT
) {
687 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
688 for (i
= 0; i
< table
->Size
; i
++) {
689 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
690 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
691 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
692 rgba
[i
][ACOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
696 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
697 for (i
= 0; i
< table
->Size
; i
++) {
698 rgba
[i
][RCOMP
] = tableUB
[i
];
699 rgba
[i
][GCOMP
] = tableUB
[i
];
700 rgba
[i
][BCOMP
] = tableUB
[i
];
701 rgba
[i
][ACOMP
] = tableUB
[i
];
706 if (table
->TableType
== GL_FLOAT
) {
707 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
708 for (i
= 0; i
< table
->Size
; i
++) {
709 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
*3+0] * 255.0F
);
710 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
*3+1] * 255.0F
);
711 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
*3+2] * 255.0F
);
712 rgba
[i
][ACOMP
] = 255;
716 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
717 for (i
= 0; i
< table
->Size
; i
++) {
718 rgba
[i
][RCOMP
] = tableUB
[i
*3+0];
719 rgba
[i
][GCOMP
] = tableUB
[i
*3+1];
720 rgba
[i
][BCOMP
] = tableUB
[i
*3+2];
721 rgba
[i
][ACOMP
] = 255;
726 if (table
->TableType
== GL_FLOAT
) {
727 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
728 for (i
= 0; i
< table
->Size
; i
++) {
729 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
*4+0] * 255.0F
);
730 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
*4+1] * 255.0F
);
731 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
*4+2] * 255.0F
);
732 rgba
[i
][ACOMP
] = (GLint
) (tableF
[i
*4+3] * 255.0F
);
736 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
737 for (i
= 0; i
< table
->Size
; i
++) {
738 rgba
[i
][RCOMP
] = tableUB
[i
*4+0];
739 rgba
[i
][GCOMP
] = tableUB
[i
*4+1];
740 rgba
[i
][BCOMP
] = tableUB
[i
*4+2];
741 rgba
[i
][ACOMP
] = tableUB
[i
*4+3];
746 gl_problem(ctx
, "bad table format in glGetColorTable");
750 _mesa_pack_rgba_span(ctx
, table
->Size
, (const GLubyte (*)[]) rgba
,
751 format
, type
, data
, &ctx
->Pack
, GL_FALSE
);
757 _mesa_ColorTableParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
759 GET_CURRENT_CONTEXT(ctx
);
760 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glColorTableParameterfv");
763 case GL_COLOR_TABLE_SGI
:
764 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
765 ctx
->Pixel
.ColorTableScale
[0] = params
[0];
766 ctx
->Pixel
.ColorTableScale
[1] = params
[1];
767 ctx
->Pixel
.ColorTableScale
[2] = params
[2];
768 ctx
->Pixel
.ColorTableScale
[3] = params
[3];
770 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
771 ctx
->Pixel
.ColorTableBias
[0] = params
[0];
772 ctx
->Pixel
.ColorTableBias
[1] = params
[1];
773 ctx
->Pixel
.ColorTableBias
[2] = params
[2];
774 ctx
->Pixel
.ColorTableBias
[3] = params
[3];
777 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
781 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI
:
782 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
783 ctx
->Pixel
.PCCTscale
[0] = params
[0];
784 ctx
->Pixel
.PCCTscale
[1] = params
[1];
785 ctx
->Pixel
.PCCTscale
[2] = params
[2];
786 ctx
->Pixel
.PCCTscale
[3] = params
[3];
788 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
789 ctx
->Pixel
.PCCTbias
[0] = params
[0];
790 ctx
->Pixel
.PCCTbias
[1] = params
[1];
791 ctx
->Pixel
.PCCTbias
[2] = params
[2];
792 ctx
->Pixel
.PCCTbias
[3] = params
[3];
795 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
799 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
:
800 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
801 ctx
->Pixel
.PCMCTscale
[0] = params
[0];
802 ctx
->Pixel
.PCMCTscale
[1] = params
[1];
803 ctx
->Pixel
.PCMCTscale
[2] = params
[2];
804 ctx
->Pixel
.PCMCTscale
[3] = params
[3];
806 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
807 ctx
->Pixel
.PCMCTbias
[0] = params
[0];
808 ctx
->Pixel
.PCMCTbias
[1] = params
[1];
809 ctx
->Pixel
.PCMCTbias
[2] = params
[2];
810 ctx
->Pixel
.PCMCTbias
[3] = params
[3];
813 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
818 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameter(target)");
826 _mesa_ColorTableParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
829 if (pname
== GL_COLOR_TABLE_SGI
||
830 pname
== GL_POST_CONVOLUTION_COLOR_TABLE_SGI
||
831 pname
== GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
) {
833 fparams
[0] = (GLfloat
) params
[0];
834 fparams
[1] = (GLfloat
) params
[1];
835 fparams
[2] = (GLfloat
) params
[2];
836 fparams
[3] = (GLfloat
) params
[3];
840 fparams
[0] = (GLfloat
) params
[0];
842 _mesa_ColorTableParameterfv(target
, pname
, fparams
);
848 _mesa_GetColorTableParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
850 GET_CURRENT_CONTEXT(ctx
);
851 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
852 struct gl_color_table
*table
= NULL
;
854 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetColorTableParameterfv");
858 table
= &texUnit
->CurrentD
[1]->Palette
;
861 table
= &texUnit
->CurrentD
[2]->Palette
;
864 table
= &texUnit
->CurrentD
[3]->Palette
;
866 case GL_PROXY_TEXTURE_1D
:
867 table
= &ctx
->Texture
.Proxy1D
->Palette
;
869 case GL_PROXY_TEXTURE_2D
:
870 table
= &ctx
->Texture
.Proxy2D
->Palette
;
872 case GL_PROXY_TEXTURE_3D
:
873 table
= &ctx
->Texture
.Proxy3D
->Palette
;
875 case GL_SHARED_TEXTURE_PALETTE_EXT
:
876 table
= &ctx
->Texture
.Palette
;
879 table
= &ctx
->ColorTable
;
880 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
881 params
[0] = ctx
->Pixel
.ColorTableScale
[0];
882 params
[1] = ctx
->Pixel
.ColorTableScale
[1];
883 params
[2] = ctx
->Pixel
.ColorTableScale
[2];
884 params
[3] = ctx
->Pixel
.ColorTableScale
[3];
887 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
888 params
[0] = ctx
->Pixel
.ColorTableBias
[0];
889 params
[1] = ctx
->Pixel
.ColorTableBias
[1];
890 params
[2] = ctx
->Pixel
.ColorTableBias
[2];
891 params
[3] = ctx
->Pixel
.ColorTableBias
[3];
895 case GL_PROXY_COLOR_TABLE
:
896 table
= &ctx
->ProxyColorTable
;
898 case GL_POST_CONVOLUTION_COLOR_TABLE
:
899 table
= &ctx
->PostConvolutionColorTable
;
900 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
901 params
[0] = ctx
->Pixel
.PCCTscale
[0];
902 params
[1] = ctx
->Pixel
.PCCTscale
[1];
903 params
[2] = ctx
->Pixel
.PCCTscale
[2];
904 params
[3] = ctx
->Pixel
.PCCTscale
[3];
907 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
908 params
[0] = ctx
->Pixel
.PCCTbias
[0];
909 params
[1] = ctx
->Pixel
.PCCTbias
[1];
910 params
[2] = ctx
->Pixel
.PCCTbias
[2];
911 params
[3] = ctx
->Pixel
.PCCTbias
[3];
915 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
916 table
= &ctx
->ProxyPostConvolutionColorTable
;
918 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
919 table
= &ctx
->PostColorMatrixColorTable
;
920 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
921 params
[0] = ctx
->Pixel
.PCMCTscale
[0];
922 params
[1] = ctx
->Pixel
.PCMCTscale
[1];
923 params
[2] = ctx
->Pixel
.PCMCTscale
[2];
924 params
[3] = ctx
->Pixel
.PCMCTscale
[3];
927 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
928 params
[0] = ctx
->Pixel
.PCMCTbias
[0];
929 params
[1] = ctx
->Pixel
.PCMCTbias
[1];
930 params
[2] = ctx
->Pixel
.PCMCTbias
[2];
931 params
[3] = ctx
->Pixel
.PCMCTbias
[3];
935 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
936 table
= &ctx
->ProxyPostColorMatrixColorTable
;
939 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(target)");
946 case GL_COLOR_TABLE_FORMAT
:
947 *params
= table
->IntFormat
;
949 case GL_COLOR_TABLE_WIDTH
:
950 *params
= table
->Size
;
952 case GL_COLOR_TABLE_RED_SIZE
:
953 *params
= table
->RedSize
;
955 case GL_COLOR_TABLE_GREEN_SIZE
:
956 *params
= table
->GreenSize
;
958 case GL_COLOR_TABLE_BLUE_SIZE
:
959 *params
= table
->BlueSize
;
961 case GL_COLOR_TABLE_ALPHA_SIZE
:
962 *params
= table
->AlphaSize
;
964 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
965 *params
= table
->LuminanceSize
;
967 case GL_COLOR_TABLE_INTENSITY_SIZE
:
968 *params
= table
->IntensitySize
;
971 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(pname)" );
979 _mesa_GetColorTableParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
981 GET_CURRENT_CONTEXT(ctx
);
982 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
983 struct gl_color_table
*table
= NULL
;
985 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetColorTableParameteriv");
989 table
= &texUnit
->CurrentD
[1]->Palette
;
992 table
= &texUnit
->CurrentD
[2]->Palette
;
995 table
= &texUnit
->CurrentD
[3]->Palette
;
997 case GL_PROXY_TEXTURE_1D
:
998 table
= &ctx
->Texture
.Proxy1D
->Palette
;
1000 case GL_PROXY_TEXTURE_2D
:
1001 table
= &ctx
->Texture
.Proxy2D
->Palette
;
1003 case GL_PROXY_TEXTURE_3D
:
1004 table
= &ctx
->Texture
.Proxy3D
->Palette
;
1006 case GL_SHARED_TEXTURE_PALETTE_EXT
:
1007 table
= &ctx
->Texture
.Palette
;
1009 case GL_COLOR_TABLE
:
1010 table
= &ctx
->ColorTable
;
1011 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1012 params
[0] = (GLint
) ctx
->Pixel
.ColorTableScale
[0];
1013 params
[1] = (GLint
) ctx
->Pixel
.ColorTableScale
[1];
1014 params
[2] = (GLint
) ctx
->Pixel
.ColorTableScale
[2];
1015 params
[3] = (GLint
) ctx
->Pixel
.ColorTableScale
[3];
1018 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1019 params
[0] = (GLint
) ctx
->Pixel
.ColorTableBias
[0];
1020 params
[1] = (GLint
) ctx
->Pixel
.ColorTableBias
[1];
1021 params
[2] = (GLint
) ctx
->Pixel
.ColorTableBias
[2];
1022 params
[3] = (GLint
) ctx
->Pixel
.ColorTableBias
[3];
1026 case GL_PROXY_COLOR_TABLE
:
1027 table
= &ctx
->ProxyColorTable
;
1029 case GL_POST_CONVOLUTION_COLOR_TABLE
:
1030 table
= &ctx
->PostConvolutionColorTable
;
1031 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1032 params
[0] = (GLint
) ctx
->Pixel
.PCCTscale
[0];
1033 params
[1] = (GLint
) ctx
->Pixel
.PCCTscale
[1];
1034 params
[2] = (GLint
) ctx
->Pixel
.PCCTscale
[2];
1035 params
[3] = (GLint
) ctx
->Pixel
.PCCTscale
[3];
1038 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1039 params
[0] = (GLint
) ctx
->Pixel
.PCCTbias
[0];
1040 params
[1] = (GLint
) ctx
->Pixel
.PCCTbias
[1];
1041 params
[2] = (GLint
) ctx
->Pixel
.PCCTbias
[2];
1042 params
[3] = (GLint
) ctx
->Pixel
.PCCTbias
[3];
1046 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
1047 table
= &ctx
->ProxyPostConvolutionColorTable
;
1049 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
1050 table
= &ctx
->PostColorMatrixColorTable
;
1051 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1052 params
[0] = (GLint
) ctx
->Pixel
.PCMCTscale
[0];
1053 params
[1] = (GLint
) ctx
->Pixel
.PCMCTscale
[1];
1054 params
[2] = (GLint
) ctx
->Pixel
.PCMCTscale
[2];
1055 params
[3] = (GLint
) ctx
->Pixel
.PCMCTscale
[3];
1058 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1059 params
[0] = (GLint
) ctx
->Pixel
.PCMCTbias
[0];
1060 params
[1] = (GLint
) ctx
->Pixel
.PCMCTbias
[1];
1061 params
[2] = (GLint
) ctx
->Pixel
.PCMCTbias
[2];
1062 params
[3] = (GLint
) ctx
->Pixel
.PCMCTbias
[3];
1066 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
1067 table
= &ctx
->ProxyPostColorMatrixColorTable
;
1070 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(target)");
1077 case GL_COLOR_TABLE_FORMAT
:
1078 *params
= table
->IntFormat
;
1080 case GL_COLOR_TABLE_WIDTH
:
1081 *params
= table
->Size
;
1083 case GL_COLOR_TABLE_RED_SIZE
:
1084 *params
= table
->RedSize
;
1086 case GL_COLOR_TABLE_GREEN_SIZE
:
1087 *params
= table
->GreenSize
;
1089 case GL_COLOR_TABLE_BLUE_SIZE
:
1090 *params
= table
->BlueSize
;
1092 case GL_COLOR_TABLE_ALPHA_SIZE
:
1093 *params
= table
->AlphaSize
;
1095 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1096 *params
= table
->LuminanceSize
;
1098 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1099 *params
= table
->IntensitySize
;
1102 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(pname)" );