1 /* $Id: colortab.c,v 1.19 2000/06/27 15:47:59 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 format
== GL_INTENSITY
) {
306 gl_error(ctx
, GL_INVALID_ENUM
, "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
< 1 || width
> ctx
->Const
.MaxColorTableSize
317 || _mesa_bitcount(width
) != 1) {
318 if (width
> ctx
->Const
.MaxColorTableSize
)
319 gl_error(ctx
, GL_TABLE_TOO_LARGE
, "glColorTable(width)");
321 gl_error(ctx
, GL_INVALID_VALUE
, "glColorTable(width)");
324 table
->IntFormat
= (GLenum
) 0;
325 table
->Format
= (GLenum
) 0;
331 table
->IntFormat
= internalFormat
;
332 table
->Format
= (GLenum
) baseFormat
;
333 set_component_sizes(table
);
335 comps
= _mesa_components_in_format(table
->Format
);
336 assert(comps
> 0); /* error should have been caught sooner */
339 /* free old table, if any */
344 GLubyte tableUB
[MAX_COLOR_TABLE_SIZE
* 4];
348 _mesa_unpack_ubyte_color_span(ctx
, width
, table
->Format
,
351 &ctx
->Unpack
, GL_TRUE
);
353 table
->TableType
= GL_FLOAT
;
354 table
->Table
= MALLOC(comps
* width
* sizeof(GLfloat
));
356 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
360 /* Apply scale and bias and convert GLubyte values to GLfloats
361 * in [0, 1]. Store results in the tableF[].
367 tableF
= (GLfloat
*) table
->Table
;
369 switch (table
->Format
) {
371 for (i
= 0; i
< width
; i
++) {
372 tableF
[i
] = tableUB
[i
] * rScale
+ rBias
;
376 for (i
= 0; i
< width
; i
++) {
377 tableF
[i
] = tableUB
[i
] * rScale
+ rBias
;
381 for (i
= 0; i
< width
; i
++) {
382 tableF
[i
] = tableUB
[i
] * aScale
+ aBias
;
385 case GL_LUMINANCE_ALPHA
:
386 for (i
= 0; i
< width
; i
++) {
387 tableF
[i
*2+0] = tableUB
[i
*2+0] * rScale
+ rBias
;
388 tableF
[i
*2+1] = tableUB
[i
*2+1] * aScale
+ aBias
;
392 for (i
= 0; i
< width
; i
++) {
393 tableF
[i
*3+0] = tableUB
[i
*3+0] * rScale
+ rBias
;
394 tableF
[i
*3+1] = tableUB
[i
*3+1] * gScale
+ gBias
;
395 tableF
[i
*3+2] = tableUB
[i
*3+2] * bScale
+ bBias
;
399 for (i
= 0; i
< width
; i
++) {
400 tableF
[i
*4+0] = tableUB
[i
*4+0] * rScale
+ rBias
;
401 tableF
[i
*4+1] = tableUB
[i
*4+1] * gScale
+ gBias
;
402 tableF
[i
*4+2] = tableUB
[i
*4+2] * bScale
+ bBias
;
403 tableF
[i
*4+3] = tableUB
[i
*4+3] * aScale
+ aBias
;
407 gl_problem(ctx
, "Bad format in _mesa_ColorTable");
412 /* store GLubyte table */
413 table
->TableType
= GL_UNSIGNED_BYTE
;
414 table
->Table
= MALLOC(comps
* width
* sizeof(GLubyte
));
416 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
419 _mesa_unpack_ubyte_color_span(ctx
, width
, table
->Format
,
420 table
->Table
, /* dest */
422 &ctx
->Unpack
, GL_TRUE
);
426 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
427 /* texture object palette, texObj==NULL means the shared palette */
428 if (ctx
->Driver
.UpdateTexturePalette
) {
429 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
437 _mesa_ColorSubTable( GLenum target
, GLsizei start
,
438 GLsizei count
, GLenum format
, GLenum type
,
441 GET_CURRENT_CONTEXT(ctx
);
442 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
443 struct gl_texture_object
*texObj
= NULL
;
444 struct gl_color_table
*table
= NULL
;
447 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glColorSubTable");
451 texObj
= texUnit
->CurrentD
[1];
452 table
= &texObj
->Palette
;
455 texObj
= texUnit
->CurrentD
[2];
456 table
= &texObj
->Palette
;
459 texObj
= texUnit
->CurrentD
[3];
460 table
= &texObj
->Palette
;
462 case GL_SHARED_TEXTURE_PALETTE_EXT
:
463 table
= &ctx
->Texture
.Palette
;
466 table
= &ctx
->ColorTable
;
468 case GL_POST_CONVOLUTION_COLOR_TABLE
:
469 table
= &ctx
->PostConvolutionColorTable
;
471 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
472 table
= &ctx
->PostColorMatrixColorTable
;
475 gl_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
481 if (!_mesa_is_legal_format_and_type(format
, type
) ||
482 format
== GL_INTENSITY
) {
483 gl_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(format or type)");
488 gl_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
492 comps
= _mesa_components_in_format(table
->Format
);
493 assert(comps
> 0); /* error should have been caught sooner */
495 if (start
+ count
> table
->Size
) {
496 gl_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
501 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glColorSubTable");
505 if (table
->TableType
== GL_UNSIGNED_BYTE
) {
506 GLubyte
*dest
= (GLubyte
*) table
->Table
+ start
* comps
* sizeof(GLubyte
);
507 _mesa_unpack_ubyte_color_span(ctx
, count
, table
->Format
, dest
,
508 format
, type
, data
, &ctx
->Unpack
, GL_TRUE
);
511 GLfloat
*dest
= (GLfloat
*) table
->Table
+ start
* comps
* sizeof(GLfloat
);
512 ASSERT(table
->TableType
== GL_FLOAT
);
513 _mesa_unpack_float_color_span(ctx
, count
, table
->Format
, dest
,
514 format
, type
, data
, &ctx
->Unpack
,
518 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
519 /* per-texture object palette */
520 if (ctx
->Driver
.UpdateTexturePalette
) {
521 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
530 _mesa_CopyColorTable(GLenum target
, GLenum internalformat
,
531 GLint x
, GLint y
, GLsizei width
)
533 GLubyte data
[MAX_WIDTH
][4];
534 GET_CURRENT_CONTEXT(ctx
);
535 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glCopyColorTable");
537 /* Select buffer to read from */
538 (*ctx
->Driver
.SetReadBuffer
)( ctx
, ctx
->ReadBuffer
,
539 ctx
->Pixel
.DriverReadBuffer
);
541 if (width
> MAX_WIDTH
)
544 /* read the data from framebuffer */
545 gl_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
, data
);
547 /* Restore reading from draw buffer (the default) */
548 (*ctx
->Driver
.SetReadBuffer
)( ctx
, ctx
->DrawBuffer
,
549 ctx
->Color
.DriverDrawBuffer
);
551 _mesa_ColorTable(target
, internalformat
, width
,
552 GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
559 _mesa_CopyColorSubTable(GLenum target
, GLsizei start
,
560 GLint x
, GLint y
, GLsizei width
)
562 GLubyte data
[MAX_WIDTH
][4];
563 GET_CURRENT_CONTEXT(ctx
);
564 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glCopyColorSubTable");
566 /* Select buffer to read from */
567 (*ctx
->Driver
.SetReadBuffer
)( ctx
, ctx
->ReadBuffer
,
568 ctx
->Pixel
.DriverReadBuffer
);
570 if (width
> MAX_WIDTH
)
573 /* read the data from framebuffer */
574 gl_read_rgba_span( ctx
, ctx
->ReadBuffer
, width
, x
, y
, data
);
576 /* Restore reading from draw buffer (the default) */
577 (*ctx
->Driver
.SetReadBuffer
)( ctx
, ctx
->DrawBuffer
,
578 ctx
->Color
.DriverDrawBuffer
);
580 _mesa_ColorSubTable(target
, start
, width
, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
586 _mesa_GetColorTable( GLenum target
, GLenum format
,
587 GLenum type
, GLvoid
*data
)
589 GET_CURRENT_CONTEXT(ctx
);
590 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
591 struct gl_color_table
*table
= NULL
;
592 GLubyte rgba
[MAX_COLOR_TABLE_SIZE
][4];
595 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetColorTable");
599 table
= &texUnit
->CurrentD
[1]->Palette
;
602 table
= &texUnit
->CurrentD
[2]->Palette
;
605 table
= &texUnit
->CurrentD
[3]->Palette
;
607 case GL_SHARED_TEXTURE_PALETTE_EXT
:
608 table
= &ctx
->Texture
.Palette
;
611 table
= &ctx
->ColorTable
;
613 case GL_POST_CONVOLUTION_COLOR_TABLE
:
614 table
= &ctx
->PostConvolutionColorTable
;
616 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
617 table
= &ctx
->PostColorMatrixColorTable
;
620 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
626 switch (table
->Format
) {
628 if (table
->TableType
== GL_FLOAT
) {
629 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
630 for (i
= 0; i
< table
->Size
; i
++) {
634 rgba
[i
][ACOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
638 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
639 for (i
= 0; i
< table
->Size
; i
++) {
643 rgba
[i
][ACOMP
] = tableUB
[i
];
648 if (table
->TableType
== GL_FLOAT
) {
649 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
650 for (i
= 0; i
< table
->Size
; i
++) {
651 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
652 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
653 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
654 rgba
[i
][ACOMP
] = 255;
658 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
659 for (i
= 0; i
< table
->Size
; i
++) {
660 rgba
[i
][RCOMP
] = tableUB
[i
];
661 rgba
[i
][GCOMP
] = tableUB
[i
];
662 rgba
[i
][BCOMP
] = tableUB
[i
];
663 rgba
[i
][ACOMP
] = 255;
667 case GL_LUMINANCE_ALPHA
:
668 if (table
->TableType
== GL_FLOAT
) {
669 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
670 for (i
= 0; i
< table
->Size
; i
++) {
671 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
*2+0] * 255.0F
);
672 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
*2+0] * 255.0F
);
673 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
*2+0] * 255.0F
);
674 rgba
[i
][ACOMP
] = (GLint
) (tableF
[i
*2+1] * 255.0F
);
678 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
679 for (i
= 0; i
< table
->Size
; i
++) {
680 rgba
[i
][RCOMP
] = tableUB
[i
*2+0];
681 rgba
[i
][GCOMP
] = tableUB
[i
*2+0];
682 rgba
[i
][BCOMP
] = tableUB
[i
*2+0];
683 rgba
[i
][ACOMP
] = tableUB
[i
*2+1];
688 if (table
->TableType
== GL_FLOAT
) {
689 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
690 for (i
= 0; i
< table
->Size
; i
++) {
691 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
692 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
693 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
694 rgba
[i
][ACOMP
] = (GLint
) (tableF
[i
] * 255.0F
);
698 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
699 for (i
= 0; i
< table
->Size
; i
++) {
700 rgba
[i
][RCOMP
] = tableUB
[i
];
701 rgba
[i
][GCOMP
] = tableUB
[i
];
702 rgba
[i
][BCOMP
] = tableUB
[i
];
703 rgba
[i
][ACOMP
] = tableUB
[i
];
708 if (table
->TableType
== GL_FLOAT
) {
709 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
710 for (i
= 0; i
< table
->Size
; i
++) {
711 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
*3+0] * 255.0F
);
712 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
*3+1] * 255.0F
);
713 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
*3+2] * 255.0F
);
714 rgba
[i
][ACOMP
] = 255;
718 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
719 for (i
= 0; i
< table
->Size
; i
++) {
720 rgba
[i
][RCOMP
] = tableUB
[i
*3+0];
721 rgba
[i
][GCOMP
] = tableUB
[i
*3+1];
722 rgba
[i
][BCOMP
] = tableUB
[i
*3+2];
723 rgba
[i
][ACOMP
] = 255;
728 if (table
->TableType
== GL_FLOAT
) {
729 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
730 for (i
= 0; i
< table
->Size
; i
++) {
731 rgba
[i
][RCOMP
] = (GLint
) (tableF
[i
*4+0] * 255.0F
);
732 rgba
[i
][GCOMP
] = (GLint
) (tableF
[i
*4+1] * 255.0F
);
733 rgba
[i
][BCOMP
] = (GLint
) (tableF
[i
*4+2] * 255.0F
);
734 rgba
[i
][ACOMP
] = (GLint
) (tableF
[i
*4+3] * 255.0F
);
738 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
739 for (i
= 0; i
< table
->Size
; i
++) {
740 rgba
[i
][RCOMP
] = tableUB
[i
*4+0];
741 rgba
[i
][GCOMP
] = tableUB
[i
*4+1];
742 rgba
[i
][BCOMP
] = tableUB
[i
*4+2];
743 rgba
[i
][ACOMP
] = tableUB
[i
*4+3];
748 gl_problem(ctx
, "bad table format in glGetColorTable");
752 _mesa_pack_rgba_span(ctx
, table
->Size
, (const GLubyte (*)[]) rgba
,
753 format
, type
, data
, &ctx
->Pack
, GL_FALSE
);
759 _mesa_ColorTableParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
761 GET_CURRENT_CONTEXT(ctx
);
762 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glColorTableParameterfv");
765 case GL_COLOR_TABLE_SGI
:
766 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
767 ctx
->Pixel
.ColorTableScale
[0] = params
[0];
768 ctx
->Pixel
.ColorTableScale
[1] = params
[1];
769 ctx
->Pixel
.ColorTableScale
[2] = params
[2];
770 ctx
->Pixel
.ColorTableScale
[3] = params
[3];
772 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
773 ctx
->Pixel
.ColorTableBias
[0] = params
[0];
774 ctx
->Pixel
.ColorTableBias
[1] = params
[1];
775 ctx
->Pixel
.ColorTableBias
[2] = params
[2];
776 ctx
->Pixel
.ColorTableBias
[3] = params
[3];
779 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
783 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI
:
784 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
785 ctx
->Pixel
.PCCTscale
[0] = params
[0];
786 ctx
->Pixel
.PCCTscale
[1] = params
[1];
787 ctx
->Pixel
.PCCTscale
[2] = params
[2];
788 ctx
->Pixel
.PCCTscale
[3] = params
[3];
790 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
791 ctx
->Pixel
.PCCTbias
[0] = params
[0];
792 ctx
->Pixel
.PCCTbias
[1] = params
[1];
793 ctx
->Pixel
.PCCTbias
[2] = params
[2];
794 ctx
->Pixel
.PCCTbias
[3] = params
[3];
797 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
801 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
:
802 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
803 ctx
->Pixel
.PCMCTscale
[0] = params
[0];
804 ctx
->Pixel
.PCMCTscale
[1] = params
[1];
805 ctx
->Pixel
.PCMCTscale
[2] = params
[2];
806 ctx
->Pixel
.PCMCTscale
[3] = params
[3];
808 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
809 ctx
->Pixel
.PCMCTbias
[0] = params
[0];
810 ctx
->Pixel
.PCMCTbias
[1] = params
[1];
811 ctx
->Pixel
.PCMCTbias
[2] = params
[2];
812 ctx
->Pixel
.PCMCTbias
[3] = params
[3];
815 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
820 gl_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameter(target)");
828 _mesa_ColorTableParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
831 if (pname
== GL_COLOR_TABLE_SGI
||
832 pname
== GL_POST_CONVOLUTION_COLOR_TABLE_SGI
||
833 pname
== GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
) {
835 fparams
[0] = (GLfloat
) params
[0];
836 fparams
[1] = (GLfloat
) params
[1];
837 fparams
[2] = (GLfloat
) params
[2];
838 fparams
[3] = (GLfloat
) params
[3];
842 fparams
[0] = (GLfloat
) params
[0];
844 _mesa_ColorTableParameterfv(target
, pname
, fparams
);
850 _mesa_GetColorTableParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
852 GET_CURRENT_CONTEXT(ctx
);
853 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
854 struct gl_color_table
*table
= NULL
;
856 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetColorTableParameterfv");
860 table
= &texUnit
->CurrentD
[1]->Palette
;
863 table
= &texUnit
->CurrentD
[2]->Palette
;
866 table
= &texUnit
->CurrentD
[3]->Palette
;
868 case GL_PROXY_TEXTURE_1D
:
869 table
= &ctx
->Texture
.Proxy1D
->Palette
;
871 case GL_PROXY_TEXTURE_2D
:
872 table
= &ctx
->Texture
.Proxy2D
->Palette
;
874 case GL_PROXY_TEXTURE_3D
:
875 table
= &ctx
->Texture
.Proxy3D
->Palette
;
877 case GL_SHARED_TEXTURE_PALETTE_EXT
:
878 table
= &ctx
->Texture
.Palette
;
881 table
= &ctx
->ColorTable
;
882 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
883 params
[0] = ctx
->Pixel
.ColorTableScale
[0];
884 params
[1] = ctx
->Pixel
.ColorTableScale
[1];
885 params
[2] = ctx
->Pixel
.ColorTableScale
[2];
886 params
[3] = ctx
->Pixel
.ColorTableScale
[3];
889 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
890 params
[0] = ctx
->Pixel
.ColorTableBias
[0];
891 params
[1] = ctx
->Pixel
.ColorTableBias
[1];
892 params
[2] = ctx
->Pixel
.ColorTableBias
[2];
893 params
[3] = ctx
->Pixel
.ColorTableBias
[3];
897 case GL_PROXY_COLOR_TABLE
:
898 table
= &ctx
->ProxyColorTable
;
900 case GL_POST_CONVOLUTION_COLOR_TABLE
:
901 table
= &ctx
->PostConvolutionColorTable
;
902 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
903 params
[0] = ctx
->Pixel
.PCCTscale
[0];
904 params
[1] = ctx
->Pixel
.PCCTscale
[1];
905 params
[2] = ctx
->Pixel
.PCCTscale
[2];
906 params
[3] = ctx
->Pixel
.PCCTscale
[3];
909 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
910 params
[0] = ctx
->Pixel
.PCCTbias
[0];
911 params
[1] = ctx
->Pixel
.PCCTbias
[1];
912 params
[2] = ctx
->Pixel
.PCCTbias
[2];
913 params
[3] = ctx
->Pixel
.PCCTbias
[3];
917 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
918 table
= &ctx
->ProxyPostConvolutionColorTable
;
920 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
921 table
= &ctx
->PostColorMatrixColorTable
;
922 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
923 params
[0] = ctx
->Pixel
.PCMCTscale
[0];
924 params
[1] = ctx
->Pixel
.PCMCTscale
[1];
925 params
[2] = ctx
->Pixel
.PCMCTscale
[2];
926 params
[3] = ctx
->Pixel
.PCMCTscale
[3];
929 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
930 params
[0] = ctx
->Pixel
.PCMCTbias
[0];
931 params
[1] = ctx
->Pixel
.PCMCTbias
[1];
932 params
[2] = ctx
->Pixel
.PCMCTbias
[2];
933 params
[3] = ctx
->Pixel
.PCMCTbias
[3];
937 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
938 table
= &ctx
->ProxyPostColorMatrixColorTable
;
941 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(target)");
948 case GL_COLOR_TABLE_FORMAT
:
949 *params
= table
->IntFormat
;
951 case GL_COLOR_TABLE_WIDTH
:
952 *params
= table
->Size
;
954 case GL_COLOR_TABLE_RED_SIZE
:
955 *params
= table
->RedSize
;
957 case GL_COLOR_TABLE_GREEN_SIZE
:
958 *params
= table
->GreenSize
;
960 case GL_COLOR_TABLE_BLUE_SIZE
:
961 *params
= table
->BlueSize
;
963 case GL_COLOR_TABLE_ALPHA_SIZE
:
964 *params
= table
->AlphaSize
;
966 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
967 *params
= table
->LuminanceSize
;
969 case GL_COLOR_TABLE_INTENSITY_SIZE
:
970 *params
= table
->IntensitySize
;
973 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(pname)" );
981 _mesa_GetColorTableParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
983 GET_CURRENT_CONTEXT(ctx
);
984 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
985 struct gl_color_table
*table
= NULL
;
987 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetColorTableParameteriv");
991 table
= &texUnit
->CurrentD
[1]->Palette
;
994 table
= &texUnit
->CurrentD
[2]->Palette
;
997 table
= &texUnit
->CurrentD
[3]->Palette
;
999 case GL_PROXY_TEXTURE_1D
:
1000 table
= &ctx
->Texture
.Proxy1D
->Palette
;
1002 case GL_PROXY_TEXTURE_2D
:
1003 table
= &ctx
->Texture
.Proxy2D
->Palette
;
1005 case GL_PROXY_TEXTURE_3D
:
1006 table
= &ctx
->Texture
.Proxy3D
->Palette
;
1008 case GL_SHARED_TEXTURE_PALETTE_EXT
:
1009 table
= &ctx
->Texture
.Palette
;
1011 case GL_COLOR_TABLE
:
1012 table
= &ctx
->ColorTable
;
1013 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1014 params
[0] = (GLint
) ctx
->Pixel
.ColorTableScale
[0];
1015 params
[1] = (GLint
) ctx
->Pixel
.ColorTableScale
[1];
1016 params
[2] = (GLint
) ctx
->Pixel
.ColorTableScale
[2];
1017 params
[3] = (GLint
) ctx
->Pixel
.ColorTableScale
[3];
1020 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1021 params
[0] = (GLint
) ctx
->Pixel
.ColorTableBias
[0];
1022 params
[1] = (GLint
) ctx
->Pixel
.ColorTableBias
[1];
1023 params
[2] = (GLint
) ctx
->Pixel
.ColorTableBias
[2];
1024 params
[3] = (GLint
) ctx
->Pixel
.ColorTableBias
[3];
1028 case GL_PROXY_COLOR_TABLE
:
1029 table
= &ctx
->ProxyColorTable
;
1031 case GL_POST_CONVOLUTION_COLOR_TABLE
:
1032 table
= &ctx
->PostConvolutionColorTable
;
1033 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1034 params
[0] = (GLint
) ctx
->Pixel
.PCCTscale
[0];
1035 params
[1] = (GLint
) ctx
->Pixel
.PCCTscale
[1];
1036 params
[2] = (GLint
) ctx
->Pixel
.PCCTscale
[2];
1037 params
[3] = (GLint
) ctx
->Pixel
.PCCTscale
[3];
1040 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1041 params
[0] = (GLint
) ctx
->Pixel
.PCCTbias
[0];
1042 params
[1] = (GLint
) ctx
->Pixel
.PCCTbias
[1];
1043 params
[2] = (GLint
) ctx
->Pixel
.PCCTbias
[2];
1044 params
[3] = (GLint
) ctx
->Pixel
.PCCTbias
[3];
1048 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
1049 table
= &ctx
->ProxyPostConvolutionColorTable
;
1051 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
1052 table
= &ctx
->PostColorMatrixColorTable
;
1053 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1054 params
[0] = (GLint
) ctx
->Pixel
.PCMCTscale
[0];
1055 params
[1] = (GLint
) ctx
->Pixel
.PCMCTscale
[1];
1056 params
[2] = (GLint
) ctx
->Pixel
.PCMCTscale
[2];
1057 params
[3] = (GLint
) ctx
->Pixel
.PCMCTscale
[3];
1060 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1061 params
[0] = (GLint
) ctx
->Pixel
.PCMCTbias
[0];
1062 params
[1] = (GLint
) ctx
->Pixel
.PCMCTbias
[1];
1063 params
[2] = (GLint
) ctx
->Pixel
.PCMCTbias
[2];
1064 params
[3] = (GLint
) ctx
->Pixel
.PCMCTbias
[3];
1068 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
1069 table
= &ctx
->ProxyPostColorMatrixColorTable
;
1072 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(target)");
1079 case GL_COLOR_TABLE_FORMAT
:
1080 *params
= table
->IntFormat
;
1082 case GL_COLOR_TABLE_WIDTH
:
1083 *params
= table
->Size
;
1085 case GL_COLOR_TABLE_RED_SIZE
:
1086 *params
= table
->RedSize
;
1088 case GL_COLOR_TABLE_GREEN_SIZE
:
1089 *params
= table
->GreenSize
;
1091 case GL_COLOR_TABLE_BLUE_SIZE
:
1092 *params
= table
->BlueSize
;
1094 case GL_COLOR_TABLE_ALPHA_SIZE
:
1095 *params
= table
->AlphaSize
;
1097 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1098 *params
= table
->LuminanceSize
;
1100 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1101 *params
= table
->IntensitySize
;
1104 gl_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(pname)" );