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