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