1 /* $Id: pixel.c,v 1.2 1999/10/08 09:27:11 keithw 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 pixel mapping to an array of RGBA pixels.
594 void gl_map_rgba( const GLcontext
*ctx
, GLuint n
, GLubyte rgba
[][4] )
596 GLfloat rscale
= (ctx
->Pixel
.MapRtoRsize
- 1) / 255.0F
;
597 GLfloat gscale
= (ctx
->Pixel
.MapGtoGsize
- 1) / 255.0F
;
598 GLfloat bscale
= (ctx
->Pixel
.MapBtoBsize
- 1) / 255.0F
;
599 GLfloat ascale
= (ctx
->Pixel
.MapAtoAsize
- 1) / 255.0F
;
602 GLint ir
= (GLint
) (rgba
[i
][RCOMP
] * rscale
);
603 GLint ig
= (GLint
) (rgba
[i
][GCOMP
] * gscale
);
604 GLint ib
= (GLint
) (rgba
[i
][BCOMP
] * bscale
);
605 GLint ia
= (GLint
) (rgba
[i
][ACOMP
] * ascale
);
606 rgba
[i
][RCOMP
] = (GLint
) (ctx
->Pixel
.MapRtoR
[ir
] * 255.0F
);
607 rgba
[i
][GCOMP
] = (GLint
) (ctx
->Pixel
.MapGtoG
[ig
] * 255.0F
);
608 rgba
[i
][BCOMP
] = (GLint
) (ctx
->Pixel
.MapBtoB
[ib
] * 255.0F
);
609 rgba
[i
][ACOMP
] = (GLint
) (ctx
->Pixel
.MapAtoA
[ia
] * 255.0F
);
615 * Apply pixel mapping to an array of RGBA pixels.
617 void gl_map_color( const GLcontext
*ctx
, GLuint n
,
618 GLfloat red
[], GLfloat green
[],
619 GLfloat blue
[], GLfloat alpha
[] )
621 GLfloat rscale
= ctx
->Pixel
.MapRtoRsize
-1;
622 GLfloat gscale
= ctx
->Pixel
.MapGtoGsize
-1;
623 GLfloat bscale
= ctx
->Pixel
.MapBtoBsize
-1;
624 GLfloat ascale
= ctx
->Pixel
.MapAtoAsize
-1;
627 red
[i
] = ctx
->Pixel
.MapRtoR
[ (GLint
) (red
[i
] * rscale
) ];
628 green
[i
] = ctx
->Pixel
.MapGtoG
[ (GLint
) (green
[i
] * gscale
) ];
629 blue
[i
] = ctx
->Pixel
.MapBtoB
[ (GLint
) (blue
[i
] * bscale
) ];
630 alpha
[i
] = ctx
->Pixel
.MapAtoA
[ (GLint
) (alpha
[i
] * ascale
) ];
637 * Apply color index shift and offset to an array of pixels.
639 void gl_shift_and_offset_ci( const GLcontext
*ctx
, GLuint n
, GLuint indexes
[] )
641 GLint shift
= ctx
->Pixel
.IndexShift
;
642 GLint offset
= ctx
->Pixel
.IndexOffset
;
646 indexes
[i
] = (indexes
[i
] << shift
) + offset
;
649 else if (shift
< 0) {
652 indexes
[i
] = (indexes
[i
] >> shift
) + offset
;
657 indexes
[i
] = indexes
[i
] + offset
;
664 * Apply color index mapping to color indexes.
666 void gl_map_ci( const GLcontext
*ctx
, GLuint n
, GLuint index
[] )
668 GLuint mask
= ctx
->Pixel
.MapItoIsize
- 1;
671 index
[i
] = ctx
->Pixel
.MapItoI
[ index
[i
] & mask
];
677 * Map color indexes to rgb values.
679 void gl_map_ci_to_rgba( const GLcontext
*ctx
, GLuint n
, const GLuint index
[],
682 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
683 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
684 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
685 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
686 const GLubyte
*rMap
= ctx
->Pixel
.MapItoR8
;
687 const GLubyte
*gMap
= ctx
->Pixel
.MapItoG8
;
688 const GLubyte
*bMap
= ctx
->Pixel
.MapItoB8
;
689 const GLubyte
*aMap
= ctx
->Pixel
.MapItoA8
;
692 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
693 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
694 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
695 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
701 * Map 8-bit color indexes to rgb values.
703 void gl_map_ci8_to_rgba( const GLcontext
*ctx
, GLuint n
, const GLubyte index
[],
706 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
707 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
708 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
709 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
710 const GLubyte
*rMap
= ctx
->Pixel
.MapItoR8
;
711 const GLubyte
*gMap
= ctx
->Pixel
.MapItoG8
;
712 const GLubyte
*bMap
= ctx
->Pixel
.MapItoB8
;
713 const GLubyte
*aMap
= ctx
->Pixel
.MapItoA8
;
716 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
717 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
718 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
719 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
724 void gl_map_ci_to_color( const GLcontext
*ctx
, GLuint n
, const GLuint index
[],
725 GLfloat r
[], GLfloat g
[],
726 GLfloat b
[], GLfloat a
[] )
728 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
729 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
730 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
731 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
734 r
[i
] = ctx
->Pixel
.MapItoR
[index
[i
] & rmask
];
735 g
[i
] = ctx
->Pixel
.MapItoG
[index
[i
] & gmask
];
736 b
[i
] = ctx
->Pixel
.MapItoB
[index
[i
] & bmask
];
737 a
[i
] = ctx
->Pixel
.MapItoA
[index
[i
] & amask
];
743 void gl_shift_and_offset_stencil( const GLcontext
*ctx
, GLuint n
,
744 GLstencil stencil
[] )
747 GLint shift
= ctx
->Pixel
.IndexShift
;
748 GLint offset
= ctx
->Pixel
.IndexOffset
;
751 stencil
[i
] = (stencil
[i
] << shift
) + offset
;
754 else if (shift
< 0) {
757 stencil
[i
] = (stencil
[i
] >> shift
) + offset
;
762 stencil
[i
] = stencil
[i
] + offset
;
770 void gl_map_stencil( const GLcontext
*ctx
, GLuint n
, GLstencil stencil
[] )
772 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
775 stencil
[i
] = ctx
->Pixel
.MapStoS
[ stencil
[i
] & mask
];