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