1 /* $Id: pixel.c,v 1.5 1999/11/11 01:22:27 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * glPixelStore, glPixelTransfer, glPixelMap, glPixelZoom, etc.
46 /**********************************************************************/
47 /***** glPixelZoom *****/
48 /**********************************************************************/
53 _mesa_PixelZoom( GLfloat xfactor
, GLfloat yfactor
)
55 GET_CURRENT_CONTEXT(ctx
);
56 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPixelZoom");
58 ctx
->Pixel
.ZoomX
= xfactor
;
59 ctx
->Pixel
.ZoomY
= yfactor
;
64 /**********************************************************************/
65 /***** glPixelStore *****/
66 /**********************************************************************/
70 _mesa_PixelStorei( GLenum pname
, GLint param
)
72 /* NOTE: this call can't be compiled into the display list */
73 GET_CURRENT_CONTEXT(ctx
);
74 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPixelStore");
77 case GL_PACK_SWAP_BYTES
:
78 ctx
->Pack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
80 case GL_PACK_LSB_FIRST
:
81 ctx
->Pack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
83 case GL_PACK_ROW_LENGTH
:
85 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
88 ctx
->Pack
.RowLength
= param
;
91 case GL_PACK_IMAGE_HEIGHT
:
93 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
95 ctx
->Pack
.ImageHeight
= param
;
97 case GL_PACK_SKIP_PIXELS
:
99 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
102 ctx
->Pack
.SkipPixels
= param
;
105 case GL_PACK_SKIP_ROWS
:
107 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
110 ctx
->Pack
.SkipRows
= param
;
113 case GL_PACK_ALIGNMENT
:
114 if (param
==1 || param
==2 || param
==4 || param
==8) {
115 ctx
->Pack
.Alignment
= param
;
118 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
121 case GL_UNPACK_SWAP_BYTES
:
122 ctx
->Unpack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
124 case GL_UNPACK_LSB_FIRST
:
125 ctx
->Unpack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
127 case GL_UNPACK_ROW_LENGTH
:
129 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
132 ctx
->Unpack
.RowLength
= param
;
135 case GL_UNPACK_IMAGE_HEIGHT
:
137 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
139 ctx
->Unpack
.ImageHeight
= param
;
141 case GL_UNPACK_SKIP_PIXELS
:
143 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
146 ctx
->Unpack
.SkipPixels
= param
;
149 case GL_UNPACK_SKIP_ROWS
:
151 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
154 ctx
->Unpack
.SkipRows
= param
;
157 case GL_UNPACK_ALIGNMENT
:
158 if (param
==1 || param
==2 || param
==4 || param
==8) {
159 ctx
->Unpack
.Alignment
= param
;
162 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore" );
166 gl_error( ctx
, GL_INVALID_ENUM
, "glPixelStore" );
172 _mesa_PixelStoref( GLenum pname
, GLfloat param
)
174 _mesa_PixelStorei( pname
, (GLint
) param
);
179 /**********************************************************************/
180 /***** glPixelMap *****/
181 /**********************************************************************/
186 _mesa_PixelMapfv( GLenum map
, GLint mapsize
, const GLfloat
*values
)
189 GET_CURRENT_CONTEXT(ctx
);
190 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPixelMapfv");
193 if (mapsize
<0 || mapsize
>MAX_PIXEL_MAP_TABLE
) {
194 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelMapfv(mapsize)" );
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 */
201 GLboolean ok
= GL_FALSE
;
202 for (p
=1; p
<=MAX_PIXEL_MAP_TABLE
; p
=p
<<1) {
203 if ( (p
&mapsize
) == p
) {
209 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelMapfv(mapsize)" );
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
];
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
];
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
);
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
);
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
);
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
);
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 );
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 );
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 );
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 );
284 gl_error( ctx
, GL_INVALID_ENUM
, "glPixelMapfv(map)" );
291 _mesa_PixelMapuiv(GLenum map
, GLint mapsize
, const GLuint
*values
)
293 GLfloat fvalues
[MAX_PIXEL_MAP_TABLE
];
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
];
301 for (i
=0;i
<mapsize
;i
++) {
302 fvalues
[i
] = UINT_TO_FLOAT( values
[i
] );
305 _mesa_PixelMapfv(map
, mapsize
, fvalues
);
311 _mesa_PixelMapusv(GLenum map
, GLint mapsize
, const GLushort
*values
)
313 GLfloat fvalues
[MAX_PIXEL_MAP_TABLE
];
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
];
321 for (i
=0;i
<mapsize
;i
++) {
322 fvalues
[i
] = USHORT_TO_FLOAT( values
[i
] );
325 _mesa_PixelMapfv(map
, mapsize
, fvalues
);
331 _mesa_GetPixelMapfv( GLenum map
, GLfloat
*values
)
333 GET_CURRENT_CONTEXT(ctx
);
336 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetPixelMapfv");
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
];
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
];
349 case GL_PIXEL_MAP_I_TO_R
:
350 MEMCPY(values
,ctx
->Pixel
.MapItoR
,ctx
->Pixel
.MapItoRsize
*sizeof(GLfloat
));
352 case GL_PIXEL_MAP_I_TO_G
:
353 MEMCPY(values
,ctx
->Pixel
.MapItoG
,ctx
->Pixel
.MapItoGsize
*sizeof(GLfloat
));
355 case GL_PIXEL_MAP_I_TO_B
:
356 MEMCPY(values
,ctx
->Pixel
.MapItoB
,ctx
->Pixel
.MapItoBsize
*sizeof(GLfloat
));
358 case GL_PIXEL_MAP_I_TO_A
:
359 MEMCPY(values
,ctx
->Pixel
.MapItoA
,ctx
->Pixel
.MapItoAsize
*sizeof(GLfloat
));
361 case GL_PIXEL_MAP_R_TO_R
:
362 MEMCPY(values
,ctx
->Pixel
.MapRtoR
,ctx
->Pixel
.MapRtoRsize
*sizeof(GLfloat
));
364 case GL_PIXEL_MAP_G_TO_G
:
365 MEMCPY(values
,ctx
->Pixel
.MapGtoG
,ctx
->Pixel
.MapGtoGsize
*sizeof(GLfloat
));
367 case GL_PIXEL_MAP_B_TO_B
:
368 MEMCPY(values
,ctx
->Pixel
.MapBtoB
,ctx
->Pixel
.MapBtoBsize
*sizeof(GLfloat
));
370 case GL_PIXEL_MAP_A_TO_A
:
371 MEMCPY(values
,ctx
->Pixel
.MapAtoA
,ctx
->Pixel
.MapAtoAsize
*sizeof(GLfloat
));
374 gl_error( ctx
, GL_INVALID_ENUM
, "glGetPixelMapfv" );
380 _mesa_GetPixelMapuiv( GLenum map
, GLuint
*values
)
382 GET_CURRENT_CONTEXT(ctx
);
385 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetPixelMapfv");
388 case GL_PIXEL_MAP_I_TO_I
:
389 MEMCPY(values
, ctx
->Pixel
.MapItoI
, ctx
->Pixel
.MapItoIsize
*sizeof(GLint
));
391 case GL_PIXEL_MAP_S_TO_S
:
392 MEMCPY(values
, ctx
->Pixel
.MapStoS
, ctx
->Pixel
.MapStoSsize
*sizeof(GLint
));
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
] );
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
] );
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
] );
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
] );
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
] );
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
] );
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
] );
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
] );
435 gl_error( ctx
, GL_INVALID_ENUM
, "glGetPixelMapfv" );
441 _mesa_GetPixelMapusv( GLenum map
, GLushort
*values
)
443 GET_CURRENT_CONTEXT(ctx
);
446 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetPixelMapfv");
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
];
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
];
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
] );
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
] );
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
] );
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
] );
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
] );
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
] );
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
] );
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
] );
500 gl_error( ctx
, GL_INVALID_ENUM
, "glGetPixelMapfv" );
506 /**********************************************************************/
507 /***** glPixelTransfer *****/
508 /**********************************************************************/
512 * Implements glPixelTransfer[fi] whether called immediately or from a
516 _mesa_PixelTransferf( GLenum pname
, GLfloat param
)
518 GET_CURRENT_CONTEXT(ctx
);
519 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPixelTransfer");
524 ctx
->Pixel
.MapColorFlag
= param
? GL_TRUE
: GL_FALSE
;
527 ctx
->Pixel
.MapStencilFlag
= param
? GL_TRUE
: GL_FALSE
;
530 ctx
->Pixel
.IndexShift
= (GLint
) param
;
532 case GL_INDEX_OFFSET
:
533 ctx
->Pixel
.IndexOffset
= (GLint
) param
;
536 ctx
->Pixel
.RedScale
= param
;
539 ctx
->Pixel
.RedBias
= param
;
542 ctx
->Pixel
.GreenScale
= param
;
545 ctx
->Pixel
.GreenBias
= param
;
548 ctx
->Pixel
.BlueScale
= param
;
551 ctx
->Pixel
.BlueBias
= param
;
554 ctx
->Pixel
.AlphaScale
= param
;
557 ctx
->Pixel
.AlphaBias
= param
;
560 ctx
->Pixel
.DepthScale
= param
;
563 ctx
->Pixel
.DepthBias
= param
;
566 gl_error( ctx
, GL_INVALID_ENUM
, "glPixelTransfer(pname)" );
570 if (ctx
->Pixel
.RedScale
!=1.0F
|| ctx
->Pixel
.RedBias
!=0.0F
||
571 ctx
->Pixel
.GreenScale
!=1.0F
|| ctx
->Pixel
.GreenBias
!=0.0F
||
572 ctx
->Pixel
.BlueScale
!=1.0F
|| ctx
->Pixel
.BlueBias
!=0.0F
||
573 ctx
->Pixel
.AlphaScale
!=1.0F
|| ctx
->Pixel
.AlphaBias
!=0.0F
) {
574 ctx
->Pixel
.ScaleOrBiasRGBA
= GL_TRUE
;
577 ctx
->Pixel
.ScaleOrBiasRGBA
= GL_FALSE
;
583 _mesa_PixelTransferi( GLenum pname
, GLint param
)
585 _mesa_PixelTransferf( pname
, (GLfloat
) param
);
592 * Pixel processing functions
597 * Apply scale and bias factors to an array of RGBA pixels.
599 void gl_scale_and_bias_color( const GLcontext
*ctx
, GLuint n
,
600 GLfloat red
[], GLfloat green
[],
601 GLfloat blue
[], GLfloat alpha
[] )
605 GLfloat r
= red
[i
] * ctx
->Pixel
.RedScale
+ ctx
->Pixel
.RedBias
;
606 GLfloat g
= green
[i
] * ctx
->Pixel
.GreenScale
+ ctx
->Pixel
.GreenBias
;
607 GLfloat b
= blue
[i
] * ctx
->Pixel
.BlueScale
+ ctx
->Pixel
.BlueBias
;
608 GLfloat a
= alpha
[i
] * ctx
->Pixel
.AlphaScale
+ ctx
->Pixel
.AlphaBias
;
609 red
[i
] = CLAMP( r
, 0.0F
, 1.0F
);
610 green
[i
] = CLAMP( g
, 0.0F
, 1.0F
);
611 blue
[i
] = CLAMP( b
, 0.0F
, 1.0F
);
612 alpha
[i
] = CLAMP( a
, 0.0F
, 1.0F
);
618 * Apply scale and bias factors to an array of RGBA pixels.
620 void gl_scale_and_bias_rgba( const GLcontext
*ctx
, GLuint n
, GLubyte rgba
[][4] )
622 GLfloat rbias
= ctx
->Pixel
.RedBias
* 255.0F
;
623 GLfloat gbias
= ctx
->Pixel
.GreenBias
* 255.0F
;
624 GLfloat bbias
= ctx
->Pixel
.BlueBias
* 255.0F
;
625 GLfloat abias
= ctx
->Pixel
.AlphaBias
* 255.0F
;
628 GLint r
= (GLint
) (rgba
[i
][RCOMP
] * ctx
->Pixel
.RedScale
+ rbias
);
629 GLint g
= (GLint
) (rgba
[i
][GCOMP
] * ctx
->Pixel
.GreenScale
+ gbias
);
630 GLint b
= (GLint
) (rgba
[i
][BCOMP
] * ctx
->Pixel
.BlueScale
+ bbias
);
631 GLint a
= (GLint
) (rgba
[i
][ACOMP
] * ctx
->Pixel
.AlphaScale
+ abias
);
632 rgba
[i
][RCOMP
] = CLAMP( r
, 0, 255 );
633 rgba
[i
][GCOMP
] = CLAMP( g
, 0, 255 );
634 rgba
[i
][BCOMP
] = CLAMP( b
, 0, 255 );
635 rgba
[i
][ACOMP
] = CLAMP( a
, 0, 255 );
641 * Apply scale and bias factors to an array of RGBA pixels.
643 void gl_scale_and_bias_rgba_float( const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4] )
645 if (ctx
->Pixel
.RedScale
!= 1.0 || ctx
->Pixel
.RedBias
!= 0.0) {
646 const GLfloat scale
= ctx
->Pixel
.RedScale
;
647 const GLfloat bias
= ctx
->Pixel
.RedBias
;
649 for (i
= 0; i
< n
; i
++) {
650 rgba
[i
][RCOMP
] = rgba
[i
][RCOMP
] * scale
+ bias
;
653 if (ctx
->Pixel
.GreenScale
!= 1.0 || ctx
->Pixel
.GreenBias
!= 0.0) {
654 const GLfloat scale
= ctx
->Pixel
.GreenScale
;
655 const GLfloat bias
= ctx
->Pixel
.GreenBias
;
657 for (i
= 0; i
< n
; i
++) {
658 rgba
[i
][GCOMP
] = rgba
[i
][GCOMP
] * scale
+ bias
;
661 if (ctx
->Pixel
.BlueScale
!= 1.0 || ctx
->Pixel
.BlueBias
!= 0.0) {
662 const GLfloat scale
= ctx
->Pixel
.BlueScale
;
663 const GLfloat bias
= ctx
->Pixel
.BlueBias
;
665 for (i
= 0; i
< n
; i
++) {
666 rgba
[i
][BCOMP
] = rgba
[i
][BCOMP
] * scale
+ bias
;
669 if (ctx
->Pixel
.AlphaScale
!= 1.0 || ctx
->Pixel
.AlphaBias
!= 0.0) {
670 const GLfloat scale
= ctx
->Pixel
.AlphaScale
;
671 const GLfloat bias
= ctx
->Pixel
.AlphaBias
;
673 for (i
= 0; i
< n
; i
++) {
674 rgba
[i
][ACOMP
] = rgba
[i
][ACOMP
] * scale
+ bias
;
681 * Apply pixel mapping to an array of RGBA pixels.
683 void gl_map_rgba( const GLcontext
*ctx
, GLuint n
, GLubyte rgba
[][4] )
685 GLfloat rscale
= (ctx
->Pixel
.MapRtoRsize
- 1) / 255.0F
;
686 GLfloat gscale
= (ctx
->Pixel
.MapGtoGsize
- 1) / 255.0F
;
687 GLfloat bscale
= (ctx
->Pixel
.MapBtoBsize
- 1) / 255.0F
;
688 GLfloat ascale
= (ctx
->Pixel
.MapAtoAsize
- 1) / 255.0F
;
691 GLint ir
= (GLint
) (rgba
[i
][RCOMP
] * rscale
);
692 GLint ig
= (GLint
) (rgba
[i
][GCOMP
] * gscale
);
693 GLint ib
= (GLint
) (rgba
[i
][BCOMP
] * bscale
);
694 GLint ia
= (GLint
) (rgba
[i
][ACOMP
] * ascale
);
695 rgba
[i
][RCOMP
] = (GLint
) (ctx
->Pixel
.MapRtoR
[ir
] * 255.0F
);
696 rgba
[i
][GCOMP
] = (GLint
) (ctx
->Pixel
.MapGtoG
[ig
] * 255.0F
);
697 rgba
[i
][BCOMP
] = (GLint
) (ctx
->Pixel
.MapBtoB
[ib
] * 255.0F
);
698 rgba
[i
][ACOMP
] = (GLint
) (ctx
->Pixel
.MapAtoA
[ia
] * 255.0F
);
704 * Apply pixel mapping to an array of floating point RGBA pixels.
706 void gl_map_rgba_float( const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4] )
708 const GLfloat rscale
= ctx
->Pixel
.MapRtoRsize
- 1;
709 const GLfloat gscale
= ctx
->Pixel
.MapGtoGsize
- 1;
710 const GLfloat bscale
= ctx
->Pixel
.MapBtoBsize
- 1;
711 const GLfloat ascale
= ctx
->Pixel
.MapAtoAsize
- 1;
712 const GLfloat
*rMap
= ctx
->Pixel
.MapRtoR
;
713 const GLfloat
*gMap
= ctx
->Pixel
.MapGtoG
;
714 const GLfloat
*bMap
= ctx
->Pixel
.MapBtoB
;
715 const GLfloat
*aMap
= ctx
->Pixel
.MapAtoA
;
718 rgba
[i
][RCOMP
] = rMap
[(GLint
) (rgba
[i
][RCOMP
] * rscale
+ 0.5F
)];
719 rgba
[i
][GCOMP
] = gMap
[(GLint
) (rgba
[i
][GCOMP
] * gscale
+ 0.5F
)];
720 rgba
[i
][BCOMP
] = bMap
[(GLint
) (rgba
[i
][BCOMP
] * bscale
+ 0.5F
)];
721 rgba
[i
][ACOMP
] = aMap
[(GLint
) (rgba
[i
][ACOMP
] * ascale
+ 0.5F
)];
727 * Apply pixel mapping to an array of RGBA pixels.
729 void gl_map_color( const GLcontext
*ctx
, GLuint n
,
730 GLfloat red
[], GLfloat green
[],
731 GLfloat blue
[], GLfloat alpha
[] )
733 GLfloat rscale
= ctx
->Pixel
.MapRtoRsize
- 1;
734 GLfloat gscale
= ctx
->Pixel
.MapGtoGsize
- 1;
735 GLfloat bscale
= ctx
->Pixel
.MapBtoBsize
- 1;
736 GLfloat ascale
= ctx
->Pixel
.MapAtoAsize
- 1;
739 red
[i
] = ctx
->Pixel
.MapRtoR
[ (GLint
) (red
[i
] * rscale
+ 0.5F
) ];
740 green
[i
] = ctx
->Pixel
.MapGtoG
[ (GLint
) (green
[i
] * gscale
+ 0.5F
) ];
741 blue
[i
] = ctx
->Pixel
.MapBtoB
[ (GLint
) (blue
[i
] * bscale
+ 0.5F
) ];
742 alpha
[i
] = ctx
->Pixel
.MapAtoA
[ (GLint
) (alpha
[i
] * ascale
+ 0.5F
) ];
749 * Apply color index shift and offset to an array of pixels.
751 void gl_shift_and_offset_ci( const GLcontext
*ctx
, GLuint n
, GLuint indexes
[] )
753 GLint shift
= ctx
->Pixel
.IndexShift
;
754 GLint offset
= ctx
->Pixel
.IndexOffset
;
758 indexes
[i
] = (indexes
[i
] << shift
) + offset
;
761 else if (shift
< 0) {
764 indexes
[i
] = (indexes
[i
] >> shift
) + offset
;
769 indexes
[i
] = indexes
[i
] + offset
;
776 * Apply color index mapping to color indexes.
778 void gl_map_ci( const GLcontext
*ctx
, GLuint n
, GLuint index
[] )
780 GLuint mask
= ctx
->Pixel
.MapItoIsize
- 1;
783 index
[i
] = ctx
->Pixel
.MapItoI
[ index
[i
] & mask
];
789 * Map color indexes to rgba values.
791 void gl_map_ci_to_rgba( const GLcontext
*ctx
, GLuint n
, const GLuint index
[],
794 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
795 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
796 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
797 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
798 const GLubyte
*rMap
= ctx
->Pixel
.MapItoR8
;
799 const GLubyte
*gMap
= ctx
->Pixel
.MapItoG8
;
800 const GLubyte
*bMap
= ctx
->Pixel
.MapItoB8
;
801 const GLubyte
*aMap
= ctx
->Pixel
.MapItoA8
;
804 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
805 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
806 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
807 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
813 * Map color indexes to float rgba values.
815 void gl_map_ci_to_rgba_float( const GLcontext
*ctx
, GLuint n
, const GLuint index
[],
818 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
819 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
820 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
821 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
822 const GLfloat
*rMap
= ctx
->Pixel
.MapItoR
;
823 const GLfloat
*gMap
= ctx
->Pixel
.MapItoG
;
824 const GLfloat
*bMap
= ctx
->Pixel
.MapItoB
;
825 const GLfloat
*aMap
= ctx
->Pixel
.MapItoA
;
828 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
829 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
830 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
831 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
837 * Map 8-bit color indexes to rgb values.
839 void gl_map_ci8_to_rgba( const GLcontext
*ctx
, GLuint n
, const GLubyte index
[],
842 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
843 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
844 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
845 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
846 const GLubyte
*rMap
= ctx
->Pixel
.MapItoR8
;
847 const GLubyte
*gMap
= ctx
->Pixel
.MapItoG8
;
848 const GLubyte
*bMap
= ctx
->Pixel
.MapItoB8
;
849 const GLubyte
*aMap
= ctx
->Pixel
.MapItoA8
;
852 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
853 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
854 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
855 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
860 void gl_map_ci_to_color( const GLcontext
*ctx
, GLuint n
, const GLuint index
[],
861 GLfloat r
[], GLfloat g
[],
862 GLfloat b
[], GLfloat a
[] )
864 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
865 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
866 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
867 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
870 r
[i
] = ctx
->Pixel
.MapItoR
[index
[i
] & rmask
];
871 g
[i
] = ctx
->Pixel
.MapItoG
[index
[i
] & gmask
];
872 b
[i
] = ctx
->Pixel
.MapItoB
[index
[i
] & bmask
];
873 a
[i
] = ctx
->Pixel
.MapItoA
[index
[i
] & amask
];
879 void gl_shift_and_offset_stencil( const GLcontext
*ctx
, GLuint n
,
880 GLstencil stencil
[] )
883 GLint shift
= ctx
->Pixel
.IndexShift
;
884 GLint offset
= ctx
->Pixel
.IndexOffset
;
887 stencil
[i
] = (stencil
[i
] << shift
) + offset
;
890 else if (shift
< 0) {
893 stencil
[i
] = (stencil
[i
] >> shift
) + offset
;
898 stencil
[i
] = stencil
[i
] + offset
;
906 void gl_map_stencil( const GLcontext
*ctx
, GLuint n
, GLstencil stencil
[] )
908 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
911 stencil
[i
] = ctx
->Pixel
.MapStoS
[ stencil
[i
] & mask
];