1 /* $Id: pixel.c,v 1.3 1999/10/30 08:20:57 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.
32 * glPixelStore, glPixelTransfer, glPixelMap, glPixelZoom, etc.
44 #include "GL/xf86glx.h"
51 #include "GL/xf86glx.h"
57 /**********************************************************************/
58 /***** glPixelZoom *****/
59 /**********************************************************************/
63 void gl_PixelZoom( GLcontext
*ctx
, GLfloat xfactor
, GLfloat yfactor
)
65 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPixelZoom");
67 ctx
->Pixel
.ZoomX
= xfactor
;
68 ctx
->Pixel
.ZoomY
= yfactor
;
73 /**********************************************************************/
74 /***** glPixelStore *****/
75 /**********************************************************************/
78 void gl_PixelStorei( GLcontext
*ctx
, GLenum pname
, GLint param
)
80 /* NOTE: this call can't be compiled into the display list */
82 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPixelStore");
86 case GL_PACK_SWAP_BYTES
:
87 ctx
->Pack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
89 case GL_PACK_LSB_FIRST
:
90 ctx
->Pack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
92 case GL_PACK_ROW_LENGTH
:
94 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
97 ctx
->Pack
.RowLength
= param
;
100 case GL_PACK_IMAGE_HEIGHT
:
102 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
104 ctx
->Pack
.ImageHeight
= param
;
106 case GL_PACK_SKIP_PIXELS
:
108 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
111 ctx
->Pack
.SkipPixels
= param
;
114 case GL_PACK_SKIP_ROWS
:
116 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
119 ctx
->Pack
.SkipRows
= param
;
122 case GL_PACK_ALIGNMENT
:
123 if (param
==1 || param
==2 || param
==4 || param
==8) {
124 ctx
->Pack
.Alignment
= param
;
127 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
130 case GL_UNPACK_SWAP_BYTES
:
131 ctx
->Unpack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
133 case GL_UNPACK_LSB_FIRST
:
134 ctx
->Unpack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
136 case GL_UNPACK_ROW_LENGTH
:
138 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
141 ctx
->Unpack
.RowLength
= param
;
144 case GL_UNPACK_IMAGE_HEIGHT
:
146 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
148 ctx
->Unpack
.ImageHeight
= param
;
150 case GL_UNPACK_SKIP_PIXELS
:
152 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
155 ctx
->Unpack
.SkipPixels
= param
;
158 case GL_UNPACK_SKIP_ROWS
:
160 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
163 ctx
->Unpack
.SkipRows
= param
;
166 case GL_UNPACK_ALIGNMENT
:
167 if (param
==1 || param
==2 || param
==4 || param
==8) {
168 ctx
->Unpack
.Alignment
= param
;
171 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelStore" );
175 gl_error( ctx
, GL_INVALID_ENUM
, "glPixelStore" );
183 /**********************************************************************/
184 /***** glPixelMap *****/
185 /**********************************************************************/
189 void gl_PixelMapfv( GLcontext
*ctx
,
190 GLenum map
, GLint mapsize
, const GLfloat
*values
)
194 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPixelMapfv");
197 if (mapsize
<0 || mapsize
>MAX_PIXEL_MAP_TABLE
) {
198 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelMapfv(mapsize)" );
202 if (map
>=GL_PIXEL_MAP_S_TO_S
&& map
<=GL_PIXEL_MAP_I_TO_A
) {
203 /* test that mapsize is a power of two */
205 GLboolean ok
= GL_FALSE
;
206 for (p
=1; p
<=MAX_PIXEL_MAP_TABLE
; p
=p
<<1) {
207 if ( (p
&mapsize
) == p
) {
213 gl_error( ctx
, GL_INVALID_VALUE
, "glPixelMapfv(mapsize)" );
219 case GL_PIXEL_MAP_S_TO_S
:
220 ctx
->Pixel
.MapStoSsize
= mapsize
;
221 for (i
=0;i
<mapsize
;i
++) {
222 ctx
->Pixel
.MapStoS
[i
] = (GLint
) values
[i
];
225 case GL_PIXEL_MAP_I_TO_I
:
226 ctx
->Pixel
.MapItoIsize
= mapsize
;
227 for (i
=0;i
<mapsize
;i
++) {
228 ctx
->Pixel
.MapItoI
[i
] = (GLint
) values
[i
];
231 case GL_PIXEL_MAP_I_TO_R
:
232 ctx
->Pixel
.MapItoRsize
= mapsize
;
233 for (i
=0;i
<mapsize
;i
++) {
234 GLfloat val
= CLAMP( values
[i
], 0.0, 1.0 );
235 ctx
->Pixel
.MapItoR
[i
] = val
;
236 ctx
->Pixel
.MapItoR8
[i
] = (GLint
) (val
* 255.0F
);
239 case GL_PIXEL_MAP_I_TO_G
:
240 ctx
->Pixel
.MapItoGsize
= mapsize
;
241 for (i
=0;i
<mapsize
;i
++) {
242 GLfloat val
= CLAMP( values
[i
], 0.0, 1.0 );
243 ctx
->Pixel
.MapItoG
[i
] = val
;
244 ctx
->Pixel
.MapItoG8
[i
] = (GLint
) (val
* 255.0F
);
247 case GL_PIXEL_MAP_I_TO_B
:
248 ctx
->Pixel
.MapItoBsize
= mapsize
;
249 for (i
=0;i
<mapsize
;i
++) {
250 GLfloat val
= CLAMP( values
[i
], 0.0, 1.0 );
251 ctx
->Pixel
.MapItoB
[i
] = val
;
252 ctx
->Pixel
.MapItoB8
[i
] = (GLint
) (val
* 255.0F
);
255 case GL_PIXEL_MAP_I_TO_A
:
256 ctx
->Pixel
.MapItoAsize
= mapsize
;
257 for (i
=0;i
<mapsize
;i
++) {
258 GLfloat val
= CLAMP( values
[i
], 0.0, 1.0 );
259 ctx
->Pixel
.MapItoA
[i
] = val
;
260 ctx
->Pixel
.MapItoA8
[i
] = (GLint
) (val
* 255.0F
);
263 case GL_PIXEL_MAP_R_TO_R
:
264 ctx
->Pixel
.MapRtoRsize
= mapsize
;
265 for (i
=0;i
<mapsize
;i
++) {
266 ctx
->Pixel
.MapRtoR
[i
] = CLAMP( values
[i
], 0.0, 1.0 );
269 case GL_PIXEL_MAP_G_TO_G
:
270 ctx
->Pixel
.MapGtoGsize
= mapsize
;
271 for (i
=0;i
<mapsize
;i
++) {
272 ctx
->Pixel
.MapGtoG
[i
] = CLAMP( values
[i
], 0.0, 1.0 );
275 case GL_PIXEL_MAP_B_TO_B
:
276 ctx
->Pixel
.MapBtoBsize
= mapsize
;
277 for (i
=0;i
<mapsize
;i
++) {
278 ctx
->Pixel
.MapBtoB
[i
] = CLAMP( values
[i
], 0.0, 1.0 );
281 case GL_PIXEL_MAP_A_TO_A
:
282 ctx
->Pixel
.MapAtoAsize
= mapsize
;
283 for (i
=0;i
<mapsize
;i
++) {
284 ctx
->Pixel
.MapAtoA
[i
] = CLAMP( values
[i
], 0.0, 1.0 );
288 gl_error( ctx
, GL_INVALID_ENUM
, "glPixelMapfv(map)" );
296 void gl_GetPixelMapfv( GLcontext
*ctx
, GLenum map
, GLfloat
*values
)
300 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetPixelMapfv");
303 case GL_PIXEL_MAP_I_TO_I
:
304 for (i
=0;i
<ctx
->Pixel
.MapItoIsize
;i
++) {
305 values
[i
] = (GLfloat
) ctx
->Pixel
.MapItoI
[i
];
308 case GL_PIXEL_MAP_S_TO_S
:
309 for (i
=0;i
<ctx
->Pixel
.MapStoSsize
;i
++) {
310 values
[i
] = (GLfloat
) ctx
->Pixel
.MapStoS
[i
];
313 case GL_PIXEL_MAP_I_TO_R
:
314 MEMCPY(values
,ctx
->Pixel
.MapItoR
,ctx
->Pixel
.MapItoRsize
*sizeof(GLfloat
));
316 case GL_PIXEL_MAP_I_TO_G
:
317 MEMCPY(values
,ctx
->Pixel
.MapItoG
,ctx
->Pixel
.MapItoGsize
*sizeof(GLfloat
));
319 case GL_PIXEL_MAP_I_TO_B
:
320 MEMCPY(values
,ctx
->Pixel
.MapItoB
,ctx
->Pixel
.MapItoBsize
*sizeof(GLfloat
));
322 case GL_PIXEL_MAP_I_TO_A
:
323 MEMCPY(values
,ctx
->Pixel
.MapItoA
,ctx
->Pixel
.MapItoAsize
*sizeof(GLfloat
));
325 case GL_PIXEL_MAP_R_TO_R
:
326 MEMCPY(values
,ctx
->Pixel
.MapRtoR
,ctx
->Pixel
.MapRtoRsize
*sizeof(GLfloat
));
328 case GL_PIXEL_MAP_G_TO_G
:
329 MEMCPY(values
,ctx
->Pixel
.MapGtoG
,ctx
->Pixel
.MapGtoGsize
*sizeof(GLfloat
));
331 case GL_PIXEL_MAP_B_TO_B
:
332 MEMCPY(values
,ctx
->Pixel
.MapBtoB
,ctx
->Pixel
.MapBtoBsize
*sizeof(GLfloat
));
334 case GL_PIXEL_MAP_A_TO_A
:
335 MEMCPY(values
,ctx
->Pixel
.MapAtoA
,ctx
->Pixel
.MapAtoAsize
*sizeof(GLfloat
));
338 gl_error( ctx
, GL_INVALID_ENUM
, "glGetPixelMapfv" );
343 void gl_GetPixelMapuiv( GLcontext
*ctx
, GLenum map
, GLuint
*values
)
347 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetPixelMapfv");
350 case GL_PIXEL_MAP_I_TO_I
:
351 MEMCPY(values
, ctx
->Pixel
.MapItoI
, ctx
->Pixel
.MapItoIsize
*sizeof(GLint
));
353 case GL_PIXEL_MAP_S_TO_S
:
354 MEMCPY(values
, ctx
->Pixel
.MapStoS
, ctx
->Pixel
.MapStoSsize
*sizeof(GLint
));
356 case GL_PIXEL_MAP_I_TO_R
:
357 for (i
=0;i
<ctx
->Pixel
.MapItoRsize
;i
++) {
358 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapItoR
[i
] );
361 case GL_PIXEL_MAP_I_TO_G
:
362 for (i
=0;i
<ctx
->Pixel
.MapItoGsize
;i
++) {
363 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapItoG
[i
] );
366 case GL_PIXEL_MAP_I_TO_B
:
367 for (i
=0;i
<ctx
->Pixel
.MapItoBsize
;i
++) {
368 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapItoB
[i
] );
371 case GL_PIXEL_MAP_I_TO_A
:
372 for (i
=0;i
<ctx
->Pixel
.MapItoAsize
;i
++) {
373 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapItoA
[i
] );
376 case GL_PIXEL_MAP_R_TO_R
:
377 for (i
=0;i
<ctx
->Pixel
.MapRtoRsize
;i
++) {
378 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapRtoR
[i
] );
381 case GL_PIXEL_MAP_G_TO_G
:
382 for (i
=0;i
<ctx
->Pixel
.MapGtoGsize
;i
++) {
383 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapGtoG
[i
] );
386 case GL_PIXEL_MAP_B_TO_B
:
387 for (i
=0;i
<ctx
->Pixel
.MapBtoBsize
;i
++) {
388 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapBtoB
[i
] );
391 case GL_PIXEL_MAP_A_TO_A
:
392 for (i
=0;i
<ctx
->Pixel
.MapAtoAsize
;i
++) {
393 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapAtoA
[i
] );
397 gl_error( ctx
, GL_INVALID_ENUM
, "glGetPixelMapfv" );
402 void gl_GetPixelMapusv( GLcontext
*ctx
, GLenum map
, GLushort
*values
)
406 ASSERT_OUTSIDE_BEGIN_END(ctx
, "glGetPixelMapfv");
409 case GL_PIXEL_MAP_I_TO_I
:
410 for (i
=0;i
<ctx
->Pixel
.MapItoIsize
;i
++) {
411 values
[i
] = (GLushort
) ctx
->Pixel
.MapItoI
[i
];
414 case GL_PIXEL_MAP_S_TO_S
:
415 for (i
=0;i
<ctx
->Pixel
.MapStoSsize
;i
++) {
416 values
[i
] = (GLushort
) ctx
->Pixel
.MapStoS
[i
];
419 case GL_PIXEL_MAP_I_TO_R
:
420 for (i
=0;i
<ctx
->Pixel
.MapItoRsize
;i
++) {
421 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapItoR
[i
] );
424 case GL_PIXEL_MAP_I_TO_G
:
425 for (i
=0;i
<ctx
->Pixel
.MapItoGsize
;i
++) {
426 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapItoG
[i
] );
429 case GL_PIXEL_MAP_I_TO_B
:
430 for (i
=0;i
<ctx
->Pixel
.MapItoBsize
;i
++) {
431 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapItoB
[i
] );
434 case GL_PIXEL_MAP_I_TO_A
:
435 for (i
=0;i
<ctx
->Pixel
.MapItoAsize
;i
++) {
436 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapItoA
[i
] );
439 case GL_PIXEL_MAP_R_TO_R
:
440 for (i
=0;i
<ctx
->Pixel
.MapRtoRsize
;i
++) {
441 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapRtoR
[i
] );
444 case GL_PIXEL_MAP_G_TO_G
:
445 for (i
=0;i
<ctx
->Pixel
.MapGtoGsize
;i
++) {
446 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapGtoG
[i
] );
449 case GL_PIXEL_MAP_B_TO_B
:
450 for (i
=0;i
<ctx
->Pixel
.MapBtoBsize
;i
++) {
451 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapBtoB
[i
] );
454 case GL_PIXEL_MAP_A_TO_A
:
455 for (i
=0;i
<ctx
->Pixel
.MapAtoAsize
;i
++) {
456 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapAtoA
[i
] );
460 gl_error( ctx
, GL_INVALID_ENUM
, "glGetPixelMapfv" );
466 /**********************************************************************/
467 /***** glPixelTransfer *****/
468 /**********************************************************************/
472 * Implements glPixelTransfer[fi] whether called immediately or from a
475 void gl_PixelTransferf( GLcontext
*ctx
, GLenum pname
, GLfloat param
)
477 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPixelTransfer");
482 ctx
->Pixel
.MapColorFlag
= param
? GL_TRUE
: GL_FALSE
;
485 ctx
->Pixel
.MapStencilFlag
= param
? GL_TRUE
: GL_FALSE
;
488 ctx
->Pixel
.IndexShift
= (GLint
) param
;
490 case GL_INDEX_OFFSET
:
491 ctx
->Pixel
.IndexOffset
= (GLint
) param
;
494 ctx
->Pixel
.RedScale
= param
;
497 ctx
->Pixel
.RedBias
= param
;
500 ctx
->Pixel
.GreenScale
= param
;
503 ctx
->Pixel
.GreenBias
= param
;
506 ctx
->Pixel
.BlueScale
= param
;
509 ctx
->Pixel
.BlueBias
= param
;
512 ctx
->Pixel
.AlphaScale
= param
;
515 ctx
->Pixel
.AlphaBias
= param
;
518 ctx
->Pixel
.DepthScale
= param
;
521 ctx
->Pixel
.DepthBias
= param
;
524 gl_error( ctx
, GL_INVALID_ENUM
, "glPixelTransfer(pname)" );
528 if (ctx
->Pixel
.RedScale
!=1.0F
|| ctx
->Pixel
.RedBias
!=0.0F
||
529 ctx
->Pixel
.GreenScale
!=1.0F
|| ctx
->Pixel
.GreenBias
!=0.0F
||
530 ctx
->Pixel
.BlueScale
!=1.0F
|| ctx
->Pixel
.BlueBias
!=0.0F
||
531 ctx
->Pixel
.AlphaScale
!=1.0F
|| ctx
->Pixel
.AlphaBias
!=0.0F
) {
532 ctx
->Pixel
.ScaleOrBiasRGBA
= GL_TRUE
;
535 ctx
->Pixel
.ScaleOrBiasRGBA
= GL_FALSE
;
543 * Pixel processing functions
548 * Apply scale and bias factors to an array of RGBA pixels.
550 void gl_scale_and_bias_color( const GLcontext
*ctx
, GLuint n
,
551 GLfloat red
[], GLfloat green
[],
552 GLfloat blue
[], GLfloat alpha
[] )
556 GLfloat r
= red
[i
] * ctx
->Pixel
.RedScale
+ ctx
->Pixel
.RedBias
;
557 GLfloat g
= green
[i
] * ctx
->Pixel
.GreenScale
+ ctx
->Pixel
.GreenBias
;
558 GLfloat b
= blue
[i
] * ctx
->Pixel
.BlueScale
+ ctx
->Pixel
.BlueBias
;
559 GLfloat a
= alpha
[i
] * ctx
->Pixel
.AlphaScale
+ ctx
->Pixel
.AlphaBias
;
560 red
[i
] = CLAMP( r
, 0.0F
, 1.0F
);
561 green
[i
] = CLAMP( g
, 0.0F
, 1.0F
);
562 blue
[i
] = CLAMP( b
, 0.0F
, 1.0F
);
563 alpha
[i
] = CLAMP( a
, 0.0F
, 1.0F
);
569 * Apply scale and bias factors to an array of RGBA pixels.
571 void gl_scale_and_bias_rgba( const GLcontext
*ctx
, GLuint n
, GLubyte rgba
[][4] )
573 GLfloat rbias
= ctx
->Pixel
.RedBias
* 255.0F
;
574 GLfloat gbias
= ctx
->Pixel
.GreenBias
* 255.0F
;
575 GLfloat bbias
= ctx
->Pixel
.BlueBias
* 255.0F
;
576 GLfloat abias
= ctx
->Pixel
.AlphaBias
* 255.0F
;
579 GLint r
= (GLint
) (rgba
[i
][RCOMP
] * ctx
->Pixel
.RedScale
+ rbias
);
580 GLint g
= (GLint
) (rgba
[i
][GCOMP
] * ctx
->Pixel
.GreenScale
+ gbias
);
581 GLint b
= (GLint
) (rgba
[i
][BCOMP
] * ctx
->Pixel
.BlueScale
+ bbias
);
582 GLint a
= (GLint
) (rgba
[i
][ACOMP
] * ctx
->Pixel
.AlphaScale
+ abias
);
583 rgba
[i
][RCOMP
] = CLAMP( r
, 0, 255 );
584 rgba
[i
][GCOMP
] = CLAMP( g
, 0, 255 );
585 rgba
[i
][BCOMP
] = CLAMP( b
, 0, 255 );
586 rgba
[i
][ACOMP
] = CLAMP( a
, 0, 255 );
592 * Apply scale and bias factors to an array of RGBA pixels.
594 void gl_scale_and_bias_rgba_float( const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4] )
596 if (ctx
->Pixel
.RedScale
!= 1.0 || ctx
->Pixel
.RedBias
!= 0.0) {
597 const GLfloat scale
= ctx
->Pixel
.RedScale
;
598 const GLfloat bias
= ctx
->Pixel
.RedBias
;
600 for (i
= 0; i
< n
; i
++) {
601 rgba
[i
][RCOMP
] = rgba
[i
][RCOMP
] * scale
+ bias
;
604 if (ctx
->Pixel
.GreenScale
!= 1.0 || ctx
->Pixel
.GreenBias
!= 0.0) {
605 const GLfloat scale
= ctx
->Pixel
.GreenScale
;
606 const GLfloat bias
= ctx
->Pixel
.GreenBias
;
608 for (i
= 0; i
< n
; i
++) {
609 rgba
[i
][GCOMP
] = rgba
[i
][GCOMP
] * scale
+ bias
;
612 if (ctx
->Pixel
.BlueScale
!= 1.0 || ctx
->Pixel
.BlueBias
!= 0.0) {
613 const GLfloat scale
= ctx
->Pixel
.BlueScale
;
614 const GLfloat bias
= ctx
->Pixel
.BlueBias
;
616 for (i
= 0; i
< n
; i
++) {
617 rgba
[i
][BCOMP
] = rgba
[i
][BCOMP
] * scale
+ bias
;
620 if (ctx
->Pixel
.AlphaScale
!= 1.0 || ctx
->Pixel
.AlphaBias
!= 0.0) {
621 const GLfloat scale
= ctx
->Pixel
.AlphaScale
;
622 const GLfloat bias
= ctx
->Pixel
.AlphaBias
;
624 for (i
= 0; i
< n
; i
++) {
625 rgba
[i
][ACOMP
] = rgba
[i
][ACOMP
] * scale
+ bias
;
632 * Apply pixel mapping to an array of RGBA pixels.
634 void gl_map_rgba( const GLcontext
*ctx
, GLuint n
, GLubyte rgba
[][4] )
636 GLfloat rscale
= (ctx
->Pixel
.MapRtoRsize
- 1) / 255.0F
;
637 GLfloat gscale
= (ctx
->Pixel
.MapGtoGsize
- 1) / 255.0F
;
638 GLfloat bscale
= (ctx
->Pixel
.MapBtoBsize
- 1) / 255.0F
;
639 GLfloat ascale
= (ctx
->Pixel
.MapAtoAsize
- 1) / 255.0F
;
642 GLint ir
= (GLint
) (rgba
[i
][RCOMP
] * rscale
);
643 GLint ig
= (GLint
) (rgba
[i
][GCOMP
] * gscale
);
644 GLint ib
= (GLint
) (rgba
[i
][BCOMP
] * bscale
);
645 GLint ia
= (GLint
) (rgba
[i
][ACOMP
] * ascale
);
646 rgba
[i
][RCOMP
] = (GLint
) (ctx
->Pixel
.MapRtoR
[ir
] * 255.0F
);
647 rgba
[i
][GCOMP
] = (GLint
) (ctx
->Pixel
.MapGtoG
[ig
] * 255.0F
);
648 rgba
[i
][BCOMP
] = (GLint
) (ctx
->Pixel
.MapBtoB
[ib
] * 255.0F
);
649 rgba
[i
][ACOMP
] = (GLint
) (ctx
->Pixel
.MapAtoA
[ia
] * 255.0F
);
655 * Apply pixel mapping to an array of floating point RGBA pixels.
657 void gl_map_rgba_float( const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4] )
659 const GLfloat rscale
= ctx
->Pixel
.MapRtoRsize
- 1;
660 const GLfloat gscale
= ctx
->Pixel
.MapGtoGsize
- 1;
661 const GLfloat bscale
= ctx
->Pixel
.MapBtoBsize
- 1;
662 const GLfloat ascale
= ctx
->Pixel
.MapAtoAsize
- 1;
663 const GLfloat
*rMap
= ctx
->Pixel
.MapRtoR
;
664 const GLfloat
*gMap
= ctx
->Pixel
.MapGtoG
;
665 const GLfloat
*bMap
= ctx
->Pixel
.MapBtoB
;
666 const GLfloat
*aMap
= ctx
->Pixel
.MapAtoA
;
669 rgba
[i
][RCOMP
] = rMap
[(GLint
) (rgba
[i
][RCOMP
] * rscale
+ 0.5F
)];
670 rgba
[i
][GCOMP
] = gMap
[(GLint
) (rgba
[i
][GCOMP
] * gscale
+ 0.5F
)];
671 rgba
[i
][BCOMP
] = bMap
[(GLint
) (rgba
[i
][BCOMP
] * bscale
+ 0.5F
)];
672 rgba
[i
][ACOMP
] = aMap
[(GLint
) (rgba
[i
][ACOMP
] * ascale
+ 0.5F
)];
678 * Apply pixel mapping to an array of RGBA pixels.
680 void gl_map_color( const GLcontext
*ctx
, GLuint n
,
681 GLfloat red
[], GLfloat green
[],
682 GLfloat blue
[], GLfloat alpha
[] )
684 GLfloat rscale
= ctx
->Pixel
.MapRtoRsize
- 1;
685 GLfloat gscale
= ctx
->Pixel
.MapGtoGsize
- 1;
686 GLfloat bscale
= ctx
->Pixel
.MapBtoBsize
- 1;
687 GLfloat ascale
= ctx
->Pixel
.MapAtoAsize
- 1;
690 red
[i
] = ctx
->Pixel
.MapRtoR
[ (GLint
) (red
[i
] * rscale
+ 0.5F
) ];
691 green
[i
] = ctx
->Pixel
.MapGtoG
[ (GLint
) (green
[i
] * gscale
+ 0.5F
) ];
692 blue
[i
] = ctx
->Pixel
.MapBtoB
[ (GLint
) (blue
[i
] * bscale
+ 0.5F
) ];
693 alpha
[i
] = ctx
->Pixel
.MapAtoA
[ (GLint
) (alpha
[i
] * ascale
+ 0.5F
) ];
700 * Apply color index shift and offset to an array of pixels.
702 void gl_shift_and_offset_ci( const GLcontext
*ctx
, GLuint n
, GLuint indexes
[] )
704 GLint shift
= ctx
->Pixel
.IndexShift
;
705 GLint offset
= ctx
->Pixel
.IndexOffset
;
709 indexes
[i
] = (indexes
[i
] << shift
) + offset
;
712 else if (shift
< 0) {
715 indexes
[i
] = (indexes
[i
] >> shift
) + offset
;
720 indexes
[i
] = indexes
[i
] + offset
;
727 * Apply color index mapping to color indexes.
729 void gl_map_ci( const GLcontext
*ctx
, GLuint n
, GLuint index
[] )
731 GLuint mask
= ctx
->Pixel
.MapItoIsize
- 1;
734 index
[i
] = ctx
->Pixel
.MapItoI
[ index
[i
] & mask
];
740 * Map color indexes to rgba values.
742 void gl_map_ci_to_rgba( const GLcontext
*ctx
, GLuint n
, const GLuint index
[],
745 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
746 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
747 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
748 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
749 const GLubyte
*rMap
= ctx
->Pixel
.MapItoR8
;
750 const GLubyte
*gMap
= ctx
->Pixel
.MapItoG8
;
751 const GLubyte
*bMap
= ctx
->Pixel
.MapItoB8
;
752 const GLubyte
*aMap
= ctx
->Pixel
.MapItoA8
;
755 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
756 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
757 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
758 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
764 * Map color indexes to float rgba values.
766 void gl_map_ci_to_rgba_float( const GLcontext
*ctx
, GLuint n
, const GLuint index
[],
769 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
770 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
771 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
772 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
773 const GLfloat
*rMap
= ctx
->Pixel
.MapItoR
;
774 const GLfloat
*gMap
= ctx
->Pixel
.MapItoG
;
775 const GLfloat
*bMap
= ctx
->Pixel
.MapItoB
;
776 const GLfloat
*aMap
= ctx
->Pixel
.MapItoA
;
779 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
780 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
781 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
782 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
788 * Map 8-bit color indexes to rgb values.
790 void gl_map_ci8_to_rgba( const GLcontext
*ctx
, GLuint n
, const GLubyte index
[],
793 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
794 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
795 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
796 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
797 const GLubyte
*rMap
= ctx
->Pixel
.MapItoR8
;
798 const GLubyte
*gMap
= ctx
->Pixel
.MapItoG8
;
799 const GLubyte
*bMap
= ctx
->Pixel
.MapItoB8
;
800 const GLubyte
*aMap
= ctx
->Pixel
.MapItoA8
;
803 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
804 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
805 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
806 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
811 void gl_map_ci_to_color( const GLcontext
*ctx
, GLuint n
, const GLuint index
[],
812 GLfloat r
[], GLfloat g
[],
813 GLfloat b
[], GLfloat a
[] )
815 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
816 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
817 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
818 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
821 r
[i
] = ctx
->Pixel
.MapItoR
[index
[i
] & rmask
];
822 g
[i
] = ctx
->Pixel
.MapItoG
[index
[i
] & gmask
];
823 b
[i
] = ctx
->Pixel
.MapItoB
[index
[i
] & bmask
];
824 a
[i
] = ctx
->Pixel
.MapItoA
[index
[i
] & amask
];
830 void gl_shift_and_offset_stencil( const GLcontext
*ctx
, GLuint n
,
831 GLstencil stencil
[] )
834 GLint shift
= ctx
->Pixel
.IndexShift
;
835 GLint offset
= ctx
->Pixel
.IndexOffset
;
838 stencil
[i
] = (stencil
[i
] << shift
) + offset
;
841 else if (shift
< 0) {
844 stencil
[i
] = (stencil
[i
] >> shift
) + offset
;
849 stencil
[i
] = stencil
[i
] + offset
;
857 void gl_map_stencil( const GLcontext
*ctx
, GLuint n
, GLstencil stencil
[] )
859 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
862 stencil
[i
] = ctx
->Pixel
.MapStoS
[ stencil
[i
] & mask
];