blob: 213aa2c8944f565d4ff98b3e3988440820459248 [file] [log] [blame]
Brian Paul250069d2000-04-08 18:57:45 +00001/* $Id: pixel.c,v 1.6 2000/04/08 18:57:45 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paulfbd8f211999-11-11 01:22:25 +00005 * Version: 3.3
jtgafb833d1999-08-19 00:55:39 +00006 *
7 * Copyright (C) 1999 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
jtgafb833d1999-08-19 00:55:39 +000028/*
29 * glPixelStore, glPixelTransfer, glPixelMap, glPixelZoom, etc.
30 */
31
32
33#ifdef PC_HEADER
34#include "all.h"
35#else
Brian Paulfbd8f211999-11-11 01:22:25 +000036#include "glheader.h"
jtgafb833d1999-08-19 00:55:39 +000037#include "context.h"
38#include "macros.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000039#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000040#include "pixel.h"
41#include "types.h"
jtgafb833d1999-08-19 00:55:39 +000042#endif
43
44
45
46/**********************************************************************/
47/***** glPixelZoom *****/
48/**********************************************************************/
49
50
51
Brian Paulfbd8f211999-11-11 01:22:25 +000052void
53_mesa_PixelZoom( GLfloat xfactor, GLfloat yfactor )
jtgafb833d1999-08-19 00:55:39 +000054{
Brian Paulfbd8f211999-11-11 01:22:25 +000055 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +000056 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPixelZoom");
57
58 ctx->Pixel.ZoomX = xfactor;
59 ctx->Pixel.ZoomY = yfactor;
60}
61
62
63
64/**********************************************************************/
65/***** glPixelStore *****/
66/**********************************************************************/
67
68
Brian Paulfbd8f211999-11-11 01:22:25 +000069void
70_mesa_PixelStorei( GLenum pname, GLint param )
jtgafb833d1999-08-19 00:55:39 +000071{
72 /* NOTE: this call can't be compiled into the display list */
Brian Paulfbd8f211999-11-11 01:22:25 +000073 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +000074 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPixelStore");
75
jtgafb833d1999-08-19 00:55:39 +000076 switch (pname) {
77 case GL_PACK_SWAP_BYTES:
78 ctx->Pack.SwapBytes = param ? GL_TRUE : GL_FALSE;
79 break;
80 case GL_PACK_LSB_FIRST:
81 ctx->Pack.LsbFirst = param ? GL_TRUE : GL_FALSE;
82 break;
83 case GL_PACK_ROW_LENGTH:
84 if (param<0) {
85 gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
86 }
87 else {
88 ctx->Pack.RowLength = param;
89 }
90 break;
91 case GL_PACK_IMAGE_HEIGHT:
92 if (param<0)
93 gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
94 else
95 ctx->Pack.ImageHeight = param;
96 break;
97 case GL_PACK_SKIP_PIXELS:
98 if (param<0) {
99 gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
100 }
101 else {
102 ctx->Pack.SkipPixels = param;
103 }
104 break;
105 case GL_PACK_SKIP_ROWS:
106 if (param<0) {
107 gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
108 }
109 else {
110 ctx->Pack.SkipRows = param;
111 }
112 break;
113 case GL_PACK_ALIGNMENT:
114 if (param==1 || param==2 || param==4 || param==8) {
115 ctx->Pack.Alignment = param;
116 }
117 else {
118 gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
119 }
120 break;
121 case GL_UNPACK_SWAP_BYTES:
122 ctx->Unpack.SwapBytes = param ? GL_TRUE : GL_FALSE;
123 break;
124 case GL_UNPACK_LSB_FIRST:
125 ctx->Unpack.LsbFirst = param ? GL_TRUE : GL_FALSE;
126 break;
127 case GL_UNPACK_ROW_LENGTH:
128 if (param<0) {
129 gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
130 }
131 else {
132 ctx->Unpack.RowLength = param;
133 }
134 break;
135 case GL_UNPACK_IMAGE_HEIGHT:
136 if (param<0)
137 gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
138 else
139 ctx->Unpack.ImageHeight = param;
140 break;
141 case GL_UNPACK_SKIP_PIXELS:
142 if (param<0) {
143 gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
144 }
145 else {
146 ctx->Unpack.SkipPixels = param;
147 }
148 break;
149 case GL_UNPACK_SKIP_ROWS:
150 if (param<0) {
151 gl_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
152 }
153 else {
154 ctx->Unpack.SkipRows = param;
155 }
156 break;
157 case GL_UNPACK_ALIGNMENT:
158 if (param==1 || param==2 || param==4 || param==8) {
159 ctx->Unpack.Alignment = param;
160 }
161 else {
162 gl_error( ctx, GL_INVALID_VALUE, "glPixelStore" );
163 }
164 break;
165 default:
166 gl_error( ctx, GL_INVALID_ENUM, "glPixelStore" );
167 }
168}
169
170
Brian Paulfbd8f211999-11-11 01:22:25 +0000171void
172_mesa_PixelStoref( GLenum pname, GLfloat param )
173{
174 _mesa_PixelStorei( pname, (GLint) param );
175}
jtgafb833d1999-08-19 00:55:39 +0000176
177
178
179/**********************************************************************/
180/***** glPixelMap *****/
181/**********************************************************************/
182
183
184
Brian Paulfbd8f211999-11-11 01:22:25 +0000185void
186_mesa_PixelMapfv( GLenum map, GLint mapsize, const GLfloat *values )
jtgafb833d1999-08-19 00:55:39 +0000187{
188 GLint i;
Brian Paulfbd8f211999-11-11 01:22:25 +0000189 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000190 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPixelMapfv");
191
192
193 if (mapsize<0 || mapsize>MAX_PIXEL_MAP_TABLE) {
194 gl_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
195 return;
196 }
197
198 if (map>=GL_PIXEL_MAP_S_TO_S && map<=GL_PIXEL_MAP_I_TO_A) {
199 /* test that mapsize is a power of two */
200 GLuint p;
201 GLboolean ok = GL_FALSE;
202 for (p=1; p<=MAX_PIXEL_MAP_TABLE; p=p<<1) {
203 if ( (p&mapsize) == p ) {
204 ok = GL_TRUE;
205 break;
206 }
207 }
208 if (!ok) {
209 gl_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
210 return;
211 }
212 }
213
214 switch (map) {
215 case GL_PIXEL_MAP_S_TO_S:
216 ctx->Pixel.MapStoSsize = mapsize;
217 for (i=0;i<mapsize;i++) {
218 ctx->Pixel.MapStoS[i] = (GLint) values[i];
219 }
220 break;
221 case GL_PIXEL_MAP_I_TO_I:
222 ctx->Pixel.MapItoIsize = mapsize;
223 for (i=0;i<mapsize;i++) {
224 ctx->Pixel.MapItoI[i] = (GLint) values[i];
225 }
226 break;
227 case GL_PIXEL_MAP_I_TO_R:
228 ctx->Pixel.MapItoRsize = mapsize;
229 for (i=0;i<mapsize;i++) {
230 GLfloat val = CLAMP( values[i], 0.0, 1.0 );
231 ctx->Pixel.MapItoR[i] = val;
232 ctx->Pixel.MapItoR8[i] = (GLint) (val * 255.0F);
233 }
234 break;
235 case GL_PIXEL_MAP_I_TO_G:
236 ctx->Pixel.MapItoGsize = mapsize;
237 for (i=0;i<mapsize;i++) {
238 GLfloat val = CLAMP( values[i], 0.0, 1.0 );
239 ctx->Pixel.MapItoG[i] = val;
240 ctx->Pixel.MapItoG8[i] = (GLint) (val * 255.0F);
241 }
242 break;
243 case GL_PIXEL_MAP_I_TO_B:
244 ctx->Pixel.MapItoBsize = mapsize;
245 for (i=0;i<mapsize;i++) {
246 GLfloat val = CLAMP( values[i], 0.0, 1.0 );
247 ctx->Pixel.MapItoB[i] = val;
248 ctx->Pixel.MapItoB8[i] = (GLint) (val * 255.0F);
249 }
250 break;
251 case GL_PIXEL_MAP_I_TO_A:
252 ctx->Pixel.MapItoAsize = mapsize;
253 for (i=0;i<mapsize;i++) {
254 GLfloat val = CLAMP( values[i], 0.0, 1.0 );
255 ctx->Pixel.MapItoA[i] = val;
256 ctx->Pixel.MapItoA8[i] = (GLint) (val * 255.0F);
257 }
258 break;
259 case GL_PIXEL_MAP_R_TO_R:
260 ctx->Pixel.MapRtoRsize = mapsize;
261 for (i=0;i<mapsize;i++) {
262 ctx->Pixel.MapRtoR[i] = CLAMP( values[i], 0.0, 1.0 );
263 }
264 break;
265 case GL_PIXEL_MAP_G_TO_G:
266 ctx->Pixel.MapGtoGsize = mapsize;
267 for (i=0;i<mapsize;i++) {
268 ctx->Pixel.MapGtoG[i] = CLAMP( values[i], 0.0, 1.0 );
269 }
270 break;
271 case GL_PIXEL_MAP_B_TO_B:
272 ctx->Pixel.MapBtoBsize = mapsize;
273 for (i=0;i<mapsize;i++) {
274 ctx->Pixel.MapBtoB[i] = CLAMP( values[i], 0.0, 1.0 );
275 }
276 break;
277 case GL_PIXEL_MAP_A_TO_A:
278 ctx->Pixel.MapAtoAsize = mapsize;
279 for (i=0;i<mapsize;i++) {
280 ctx->Pixel.MapAtoA[i] = CLAMP( values[i], 0.0, 1.0 );
281 }
282 break;
283 default:
284 gl_error( ctx, GL_INVALID_ENUM, "glPixelMapfv(map)" );
285 }
286}
287
288
289
Brian Paulfbd8f211999-11-11 01:22:25 +0000290void
291_mesa_PixelMapuiv(GLenum map, GLint mapsize, const GLuint *values )
jtgafb833d1999-08-19 00:55:39 +0000292{
Brian Paulfbd8f211999-11-11 01:22:25 +0000293 GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
294 GLint i;
295 if (map==GL_PIXEL_MAP_I_TO_I || map==GL_PIXEL_MAP_S_TO_S) {
296 for (i=0;i<mapsize;i++) {
297 fvalues[i] = (GLfloat) values[i];
298 }
299 }
300 else {
301 for (i=0;i<mapsize;i++) {
302 fvalues[i] = UINT_TO_FLOAT( values[i] );
303 }
304 }
305 _mesa_PixelMapfv(map, mapsize, fvalues);
306}
307
308
309
310void
311_mesa_PixelMapusv(GLenum map, GLint mapsize, const GLushort *values )
312{
313 GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
314 GLint i;
315 if (map==GL_PIXEL_MAP_I_TO_I || map==GL_PIXEL_MAP_S_TO_S) {
316 for (i=0;i<mapsize;i++) {
317 fvalues[i] = (GLfloat) values[i];
318 }
319 }
320 else {
321 for (i=0;i<mapsize;i++) {
322 fvalues[i] = USHORT_TO_FLOAT( values[i] );
323 }
324 }
325 _mesa_PixelMapfv(map, mapsize, fvalues);
326}
327
328
329
330void
331_mesa_GetPixelMapfv( GLenum map, GLfloat *values )
332{
333 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000334 GLint i;
335
336 ASSERT_OUTSIDE_BEGIN_END(ctx, "glGetPixelMapfv");
337
338 switch (map) {
339 case GL_PIXEL_MAP_I_TO_I:
340 for (i=0;i<ctx->Pixel.MapItoIsize;i++) {
341 values[i] = (GLfloat) ctx->Pixel.MapItoI[i];
342 }
343 break;
344 case GL_PIXEL_MAP_S_TO_S:
345 for (i=0;i<ctx->Pixel.MapStoSsize;i++) {
346 values[i] = (GLfloat) ctx->Pixel.MapStoS[i];
347 }
348 break;
349 case GL_PIXEL_MAP_I_TO_R:
350 MEMCPY(values,ctx->Pixel.MapItoR,ctx->Pixel.MapItoRsize*sizeof(GLfloat));
351 break;
352 case GL_PIXEL_MAP_I_TO_G:
353 MEMCPY(values,ctx->Pixel.MapItoG,ctx->Pixel.MapItoGsize*sizeof(GLfloat));
354 break;
355 case GL_PIXEL_MAP_I_TO_B:
356 MEMCPY(values,ctx->Pixel.MapItoB,ctx->Pixel.MapItoBsize*sizeof(GLfloat));
357 break;
358 case GL_PIXEL_MAP_I_TO_A:
359 MEMCPY(values,ctx->Pixel.MapItoA,ctx->Pixel.MapItoAsize*sizeof(GLfloat));
360 break;
361 case GL_PIXEL_MAP_R_TO_R:
362 MEMCPY(values,ctx->Pixel.MapRtoR,ctx->Pixel.MapRtoRsize*sizeof(GLfloat));
363 break;
364 case GL_PIXEL_MAP_G_TO_G:
365 MEMCPY(values,ctx->Pixel.MapGtoG,ctx->Pixel.MapGtoGsize*sizeof(GLfloat));
366 break;
367 case GL_PIXEL_MAP_B_TO_B:
368 MEMCPY(values,ctx->Pixel.MapBtoB,ctx->Pixel.MapBtoBsize*sizeof(GLfloat));
369 break;
370 case GL_PIXEL_MAP_A_TO_A:
371 MEMCPY(values,ctx->Pixel.MapAtoA,ctx->Pixel.MapAtoAsize*sizeof(GLfloat));
372 break;
373 default:
374 gl_error( ctx, GL_INVALID_ENUM, "glGetPixelMapfv" );
375 }
376}
377
378
Brian Paulfbd8f211999-11-11 01:22:25 +0000379void
380_mesa_GetPixelMapuiv( GLenum map, GLuint *values )
jtgafb833d1999-08-19 00:55:39 +0000381{
Brian Paulfbd8f211999-11-11 01:22:25 +0000382 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000383 GLint i;
384
385 ASSERT_OUTSIDE_BEGIN_END(ctx, "glGetPixelMapfv");
386
387 switch (map) {
388 case GL_PIXEL_MAP_I_TO_I:
389 MEMCPY(values, ctx->Pixel.MapItoI, ctx->Pixel.MapItoIsize*sizeof(GLint));
390 break;
391 case GL_PIXEL_MAP_S_TO_S:
392 MEMCPY(values, ctx->Pixel.MapStoS, ctx->Pixel.MapStoSsize*sizeof(GLint));
393 break;
394 case GL_PIXEL_MAP_I_TO_R:
395 for (i=0;i<ctx->Pixel.MapItoRsize;i++) {
396 values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoR[i] );
397 }
398 break;
399 case GL_PIXEL_MAP_I_TO_G:
400 for (i=0;i<ctx->Pixel.MapItoGsize;i++) {
401 values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoG[i] );
402 }
403 break;
404 case GL_PIXEL_MAP_I_TO_B:
405 for (i=0;i<ctx->Pixel.MapItoBsize;i++) {
406 values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoB[i] );
407 }
408 break;
409 case GL_PIXEL_MAP_I_TO_A:
410 for (i=0;i<ctx->Pixel.MapItoAsize;i++) {
411 values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoA[i] );
412 }
413 break;
414 case GL_PIXEL_MAP_R_TO_R:
415 for (i=0;i<ctx->Pixel.MapRtoRsize;i++) {
416 values[i] = FLOAT_TO_UINT( ctx->Pixel.MapRtoR[i] );
417 }
418 break;
419 case GL_PIXEL_MAP_G_TO_G:
420 for (i=0;i<ctx->Pixel.MapGtoGsize;i++) {
421 values[i] = FLOAT_TO_UINT( ctx->Pixel.MapGtoG[i] );
422 }
423 break;
424 case GL_PIXEL_MAP_B_TO_B:
425 for (i=0;i<ctx->Pixel.MapBtoBsize;i++) {
426 values[i] = FLOAT_TO_UINT( ctx->Pixel.MapBtoB[i] );
427 }
428 break;
429 case GL_PIXEL_MAP_A_TO_A:
430 for (i=0;i<ctx->Pixel.MapAtoAsize;i++) {
431 values[i] = FLOAT_TO_UINT( ctx->Pixel.MapAtoA[i] );
432 }
433 break;
434 default:
435 gl_error( ctx, GL_INVALID_ENUM, "glGetPixelMapfv" );
436 }
437}
438
439
Brian Paulfbd8f211999-11-11 01:22:25 +0000440void
441_mesa_GetPixelMapusv( GLenum map, GLushort *values )
jtgafb833d1999-08-19 00:55:39 +0000442{
Brian Paulfbd8f211999-11-11 01:22:25 +0000443 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000444 GLint i;
445
446 ASSERT_OUTSIDE_BEGIN_END(ctx, "glGetPixelMapfv");
447
448 switch (map) {
449 case GL_PIXEL_MAP_I_TO_I:
450 for (i=0;i<ctx->Pixel.MapItoIsize;i++) {
451 values[i] = (GLushort) ctx->Pixel.MapItoI[i];
452 }
453 break;
454 case GL_PIXEL_MAP_S_TO_S:
455 for (i=0;i<ctx->Pixel.MapStoSsize;i++) {
456 values[i] = (GLushort) ctx->Pixel.MapStoS[i];
457 }
458 break;
459 case GL_PIXEL_MAP_I_TO_R:
460 for (i=0;i<ctx->Pixel.MapItoRsize;i++) {
461 values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoR[i] );
462 }
463 break;
464 case GL_PIXEL_MAP_I_TO_G:
465 for (i=0;i<ctx->Pixel.MapItoGsize;i++) {
466 values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoG[i] );
467 }
468 break;
469 case GL_PIXEL_MAP_I_TO_B:
470 for (i=0;i<ctx->Pixel.MapItoBsize;i++) {
471 values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoB[i] );
472 }
473 break;
474 case GL_PIXEL_MAP_I_TO_A:
475 for (i=0;i<ctx->Pixel.MapItoAsize;i++) {
476 values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoA[i] );
477 }
478 break;
479 case GL_PIXEL_MAP_R_TO_R:
480 for (i=0;i<ctx->Pixel.MapRtoRsize;i++) {
481 values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapRtoR[i] );
482 }
483 break;
484 case GL_PIXEL_MAP_G_TO_G:
485 for (i=0;i<ctx->Pixel.MapGtoGsize;i++) {
486 values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapGtoG[i] );
487 }
488 break;
489 case GL_PIXEL_MAP_B_TO_B:
490 for (i=0;i<ctx->Pixel.MapBtoBsize;i++) {
491 values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapBtoB[i] );
492 }
493 break;
494 case GL_PIXEL_MAP_A_TO_A:
495 for (i=0;i<ctx->Pixel.MapAtoAsize;i++) {
496 values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapAtoA[i] );
497 }
498 break;
499 default:
500 gl_error( ctx, GL_INVALID_ENUM, "glGetPixelMapfv" );
501 }
502}
503
504
505
506/**********************************************************************/
507/***** glPixelTransfer *****/
508/**********************************************************************/
509
510
511/*
512 * Implements glPixelTransfer[fi] whether called immediately or from a
513 * display list.
514 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000515void
516_mesa_PixelTransferf( GLenum pname, GLfloat param )
jtgafb833d1999-08-19 00:55:39 +0000517{
Brian Paulfbd8f211999-11-11 01:22:25 +0000518 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000519 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPixelTransfer");
520
521
522 switch (pname) {
523 case GL_MAP_COLOR:
524 ctx->Pixel.MapColorFlag = param ? GL_TRUE : GL_FALSE;
525 break;
526 case GL_MAP_STENCIL:
527 ctx->Pixel.MapStencilFlag = param ? GL_TRUE : GL_FALSE;
528 break;
529 case GL_INDEX_SHIFT:
530 ctx->Pixel.IndexShift = (GLint) param;
531 break;
532 case GL_INDEX_OFFSET:
533 ctx->Pixel.IndexOffset = (GLint) param;
534 break;
535 case GL_RED_SCALE:
536 ctx->Pixel.RedScale = param;
537 break;
538 case GL_RED_BIAS:
539 ctx->Pixel.RedBias = param;
540 break;
541 case GL_GREEN_SCALE:
542 ctx->Pixel.GreenScale = param;
543 break;
544 case GL_GREEN_BIAS:
545 ctx->Pixel.GreenBias = param;
546 break;
547 case GL_BLUE_SCALE:
548 ctx->Pixel.BlueScale = param;
549 break;
550 case GL_BLUE_BIAS:
551 ctx->Pixel.BlueBias = param;
552 break;
553 case GL_ALPHA_SCALE:
554 ctx->Pixel.AlphaScale = param;
555 break;
556 case GL_ALPHA_BIAS:
557 ctx->Pixel.AlphaBias = param;
558 break;
559 case GL_DEPTH_SCALE:
560 ctx->Pixel.DepthScale = param;
561 break;
562 case GL_DEPTH_BIAS:
563 ctx->Pixel.DepthBias = param;
564 break;
Brian Paul250069d2000-04-08 18:57:45 +0000565 case GL_POST_COLOR_MATRIX_RED_SCALE:
566 ctx->Pixel.PostColorMatrixRedScale = param;
567 break;
568 case GL_POST_COLOR_MATRIX_RED_BIAS:
569 ctx->Pixel.PostColorMatrixRedBias = param;
570 break;
571 case GL_POST_COLOR_MATRIX_GREEN_SCALE:
572 ctx->Pixel.PostColorMatrixGreenScale = param;
573 break;
574 case GL_POST_COLOR_MATRIX_GREEN_BIAS:
575 ctx->Pixel.PostColorMatrixGreenBias = param;
576 break;
577 case GL_POST_COLOR_MATRIX_BLUE_SCALE:
578 ctx->Pixel.PostColorMatrixBlueScale = param;
579 break;
580 case GL_POST_COLOR_MATRIX_BLUE_BIAS:
581 ctx->Pixel.PostColorMatrixBlueBias = param;
582 break;
583 case GL_POST_COLOR_MATRIX_ALPHA_SCALE:
584 ctx->Pixel.PostColorMatrixAlphaScale = param;
585 break;
586 case GL_POST_COLOR_MATRIX_ALPHA_BIAS:
587 ctx->Pixel.PostColorMatrixAlphaBias = param;
588 break;
jtgafb833d1999-08-19 00:55:39 +0000589 default:
590 gl_error( ctx, GL_INVALID_ENUM, "glPixelTransfer(pname)" );
591 return;
592 }
593
594 if (ctx->Pixel.RedScale!=1.0F || ctx->Pixel.RedBias!=0.0F ||
595 ctx->Pixel.GreenScale!=1.0F || ctx->Pixel.GreenBias!=0.0F ||
596 ctx->Pixel.BlueScale!=1.0F || ctx->Pixel.BlueBias!=0.0F ||
597 ctx->Pixel.AlphaScale!=1.0F || ctx->Pixel.AlphaBias!=0.0F) {
598 ctx->Pixel.ScaleOrBiasRGBA = GL_TRUE;
599 }
600 else {
601 ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE;
602 }
Brian Paul250069d2000-04-08 18:57:45 +0000603
604 if (ctx->Pixel.PostColorMatrixRedScale!=1.0F ||
605 ctx->Pixel.PostColorMatrixRedBias!=0.0F ||
606 ctx->Pixel.PostColorMatrixGreenScale!=1.0F ||
607 ctx->Pixel.PostColorMatrixGreenBias!=0.0F ||
608 ctx->Pixel.PostColorMatrixBlueScale!=1.0F ||
609 ctx->Pixel.PostColorMatrixBlueBias!=0.0F ||
610 ctx->Pixel.PostColorMatrixAlphaScale!=1.0F ||
611 ctx->Pixel.PostColorMatrixAlphaBias!=0.0F) {
612 ctx->Pixel.ScaleOrBiasRGBApcm = GL_TRUE;
613 }
614 else {
615 ctx->Pixel.ScaleOrBiasRGBApcm = GL_FALSE;
616 }
jtgafb833d1999-08-19 00:55:39 +0000617}
618
619
Brian Paulfbd8f211999-11-11 01:22:25 +0000620void
621_mesa_PixelTransferi( GLenum pname, GLint param )
622{
623 _mesa_PixelTransferf( pname, (GLfloat) param );
624}
625
626
jtgafb833d1999-08-19 00:55:39 +0000627
628
629/*
630 * Pixel processing functions
631 */
632
633
634/*
635 * Apply scale and bias factors to an array of RGBA pixels.
636 */
637void gl_scale_and_bias_color( const GLcontext *ctx, GLuint n,
638 GLfloat red[], GLfloat green[],
639 GLfloat blue[], GLfloat alpha[] )
640{
641 GLuint i;
642 for (i=0;i<n;i++) {
643 GLfloat r = red[i] * ctx->Pixel.RedScale + ctx->Pixel.RedBias;
644 GLfloat g = green[i] * ctx->Pixel.GreenScale + ctx->Pixel.GreenBias;
645 GLfloat b = blue[i] * ctx->Pixel.BlueScale + ctx->Pixel.BlueBias;
646 GLfloat a = alpha[i] * ctx->Pixel.AlphaScale + ctx->Pixel.AlphaBias;
647 red[i] = CLAMP( r, 0.0F, 1.0F );
648 green[i] = CLAMP( g, 0.0F, 1.0F );
649 blue[i] = CLAMP( b, 0.0F, 1.0F );
650 alpha[i] = CLAMP( a, 0.0F, 1.0F );
651 }
652}
653
654
655/*
656 * Apply scale and bias factors to an array of RGBA pixels.
657 */
658void gl_scale_and_bias_rgba( const GLcontext *ctx, GLuint n, GLubyte rgba[][4] )
659{
660 GLfloat rbias = ctx->Pixel.RedBias * 255.0F;
661 GLfloat gbias = ctx->Pixel.GreenBias * 255.0F;
662 GLfloat bbias = ctx->Pixel.BlueBias * 255.0F;
663 GLfloat abias = ctx->Pixel.AlphaBias * 255.0F;
664 GLuint i;
665 for (i=0;i<n;i++) {
666 GLint r = (GLint) (rgba[i][RCOMP] * ctx->Pixel.RedScale + rbias);
667 GLint g = (GLint) (rgba[i][GCOMP] * ctx->Pixel.GreenScale + gbias);
668 GLint b = (GLint) (rgba[i][BCOMP] * ctx->Pixel.BlueScale + bbias);
669 GLint a = (GLint) (rgba[i][ACOMP] * ctx->Pixel.AlphaScale + abias);
670 rgba[i][RCOMP] = CLAMP( r, 0, 255 );
671 rgba[i][GCOMP] = CLAMP( g, 0, 255 );
672 rgba[i][BCOMP] = CLAMP( b, 0, 255 );
673 rgba[i][ACOMP] = CLAMP( a, 0, 255 );
674 }
675}
676
677
678/*
Brian Paul3c14ec91999-10-30 08:20:57 +0000679 * Apply scale and bias factors to an array of RGBA pixels.
680 */
Brian Paul250069d2000-04-08 18:57:45 +0000681void
682_mesa_scale_and_bias_rgba_float(const GLcontext *ctx, GLuint n,
683 GLfloat rgba[][4])
Brian Paul3c14ec91999-10-30 08:20:57 +0000684{
685 if (ctx->Pixel.RedScale != 1.0 || ctx->Pixel.RedBias != 0.0) {
686 const GLfloat scale = ctx->Pixel.RedScale;
687 const GLfloat bias = ctx->Pixel.RedBias;
688 GLuint i;
689 for (i = 0; i < n; i++) {
690 rgba[i][RCOMP] = rgba[i][RCOMP] * scale + bias;
691 }
692 }
693 if (ctx->Pixel.GreenScale != 1.0 || ctx->Pixel.GreenBias != 0.0) {
694 const GLfloat scale = ctx->Pixel.GreenScale;
695 const GLfloat bias = ctx->Pixel.GreenBias;
696 GLuint i;
697 for (i = 0; i < n; i++) {
698 rgba[i][GCOMP] = rgba[i][GCOMP] * scale + bias;
699 }
700 }
701 if (ctx->Pixel.BlueScale != 1.0 || ctx->Pixel.BlueBias != 0.0) {
702 const GLfloat scale = ctx->Pixel.BlueScale;
703 const GLfloat bias = ctx->Pixel.BlueBias;
704 GLuint i;
705 for (i = 0; i < n; i++) {
706 rgba[i][BCOMP] = rgba[i][BCOMP] * scale + bias;
707 }
708 }
709 if (ctx->Pixel.AlphaScale != 1.0 || ctx->Pixel.AlphaBias != 0.0) {
710 const GLfloat scale = ctx->Pixel.AlphaScale;
711 const GLfloat bias = ctx->Pixel.AlphaBias;
712 GLuint i;
713 for (i = 0; i < n; i++) {
714 rgba[i][ACOMP] = rgba[i][ACOMP] * scale + bias;
715 }
716 }
717}
718
719
720/*
jtgafb833d1999-08-19 00:55:39 +0000721 * Apply pixel mapping to an array of RGBA pixels.
722 */
723void gl_map_rgba( const GLcontext *ctx, GLuint n, GLubyte rgba[][4] )
724{
725 GLfloat rscale = (ctx->Pixel.MapRtoRsize - 1) / 255.0F;
726 GLfloat gscale = (ctx->Pixel.MapGtoGsize - 1) / 255.0F;
727 GLfloat bscale = (ctx->Pixel.MapBtoBsize - 1) / 255.0F;
728 GLfloat ascale = (ctx->Pixel.MapAtoAsize - 1) / 255.0F;
729 GLuint i;
730 for (i=0;i<n;i++) {
731 GLint ir = (GLint) (rgba[i][RCOMP] * rscale);
732 GLint ig = (GLint) (rgba[i][GCOMP] * gscale);
733 GLint ib = (GLint) (rgba[i][BCOMP] * bscale);
734 GLint ia = (GLint) (rgba[i][ACOMP] * ascale);
735 rgba[i][RCOMP] = (GLint) (ctx->Pixel.MapRtoR[ir] * 255.0F);
736 rgba[i][GCOMP] = (GLint) (ctx->Pixel.MapGtoG[ig] * 255.0F);
737 rgba[i][BCOMP] = (GLint) (ctx->Pixel.MapBtoB[ib] * 255.0F);
738 rgba[i][ACOMP] = (GLint) (ctx->Pixel.MapAtoA[ia] * 255.0F);
739 }
740}
741
742
743/*
Brian Paul3c14ec91999-10-30 08:20:57 +0000744 * Apply pixel mapping to an array of floating point RGBA pixels.
745 */
Brian Paul250069d2000-04-08 18:57:45 +0000746void
747_mesa_map_rgba_float( const GLcontext *ctx, GLuint n, GLfloat rgba[][4] )
Brian Paul3c14ec91999-10-30 08:20:57 +0000748{
749 const GLfloat rscale = ctx->Pixel.MapRtoRsize - 1;
750 const GLfloat gscale = ctx->Pixel.MapGtoGsize - 1;
751 const GLfloat bscale = ctx->Pixel.MapBtoBsize - 1;
752 const GLfloat ascale = ctx->Pixel.MapAtoAsize - 1;
753 const GLfloat *rMap = ctx->Pixel.MapRtoR;
754 const GLfloat *gMap = ctx->Pixel.MapGtoG;
755 const GLfloat *bMap = ctx->Pixel.MapBtoB;
756 const GLfloat *aMap = ctx->Pixel.MapAtoA;
757 GLuint i;
758 for (i=0;i<n;i++) {
759 rgba[i][RCOMP] = rMap[(GLint) (rgba[i][RCOMP] * rscale + 0.5F)];
760 rgba[i][GCOMP] = gMap[(GLint) (rgba[i][GCOMP] * gscale + 0.5F)];
761 rgba[i][BCOMP] = bMap[(GLint) (rgba[i][BCOMP] * bscale + 0.5F)];
762 rgba[i][ACOMP] = aMap[(GLint) (rgba[i][ACOMP] * ascale + 0.5F)];
763 }
764}
765
766
767/*
Brian Paul250069d2000-04-08 18:57:45 +0000768 * Apply the color matrix and post color matrix scaling and biasing.
769 */
770void
771_mesa_transform_rgba(const GLcontext *ctx, GLuint n, GLfloat rgba[][4])
772{
773 const GLfloat rs = ctx->Pixel.PostColorMatrixRedScale;
774 const GLfloat rb = ctx->Pixel.PostColorMatrixRedBias;
775 const GLfloat gs = ctx->Pixel.PostColorMatrixGreenScale;
776 const GLfloat gb = ctx->Pixel.PostColorMatrixGreenBias;
777 const GLfloat bs = ctx->Pixel.PostColorMatrixBlueScale;
778 const GLfloat bb = ctx->Pixel.PostColorMatrixBlueBias;
779 const GLfloat as = ctx->Pixel.PostColorMatrixAlphaScale;
780 const GLfloat ab = ctx->Pixel.PostColorMatrixAlphaBias;
781 const GLfloat *m = ctx->ColorMatrix.m;
782 GLuint i;
783 for (i = 0; i < n; i++) {
784 const GLfloat r = rgba[i][RCOMP];
785 const GLfloat g = rgba[i][GCOMP];
786 const GLfloat b = rgba[i][BCOMP];
787 const GLfloat a = rgba[i][ACOMP];
788 rgba[i][RCOMP] = (m[0] * r + m[4] * g + m[ 8] * b + m[12] * a) * rs + rb;
789 rgba[i][GCOMP] = (m[1] * r + m[5] * g + m[ 9] * b + m[13] * a) * gs + gb;
790 rgba[i][BCOMP] = (m[2] * r + m[6] * g + m[10] * b + m[14] * a) * bs + bb;
791 rgba[i][ACOMP] = (m[3] * r + m[7] * g + m[11] * b + m[15] * a) * as + ab;
792 }
793}
794
795
796
797/*
jtgafb833d1999-08-19 00:55:39 +0000798 * Apply pixel mapping to an array of RGBA pixels.
799 */
800void gl_map_color( const GLcontext *ctx, GLuint n,
801 GLfloat red[], GLfloat green[],
802 GLfloat blue[], GLfloat alpha[] )
803{
Brian Paul3c14ec91999-10-30 08:20:57 +0000804 GLfloat rscale = ctx->Pixel.MapRtoRsize - 1;
805 GLfloat gscale = ctx->Pixel.MapGtoGsize - 1;
806 GLfloat bscale = ctx->Pixel.MapBtoBsize - 1;
807 GLfloat ascale = ctx->Pixel.MapAtoAsize - 1;
jtgafb833d1999-08-19 00:55:39 +0000808 GLuint i;
809 for (i=0;i<n;i++) {
Brian Paul3c14ec91999-10-30 08:20:57 +0000810 red[i] = ctx->Pixel.MapRtoR[ (GLint) (red[i] * rscale + 0.5F) ];
811 green[i] = ctx->Pixel.MapGtoG[ (GLint) (green[i] * gscale + 0.5F) ];
812 blue[i] = ctx->Pixel.MapBtoB[ (GLint) (blue[i] * bscale + 0.5F) ];
813 alpha[i] = ctx->Pixel.MapAtoA[ (GLint) (alpha[i] * ascale + 0.5F) ];
jtgafb833d1999-08-19 00:55:39 +0000814 }
815}
816
817
818
819/*
820 * Apply color index shift and offset to an array of pixels.
821 */
822void gl_shift_and_offset_ci( const GLcontext *ctx, GLuint n, GLuint indexes[] )
823{
824 GLint shift = ctx->Pixel.IndexShift;
825 GLint offset = ctx->Pixel.IndexOffset;
826 GLuint i;
827 if (shift > 0) {
828 for (i=0;i<n;i++) {
829 indexes[i] = (indexes[i] << shift) + offset;
830 }
831 }
832 else if (shift < 0) {
833 shift = -shift;
834 for (i=0;i<n;i++) {
835 indexes[i] = (indexes[i] >> shift) + offset;
836 }
837 }
838 else {
839 for (i=0;i<n;i++) {
840 indexes[i] = indexes[i] + offset;
841 }
842 }
843}
844
845
846/*
847 * Apply color index mapping to color indexes.
848 */
849void gl_map_ci( const GLcontext *ctx, GLuint n, GLuint index[] )
850{
851 GLuint mask = ctx->Pixel.MapItoIsize - 1;
852 GLuint i;
853 for (i=0;i<n;i++) {
854 index[i] = ctx->Pixel.MapItoI[ index[i] & mask ];
855 }
856}
857
858
859/*
Brian Paul3c14ec91999-10-30 08:20:57 +0000860 * Map color indexes to rgba values.
jtgafb833d1999-08-19 00:55:39 +0000861 */
862void gl_map_ci_to_rgba( const GLcontext *ctx, GLuint n, const GLuint index[],
863 GLubyte rgba[][4] )
864{
865 GLuint rmask = ctx->Pixel.MapItoRsize - 1;
866 GLuint gmask = ctx->Pixel.MapItoGsize - 1;
867 GLuint bmask = ctx->Pixel.MapItoBsize - 1;
868 GLuint amask = ctx->Pixel.MapItoAsize - 1;
869 const GLubyte *rMap = ctx->Pixel.MapItoR8;
870 const GLubyte *gMap = ctx->Pixel.MapItoG8;
871 const GLubyte *bMap = ctx->Pixel.MapItoB8;
872 const GLubyte *aMap = ctx->Pixel.MapItoA8;
873 GLuint i;
874 for (i=0;i<n;i++) {
875 rgba[i][RCOMP] = rMap[index[i] & rmask];
876 rgba[i][GCOMP] = gMap[index[i] & gmask];
877 rgba[i][BCOMP] = bMap[index[i] & bmask];
878 rgba[i][ACOMP] = aMap[index[i] & amask];
879 }
880}
881
882
883/*
Brian Paul3c14ec91999-10-30 08:20:57 +0000884 * Map color indexes to float rgba values.
885 */
886void gl_map_ci_to_rgba_float( const GLcontext *ctx, GLuint n, const GLuint index[],
887 GLfloat rgba[][4] )
888{
889 GLuint rmask = ctx->Pixel.MapItoRsize - 1;
890 GLuint gmask = ctx->Pixel.MapItoGsize - 1;
891 GLuint bmask = ctx->Pixel.MapItoBsize - 1;
892 GLuint amask = ctx->Pixel.MapItoAsize - 1;
893 const GLfloat *rMap = ctx->Pixel.MapItoR;
894 const GLfloat *gMap = ctx->Pixel.MapItoG;
895 const GLfloat *bMap = ctx->Pixel.MapItoB;
896 const GLfloat *aMap = ctx->Pixel.MapItoA;
897 GLuint i;
898 for (i=0;i<n;i++) {
899 rgba[i][RCOMP] = rMap[index[i] & rmask];
900 rgba[i][GCOMP] = gMap[index[i] & gmask];
901 rgba[i][BCOMP] = bMap[index[i] & bmask];
902 rgba[i][ACOMP] = aMap[index[i] & amask];
903 }
904}
905
906
907/*
jtgafb833d1999-08-19 00:55:39 +0000908 * Map 8-bit color indexes to rgb values.
909 */
910void gl_map_ci8_to_rgba( const GLcontext *ctx, GLuint n, const GLubyte index[],
911 GLubyte rgba[][4] )
912{
913 GLuint rmask = ctx->Pixel.MapItoRsize - 1;
914 GLuint gmask = ctx->Pixel.MapItoGsize - 1;
915 GLuint bmask = ctx->Pixel.MapItoBsize - 1;
916 GLuint amask = ctx->Pixel.MapItoAsize - 1;
917 const GLubyte *rMap = ctx->Pixel.MapItoR8;
918 const GLubyte *gMap = ctx->Pixel.MapItoG8;
919 const GLubyte *bMap = ctx->Pixel.MapItoB8;
920 const GLubyte *aMap = ctx->Pixel.MapItoA8;
921 GLuint i;
922 for (i=0;i<n;i++) {
923 rgba[i][RCOMP] = rMap[index[i] & rmask];
924 rgba[i][GCOMP] = gMap[index[i] & gmask];
925 rgba[i][BCOMP] = bMap[index[i] & bmask];
926 rgba[i][ACOMP] = aMap[index[i] & amask];
927 }
928}
929
930
931void gl_map_ci_to_color( const GLcontext *ctx, GLuint n, const GLuint index[],
932 GLfloat r[], GLfloat g[],
933 GLfloat b[], GLfloat a[] )
934{
935 GLuint rmask = ctx->Pixel.MapItoRsize - 1;
936 GLuint gmask = ctx->Pixel.MapItoGsize - 1;
937 GLuint bmask = ctx->Pixel.MapItoBsize - 1;
938 GLuint amask = ctx->Pixel.MapItoAsize - 1;
939 GLuint i;
940 for (i=0;i<n;i++) {
941 r[i] = ctx->Pixel.MapItoR[index[i] & rmask];
942 g[i] = ctx->Pixel.MapItoG[index[i] & gmask];
943 b[i] = ctx->Pixel.MapItoB[index[i] & bmask];
944 a[i] = ctx->Pixel.MapItoA[index[i] & amask];
945 }
946}
947
948
949
950void gl_shift_and_offset_stencil( const GLcontext *ctx, GLuint n,
951 GLstencil stencil[] )
952{
953 GLuint i;
954 GLint shift = ctx->Pixel.IndexShift;
955 GLint offset = ctx->Pixel.IndexOffset;
956 if (shift > 0) {
957 for (i=0;i<n;i++) {
958 stencil[i] = (stencil[i] << shift) + offset;
959 }
960 }
961 else if (shift < 0) {
962 shift = -shift;
963 for (i=0;i<n;i++) {
964 stencil[i] = (stencil[i] >> shift) + offset;
965 }
966 }
967 else {
968 for (i=0;i<n;i++) {
969 stencil[i] = stencil[i] + offset;
970 }
971 }
972
973}
974
975
976
977void gl_map_stencil( const GLcontext *ctx, GLuint n, GLstencil stencil[] )
978{
979 GLuint mask = ctx->Pixel.MapStoSsize - 1;
980 GLuint i;
981 for (i=0;i<n;i++) {
982 stencil[i] = ctx->Pixel.MapStoS[ stencil[i] & mask ];
983 }
984}
985