0a785743c06d1542400423257180005e04354a2b
[mesa.git] / src / mesa / main / colortab.c
1 /* $Id: colortab.c,v 1.49 2003/03/01 01:50:20 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 5.1
6 *
7 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28 #include "glheader.h"
29 #include "imports.h"
30 #include "colortab.h"
31 #include "context.h"
32 #include "image.h"
33 #include "macros.h"
34 #include "state.h"
35
36
37 /*
38 * Given an internalFormat token passed to glColorTable,
39 * return the corresponding base format.
40 * Return -1 if invalid token.
41 */
42 static GLint
43 base_colortab_format( GLenum format )
44 {
45 switch (format) {
46 case GL_ALPHA:
47 case GL_ALPHA4:
48 case GL_ALPHA8:
49 case GL_ALPHA12:
50 case GL_ALPHA16:
51 return GL_ALPHA;
52 case GL_LUMINANCE:
53 case GL_LUMINANCE4:
54 case GL_LUMINANCE8:
55 case GL_LUMINANCE12:
56 case GL_LUMINANCE16:
57 return GL_LUMINANCE;
58 case GL_LUMINANCE_ALPHA:
59 case GL_LUMINANCE4_ALPHA4:
60 case GL_LUMINANCE6_ALPHA2:
61 case GL_LUMINANCE8_ALPHA8:
62 case GL_LUMINANCE12_ALPHA4:
63 case GL_LUMINANCE12_ALPHA12:
64 case GL_LUMINANCE16_ALPHA16:
65 return GL_LUMINANCE_ALPHA;
66 case GL_INTENSITY:
67 case GL_INTENSITY4:
68 case GL_INTENSITY8:
69 case GL_INTENSITY12:
70 case GL_INTENSITY16:
71 return GL_INTENSITY;
72 case GL_RGB:
73 case GL_R3_G3_B2:
74 case GL_RGB4:
75 case GL_RGB5:
76 case GL_RGB8:
77 case GL_RGB10:
78 case GL_RGB12:
79 case GL_RGB16:
80 return GL_RGB;
81 case GL_RGBA:
82 case GL_RGBA2:
83 case GL_RGBA4:
84 case GL_RGB5_A1:
85 case GL_RGBA8:
86 case GL_RGB10_A2:
87 case GL_RGBA12:
88 case GL_RGBA16:
89 return GL_RGBA;
90 default:
91 return -1; /* error */
92 }
93 }
94
95
96 void
97 _mesa_init_colortable( struct gl_color_table *p )
98 {
99 p->FloatTable = GL_FALSE;
100 p->Table = NULL;
101 p->Size = 0;
102 p->IntFormat = GL_RGBA;
103 }
104
105
106
107 void
108 _mesa_free_colortable_data( struct gl_color_table *p )
109 {
110 if (p->Table) {
111 FREE(p->Table);
112 p->Table = NULL;
113 }
114 }
115
116
117 /*
118 * Examine table's format and set the component sizes accordingly.
119 */
120 static void
121 set_component_sizes( struct gl_color_table *table )
122 {
123 switch (table->Format) {
124 case GL_ALPHA:
125 table->RedSize = 0;
126 table->GreenSize = 0;
127 table->BlueSize = 0;
128 table->AlphaSize = CHAN_BITS;
129 table->IntensitySize = 0;
130 table->LuminanceSize = 0;
131 break;
132 case GL_LUMINANCE:
133 table->RedSize = 0;
134 table->GreenSize = 0;
135 table->BlueSize = 0;
136 table->AlphaSize = 0;
137 table->IntensitySize = 0;
138 table->LuminanceSize = CHAN_BITS;
139 break;
140 case GL_LUMINANCE_ALPHA:
141 table->RedSize = 0;
142 table->GreenSize = 0;
143 table->BlueSize = 0;
144 table->AlphaSize = CHAN_BITS;
145 table->IntensitySize = 0;
146 table->LuminanceSize = CHAN_BITS;
147 break;
148 case GL_INTENSITY:
149 table->RedSize = 0;
150 table->GreenSize = 0;
151 table->BlueSize = 0;
152 table->AlphaSize = 0;
153 table->IntensitySize = CHAN_BITS;
154 table->LuminanceSize = 0;
155 break;
156 case GL_RGB:
157 table->RedSize = CHAN_BITS;
158 table->GreenSize = CHAN_BITS;
159 table->BlueSize = CHAN_BITS;
160 table->AlphaSize = 0;
161 table->IntensitySize = 0;
162 table->LuminanceSize = 0;
163 break;
164 case GL_RGBA:
165 table->RedSize = CHAN_BITS;
166 table->GreenSize = CHAN_BITS;
167 table->BlueSize = CHAN_BITS;
168 table->AlphaSize = CHAN_BITS;
169 table->IntensitySize = 0;
170 table->LuminanceSize = 0;
171 break;
172 default:
173 _mesa_problem(NULL, "unexpected format in set_component_sizes");
174 }
175 }
176
177
178
179 void
180 _mesa_ColorTable( GLenum target, GLenum internalFormat,
181 GLsizei width, GLenum format, GLenum type,
182 const GLvoid *data )
183 {
184 GET_CURRENT_CONTEXT(ctx);
185 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
186 struct gl_texture_object *texObj = NULL;
187 struct gl_color_table *table = NULL;
188 GLboolean proxy = GL_FALSE;
189 GLint baseFormat;
190 GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0;
191 GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0;
192 GLboolean floatTable = GL_FALSE;
193 GLint comps;
194 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */
195
196 switch (target) {
197 case GL_TEXTURE_1D:
198 texObj = texUnit->Current1D;
199 table = &texObj->Palette;
200 break;
201 case GL_TEXTURE_2D:
202 texObj = texUnit->Current2D;
203 table = &texObj->Palette;
204 break;
205 case GL_TEXTURE_3D:
206 texObj = texUnit->Current3D;
207 table = &texObj->Palette;
208 break;
209 case GL_TEXTURE_CUBE_MAP_ARB:
210 if (!ctx->Extensions.ARB_texture_cube_map) {
211 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
212 return;
213 }
214 texObj = texUnit->CurrentCubeMap;
215 table = &texObj->Palette;
216 break;
217 case GL_PROXY_TEXTURE_1D:
218 texObj = ctx->Texture.Proxy1D;
219 table = &texObj->Palette;
220 proxy = GL_TRUE;
221 break;
222 case GL_PROXY_TEXTURE_2D:
223 texObj = ctx->Texture.Proxy2D;
224 table = &texObj->Palette;
225 proxy = GL_TRUE;
226 break;
227 case GL_PROXY_TEXTURE_3D:
228 texObj = ctx->Texture.Proxy3D;
229 table = &texObj->Palette;
230 proxy = GL_TRUE;
231 break;
232 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
233 if (!ctx->Extensions.ARB_texture_cube_map) {
234 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
235 return;
236 }
237 texObj = ctx->Texture.ProxyCubeMap;
238 table = &texObj->Palette;
239 break;
240 case GL_SHARED_TEXTURE_PALETTE_EXT:
241 table = &ctx->Texture.Palette;
242 break;
243 case GL_COLOR_TABLE:
244 table = &ctx->ColorTable;
245 floatTable = GL_TRUE;
246 rScale = ctx->Pixel.ColorTableScale[0];
247 gScale = ctx->Pixel.ColorTableScale[1];
248 bScale = ctx->Pixel.ColorTableScale[2];
249 aScale = ctx->Pixel.ColorTableScale[3];
250 rBias = ctx->Pixel.ColorTableBias[0];
251 gBias = ctx->Pixel.ColorTableBias[1];
252 bBias = ctx->Pixel.ColorTableBias[2];
253 aBias = ctx->Pixel.ColorTableBias[3];
254 break;
255 case GL_PROXY_COLOR_TABLE:
256 table = &ctx->ProxyColorTable;
257 proxy = GL_TRUE;
258 break;
259 case GL_TEXTURE_COLOR_TABLE_SGI:
260 if (!ctx->Extensions.SGI_texture_color_table) {
261 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
262 return;
263 }
264 table = &(texUnit->ColorTable);
265 floatTable = GL_TRUE;
266 rScale = ctx->Pixel.TextureColorTableScale[0];
267 gScale = ctx->Pixel.TextureColorTableScale[1];
268 bScale = ctx->Pixel.TextureColorTableScale[2];
269 aScale = ctx->Pixel.TextureColorTableScale[3];
270 rBias = ctx->Pixel.TextureColorTableBias[0];
271 gBias = ctx->Pixel.TextureColorTableBias[1];
272 bBias = ctx->Pixel.TextureColorTableBias[2];
273 aBias = ctx->Pixel.TextureColorTableBias[3];
274 break;
275 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
276 if (!ctx->Extensions.SGI_texture_color_table) {
277 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
278 return;
279 }
280 table = &(texUnit->ProxyColorTable);
281 proxy = GL_TRUE;
282 break;
283 case GL_POST_CONVOLUTION_COLOR_TABLE:
284 table = &ctx->PostConvolutionColorTable;
285 floatTable = GL_TRUE;
286 rScale = ctx->Pixel.PCCTscale[0];
287 gScale = ctx->Pixel.PCCTscale[1];
288 bScale = ctx->Pixel.PCCTscale[2];
289 aScale = ctx->Pixel.PCCTscale[3];
290 rBias = ctx->Pixel.PCCTbias[0];
291 gBias = ctx->Pixel.PCCTbias[1];
292 bBias = ctx->Pixel.PCCTbias[2];
293 aBias = ctx->Pixel.PCCTbias[3];
294 break;
295 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
296 table = &ctx->ProxyPostConvolutionColorTable;
297 proxy = GL_TRUE;
298 break;
299 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
300 table = &ctx->PostColorMatrixColorTable;
301 floatTable = GL_TRUE;
302 rScale = ctx->Pixel.PCMCTscale[0];
303 gScale = ctx->Pixel.PCMCTscale[1];
304 bScale = ctx->Pixel.PCMCTscale[2];
305 aScale = ctx->Pixel.PCMCTscale[3];
306 rBias = ctx->Pixel.PCMCTbias[0];
307 gBias = ctx->Pixel.PCMCTbias[1];
308 bBias = ctx->Pixel.PCMCTbias[2];
309 aBias = ctx->Pixel.PCMCTbias[3];
310 break;
311 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
312 table = &ctx->ProxyPostColorMatrixColorTable;
313 proxy = GL_TRUE;
314 break;
315 default:
316 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
317 return;
318 }
319
320 assert(table);
321
322 if (!_mesa_is_legal_format_and_type(format, type) ||
323 format == GL_INTENSITY) {
324 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)");
325 return;
326 }
327
328 baseFormat = base_colortab_format(internalFormat);
329 if (baseFormat < 0 || baseFormat == GL_COLOR_INDEX) {
330 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)");
331 return;
332 }
333
334 if (width < 0 || (width != 0 && _mesa_bitcount(width) != 1)) {
335 /* error */
336 if (proxy) {
337 table->Size = 0;
338 table->IntFormat = (GLenum) 0;
339 table->Format = (GLenum) 0;
340 }
341 else {
342 _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width);
343 }
344 return;
345 }
346
347 if (width > (GLsizei) ctx->Const.MaxColorTableSize) {
348 if (proxy) {
349 table->Size = 0;
350 table->IntFormat = (GLenum) 0;
351 table->Format = (GLenum) 0;
352 }
353 else {
354 _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)");
355 }
356 return;
357 }
358
359 table->Size = width;
360 table->IntFormat = internalFormat;
361 table->Format = (GLenum) baseFormat;
362 set_component_sizes(table);
363
364 comps = _mesa_components_in_format(table->Format);
365 assert(comps > 0); /* error should have been caught sooner */
366
367 if (!proxy) {
368 /* free old table, if any */
369 if (table->Table) {
370 FREE(table->Table);
371 table->Table = NULL;
372 }
373 if (width > 0) {
374 if (floatTable) {
375 GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4];
376 GLfloat *tableF;
377 GLint i;
378
379 _mesa_unpack_float_color_span(ctx, width, table->Format,
380 tempTab, /* dest */
381 format, type, data, &ctx->Unpack,
382 0, GL_FALSE);
383
384 table->FloatTable = GL_TRUE;
385 table->Table = MALLOC(comps * width * sizeof(GLfloat));
386 if (!table->Table) {
387 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
388 return;
389 }
390
391 tableF = (GLfloat *) table->Table;
392
393 switch (table->Format) {
394 case GL_INTENSITY:
395 for (i = 0; i < width; i++) {
396 tableF[i] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
397 }
398 break;
399 case GL_LUMINANCE:
400 for (i = 0; i < width; i++) {
401 tableF[i] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
402 }
403 break;
404 case GL_ALPHA:
405 for (i = 0; i < width; i++) {
406 tableF[i] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F);
407 }
408 break;
409 case GL_LUMINANCE_ALPHA:
410 for (i = 0; i < width; i++) {
411 tableF[i*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F);
412 tableF[i*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F);
413 }
414 break;
415 case GL_RGB:
416 for (i = 0; i < width; i++) {
417 tableF[i*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F);
418 tableF[i*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F);
419 tableF[i*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F);
420 }
421 break;
422 case GL_RGBA:
423 for (i = 0; i < width; i++) {
424 tableF[i*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F);
425 tableF[i*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F);
426 tableF[i*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F);
427 tableF[i*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F);
428 }
429 break;
430 default:
431 _mesa_problem(ctx, "Bad format in _mesa_ColorTable");
432 return;
433 }
434 }
435 else {
436 /* store GLchan table */
437 table->FloatTable = GL_FALSE;
438 table->Table = MALLOC(comps * width * sizeof(GLchan));
439 if (!table->Table) {
440 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
441 return;
442 }
443 _mesa_unpack_chan_color_span(ctx, width, table->Format,
444 (GLchan *) table->Table, /* dest */
445 format, type, data,
446 &ctx->Unpack, 0);
447 } /* floatTable */
448 } /* width > 0 */
449 } /* proxy */
450
451 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
452 /* texture object palette, texObj==NULL means the shared palette */
453 if (ctx->Driver.UpdateTexturePalette) {
454 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
455 }
456 }
457
458 ctx->NewState |= _NEW_PIXEL;
459 }
460
461
462
463 void
464 _mesa_ColorSubTable( GLenum target, GLsizei start,
465 GLsizei count, GLenum format, GLenum type,
466 const GLvoid *data )
467 {
468 GET_CURRENT_CONTEXT(ctx);
469 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
470 struct gl_texture_object *texObj = NULL;
471 struct gl_color_table *table = NULL;
472 GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0;
473 GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0;
474 GLint comps;
475 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
476
477 switch (target) {
478 case GL_TEXTURE_1D:
479 texObj = texUnit->Current1D;
480 table = &texObj->Palette;
481 break;
482 case GL_TEXTURE_2D:
483 texObj = texUnit->Current2D;
484 table = &texObj->Palette;
485 break;
486 case GL_TEXTURE_3D:
487 texObj = texUnit->Current3D;
488 table = &texObj->Palette;
489 break;
490 case GL_TEXTURE_CUBE_MAP_ARB:
491 if (!ctx->Extensions.ARB_texture_cube_map) {
492 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
493 return;
494 }
495 texObj = texUnit->CurrentCubeMap;
496 table = &texObj->Palette;
497 break;
498 case GL_SHARED_TEXTURE_PALETTE_EXT:
499 table = &ctx->Texture.Palette;
500 break;
501 case GL_COLOR_TABLE:
502 table = &ctx->ColorTable;
503 rScale = ctx->Pixel.ColorTableScale[0];
504 gScale = ctx->Pixel.ColorTableScale[1];
505 bScale = ctx->Pixel.ColorTableScale[2];
506 aScale = ctx->Pixel.ColorTableScale[3];
507 rBias = ctx->Pixel.ColorTableBias[0];
508 gBias = ctx->Pixel.ColorTableBias[1];
509 bBias = ctx->Pixel.ColorTableBias[2];
510 aBias = ctx->Pixel.ColorTableBias[3];
511 break;
512 case GL_TEXTURE_COLOR_TABLE_SGI:
513 if (!ctx->Extensions.SGI_texture_color_table) {
514 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
515 return;
516 }
517 table = &(texUnit->ColorTable);
518 rScale = ctx->Pixel.TextureColorTableScale[0];
519 gScale = ctx->Pixel.TextureColorTableScale[1];
520 bScale = ctx->Pixel.TextureColorTableScale[2];
521 aScale = ctx->Pixel.TextureColorTableScale[3];
522 rBias = ctx->Pixel.TextureColorTableBias[0];
523 gBias = ctx->Pixel.TextureColorTableBias[1];
524 bBias = ctx->Pixel.TextureColorTableBias[2];
525 aBias = ctx->Pixel.TextureColorTableBias[3];
526 break;
527 case GL_POST_CONVOLUTION_COLOR_TABLE:
528 table = &ctx->PostConvolutionColorTable;
529 rScale = ctx->Pixel.PCCTscale[0];
530 gScale = ctx->Pixel.PCCTscale[1];
531 bScale = ctx->Pixel.PCCTscale[2];
532 aScale = ctx->Pixel.PCCTscale[3];
533 rBias = ctx->Pixel.PCCTbias[0];
534 gBias = ctx->Pixel.PCCTbias[1];
535 bBias = ctx->Pixel.PCCTbias[2];
536 aBias = ctx->Pixel.PCCTbias[3];
537 break;
538 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
539 table = &ctx->PostColorMatrixColorTable;
540 rScale = ctx->Pixel.PCMCTscale[0];
541 gScale = ctx->Pixel.PCMCTscale[1];
542 bScale = ctx->Pixel.PCMCTscale[2];
543 aScale = ctx->Pixel.PCMCTscale[3];
544 rBias = ctx->Pixel.PCMCTbias[0];
545 gBias = ctx->Pixel.PCMCTbias[1];
546 bBias = ctx->Pixel.PCMCTbias[2];
547 aBias = ctx->Pixel.PCMCTbias[3];
548 break;
549 default:
550 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
551 return;
552 }
553
554 assert(table);
555
556 if (!_mesa_is_legal_format_and_type(format, type) ||
557 format == GL_INTENSITY) {
558 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorSubTable(format or type)");
559 return;
560 }
561
562 if (count < 1) {
563 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
564 return;
565 }
566
567 comps = _mesa_components_in_format(table->Format);
568 assert(comps > 0); /* error should have been caught sooner */
569
570 if (start + count > (GLint) table->Size) {
571 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
572 return;
573 }
574
575 if (!table->Table) {
576 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorSubTable");
577 return;
578 }
579
580 if (!table->FloatTable) {
581 GLchan *dest = (GLchan *) table->Table + start * comps * sizeof(GLchan);
582 _mesa_unpack_chan_color_span(ctx, count, table->Format, dest,
583 format, type, data, &ctx->Unpack, 0);
584 }
585 else {
586 GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4];
587 GLfloat *tableF;
588 GLint i;
589
590 ASSERT(table->FloatTable);
591
592 _mesa_unpack_float_color_span(ctx, count, table->Format,
593 tempTab, /* dest */
594 format, type, data, &ctx->Unpack,
595 0, GL_FALSE);
596
597 tableF = (GLfloat *) table->Table;
598
599 switch (table->Format) {
600 case GL_INTENSITY:
601 for (i = 0; i < count; i++) {
602 GLuint j = start + i;
603 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
604 }
605 break;
606 case GL_LUMINANCE:
607 for (i = 0; i < count; i++) {
608 GLuint j = start + i;
609 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
610 }
611 break;
612 case GL_ALPHA:
613 for (i = 0; i < count; i++) {
614 GLuint j = start + i;
615 tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F);
616 }
617 break;
618 case GL_LUMINANCE_ALPHA:
619 for (i = 0; i < count; i++) {
620 GLuint j = start + i;
621 tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F);
622 tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F);
623 }
624 break;
625 case GL_RGB:
626 for (i = 0; i < count; i++) {
627 GLuint j = start + i;
628 tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F);
629 tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F);
630 tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F);
631 }
632 break;
633 case GL_RGBA:
634 for (i = 0; i < count; i++) {
635 GLuint j = start + i;
636 tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F);
637 tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F);
638 tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F);
639 tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F);
640 }
641 break;
642 default:
643 _mesa_problem(ctx, "Bad format in _mesa_ColorSubTable");
644 return;
645 }
646 }
647
648 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
649 /* per-texture object palette */
650 if (ctx->Driver.UpdateTexturePalette) {
651 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
652 }
653 }
654
655 ctx->NewState |= _NEW_PIXEL;
656 }
657
658
659
660 /* XXX not tested */
661 void
662 _mesa_CopyColorTable(GLenum target, GLenum internalformat,
663 GLint x, GLint y, GLsizei width)
664 {
665 GET_CURRENT_CONTEXT(ctx);
666 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
667
668 /* Select buffer to read from */
669 ctx->Driver.CopyColorTable( ctx, target, internalformat, x, y, width );
670 }
671
672
673
674 /* XXX not tested */
675 void
676 _mesa_CopyColorSubTable(GLenum target, GLsizei start,
677 GLint x, GLint y, GLsizei width)
678 {
679 GET_CURRENT_CONTEXT(ctx);
680 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
681
682 ctx->Driver.CopyColorSubTable( ctx, target, start, x, y, width );
683 }
684
685
686
687 void
688 _mesa_GetColorTable( GLenum target, GLenum format,
689 GLenum type, GLvoid *data )
690 {
691 GET_CURRENT_CONTEXT(ctx);
692 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
693 struct gl_color_table *table = NULL;
694 GLchan rgba[MAX_COLOR_TABLE_SIZE][4];
695 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
696
697 if (ctx->NewState) {
698 _mesa_update_state(ctx);
699 }
700
701 switch (target) {
702 case GL_TEXTURE_1D:
703 table = &texUnit->Current1D->Palette;
704 break;
705 case GL_TEXTURE_2D:
706 table = &texUnit->Current2D->Palette;
707 break;
708 case GL_TEXTURE_3D:
709 table = &texUnit->Current3D->Palette;
710 break;
711 case GL_TEXTURE_CUBE_MAP_ARB:
712 if (!ctx->Extensions.ARB_texture_cube_map) {
713 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
714 return;
715 }
716 table = &texUnit->CurrentCubeMap->Palette;
717 break;
718 case GL_SHARED_TEXTURE_PALETTE_EXT:
719 table = &ctx->Texture.Palette;
720 break;
721 case GL_COLOR_TABLE:
722 table = &ctx->ColorTable;
723 break;
724 case GL_TEXTURE_COLOR_TABLE_SGI:
725 if (!ctx->Extensions.SGI_texture_color_table) {
726 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
727 return;
728 }
729 table = &(texUnit->ColorTable);
730 break;
731 case GL_POST_CONVOLUTION_COLOR_TABLE:
732 table = &ctx->PostConvolutionColorTable;
733 break;
734 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
735 table = &ctx->PostColorMatrixColorTable;
736 break;
737 default:
738 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
739 return;
740 }
741
742 assert(table);
743
744 switch (table->Format) {
745 case GL_ALPHA:
746 if (table->FloatTable) {
747 const GLfloat *tableF = (const GLfloat *) table->Table;
748 GLuint i;
749 for (i = 0; i < table->Size; i++) {
750 rgba[i][RCOMP] = 0;
751 rgba[i][GCOMP] = 0;
752 rgba[i][BCOMP] = 0;
753 rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
754 }
755 }
756 else {
757 const GLchan *tableUB = (const GLchan *) table->Table;
758 GLuint i;
759 for (i = 0; i < table->Size; i++) {
760 rgba[i][RCOMP] = 0;
761 rgba[i][GCOMP] = 0;
762 rgba[i][BCOMP] = 0;
763 rgba[i][ACOMP] = tableUB[i];
764 }
765 }
766 break;
767 case GL_LUMINANCE:
768 if (table->FloatTable) {
769 const GLfloat *tableF = (const GLfloat *) table->Table;
770 GLuint i;
771 for (i = 0; i < table->Size; i++) {
772 rgba[i][RCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
773 rgba[i][GCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
774 rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
775 rgba[i][ACOMP] = CHAN_MAX;
776 }
777 }
778 else {
779 const GLchan *tableUB = (const GLchan *) table->Table;
780 GLuint i;
781 for (i = 0; i < table->Size; i++) {
782 rgba[i][RCOMP] = tableUB[i];
783 rgba[i][GCOMP] = tableUB[i];
784 rgba[i][BCOMP] = tableUB[i];
785 rgba[i][ACOMP] = CHAN_MAX;
786 }
787 }
788 break;
789 case GL_LUMINANCE_ALPHA:
790 if (table->FloatTable) {
791 const GLfloat *tableF = (const GLfloat *) table->Table;
792 GLuint i;
793 for (i = 0; i < table->Size; i++) {
794 rgba[i][RCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
795 rgba[i][GCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
796 rgba[i][BCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
797 rgba[i][ACOMP] = IROUND_POS(tableF[i*2+1] * CHAN_MAXF);
798 }
799 }
800 else {
801 const GLchan *tableUB = (const GLchan *) table->Table;
802 GLuint i;
803 for (i = 0; i < table->Size; i++) {
804 rgba[i][RCOMP] = tableUB[i*2+0];
805 rgba[i][GCOMP] = tableUB[i*2+0];
806 rgba[i][BCOMP] = tableUB[i*2+0];
807 rgba[i][ACOMP] = tableUB[i*2+1];
808 }
809 }
810 break;
811 case GL_INTENSITY:
812 if (table->FloatTable) {
813 const GLfloat *tableF = (const GLfloat *) table->Table;
814 GLuint i;
815 for (i = 0; i < table->Size; i++) {
816 rgba[i][RCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
817 rgba[i][GCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
818 rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
819 rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
820 }
821 }
822 else {
823 const GLchan *tableUB = (const GLchan *) table->Table;
824 GLuint i;
825 for (i = 0; i < table->Size; i++) {
826 rgba[i][RCOMP] = tableUB[i];
827 rgba[i][GCOMP] = tableUB[i];
828 rgba[i][BCOMP] = tableUB[i];
829 rgba[i][ACOMP] = tableUB[i];
830 }
831 }
832 break;
833 case GL_RGB:
834 if (table->FloatTable) {
835 const GLfloat *tableF = (const GLfloat *) table->Table;
836 GLuint i;
837 for (i = 0; i < table->Size; i++) {
838 rgba[i][RCOMP] = IROUND_POS(tableF[i*3+0] * CHAN_MAXF);
839 rgba[i][GCOMP] = IROUND_POS(tableF[i*3+1] * CHAN_MAXF);
840 rgba[i][BCOMP] = IROUND_POS(tableF[i*3+2] * CHAN_MAXF);
841 rgba[i][ACOMP] = CHAN_MAX;
842 }
843 }
844 else {
845 const GLchan *tableUB = (const GLchan *) table->Table;
846 GLuint i;
847 for (i = 0; i < table->Size; i++) {
848 rgba[i][RCOMP] = tableUB[i*3+0];
849 rgba[i][GCOMP] = tableUB[i*3+1];
850 rgba[i][BCOMP] = tableUB[i*3+2];
851 rgba[i][ACOMP] = CHAN_MAX;
852 }
853 }
854 break;
855 case GL_RGBA:
856 if (table->FloatTable) {
857 const GLfloat *tableF = (const GLfloat *) table->Table;
858 GLuint i;
859 for (i = 0; i < table->Size; i++) {
860 rgba[i][RCOMP] = IROUND_POS(tableF[i*4+0] * CHAN_MAXF);
861 rgba[i][GCOMP] = IROUND_POS(tableF[i*4+1] * CHAN_MAXF);
862 rgba[i][BCOMP] = IROUND_POS(tableF[i*4+2] * CHAN_MAXF);
863 rgba[i][ACOMP] = IROUND_POS(tableF[i*4+3] * CHAN_MAXF);
864 }
865 }
866 else {
867 const GLchan *tableUB = (const GLchan *) table->Table;
868 GLuint i;
869 for (i = 0; i < table->Size; i++) {
870 rgba[i][RCOMP] = tableUB[i*4+0];
871 rgba[i][GCOMP] = tableUB[i*4+1];
872 rgba[i][BCOMP] = tableUB[i*4+2];
873 rgba[i][ACOMP] = tableUB[i*4+3];
874 }
875 }
876 break;
877 default:
878 _mesa_problem(ctx, "bad table format in glGetColorTable");
879 return;
880 }
881
882 _mesa_pack_rgba_span(ctx, table->Size, (const GLchan (*)[4]) rgba,
883 format, type, data, &ctx->Pack, GL_FALSE);
884 }
885
886
887
888 void
889 _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
890 {
891 GET_CURRENT_CONTEXT(ctx);
892 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
893
894 switch (target) {
895 case GL_COLOR_TABLE_SGI:
896 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
897 ctx->Pixel.ColorTableScale[0] = params[0];
898 ctx->Pixel.ColorTableScale[1] = params[1];
899 ctx->Pixel.ColorTableScale[2] = params[2];
900 ctx->Pixel.ColorTableScale[3] = params[3];
901 }
902 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
903 ctx->Pixel.ColorTableBias[0] = params[0];
904 ctx->Pixel.ColorTableBias[1] = params[1];
905 ctx->Pixel.ColorTableBias[2] = params[2];
906 ctx->Pixel.ColorTableBias[3] = params[3];
907 }
908 else {
909 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
910 return;
911 }
912 break;
913 case GL_TEXTURE_COLOR_TABLE_SGI:
914 if (!ctx->Extensions.SGI_texture_color_table) {
915 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
916 return;
917 }
918 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
919 ctx->Pixel.TextureColorTableScale[0] = params[0];
920 ctx->Pixel.TextureColorTableScale[1] = params[1];
921 ctx->Pixel.TextureColorTableScale[2] = params[2];
922 ctx->Pixel.TextureColorTableScale[3] = params[3];
923 }
924 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
925 ctx->Pixel.TextureColorTableBias[0] = params[0];
926 ctx->Pixel.TextureColorTableBias[1] = params[1];
927 ctx->Pixel.TextureColorTableBias[2] = params[2];
928 ctx->Pixel.TextureColorTableBias[3] = params[3];
929 }
930 else {
931 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
932 return;
933 }
934 break;
935 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
936 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
937 ctx->Pixel.PCCTscale[0] = params[0];
938 ctx->Pixel.PCCTscale[1] = params[1];
939 ctx->Pixel.PCCTscale[2] = params[2];
940 ctx->Pixel.PCCTscale[3] = params[3];
941 }
942 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
943 ctx->Pixel.PCCTbias[0] = params[0];
944 ctx->Pixel.PCCTbias[1] = params[1];
945 ctx->Pixel.PCCTbias[2] = params[2];
946 ctx->Pixel.PCCTbias[3] = params[3];
947 }
948 else {
949 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
950 return;
951 }
952 break;
953 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
954 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
955 ctx->Pixel.PCMCTscale[0] = params[0];
956 ctx->Pixel.PCMCTscale[1] = params[1];
957 ctx->Pixel.PCMCTscale[2] = params[2];
958 ctx->Pixel.PCMCTscale[3] = params[3];
959 }
960 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
961 ctx->Pixel.PCMCTbias[0] = params[0];
962 ctx->Pixel.PCMCTbias[1] = params[1];
963 ctx->Pixel.PCMCTbias[2] = params[2];
964 ctx->Pixel.PCMCTbias[3] = params[3];
965 }
966 else {
967 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
968 return;
969 }
970 break;
971 default:
972 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
973 return;
974 }
975
976 ctx->NewState |= _NEW_PIXEL;
977 }
978
979
980
981 void
982 _mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
983 {
984 GLfloat fparams[4];
985 if (pname == GL_COLOR_TABLE_SGI ||
986 pname == GL_TEXTURE_COLOR_TABLE_SGI ||
987 pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
988 pname == GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI) {
989 /* four values */
990 fparams[0] = (GLfloat) params[0];
991 fparams[1] = (GLfloat) params[1];
992 fparams[2] = (GLfloat) params[2];
993 fparams[3] = (GLfloat) params[3];
994 }
995 else {
996 /* one values */
997 fparams[0] = (GLfloat) params[0];
998 }
999 _mesa_ColorTableParameterfv(target, pname, fparams);
1000 }
1001
1002
1003
1004 void
1005 _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
1006 {
1007 GET_CURRENT_CONTEXT(ctx);
1008 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1009 struct gl_color_table *table = NULL;
1010 ASSERT_OUTSIDE_BEGIN_END(ctx);
1011
1012 switch (target) {
1013 case GL_TEXTURE_1D:
1014 table = &texUnit->Current1D->Palette;
1015 break;
1016 case GL_TEXTURE_2D:
1017 table = &texUnit->Current2D->Palette;
1018 break;
1019 case GL_TEXTURE_3D:
1020 table = &texUnit->Current3D->Palette;
1021 break;
1022 case GL_TEXTURE_CUBE_MAP_ARB:
1023 if (!ctx->Extensions.ARB_texture_cube_map) {
1024 _mesa_error(ctx, GL_INVALID_ENUM,
1025 "glGetColorTableParameterfv(target)");
1026 return;
1027 }
1028 table = &texUnit->CurrentCubeMap->Palette;
1029 break;
1030 case GL_PROXY_TEXTURE_1D:
1031 table = &ctx->Texture.Proxy1D->Palette;
1032 break;
1033 case GL_PROXY_TEXTURE_2D:
1034 table = &ctx->Texture.Proxy2D->Palette;
1035 break;
1036 case GL_PROXY_TEXTURE_3D:
1037 table = &ctx->Texture.Proxy3D->Palette;
1038 break;
1039 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1040 if (!ctx->Extensions.ARB_texture_cube_map) {
1041 _mesa_error(ctx, GL_INVALID_ENUM,
1042 "glGetColorTableParameterfv(target)");
1043 return;
1044 }
1045 table = &ctx->Texture.ProxyCubeMap->Palette;
1046 break;
1047 case GL_SHARED_TEXTURE_PALETTE_EXT:
1048 table = &ctx->Texture.Palette;
1049 break;
1050 case GL_COLOR_TABLE:
1051 table = &ctx->ColorTable;
1052 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1053 params[0] = ctx->Pixel.ColorTableScale[0];
1054 params[1] = ctx->Pixel.ColorTableScale[1];
1055 params[2] = ctx->Pixel.ColorTableScale[2];
1056 params[3] = ctx->Pixel.ColorTableScale[3];
1057 return;
1058 }
1059 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1060 params[0] = ctx->Pixel.ColorTableBias[0];
1061 params[1] = ctx->Pixel.ColorTableBias[1];
1062 params[2] = ctx->Pixel.ColorTableBias[2];
1063 params[3] = ctx->Pixel.ColorTableBias[3];
1064 return;
1065 }
1066 break;
1067 case GL_PROXY_COLOR_TABLE:
1068 table = &ctx->ProxyColorTable;
1069 break;
1070 case GL_TEXTURE_COLOR_TABLE_SGI:
1071 if (!ctx->Extensions.SGI_texture_color_table) {
1072 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1073 return;
1074 }
1075 table = &(texUnit->ColorTable);
1076 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1077 params[0] = ctx->Pixel.TextureColorTableScale[0];
1078 params[1] = ctx->Pixel.TextureColorTableScale[1];
1079 params[2] = ctx->Pixel.TextureColorTableScale[2];
1080 params[3] = ctx->Pixel.TextureColorTableScale[3];
1081 return;
1082 }
1083 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1084 params[0] = ctx->Pixel.TextureColorTableBias[0];
1085 params[1] = ctx->Pixel.TextureColorTableBias[1];
1086 params[2] = ctx->Pixel.TextureColorTableBias[2];
1087 params[3] = ctx->Pixel.TextureColorTableBias[3];
1088 return;
1089 }
1090 break;
1091 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
1092 if (!ctx->Extensions.SGI_texture_color_table) {
1093 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1094 return;
1095 }
1096 table = &(texUnit->ProxyColorTable);
1097 break;
1098 case GL_POST_CONVOLUTION_COLOR_TABLE:
1099 table = &ctx->PostConvolutionColorTable;
1100 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1101 params[0] = ctx->Pixel.PCCTscale[0];
1102 params[1] = ctx->Pixel.PCCTscale[1];
1103 params[2] = ctx->Pixel.PCCTscale[2];
1104 params[3] = ctx->Pixel.PCCTscale[3];
1105 return;
1106 }
1107 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1108 params[0] = ctx->Pixel.PCCTbias[0];
1109 params[1] = ctx->Pixel.PCCTbias[1];
1110 params[2] = ctx->Pixel.PCCTbias[2];
1111 params[3] = ctx->Pixel.PCCTbias[3];
1112 return;
1113 }
1114 break;
1115 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
1116 table = &ctx->ProxyPostConvolutionColorTable;
1117 break;
1118 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
1119 table = &ctx->PostColorMatrixColorTable;
1120 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1121 params[0] = ctx->Pixel.PCMCTscale[0];
1122 params[1] = ctx->Pixel.PCMCTscale[1];
1123 params[2] = ctx->Pixel.PCMCTscale[2];
1124 params[3] = ctx->Pixel.PCMCTscale[3];
1125 return;
1126 }
1127 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1128 params[0] = ctx->Pixel.PCMCTbias[0];
1129 params[1] = ctx->Pixel.PCMCTbias[1];
1130 params[2] = ctx->Pixel.PCMCTbias[2];
1131 params[3] = ctx->Pixel.PCMCTbias[3];
1132 return;
1133 }
1134 break;
1135 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
1136 table = &ctx->ProxyPostColorMatrixColorTable;
1137 break;
1138 default:
1139 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(target)");
1140 return;
1141 }
1142
1143 assert(table);
1144
1145 switch (pname) {
1146 case GL_COLOR_TABLE_FORMAT:
1147 *params = (GLfloat) table->IntFormat;
1148 break;
1149 case GL_COLOR_TABLE_WIDTH:
1150 *params = (GLfloat) table->Size;
1151 break;
1152 case GL_COLOR_TABLE_RED_SIZE:
1153 *params = (GLfloat) table->RedSize;
1154 break;
1155 case GL_COLOR_TABLE_GREEN_SIZE:
1156 *params = (GLfloat) table->GreenSize;
1157 break;
1158 case GL_COLOR_TABLE_BLUE_SIZE:
1159 *params = (GLfloat) table->BlueSize;
1160 break;
1161 case GL_COLOR_TABLE_ALPHA_SIZE:
1162 *params = (GLfloat) table->AlphaSize;
1163 break;
1164 case GL_COLOR_TABLE_LUMINANCE_SIZE:
1165 *params = (GLfloat) table->LuminanceSize;
1166 break;
1167 case GL_COLOR_TABLE_INTENSITY_SIZE:
1168 *params = (GLfloat) table->IntensitySize;
1169 break;
1170 default:
1171 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" );
1172 return;
1173 }
1174 }
1175
1176
1177
1178 void
1179 _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
1180 {
1181 GET_CURRENT_CONTEXT(ctx);
1182 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1183 struct gl_color_table *table = NULL;
1184 ASSERT_OUTSIDE_BEGIN_END(ctx);
1185
1186 switch (target) {
1187 case GL_TEXTURE_1D:
1188 table = &texUnit->Current1D->Palette;
1189 break;
1190 case GL_TEXTURE_2D:
1191 table = &texUnit->Current2D->Palette;
1192 break;
1193 case GL_TEXTURE_3D:
1194 table = &texUnit->Current3D->Palette;
1195 break;
1196 case GL_TEXTURE_CUBE_MAP_ARB:
1197 if (!ctx->Extensions.ARB_texture_cube_map) {
1198 _mesa_error(ctx, GL_INVALID_ENUM,
1199 "glGetColorTableParameteriv(target)");
1200 return;
1201 }
1202 table = &texUnit->CurrentCubeMap->Palette;
1203 break;
1204 case GL_PROXY_TEXTURE_1D:
1205 table = &ctx->Texture.Proxy1D->Palette;
1206 break;
1207 case GL_PROXY_TEXTURE_2D:
1208 table = &ctx->Texture.Proxy2D->Palette;
1209 break;
1210 case GL_PROXY_TEXTURE_3D:
1211 table = &ctx->Texture.Proxy3D->Palette;
1212 break;
1213 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1214 if (!ctx->Extensions.ARB_texture_cube_map) {
1215 _mesa_error(ctx, GL_INVALID_ENUM,
1216 "glGetColorTableParameteriv(target)");
1217 return;
1218 }
1219 table = &ctx->Texture.ProxyCubeMap->Palette;
1220 break;
1221 case GL_SHARED_TEXTURE_PALETTE_EXT:
1222 table = &ctx->Texture.Palette;
1223 break;
1224 case GL_COLOR_TABLE:
1225 table = &ctx->ColorTable;
1226 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1227 params[0] = (GLint) ctx->Pixel.ColorTableScale[0];
1228 params[1] = (GLint) ctx->Pixel.ColorTableScale[1];
1229 params[2] = (GLint) ctx->Pixel.ColorTableScale[2];
1230 params[3] = (GLint) ctx->Pixel.ColorTableScale[3];
1231 return;
1232 }
1233 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1234 params[0] = (GLint) ctx->Pixel.ColorTableBias[0];
1235 params[1] = (GLint) ctx->Pixel.ColorTableBias[1];
1236 params[2] = (GLint) ctx->Pixel.ColorTableBias[2];
1237 params[3] = (GLint) ctx->Pixel.ColorTableBias[3];
1238 return;
1239 }
1240 break;
1241 case GL_PROXY_COLOR_TABLE:
1242 table = &ctx->ProxyColorTable;
1243 break;
1244 case GL_TEXTURE_COLOR_TABLE_SGI:
1245 if (!ctx->Extensions.SGI_texture_color_table) {
1246 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1247 return;
1248 }
1249 table = &(texUnit->ColorTable);
1250 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1251 params[0] = (GLint) ctx->Pixel.TextureColorTableScale[0];
1252 params[1] = (GLint) ctx->Pixel.TextureColorTableScale[1];
1253 params[2] = (GLint) ctx->Pixel.TextureColorTableScale[2];
1254 params[3] = (GLint) ctx->Pixel.TextureColorTableScale[3];
1255 return;
1256 }
1257 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1258 params[0] = (GLint) ctx->Pixel.TextureColorTableBias[0];
1259 params[1] = (GLint) ctx->Pixel.TextureColorTableBias[1];
1260 params[2] = (GLint) ctx->Pixel.TextureColorTableBias[2];
1261 params[3] = (GLint) ctx->Pixel.TextureColorTableBias[3];
1262 return;
1263 }
1264 break;
1265 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
1266 if (!ctx->Extensions.SGI_texture_color_table) {
1267 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1268 return;
1269 }
1270 table = &(texUnit->ProxyColorTable);
1271 break;
1272 case GL_POST_CONVOLUTION_COLOR_TABLE:
1273 table = &ctx->PostConvolutionColorTable;
1274 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1275 params[0] = (GLint) ctx->Pixel.PCCTscale[0];
1276 params[1] = (GLint) ctx->Pixel.PCCTscale[1];
1277 params[2] = (GLint) ctx->Pixel.PCCTscale[2];
1278 params[3] = (GLint) ctx->Pixel.PCCTscale[3];
1279 return;
1280 }
1281 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1282 params[0] = (GLint) ctx->Pixel.PCCTbias[0];
1283 params[1] = (GLint) ctx->Pixel.PCCTbias[1];
1284 params[2] = (GLint) ctx->Pixel.PCCTbias[2];
1285 params[3] = (GLint) ctx->Pixel.PCCTbias[3];
1286 return;
1287 }
1288 break;
1289 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
1290 table = &ctx->ProxyPostConvolutionColorTable;
1291 break;
1292 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
1293 table = &ctx->PostColorMatrixColorTable;
1294 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1295 params[0] = (GLint) ctx->Pixel.PCMCTscale[0];
1296 params[1] = (GLint) ctx->Pixel.PCMCTscale[1];
1297 params[2] = (GLint) ctx->Pixel.PCMCTscale[2];
1298 params[3] = (GLint) ctx->Pixel.PCMCTscale[3];
1299 return;
1300 }
1301 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1302 params[0] = (GLint) ctx->Pixel.PCMCTbias[0];
1303 params[1] = (GLint) ctx->Pixel.PCMCTbias[1];
1304 params[2] = (GLint) ctx->Pixel.PCMCTbias[2];
1305 params[3] = (GLint) ctx->Pixel.PCMCTbias[3];
1306 return;
1307 }
1308 break;
1309 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
1310 table = &ctx->ProxyPostColorMatrixColorTable;
1311 break;
1312 default:
1313 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(target)");
1314 return;
1315 }
1316
1317 assert(table);
1318
1319 switch (pname) {
1320 case GL_COLOR_TABLE_FORMAT:
1321 *params = table->IntFormat;
1322 break;
1323 case GL_COLOR_TABLE_WIDTH:
1324 *params = table->Size;
1325 break;
1326 case GL_COLOR_TABLE_RED_SIZE:
1327 *params = table->RedSize;
1328 break;
1329 case GL_COLOR_TABLE_GREEN_SIZE:
1330 *params = table->GreenSize;
1331 break;
1332 case GL_COLOR_TABLE_BLUE_SIZE:
1333 *params = table->BlueSize;
1334 break;
1335 case GL_COLOR_TABLE_ALPHA_SIZE:
1336 *params = table->AlphaSize;
1337 break;
1338 case GL_COLOR_TABLE_LUMINANCE_SIZE:
1339 *params = table->LuminanceSize;
1340 break;
1341 case GL_COLOR_TABLE_INTENSITY_SIZE:
1342 *params = table->IntensitySize;
1343 break;
1344 default:
1345 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" );
1346 return;
1347 }
1348 }