added Window-isms previously in gl.h
[mesa.git] / src / mesa / main / colortab.c
1 /* $Id: colortab.c,v 1.17 2000/05/10 14:39:53 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999-2000 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 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "colortab.h"
33 #include "context.h"
34 #include "image.h"
35 #include "macros.h"
36 #include "mem.h"
37 #include "mmath.h"
38 #include "span.h"
39 #include "teximage.h"
40 #endif
41
42
43
44 void
45 _mesa_init_colortable( struct gl_color_table *p )
46 {
47 p->TableType = GL_UNSIGNED_BYTE;
48 /* allocate a width=1 table by default */
49 p->Table = CALLOC(4 * sizeof(GLubyte));
50 if (p->Table) {
51 GLubyte *t = (GLubyte *) p->Table;
52 t[0] = 255;
53 t[1] = 255;
54 t[2] = 255;
55 t[3] = 255;
56 }
57 p->Size = 1;
58 p->IntFormat = GL_RGBA;
59 p->Format = GL_RGBA;
60 p->RedSize = 8;
61 p->GreenSize = 8;
62 p->BlueSize = 8;
63 p->AlphaSize = 8;
64 p->IntensitySize = 0;
65 p->LuminanceSize = 0;
66 }
67
68
69
70 void
71 _mesa_free_colortable_data( struct gl_color_table *p )
72 {
73 if (p->Table) {
74 FREE(p->Table);
75 p->Table = NULL;
76 }
77 }
78
79
80 /*
81 * Examine table's format and set the component sizes accordingly.
82 */
83 static void
84 set_component_sizes( struct gl_color_table *table )
85 {
86 switch (table->Format) {
87 case GL_ALPHA:
88 table->RedSize = 0;
89 table->GreenSize = 0;
90 table->BlueSize = 0;
91 table->AlphaSize = 8;
92 table->IntensitySize = 0;
93 table->LuminanceSize = 0;
94 break;
95 case GL_LUMINANCE:
96 table->RedSize = 0;
97 table->GreenSize = 0;
98 table->BlueSize = 0;
99 table->AlphaSize = 0;
100 table->IntensitySize = 0;
101 table->LuminanceSize = 8;
102 break;
103 case GL_LUMINANCE_ALPHA:
104 table->RedSize = 0;
105 table->GreenSize = 0;
106 table->BlueSize = 0;
107 table->AlphaSize = 8;
108 table->IntensitySize = 0;
109 table->LuminanceSize = 8;
110 break;
111 case GL_INTENSITY:
112 table->RedSize = 0;
113 table->GreenSize = 0;
114 table->BlueSize = 0;
115 table->AlphaSize = 0;
116 table->IntensitySize = 8;
117 table->LuminanceSize = 0;
118 break;
119 case GL_RGB:
120 table->RedSize = 8;
121 table->GreenSize = 8;
122 table->BlueSize = 8;
123 table->AlphaSize = 0;
124 table->IntensitySize = 0;
125 table->LuminanceSize = 0;
126 break;
127 case GL_RGBA:
128 table->RedSize = 8;
129 table->GreenSize = 8;
130 table->BlueSize = 8;
131 table->AlphaSize = 8;
132 table->IntensitySize = 0;
133 table->LuminanceSize = 0;
134 break;
135 default:
136 gl_problem(NULL, "unexpected format in set_component_sizes");
137 }
138 }
139
140
141
142 void
143 _mesa_ColorTable( GLenum target, GLenum internalFormat,
144 GLsizei width, GLenum format, GLenum type,
145 const GLvoid *data )
146 {
147 GET_CURRENT_CONTEXT(ctx);
148 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
149 struct gl_texture_object *texObj = NULL;
150 struct gl_color_table *table = NULL;
151 GLboolean proxy = GL_FALSE;
152 GLint baseFormat;
153 GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0;
154 GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0;
155 GLboolean floatTable = GL_FALSE;
156 GLint comps;
157
158 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glColorTable");
159
160 switch (target) {
161 case GL_TEXTURE_1D:
162 texObj = texUnit->CurrentD[1];
163 table = &texObj->Palette;
164 break;
165 case GL_TEXTURE_2D:
166 texObj = texUnit->CurrentD[2];
167 table = &texObj->Palette;
168 break;
169 case GL_TEXTURE_3D:
170 texObj = texUnit->CurrentD[3];
171 table = &texObj->Palette;
172 break;
173 case GL_PROXY_TEXTURE_1D:
174 texObj = ctx->Texture.Proxy1D;
175 table = &texObj->Palette;
176 proxy = GL_TRUE;
177 break;
178 case GL_PROXY_TEXTURE_2D:
179 texObj = ctx->Texture.Proxy2D;
180 table = &texObj->Palette;
181 proxy = GL_TRUE;
182 break;
183 case GL_PROXY_TEXTURE_3D:
184 texObj = ctx->Texture.Proxy3D;
185 table = &texObj->Palette;
186 proxy = GL_TRUE;
187 break;
188 case GL_SHARED_TEXTURE_PALETTE_EXT:
189 table = &ctx->Texture.Palette;
190 break;
191 case GL_COLOR_TABLE:
192 table = &ctx->ColorTable;
193 floatTable = GL_TRUE;
194 rScale = ctx->Pixel.ColorTableScale[0];
195 gScale = ctx->Pixel.ColorTableScale[1];
196 bScale = ctx->Pixel.ColorTableScale[2];
197 aScale = ctx->Pixel.ColorTableScale[3];
198 rBias = ctx->Pixel.ColorTableBias[0];
199 gBias = ctx->Pixel.ColorTableBias[1];
200 bBias = ctx->Pixel.ColorTableBias[2];
201 aBias = ctx->Pixel.ColorTableBias[3];
202 break;
203 case GL_PROXY_COLOR_TABLE:
204 table = &ctx->ProxyColorTable;
205 proxy = GL_TRUE;
206 break;
207 case GL_POST_CONVOLUTION_COLOR_TABLE:
208 table = &ctx->PostConvolutionColorTable;
209 floatTable = GL_TRUE;
210 rScale = ctx->Pixel.PCCTscale[0];
211 gScale = ctx->Pixel.PCCTscale[1];
212 bScale = ctx->Pixel.PCCTscale[2];
213 aScale = ctx->Pixel.PCCTscale[3];
214 rBias = ctx->Pixel.PCCTbias[0];
215 gBias = ctx->Pixel.PCCTbias[1];
216 bBias = ctx->Pixel.PCCTbias[2];
217 aBias = ctx->Pixel.PCCTbias[3];
218 break;
219 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
220 table = &ctx->ProxyPostConvolutionColorTable;
221 proxy = GL_TRUE;
222 break;
223 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
224 table = &ctx->PostColorMatrixColorTable;
225 floatTable = GL_TRUE;
226 rScale = ctx->Pixel.PCMCTscale[0];
227 gScale = ctx->Pixel.PCMCTscale[1];
228 bScale = ctx->Pixel.PCMCTscale[2];
229 aScale = ctx->Pixel.PCMCTscale[3];
230 rBias = ctx->Pixel.PCMCTbias[0];
231 gBias = ctx->Pixel.PCMCTbias[1];
232 bBias = ctx->Pixel.PCMCTbias[2];
233 aBias = ctx->Pixel.PCMCTbias[3];
234 break;
235 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
236 table = &ctx->ProxyPostColorMatrixColorTable;
237 proxy = GL_TRUE;
238 break;
239 default:
240 gl_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
241 return;
242 }
243
244 assert(table);
245
246 if (!_mesa_is_legal_format_and_type(format, type)) {
247 gl_error(ctx, GL_INVALID_ENUM, "glColorTable(format or type)");
248 return;
249 }
250
251 baseFormat = _mesa_base_tex_format(internalFormat);
252 if (baseFormat < 0 || baseFormat == GL_COLOR_INDEX) {
253 gl_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)");
254 return;
255 }
256
257 if (width < 1 || width > ctx->Const.MaxColorTableSize
258 || _mesa_bitcount(width) != 1) {
259 if (width > ctx->Const.MaxColorTableSize)
260 gl_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)");
261 else
262 gl_error(ctx, GL_INVALID_VALUE, "glColorTable(width)");
263 if (proxy) {
264 table->Size = 0;
265 table->IntFormat = (GLenum) 0;
266 table->Format = (GLenum) 0;
267 }
268 return;
269 }
270
271 table->Size = width;
272 table->IntFormat = internalFormat;
273 table->Format = (GLenum) baseFormat;
274 set_component_sizes(table);
275
276 comps = _mesa_components_in_format(table->Format);
277 assert(comps > 0); /* error should have been caught sooner */
278
279 if (!proxy) {
280 /* free old table, if any */
281 if (table->Table) {
282 FREE(table->Table);
283 }
284 if (floatTable) {
285 GLubyte tableUB[MAX_COLOR_TABLE_SIZE * 4];
286 GLfloat *tableF;
287 GLuint i;
288
289 _mesa_unpack_ubyte_color_span(ctx, width, table->Format,
290 tableUB, /* dest */
291 format, type, data,
292 &ctx->Unpack, GL_TRUE);
293
294 table->TableType = GL_FLOAT;
295 table->Table = MALLOC(comps * width * sizeof(GLfloat));
296 if (!table->Table) {
297 gl_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
298 return;
299 }
300
301 /* Apply scale and bias and convert GLubyte values to GLfloats
302 * in [0, 1]. Store results in the tableF[].
303 */
304 rScale /= 255.0;
305 gScale /= 255.0;
306 bScale /= 255.0;
307 aScale /= 255.0;
308 tableF = (GLfloat *) table->Table;
309
310 switch (table->Format) {
311 case GL_INTENSITY:
312 for (i = 0; i < width; i++) {
313 tableF[i] = tableUB[i] * rScale + rBias;
314 }
315 break;
316 case GL_LUMINANCE:
317 for (i = 0; i < width; i++) {
318 tableF[i] = tableUB[i] * rScale + rBias;
319 }
320 break;
321 case GL_ALPHA:
322 for (i = 0; i < width; i++) {
323 tableF[i] = tableUB[i] * aScale + aBias;
324 }
325 break;
326 case GL_LUMINANCE_ALPHA:
327 for (i = 0; i < width; i++) {
328 tableF[i*2+0] = tableUB[i*2+0] * rScale + rBias;
329 tableF[i*2+1] = tableUB[i*2+1] * aScale + aBias;
330 }
331 break;
332 case GL_RGB:
333 for (i = 0; i < width; i++) {
334 tableF[i*3+0] = tableUB[i*3+0] * rScale + rBias;
335 tableF[i*3+1] = tableUB[i*3+1] * gScale + gBias;
336 tableF[i*3+2] = tableUB[i*3+2] * bScale + bBias;
337 }
338 break;
339 case GL_RGBA:
340 for (i = 0; i < width; i++) {
341 tableF[i*4+0] = tableUB[i*4+0] * rScale + rBias;
342 tableF[i*4+1] = tableUB[i*4+1] * gScale + gBias;
343 tableF[i*4+2] = tableUB[i*4+2] * bScale + bBias;
344 tableF[i*4+3] = tableUB[i*4+3] * aScale + aBias;
345 }
346 break;
347 default:
348 gl_problem(ctx, "Bad format in _mesa_ColorTable");
349 return;
350 }
351 }
352 else {
353 /* store GLubyte table */
354 table->TableType = GL_UNSIGNED_BYTE;
355 table->Table = MALLOC(comps * width * sizeof(GLubyte));
356 if (!table->Table) {
357 gl_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
358 return;
359 }
360 _mesa_unpack_ubyte_color_span(ctx, width, table->Format,
361 table->Table, /* dest */
362 format, type, data,
363 &ctx->Unpack, GL_TRUE);
364 } /* floatTable */
365 } /* proxy */
366
367 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
368 /* texture object palette, texObj==NULL means the shared palette */
369 if (ctx->Driver.UpdateTexturePalette) {
370 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
371 }
372 }
373 }
374
375
376
377 void
378 _mesa_ColorSubTable( GLenum target, GLsizei start,
379 GLsizei count, GLenum format, GLenum type,
380 const GLvoid *data )
381 {
382 GET_CURRENT_CONTEXT(ctx);
383 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
384 struct gl_texture_object *texObj = NULL;
385 struct gl_color_table *table = NULL;
386 GLint comps;
387
388 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glColorSubTable");
389
390 switch (target) {
391 case GL_TEXTURE_1D:
392 texObj = texUnit->CurrentD[1];
393 table = &texObj->Palette;
394 break;
395 case GL_TEXTURE_2D:
396 texObj = texUnit->CurrentD[2];
397 table = &texObj->Palette;
398 break;
399 case GL_TEXTURE_3D:
400 texObj = texUnit->CurrentD[3];
401 table = &texObj->Palette;
402 break;
403 case GL_SHARED_TEXTURE_PALETTE_EXT:
404 table = &ctx->Texture.Palette;
405 break;
406 case GL_COLOR_TABLE:
407 table = &ctx->ColorTable;
408 break;
409 case GL_POST_CONVOLUTION_COLOR_TABLE:
410 table = &ctx->PostConvolutionColorTable;
411 break;
412 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
413 table = &ctx->PostColorMatrixColorTable;
414 break;
415 default:
416 gl_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
417 return;
418 }
419
420 assert(table);
421
422 if (!_mesa_is_legal_format_and_type(format, type)) {
423 gl_error(ctx, GL_INVALID_ENUM, "glColorSubTable(format or type)");
424 return;
425 }
426
427 if (count < 1) {
428 gl_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
429 return;
430 }
431
432 comps = _mesa_components_in_format(table->Format);
433 assert(comps > 0); /* error should have been caught sooner */
434
435 if (start + count > table->Size) {
436 gl_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
437 return;
438 }
439
440 if (!table->Table) {
441 gl_error(ctx, GL_OUT_OF_MEMORY, "glColorSubTable");
442 return;
443 }
444
445 if (table->TableType == GL_UNSIGNED_BYTE) {
446 GLubyte *dest = (GLubyte *) table->Table + start * comps * sizeof(GLubyte);
447 _mesa_unpack_ubyte_color_span(ctx, count, table->Format, dest,
448 format, type, data, &ctx->Unpack, GL_TRUE);
449 }
450 else {
451 GLfloat *dest = (GLfloat *) table->Table + start * comps * sizeof(GLfloat);
452 ASSERT(table->TableType == GL_FLOAT);
453 _mesa_unpack_float_color_span(ctx, count, table->Format, dest,
454 format, type, data, &ctx->Unpack,
455 GL_FALSE, GL_TRUE);
456 }
457
458 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
459 /* per-texture object palette */
460 if (ctx->Driver.UpdateTexturePalette) {
461 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
462 }
463 }
464 }
465
466
467
468 /* XXX not tested */
469 void
470 _mesa_CopyColorTable(GLenum target, GLenum internalformat,
471 GLint x, GLint y, GLsizei width)
472 {
473 GLubyte data[MAX_WIDTH][4];
474 GET_CURRENT_CONTEXT(ctx);
475 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyColorTable");
476
477 /* Select buffer to read from */
478 (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
479 ctx->Pixel.DriverReadBuffer );
480
481 if (width > MAX_WIDTH)
482 width = MAX_WIDTH;
483
484 /* read the data from framebuffer */
485 gl_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
486
487 /* Restore reading from draw buffer (the default) */
488 (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
489 ctx->Color.DriverDrawBuffer );
490
491 _mesa_ColorTable(target, internalformat, width,
492 GL_RGBA, GL_UNSIGNED_BYTE, data);
493 }
494
495
496
497 /* XXX not tested */
498 void
499 _mesa_CopyColorSubTable(GLenum target, GLsizei start,
500 GLint x, GLint y, GLsizei width)
501 {
502 GLubyte data[MAX_WIDTH][4];
503 GET_CURRENT_CONTEXT(ctx);
504 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyColorSubTable");
505
506 /* Select buffer to read from */
507 (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
508 ctx->Pixel.DriverReadBuffer );
509
510 if (width > MAX_WIDTH)
511 width = MAX_WIDTH;
512
513 /* read the data from framebuffer */
514 gl_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
515
516 /* Restore reading from draw buffer (the default) */
517 (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
518 ctx->Color.DriverDrawBuffer );
519
520 _mesa_ColorSubTable(target, start, width, GL_RGBA, GL_UNSIGNED_BYTE, data);
521 }
522
523
524
525 void
526 _mesa_GetColorTable( GLenum target, GLenum format,
527 GLenum type, GLvoid *data )
528 {
529 GET_CURRENT_CONTEXT(ctx);
530 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
531 struct gl_color_table *table = NULL;
532 GLubyte rgba[MAX_COLOR_TABLE_SIZE][4];
533 GLint i;
534
535 ASSERT_OUTSIDE_BEGIN_END(ctx, "glGetColorTable");
536
537 switch (target) {
538 case GL_TEXTURE_1D:
539 table = &texUnit->CurrentD[1]->Palette;
540 break;
541 case GL_TEXTURE_2D:
542 table = &texUnit->CurrentD[2]->Palette;
543 break;
544 case GL_TEXTURE_3D:
545 table = &texUnit->CurrentD[3]->Palette;
546 break;
547 case GL_SHARED_TEXTURE_PALETTE_EXT:
548 table = &ctx->Texture.Palette;
549 break;
550 case GL_COLOR_TABLE:
551 table = &ctx->ColorTable;
552 break;
553 case GL_POST_CONVOLUTION_COLOR_TABLE:
554 table = &ctx->PostConvolutionColorTable;
555 break;
556 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
557 table = &ctx->PostColorMatrixColorTable;
558 break;
559 default:
560 gl_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
561 return;
562 }
563
564 assert(table);
565
566 switch (table->Format) {
567 case GL_ALPHA:
568 if (table->TableType == GL_FLOAT) {
569 const GLfloat *tableF = (const GLfloat *) table->Table;
570 for (i = 0; i < table->Size; i++) {
571 rgba[i][RCOMP] = 0;
572 rgba[i][GCOMP] = 0;
573 rgba[i][BCOMP] = 0;
574 rgba[i][ACOMP] = (GLint) (tableF[i] * 255.0F);
575 }
576 }
577 else {
578 const GLubyte *tableUB = (const GLubyte *) table->Table;
579 for (i = 0; i < table->Size; i++) {
580 rgba[i][RCOMP] = 0;
581 rgba[i][GCOMP] = 0;
582 rgba[i][BCOMP] = 0;
583 rgba[i][ACOMP] = tableUB[i];
584 }
585 }
586 break;
587 case GL_LUMINANCE:
588 if (table->TableType == GL_FLOAT) {
589 const GLfloat *tableF = (const GLfloat *) table->Table;
590 for (i = 0; i < table->Size; i++) {
591 rgba[i][RCOMP] = (GLint) (tableF[i] * 255.0F);
592 rgba[i][GCOMP] = (GLint) (tableF[i] * 255.0F);
593 rgba[i][BCOMP] = (GLint) (tableF[i] * 255.0F);
594 rgba[i][ACOMP] = 255;
595 }
596 }
597 else {
598 const GLubyte *tableUB = (const GLubyte *) table->Table;
599 for (i = 0; i < table->Size; i++) {
600 rgba[i][RCOMP] = tableUB[i];
601 rgba[i][GCOMP] = tableUB[i];
602 rgba[i][BCOMP] = tableUB[i];
603 rgba[i][ACOMP] = 255;
604 }
605 }
606 break;
607 case GL_LUMINANCE_ALPHA:
608 if (table->TableType == GL_FLOAT) {
609 const GLfloat *tableF = (const GLfloat *) table->Table;
610 for (i = 0; i < table->Size; i++) {
611 rgba[i][RCOMP] = (GLint) (tableF[i*2+0] * 255.0F);
612 rgba[i][GCOMP] = (GLint) (tableF[i*2+0] * 255.0F);
613 rgba[i][BCOMP] = (GLint) (tableF[i*2+0] * 255.0F);
614 rgba[i][ACOMP] = (GLint) (tableF[i*2+1] * 255.0F);
615 }
616 }
617 else {
618 const GLubyte *tableUB = (const GLubyte *) table->Table;
619 for (i = 0; i < table->Size; i++) {
620 rgba[i][RCOMP] = tableUB[i*2+0];
621 rgba[i][GCOMP] = tableUB[i*2+0];
622 rgba[i][BCOMP] = tableUB[i*2+0];
623 rgba[i][ACOMP] = tableUB[i*2+1];
624 }
625 }
626 break;
627 case GL_INTENSITY:
628 if (table->TableType == GL_FLOAT) {
629 const GLfloat *tableF = (const GLfloat *) table->Table;
630 for (i = 0; i < table->Size; i++) {
631 rgba[i][RCOMP] = (GLint) (tableF[i] * 255.0F);
632 rgba[i][GCOMP] = (GLint) (tableF[i] * 255.0F);
633 rgba[i][BCOMP] = (GLint) (tableF[i] * 255.0F);
634 rgba[i][ACOMP] = (GLint) (tableF[i] * 255.0F);
635 }
636 }
637 else {
638 const GLubyte *tableUB = (const GLubyte *) table->Table;
639 for (i = 0; i < table->Size; i++) {
640 rgba[i][RCOMP] = tableUB[i];
641 rgba[i][GCOMP] = tableUB[i];
642 rgba[i][BCOMP] = tableUB[i];
643 rgba[i][ACOMP] = tableUB[i];
644 }
645 }
646 break;
647 case GL_RGB:
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*3+0] * 255.0F);
652 rgba[i][GCOMP] = (GLint) (tableF[i*3+1] * 255.0F);
653 rgba[i][BCOMP] = (GLint) (tableF[i*3+2] * 255.0F);
654 rgba[i][ACOMP] = 255;
655 }
656 }
657 else {
658 const GLubyte *tableUB = (const GLubyte *) table->Table;
659 for (i = 0; i < table->Size; i++) {
660 rgba[i][RCOMP] = tableUB[i*3+0];
661 rgba[i][GCOMP] = tableUB[i*3+1];
662 rgba[i][BCOMP] = tableUB[i*3+2];
663 rgba[i][ACOMP] = 255;
664 }
665 }
666 break;
667 case GL_RGBA:
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*4+0] * 255.0F);
672 rgba[i][GCOMP] = (GLint) (tableF[i*4+1] * 255.0F);
673 rgba[i][BCOMP] = (GLint) (tableF[i*4+2] * 255.0F);
674 rgba[i][ACOMP] = (GLint) (tableF[i*4+3] * 255.0F);
675 }
676 }
677 else {
678 const GLubyte *tableUB = (const GLubyte *) table->Table;
679 for (i = 0; i < table->Size; i++) {
680 rgba[i][RCOMP] = tableUB[i*4+0];
681 rgba[i][GCOMP] = tableUB[i*4+1];
682 rgba[i][BCOMP] = tableUB[i*4+2];
683 rgba[i][ACOMP] = tableUB[i*4+3];
684 }
685 }
686 break;
687 default:
688 gl_problem(ctx, "bad table format in glGetColorTable");
689 return;
690 }
691
692 _mesa_pack_rgba_span(ctx, table->Size, (const GLubyte (*)[]) rgba,
693 format, type, data, &ctx->Pack, GL_FALSE);
694 }
695
696
697
698 void
699 _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
700 {
701 GET_CURRENT_CONTEXT(ctx);
702 ASSERT_OUTSIDE_BEGIN_END(ctx, "glColorTableParameterfv");
703
704 switch (target) {
705 case GL_COLOR_TABLE_SGI:
706 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
707 ctx->Pixel.ColorTableScale[0] = params[0];
708 ctx->Pixel.ColorTableScale[1] = params[1];
709 ctx->Pixel.ColorTableScale[2] = params[2];
710 ctx->Pixel.ColorTableScale[3] = params[3];
711 }
712 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
713 ctx->Pixel.ColorTableBias[0] = params[0];
714 ctx->Pixel.ColorTableBias[1] = params[1];
715 ctx->Pixel.ColorTableBias[2] = params[2];
716 ctx->Pixel.ColorTableBias[3] = params[3];
717 }
718 else {
719 gl_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
720 return;
721 }
722 break;
723 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
724 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
725 ctx->Pixel.PCCTscale[0] = params[0];
726 ctx->Pixel.PCCTscale[1] = params[1];
727 ctx->Pixel.PCCTscale[2] = params[2];
728 ctx->Pixel.PCCTscale[3] = params[3];
729 }
730 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
731 ctx->Pixel.PCCTbias[0] = params[0];
732 ctx->Pixel.PCCTbias[1] = params[1];
733 ctx->Pixel.PCCTbias[2] = params[2];
734 ctx->Pixel.PCCTbias[3] = params[3];
735 }
736 else {
737 gl_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
738 return;
739 }
740 break;
741 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
742 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
743 ctx->Pixel.PCMCTscale[0] = params[0];
744 ctx->Pixel.PCMCTscale[1] = params[1];
745 ctx->Pixel.PCMCTscale[2] = params[2];
746 ctx->Pixel.PCMCTscale[3] = params[3];
747 }
748 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
749 ctx->Pixel.PCMCTbias[0] = params[0];
750 ctx->Pixel.PCMCTbias[1] = params[1];
751 ctx->Pixel.PCMCTbias[2] = params[2];
752 ctx->Pixel.PCMCTbias[3] = params[3];
753 }
754 else {
755 gl_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
756 return;
757 }
758 break;
759 default:
760 gl_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
761 return;
762 }
763 }
764
765
766
767 void
768 _mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
769 {
770 GLfloat fparams[4];
771 if (pname == GL_COLOR_TABLE_SGI ||
772 pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
773 pname == GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI) {
774 /* four values */
775 fparams[0] = (GLfloat) params[0];
776 fparams[1] = (GLfloat) params[1];
777 fparams[2] = (GLfloat) params[2];
778 fparams[3] = (GLfloat) params[3];
779 }
780 else {
781 /* one values */
782 fparams[0] = (GLfloat) params[0];
783 }
784 _mesa_ColorTableParameterfv(target, pname, fparams);
785 }
786
787
788
789 void
790 _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
791 {
792 GET_CURRENT_CONTEXT(ctx);
793 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
794 struct gl_color_table *table = NULL;
795
796 ASSERT_OUTSIDE_BEGIN_END(ctx, "glGetColorTableParameterfv");
797
798 switch (target) {
799 case GL_TEXTURE_1D:
800 table = &texUnit->CurrentD[1]->Palette;
801 break;
802 case GL_TEXTURE_2D:
803 table = &texUnit->CurrentD[2]->Palette;
804 break;
805 case GL_TEXTURE_3D:
806 table = &texUnit->CurrentD[3]->Palette;
807 break;
808 case GL_PROXY_TEXTURE_1D:
809 table = &ctx->Texture.Proxy1D->Palette;
810 break;
811 case GL_PROXY_TEXTURE_2D:
812 table = &ctx->Texture.Proxy2D->Palette;
813 break;
814 case GL_PROXY_TEXTURE_3D:
815 table = &ctx->Texture.Proxy3D->Palette;
816 break;
817 case GL_SHARED_TEXTURE_PALETTE_EXT:
818 table = &ctx->Texture.Palette;
819 break;
820 case GL_COLOR_TABLE:
821 table = &ctx->ColorTable;
822 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
823 params[0] = ctx->Pixel.ColorTableScale[0];
824 params[1] = ctx->Pixel.ColorTableScale[1];
825 params[2] = ctx->Pixel.ColorTableScale[2];
826 params[3] = ctx->Pixel.ColorTableScale[3];
827 return;
828 }
829 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
830 params[0] = ctx->Pixel.ColorTableBias[0];
831 params[1] = ctx->Pixel.ColorTableBias[1];
832 params[2] = ctx->Pixel.ColorTableBias[2];
833 params[3] = ctx->Pixel.ColorTableBias[3];
834 return;
835 }
836 break;
837 case GL_PROXY_COLOR_TABLE:
838 table = &ctx->ProxyColorTable;
839 break;
840 case GL_POST_CONVOLUTION_COLOR_TABLE:
841 table = &ctx->PostConvolutionColorTable;
842 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
843 params[0] = ctx->Pixel.PCCTscale[0];
844 params[1] = ctx->Pixel.PCCTscale[1];
845 params[2] = ctx->Pixel.PCCTscale[2];
846 params[3] = ctx->Pixel.PCCTscale[3];
847 return;
848 }
849 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
850 params[0] = ctx->Pixel.PCCTbias[0];
851 params[1] = ctx->Pixel.PCCTbias[1];
852 params[2] = ctx->Pixel.PCCTbias[2];
853 params[3] = ctx->Pixel.PCCTbias[3];
854 return;
855 }
856 break;
857 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
858 table = &ctx->ProxyPostConvolutionColorTable;
859 break;
860 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
861 table = &ctx->PostColorMatrixColorTable;
862 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
863 params[0] = ctx->Pixel.PCMCTscale[0];
864 params[1] = ctx->Pixel.PCMCTscale[1];
865 params[2] = ctx->Pixel.PCMCTscale[2];
866 params[3] = ctx->Pixel.PCMCTscale[3];
867 return;
868 }
869 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
870 params[0] = ctx->Pixel.PCMCTbias[0];
871 params[1] = ctx->Pixel.PCMCTbias[1];
872 params[2] = ctx->Pixel.PCMCTbias[2];
873 params[3] = ctx->Pixel.PCMCTbias[3];
874 return;
875 }
876 break;
877 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
878 table = &ctx->ProxyPostColorMatrixColorTable;
879 break;
880 default:
881 gl_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(target)");
882 return;
883 }
884
885 assert(table);
886
887 switch (pname) {
888 case GL_COLOR_TABLE_FORMAT:
889 *params = table->IntFormat;
890 break;
891 case GL_COLOR_TABLE_WIDTH:
892 *params = table->Size;
893 break;
894 case GL_COLOR_TABLE_RED_SIZE:
895 *params = table->RedSize;
896 break;
897 case GL_COLOR_TABLE_GREEN_SIZE:
898 *params = table->GreenSize;
899 break;
900 case GL_COLOR_TABLE_BLUE_SIZE:
901 *params = table->BlueSize;
902 break;
903 case GL_COLOR_TABLE_ALPHA_SIZE:
904 *params = table->AlphaSize;
905 break;
906 case GL_COLOR_TABLE_LUMINANCE_SIZE:
907 *params = table->LuminanceSize;
908 break;
909 case GL_COLOR_TABLE_INTENSITY_SIZE:
910 *params = table->IntensitySize;
911 break;
912 default:
913 gl_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" );
914 return;
915 }
916 }
917
918
919
920 void
921 _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
922 {
923 GET_CURRENT_CONTEXT(ctx);
924 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
925 struct gl_color_table *table = NULL;
926
927 ASSERT_OUTSIDE_BEGIN_END(ctx, "glGetColorTableParameteriv");
928
929 switch (target) {
930 case GL_TEXTURE_1D:
931 table = &texUnit->CurrentD[1]->Palette;
932 break;
933 case GL_TEXTURE_2D:
934 table = &texUnit->CurrentD[2]->Palette;
935 break;
936 case GL_TEXTURE_3D:
937 table = &texUnit->CurrentD[3]->Palette;
938 break;
939 case GL_PROXY_TEXTURE_1D:
940 table = &ctx->Texture.Proxy1D->Palette;
941 break;
942 case GL_PROXY_TEXTURE_2D:
943 table = &ctx->Texture.Proxy2D->Palette;
944 break;
945 case GL_PROXY_TEXTURE_3D:
946 table = &ctx->Texture.Proxy3D->Palette;
947 break;
948 case GL_SHARED_TEXTURE_PALETTE_EXT:
949 table = &ctx->Texture.Palette;
950 break;
951 case GL_COLOR_TABLE:
952 table = &ctx->ColorTable;
953 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
954 params[0] = (GLint) ctx->Pixel.ColorTableScale[0];
955 params[1] = (GLint) ctx->Pixel.ColorTableScale[1];
956 params[2] = (GLint) ctx->Pixel.ColorTableScale[2];
957 params[3] = (GLint) ctx->Pixel.ColorTableScale[3];
958 return;
959 }
960 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
961 params[0] = (GLint) ctx->Pixel.ColorTableBias[0];
962 params[1] = (GLint) ctx->Pixel.ColorTableBias[1];
963 params[2] = (GLint) ctx->Pixel.ColorTableBias[2];
964 params[3] = (GLint) ctx->Pixel.ColorTableBias[3];
965 return;
966 }
967 break;
968 case GL_PROXY_COLOR_TABLE:
969 table = &ctx->ProxyColorTable;
970 break;
971 case GL_POST_CONVOLUTION_COLOR_TABLE:
972 table = &ctx->PostConvolutionColorTable;
973 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
974 params[0] = (GLint) ctx->Pixel.PCCTscale[0];
975 params[1] = (GLint) ctx->Pixel.PCCTscale[1];
976 params[2] = (GLint) ctx->Pixel.PCCTscale[2];
977 params[3] = (GLint) ctx->Pixel.PCCTscale[3];
978 return;
979 }
980 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
981 params[0] = (GLint) ctx->Pixel.PCCTbias[0];
982 params[1] = (GLint) ctx->Pixel.PCCTbias[1];
983 params[2] = (GLint) ctx->Pixel.PCCTbias[2];
984 params[3] = (GLint) ctx->Pixel.PCCTbias[3];
985 return;
986 }
987 break;
988 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
989 table = &ctx->ProxyPostConvolutionColorTable;
990 break;
991 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
992 table = &ctx->PostColorMatrixColorTable;
993 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
994 params[0] = (GLint) ctx->Pixel.PCMCTscale[0];
995 params[1] = (GLint) ctx->Pixel.PCMCTscale[1];
996 params[2] = (GLint) ctx->Pixel.PCMCTscale[2];
997 params[3] = (GLint) ctx->Pixel.PCMCTscale[3];
998 return;
999 }
1000 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1001 params[0] = (GLint) ctx->Pixel.PCMCTbias[0];
1002 params[1] = (GLint) ctx->Pixel.PCMCTbias[1];
1003 params[2] = (GLint) ctx->Pixel.PCMCTbias[2];
1004 params[3] = (GLint) ctx->Pixel.PCMCTbias[3];
1005 return;
1006 }
1007 break;
1008 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
1009 table = &ctx->ProxyPostColorMatrixColorTable;
1010 break;
1011 default:
1012 gl_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(target)");
1013 return;
1014 }
1015
1016 assert(table);
1017
1018 switch (pname) {
1019 case GL_COLOR_TABLE_FORMAT:
1020 *params = table->IntFormat;
1021 break;
1022 case GL_COLOR_TABLE_WIDTH:
1023 *params = table->Size;
1024 break;
1025 case GL_COLOR_TABLE_RED_SIZE:
1026 *params = table->RedSize;
1027 break;
1028 case GL_COLOR_TABLE_GREEN_SIZE:
1029 *params = table->GreenSize;
1030 break;
1031 case GL_COLOR_TABLE_BLUE_SIZE:
1032 *params = table->BlueSize;
1033 break;
1034 case GL_COLOR_TABLE_ALPHA_SIZE:
1035 *params = table->AlphaSize;
1036 break;
1037 case GL_COLOR_TABLE_LUMINANCE_SIZE:
1038 *params = table->LuminanceSize;
1039 break;
1040 case GL_COLOR_TABLE_INTENSITY_SIZE:
1041 *params = table->IntensitySize;
1042 break;
1043 default:
1044 gl_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" );
1045 return;
1046 }
1047 }