| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.3 |
| 4 |
* |
| 5 |
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved. |
| 6 |
* |
| 7 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 8 |
* copy of this software and associated documentation files (the "Software"), |
| 9 |
* to deal in the Software without restriction, including without limitation |
| 10 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 12 |
* Software is furnished to do so, subject to the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice shall be included |
| 15 |
* in all copies or substantial portions of the Software. |
| 16 |
* |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 |
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 |
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* \file image.c |
| 28 |
* Image handling. |
| 29 |
*/ |
| 30 |
|
| 31 |
|
| 32 |
#include "glheader.h" |
| 33 |
#include "bufferobj.h" |
| 34 |
#include "colormac.h" |
| 35 |
#include "context.h" |
| 36 |
#include "image.h" |
| 37 |
#include "imports.h" |
| 38 |
#include "histogram.h" |
| 39 |
#include "macros.h" |
| 40 |
#include "pixel.h" |
| 41 |
#include "mtypes.h" |
| 42 |
|
| 43 |
|
| 44 |
/** Compute ceiling of integer quotient of A divided by B. */ |
| 45 |
#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 ) |
| 46 |
|
| 47 |
|
| 48 |
/** |
| 49 |
* Flip the 8 bits in each byte of the given array. |
| 50 |
* |
| 51 |
* \param p array. |
| 52 |
* \param n number of bytes. |
| 53 |
* |
| 54 |
* \todo try this trick to flip bytes someday: |
| 55 |
* \code |
| 56 |
* v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555); |
| 57 |
* v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333); |
| 58 |
* v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f); |
| 59 |
* \endcode |
| 60 |
*/ |
| 61 |
static void |
| 62 |
flip_bytes( GLubyte *p, GLuint n ) |
| 63 |
{ |
| 64 |
register GLuint i, a, b; |
| 65 |
|
| 66 |
for (i=0;i<n;i++) { |
| 67 |
b = (GLuint) p[i]; /* words are often faster than bytes */ |
| 68 |
a = ((b & 0x01) << 7) | |
| 69 |
((b & 0x02) << 5) | |
| 70 |
((b & 0x04) << 3) | |
| 71 |
((b & 0x08) << 1) | |
| 72 |
((b & 0x10) >> 1) | |
| 73 |
((b & 0x20) >> 3) | |
| 74 |
((b & 0x40) >> 5) | |
| 75 |
((b & 0x80) >> 7); |
| 76 |
p[i] = (GLubyte) a; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
/** |
| 82 |
* Flip the order of the 2 bytes in each word in the given array. |
| 83 |
* |
| 84 |
* \param p array. |
| 85 |
* \param n number of words. |
| 86 |
*/ |
| 87 |
void |
| 88 |
_mesa_swap2( GLushort *p, GLuint n ) |
| 89 |
{ |
| 90 |
register GLuint i; |
| 91 |
|
| 92 |
for (i=0;i<n;i++) { |
| 93 |
p[i] = (p[i] >> 8) | ((p[i] << 8) & 0xff00); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
/* |
| 100 |
* Flip the order of the 4 bytes in each word in the given array. |
| 101 |
*/ |
| 102 |
void |
| 103 |
_mesa_swap4( GLuint *p, GLuint n ) |
| 104 |
{ |
| 105 |
register GLuint i, a, b; |
| 106 |
|
| 107 |
for (i=0;i<n;i++) { |
| 108 |
b = p[i]; |
| 109 |
a = (b >> 24) |
| 110 |
| ((b >> 8) & 0xff00) |
| 111 |
| ((b << 8) & 0xff0000) |
| 112 |
| ((b << 24) & 0xff000000); |
| 113 |
p[i] = a; |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
/** |
| 119 |
* Get the size of a GL data type. |
| 120 |
* |
| 121 |
* \param type GL data type. |
| 122 |
* |
| 123 |
* \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1 |
| 124 |
* if an invalid type enum. |
| 125 |
*/ |
| 126 |
GLint _mesa_sizeof_type( GLenum type ) |
| 127 |
{ |
| 128 |
switch (type) { |
| 129 |
case GL_BITMAP: |
| 130 |
return 0; |
| 131 |
case GL_UNSIGNED_BYTE: |
| 132 |
return sizeof(GLubyte); |
| 133 |
case GL_BYTE: |
| 134 |
return sizeof(GLbyte); |
| 135 |
case GL_UNSIGNED_SHORT: |
| 136 |
return sizeof(GLushort); |
| 137 |
case GL_SHORT: |
| 138 |
return sizeof(GLshort); |
| 139 |
case GL_UNSIGNED_INT: |
| 140 |
return sizeof(GLuint); |
| 141 |
case GL_INT: |
| 142 |
return sizeof(GLint); |
| 143 |
case GL_FLOAT: |
| 144 |
return sizeof(GLfloat); |
| 145 |
case GL_HALF_FLOAT_ARB: |
| 146 |
return sizeof(GLhalfARB); |
| 147 |
default: |
| 148 |
return -1; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
/** |
| 154 |
* Same as _mesa_sizeof_type() but also accepting the packed pixel |
| 155 |
* format data types. |
| 156 |
*/ |
| 157 |
GLint _mesa_sizeof_packed_type( GLenum type ) |
| 158 |
{ |
| 159 |
switch (type) { |
| 160 |
case GL_BITMAP: |
| 161 |
return 0; |
| 162 |
case GL_UNSIGNED_BYTE: |
| 163 |
return sizeof(GLubyte); |
| 164 |
case GL_BYTE: |
| 165 |
return sizeof(GLbyte); |
| 166 |
case GL_UNSIGNED_SHORT: |
| 167 |
return sizeof(GLushort); |
| 168 |
case GL_SHORT: |
| 169 |
return sizeof(GLshort); |
| 170 |
case GL_UNSIGNED_INT: |
| 171 |
return sizeof(GLuint); |
| 172 |
case GL_INT: |
| 173 |
return sizeof(GLint); |
| 174 |
case GL_HALF_FLOAT_ARB: |
| 175 |
return sizeof(GLhalfARB); |
| 176 |
case GL_FLOAT: |
| 177 |
return sizeof(GLfloat); |
| 178 |
case GL_UNSIGNED_BYTE_3_3_2: |
| 179 |
return sizeof(GLubyte); |
| 180 |
case GL_UNSIGNED_BYTE_2_3_3_REV: |
| 181 |
return sizeof(GLubyte); |
| 182 |
case GL_UNSIGNED_SHORT_5_6_5: |
| 183 |
return sizeof(GLushort); |
| 184 |
case GL_UNSIGNED_SHORT_5_6_5_REV: |
| 185 |
return sizeof(GLushort); |
| 186 |
case GL_UNSIGNED_SHORT_4_4_4_4: |
| 187 |
return sizeof(GLushort); |
| 188 |
case GL_UNSIGNED_SHORT_4_4_4_4_REV: |
| 189 |
return sizeof(GLushort); |
| 190 |
case GL_UNSIGNED_SHORT_5_5_5_1: |
| 191 |
return sizeof(GLushort); |
| 192 |
case GL_UNSIGNED_SHORT_1_5_5_5_REV: |
| 193 |
return sizeof(GLushort); |
| 194 |
case GL_UNSIGNED_INT_8_8_8_8: |
| 195 |
return sizeof(GLuint); |
| 196 |
case GL_UNSIGNED_INT_8_8_8_8_REV: |
| 197 |
return sizeof(GLuint); |
| 198 |
case GL_UNSIGNED_INT_10_10_10_2: |
| 199 |
return sizeof(GLuint); |
| 200 |
case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 201 |
return sizeof(GLuint); |
| 202 |
case GL_UNSIGNED_SHORT_8_8_MESA: |
| 203 |
case GL_UNSIGNED_SHORT_8_8_REV_MESA: |
| 204 |
return sizeof(GLushort); |
| 205 |
default: |
| 206 |
return -1; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
/** |
| 212 |
* Get the number of components in a pixel format. |
| 213 |
* |
| 214 |
* \param format pixel format. |
| 215 |
* |
| 216 |
* \return the number of components in the given format, or -1 if a bad format. |
| 217 |
*/ |
| 218 |
GLint _mesa_components_in_format( GLenum format ) |
| 219 |
{ |
| 220 |
switch (format) { |
| 221 |
case GL_COLOR_INDEX: |
| 222 |
case GL_COLOR_INDEX1_EXT: |
| 223 |
case GL_COLOR_INDEX2_EXT: |
| 224 |
case GL_COLOR_INDEX4_EXT: |
| 225 |
case GL_COLOR_INDEX8_EXT: |
| 226 |
case GL_COLOR_INDEX12_EXT: |
| 227 |
case GL_COLOR_INDEX16_EXT: |
| 228 |
case GL_STENCIL_INDEX: |
| 229 |
case GL_DEPTH_COMPONENT: |
| 230 |
case GL_RED: |
| 231 |
case GL_GREEN: |
| 232 |
case GL_BLUE: |
| 233 |
case GL_ALPHA: |
| 234 |
case GL_LUMINANCE: |
| 235 |
case GL_INTENSITY: |
| 236 |
return 1; |
| 237 |
case GL_LUMINANCE_ALPHA: |
| 238 |
return 2; |
| 239 |
case GL_RGB: |
| 240 |
return 3; |
| 241 |
case GL_RGBA: |
| 242 |
return 4; |
| 243 |
case GL_BGR: |
| 244 |
return 3; |
| 245 |
case GL_BGRA: |
| 246 |
return 4; |
| 247 |
case GL_ABGR_EXT: |
| 248 |
return 4; |
| 249 |
case GL_YCBCR_MESA: |
| 250 |
return 2; |
| 251 |
default: |
| 252 |
return -1; |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
/** |
| 258 |
* Get the bytes per pixel of pixel format type pair. |
| 259 |
* |
| 260 |
* \param format pixel format. |
| 261 |
* \param type pixel type. |
| 262 |
* |
| 263 |
* \return bytes per pixel, or -1 if a bad format or type was given. |
| 264 |
*/ |
| 265 |
GLint _mesa_bytes_per_pixel( GLenum format, GLenum type ) |
| 266 |
{ |
| 267 |
GLint comps = _mesa_components_in_format( format ); |
| 268 |
if (comps < 0) |
| 269 |
return -1; |
| 270 |
|
| 271 |
switch (type) { |
| 272 |
case GL_BITMAP: |
| 273 |
return 0; /* special case */ |
| 274 |
case GL_BYTE: |
| 275 |
case GL_UNSIGNED_BYTE: |
| 276 |
return comps * sizeof(GLubyte); |
| 277 |
case GL_SHORT: |
| 278 |
case GL_UNSIGNED_SHORT: |
| 279 |
return comps * sizeof(GLshort); |
| 280 |
case GL_INT: |
| 281 |
case GL_UNSIGNED_INT: |
| 282 |
return comps * sizeof(GLint); |
| 283 |
case GL_FLOAT: |
| 284 |
return comps * sizeof(GLfloat); |
| 285 |
case GL_HALF_FLOAT_ARB: |
| 286 |
return comps * sizeof(GLhalfARB); |
| 287 |
case GL_UNSIGNED_BYTE_3_3_2: |
| 288 |
case GL_UNSIGNED_BYTE_2_3_3_REV: |
| 289 |
if (format == GL_RGB || format == GL_BGR) |
| 290 |
return sizeof(GLubyte); |
| 291 |
else |
| 292 |
return -1; /* error */ |
| 293 |
case GL_UNSIGNED_SHORT_5_6_5: |
| 294 |
case GL_UNSIGNED_SHORT_5_6_5_REV: |
| 295 |
if (format == GL_RGB || format == GL_BGR) |
| 296 |
return sizeof(GLushort); |
| 297 |
else |
| 298 |
return -1; /* error */ |
| 299 |
case GL_UNSIGNED_SHORT_4_4_4_4: |
| 300 |
case GL_UNSIGNED_SHORT_4_4_4_4_REV: |
| 301 |
case GL_UNSIGNED_SHORT_5_5_5_1: |
| 302 |
case GL_UNSIGNED_SHORT_1_5_5_5_REV: |
| 303 |
if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT) |
| 304 |
return sizeof(GLushort); |
| 305 |
else |
| 306 |
return -1; |
| 307 |
case GL_UNSIGNED_INT_8_8_8_8: |
| 308 |
case GL_UNSIGNED_INT_8_8_8_8_REV: |
| 309 |
case GL_UNSIGNED_INT_10_10_10_2: |
| 310 |
case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 311 |
if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT) |
| 312 |
return sizeof(GLuint); |
| 313 |
else |
| 314 |
return -1; |
| 315 |
case GL_UNSIGNED_SHORT_8_8_MESA: |
| 316 |
case GL_UNSIGNED_SHORT_8_8_REV_MESA: |
| 317 |
if (format == GL_YCBCR_MESA) |
| 318 |
return sizeof(GLushort); |
| 319 |
else |
| 320 |
return -1; |
| 321 |
default: |
| 322 |
return -1; |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
/** |
| 328 |
* Test for a legal pixel format and type. |
| 329 |
* |
| 330 |
* \param format pixel format. |
| 331 |
* \param type pixel type. |
| 332 |
* |
| 333 |
* \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE |
| 334 |
* otherwise. |
| 335 |
*/ |
| 336 |
GLboolean |
| 337 |
_mesa_is_legal_format_and_type( GLcontext *ctx, GLenum format, GLenum type ) |
| 338 |
{ |
| 339 |
switch (format) { |
| 340 |
case GL_COLOR_INDEX: |
| 341 |
case GL_STENCIL_INDEX: |
| 342 |
switch (type) { |
| 343 |
case GL_BITMAP: |
| 344 |
case GL_BYTE: |
| 345 |
case GL_UNSIGNED_BYTE: |
| 346 |
case GL_SHORT: |
| 347 |
case GL_UNSIGNED_SHORT: |
| 348 |
case GL_INT: |
| 349 |
case GL_UNSIGNED_INT: |
| 350 |
case GL_FLOAT: |
| 351 |
return GL_TRUE; |
| 352 |
case GL_HALF_FLOAT_ARB: |
| 353 |
return ctx->Extensions.ARB_half_float_pixel; |
| 354 |
default: |
| 355 |
return GL_FALSE; |
| 356 |
} |
| 357 |
case GL_RED: |
| 358 |
case GL_GREEN: |
| 359 |
case GL_BLUE: |
| 360 |
case GL_ALPHA: |
| 361 |
#if 0 /* not legal! see table 3.6 of the 1.5 spec */ |
| 362 |
case GL_INTENSITY: |
| 363 |
#endif |
| 364 |
case GL_LUMINANCE: |
| 365 |
case GL_LUMINANCE_ALPHA: |
| 366 |
case GL_DEPTH_COMPONENT: |
| 367 |
switch (type) { |
| 368 |
case GL_BYTE: |
| 369 |
case GL_UNSIGNED_BYTE: |
| 370 |
case GL_SHORT: |
| 371 |
case GL_UNSIGNED_SHORT: |
| 372 |
case GL_INT: |
| 373 |
case GL_UNSIGNED_INT: |
| 374 |
case GL_FLOAT: |
| 375 |
return GL_TRUE; |
| 376 |
case GL_HALF_FLOAT_ARB: |
| 377 |
return ctx->Extensions.ARB_half_float_pixel; |
| 378 |
default: |
| 379 |
return GL_FALSE; |
| 380 |
} |
| 381 |
case GL_RGB: |
| 382 |
switch (type) { |
| 383 |
case GL_BYTE: |
| 384 |
case GL_UNSIGNED_BYTE: |
| 385 |
case GL_SHORT: |
| 386 |
case GL_UNSIGNED_SHORT: |
| 387 |
case GL_INT: |
| 388 |
case GL_UNSIGNED_INT: |
| 389 |
case GL_FLOAT: |
| 390 |
case GL_UNSIGNED_BYTE_3_3_2: |
| 391 |
case GL_UNSIGNED_BYTE_2_3_3_REV: |
| 392 |
case GL_UNSIGNED_SHORT_5_6_5: |
| 393 |
case GL_UNSIGNED_SHORT_5_6_5_REV: |
| 394 |
return GL_TRUE; |
| 395 |
case GL_HALF_FLOAT_ARB: |
| 396 |
return ctx->Extensions.ARB_half_float_pixel; |
| 397 |
default: |
| 398 |
return GL_FALSE; |
| 399 |
} |
| 400 |
case GL_BGR: |
| 401 |
switch (type) { |
| 402 |
case GL_BYTE: |
| 403 |
case GL_UNSIGNED_BYTE: |
| 404 |
case GL_SHORT: |
| 405 |
case GL_UNSIGNED_SHORT: |
| 406 |
case GL_INT: |
| 407 |
case GL_UNSIGNED_INT: |
| 408 |
case GL_FLOAT: |
| 409 |
return GL_TRUE; |
| 410 |
case GL_HALF_FLOAT_ARB: |
| 411 |
return ctx->Extensions.ARB_half_float_pixel; |
| 412 |
default: |
| 413 |
return GL_FALSE; |
| 414 |
} |
| 415 |
case GL_RGBA: |
| 416 |
case GL_BGRA: |
| 417 |
case GL_ABGR_EXT: |
| 418 |
switch (type) { |
| 419 |
case GL_BYTE: |
| 420 |
case GL_UNSIGNED_BYTE: |
| 421 |
case GL_SHORT: |
| 422 |
case GL_UNSIGNED_SHORT: |
| 423 |
case GL_INT: |
| 424 |
case GL_UNSIGNED_INT: |
| 425 |
case GL_FLOAT: |
| 426 |
case GL_UNSIGNED_SHORT_4_4_4_4: |
| 427 |
case GL_UNSIGNED_SHORT_4_4_4_4_REV: |
| 428 |
case GL_UNSIGNED_SHORT_5_5_5_1: |
| 429 |
case GL_UNSIGNED_SHORT_1_5_5_5_REV: |
| 430 |
case GL_UNSIGNED_INT_8_8_8_8: |
| 431 |
case GL_UNSIGNED_INT_8_8_8_8_REV: |
| 432 |
case GL_UNSIGNED_INT_10_10_10_2: |
| 433 |
case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 434 |
return GL_TRUE; |
| 435 |
case GL_HALF_FLOAT_ARB: |
| 436 |
return ctx->Extensions.ARB_half_float_pixel; |
| 437 |
default: |
| 438 |
return GL_FALSE; |
| 439 |
} |
| 440 |
case GL_YCBCR_MESA: |
| 441 |
if (type == GL_UNSIGNED_SHORT_8_8_MESA || |
| 442 |
type == GL_UNSIGNED_SHORT_8_8_REV_MESA) |
| 443 |
return GL_TRUE; |
| 444 |
else |
| 445 |
return GL_FALSE; |
| 446 |
default: |
| 447 |
; /* fall-through */ |
| 448 |
} |
| 449 |
return GL_FALSE; |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
/** |
| 454 |
* Return the address of a specific pixel in an image (1D, 2D or 3D). |
| 455 |
* |
| 456 |
* Pixel unpacking/packing parameters are observed according to \p packing. |
| 457 |
* |
| 458 |
* \param dimensions either 1, 2 or 3 to indicate dimensionality of image |
| 459 |
* \param image starting address of image data |
| 460 |
* \param width the image width |
| 461 |
* \param height theimage height |
| 462 |
* \param format the pixel format |
| 463 |
* \param type the pixel data type |
| 464 |
* \param packing the pixelstore attributes |
| 465 |
* \param img which image in the volume (0 for 1D or 2D images) |
| 466 |
* \param row row of pixel in the image (0 for 1D images) |
| 467 |
* \param column column of pixel in the image |
| 468 |
* |
| 469 |
* \return address of pixel on success, or NULL on error. |
| 470 |
* |
| 471 |
* \sa gl_pixelstore_attrib. |
| 472 |
*/ |
| 473 |
GLvoid * |
| 474 |
_mesa_image_address( GLuint dimensions, |
| 475 |
const struct gl_pixelstore_attrib *packing, |
| 476 |
const GLvoid *image, |
| 477 |
GLsizei width, GLsizei height, |
| 478 |
GLenum format, GLenum type, |
| 479 |
GLint img, GLint row, GLint column ) |
| 480 |
{ |
| 481 |
GLint alignment; /* 1, 2 or 4 */ |
| 482 |
GLint pixels_per_row; |
| 483 |
GLint rows_per_image; |
| 484 |
GLint skiprows; |
| 485 |
GLint skippixels; |
| 486 |
GLint skipimages; /* for 3-D volume images */ |
| 487 |
GLubyte *pixel_addr; |
| 488 |
|
| 489 |
ASSERT(dimensions >= 1 && dimensions <= 3); |
| 490 |
|
| 491 |
alignment = packing->Alignment; |
| 492 |
if (packing->RowLength > 0) { |
| 493 |
pixels_per_row = packing->RowLength; |
| 494 |
} |
| 495 |
else { |
| 496 |
pixels_per_row = width; |
| 497 |
} |
| 498 |
if (packing->ImageHeight > 0) { |
| 499 |
rows_per_image = packing->ImageHeight; |
| 500 |
} |
| 501 |
else { |
| 502 |
rows_per_image = height; |
| 503 |
} |
| 504 |
|
| 505 |
skippixels = packing->SkipPixels; |
| 506 |
/* Note: SKIP_ROWS _is_ used for 1D images */ |
| 507 |
skiprows = packing->SkipRows; |
| 508 |
/* Note: SKIP_IMAGES is only used for 3D images */ |
| 509 |
skipimages = (dimensions == 3) ? packing->SkipImages : 0; |
| 510 |
|
| 511 |
if (type == GL_BITMAP) { |
| 512 |
/* BITMAP data */ |
| 513 |
GLint comp_per_pixel; /* components per pixel */ |
| 514 |
GLint bytes_per_comp; /* bytes per component */ |
| 515 |
GLint bytes_per_row; |
| 516 |
GLint bytes_per_image; |
| 517 |
|
| 518 |
/* Compute bytes per component */ |
| 519 |
bytes_per_comp = _mesa_sizeof_packed_type( type ); |
| 520 |
if (bytes_per_comp < 0) { |
| 521 |
return NULL; |
| 522 |
} |
| 523 |
|
| 524 |
/* Compute number of components per pixel */ |
| 525 |
comp_per_pixel = _mesa_components_in_format( format ); |
| 526 |
if (comp_per_pixel < 0) { |
| 527 |
return NULL; |
| 528 |
} |
| 529 |
|
| 530 |
bytes_per_row = alignment |
| 531 |
* CEILING( comp_per_pixel*pixels_per_row, 8*alignment ); |
| 532 |
|
| 533 |
bytes_per_image = bytes_per_row * rows_per_image; |
| 534 |
|
| 535 |
pixel_addr = (GLubyte *) image |
| 536 |
+ (skipimages + img) * bytes_per_image |
| 537 |
+ (skiprows + row) * bytes_per_row |
| 538 |
+ (skippixels + column) / 8; |
| 539 |
} |
| 540 |
else { |
| 541 |
/* Non-BITMAP data */ |
| 542 |
GLint bytes_per_pixel, bytes_per_row, remainder, bytes_per_image; |
| 543 |
GLint topOfImage; |
| 544 |
|
| 545 |
bytes_per_pixel = _mesa_bytes_per_pixel( format, type ); |
| 546 |
|
| 547 |
/* The pixel type and format should have been error checked earlier */ |
| 548 |
assert(bytes_per_pixel > 0); |
| 549 |
|
| 550 |
bytes_per_row = pixels_per_row * bytes_per_pixel; |
| 551 |
remainder = bytes_per_row % alignment; |
| 552 |
if (remainder > 0) |
| 553 |
bytes_per_row += (alignment - remainder); |
| 554 |
|
| 555 |
ASSERT(bytes_per_row % alignment == 0); |
| 556 |
|
| 557 |
bytes_per_image = bytes_per_row * rows_per_image; |
| 558 |
|
| 559 |
if (packing->Invert) { |
| 560 |
/* set pixel_addr to the last row */ |
| 561 |
topOfImage = bytes_per_row * (height - 1); |
| 562 |
bytes_per_row = -bytes_per_row; |
| 563 |
} |
| 564 |
else { |
| 565 |
topOfImage = 0; |
| 566 |
} |
| 567 |
|
| 568 |
/* compute final pixel address */ |
| 569 |
pixel_addr = (GLubyte *) image |
| 570 |
+ (skipimages + img) * bytes_per_image |
| 571 |
+ topOfImage |
| 572 |
+ (skiprows + row) * bytes_per_row |
| 573 |
+ (skippixels + column) * bytes_per_pixel; |
| 574 |
} |
| 575 |
|
| 576 |
return (GLvoid *) pixel_addr; |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
GLvoid * |
| 581 |
_mesa_image_address1d( const struct gl_pixelstore_attrib *packing, |
| 582 |
const GLvoid *image, |
| 583 |
GLsizei width, |
| 584 |
GLenum format, GLenum type, |
| 585 |
GLint column ) |
| 586 |
{ |
| 587 |
return _mesa_image_address(1, packing, image, width, 1, |
| 588 |
format, type, 0, 0, column); |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
GLvoid * |
| 593 |
_mesa_image_address2d( const struct gl_pixelstore_attrib *packing, |
| 594 |
const GLvoid *image, |
| 595 |
GLsizei width, GLsizei height, |
| 596 |
GLenum format, GLenum type, |
| 597 |
GLint row, GLint column ) |
| 598 |
{ |
| 599 |
return _mesa_image_address(2, packing, image, width, height, |
| 600 |
format, type, 0, row, column); |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
GLvoid * |
| 605 |
_mesa_image_address3d( const struct gl_pixelstore_attrib *packing, |
| 606 |
const GLvoid *image, |
| 607 |
GLsizei width, GLsizei height, |
| 608 |
GLenum format, GLenum type, |
| 609 |
GLint img, GLint row, GLint column ) |
| 610 |
{ |
| 611 |
return _mesa_image_address(3, packing, image, width, height, |
| 612 |
format, type, img, row, column); |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
/** |
| 618 |
* Compute the stride between image rows. |
| 619 |
* |
| 620 |
* \param packing the pixelstore attributes |
| 621 |
* \param width image width. |
| 622 |
* \param format pixel format. |
| 623 |
* \param type pixel data type. |
| 624 |
* |
| 625 |
* \return the stride in bytes for the given parameters. |
| 626 |
* |
| 627 |
* Computes the number of bytes per pixel and row and compensates for alignment. |
| 628 |
* |
| 629 |
* \sa gl_pixelstore_attrib. |
| 630 |
*/ |
| 631 |
GLint |
| 632 |
_mesa_image_row_stride( const struct gl_pixelstore_attrib *packing, |
| 633 |
GLint width, GLenum format, GLenum type ) |
| 634 |
{ |
| 635 |
ASSERT(packing); |
| 636 |
if (type == GL_BITMAP) { |
| 637 |
/* BITMAP data */ |
| 638 |
GLint bytes; |
| 639 |
if (packing->RowLength == 0) { |
| 640 |
bytes = (width + 7) / 8; |
| 641 |
} |
| 642 |
else { |
| 643 |
bytes = (packing->RowLength + 7) / 8; |
| 644 |
} |
| 645 |
if (packing->Invert) { |
| 646 |
/* negate the bytes per row (negative row stride) */ |
| 647 |
bytes = -bytes; |
| 648 |
} |
| 649 |
return bytes; |
| 650 |
} |
| 651 |
else { |
| 652 |
/* Non-BITMAP data */ |
| 653 |
const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type); |
| 654 |
GLint bytesPerRow, remainder; |
| 655 |
if (bytesPerPixel <= 0) |
| 656 |
return -1; /* error */ |
| 657 |
if (packing->RowLength == 0) { |
| 658 |
bytesPerRow = bytesPerPixel * width; |
| 659 |
} |
| 660 |
else { |
| 661 |
bytesPerRow = bytesPerPixel * packing->RowLength; |
| 662 |
} |
| 663 |
remainder = bytesPerRow % packing->Alignment; |
| 664 |
if (remainder > 0) |
| 665 |
bytesPerRow += (packing->Alignment - remainder); |
| 666 |
if (packing->Invert) |
| 667 |
bytesPerRow = -bytesPerRow; |
| 668 |
return bytesPerRow; |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
#if _HAVE_FULL_GL |
| 674 |
|
| 675 |
/* |
| 676 |
* Compute the stride between images in a 3D texture (in bytes) for the given |
| 677 |
* pixel packing parameters and image width, format and type. |
| 678 |
*/ |
| 679 |
GLint |
| 680 |
_mesa_image_image_stride( const struct gl_pixelstore_attrib *packing, |
| 681 |
GLint width, GLint height, |
| 682 |
GLenum format, GLenum type ) |
| 683 |
{ |
| 684 |
ASSERT(packing); |
| 685 |
ASSERT(type != GL_BITMAP); |
| 686 |
|
| 687 |
{ |
| 688 |
const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type); |
| 689 |
GLint bytesPerRow, bytesPerImage, remainder; |
| 690 |
|
| 691 |
if (bytesPerPixel <= 0) |
| 692 |
return -1; /* error */ |
| 693 |
if (packing->RowLength == 0) { |
| 694 |
bytesPerRow = bytesPerPixel * width; |
| 695 |
} |
| 696 |
else { |
| 697 |
bytesPerRow = bytesPerPixel * packing->RowLength; |
| 698 |
} |
| 699 |
remainder = bytesPerRow % packing->Alignment; |
| 700 |
if (remainder > 0) |
| 701 |
bytesPerRow += (packing->Alignment - remainder); |
| 702 |
|
| 703 |
if (packing->ImageHeight == 0) |
| 704 |
bytesPerImage = bytesPerRow * height; |
| 705 |
else |
| 706 |
bytesPerImage = bytesPerRow * packing->ImageHeight; |
| 707 |
|
| 708 |
return bytesPerImage; |
| 709 |
} |
| 710 |
} |
| 711 |
|
| 712 |
|
| 713 |
/* |
| 714 |
* Unpack a 32x32 pixel polygon stipple from user memory using the |
| 715 |
* current pixel unpack settings. |
| 716 |
*/ |
| 717 |
void |
| 718 |
_mesa_unpack_polygon_stipple( const GLubyte *pattern, GLuint dest[32], |
| 719 |
const struct gl_pixelstore_attrib *unpacking ) |
| 720 |
{ |
| 721 |
GLubyte *ptrn = (GLubyte *) _mesa_unpack_bitmap( 32, 32, pattern, unpacking ); |
| 722 |
if (ptrn) { |
| 723 |
/* Convert pattern from GLubytes to GLuints and handle big/little |
| 724 |
* endian differences |
| 725 |
*/ |
| 726 |
GLubyte *p = ptrn; |
| 727 |
GLint i; |
| 728 |
for (i = 0; i < 32; i++) { |
| 729 |
dest[i] = (p[0] << 24) |
| 730 |
| (p[1] << 16) |
| 731 |
| (p[2] << 8) |
| 732 |
| (p[3] ); |
| 733 |
p += 4; |
| 734 |
} |
| 735 |
FREE(ptrn); |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
/* |
| 741 |
* Pack polygon stipple into user memory given current pixel packing |
| 742 |
* settings. |
| 743 |
*/ |
| 744 |
void |
| 745 |
_mesa_pack_polygon_stipple( const GLuint pattern[32], GLubyte *dest, |
| 746 |
const struct gl_pixelstore_attrib *packing ) |
| 747 |
{ |
| 748 |
/* Convert pattern from GLuints to GLubytes to handle big/little |
| 749 |
* endian differences. |
| 750 |
*/ |
| 751 |
GLubyte ptrn[32*4]; |
| 752 |
GLint i; |
| 753 |
for (i = 0; i < 32; i++) { |
| 754 |
ptrn[i * 4 + 0] = (GLubyte) ((pattern[i] >> 24) & 0xff); |
| 755 |
ptrn[i * 4 + 1] = (GLubyte) ((pattern[i] >> 16) & 0xff); |
| 756 |
ptrn[i * 4 + 2] = (GLubyte) ((pattern[i] >> 8 ) & 0xff); |
| 757 |
ptrn[i * 4 + 3] = (GLubyte) ((pattern[i] ) & 0xff); |
| 758 |
} |
| 759 |
|
| 760 |
_mesa_pack_bitmap(32, 32, ptrn, dest, packing); |
| 761 |
} |
| 762 |
|
| 763 |
|
| 764 |
/* |
| 765 |
* Unpack bitmap data. Resulting data will be in most-significant-bit-first |
| 766 |
* order with row alignment = 1 byte. |
| 767 |
*/ |
| 768 |
GLvoid * |
| 769 |
_mesa_unpack_bitmap( GLint width, GLint height, const GLubyte *pixels, |
| 770 |
const struct gl_pixelstore_attrib *packing ) |
| 771 |
{ |
| 772 |
GLint bytes, row, width_in_bytes; |
| 773 |
GLubyte *buffer, *dst; |
| 774 |
|
| 775 |
if (!pixels) |
| 776 |
return NULL; |
| 777 |
|
| 778 |
/* Alloc dest storage */ |
| 779 |
bytes = ((width + 7) / 8 * height); |
| 780 |
buffer = (GLubyte *) MALLOC( bytes ); |
| 781 |
if (!buffer) |
| 782 |
return NULL; |
| 783 |
|
| 784 |
|
| 785 |
width_in_bytes = CEILING( width, 8 ); |
| 786 |
dst = buffer; |
| 787 |
for (row = 0; row < height; row++) { |
| 788 |
const GLubyte *src = (const GLubyte *) |
| 789 |
_mesa_image_address2d(packing, pixels, width, height, |
| 790 |
GL_COLOR_INDEX, GL_BITMAP, row, 0); |
| 791 |
if (!src) { |
| 792 |
FREE(buffer); |
| 793 |
return NULL; |
| 794 |
} |
| 795 |
|
| 796 |
if (packing->SkipPixels == 0) { |
| 797 |
MEMCPY( dst, src, width_in_bytes ); |
| 798 |
if (packing->LsbFirst) { |
| 799 |
flip_bytes( dst, width_in_bytes ); |
| 800 |
} |
| 801 |
} |
| 802 |
else { |
| 803 |
/* handling SkipPixels is a bit tricky (no pun intended!) */ |
| 804 |
GLint i; |
| 805 |
if (packing->LsbFirst) { |
| 806 |
GLubyte srcMask = 1 << (packing->SkipPixels & 0x7); |
| 807 |
GLubyte dstMask = 128; |
| 808 |
const GLubyte *s = src; |
| 809 |
GLubyte *d = dst; |
| 810 |
*d = 0; |
| 811 |
for (i = 0; i < width; i++) { |
| 812 |
if (*s & srcMask) { |
| 813 |
*d |= dstMask; |
| 814 |
} |
| 815 |
if (srcMask == 128) { |
| 816 |
srcMask = 1; |
| 817 |
s++; |
| 818 |
} |
| 819 |
else { |
| 820 |
srcMask = srcMask << 1; |
| 821 |
} |
| 822 |
if (dstMask == 1) { |
| 823 |
dstMask = 128; |
| 824 |
d++; |
| 825 |
*d = 0; |
| 826 |
} |
| 827 |
else { |
| 828 |
dstMask = dstMask >> 1; |
| 829 |
} |
| 830 |
} |
| 831 |
} |
| 832 |
else { |
| 833 |
GLubyte srcMask = 128 >> (packing->SkipPixels & 0x7); |
| 834 |
GLubyte dstMask = 128; |
| 835 |
const GLubyte *s = src; |
| 836 |
GLubyte *d = dst; |
| 837 |
*d = 0; |
| 838 |
for (i = 0; i < width; i++) { |
| 839 |
if (*s & srcMask) { |
| 840 |
*d |= dstMask; |
| 841 |
} |
| 842 |
if (srcMask == 1) { |
| 843 |
srcMask = 128; |
| 844 |
s++; |
| 845 |
} |
| 846 |
else { |
| 847 |
srcMask = srcMask >> 1; |
| 848 |
} |
| 849 |
if (dstMask == 1) { |
| 850 |
dstMask = 128; |
| 851 |
d++; |
| 852 |
*d = 0; |
| 853 |
} |
| 854 |
else { |
| 855 |
dstMask = dstMask >> 1; |
| 856 |
} |
| 857 |
} |
| 858 |
} |
| 859 |
} |
| 860 |
dst += width_in_bytes; |
| 861 |
} |
| 862 |
|
| 863 |
return buffer; |
| 864 |
} |
| 865 |
|
| 866 |
|
| 867 |
/* |
| 868 |
* Pack bitmap data. |
| 869 |
*/ |
| 870 |
void |
| 871 |
_mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source, |
| 872 |
GLubyte *dest, const struct gl_pixelstore_attrib *packing ) |
| 873 |
{ |
| 874 |
GLint row, width_in_bytes; |
| 875 |
const GLubyte *src; |
| 876 |
|
| 877 |
if (!source) |
| 878 |
return; |
| 879 |
|
| 880 |
width_in_bytes = CEILING( width, 8 ); |
| 881 |
src = source; |
| 882 |
for (row = 0; row < height; row++) { |
| 883 |
GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing, dest, |
| 884 |
width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0); |
| 885 |
if (!dst) |
| 886 |
return; |
| 887 |
|
| 888 |
if (packing->SkipPixels == 0) { |
| 889 |
MEMCPY( dst, src, width_in_bytes ); |
| 890 |
if (packing->LsbFirst) { |
| 891 |
flip_bytes( dst, width_in_bytes ); |
| 892 |
} |
| 893 |
} |
| 894 |
else { |
| 895 |
/* handling SkipPixels is a bit tricky (no pun intended!) */ |
| 896 |
GLint i; |
| 897 |
if (packing->LsbFirst) { |
| 898 |
GLubyte srcMask = 1 << (packing->SkipPixels & 0x7); |
| 899 |
GLubyte dstMask = 128; |
| 900 |
const GLubyte *s = src; |
| 901 |
GLubyte *d = dst; |
| 902 |
*d = 0; |
| 903 |
for (i = 0; i < width; i++) { |
| 904 |
if (*s & srcMask) { |
| 905 |
*d |= dstMask; |
| 906 |
} |
| 907 |
if (srcMask == 128) { |
| 908 |
srcMask = 1; |
| 909 |
s++; |
| 910 |
} |
| 911 |
else { |
| 912 |
srcMask = srcMask << 1; |
| 913 |
} |
| 914 |
if (dstMask == 1) { |
| 915 |
dstMask = 128; |
| 916 |
d++; |
| 917 |
*d = 0; |
| 918 |
} |
| 919 |
else { |
| 920 |
dstMask = dstMask >> 1; |
| 921 |
} |
| 922 |
} |
| 923 |
} |
| 924 |
else { |
| 925 |
GLubyte srcMask = 128 >> (packing->SkipPixels & 0x7); |
| 926 |
GLubyte dstMask = 128; |
| 927 |
const GLubyte *s = src; |
| 928 |
GLubyte *d = dst; |
| 929 |
*d = 0; |
| 930 |
for (i = 0; i < width; i++) { |
| 931 |
if (*s & srcMask) { |
| 932 |
*d |= dstMask; |
| 933 |
} |
| 934 |
if (srcMask == 1) { |
| 935 |
srcMask = 128; |
| 936 |
s++; |
| 937 |
} |
| 938 |
else { |
| 939 |
srcMask = srcMask >> 1; |
| 940 |
} |
| 941 |
if (dstMask == 1) { |
| 942 |
dstMask = 128; |
| 943 |
d++; |
| 944 |
*d = 0; |
| 945 |
} |
| 946 |
else { |
| 947 |
dstMask = dstMask >> 1; |
| 948 |
} |
| 949 |
} |
| 950 |
} |
| 951 |
} |
| 952 |
src += width_in_bytes; |
| 953 |
} |
| 954 |
} |
| 955 |
|
| 956 |
|
| 957 |
/** |
| 958 |
* Apply various pixel transfer operations to an array of RGBA pixels |
| 959 |
* as indicated by the transferOps bitmask |
| 960 |
*/ |
| 961 |
void |
| 962 |
_mesa_apply_rgba_transfer_ops(GLcontext *ctx, GLuint transferOps, |
| 963 |
GLuint n, GLfloat rgba[][4]) |
| 964 |
{ |
| 965 |
/* scale & bias */ |
| 966 |
if (transferOps & IMAGE_SCALE_BIAS_BIT) { |
| 967 |
_mesa_scale_and_bias_rgba(n, rgba, |
| 968 |
ctx->Pixel.RedScale, ctx->Pixel.GreenScale, |
| 969 |
ctx->Pixel.BlueScale, ctx->Pixel.AlphaScale, |
| 970 |
ctx->Pixel.RedBias, ctx->Pixel.GreenBias, |
| 971 |
ctx->Pixel.BlueBias, ctx->Pixel.AlphaBias); |
| 972 |
} |
| 973 |
/* color map lookup */ |
| 974 |
if (transferOps & IMAGE_MAP_COLOR_BIT) { |
| 975 |
_mesa_map_rgba( ctx, n, rgba ); |
| 976 |
} |
| 977 |
/* GL_COLOR_TABLE lookup */ |
| 978 |
if (transferOps & IMAGE_COLOR_TABLE_BIT) { |
| 979 |
_mesa_lookup_rgba_float(&ctx->ColorTable, n, rgba); |
| 980 |
} |
| 981 |
/* convolution */ |
| 982 |
if (transferOps & IMAGE_CONVOLUTION_BIT) { |
| 983 |
/* this has to be done in the calling code */ |
| 984 |
_mesa_problem(ctx, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops"); |
| 985 |
} |
| 986 |
/* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */ |
| 987 |
if (transferOps & IMAGE_POST_CONVOLUTION_SCALE_BIAS) { |
| 988 |
_mesa_scale_and_bias_rgba(n, rgba, |
| 989 |
ctx->Pixel.PostConvolutionScale[RCOMP], |
| 990 |
ctx->Pixel.PostConvolutionScale[GCOMP], |
| 991 |
ctx->Pixel.PostConvolutionScale[BCOMP], |
| 992 |
ctx->Pixel.PostConvolutionScale[ACOMP], |
| 993 |
ctx->Pixel.PostConvolutionBias[RCOMP], |
| 994 |
ctx->Pixel.PostConvolutionBias[GCOMP], |
| 995 |
ctx->Pixel.PostConvolutionBias[BCOMP], |
| 996 |
ctx->Pixel.PostConvolutionBias[ACOMP]); |
| 997 |
} |
| 998 |
/* GL_POST_CONVOLUTION_COLOR_TABLE lookup */ |
| 999 |
if (transferOps & IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT) { |
| 1000 |
_mesa_lookup_rgba_float(&ctx->PostConvolutionColorTable, n, rgba); |
| 1001 |
} |
| 1002 |
/* color matrix transform */ |
| 1003 |
if (transferOps & IMAGE_COLOR_MATRIX_BIT) { |
| 1004 |
_mesa_transform_rgba(ctx, n, rgba); |
| 1005 |
} |
| 1006 |
/* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */ |
| 1007 |
if (transferOps & IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT) { |
| 1008 |
_mesa_lookup_rgba_float(&ctx->PostColorMatrixColorTable, n, rgba); |
| 1009 |
} |
| 1010 |
/* update histogram count */ |
| 1011 |
if (transferOps & IMAGE_HISTOGRAM_BIT) { |
| 1012 |
_mesa_update_histogram(ctx, n, (CONST GLfloat (*)[4]) rgba); |
| 1013 |
} |
| 1014 |
/* update min/max values */ |
| 1015 |
if (transferOps & IMAGE_MIN_MAX_BIT) { |
| 1016 |
_mesa_update_minmax(ctx, n, (CONST GLfloat (*)[4]) rgba); |
| 1017 |
} |
| 1018 |
/* clamping to [0,1] */ |
| 1019 |
if (transferOps & IMAGE_CLAMP_BIT) { |
| 1020 |
GLuint i; |
| 1021 |
for (i = 0; i < n; i++) { |
| 1022 |
rgba[i][RCOMP] = CLAMP(rgba[i][RCOMP], 0.0F, 1.0F); |
| 1023 |
rgba[i][GCOMP] = CLAMP(rgba[i][GCOMP], 0.0F, 1.0F); |
| 1024 |
rgba[i][BCOMP] = CLAMP(rgba[i][BCOMP], 0.0F, 1.0F); |
| 1025 |
rgba[i][ACOMP] = CLAMP(rgba[i][ACOMP], 0.0F, 1.0F); |
| 1026 |
} |
| 1027 |
} |
| 1028 |
} |
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
/** |
| 1033 |
* Used to pack an array [][4] of RGBA float colors as specified |
| 1034 |
* by the dstFormat, dstType and dstPacking. Used by glReadPixels, |
| 1035 |
* glGetConvolutionFilter(), etc. |
| 1036 |
* NOTE: it's assumed the incoming float colors are all in [0,1]. |
| 1037 |
*/ |
| 1038 |
void |
| 1039 |
_mesa_pack_rgba_span_float( GLcontext *ctx, |
| 1040 |
GLuint n, CONST GLfloat rgbaIn[][4], |
| 1041 |
GLenum dstFormat, GLenum dstType, |
| 1042 |
GLvoid *dstAddr, |
| 1043 |
const struct gl_pixelstore_attrib *dstPacking, |
| 1044 |
GLuint transferOps ) |
| 1045 |
{ |
| 1046 |
const GLint comps = _mesa_components_in_format(dstFormat); |
| 1047 |
GLfloat luminance[MAX_WIDTH]; |
| 1048 |
const GLfloat (*rgba)[4]; |
| 1049 |
GLuint i; |
| 1050 |
|
| 1051 |
if (transferOps) { |
| 1052 |
/* make copy of incoming data */ |
| 1053 |
DEFMARRAY(GLfloat, rgbaCopy, MAX_WIDTH, 4); /* mac 32k limitation */ |
| 1054 |
CHECKARRAY(rgbaCopy, return); /* mac 32k limitation */ |
| 1055 |
|
| 1056 |
_mesa_memcpy(rgbaCopy, rgbaIn, n * 4 * sizeof(GLfloat)); |
| 1057 |
_mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgbaCopy); |
| 1058 |
rgba = (const GLfloat (*)[4]) rgbaCopy; |
| 1059 |
|
| 1060 |
if ((transferOps & IMAGE_MIN_MAX_BIT) && ctx->MinMax.Sink) { |
| 1061 |
UNDEFARRAY(rgbaCopy); /* mac 32k limitation */ |
| 1062 |
return; |
| 1063 |
} |
| 1064 |
UNDEFARRAY(rgbaCopy); /* mac 32k limitation */ |
| 1065 |
} |
| 1066 |
else { |
| 1067 |
/* use incoming data, not a copy */ |
| 1068 |
rgba = (const GLfloat (*)[4]) rgbaIn; |
| 1069 |
} |
| 1070 |
|
| 1071 |
if (dstFormat == GL_LUMINANCE || dstFormat == GL_LUMINANCE_ALPHA) { |
| 1072 |
/* compute luminance values */ |
| 1073 |
if (ctx->Color.ClampReadColor == GL_TRUE) { |
| 1074 |
for (i = 0; i < n; i++) { |
| 1075 |
GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP]; |
| 1076 |
luminance[i] = CLAMP(sum, 0.0F, 1.0F); |
| 1077 |
} |
| 1078 |
} |
| 1079 |
else { |
| 1080 |
for (i = 0; i < n; i++) { |
| 1081 |
luminance[i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP]; |
| 1082 |
} |
| 1083 |
} |
| 1084 |
} |
| 1085 |
|
| 1086 |
/* |
| 1087 |
* Pack/store the pixels. Ugh! Lots of cases!!! |
| 1088 |
*/ |
| 1089 |
switch (dstType) { |
| 1090 |
case GL_UNSIGNED_BYTE: |
| 1091 |
{ |
| 1092 |
GLubyte *dst = (GLubyte *) dstAddr; |
| 1093 |
switch (dstFormat) { |
| 1094 |
case GL_RED: |
| 1095 |
for (i=0;i<n;i++) |
| 1096 |
dst[i] = FLOAT_TO_UBYTE(rgba[i][RCOMP]); |
| 1097 |
break; |
| 1098 |
case GL_GREEN: |
| 1099 |
for (i=0;i<n;i++) |
| 1100 |
dst[i] = FLOAT_TO_UBYTE(rgba[i][GCOMP]); |
| 1101 |
break; |
| 1102 |
case GL_BLUE: |
| 1103 |
for (i=0;i<n;i++) |
| 1104 |
dst[i] = FLOAT_TO_UBYTE(rgba[i][BCOMP]); |
| 1105 |
break; |
| 1106 |
case GL_ALPHA: |
| 1107 |
for (i=0;i<n;i++) |
| 1108 |
dst[i] = FLOAT_TO_UBYTE(rgba[i][ACOMP]); |
| 1109 |
break; |
| 1110 |
case GL_LUMINANCE: |
| 1111 |
for (i=0;i<n;i++) |
| 1112 |
dst[i] = FLOAT_TO_UBYTE(luminance[i]); |
| 1113 |
break; |
| 1114 |
case GL_LUMINANCE_ALPHA: |
| 1115 |
for (i=0;i<n;i++) { |
| 1116 |
dst[i*2+0] = FLOAT_TO_UBYTE(luminance[i]); |
| 1117 |
dst[i*2+1] = FLOAT_TO_UBYTE(rgba[i][ACOMP]); |
| 1118 |
} |
| 1119 |
break; |
| 1120 |
case GL_RGB: |
| 1121 |
for (i=0;i<n;i++) { |
| 1122 |
dst[i*3+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]); |
| 1123 |
dst[i*3+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]); |
| 1124 |
dst[i*3+2] = FLOAT_TO_UBYTE(rgba[i][BCOMP]); |
| 1125 |
} |
| 1126 |
break; |
| 1127 |
case GL_RGBA: |
| 1128 |
for (i=0;i<n;i++) { |
| 1129 |
dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]); |
| 1130 |
dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]); |
| 1131 |
dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][BCOMP]); |
| 1132 |
dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][ACOMP]); |
| 1133 |
} |
| 1134 |
break; |
| 1135 |
case GL_BGR: |
| 1136 |
for (i=0;i<n;i++) { |
| 1137 |
dst[i*3+0] = FLOAT_TO_UBYTE(rgba[i][BCOMP]); |
| 1138 |
dst[i*3+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]); |
| 1139 |
dst[i*3+2] = FLOAT_TO_UBYTE(rgba[i][RCOMP]); |
| 1140 |
} |
| 1141 |
break; |
| 1142 |
case GL_BGRA: |
| 1143 |
for (i=0;i<n;i++) { |
| 1144 |
dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][BCOMP]); |
| 1145 |
dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]); |
| 1146 |
dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][RCOMP]); |
| 1147 |
dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][ACOMP]); |
| 1148 |
} |
| 1149 |
break; |
| 1150 |
case GL_ABGR_EXT: |
| 1151 |
for (i=0;i<n;i++) { |
| 1152 |
dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][ACOMP]); |
| 1153 |
dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][BCOMP]); |
| 1154 |
dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][GCOMP]); |
| 1155 |
dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][RCOMP]); |
| 1156 |
} |
| 1157 |
break; |
| 1158 |
default: |
| 1159 |
_mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
| 1160 |
} |
| 1161 |
} |
| 1162 |
break; |
| 1163 |
case GL_BYTE: |
| 1164 |
{ |
| 1165 |
GLbyte *dst = (GLbyte *) dstAddr; |
| 1166 |
switch (dstFormat) { |
| 1167 |
case GL_RED: |
| 1168 |
for (i=0;i<n;i++) |
| 1169 |
dst[i] = FLOAT_TO_BYTE(rgba[i][RCOMP]); |
| 1170 |
break; |
| 1171 |
case GL_GREEN: |
| 1172 |
for (i=0;i<n;i++) |
| 1173 |
dst[i] = FLOAT_TO_BYTE(rgba[i][GCOMP]); |
| 1174 |
break; |
| 1175 |
case GL_BLUE: |
| 1176 |
for (i=0;i<n;i++) |
| 1177 |
dst[i] = FLOAT_TO_BYTE(rgba[i][BCOMP]); |
| 1178 |
break; |
| 1179 |
case GL_ALPHA: |
| 1180 |
for (i=0;i<n;i++) |
| 1181 |
dst[i] = FLOAT_TO_BYTE(rgba[i][ACOMP]); |
| 1182 |
break; |
| 1183 |
case GL_LUMINANCE: |
| 1184 |
for (i=0;i<n;i++) |
| 1185 |
dst[i] = FLOAT_TO_BYTE(luminance[i]); |
| 1186 |
break; |
| 1187 |
case GL_LUMINANCE_ALPHA: |
| 1188 |
for (i=0;i<n;i++) { |
| 1189 |
dst[i*2+0] = FLOAT_TO_BYTE(luminance[i]); |
| 1190 |
dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][ACOMP]); |
| 1191 |
} |
| 1192 |
break; |
| 1193 |
case GL_RGB: |
| 1194 |
for (i=0;i<n;i++) { |
| 1195 |
dst[i*3+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]); |
| 1196 |
dst[i*3+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]); |
| 1197 |
dst[i*3+2] = FLOAT_TO_BYTE(rgba[i][BCOMP]); |
| 1198 |
} |
| 1199 |
break; |
| 1200 |
case GL_RGBA: |
| 1201 |
for (i=0;i<n;i++) { |
| 1202 |
dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]); |
| 1203 |
dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]); |
| 1204 |
dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][BCOMP]); |
| 1205 |
dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][ACOMP]); |
| 1206 |
} |
| 1207 |
break; |
| 1208 |
case GL_BGR: |
| 1209 |
for (i=0;i<n;i++) { |
| 1210 |
dst[i*3+0] = FLOAT_TO_BYTE(rgba[i][BCOMP]); |
| 1211 |
dst[i*3+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]); |
| 1212 |
dst[i*3+2] = FLOAT_TO_BYTE(rgba[i][RCOMP]); |
| 1213 |
} |
| 1214 |
break; |
| 1215 |
case GL_BGRA: |
| 1216 |
for (i=0;i<n;i++) { |
| 1217 |
dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][BCOMP]); |
| 1218 |
dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]); |
| 1219 |
dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][RCOMP]); |
| 1220 |
dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][ACOMP]); |
| 1221 |
} |
| 1222 |
case GL_ABGR_EXT: |
| 1223 |
for (i=0;i<n;i++) { |
| 1224 |
dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][ACOMP]); |
| 1225 |
dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][BCOMP]); |
| 1226 |
dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][GCOMP]); |
| 1227 |
dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][RCOMP]); |
| 1228 |
} |
| 1229 |
break; |
| 1230 |
default: |
| 1231 |
_mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
| 1232 |
} |
| 1233 |
} |
| 1234 |
break; |
| 1235 |
case GL_UNSIGNED_SHORT: |
| 1236 |
{ |
| 1237 |
GLushort *dst = (GLushort *) dstAddr; |
| 1238 |
switch (dstFormat) { |
| 1239 |
case GL_RED: |
| 1240 |
for (i=0;i<n;i++) |
| 1241 |
CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][RCOMP]); |
| 1242 |
break; |
| 1243 |
case GL_GREEN: |
| 1244 |
for (i=0;i<n;i++) |
| 1245 |
CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][GCOMP]); |
| 1246 |
break; |
| 1247 |
case GL_BLUE: |
| 1248 |
for (i=0;i<n;i++) |
| 1249 |
CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][BCOMP]); |
| 1250 |
break; |
| 1251 |
case GL_ALPHA: |
| 1252 |
for (i=0;i<n;i++) |
| 1253 |
CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][ACOMP]); |
| 1254 |
break; |
| 1255 |
case GL_LUMINANCE: |
| 1256 |
for (i=0;i<n;i++) |
| 1257 |
UNCLAMPED_FLOAT_TO_USHORT(dst[i], luminance[i]); |
| 1258 |
break; |
| 1259 |
case GL_LUMINANCE_ALPHA: |
| 1260 |
for (i=0;i<n;i++) { |
| 1261 |
UNCLAMPED_FLOAT_TO_USHORT(dst[i*2+0], luminance[i]); |
| 1262 |
CLAMPED_FLOAT_TO_USHORT(dst[i*2+1], rgba[i][ACOMP]); |
| 1263 |
} |
| 1264 |
break; |
| 1265 |
case GL_RGB: |
| 1266 |
for (i=0;i<n;i++) { |
| 1267 |
CLAMPED_FLOAT_TO_USHORT(dst[i*3+0], rgba[i][RCOMP]); |
| 1268 |
CLAMPED_FLOAT_TO_USHORT(dst[i*3+1], rgba[i][GCOMP]); |
| 1269 |
CLAMPED_FLOAT_TO_USHORT(dst[i*3+2], rgba[i][BCOMP]); |
| 1270 |
} |
| 1271 |
break; |
| 1272 |
case GL_RGBA: |
| 1273 |
for (i=0;i<n;i++) { |
| 1274 |
CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][RCOMP]); |
| 1275 |
CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][GCOMP]); |
| 1276 |
CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][BCOMP]); |
| 1277 |
CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][ACOMP]); |
| 1278 |
} |
| 1279 |
break; |
| 1280 |
case GL_BGR: |
| 1281 |
for (i=0;i<n;i++) { |
| 1282 |
CLAMPED_FLOAT_TO_USHORT(dst[i*3+0], rgba[i][BCOMP]); |
| 1283 |
CLAMPED_FLOAT_TO_USHORT(dst[i*3+1], rgba[i][GCOMP]); |
| 1284 |
CLAMPED_FLOAT_TO_USHORT(dst[i*3+2], rgba[i][RCOMP]); |
| 1285 |
} |
| 1286 |
break; |
| 1287 |
case GL_BGRA: |
| 1288 |
for (i=0;i<n;i++) { |
| 1289 |
CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][BCOMP]); |
| 1290 |
CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][GCOMP]); |
| 1291 |
CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][RCOMP]); |
| 1292 |
CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][ACOMP]); |
| 1293 |
} |
| 1294 |
break; |
| 1295 |
case GL_ABGR_EXT: |
| 1296 |
for (i=0;i<n;i++) { |
| 1297 |
CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][ACOMP]); |
| 1298 |
CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][BCOMP]); |
| 1299 |
CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][GCOMP]); |
| 1300 |
CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][RCOMP]); |
| 1301 |
} |
| 1302 |
break; |
| 1303 |
default: |
| 1304 |
_mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
| 1305 |
} |
| 1306 |
if (dstPacking->SwapBytes) { |
| 1307 |
_mesa_swap2( (GLushort *) dst, n * comps); |
| 1308 |
} |
| 1309 |
} |
| 1310 |
break; |
| 1311 |
case GL_SHORT: |
| 1312 |
{ |
| 1313 |
GLshort *dst = (GLshort *) dstAddr; |
| 1314 |
switch (dstFormat) { |
| 1315 |
case GL_RED: |
| 1316 |
for (i=0;i<n;i++) |
| 1317 |
dst[i] = FLOAT_TO_SHORT(rgba[i][RCOMP]); |
| 1318 |
break; |
| 1319 |
case GL_GREEN: |
| 1320 |
for (i=0;i<n;i++) |
| 1321 |
dst[i] = FLOAT_TO_SHORT(rgba[i][GCOMP]); |
| 1322 |
break; |
| 1323 |
case GL_BLUE: |
| 1324 |
for (i=0;i<n;i++) |
| 1325 |
dst[i] = FLOAT_TO_SHORT(rgba[i][BCOMP]); |
| 1326 |
break; |
| 1327 |
case GL_ALPHA: |
| 1328 |
for (i=0;i<n;i++) |
| 1329 |
dst[i] = FLOAT_TO_SHORT(rgba[i][ACOMP]); |
| 1330 |
break; |
| 1331 |
case GL_LUMINANCE: |
| 1332 |
for (i=0;i<n;i++) |
| 1333 |
dst[i] = FLOAT_TO_SHORT(luminance[i]); |
| 1334 |
break; |
| 1335 |
case GL_LUMINANCE_ALPHA: |
| 1336 |
for (i=0;i<n;i++) { |
| 1337 |
dst[i*2+0] = FLOAT_TO_SHORT(luminance[i]); |
| 1338 |
dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][ACOMP]); |
| 1339 |
} |
| 1340 |
break; |
| 1341 |
case GL_RGB: |
| 1342 |
for (i=0;i<n;i++) { |
| 1343 |
dst[i*3+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]); |
| 1344 |
dst[i*3+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]); |
| 1345 |
dst[i*3+2] = FLOAT_TO_SHORT(rgba[i][BCOMP]); |
| 1346 |
} |
| 1347 |
break; |
| 1348 |
case GL_RGBA: |
| 1349 |
for (i=0;i<n;i++) { |
| 1350 |
dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]); |
| 1351 |
dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]); |
| 1352 |
dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][BCOMP]); |
| 1353 |
dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][ACOMP]); |
| 1354 |
} |
| 1355 |
break; |
| 1356 |
case GL_BGR: |
| 1357 |
for (i=0;i<n;i++) { |
| 1358 |
dst[i*3+0] = FLOAT_TO_SHORT(rgba[i][BCOMP]); |
| 1359 |
dst[i*3+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]); |
| 1360 |
dst[i*3+2] = FLOAT_TO_SHORT(rgba[i][RCOMP]); |
| 1361 |
} |
| 1362 |
break; |
| 1363 |
case GL_BGRA: |
| 1364 |
for (i=0;i<n;i++) { |
| 1365 |
dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][BCOMP]); |
| 1366 |
dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]); |
| 1367 |
dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][RCOMP]); |
| 1368 |
dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][ACOMP]); |
| 1369 |
} |
| 1370 |
case GL_ABGR_EXT: |
| 1371 |
for (i=0;i<n;i++) { |
| 1372 |
dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][ACOMP]); |
| 1373 |
dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][BCOMP]); |
| 1374 |
dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][GCOMP]); |
| 1375 |
dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][RCOMP]); |
| 1376 |
} |
| 1377 |
break; |
| 1378 |
default: |
| 1379 |
_mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
| 1380 |
} |
| 1381 |
if (dstPacking->SwapBytes) { |
| 1382 |
_mesa_swap2( (GLushort *) dst, n * comps ); |
| 1383 |
} |
| 1384 |
} |
| 1385 |
break; |
| 1386 |
case GL_UNSIGNED_INT: |
| 1387 |
{ |
| 1388 |
GLuint *dst = (GLuint *) dstAddr; |
| 1389 |
switch (dstFormat) { |
| 1390 |
case GL_RED: |
| 1391 |
for (i=0;i<n;i++) |
| 1392 |
dst[i] = FLOAT_TO_UINT(rgba[i][RCOMP]); |
| 1393 |
break; |
| 1394 |
case GL_GREEN: |
| 1395 |
for (i=0;i<n;i++) |
| 1396 |
dst[i] = FLOAT_TO_UINT(rgba[i][GCOMP]); |
| 1397 |
break; |
| 1398 |
case GL_BLUE: |
| 1399 |
for (i=0;i<n;i++) |
| 1400 |
dst[i] = FLOAT_TO_UINT(rgba[i][BCOMP]); |
| 1401 |
break; |
| 1402 |
case GL_ALPHA: |
| 1403 |
for (i=0;i<n;i++) |
| 1404 |
dst[i] = FLOAT_TO_UINT(rgba[i][ACOMP]); |
| 1405 |
break; |
| 1406 |
case GL_LUMINANCE: |
| 1407 |
for (i=0;i<n;i++) |
| 1408 |
dst[i] = FLOAT_TO_UINT(luminance[i]); |
| 1409 |
break; |
| 1410 |
case GL_LUMINANCE_ALPHA: |
| 1411 |
for (i=0;i<n;i++) { |
| 1412 |
dst[i*2+0] = FLOAT_TO_UINT(luminance[i]); |
| 1413 |
dst[i*2+1] = FLOAT_TO_UINT(rgba[i][ACOMP]); |
| 1414 |
} |
| 1415 |
break; |
| 1416 |
case GL_RGB: |
| 1417 |
for (i=0;i<n;i++) { |
| 1418 |
dst[i*3+0] = FLOAT_TO_UINT(rgba[i][RCOMP]); |
| 1419 |
dst[i*3+1] = FLOAT_TO_UINT(rgba[i][GCOMP]); |
| 1420 |
dst[i*3+2] = FLOAT_TO_UINT(rgba[i][BCOMP]); |
| 1421 |
} |
| 1422 |
break; |
| 1423 |
case GL_RGBA: |
| 1424 |
for (i=0;i<n;i++) { |
| 1425 |
dst[i*4+0] = FLOAT_TO_UINT(rgba[i][RCOMP]); |
| 1426 |
dst[i*4+1] = FLOAT_TO_UINT(rgba[i][GCOMP]); |
| 1427 |
dst[i*4+2] = FLOAT_TO_UINT(rgba[i][BCOMP]); |
| 1428 |
dst[i*4+3] = FLOAT_TO_UINT(rgba[i][ACOMP]); |
| 1429 |
} |
| 1430 |
break; |
| 1431 |
case GL_BGR: |
| 1432 |
for (i=0;i<n;i++) { |
| 1433 |
dst[i*3+0] = FLOAT_TO_UINT(rgba[i][BCOMP]); |
| 1434 |
dst[i*3+1] = FLOAT_TO_UINT(rgba[i][GCOMP]); |
| 1435 |
dst[i*3+2] = FLOAT_TO_UINT(rgba[i][RCOMP]); |
| 1436 |
} |
| 1437 |
break; |
| 1438 |
case GL_BGRA: |
| 1439 |
for (i=0;i<n;i++) { |
| 1440 |
dst[i*4+0] = FLOAT_TO_UINT(rgba[i][BCOMP]); |
| 1441 |
dst[i*4+1] = FLOAT_TO_UINT(rgba[i][GCOMP]); |
| 1442 |
dst[i*4+2] = FLOAT_TO_UINT(rgba[i][RCOMP]); |
| 1443 |
dst[i*4+3] = FLOAT_TO_UINT(rgba[i][ACOMP]); |
| 1444 |
} |
| 1445 |
break; |
| 1446 |
case GL_ABGR_EXT: |
| 1447 |
for (i=0;i<n;i++) { |
| 1448 |
dst[i*4+0] = FLOAT_TO_UINT(rgba[i][ACOMP]); |
| 1449 |
dst[i*4+1] = FLOAT_TO_UINT(rgba[i][BCOMP]); |
| 1450 |
dst[i*4+2] = FLOAT_TO_UINT(rgba[i][GCOMP]); |
| 1451 |
dst[i*4+3] = FLOAT_TO_UINT(rgba[i][RCOMP]); |
| 1452 |
} |
| 1453 |
break; |
| 1454 |
default: |
| 1455 |
_mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
| 1456 |
} |
| 1457 |
if (dstPacking->SwapBytes) { |
| 1458 |
_mesa_swap4( (GLuint *) dst, n * comps ); |
| 1459 |
} |
| 1460 |
} |
| 1461 |
break; |
| 1462 |
case GL_INT: |
| 1463 |
{ |
| 1464 |
GLint *dst = (GLint *) dstAddr; |
| 1465 |
switch (dstFormat) { |
| 1466 |
case GL_RED: |
| 1467 |
for (i=0;i<n;i++) |
| 1468 |
dst[i] = FLOAT_TO_INT(rgba[i][RCOMP]); |
| 1469 |
break; |
| 1470 |
case GL_GREEN: |
| 1471 |
for (i=0;i<n;i++) |
| 1472 |
dst[i] = FLOAT_TO_INT(rgba[i][GCOMP]); |
| 1473 |
break; |
| 1474 |
case GL_BLUE: |
| 1475 |
for (i=0;i<n;i++) |
| 1476 |
dst[i] = FLOAT_TO_INT(rgba[i][BCOMP]); |
| 1477 |
break; |
| 1478 |
case GL_ALPHA: |
| 1479 |
for (i=0;i<n;i++) |
| 1480 |
dst[i] = FLOAT_TO_INT(rgba[i][ACOMP]); |
| 1481 |
break; |
| 1482 |
case GL_LUMINANCE: |
| 1483 |
for (i=0;i<n;i++) |
| 1484 |
dst[i] = FLOAT_TO_INT(luminance[i]); |
| 1485 |
break; |
| 1486 |
case GL_LUMINANCE_ALPHA: |
| 1487 |
for (i=0;i<n;i++) { |
| 1488 |
dst[i*2+0] = FLOAT_TO_INT(luminance[i]); |
| 1489 |
dst[i*2+1] = FLOAT_TO_INT(rgba[i][ACOMP]); |
| 1490 |
} |
| 1491 |
break; |
| 1492 |
case GL_RGB: |
| 1493 |
for (i=0;i<n;i++) { |
| 1494 |
dst[i*3+0] = FLOAT_TO_INT(rgba[i][RCOMP]); |
| 1495 |
dst[i*3+1] = FLOAT_TO_INT(rgba[i][GCOMP]); |
| 1496 |
dst[i*3+2] = FLOAT_TO_INT(rgba[i][BCOMP]); |
| 1497 |
} |
| 1498 |
break; |
| 1499 |
case GL_RGBA: |
| 1500 |
for (i=0;i<n;i++) { |
| 1501 |
dst[i*4+0] = FLOAT_TO_INT(rgba[i][RCOMP]); |
| 1502 |
dst[i*4+1] = FLOAT_TO_INT(rgba[i][GCOMP]); |
| 1503 |
dst[i*4+2] = FLOAT_TO_INT(rgba[i][BCOMP]); |
| 1504 |
dst[i*4+3] = FLOAT_TO_INT(rgba[i][ACOMP]); |
| 1505 |
} |
| 1506 |
break; |
| 1507 |
case GL_BGR: |
| 1508 |
for (i=0;i<n;i++) { |
| 1509 |
dst[i*3+0] = FLOAT_TO_INT(rgba[i][BCOMP]); |
| 1510 |
dst[i*3+1] = FLOAT_TO_INT(rgba[i][GCOMP]); |
| 1511 |
dst[i*3+2] = FLOAT_TO_INT(rgba[i][RCOMP]); |
| 1512 |
} |
| 1513 |
break; |
| 1514 |
case GL_BGRA: |
| 1515 |
for (i=0;i<n;i++) { |
| 1516 |
dst[i*4+0] = FLOAT_TO_INT(rgba[i][BCOMP]); |
| 1517 |
dst[i*4+1] = FLOAT_TO_INT(rgba[i][GCOMP]); |
| 1518 |
dst[i*4+2] = FLOAT_TO_INT(rgba[i][RCOMP]); |
| 1519 |
dst[i*4+3] = FLOAT_TO_INT(rgba[i][ACOMP]); |
| 1520 |
} |
| 1521 |
break; |
| 1522 |
case GL_ABGR_EXT: |
| 1523 |
for (i=0;i<n;i++) { |
| 1524 |
dst[i*4+0] = FLOAT_TO_INT(rgba[i][ACOMP]); |
| 1525 |
dst[i*4+1] = FLOAT_TO_INT(rgba[i][BCOMP]); |
| 1526 |
dst[i*4+2] = FLOAT_TO_INT(rgba[i][GCOMP]); |
| 1527 |
dst[i*4+3] = FLOAT_TO_INT(rgba[i][RCOMP]); |
| 1528 |
} |
| 1529 |
break; |
| 1530 |
default: |
| 1531 |
_mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
| 1532 |
} |
| 1533 |
if (dstPacking->SwapBytes) { |
| 1534 |
_mesa_swap4( (GLuint *) dst, n * comps ); |
| 1535 |
} |
| 1536 |
} |
| 1537 |
break; |
| 1538 |
case GL_FLOAT: |
| 1539 |
{ |
| 1540 |
GLfloat *dst = (GLfloat *) dstAddr; |
| 1541 |
switch (dstFormat) { |
| 1542 |
case GL_RED: |
| 1543 |
for (i=0;i<n;i++) |
| 1544 |
dst[i] = rgba[i][RCOMP]; |
| 1545 |
break; |
| 1546 |
case GL_GREEN: |
| 1547 |
for (i=0;i<n;i++) |
| 1548 |
dst[i] = rgba[i][GCOMP]; |
| 1549 |
break; |
| 1550 |
case GL_BLUE: |
| 1551 |
for (i=0;i<n;i++) |
| 1552 |
dst[i] = rgba[i][BCOMP]; |
| 1553 |
break; |
| 1554 |
case GL_ALPHA: |
| 1555 |
for (i=0;i<n;i++) |
| 1556 |
dst[i] = rgba[i][ACOMP]; |
| 1557 |
break; |
| 1558 |
case GL_LUMINANCE: |
| 1559 |
for (i=0;i<n;i++) |
| 1560 |
dst[i] = luminance[i]; |
| 1561 |
break; |
| 1562 |
case GL_LUMINANCE_ALPHA: |
| 1563 |
for (i=0;i<n;i++) { |
| 1564 |
dst[i*2+0] = luminance[i]; |
| 1565 |
dst[i*2+1] = rgba[i][ACOMP]; |
| 1566 |
} |
| 1567 |
break; |
| 1568 |
case GL_RGB: |
| 1569 |
for (i=0;i<n;i++) { |
| 1570 |
dst[i*3+0] = rgba[i][RCOMP]; |
| 1571 |
dst[i*3+1] = rgba[i][GCOMP]; |
| 1572 |
dst[i*3+2] = rgba[i][BCOMP]; |
| 1573 |
} |
| 1574 |
break; |
| 1575 |
case GL_RGBA: |
| 1576 |
for (i=0;i<n;i++) { |
| 1577 |
dst[i*4+0] = rgba[i][RCOMP]; |
| 1578 |
dst[i*4+1] = rgba[i][GCOMP]; |
| 1579 |
dst[i*4+2] = rgba[i][BCOMP]; |
| 1580 |
dst[i*4+3] = rgba[i][ACOMP]; |
| 1581 |
} |
| 1582 |
break; |
| 1583 |
case GL_BGR: |
| 1584 |
for (i=0;i<n;i++) { |
| 1585 |
dst[i*3+0] = rgba[i][BCOMP]; |
| 1586 |
dst[i*3+1] = rgba[i][GCOMP]; |
| 1587 |
dst[i*3+2] = rgba[i][RCOMP]; |
| 1588 |
} |
| 1589 |
break; |
| 1590 |
case GL_BGRA: |
| 1591 |
for (i=0;i<n;i++) { |
| 1592 |
dst[i*4+0] = rgba[i][BCOMP]; |
| 1593 |
dst[i*4+1] = rgba[i][GCOMP]; |
| 1594 |
dst[i*4+2] = rgba[i][RCOMP]; |
| 1595 |
dst[i*4+3] = rgba[i][ACOMP]; |
| 1596 |
} |
| 1597 |
break; |
| 1598 |
case GL_ABGR_EXT: |
| 1599 |
for (i=0;i<n;i++) { |
| 1600 |
dst[i*4+0] = rgba[i][ACOMP]; |
| 1601 |
dst[i*4+1] = rgba[i][BCOMP]; |
| 1602 |
dst[i*4+2] = rgba[i][GCOMP]; |
| 1603 |
dst[i*4+3] = rgba[i][RCOMP]; |
| 1604 |
} |
| 1605 |
break; |
| 1606 |
default: |
| 1607 |
_mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
| 1608 |
} |
| 1609 |
if (dstPacking->SwapBytes) { |
| 1610 |
_mesa_swap4( (GLuint *) dst, n * comps ); |
| 1611 |
} |
| 1612 |
} |
| 1613 |
break; |
| 1614 |
case GL_HALF_FLOAT_ARB: |
| 1615 |
{ |
| 1616 |
GLhalfARB *dst = (GLhalfARB *) dstAddr; |
| 1617 |
switch (dstFormat) { |
| 1618 |
case GL_RED: |
| 1619 |
for (i=0;i<n;i++) |
| 1620 |
dst[i] = _mesa_float_to_half(rgba[i][RCOMP]); |
| 1621 |
break; |
| 1622 |
case GL_GREEN: |
| 1623 |
for (i=0;i<n;i++) |
| 1624 |
dst[i] = _mesa_float_to_half(rgba[i][GCOMP]); |
| 1625 |
break; |
| 1626 |
case GL_BLUE: |
| 1627 |
for (i=0;i<n;i++) |
| 1628 |
dst[i] = _mesa_float_to_half(rgba[i][BCOMP]); |
| 1629 |
break; |
| 1630 |
case GL_ALPHA: |
| 1631 |
for (i=0;i<n;i++) |
| 1632 |
dst[i] = _mesa_float_to_half(rgba[i][ACOMP]); |
| 1633 |
break; |
| 1634 |
case GL_LUMINANCE: |
| 1635 |
for (i=0;i<n;i++) |
| 1636 |
dst[i] = _mesa_float_to_half(luminance[i]); |
| 1637 |
break; |
| 1638 |
case GL_LUMINANCE_ALPHA: |
| 1639 |
for (i=0;i<n;i++) { |
| 1640 |
dst[i*2+0] = _mesa_float_to_half(luminance[i]); |
| 1641 |
dst[i*2+1] = _mesa_float_to_half(rgba[i][ACOMP]); |
| 1642 |
} |
| 1643 |
break; |
| 1644 |
case GL_RGB: |
| 1645 |
for (i=0;i<n;i++) { |
| 1646 |
dst[i*3+0] = _mesa_float_to_half(rgba[i][RCOMP]); |
| 1647 |
dst[i*3+1] = _mesa_float_to_half(rgba[i][GCOMP]); |
| 1648 |
dst[i*3+2] = _mesa_float_to_half(rgba[i][BCOMP]); |
| 1649 |
} |
| 1650 |
break; |
| 1651 |
case GL_RGBA: |
| 1652 |
for (i=0;i<n;i++) { |
| 1653 |
dst[i*4+0] = _mesa_float_to_half(rgba[i][RCOMP]); |
| 1654 |
dst[i*4+1] = _mesa_float_to_half(rgba[i][GCOMP]); |
| 1655 |
dst[i*4+2] = _mesa_float_to_half(rgba[i][BCOMP]); |
| 1656 |
dst[i*4+3] = _mesa_float_to_half(rgba[i][ACOMP]); |
| 1657 |
} |
| 1658 |
break; |
| 1659 |
case GL_BGR: |
| 1660 |
for (i=0;i<n;i++) { |
| 1661 |
dst[i*3+0] = _mesa_float_to_half(rgba[i][BCOMP]); |
| 1662 |
dst[i*3+1] = _mesa_float_to_half(rgba[i][GCOMP]); |
| 1663 |
dst[i*3+2] = _mesa_float_to_half(rgba[i][RCOMP]); |
| 1664 |
} |
| 1665 |
break; |
| 1666 |
case GL_BGRA: |
| 1667 |
for (i=0;i<n;i++) { |
| 1668 |
dst[i*4+0] = _mesa_float_to_half(rgba[i][BCOMP]); |
| 1669 |
dst[i*4+1] = _mesa_float_to_half(rgba[i][GCOMP]); |
| 1670 |
dst[i*4+2] = _mesa_float_to_half(rgba[i][RCOMP]); |
| 1671 |
dst[i*4+3] = _mesa_float_to_half(rgba[i][ACOMP]); |
| 1672 |
} |
| 1673 |
break; |
| 1674 |
case GL_ABGR_EXT: |
| 1675 |
for (i=0;i<n;i++) { |
| 1676 |
dst[i*4+0] = _mesa_float_to_half(rgba[i][ACOMP]); |
| 1677 |
dst[i*4+1] = _mesa_float_to_half(rgba[i][BCOMP]); |
| 1678 |
dst[i*4+2] = _mesa_float_to_half(rgba[i][GCOMP]); |
| 1679 |
dst[i*4+3] = _mesa_float_to_half(rgba[i][RCOMP]); |
| 1680 |
} |
| 1681 |
break; |
| 1682 |
default: |
| 1683 |
_mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
| 1684 |
} |
| 1685 |
if (dstPacking->SwapBytes) { |
| 1686 |
_mesa_swap2( (GLushort *) dst, n * comps ); |
| 1687 |
} |
| 1688 |
} |
| 1689 |
break; |
| 1690 |
case GL_UNSIGNED_BYTE_3_3_2: |
| 1691 |
if (dstFormat == GL_RGB) { |
| 1692 |
GLubyte *dst = (GLubyte *) dstAddr; |
| 1693 |
for (i=0;i<n;i++) { |
| 1694 |
dst[i] = (((GLint) (rgba[i][RCOMP] * 7.0F)) << 5) |
| 1695 |
| (((GLint) (rgba[i][GCOMP] * 7.0F)) << 2) |
| 1696 |
| (((GLint) (rgba[i][BCOMP] * 3.0F)) ); |
| 1697 |
} |
| 1698 |
} |
| 1699 |
break; |
| 1700 |
case GL_UNSIGNED_BYTE_2_3_3_REV: |
| 1701 |
if (dstFormat == GL_RGB) { |
| 1702 |
GLubyte *dst = (GLubyte *) dstAddr; |
| 1703 |
for (i=0;i<n;i++) { |
| 1704 |
dst[i] = (((GLint) (rgba[i][RCOMP] * 7.0F)) ) |
| 1705 |
| (((GLint) (rgba[i][GCOMP] * 7.0F)) << 3) |
| 1706 |
| (((GLint) (rgba[i][BCOMP] * 3.0F)) << 5); |
| 1707 |
} |
| 1708 |
} |
| 1709 |
break; |
| 1710 |
case GL_UNSIGNED_SHORT_5_6_5: |
| 1711 |
if (dstFormat == GL_RGB) { |
| 1712 |
GLushort *dst = (GLushort *) dstAddr; |
| 1713 |
for (i=0;i<n;i++) { |
| 1714 |
dst[i] = (((GLint) (rgba[i][RCOMP] * 31.0F)) << 11) |
| 1715 |
| (((GLint) (rgba[i][GCOMP] * 63.0F)) << 5) |
| 1716 |
| (((GLint) (rgba[i][BCOMP] * 31.0F)) ); |
| 1717 |
} |
| 1718 |
} |
| 1719 |
break; |
| 1720 |
case GL_UNSIGNED_SHORT_5_6_5_REV: |
| 1721 |
if (dstFormat == GL_RGB) { |
| 1722 |
GLushort *dst = (GLushort *) dstAddr; |
| 1723 |
for (i=0;i<n;i++) { |
| 1724 |
dst[i] = (((GLint) (rgba[i][RCOMP] * 31.0F)) ) |
| 1725 |
| (((GLint) (rgba[i][GCOMP] * 63.0F)) << 5) |
| 1726 |
| (((GLint) (rgba[i][BCOMP] * 31.0F)) << 11); |
| 1727 |
} |
| 1728 |
} |
| 1729 |
break; |
| 1730 |
case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1731 |
if (dstFormat == GL_RGBA) { |
| 1732 |
GLushort *dst = (GLushort *) dstAddr; |
| 1733 |
for (i=0;i<n;i++) { |
| 1734 |
dst[i] = (((GLint) (rgba[i][RCOMP] * 15.0F)) << 12) |
| 1735 |
| (((GLint) (rgba[i][GCOMP] * 15.0F)) << 8) |
| 1736 |
| (((GLint) (rgba[i][BCOMP] * 15.0F)) << 4) |
| 1737 |
| (((GLint) (rgba[i][ACOMP] * 15.0F)) ); |
| 1738 |
} |
| 1739 |
} |
| 1740 |
else if (dstFormat == GL_BGRA) { |
| 1741 |
GLushort *dst = (GLushort *) dstAddr; |
| 1742 |
for (i=0;i<n;i++) { |
| 1743 |
dst[i] = (((GLint) (rgba[i][BCOMP] * 15.0F)) << 12) |
| 1744 |
| (((GLint) (rgba[i][GCOMP] * 15.0F)) << 8) |
| 1745 |
| (((GLint) (rgba[i][RCOMP] * 15.0F)) << 4) |
| 1746 |
| (((GLint) (rgba[i][ACOMP] * 15.0F)) ); |
| 1747 |
} |
| 1748 |
} |
| 1749 |
else if (dstFormat == GL_ABGR_EXT) { |
| 1750 |
GLushort *dst = (GLushort *) dstAddr; |
| 1751 |
for (i=0;i<n;i++) { |
| 1752 |
dst[i] = (((GLint) (rgba[i][ACOMP] * 15.0F)) << 4) |
| 1753 |
| (((GLint) (rgba[i][BCOMP] * 15.0F)) << 8) |
| 1754 |
| (((GLint) (rgba[i][GCOMP] * 15.0F)) << 12) |
| 1755 |
| (((GLint) (rgba[i][RCOMP] * 15.0F)) ); |
| 1756 |
} |
| 1757 |
} |
| 1758 |
break; |
| 1759 |
case GL_UNSIGNED_SHORT_4_4_4_4_REV: |
| 1760 |
if (dstFormat == GL_RGBA) { |
| 1761 |
GLushort *dst = (GLushort *) dstAddr; |
| 1762 |
for (i=0;i<n;i++) { |
| 1763 |
dst[i] = (((GLint) (rgba[i][RCOMP] * 15.0F)) ) |
| 1764 |
| (((GLint) (rgba[i][GCOMP] * 15.0F)) << 4) |
| 1765 |
| (((GLint) (rgba[i][BCOMP] * 15.0F)) << 8) |
| 1766 |
| (((GLint) (rgba[i][ACOMP] * 15.0F)) << 12); |
| 1767 |
} |
| 1768 |
} |
| 1769 |
else if (dstFormat == GL_BGRA) { |
| 1770 |
GLushort *dst = (GLushort *) dstAddr; |
| 1771 |
for (i=0;i<n;i++) { |
| 1772 |
dst[i] = (((GLint) (rgba[i][BCOMP] * 15.0F)) ) |
| 1773 |
| (((GLint) (rgba[i][GCOMP] * 15.0F)) << 4) |
| 1774 |
| (((GLint) (rgba[i][RCOMP] * 15.0F)) << 8) |
| 1775 |
| (((GLint) (rgba[i][ACOMP] * 15.0F)) << 12); |
| 1776 |
} |
| 1777 |
} |
| 1778 |
else if (dstFormat == GL_ABGR_EXT) { |
| 1779 |
GLushort *dst = (GLushort *) dstAddr; |
| 1780 |
for (i=0;i<n;i++) { |
| 1781 |
dst[i] = (((GLint) (rgba[i][ACOMP] * 15.0F)) ) |
| 1782 |
| (((GLint) (rgba[i][BCOMP] * 15.0F)) << 4) |
| 1783 |
| (((GLint) (rgba[i][GCOMP] * 15.0F)) << 8) |
| 1784 |
| (((GLint) (rgba[i][RCOMP] * 15.0F)) << 12); |
| 1785 |
} |
| 1786 |
} |
| 1787 |
break; |
| 1788 |
case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1789 |
if (dstFormat == GL_RGBA) { |
| 1790 |
GLushort *dst = (GLushort *) dstAddr; |
| 1791 |
for (i=0;i<n;i++) { |
| 1792 |
dst[i] = (((GLint) (rgba[i][RCOMP] * 31.0F)) << 11) |
| 1793 |
| (((GLint) (rgba[i][GCOMP] * 31.0F)) << 6) |
| 1794 |
| (((GLint) (rgba[i][BCOMP] * 31.0F)) << 1) |
| 1795 |
| (((GLint) (rgba[i][ACOMP] * 1.0F)) ); |
| 1796 |
} |
| 1797 |
} |
| 1798 |
else if (dstFormat == GL_BGRA) { |
| 1799 |
GLushort *dst = (GLushort *) dstAddr; |
| 1800 |
for (i=0;i<n;i++) { |
| 1801 |
dst[i] = (((GLint) (rgba[i][BCOMP] * 31.0F)) << 11) |
| 1802 |
| (((GLint) (rgba[i][GCOMP] * 31.0F)) << 6) |
| 1803 |
| (((GLint) (rgba[i][RCOMP] * 31.0F)) << 1) |
| 1804 |
| (((GLint) (rgba[i][ACOMP] * 1.0F)) ); |
| 1805 |
} |
| 1806 |
} |
| 1807 |
else if (dstFormat == GL_ABGR_EXT) { |
| 1808 |
GLushort *dst = (GLushort *) dstAddr; |
| 1809 |
for (i=0;i<n;i++) { |
| 1810 |
dst[i] = (((GLint) (rgba[i][ACOMP] * 31.0F)) << 11) |
| 1811 |
| (((GLint) (rgba[i][BCOMP] * 31.0F)) << 6) |
| 1812 |
| (((GLint) (rgba[i][GCOMP] * 31.0F)) << 1) |
| 1813 |
| (((GLint) (rgba[i][RCOMP] * 1.0F)) ); |
| 1814 |
} |
| 1815 |
} |
| 1816 |
break; |
| 1817 |
case GL_UNSIGNED_SHORT_1_5_5_5_REV: |
| 1818 |
if (dstFormat == GL_RGBA) { |
| 1819 |
GLushort *dst = (GLushort *) dstAddr; |
| 1820 |
for (i=0;i<n;i++) { |
| 1821 |
dst[i] = (((GLint) (rgba[i][RCOMP] * 31.0F)) ) |
| 1822 |
| (((GLint) (rgba[i][GCOMP] * 31.0F)) << 5) |
| 1823 |
| (((GLint) (rgba[i][BCOMP] * 31.0F)) << 10) |
| 1824 |
| (((GLint) (rgba[i][ACOMP] * 1.0F)) << 15); |
| 1825 |
} |
| 1826 |
} |
| 1827 |
else if (dstFormat == GL_BGRA) { |
| 1828 |
GLushort *dst = (GLushort *) dstAddr; |
| 1829 |
for (i=0;i<n;i++) { |
| 1830 |
dst[i] = (((GLint) (rgba[i][BCOMP] * 31.0F)) ) |
| 1831 |
| (((GLint) (rgba[i][GCOMP] * 31.0F)) << 5) |
| 1832 |
| (((GLint) (rgba[i][RCOMP] * 31.0F)) << 10) |
| 1833 |
| (((GLint) (rgba[i][ACOMP] * 1.0F)) << 15); |
| 1834 |
} |
| 1835 |
} |
| 1836 |
else if (dstFormat == GL_ABGR_EXT) { |
| 1837 |
GLushort *dst = (GLushort *) dstAddr; |
| 1838 |
for (i=0;i<n;i++) { |
| 1839 |
dst[i] = (((GLint) (rgba[i][ACOMP] * 31.0F)) ) |
| 1840 |
| (((GLint) (rgba[i][BCOMP] * 31.0F)) << 5) |
| 1841 |
| (((GLint) (rgba[i][GCOMP] * 31.0F)) << 10) |
| 1842 |
| (((GLint) (rgba[i][RCOMP] * 1.0F)) << 15); |
| 1843 |
} |
| 1844 |
} |
| 1845 |
break; |
| 1846 |
case GL_UNSIGNED_INT_8_8_8_8: |
| 1847 |
if (dstFormat == GL_RGBA) { |
| 1848 |
GLuint *dst = (GLuint *) dstAddr; |
| 1849 |
for (i=0;i<n;i++) { |
| 1850 |
dst[i] = (((GLuint) (rgba[i][RCOMP] * 255.0F)) << 24) |
| 1851 |
| (((GLuint) (rgba[i][GCOMP] * 255.0F)) << 16) |
| 1852 |
| (((GLuint) (rgba[i][BCOMP] * 255.0F)) << 8) |
| 1853 |
| (((GLuint) (rgba[i][ACOMP] * 255.0F)) ); |
| 1854 |
} |
| 1855 |
} |
| 1856 |
else if (dstFormat == GL_BGRA) { |
| 1857 |
GLuint *dst = (GLuint *) dstAddr; |
| 1858 |
for (i=0;i<n;i++) { |
| 1859 |
dst[i] = (((GLuint) (rgba[i][BCOMP] * 255.0F)) << 24) |
| 1860 |
| (((GLuint) (rgba[i][GCOMP] * 255.0F)) << 16) |
| 1861 |
| (((GLuint) (rgba[i][RCOMP] * 255.0F)) << 8) |
| 1862 |
| (((GLuint) (rgba[i][ACOMP] * 255.0F)) ); |
| 1863 |
} |
| 1864 |
} |
| 1865 |
else if (dstFormat == GL_ABGR_EXT) { |
| 1866 |
GLuint *dst = (GLuint *) dstAddr; |
| 1867 |
for (i=0;i<n;i++) { |
| 1868 |
dst[i] = (((GLuint) (rgba[i][ACOMP] * 255.0F)) << 24) |
| 1869 |
| (((GLuint) (rgba[i][BCOMP] * 255.0F)) << 16) |
| 1870 |
| (((GLuint) (rgba[i][GCOMP] * 255.0F)) << 8) |
| 1871 |
| (((GLuint) (rgba[i][RCOMP] * 255.0F)) ); |
| 1872 |
} |
| 1873 |
} |
| 1874 |
break; |
| 1875 |
case GL_UNSIGNED_INT_8_8_8_8_REV: |
| 1876 |
if (dstFormat == GL_RGBA) { |
| 1877 |
GLuint *dst = (GLuint *) dstAddr; |
| 1878 |
for (i=0;i<n;i++) { |
| 1879 |
dst[i] = (((GLuint) (rgba[i][RCOMP] * 255.0F)) ) |
| 1880 |
| (((GLuint) (rgba[i][GCOMP] * 255.0F)) << 8) |
| 1881 |
| (((GLuint) (rgba[i][BCOMP] * 255.0F)) << 16) |
| 1882 |
| (((GLuint) (rgba[i][ACOMP] * 255.0F)) << 24); |
| 1883 |
} |
| 1884 |
} |
| 1885 |
else if (dstFormat == GL_BGRA) { |
| 1886 |
GLuint *dst = (GLuint *) dstAddr; |
| 1887 |
for (i=0;i<n;i++) { |
| 1888 |
dst[i] = (((GLuint) (rgba[i][BCOMP] * 255.0F)) ) |
| 1889 |
| (((GLuint) (rgba[i][GCOMP] * 255.0F)) << 8) |
| 1890 |
| (((GLuint) (rgba[i][RCOMP] * 255.0F)) << 16) |
| 1891 |
| (((GLuint) (rgba[i][ACOMP] * 255.0F)) << 24); |
| 1892 |
} |
| 1893 |
} |
| 1894 |
else if (dstFormat == GL_ABGR_EXT) { |
| 1895 |
GLuint *dst = (GLuint *) dstAddr; |
| 1896 |
for (i=0;i<n;i++) { |
| 1897 |
dst[i] = (((GLuint) (rgba[i][ACOMP] * 255.0F)) ) |
| 1898 |
| (((GLuint) (rgba[i][BCOMP] * 255.0F)) << 8) |
| 1899 |
| (((GLuint) (rgba[i][GCOMP] * 255.0F)) << 16) |
| 1900 |
| (((GLuint) (rgba[i][RCOMP] * 255.0F)) << 24); |
| 1901 |
} |
| 1902 |
} |
| 1903 |
break; |
| 1904 |
case GL_UNSIGNED_INT_10_10_10_2: |
| 1905 |
if (dstFormat == GL_RGBA) { |
| 1906 |
GLuint *dst = (GLuint *) dstAddr; |
| 1907 |
for (i=0;i<n;i++) { |
| 1908 |
dst[i] = (((GLuint) (rgba[i][RCOMP] * 1023.0F)) << 22) |
| 1909 |
| (((GLuint) (rgba[i][GCOMP] * 1023.0F)) << 12) |
| 1910 |
| (((GLuint) (rgba[i][BCOMP] * 1023.0F)) << 2) |
| 1911 |
| (((GLuint) (rgba[i][ACOMP] * 3.0F)) ); |
| 1912 |
} |
| 1913 |
} |
| 1914 |
else if (dstFormat == GL_BGRA) { |
| 1915 |
GLuint *dst = (GLuint *) dstAddr; |
| 1916 |
for (i=0;i<n;i++) { |
| 1917 |
dst[i] = (((GLuint) (rgba[i][BCOMP] * 1023.0F)) << 22) |
| 1918 |
| (((GLuint) (rgba[i][GCOMP] * 1023.0F)) << 12) |
| 1919 |
| (((GLuint) (rgba[i][RCOMP] * 1023.0F)) << 2) |
| 1920 |
| (((GLuint) (rgba[i][ACOMP] * 3.0F)) ); |
| 1921 |
} |
| 1922 |
} |
| 1923 |
else if (dstFormat == GL_ABGR_EXT) { |
| 1924 |
GLuint *dst = (GLuint *) dstAddr; |
| 1925 |
for (i=0;i<n;i++) { |
| 1926 |
dst[i] = (((GLuint) (rgba[i][ACOMP] * 1023.0F)) << 22) |
| 1927 |
| (((GLuint) (rgba[i][BCOMP] * 1023.0F)) << 12) |
| 1928 |
| (((GLuint) (rgba[i][GCOMP] * 1023.0F)) << 2) |
| 1929 |
| (((GLuint) (rgba[i][RCOMP] * 3.0F)) ); |
| 1930 |
} |
| 1931 |
} |
| 1932 |
break; |
| 1933 |
case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 1934 |
if (dstFormat == GL_RGBA) { |
| 1935 |
GLuint *dst = (GLuint *) dstAddr; |
| 1936 |
for (i=0;i<n;i++) { |
| 1937 |
dst[i] = (((GLuint) (rgba[i][RCOMP] * 1023.0F)) ) |
| 1938 |
| (((GLuint) (rgba[i][GCOMP] * 1023.0F)) << 10) |
| 1939 |
| (((GLuint) (rgba[i][BCOMP] * 1023.0F)) << 20) |
| 1940 |
| (((GLuint) (rgba[i][ACOMP] * 3.0F)) << 30); |
| 1941 |
} |
| 1942 |
} |
| 1943 |
else if (dstFormat == GL_BGRA) { |
| 1944 |
GLuint *dst = (GLuint *) dstAddr; |
| 1945 |
for (i=0;i<n;i++) { |
| 1946 |
dst[i] = (((GLuint) (rgba[i][BCOMP] * 1023.0F)) ) |
| 1947 |
| (((GLuint) (rgba[i][GCOMP] * 1023.0F)) << 10) |
| 1948 |
| (((GLuint) (rgba[i][RCOMP] * 1023.0F)) << 20) |
| 1949 |
| (((GLuint) (rgba[i][ACOMP] * 3.0F)) << 30); |
| 1950 |
} |
| 1951 |
} |
| 1952 |
else if (dstFormat == GL_ABGR_EXT) { |
| 1953 |
GLuint *dst = (GLuint *) dstAddr; |
| 1954 |
for (i=0;i<n;i++) { |
| 1955 |
dst[i] = (((GLuint) (rgba[i][ACOMP] * 1023.0F)) ) |
| 1956 |
| (((GLuint) (rgba[i][BCOMP] * 1023.0F)) << 10) |
| 1957 |
| (((GLuint) (rgba[i][GCOMP] * 1023.0F)) << 20) |
| 1958 |
| (((GLuint) (rgba[i][RCOMP] * 3.0F)) << 30); |
| 1959 |
} |
| 1960 |
} |
| 1961 |
break; |
| 1962 |
default: |
| 1963 |
_mesa_problem(ctx, "bad type in _mesa_pack_rgba_span_float"); |
| 1964 |
} |
| 1965 |
} |
| 1966 |
|
| 1967 |
|
| 1968 |
/* |
| 1969 |
* Pack the given RGBA span into client memory at 'dest' address |
| 1970 |
* in the given pixel format and type. |
| 1971 |
* Optionally apply the enabled pixel transfer ops. |
| 1972 |
* Pack into memory using the given packing params struct. |
| 1973 |
* This is used by glReadPixels and glGetTexImage?D() |
| 1974 |
* \param ctx - the context |
| 1975 |
* n - number of pixels in the span |
| 1976 |
* rgba - the pixels |
| 1977 |
* format - dest packing format |
| 1978 |
* type - dest packing data type |
| 1979 |
* destination - destination packing address |
| 1980 |
* packing - pixel packing parameters |
| 1981 |
* transferOps - bitmask of IMAGE_*_BIT operations to apply |
| 1982 |
*/ |
| 1983 |
void |
| 1984 |
_mesa_pack_rgba_span_chan( GLcontext *ctx, |
| 1985 |
GLuint n, CONST GLchan srcRgba[][4], |
| 1986 |
GLenum dstFormat, GLenum dstType, |
| 1987 |
GLvoid *dstAddr, |
| 1988 |
const struct gl_pixelstore_attrib *dstPacking, |
| 1989 |
GLuint transferOps) |
| 1990 |
{ |
| 1991 |
ASSERT((ctx->NewState & _NEW_PIXEL) == 0 || transferOps == 0); |
| 1992 |
|
| 1993 |
/* Test for optimized case first */ |
| 1994 |
if (transferOps == 0 && dstFormat == GL_RGBA && dstType == CHAN_TYPE) { |
| 1995 |
/* common simple case */ |
| 1996 |
MEMCPY(dstAddr, srcRgba, n * 4 * sizeof(GLchan)); |
| 1997 |
} |
| 1998 |
else if (transferOps == 0 && dstFormat == GL_RGB && dstType == CHAN_TYPE) { |
| 1999 |
/* common simple case */ |
| 2000 |
GLuint i; |
| 2001 |
GLchan *dest = (GLchan *) dstAddr; |
| 2002 |
for (i = 0; i < n; i++) { |
| 2003 |
dest[0] = srcRgba[i][RCOMP]; |
| 2004 |
dest[1] = srcRgba[i][GCOMP]; |
| 2005 |
dest[2] = srcRgba[i][BCOMP]; |
| 2006 |
dest += 3; |
| 2007 |
} |
| 2008 |
} |
| 2009 |
else if (transferOps == 0 && dstFormat == GL_RGBA && dstType == GL_UNSIGNED_BYTE) { |
| 2010 |
/* common simple case */ |
| 2011 |
GLuint i; |
| 2012 |
GLubyte *dest = (GLubyte *) dstAddr; |
| 2013 |
for (i = 0; i < n; i++) { |
| 2014 |
dest[0] = CHAN_TO_UBYTE(srcRgba[i][RCOMP]); |
| 2015 |
dest[1] = CHAN_TO_UBYTE(srcRgba[i][GCOMP]); |
| 2016 |
dest[2] = CHAN_TO_UBYTE(srcRgba[i][BCOMP]); |
| 2017 |
dest[3] = CHAN_TO_UBYTE(srcRgba[i][ACOMP]); |
| 2018 |
dest += 4; |
| 2019 |
} |
| 2020 |
} |
| 2021 |
else { |
| 2022 |
/* general solution */ |
| 2023 |
GLuint i; |
| 2024 |
DEFMARRAY(GLfloat, rgba, MAX_WIDTH, 4); /* mac 32k limitation */ |
| 2025 |
CHECKARRAY(rgba, return); /* mac 32k limitation */ |
| 2026 |
|
| 2027 |
assert(n <= MAX_WIDTH); |
| 2028 |
/* convert color components to floating point */ |
| 2029 |
for (i = 0; i < n; i++) { |
| 2030 |
rgba[i][RCOMP] = CHAN_TO_FLOAT(srcRgba[i][RCOMP]); |
| 2031 |
rgba[i][GCOMP] = CHAN_TO_FLOAT(srcRgba[i][GCOMP]); |
| 2032 |
rgba[i][BCOMP] = CHAN_TO_FLOAT(srcRgba[i][BCOMP]); |
| 2033 |
rgba[i][ACOMP] = CHAN_TO_FLOAT(srcRgba[i][ACOMP]); |
| 2034 |
} |
| 2035 |
_mesa_pack_rgba_span_float(ctx, n, (const GLfloat (*)[4]) rgba, |
| 2036 |
dstFormat, dstType, dstAddr, |
| 2037 |
dstPacking, transferOps); |
| 2038 |
UNDEFARRAY(rgba); /* mac 32k limitation */ |
| 2039 |
} |
| 2040 |
} |
| 2041 |
|
| 2042 |
|
| 2043 |
#define SWAP2BYTE(VALUE) \ |
| 2044 |
{ \ |
| 2045 |
GLubyte *bytes = (GLubyte *) &(VALUE); \ |
| 2046 |
GLubyte tmp = bytes[0]; \ |
| 2047 |
bytes[0] = bytes[1]; \ |
| 2048 |
bytes[1] = tmp; \ |
| 2049 |
} |
| 2050 |
|
| 2051 |
#define SWAP4BYTE(VALUE) \ |
| 2052 |
{ \ |
| 2053 |
GLubyte *bytes = (GLubyte *) &(VALUE); \ |
| 2054 |
GLubyte tmp = bytes[0]; \ |
| 2055 |
bytes[0] = bytes[3]; \ |
| 2056 |
bytes[3] = tmp; \ |
| 2057 |
tmp = bytes[1]; \ |
| 2058 |
bytes[1] = bytes[2]; \ |
| 2059 |
bytes[2] = tmp; \ |
| 2060 |
} |
| 2061 |
|
| 2062 |
|
| 2063 |
static void |
| 2064 |
extract_uint_indexes(GLuint n, GLuint indexes[], |
| 2065 |
GLenum srcFormat, GLenum srcType, const GLvoid *src, |
| 2066 |
const struct gl_pixelstore_attrib *unpack ) |
| 2067 |
{ |
| 2068 |
assert(srcFormat == GL_COLOR_INDEX); |
| 2069 |
|
| 2070 |
ASSERT(srcType == GL_BITMAP || |
| 2071 |
srcType == GL_UNSIGNED_BYTE || |
| 2072 |
srcType == GL_BYTE || |
| 2073 |
srcType == GL_UNSIGNED_SHORT || |
| 2074 |
srcType == GL_SHORT || |
| 2075 |
srcType == GL_UNSIGNED_INT || |
| 2076 |
srcType == GL_INT || |
| 2077 |
srcType == GL_HALF_FLOAT_ARB || |
| 2078 |
srcType == GL_FLOAT); |
| 2079 |
|
| 2080 |
switch (srcType) { |
| 2081 |
case GL_BITMAP: |
| 2082 |
{ |
| 2083 |
GLubyte *ubsrc = (GLubyte *) src; |
| 2084 |
if (unpack->LsbFirst) { |
| 2085 |
GLubyte mask = 1 << (unpack->SkipPixels & 0x7); |
| 2086 |
GLuint i; |
| 2087 |
for (i = 0; i < n; i++) { |
| 2088 |
indexes[i] = (*ubsrc & mask) ? 1 : 0; |
| 2089 |
if (mask == 128) { |
| 2090 |
mask = 1; |
| 2091 |
ubsrc++; |
| 2092 |
} |
| 2093 |
else { |
| 2094 |
mask = mask << 1; |
| 2095 |
} |
| 2096 |
} |
| 2097 |
} |
| 2098 |
else { |
| 2099 |
GLubyte mask = 128 >> (unpack->SkipPixels & 0x7); |
| 2100 |
GLuint i; |
| 2101 |
for (i = 0; i < n; i++) { |
| 2102 |
indexes[i] = (*ubsrc & mask) ? 1 : 0; |
| 2103 |
if (mask == 1) { |
| 2104 |
mask = 128; |
| 2105 |
ubsrc++; |
| 2106 |
} |
| 2107 |
else { |
| 2108 |
mask = mask >> 1; |
| 2109 |
} |
| 2110 |
} |
| 2111 |
} |
| 2112 |
} |
| 2113 |
break; |
| 2114 |
case GL_UNSIGNED_BYTE: |
| 2115 |
{ |
| 2116 |
GLuint i; |
| 2117 |
const GLubyte *s = (const GLubyte *) src; |
| 2118 |
for (i = 0; i < n; i++) |
| 2119 |
indexes[i] = s[i]; |
| 2120 |
} |
| 2121 |
break; |
| 2122 |
case GL_BYTE: |
| 2123 |
{ |
| 2124 |
GLuint i; |
| 2125 |
const GLbyte *s = (const GLbyte *) src; |
| 2126 |
for (i = 0; i < n; i++) |
| 2127 |
indexes[i] = s[i]; |
| 2128 |
} |
| 2129 |
break; |
| 2130 |
case GL_UNSIGNED_SHORT: |
| 2131 |
{ |
| 2132 |
GLuint i; |
| 2133 |
const GLushort *s = (const GLushort *) src; |
| 2134 |
if (unpack->SwapBytes) { |
| 2135 |
for (i = 0; i < n; i++) { |
| 2136 |
GLushort value = s[i]; |
| 2137 |
SWAP2BYTE(value); |
| 2138 |
indexes[i] = value; |
| 2139 |
} |
| 2140 |
} |
| 2141 |
else { |
| 2142 |
for (i = 0; i < n; i++) |
| 2143 |
indexes[i] = s[i]; |
| 2144 |
} |
| 2145 |
} |
| 2146 |
break; |
| 2147 |
case GL_SHORT: |
| 2148 |
{ |
| 2149 |
GLuint i; |
| 2150 |
const GLshort *s = (const GLshort *) src; |
| 2151 |
if (unpack->SwapBytes) { |
| 2152 |
for (i = 0; i < n; i++) { |
| 2153 |
GLshort value = s[i]; |
| 2154 |
SWAP2BYTE(value); |
| 2155 |
indexes[i] = value; |
| 2156 |
} |
| 2157 |
} |
| 2158 |
else { |
| 2159 |
for (i = 0; i < n; i++) |
| 2160 |
indexes[i] = s[i]; |
| 2161 |
} |
| 2162 |
} |
| 2163 |
break; |
| 2164 |
case GL_UNSIGNED_INT: |
| 2165 |
{ |
| 2166 |
GLuint i; |
| 2167 |
const GLuint *s = (const GLuint *) src; |
| 2168 |
if (unpack->SwapBytes) { |
| 2169 |
for (i = 0; i < n; i++) { |
| 2170 |
GLuint value = s[i]; |
| 2171 |
SWAP4BYTE(value); |
| 2172 |
indexes[i] = value; |
| 2173 |
} |
| 2174 |
} |
| 2175 |
else { |
| 2176 |
for (i = 0; i < n; i++) |
| 2177 |
indexes[i] = s[i]; |
| 2178 |
} |
| 2179 |
} |
| 2180 |
break; |
| 2181 |
case GL_INT: |
| 2182 |
{ |
| 2183 |
GLuint i; |
| 2184 |
const GLint *s = (const GLint *) src; |
| 2185 |
if (unpack->SwapBytes) { |
| 2186 |
for (i = 0; i < n; i++) { |
| 2187 |
GLint value = s[i]; |
| 2188 |
SWAP4BYTE(value); |
| 2189 |
indexes[i] = value; |
| 2190 |
} |
| 2191 |
} |
| 2192 |
else { |
| 2193 |
for (i = 0; i < n; i++) |
| 2194 |
indexes[i] = s[i]; |
| 2195 |
} |
| 2196 |
} |
| 2197 |
break; |
| 2198 |
case GL_FLOAT: |
| 2199 |
{ |
| 2200 |
GLuint i; |
| 2201 |
const GLfloat *s = (const GLfloat *) src; |
| 2202 |
if (unpack->SwapBytes) { |
| 2203 |
for (i = 0; i < n; i++) { |
| 2204 |
GLfloat value = s[i]; |
| 2205 |
SWAP4BYTE(value); |
| 2206 |
indexes[i] = (GLuint) value; |
| 2207 |
} |
| 2208 |
} |
| 2209 |
else { |
| 2210 |
for (i = 0; i < n; i++) |
| 2211 |
indexes[i] = (GLuint) s[i]; |
| 2212 |
} |
| 2213 |
} |
| 2214 |
break; |
| 2215 |
case GL_HALF_FLOAT_ARB: |
| 2216 |
{ |
| 2217 |
GLuint i; |
| 2218 |
const GLhalfARB *s = (const GLhalfARB *) src; |
| 2219 |
if (unpack->SwapBytes) { |
| 2220 |
for (i = 0; i < n; i++) { |
| 2221 |
GLhalfARB value = s[i]; |
| 2222 |
SWAP2BYTE(value); |
| 2223 |
indexes[i] = (GLuint) _mesa_half_to_float(value); |
| 2224 |
} |
| 2225 |
} |
| 2226 |
else { |
| 2227 |
for (i = 0; i < n; i++) |
| 2228 |
indexes[i] = (GLuint) _mesa_half_to_float(s[i]); |
| 2229 |
} |
| 2230 |
} |
| 2231 |
break; |
| 2232 |
default: |
| 2233 |
_mesa_problem(NULL, "bad srcType in extract_uint_indexes"); |
| 2234 |
return; |
| 2235 |
} |
| 2236 |
} |
| 2237 |
|
| 2238 |
|
| 2239 |
/* |
| 2240 |
* This function extracts floating point RGBA values from arbitrary |
| 2241 |
* image data. srcFormat and srcType are the format and type parameters |
| 2242 |
* passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc. |
| 2243 |
* |
| 2244 |
* Refering to section 3.6.4 of the OpenGL 1.2 spec, this function |
| 2245 |
* implements the "Conversion to floating point", "Conversion to RGB", |
| 2246 |
* and "Final Expansion to RGBA" operations. |
| 2247 |
* |
| 2248 |
* Args: n - number of pixels |
| 2249 |
* rgba - output colors |
| 2250 |
* srcFormat - format of incoming data |
| 2251 |
* srcType - data type of incoming data |
| 2252 |
* src - source data pointer |
| 2253 |
* swapBytes - perform byteswapping of incoming data? |
| 2254 |
*/ |
| 2255 |
static void |
| 2256 |
extract_float_rgba(GLuint n, GLfloat rgba[][4], |
| 2257 |
GLenum srcFormat, GLenum srcType, const GLvoid *src, |
| 2258 |
GLboolean swapBytes) |
| 2259 |
{ |
| 2260 |
GLint redIndex, greenIndex, blueIndex, alphaIndex; |
| 2261 |
GLint stride; |
| 2262 |
GLint rComp, bComp, gComp, aComp; |
| 2263 |
|
| 2264 |
ASSERT(srcFormat == GL_RED || |
| 2265 |
srcFormat == GL_GREEN || |
| 2266 |
srcFormat == GL_BLUE || |
| 2267 |
srcFormat == GL_ALPHA || |
| 2268 |
srcFormat == GL_LUMINANCE || |
| 2269 |
srcFormat == GL_LUMINANCE_ALPHA || |
| 2270 |
srcFormat == GL_INTENSITY || |
| 2271 |
srcFormat == GL_RGB || |
| 2272 |
srcFormat == GL_BGR || |
| 2273 |
srcFormat == GL_RGBA || |
| 2274 |
srcFormat == GL_BGRA || |
| 2275 |
srcFormat == GL_ABGR_EXT); |
| 2276 |
|
| 2277 |
ASSERT(srcType == GL_UNSIGNED_BYTE || |
| 2278 |
srcType == GL_BYTE || |
| 2279 |
srcType == GL_UNSIGNED_SHORT || |
| 2280 |
srcType == GL_SHORT || |
| 2281 |
srcType == GL_UNSIGNED_INT || |
| 2282 |
srcType == GL_INT || |
| 2283 |
srcType == GL_HALF_FLOAT_ARB || |
| 2284 |
srcType == GL_FLOAT || |
| 2285 |
srcType == GL_UNSIGNED_BYTE_3_3_2 || |
| 2286 |
srcType == GL_UNSIGNED_BYTE_2_3_3_REV || |
| 2287 |
srcType == GL_UNSIGNED_SHORT_5_6_5 || |
| 2288 |
srcType == GL_UNSIGNED_SHORT_5_6_5_REV || |
| 2289 |
srcType == GL_UNSIGNED_SHORT_4_4_4_4 || |
| 2290 |
srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV || |
| 2291 |
srcType == GL_UNSIGNED_SHORT_5_5_5_1 || |
| 2292 |
srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV || |
| 2293 |
srcType == GL_UNSIGNED_INT_8_8_8_8 || |
| 2294 |
srcType == GL_UNSIGNED_INT_8_8_8_8_REV || |
| 2295 |
srcType == GL_UNSIGNED_INT_10_10_10_2 || |
| 2296 |
srcType == GL_UNSIGNED_INT_2_10_10_10_REV); |
| 2297 |
|
| 2298 |
rComp = gComp = bComp = aComp = -1; |
| 2299 |
|
| 2300 |
switch (srcFormat) { |
| 2301 |
case GL_RED: |
| 2302 |
redIndex = 0; |
| 2303 |
greenIndex = blueIndex = alphaIndex = -1; |
| 2304 |
stride = 1; |
| 2305 |
break; |
| 2306 |
case GL_GREEN: |
| 2307 |
greenIndex = 0; |
| 2308 |
redIndex = blueIndex = alphaIndex = -1; |
| 2309 |
stride = 1; |
| 2310 |
break; |
| 2311 |
case GL_BLUE: |
| 2312 |
blueIndex = 0; |
| 2313 |
redIndex = greenIndex = alphaIndex = -1; |
| 2314 |
stride = 1; |
| 2315 |
break; |
| 2316 |
case GL_ALPHA: |
| 2317 |
redIndex = greenIndex = blueIndex = -1; |
| 2318 |
alphaIndex = 0; |
| 2319 |
stride = 1; |
| 2320 |
break; |
| 2321 |
case GL_LUMINANCE: |
| 2322 |
redIndex = greenIndex = blueIndex = 0; |
| 2323 |
alphaIndex = -1; |
| 2324 |
stride = 1; |
| 2325 |
break; |
| 2326 |
case GL_LUMINANCE_ALPHA: |
| 2327 |
redIndex = greenIndex = blueIndex = 0; |
| 2328 |
alphaIndex = 1; |
| 2329 |
stride = 2; |
| 2330 |
break; |
| 2331 |
case GL_INTENSITY: |
| 2332 |
redIndex = greenIndex = blueIndex = alphaIndex = 0; |
| 2333 |
stride = 1; |
| 2334 |
break; |
| 2335 |
case GL_RGB: |
| 2336 |
redIndex = 0; |
| 2337 |
greenIndex = 1; |
| 2338 |
blueIndex = 2; |
| 2339 |
alphaIndex = -1; |
| 2340 |
rComp = 0; |
| 2341 |
gComp = 1; |
| 2342 |
bComp = 2; |
| 2343 |
aComp = 3; |
| 2344 |
stride = 3; |
| 2345 |
break; |
| 2346 |
case GL_BGR: |
| 2347 |
redIndex = 2; |
| 2348 |
greenIndex = 1; |
| 2349 |
blueIndex = 0; |
| 2350 |
alphaIndex = -1; |
| 2351 |
rComp = 2; |
| 2352 |
gComp = 1; |
| 2353 |
bComp = 0; |
| 2354 |
aComp = 3; |
| 2355 |
stride = 3; |
| 2356 |
break; |
| 2357 |
case GL_RGBA: |
| 2358 |
redIndex = 0; |
| 2359 |
greenIndex = 1; |
| 2360 |
blueIndex = 2; |
| 2361 |
alphaIndex = 3; |
| 2362 |
rComp = 0; |
| 2363 |
gComp = 1; |
| 2364 |
bComp = 2; |
| 2365 |
aComp = 3; |
| 2366 |
stride = 4; |
| 2367 |
break; |
| 2368 |
case GL_BGRA: |
| 2369 |
redIndex = 2; |
| 2370 |
greenIndex = 1; |
| 2371 |
blueIndex = 0; |
| 2372 |
alphaIndex = 3; |
| 2373 |
rComp = 2; |
| 2374 |
gComp = 1; |
| 2375 |
bComp = 0; |
| 2376 |
aComp = 3; |
| 2377 |
stride = 4; |
| 2378 |
break; |
| 2379 |
case GL_ABGR_EXT: |
| 2380 |
redIndex = 3; |
| 2381 |
greenIndex = 2; |
| 2382 |
blueIndex = 1; |
| 2383 |
alphaIndex = 0; |
| 2384 |
rComp = 3; |
| 2385 |
gComp = 2; |
| 2386 |
bComp = 1; |
| 2387 |
aComp = 0; |
| 2388 |
stride = 4; |
| 2389 |
break; |
| 2390 |
default: |
| 2391 |
_mesa_problem(NULL, "bad srcFormat in extract float data"); |
| 2392 |
return; |
| 2393 |
} |
| 2394 |
|
| 2395 |
|
| 2396 |
#define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \ |
| 2397 |
if ((INDEX) < 0) { \ |
| 2398 |
GLuint i; \ |
| 2399 |
for (i = 0; i < n; i++) { \ |
| 2400 |
rgba[i][CHANNEL] = DEFAULT; \ |
| 2401 |
} \ |
| 2402 |
} \ |
| 2403 |
else if (swapBytes) { \ |
| 2404 |
const TYPE *s = (const TYPE *) src; \ |
| 2405 |
GLuint i; \ |
| 2406 |
for (i = 0; i < n; i++) { \ |
| 2407 |
TYPE value = s[INDEX]; \ |
| 2408 |
if (sizeof(TYPE) == 2) { \ |
| 2409 |
SWAP2BYTE(value); \ |
| 2410 |
} \ |
| 2411 |
else if (sizeof(TYPE) == 4) { \ |
| 2412 |
SWAP4BYTE(value); \ |
| 2413 |
} \ |
| 2414 |
rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \ |
| 2415 |
s += stride; \ |
| 2416 |
} \ |
| 2417 |
} \ |
| 2418 |
else { \ |
| 2419 |
const TYPE *s = (const TYPE *) src; \ |
| 2420 |
GLuint i; \ |
| 2421 |
for (i = 0; i < n; i++) { \ |
| 2422 |
rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \ |
| 2423 |
s += stride; \ |
| 2424 |
} \ |
| 2425 |
} |
| 2426 |
|
| 2427 |
switch (srcType) { |
| 2428 |
case GL_UNSIGNED_BYTE: |
| 2429 |
PROCESS(redIndex, RCOMP, 0.0F, GLubyte, UBYTE_TO_FLOAT); |
| 2430 |
PROCESS(greenIndex, GCOMP, 0.0F, GLubyte, UBYTE_TO_FLOAT); |
| 2431 |
PROCESS(blueIndex, BCOMP, 0.0F, GLubyte, UBYTE_TO_FLOAT); |
| 2432 |
PROCESS(alphaIndex, ACOMP, 1.0F, GLubyte, UBYTE_TO_FLOAT); |
| 2433 |
break; |
| 2434 |
case GL_BYTE: |
| 2435 |
PROCESS(redIndex, RCOMP, 0.0F, GLbyte, BYTE_TO_FLOAT); |
| 2436 |
PROCESS(greenIndex, GCOMP, 0.0F, GLbyte, BYTE_TO_FLOAT); |
| 2437 |
PROCESS(blueIndex, BCOMP, 0.0F, GLbyte, BYTE_TO_FLOAT); |
| 2438 |
PROCESS(alphaIndex, ACOMP, 1.0F, GLbyte, BYTE_TO_FLOAT); |
| 2439 |
break; |
| 2440 |
case GL_UNSIGNED_SHORT: |
| 2441 |
PROCESS(redIndex, RCOMP, 0.0F, GLushort, USHORT_TO_FLOAT); |
| 2442 |
PROCESS(greenIndex, GCOMP, 0.0F, GLushort, USHORT_TO_FLOAT); |
| 2443 |
PROCESS(blueIndex, BCOMP, 0.0F, GLushort, USHORT_TO_FLOAT); |
| 2444 |
PROCESS(alphaIndex, ACOMP, 1.0F, GLushort, USHORT_TO_FLOAT); |
| 2445 |
break; |
| 2446 |
case GL_SHORT: |
| 2447 |
PROCESS(redIndex, RCOMP, 0.0F, GLshort, SHORT_TO_FLOAT); |
| 2448 |
PROCESS(greenIndex, GCOMP, 0.0F, GLshort, SHORT_TO_FLOAT); |
| 2449 |
PROCESS(blueIndex, BCOMP, 0.0F, GLshort, SHORT_TO_FLOAT); |
| 2450 |
PROCESS(alphaIndex, ACOMP, 1.0F, GLshort, SHORT_TO_FLOAT); |
| 2451 |
break; |
| 2452 |
case GL_UNSIGNED_INT: |
| 2453 |
PROCESS(redIndex, RCOMP, 0.0F, GLuint, UINT_TO_FLOAT); |
| 2454 |
PROCESS(greenIndex, GCOMP, 0.0F, GLuint, UINT_TO_FLOAT); |
| 2455 |
PROCESS(blueIndex, BCOMP, 0.0F, GLuint, UINT_TO_FLOAT); |
| 2456 |
PROCESS(alphaIndex, ACOMP, 1.0F, GLuint, UINT_TO_FLOAT); |
| 2457 |
break; |
| 2458 |
case GL_INT: |
| 2459 |
PROCESS(redIndex, RCOMP, 0.0F, GLint, INT_TO_FLOAT); |
| 2460 |
PROCESS(greenIndex, GCOMP, 0.0F, GLint, INT_TO_FLOAT); |
| 2461 |
PROCESS(blueIndex, BCOMP, 0.0F, GLint, INT_TO_FLOAT); |
| 2462 |
PROCESS(alphaIndex, ACOMP, 1.0F, GLint, INT_TO_FLOAT); |
| 2463 |
break; |
| 2464 |
case GL_FLOAT: |
| 2465 |
PROCESS(redIndex, RCOMP, 0.0F, GLfloat, (GLfloat)); |
| 2466 |
PROCESS(greenIndex, GCOMP, 0.0F, GLfloat, (GLfloat)); |
| 2467 |
PROCESS(blueIndex, BCOMP, 0.0F, GLfloat, (GLfloat)); |
| 2468 |
PROCESS(alphaIndex, ACOMP, 1.0F, GLfloat, (GLfloat)); |
| 2469 |
break; |
| 2470 |
case GL_HALF_FLOAT_ARB: |
| 2471 |
PROCESS(redIndex, RCOMP, 0.0F, GLhalfARB, _mesa_half_to_float); |
| 2472 |
PROCESS(greenIndex, GCOMP, 0.0F, GLhalfARB, _mesa_half_to_float); |
| 2473 |
PROCESS(blueIndex, BCOMP, 0.0F, GLhalfARB, _mesa_half_to_float); |
| 2474 |
PROCESS(alphaIndex, ACOMP, 1.0F, GLhalfARB, _mesa_half_to_float); |
| 2475 |
break; |
| 2476 |
case GL_UNSIGNED_BYTE_3_3_2: |
| 2477 |
{ |
| 2478 |
const GLubyte *ubsrc = (const GLubyte *) src; |
| 2479 |
GLuint i; |
| 2480 |
for (i = 0; i < n; i ++) { |
| 2481 |
GLubyte p = ubsrc[i]; |
| 2482 |
rgba[i][rComp] = ((p >> 5) ) * (1.0F / 7.0F); |
| 2483 |
rgba[i][gComp] = ((p >> 2) & 0x7) * (1.0F / 7.0F); |
| 2484 |
rgba[i][bComp] = ((p ) & 0x3) * (1.0F / 3.0F); |
| 2485 |
rgba[i][aComp] = 1.0F; |
| 2486 |
} |
| 2487 |
} |
| 2488 |
break; |
| 2489 |
case GL_UNSIGNED_BYTE_2_3_3_REV: |
| 2490 |
{ |
| 2491 |
const GLubyte *ubsrc = (const GLubyte *) src; |
| 2492 |
GLuint i; |
| 2493 |
for (i = 0; i < n; i ++) { |
| 2494 |
GLubyte p = ubsrc[i]; |
| 2495 |
rgba[i][rComp] = ((p ) & 0x7) * (1.0F / 7.0F); |
| 2496 |
rgba[i][gComp] = ((p >> 3) & 0x7) * (1.0F / 7.0F); |
| 2497 |
rgba[i][bComp] = ((p >> 6) ) * (1.0F / 3.0F); |
| 2498 |
rgba[i][aComp] = 1.0F; |
| 2499 |
} |
| 2500 |
} |
| 2501 |
break; |
| 2502 |
case GL_UNSIGNED_SHORT_5_6_5: |
| 2503 |
if (swapBytes) { |
| 2504 |
const GLushort *ussrc = (const GLushort *) src; |
| 2505 |
GLuint i; |
| 2506 |
for (i = 0; i < n; i ++) { |
| 2507 |
GLushort p = ussrc[i]; |
| 2508 |
SWAP2BYTE(p); |
| 2509 |
rgba[i][rComp] = ((p >> 11) ) * (1.0F / 31.0F); |
| 2510 |
rgba[i][gComp] = ((p >> 5) & 0x3f) * (1.0F / 63.0F); |
| 2511 |
rgba[i][bComp] = ((p ) & 0x1f) * (1.0F / 31.0F); |
| 2512 |
rgba[i][aComp] = 1.0F; |
| 2513 |
} |
| 2514 |
} |
| 2515 |
else { |
| 2516 |
const GLushort *ussrc = (const GLushort *) src; |
| 2517 |
GLuint i; |
| 2518 |
for (i = 0; i < n; i ++) { |
| 2519 |
GLushort p = ussrc[i]; |
| 2520 |
rgba[i][rComp] = ((p >> 11) ) * (1.0F / 31.0F); |
| 2521 |
rgba[i][gComp] = ((p >> 5) & 0x3f) * (1.0F / 63.0F); |
| 2522 |
rgba[i][bComp] = ((p ) & 0x1f) * (1.0F / 31.0F); |
| 2523 |
rgba[i][aComp] = 1.0F; |
| 2524 |
} |
| 2525 |
} |
| 2526 |
break; |
| 2527 |
case GL_UNSIGNED_SHORT_5_6_5_REV: |
| 2528 |
if (swapBytes) { |
| 2529 |
const GLushort *ussrc = (const GLushort *) src; |
| 2530 |
GLuint i; |
| 2531 |
for (i = 0; i < n; i ++) { |
| 2532 |
GLushort p = ussrc[i]; |
| 2533 |
SWAP2BYTE(p); |
| 2534 |
rgba[i][rComp] = ((p ) & 0x1f) * (1.0F / 31.0F); |
| 2535 |
rgba[i][gComp] = ((p >> 5) & 0x3f) * (1.0F / 63.0F); |
| 2536 |
rgba[i][bComp] = ((p >> 11) ) * (1.0F / 31.0F); |
| 2537 |
rgba[i][aComp] = 1.0F; |
| 2538 |
} |
| 2539 |
} |
| 2540 |
else { |
| 2541 |
const GLushort *ussrc = (const GLushort *) src; |
| 2542 |
GLuint i; |
| 2543 |
for (i = 0; i < n; i ++) { |
| 2544 |
GLushort p = ussrc[i]; |
| 2545 |
rgba[i][rComp] = ((p ) & 0x1f) * (1.0F / 31.0F); |
| 2546 |
rgba[i][gComp] = ((p >> 5) & 0x3f) * (1.0F / 63.0F); |
| 2547 |
rgba[i][bComp] = ((p >> 11) ) * (1.0F / 31.0F); |
| 2548 |
rgba[i][aComp] = 1.0F; |
| 2549 |
} |
| 2550 |
} |
| 2551 |
break; |
| 2552 |
case GL_UNSIGNED_SHORT_4_4_4_4: |
| 2553 |
if (swapBytes) { |
| 2554 |
const GLushort *ussrc = (const GLushort *) src; |
| 2555 |
GLuint i; |
| 2556 |
for (i = 0; i < n; i ++) { |
| 2557 |
GLushort p = ussrc[i]; |
| 2558 |
SWAP2BYTE(p); |
| 2559 |
rgba[i][rComp] = ((p >> 12) ) * (1.0F / 15.0F); |
| 2560 |
rgba[i][gComp] = ((p >> 8) & 0xf) * (1.0F / 15.0F); |
| 2561 |
rgba[i][bComp] = ((p >> 4) & 0xf) * (1.0F / 15.0F); |
| 2562 |
rgba[i][aComp] = ((p ) & 0xf) * (1.0F / 15.0F); |
| 2563 |
} |
| 2564 |
} |
| 2565 |
else { |
| 2566 |
const GLushort *ussrc = (const GLushort *) src; |
| 2567 |
GLuint i; |
| 2568 |
for (i = 0; i < n; i ++) { |
| 2569 |
GLushort p = ussrc[i]; |
| 2570 |
rgba[i][rComp] = ((p >> 12) ) * (1.0F / 15.0F); |
| 2571 |
rgba[i][gComp] = ((p >> 8) & 0xf) * (1.0F / 15.0F); |
| 2572 |
rgba[i][bComp] = ((p >> 4) & 0xf) * (1.0F / 15.0F); |
| 2573 |
rgba[i][aComp] = ((p ) & 0xf) * (1.0F / 15.0F); |
| 2574 |
} |
| 2575 |
} |
| 2576 |
break; |
| 2577 |
case GL_UNSIGNED_SHORT_4_4_4_4_REV: |
| 2578 |
if (swapBytes) { |
| 2579 |
const GLushort *ussrc = (const GLushort *) src; |
| 2580 |
GLuint i; |
| 2581 |
for (i = 0; i < n; i ++) { |
| 2582 |
GLushort p = ussrc[i]; |
| 2583 |
SWAP2BYTE(p); |
| 2584 |
rgba[i][rComp] = ((p ) & 0xf) * (1.0F / 15.0F); |
| 2585 |
rgba[i][gComp] = ((p >> 4) & 0xf) * (1.0F / 15.0F); |
| 2586 |
rgba[i][bComp] = ((p >> 8) & 0xf) * (1.0F / 15.0F); |
| 2587 |
rgba[i][aComp] = ((p >> 12) ) * (1.0F / 15.0F); |
| 2588 |
} |
| 2589 |
} |
| 2590 |
else { |
| 2591 |
const GLushort *ussrc = (const GLushort *) src; |
| 2592 |
GLuint i; |
| 2593 |
for (i = 0; i < n; i ++) { |
| 2594 |
GLushort p = ussrc[i]; |
| 2595 |
rgba[i][rComp] = ((p ) & 0xf) * (1.0F / 15.0F); |
| 2596 |
rgba[i][gComp] = ((p >> 4) & 0xf) * (1.0F / 15.0F); |
| 2597 |
rgba[i][bComp] = ((p >> 8) & 0xf) * (1.0F / 15.0F); |
| 2598 |
rgba[i][aComp] = ((p >> 12) ) * (1.0F / 15.0F); |
| 2599 |
} |
| 2600 |
} |
| 2601 |
break; |
| 2602 |
case GL_UNSIGNED_SHORT_5_5_5_1: |
| 2603 |
if (swapBytes) { |
| 2604 |
const GLushort *ussrc = (const GLushort *) src; |
| 2605 |
GLuint i; |
| 2606 |
for (i = 0; i < n; i ++) { |
| 2607 |
GLushort p = ussrc[i]; |
| 2608 |
SWAP2BYTE(p); |
| 2609 |
rgba[i][rComp] = ((p >> 11) ) * (1.0F / 31.0F); |
| 2610 |
rgba[i][gComp] = ((p >> 6) & 0x1f) * (1.0F / 31.0F); |
| 2611 |
rgba[i][bComp] = ((p >> 1) & 0x1f) * (1.0F / 31.0F); |
| 2612 |
rgba[i][aComp] = ((p ) & 0x1) * (1.0F / 1.0F); |
| 2613 |
} |
| 2614 |
} |
| 2615 |
else { |
| 2616 |
const GLushort *ussrc = (const GLushort *) src; |
| 2617 |
GLuint i; |
| 2618 |
for (i = 0; i < n; i ++) { |
| 2619 |
GLushort p = ussrc[i]; |
| 2620 |
rgba[i][rComp] = ((p >> 11) ) * (1.0F / 31.0F); |
| 2621 |
rgba[i][gComp] = ((p >> 6) & 0x1f) * (1.0F / 31.0F); |
| 2622 |
rgba[i][bComp] = ((p >> 1) & 0x1f) * (1.0F / 31.0F); |
| 2623 |
rgba[i][aComp] = ((p ) & 0x1) * (1.0F / 1.0F); |
| 2624 |
} |
| 2625 |
} |
| 2626 |
break; |
| 2627 |
case GL_UNSIGNED_SHORT_1_5_5_5_REV: |
| 2628 |
if (swapBytes) { |
| 2629 |
const GLushort *ussrc = (const GLushort *) src; |
| 2630 |
GLuint i; |
| 2631 |
for (i = 0; i < n; i ++) { |
| 2632 |
GLushort p = ussrc[i]; |
| 2633 |
SWAP2BYTE(p); |
| 2634 |
rgba[i][rComp] = ((p ) & 0x1f) * (1.0F / 31.0F); |
| 2635 |
rgba[i][gComp] = ((p >> 5) & 0x1f) * (1.0F / 31.0F); |
| 2636 |
rgba[i][bComp] = ((p >> 10) & 0x1f) * (1.0F / 31.0F); |
| 2637 |
rgba[i][aComp] = ((p >> 15) ) * (1.0F / 1.0F); |
| 2638 |
} |
| 2639 |
} |
| 2640 |
else { |
| 2641 |
const GLushort *ussrc = (const GLushort *) src; |
| 2642 |
GLuint i; |
| 2643 |
for (i = 0; i < n; i ++) { |
| 2644 |
GLushort p = ussrc[i]; |
| 2645 |
rgba[i][rComp] = ((p ) & 0x1f) * (1.0F / 31.0F); |
| 2646 |
rgba[i][gComp] = ((p >> 5) & 0x1f) * (1.0F / 31.0F); |
| 2647 |
rgba[i][bComp] = ((p >> 10) & 0x1f) * (1.0F / 31.0F); |
| 2648 |
rgba[i][aComp] = ((p >> 15) ) * (1.0F / 1.0F); |
| 2649 |
} |
| 2650 |
} |
| 2651 |
break; |
| 2652 |
case GL_UNSIGNED_INT_8_8_8_8: |
| 2653 |
if (swapBytes) { |
| 2654 |
const GLuint *uisrc = (const GLuint *) src; |
| 2655 |
GLuint i; |
| 2656 |
for (i = 0; i < n; i ++) { |
| 2657 |
GLuint p = uisrc[i]; |
| 2658 |
rgba[i][rComp] = UBYTE_TO_FLOAT((p ) & 0xff); |
| 2659 |
rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); |
| 2660 |
rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); |
| 2661 |
rgba[i][aComp] = UBYTE_TO_FLOAT((p >> 24) ); |
| 2662 |
} |
| 2663 |
} |
| 2664 |
else { |
| 2665 |
const GLuint *uisrc = (const GLuint *) src; |
| 2666 |
GLuint i; |
| 2667 |
for (i = 0; i < n; i ++) { |
| 2668 |
GLuint p = uisrc[i]; |
| 2669 |
rgba[i][rComp] = UBYTE_TO_FLOAT((p >> 24) ); |
| 2670 |
rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); |
| 2671 |
rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); |
| 2672 |
rgba[i][aComp] = UBYTE_TO_FLOAT((p ) & 0xff); |
| 2673 |
} |
| 2674 |
} |
| 2675 |
break; |
| 2676 |
case GL_UNSIGNED_INT_8_8_8_8_REV: |
| 2677 |
if (swapBytes) { |
| 2678 |
const GLuint *uisrc = (const GLuint *) src; |
| 2679 |
GLuint i; |
| 2680 |
for (i = 0; i < n; i ++) { |
| 2681 |
GLuint p = uisrc[i]; |
| 2682 |
rgba[i][rComp] = UBYTE_TO_FLOAT((p >> 24) ); |
| 2683 |
rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); |
| 2684 |
rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); |
| 2685 |
rgba[i][aComp] = UBYTE_TO_FLOAT((p ) & 0xff); |
| 2686 |
} |
| 2687 |
} |
| 2688 |
else { |
| 2689 |
const GLuint *uisrc = (const GLuint *) src; |
| 2690 |
GLuint i; |
| 2691 |
for (i = 0; i < n; i ++) { |
| 2692 |
GLuint p = uisrc[i]; |
| 2693 |
rgba[i][rComp] = UBYTE_TO_FLOAT((p ) & 0xff); |
| 2694 |
rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); |
| 2695 |
rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); |
| 2696 |
rgba[i][aComp] = UBYTE_TO_FLOAT((p >> 24) ); |
| 2697 |
} |
| 2698 |
} |
| 2699 |
break; |
| 2700 |
case GL_UNSIGNED_INT_10_10_10_2: |
| 2701 |
if (swapBytes) { |
| 2702 |
const GLuint *uisrc = (const GLuint *) src; |
| 2703 |
GLuint i; |
| 2704 |
for (i = 0; i < n; i ++) { |
| 2705 |
GLuint p = uisrc[i]; |
| 2706 |
SWAP4BYTE(p); |
| 2707 |
rgba[i][rComp] = ((p >> 22) ) * (1.0F / 1023.0F); |
| 2708 |
rgba[i][gComp] = ((p >> 12) & 0x3ff) * (1.0F / 1023.0F); |
| 2709 |
rgba[i][bComp] = ((p >> 2) & 0x3ff) * (1.0F / 1023.0F); |
| 2710 |
rgba[i][aComp] = ((p ) & 0x3 ) * (1.0F / 3.0F); |
| 2711 |
} |
| 2712 |
} |
| 2713 |
else { |
| 2714 |
const GLuint *uisrc = (const GLuint *) src; |
| 2715 |
GLuint i; |
| 2716 |
for (i = 0; i < n; i ++) { |
| 2717 |
GLuint p = uisrc[i]; |
| 2718 |
rgba[i][rComp] = ((p >> 22) ) * (1.0F / 1023.0F); |
| 2719 |
rgba[i][gComp] = ((p >> 12) & 0x3ff) * (1.0F / 1023.0F); |
| 2720 |
rgba[i][bComp] = ((p >> 2) & 0x3ff) * (1.0F / 1023.0F); |
| 2721 |
rgba[i][aComp] = ((p ) & 0x3 ) * (1.0F / 3.0F); |
| 2722 |
} |
| 2723 |
} |
| 2724 |
break; |
| 2725 |
case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 2726 |
if (swapBytes) { |
| 2727 |
const GLuint *uisrc = (const GLuint *) src; |
| 2728 |
GLuint i; |
| 2729 |
for (i = 0; i < n; i ++) { |
| 2730 |
GLuint p = uisrc[i]; |
| 2731 |
SWAP4BYTE(p); |
| 2732 |
rgba[i][rComp] = ((p ) & 0x3ff) * (1.0F / 1023.0F); |
| 2733 |
rgba[i][gComp] = ((p >> 10) & 0x3ff) * (1.0F / 1023.0F); |
| 2734 |
rgba[i][bComp] = ((p >> 20) & 0x3ff) * (1.0F / 1023.0F); |
| 2735 |
rgba[i][aComp] = ((p >> 30) ) * (1.0F / 3.0F); |
| 2736 |
} |
| 2737 |
} |
| 2738 |
else { |
| 2739 |
const GLuint *uisrc = (const GLuint *) src; |
| 2740 |
GLuint i; |
| 2741 |
for (i = 0; i < n; i ++) { |
| 2742 |
GLuint p = uisrc[i]; |
| 2743 |
rgba[i][rComp] = ((p ) & 0x3ff) * (1.0F / 1023.0F); |
| 2744 |
rgba[i][gComp] = ((p >> 10) & 0x3ff) * (1.0F / 1023.0F); |
| 2745 |
rgba[i][bComp] = ((p >> 20) & 0x3ff) * (1.0F / 1023.0F); |
| 2746 |
rgba[i][aComp] = ((p >> 30) ) * (1.0F / 3.0F); |
| 2747 |
} |
| 2748 |
} |
| 2749 |
break; |
| 2750 |
default: |
| 2751 |
_mesa_problem(NULL, "bad srcType in extract float data"); |
| 2752 |
break; |
| 2753 |
} |
| 2754 |
} |
| 2755 |
|
| 2756 |
|
| 2757 |
/* |
| 2758 |
* Unpack a row of color image data from a client buffer according to |
| 2759 |
* the pixel unpacking parameters. |
| 2760 |
* Return GLchan values in the specified dest image format. |
| 2761 |
* This is used by glDrawPixels and glTexImage?D(). |
| 2762 |
* \param ctx - the context |
| 2763 |
* n - number of pixels in the span |
| 2764 |
* dstFormat - format of destination color array |
| 2765 |
* dest - the destination color array |
| 2766 |
* srcFormat - source image format |
| 2767 |
* srcType - source image data type |
| 2768 |
* source - source image pointer |
| 2769 |
* srcPacking - pixel unpacking parameters |
| 2770 |
* transferOps - bitmask of IMAGE_*_BIT values of operations to apply |
| 2771 |
* |
| 2772 |
* XXX perhaps expand this to process whole images someday. |
| 2773 |
*/ |
| 2774 |
void |
| 2775 |
_mesa_unpack_color_span_chan( GLcontext *ctx, |
| 2776 |
GLuint n, GLenum dstFormat, GLchan dest[], |
| 2777 |
GLenum srcFormat, GLenum srcType, |
| 2778 |
const GLvoid *source, |
| 2779 |
const struct gl_pixelstore_attrib *srcPacking, |
| 2780 |
GLuint transferOps ) |
| 2781 |
{ |
| 2782 |
ASSERT(dstFormat == GL_ALPHA || |
| 2783 |
dstFormat == GL_LUMINANCE || |
| 2784 |
dstFormat == GL_LUMINANCE_ALPHA || |
| 2785 |
dstFormat == GL_INTENSITY || |
| 2786 |
dstFormat == GL_RGB || |
| 2787 |
dstFormat == GL_RGBA || |
| 2788 |
dstFormat == GL_COLOR_INDEX); |
| 2789 |
|
| 2790 |
ASSERT(srcFormat == GL_RED || |
| 2791 |
srcFormat == GL_GREEN || |
| 2792 |
srcFormat == GL_BLUE || |
| 2793 |
srcFormat == GL_ALPHA || |
| 2794 |
srcFormat == GL_LUMINANCE || |
| 2795 |
srcFormat == GL_LUMINANCE_ALPHA || |
| 2796 |
srcFormat == GL_INTENSITY || |
| 2797 |
srcFormat == GL_RGB || |
| 2798 |
srcFormat == GL_BGR || |
| 2799 |
srcFormat == GL_RGBA || |
| 2800 |
srcFormat == GL_BGRA || |
| 2801 |
srcFormat == GL_ABGR_EXT || |
| 2802 |
srcFormat == GL_COLOR_INDEX); |
| 2803 |
|
| 2804 |
ASSERT(srcType == GL_BITMAP || |
| 2805 |
srcType == GL_UNSIGNED_BYTE || |
| 2806 |
srcType == GL_BYTE || |
| 2807 |
srcType == GL_UNSIGNED_SHORT || |
| 2808 |
srcType == GL_SHORT || |
| 2809 |
srcType == GL_UNSIGNED_INT || |
| 2810 |
srcType == GL_INT || |
| 2811 |
srcType == GL_HALF_FLOAT_ARB || |
| 2812 |
srcType == GL_FLOAT || |
| 2813 |
srcType == GL_UNSIGNED_BYTE_3_3_2 || |
| 2814 |
srcType == GL_UNSIGNED_BYTE_2_3_3_REV || |
| 2815 |
srcType == GL_UNSIGNED_SHORT_5_6_5 || |
| 2816 |
srcType == GL_UNSIGNED_SHORT_5_6_5_REV || |
| 2817 |
srcType == GL_UNSIGNED_SHORT_4_4_4_4 || |
| 2818 |
srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV || |
| 2819 |
srcType == GL_UNSIGNED_SHORT_5_5_5_1 || |
| 2820 |
srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV || |
| 2821 |
srcType == GL_UNSIGNED_INT_8_8_8_8 || |
| 2822 |
srcType == GL_UNSIGNED_INT_8_8_8_8_REV || |
| 2823 |
srcType == GL_UNSIGNED_INT_10_10_10_2 || |
| 2824 |
srcType == GL_UNSIGNED_INT_2_10_10_10_REV); |
| 2825 |
|
| 2826 |
/* Try simple cases first */ |
| 2827 |
if (transferOps == 0) { |
| 2828 |
if (srcType == CHAN_TYPE) { |
| 2829 |
if (dstFormat == GL_RGBA) { |
| 2830 |
if (srcFormat == GL_RGBA) { |
| 2831 |
MEMCPY( dest, source, n * 4 * sizeof(GLchan) ); |
| 2832 |
return; |
| 2833 |
} |
| 2834 |
else if (srcFormat == GL_RGB) { |
| 2835 |
GLuint i; |
| 2836 |
const GLchan *src = (const GLchan *) source; |
| 2837 |
GLchan *dst = dest; |
| 2838 |
for (i = 0; i < n; i++) { |
| 2839 |
dst[0] = src[0]; |
| 2840 |
dst[1] = src[1]; |
| 2841 |
dst[2] = src[2]; |
| 2842 |
dst[3] = CHAN_MAX; |
| 2843 |
src += 3; |
| 2844 |
dst += 4; |
| 2845 |
} |
| 2846 |
return; |
| 2847 |
} |
| 2848 |
} |
| 2849 |
else if (dstFormat == GL_RGB) { |
| 2850 |
if (srcFormat == GL_RGB) { |
| 2851 |
MEMCPY( dest, source, n * 3 * sizeof(GLchan) ); |
| 2852 |
return; |
| 2853 |
} |
| 2854 |
else if (srcFormat == GL_RGBA) { |
| 2855 |
GLuint i; |
| 2856 |
const GLchan *src = (const GLchan *) source; |
| 2857 |
GLchan *dst = dest; |
| 2858 |
for (i = 0; i < n; i++) { |
| 2859 |
dst[0] = src[0]; |
| 2860 |
dst[1] = src[1]; |
| 2861 |
dst[2] = src[2]; |
| 2862 |
src += 4; |
| 2863 |
dst += 3; |
| 2864 |
} |
| 2865 |
return; |
| 2866 |
} |
| 2867 |
} |
| 2868 |
else if (dstFormat == srcFormat) { |
| 2869 |
GLint comps = _mesa_components_in_format(srcFormat); |
| 2870 |
assert(comps > 0); |
| 2871 |
MEMCPY( dest, source, n * comps * sizeof(GLchan) ); |
| 2872 |
return; |
| 2873 |
} |
| 2874 |
} |
| 2875 |
/* |
| 2876 |
* Common situation, loading 8bit RGBA/RGB source images |
| 2877 |
* into 16/32 bit destination. (OSMesa16/32) |
| 2878 |
*/ |
| 2879 |
else if (srcType == GL_UNSIGNED_BYTE) { |
| 2880 |
if (dstFormat == GL_RGBA) { |
| 2881 |
if (srcFormat == GL_RGB) { |
| 2882 |
GLuint i; |
| 2883 |
const GLubyte *src = (const GLubyte *) source; |
| 2884 |
GLchan *dst = dest; |
| 2885 |
for (i = 0; i < n; i++) { |
| 2886 |
dst[0] = UBYTE_TO_CHAN(src[0]); |
| 2887 |
dst[1] = UBYTE_TO_CHAN(src[1]); |
| 2888 |
dst[2] = UBYTE_TO_CHAN(src[2]); |
| 2889 |
dst[3] = CHAN_MAX; |
| 2890 |
src += 3; |
| 2891 |
dst += 4; |
| 2892 |
} |
| 2893 |
return; |
| 2894 |
} |
| 2895 |
else if (srcFormat == GL_RGBA) { |
| 2896 |
GLuint i; |
| 2897 |
const GLubyte *src = (const GLubyte *) source; |
| 2898 |
GLchan *dst = dest; |
| 2899 |
for (i = 0; i < n; i++) { |
| 2900 |
dst[0] = UBYTE_TO_CHAN(src[0]); |
| 2901 |
dst[1] = UBYTE_TO_CHAN(src[1]); |
| 2902 |
dst[2] = UBYTE_TO_CHAN(src[2]); |
| 2903 |
dst[3] = UBYTE_TO_CHAN(src[3]); |
| 2904 |
src += 4; |
| 2905 |
dst += 4; |
| 2906 |
} |
| 2907 |
return; |
| 2908 |
} |
| 2909 |
} |
| 2910 |
else if (dstFormat == GL_RGB) { |
| 2911 |
if (srcFormat == GL_RGB) { |
| 2912 |
GLuint i; |
| 2913 |
const GLubyte *src = (const GLubyte *) source; |
| 2914 |
GLchan *dst = dest; |
| 2915 |
for (i = 0; i < n; i++) { |
| 2916 |
dst[0] = UBYTE_TO_CHAN(src[0]); |
| 2917 |
dst[1] = UBYTE_TO_CHAN(src[1]); |
| 2918 |
dst[2] = UBYTE_TO_CHAN(src[2]); |
| 2919 |
src += 3; |
| 2920 |
dst += 3; |
| 2921 |
} |
| 2922 |
return; |
| 2923 |
} |
| 2924 |
else if (srcFormat == GL_RGBA) { |
| 2925 |
GLuint i; |
| 2926 |
const GLubyte *src = (const GLubyte *) source; |
| 2927 |
GLchan *dst = dest; |
| 2928 |
for (i = 0; i < n; i++) { |
| 2929 |
dst[0] = UBYTE_TO_CHAN(src[0]); |
| 2930 |
dst[1] = UBYTE_TO_CHAN(src[1]); |
| 2931 |
dst[2] = UBYTE_TO_CHAN(src[2]); |
| 2932 |
src += 4; |
| 2933 |
dst += 3; |
| 2934 |
} |
| 2935 |
return; |
| 2936 |
} |
| 2937 |
} |
| 2938 |
} |
| 2939 |
} |
| 2940 |
|
| 2941 |
|
| 2942 |
/* general solution begins here */ |
| 2943 |
{ |
| 2944 |
GLint dstComponents; |
| 2945 |
GLint dstRedIndex, dstGreenIndex, dstBlueIndex, dstAlphaIndex; |
| 2946 |
GLint dstLuminanceIndex, dstIntensityIndex; |
| 2947 |
DEFMARRAY(GLfloat, rgba, MAX_WIDTH, 4); /* mac 32k limitation */ |
| 2948 |
CHECKARRAY(rgba, return); /* mac 32k limitation */ |
| 2949 |
|
| 2950 |
dstComponents = _mesa_components_in_format( dstFormat ); |
| 2951 |
/* source & dest image formats should have been error checked by now */ |
| 2952 |
assert(dstComponents > 0); |
| 2953 |
|
| 2954 |
/* |
| 2955 |
* Extract image data and convert to RGBA floats |
| 2956 |
*/ |
| 2957 |
assert(n <= MAX_WIDTH); |
| 2958 |
if (srcFormat == GL_COLOR_INDEX) { |
| 2959 |
GLuint indexes[MAX_WIDTH]; |
| 2960 |
extract_uint_indexes(n, indexes, srcFormat, srcType, source, |
| 2961 |
srcPacking); |
| 2962 |
|
| 2963 |
if (dstFormat == GL_COLOR_INDEX |
| 2964 |
&& (transferOps & IMAGE_MAP_COLOR_BIT)) { |
| 2965 |
_mesa_map_ci(ctx, n, indexes); |
| 2966 |
} |
| 2967 |
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) { |
| 2968 |
_mesa_shift_and_offset_ci(ctx, n, indexes); |
| 2969 |
} |
| 2970 |
|
| 2971 |
if (dstFormat == GL_COLOR_INDEX) { |
| 2972 |
/* convert to GLchan and return */ |
| 2973 |
GLuint i; |
| 2974 |
for (i = 0; i < n; i++) { |
| 2975 |
dest[i] = (GLchan) (indexes[i] & 0xff); |
| 2976 |
} |
| 2977 |
UNDEFARRAY(rgba); /* mac 32k limitation */ |
| 2978 |
return; |
| 2979 |
} |
| 2980 |
else { |
| 2981 |
/* Convert indexes to RGBA */ |
| 2982 |
_mesa_map_ci_to_rgba(ctx, n, indexes, rgba); |
| 2983 |
} |
| 2984 |
|
| 2985 |
/* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting |
| 2986 |
* with color indexes. |
| 2987 |
*/ |
| 2988 |
transferOps &= ~(IMAGE_SCALE_BIAS_BIT | IMAGE_MAP_COLOR_BIT); |
| 2989 |
} |
| 2990 |
else { |
| 2991 |
/* non-color index data */ |
| 2992 |
extract_float_rgba(n, rgba, srcFormat, srcType, source, |
| 2993 |
srcPacking->SwapBytes); |
| 2994 |
} |
| 2995 |
|
| 2996 |
/* Need to clamp if returning GLubytes or GLushorts */ |
| 2997 |
#if CHAN_TYPE != GL_FLOAT |
| 2998 |
transferOps |= IMAGE_CLAMP_BIT; |
| 2999 |
#endif |
| 3000 |
|
| 3001 |
if (transferOps) { |
| 3002 |
_mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba); |
| 3003 |
} |
| 3004 |
|
| 3005 |
/* Now determine which color channels we need to produce. |
| 3006 |
* And determine the dest index (offset) within each color tuple. |
| 3007 |
*/ |
| 3008 |
switch (dstFormat) { |
| 3009 |
case GL_ALPHA: |
| 3010 |
dstAlphaIndex = 0; |
| 3011 |
dstRedIndex = dstGreenIndex = dstBlueIndex = -1; |
| 3012 |
dstLuminanceIndex = dstIntensityIndex = -1; |
| 3013 |
break; |
| 3014 |
case GL_LUMINANCE: |
| 3015 |
dstLuminanceIndex = 0; |
| 3016 |
dstRedIndex = dstGreenIndex = dstBlueIndex = dstAlphaIndex = -1; |
| 3017 |
dstIntensityIndex = -1; |
| 3018 |
break; |
| 3019 |
case GL_LUMINANCE_ALPHA: |
| 3020 |
dstLuminanceIndex = 0; |
| 3021 |
dstAlphaIndex = 1; |
| 3022 |
dstRedIndex = dstGreenIndex = dstBlueIndex = -1; |
| 3023 |
dstIntensityIndex = -1; |
| 3024 |
break; |
| 3025 |
case GL_INTENSITY: |
| 3026 |
dstIntensityIndex = 0; |
| 3027 |
dstRedIndex = dstGreenIndex = dstBlueIndex = dstAlphaIndex = -1; |
| 3028 |
dstLuminanceIndex = -1; |
| 3029 |
break; |
| 3030 |
case GL_RGB: |
| 3031 |
dstRedIndex = 0; |
| 3032 |
dstGreenIndex = 1; |
| 3033 |
dstBlueIndex = 2; |
| 3034 |
dstAlphaIndex = dstLuminanceIndex = dstIntensityIndex = -1; |
| 3035 |
break; |
| 3036 |
case GL_RGBA: |
| 3037 |
dstRedIndex = 0; |
| 3038 |
dstGreenIndex = 1; |
| 3039 |
dstBlueIndex = 2; |
| 3040 |
dstAlphaIndex = 3; |
| 3041 |
dstLuminanceIndex = dstIntensityIndex = -1; |
| 3042 |
break; |
| 3043 |
default: |
| 3044 |
_mesa_problem(ctx, "bad dstFormat in _mesa_unpack_chan_span()"); |
| 3045 |
UNDEFARRAY(rgba); /* mac 32k limitation */ |
| 3046 |
return; |
| 3047 |
} |
| 3048 |
|
| 3049 |
|
| 3050 |
/* Now return the GLchan data in the requested dstFormat */ |
| 3051 |
|
| 3052 |
if (dstRedIndex >= 0) { |
| 3053 |
GLchan *dst = dest; |
| 3054 |
GLuint i; |
| 3055 |
for (i = 0; i < n; i++) { |
| 3056 |
CLAMPED_FLOAT_TO_CHAN(dst[dstRedIndex], rgba[i][RCOMP]); |
| 3057 |
dst += dstComponents; |
| 3058 |
} |
| 3059 |
} |
| 3060 |
|
| 3061 |
if (dstGreenIndex >= 0) { |
| 3062 |
GLchan *dst = dest; |
| 3063 |
GLuint i; |
| 3064 |
for (i = 0; i < n; i++) { |
| 3065 |
CLAMPED_FLOAT_TO_CHAN(dst[dstGreenIndex], rgba[i][GCOMP]); |
| 3066 |
dst += dstComponents; |
| 3067 |
} |
| 3068 |
} |
| 3069 |
|
| 3070 |
if (dstBlueIndex >= 0) { |
| 3071 |
GLchan *dst = dest; |
| 3072 |
GLuint i; |
| 3073 |
for (i = 0; i < n; i++) { |
| 3074 |
CLAMPED_FLOAT_TO_CHAN(dst[dstBlueIndex], rgba[i][BCOMP]); |
| 3075 |
dst += dstComponents; |
| 3076 |
} |
| 3077 |
} |
| 3078 |
|
| 3079 |
if (dstAlphaIndex >= 0) { |
| 3080 |
GLchan *dst = dest; |
| 3081 |
GLuint i; |
| 3082 |
for (i = 0; i < n; i++) { |
| 3083 |
CLAMPED_FLOAT_TO_CHAN(dst[dstAlphaIndex], rgba[i][ACOMP]); |
| 3084 |
dst += dstComponents; |
| 3085 |
} |
| 3086 |
} |
| 3087 |
|
| 3088 |
if (dstIntensityIndex >= 0) { |
| 3089 |
GLchan *dst = dest; |
| 3090 |
GLuint i; |
| 3091 |
assert(dstIntensityIndex == 0); |
| 3092 |
assert(dstComponents == 1); |
| 3093 |
for (i = 0; i < n; i++) { |
| 3094 |
/* Intensity comes from red channel */ |
| 3095 |
CLAMPED_FLOAT_TO_CHAN(dst[i], rgba[i][RCOMP]); |
| 3096 |
} |
| 3097 |
} |
| 3098 |
|
| 3099 |
if (dstLuminanceIndex >= 0) { |
| 3100 |
GLchan *dst = dest; |
| 3101 |
GLuint i; |
| 3102 |
assert(dstLuminanceIndex == 0); |
| 3103 |
for (i = 0; i < n; i++) { |
| 3104 |
/* Luminance comes from red channel */ |
| 3105 |
CLAMPED_FLOAT_TO_CHAN(dst[0], rgba[i][RCOMP]); |
| 3106 |
dst += dstComponents; |
| 3107 |
} |
| 3108 |
} |
| 3109 |
UNDEFARRAY(rgba); /* mac 32k limitation */ |
| 3110 |
} |
| 3111 |
} |
| 3112 |
|
| 3113 |
|
| 3114 |
/** |
| 3115 |
* Same as _mesa_unpack_color_span_chan(), but return GLfloat data |
| 3116 |
* instead of GLchan. |
| 3117 |
*/ |
| 3118 |
void |
| 3119 |
_mesa_unpack_color_span_float( GLcontext *ctx, |
| 3120 |
GLuint n, GLenum dstFormat, GLfloat dest[], |
| 3121 |
GLenum srcFormat, GLenum srcType, |
| 3122 |
const GLvoid *source, |
| 3123 |
const struct gl_pixelstore_attrib *srcPacking, |
| 3124 |
GLuint transferOps ) |
| 3125 |
{ |
| 3126 |
ASSERT(dstFormat == GL_ALPHA || |
| 3127 |
dstFormat == GL_LUMINANCE || |
| 3128 |
dstFormat == GL_LUMINANCE_ALPHA || |
| 3129 |
dstFormat == GL_INTENSITY || |
| 3130 |
dstFormat == GL_RGB || |
| 3131 |
dstFormat == GL_RGBA || |
| 3132 |
dstFormat == GL_COLOR_INDEX); |
| 3133 |
|
| 3134 |
ASSERT(srcFormat == GL_RED || |
| 3135 |
srcFormat == GL_GREEN || |
| 3136 |
srcFormat == GL_BLUE || |
| 3137 |
srcFormat == GL_ALPHA || |
| 3138 |
srcFormat == GL_LUMINANCE || |
| 3139 |
srcFormat == GL_LUMINANCE_ALPHA || |
| 3140 |
srcFormat == GL_INTENSITY || |
| 3141 |
srcFormat == GL_RGB || |
| 3142 |
srcFormat == GL_BGR || |
| 3143 |
srcFormat == GL_RGBA || |
| 3144 |
srcFormat == GL_BGRA || |
| 3145 |
srcFormat == GL_ABGR_EXT || |
| 3146 |
srcFormat == GL_COLOR_INDEX); |
| 3147 |
|
| 3148 |
ASSERT(srcType == GL_BITMAP || |
| 3149 |
srcType == GL_UNSIGNED_BYTE || |
| 3150 |
srcType == GL_BYTE || |
| 3151 |
srcType == GL_UNSIGNED_SHORT || |
| 3152 |
srcType == GL_SHORT || |
| 3153 |
srcType == GL_UNSIGNED_INT || |
| 3154 |
srcType == GL_INT || |
| 3155 |
srcType == GL_HALF_FLOAT_ARB || |
| 3156 |
srcType == GL_FLOAT || |
| 3157 |
srcType == GL_UNSIGNED_BYTE_3_3_2 || |
| 3158 |
srcType == GL_UNSIGNED_BYTE_2_3_3_REV || |
| 3159 |
srcType == GL_UNSIGNED_SHORT_5_6_5 || |
| 3160 |
srcType == GL_UNSIGNED_SHORT_5_6_5_REV || |
| 3161 |
srcType == GL_UNSIGNED_SHORT_4_4_4_4 || |
| 3162 |
srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV || |
| 3163 |
srcType == GL_UNSIGNED_SHORT_5_5_5_1 || |
| 3164 |
srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV || |
| 3165 |
srcType == GL_UNSIGNED_INT_8_8_8_8 || |
| 3166 |
srcType == GL_UNSIGNED_INT_8_8_8_8_REV || |
| 3167 |
srcType == GL_UNSIGNED_INT_10_10_10_2 || |
| 3168 |
srcType == GL_UNSIGNED_INT_2_10_10_10_REV); |
| 3169 |
|
| 3170 |
/* general solution, no special cases, yet */ |
| 3171 |
{ |
| 3172 |
GLint dstComponents; |
| 3173 |
GLint dstRedIndex, dstGreenIndex, dstBlueIndex, dstAlphaIndex; |
| 3174 |
GLint dstLuminanceIndex, dstIntensityIndex; |
| 3175 |
DEFMARRAY(GLfloat, rgba, MAX_WIDTH, 4); /* mac 32k limitation */ |
| 3176 |
CHECKARRAY(rgba, return); /* mac 32k limitation */ |
| 3177 |
|
| 3178 |
dstComponents = _mesa_components_in_format( dstFormat ); |
| 3179 |
/* source & dest image formats should have been error checked by now */ |
| 3180 |
assert(dstComponents > 0); |
| 3181 |
|
| 3182 |
/* |
| 3183 |
* Extract image data and convert to RGBA floats |
| 3184 |
*/ |
| 3185 |
assert(n <= MAX_WIDTH); |
| 3186 |
if (srcFormat == GL_COLOR_INDEX) { |
| 3187 |
GLuint indexes[MAX_WIDTH]; |
| 3188 |
extract_uint_indexes(n, indexes, srcFormat, srcType, source, |
| 3189 |
srcPacking); |
| 3190 |
|
| 3191 |
if (dstFormat == GL_COLOR_INDEX |
| 3192 |
&& (transferOps & IMAGE_MAP_COLOR_BIT)) { |
| 3193 |
_mesa_map_ci(ctx, n, indexes); |
| 3194 |
} |
| 3195 |
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) { |
| 3196 |
_mesa_shift_and_offset_ci(ctx, n, indexes); |
| 3197 |
} |
| 3198 |
|
| 3199 |
if (dstFormat == GL_COLOR_INDEX) { |
| 3200 |
/* convert to GLchan and return */ |
| 3201 |
GLuint i; |
| 3202 |
for (i = 0; i < n; i++) { |
| 3203 |
dest[i] = (GLchan) (indexes[i] & 0xff); |
| 3204 |
} |
| 3205 |
UNDEFARRAY(rgba); /* mac 32k limitation */ |
| 3206 |
return; |
| 3207 |
} |
| 3208 |
else { |
| 3209 |
/* Convert indexes to RGBA */ |
| 3210 |
_mesa_map_ci_to_rgba(ctx, n, indexes, rgba); |
| 3211 |
} |
| 3212 |
|
| 3213 |
/* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting |
| 3214 |
* with color indexes. |
| 3215 |
*/ |
| 3216 |
transferOps &= ~(IMAGE_SCALE_BIAS_BIT | IMAGE_MAP_COLOR_BIT); |
| 3217 |
} |
| 3218 |
else { |
| 3219 |
/* non-color index data */ |
| 3220 |
extract_float_rgba(n, rgba, srcFormat, srcType, source, |
| 3221 |
srcPacking->SwapBytes); |
| 3222 |
} |
| 3223 |
|
| 3224 |
if (transferOps) { |
| 3225 |
_mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba); |
| 3226 |
} |
| 3227 |
|
| 3228 |
/* Now determine which color channels we need to produce. |
| 3229 |
* And determine the dest index (offset) within each color tuple. |
| 3230 |
*/ |
| 3231 |
switch (dstFormat) { |
| 3232 |
case GL_ALPHA: |
| 3233 |
dstAlphaIndex = 0; |
| 3234 |
dstRedIndex = dstGreenIndex = dstBlueIndex = -1; |
| 3235 |
dstLuminanceIndex = dstIntensityIndex = -1; |
| 3236 |
break; |
| 3237 |
case GL_LUMINANCE: |
| 3238 |
dstLuminanceIndex = 0; |
| 3239 |
dstRedIndex = dstGreenIndex = dstBlueIndex = dstAlphaIndex = -1; |
| 3240 |
dstIntensityIndex = -1; |
| 3241 |
break; |
| 3242 |
case GL_LUMINANCE_ALPHA: |
| 3243 |
dstLuminanceIndex = 0; |
| 3244 |
dstAlphaIndex = 1; |
| 3245 |
dstRedIndex = dstGreenIndex = dstBlueIndex = -1; |
| 3246 |
dstIntensityIndex = -1; |
| 3247 |
break; |
| 3248 |
case GL_INTENSITY: |
| 3249 |
dstIntensityIndex = 0; |
| 3250 |
dstRedIndex = dstGreenIndex = dstBlueIndex = dstAlphaIndex = -1; |
| 3251 |
dstLuminanceIndex = -1; |
| 3252 |
break; |
| 3253 |
case GL_RGB: |
| 3254 |
dstRedIndex = 0; |
| 3255 |
dstGreenIndex = 1; |
| 3256 |
dstBlueIndex = 2; |
| 3257 |
dstAlphaIndex = dstLuminanceIndex = dstIntensityIndex = -1; |
| 3258 |
break; |
| 3259 |
case GL_RGBA: |
| 3260 |
dstRedIndex = 0; |
| 3261 |
dstGreenIndex = 1; |
| 3262 |
dstBlueIndex = 2; |
| 3263 |
dstAlphaIndex = 3; |
| 3264 |
dstLuminanceIndex = dstIntensityIndex = -1; |
| 3265 |
break; |
| 3266 |
default: |
| 3267 |
_mesa_problem(ctx, "bad dstFormat in _mesa_unpack_color_span_float()"); |
| 3268 |
UNDEFARRAY(rgba); /* mac 32k limitation */ |
| 3269 |
return; |
| 3270 |
} |
| 3271 |
|
| 3272 |
/* Now pack results in the requested dstFormat */ |
| 3273 |
if (dstRedIndex >= 0) { |
| 3274 |
GLfloat *dst = dest; |
| 3275 |
GLuint i; |
| 3276 |
for (i = 0; i < n; i++) { |
| 3277 |
dst[dstRedIndex] = rgba[i][RCOMP]; |
| 3278 |
dst += dstComponents; |
| 3279 |
} |
| 3280 |
} |
| 3281 |
|
| 3282 |
if (dstGreenIndex >= 0) { |
| 3283 |
GLfloat *dst = dest; |
| 3284 |
GLuint i; |
| 3285 |
for (i = 0; i < n; i++) { |
| 3286 |
dst[dstGreenIndex] = rgba[i][GCOMP]; |
| 3287 |
dst += dstComponents; |
| 3288 |
} |
| 3289 |
} |
| 3290 |
|
| 3291 |
if (dstBlueIndex >= 0) { |
| 3292 |
GLfloat *dst = dest; |
| 3293 |
GLuint i; |
| 3294 |
for (i = 0; i < n; i++) { |
| 3295 |
dst[dstBlueIndex] = rgba[i][BCOMP]; |
| 3296 |
dst += dstComponents; |
| 3297 |
} |
| 3298 |
} |
| 3299 |
|
| 3300 |
if (dstAlphaIndex >= 0) { |
| 3301 |
GLfloat *dst = dest; |
| 3302 |
GLuint i; |
| 3303 |
for (i = 0; i < n; i++) { |
| 3304 |
dst[dstAlphaIndex] = rgba[i][ACOMP]; |
| 3305 |
dst += dstComponents; |
| 3306 |
} |
| 3307 |
} |
| 3308 |
|
| 3309 |
if (dstIntensityIndex >= 0) { |
| 3310 |
GLfloat *dst = dest; |
| 3311 |
GLuint i; |
| 3312 |
assert(dstIntensityIndex == 0); |
| 3313 |
assert(dstComponents == 1); |
| 3314 |
for (i = 0; i < n; i++) { |
| 3315 |
/* Intensity comes from red channel */ |
| 3316 |
dst[i] = rgba[i][RCOMP]; |
| 3317 |
} |
| 3318 |
} |
| 3319 |
|
| 3320 |
if (dstLuminanceIndex >= 0) { |
| 3321 |
GLfloat *dst = dest; |
| 3322 |
GLuint i; |
| 3323 |
assert(dstLuminanceIndex == 0); |
| 3324 |
for (i = 0; i < n; i++) { |
| 3325 |
/* Luminance comes from red channel */ |
| 3326 |
dst[0] = rgba[i][RCOMP]; |
| 3327 |
dst += dstComponents; |
| 3328 |
} |
| 3329 |
} |
| 3330 |
UNDEFARRAY(rgba); /* mac 32k limitation */ |
| 3331 |
} |
| 3332 |
} |
| 3333 |
|
| 3334 |
|
| 3335 |
/* |
| 3336 |
* Unpack a row of color index data from a client buffer according to |
| 3337 |
* the pixel unpacking parameters. |
| 3338 |
* This is (or will be) used by glDrawPixels, glTexImage[123]D, etc. |
| 3339 |
* |
| 3340 |
* Args: ctx - the context |
| 3341 |
* n - number of pixels |
| 3342 |
* dstType - destination data type |
| 3343 |
* dest - destination array |
| 3344 |
* srcType - source pixel type |
| 3345 |
* source - source data pointer |
| 3346 |
* srcPacking - pixel unpacking parameters |
| 3347 |
* transferOps - the pixel transfer operations to apply |
| 3348 |
*/ |
| 3349 |
void |
| 3350 |
_mesa_unpack_index_span( const GLcontext *ctx, GLuint n, |
| 3351 |
GLenum dstType, GLvoid *dest, |
| 3352 |
GLenum srcType, const GLvoid *source, |
| 3353 |
const struct gl_pixelstore_attrib *srcPacking, |
| 3354 |
GLuint transferOps ) |
| 3355 |
{ |
| 3356 |
ASSERT(srcType == GL_BITMAP || |
| 3357 |
srcType == GL_UNSIGNED_BYTE || |
| 3358 |
srcType == GL_BYTE || |
| 3359 |
srcType == GL_UNSIGNED_SHORT || |
| 3360 |
srcType == GL_SHORT || |
| 3361 |
srcType == GL_UNSIGNED_INT || |
| 3362 |
srcType == GL_INT || |
| 3363 |
srcType == GL_HALF_FLOAT_ARB || |
| 3364 |
srcType == GL_FLOAT); |
| 3365 |
|
| 3366 |
ASSERT(dstType == GL_UNSIGNED_BYTE || |
| 3367 |
dstType == GL_UNSIGNED_SHORT || |
| 3368 |
dstType == GL_UNSIGNED_INT); |
| 3369 |
|
| 3370 |
|
| 3371 |
transferOps &= (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT); |
| 3372 |
|
| 3373 |
/* |
| 3374 |
* Try simple cases first |
| 3375 |
*/ |
| 3376 |
if (transferOps == 0 && srcType == GL_UNSIGNED_BYTE |
| 3377 |
&& dstType == GL_UNSIGNED_BYTE) { |
| 3378 |
MEMCPY(dest, source, n * sizeof(GLubyte)); |
| 3379 |
} |
| 3380 |
else if (transferOps == 0 && srcType == GL_UNSIGNED_INT |
| 3381 |
&& dstType == GL_UNSIGNED_INT && !srcPacking->SwapBytes) { |
| 3382 |
MEMCPY(dest, source, n * sizeof(GLuint)); |
| 3383 |
} |
| 3384 |
else { |
| 3385 |
/* |
| 3386 |
* general solution |
| 3387 |
*/ |
| 3388 |
GLuint indexes[MAX_WIDTH]; |
| 3389 |
assert(n <= MAX_WIDTH); |
| 3390 |
|
| 3391 |
extract_uint_indexes(n, indexes, GL_COLOR_INDEX, srcType, source, |
| 3392 |
srcPacking); |
| 3393 |
|
| 3394 |
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) { |
| 3395 |
/* shift and offset indexes */ |
| 3396 |
_mesa_shift_and_offset_ci(ctx, n, indexes); |
| 3397 |
} |
| 3398 |
if (transferOps & IMAGE_MAP_COLOR_BIT) { |
| 3399 |
/* Apply lookup table */ |
| 3400 |
_mesa_map_ci(ctx, n, indexes); |
| 3401 |
} |
| 3402 |
|
| 3403 |
/* convert to dest type */ |
| 3404 |
switch (dstType) { |
| 3405 |
case GL_UNSIGNED_BYTE: |
| 3406 |
{ |
| 3407 |
GLubyte *dst = (GLubyte *) dest; |
| 3408 |
GLuint i; |
| 3409 |
for (i = 0; i < n; i++) { |
| 3410 |
dst[i] = (GLubyte) (indexes[i] & 0xff); |
| 3411 |
} |
| 3412 |
} |
| 3413 |
break; |
| 3414 |
case GL_UNSIGNED_SHORT: |
| 3415 |
{ |
| 3416 |
GLuint *dst = (GLuint *) dest; |
| 3417 |
GLuint i; |
| 3418 |
for (i = 0; i < n; i++) { |
| 3419 |
dst[i] = (GLushort) (indexes[i] & 0xffff); |
| 3420 |
} |
| 3421 |
} |
| 3422 |
break; |
| 3423 |
case GL_UNSIGNED_INT: |
| 3424 |
MEMCPY(dest, indexes, n * sizeof(GLuint)); |
| 3425 |
break; |
| 3426 |
default: |
| 3427 |
_mesa_problem(ctx, "bad dstType in _mesa_unpack_index_span"); |
| 3428 |
} |
| 3429 |
} |
| 3430 |
} |
| 3431 |
|
| 3432 |
|
| 3433 |
void |
| 3434 |
_mesa_pack_index_span( const GLcontext *ctx, GLuint n, |
| 3435 |
GLenum dstType, GLvoid *dest, const GLuint *source, |
| 3436 |
const struct gl_pixelstore_attrib *dstPacking, |
| 3437 |
GLuint transferOps ) |
| 3438 |
{ |
| 3439 |
GLuint indexes[MAX_WIDTH]; |
| 3440 |
|
| 3441 |
ASSERT(n <= MAX_WIDTH); |
| 3442 |
|
| 3443 |
transferOps &= (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT); |
| 3444 |
|
| 3445 |
if (transferOps & (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT)) { |
| 3446 |
/* make a copy of input */ |
| 3447 |
MEMCPY(indexes, source, n * sizeof(GLuint)); |
| 3448 |
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) { |
| 3449 |
_mesa_shift_and_offset_ci( ctx, n, indexes); |
| 3450 |
} |
| 3451 |
if (transferOps & IMAGE_MAP_COLOR_BIT) { |
| 3452 |
_mesa_map_ci(ctx, n, indexes); |
| 3453 |
} |
| 3454 |
source = indexes; |
| 3455 |
} |
| 3456 |
|
| 3457 |
switch (dstType) { |
| 3458 |
case GL_UNSIGNED_BYTE: |
| 3459 |
{ |
| 3460 |
GLubyte *dst = (GLubyte *) dest; |
| 3461 |
GLuint i; |
| 3462 |
for (i = 0; i < n; i++) { |
| 3463 |
*dst++ = (GLubyte) source[i]; |
| 3464 |
} |
| 3465 |
} |
| 3466 |
break; |
| 3467 |
case GL_BYTE: |
| 3468 |
{ |
| 3469 |
GLbyte *dst = (GLbyte *) dest; |
| 3470 |
GLuint i; |
| 3471 |
for (i = 0; i < n; i++) { |
| 3472 |
dst[i] = (GLbyte) source[i]; |
| 3473 |
} |
| 3474 |
} |
| 3475 |
break; |
| 3476 |
case GL_UNSIGNED_SHORT: |
| 3477 |
{ |
| 3478 |
GLushort *dst = (GLushort *) dest; |
| 3479 |
GLuint i; |
| 3480 |
for (i = 0; i < n; i++) { |
| 3481 |
dst[i] = (GLushort) source[i]; |
| 3482 |
} |
| 3483 |
if (dstPacking->SwapBytes) { |
| 3484 |
_mesa_swap2( (GLushort *) dst, n ); |
| 3485 |
} |
| 3486 |
} |
| 3487 |
break; |
| 3488 |
case GL_SHORT: |
| 3489 |
{ |
| 3490 |
GLshort *dst = (GLshort *) dest; |
| 3491 |
GLuint i; |
| 3492 |
for (i = 0; i < n; i++) { |
| 3493 |
dst[i] = (GLshort) source[i]; |
| 3494 |
} |
| 3495 |
if (dstPacking->SwapBytes) { |
| 3496 |
_mesa_swap2( (GLushort *) dst, n ); |
| 3497 |
} |
| 3498 |
} |
| 3499 |
break; |
| 3500 |
case GL_UNSIGNED_INT: |
| 3501 |
{ |
| 3502 |
GLuint *dst = (GLuint *) dest; |
| 3503 |
GLuint i; |
| 3504 |
for (i = 0; i < n; i++) { |
| 3505 |
dst[i] = (GLuint) source[i]; |
| 3506 |
} |
| 3507 |
if (dstPacking->SwapBytes) { |
| 3508 |
_mesa_swap4( (GLuint *) dst, n ); |
| 3509 |
} |
| 3510 |
} |
| 3511 |
break; |
| 3512 |
case GL_INT: |
| 3513 |
{ |
| 3514 |
GLint *dst = (GLint *) dest; |
| 3515 |
GLuint i; |
| 3516 |
for (i = 0; i < n; i++) { |
| 3517 |
dst[i] = (GLint) source[i]; |
| 3518 |
} |
| 3519 |
if (dstPacking->SwapBytes) { |
| 3520 |
_mesa_swap4( (GLuint *) dst, n ); |
| 3521 |
} |
| 3522 |
} |
| 3523 |
break; |
| 3524 |
case GL_FLOAT: |
| 3525 |
{ |
| 3526 |
GLfloat *dst = (GLfloat *) dest; |
| 3527 |
GLuint i; |
| 3528 |
for (i = 0; i < n; i++) { |
| 3529 |
dst[i] = (GLfloat) source[i]; |
| 3530 |
} |
| 3531 |
if (dstPacking->SwapBytes) { |
| 3532 |
_mesa_swap4( (GLuint *) dst, n ); |
| 3533 |
} |
| 3534 |
} |
| 3535 |
break; |
| 3536 |
case GL_HALF_FLOAT_ARB: |
| 3537 |
{ |
| 3538 |
GLhalfARB *dst = (GLhalfARB *) dest; |
| 3539 |
GLuint i; |
| 3540 |
for (i = 0; i < n; i++) { |
| 3541 |
dst[i] = _mesa_float_to_half((GLfloat) source[i]); |
| 3542 |
} |
| 3543 |
if (dstPacking->SwapBytes) { |
| 3544 |
_mesa_swap2( (GLushort *) dst, n ); |
| 3545 |
} |
| 3546 |
} |
| 3547 |
break; |
| 3548 |
default: |
| 3549 |
_mesa_problem(ctx, "bad type in _mesa_pack_index_span"); |
| 3550 |
} |
| 3551 |
} |
| 3552 |
|
| 3553 |
|
| 3554 |
/* |
| 3555 |
* Unpack a row of stencil data from a client buffer according to |
| 3556 |
* the pixel unpacking parameters. |
| 3557 |
* This is (or will be) used by glDrawPixels |
| 3558 |
* |
| 3559 |
* Args: ctx - the context |
| 3560 |
* n - number of pixels |
| 3561 |
* dstType - destination data type |
| 3562 |
* dest - destination array |
| 3563 |
* srcType - source pixel type |
| 3564 |
* source - source data pointer |
| 3565 |
* srcPacking - pixel unpacking parameters |
| 3566 |
* transferOps - apply offset/bias/lookup ops? |
| 3567 |
*/ |
| 3568 |
void |
| 3569 |
_mesa_unpack_stencil_span( const GLcontext *ctx, GLuint n, |
| 3570 |
GLenum dstType, GLvoid *dest, |
| 3571 |
GLenum srcType, const GLvoid *source, |
| 3572 |
const struct gl_pixelstore_attrib *srcPacking, |
| 3573 |
GLuint transferOps ) |
| 3574 |
{ |
| 3575 |
ASSERT(srcType == GL_BITMAP || |
| 3576 |
srcType == GL_UNSIGNED_BYTE || |
| 3577 |
srcType == GL_BYTE || |
| 3578 |
srcType == GL_UNSIGNED_SHORT || |
| 3579 |
srcType == GL_SHORT || |
| 3580 |
srcType == GL_UNSIGNED_INT || |
| 3581 |
srcType == GL_INT || |
| 3582 |
srcType == GL_HALF_FLOAT_ARB || |
| 3583 |
srcType == GL_FLOAT); |
| 3584 |
|
| 3585 |
ASSERT(dstType == GL_UNSIGNED_BYTE || |
| 3586 |
dstType == GL_UNSIGNED_SHORT || |
| 3587 |
dstType == GL_UNSIGNED_INT); |
| 3588 |
|
| 3589 |
/* only shift and offset apply to stencil */ |
| 3590 |
transferOps &= IMAGE_SHIFT_OFFSET_BIT; |
| 3591 |
|
| 3592 |
/* |
| 3593 |
* Try simple cases first |
| 3594 |
*/ |
| 3595 |
if (transferOps == 0 && |
| 3596 |
srcType == GL_UNSIGNED_BYTE && |
| 3597 |
dstType == GL_UNSIGNED_BYTE) { |
| 3598 |
MEMCPY(dest, source, n * sizeof(GLubyte)); |
| 3599 |
} |
| 3600 |
else if (transferOps == 0 && |
| 3601 |
srcType == GL_UNSIGNED_INT && |
| 3602 |
dstType == GL_UNSIGNED_INT && |
| 3603 |
!srcPacking->SwapBytes) { |
| 3604 |
MEMCPY(dest, source, n * sizeof(GLuint)); |
| 3605 |
} |
| 3606 |
else { |
| 3607 |
/* |
| 3608 |
* general solution |
| 3609 |
*/ |
| 3610 |
GLuint indexes[MAX_WIDTH]; |
| 3611 |
assert(n <= MAX_WIDTH); |
| 3612 |
|
| 3613 |
extract_uint_indexes(n, indexes, GL_COLOR_INDEX, srcType, source, |
| 3614 |
srcPacking); |
| 3615 |
|
| 3616 |
if (transferOps) { |
| 3617 |
if (transferOps & IMAGE_SHIFT_OFFSET_BIT) { |
| 3618 |
/* shift and offset indexes */ |
| 3619 |
_mesa_shift_and_offset_ci(ctx, n, indexes); |
| 3620 |
} |
| 3621 |
|
| 3622 |
if (ctx->Pixel.MapStencilFlag) { |
| 3623 |
/* Apply stencil lookup table */ |
| 3624 |
GLuint mask = ctx->Pixel.MapStoSsize - 1; |
| 3625 |
GLuint i; |
| 3626 |
for (i=0;i<n;i++) { |
| 3627 |
indexes[i] = ctx->Pixel.MapStoS[ indexes[i] & mask ]; |
| 3628 |
} |
| 3629 |
} |
| 3630 |
} |
| 3631 |
|
| 3632 |
/* convert to dest type */ |
| 3633 |
switch (dstType) { |
| 3634 |
case GL_UNSIGNED_BYTE: |
| 3635 |
{ |
| 3636 |
GLubyte *dst = (GLubyte *) dest; |
| 3637 |
GLuint i; |
| 3638 |
for (i = 0; i < n; i++) { |
| 3639 |
dst[i] = (GLubyte) (indexes[i] & 0xff); |
| 3640 |
} |
| 3641 |
} |
| 3642 |
break; |
| 3643 |
case GL_UNSIGNED_SHORT: |
| 3644 |
{ |
| 3645 |
GLuint *dst = (GLuint *) dest; |
| 3646 |
GLuint i; |
| 3647 |
for (i = 0; i < n; i++) { |
| 3648 |
dst[i] = (GLushort) (indexes[i] & 0xffff); |
| 3649 |
} |
| 3650 |
} |
| 3651 |
break; |
| 3652 |
case GL_UNSIGNED_INT: |
| 3653 |
MEMCPY(dest, indexes, n * sizeof(GLuint)); |
| 3654 |
break; |
| 3655 |
default: |
| 3656 |
_mesa_problem(ctx, "bad dstType in _mesa_unpack_stencil_span"); |
| 3657 |
} |
| 3658 |
} |
| 3659 |
} |
| 3660 |
|
| 3661 |
|
| 3662 |
void |
| 3663 |
_mesa_pack_stencil_span( const GLcontext *ctx, GLuint n, |
| 3664 |
GLenum dstType, GLvoid *dest, const GLstencil *source, |
| 3665 |
const struct gl_pixelstore_attrib *dstPacking ) |
| 3666 |
{ |
| 3667 |
GLstencil stencil[MAX_WIDTH]; |
| 3668 |
|
| 3669 |
ASSERT(n <= MAX_WIDTH); |
| 3670 |
|
| 3671 |
if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset || |
| 3672 |
ctx->Pixel.MapStencilFlag) { |
| 3673 |
/* make a copy of input */ |
| 3674 |
MEMCPY(stencil, source, n * sizeof(GLstencil)); |
| 3675 |
if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset) { |
| 3676 |
_mesa_shift_and_offset_stencil( ctx, n, stencil ); |
| 3677 |
} |
| 3678 |
if (ctx->Pixel.MapStencilFlag) { |
| 3679 |
_mesa_map_stencil( ctx, n, stencil ); |
| 3680 |
} |
| 3681 |
source = stencil; |
| 3682 |
} |
| 3683 |
|
| 3684 |
switch (dstType) { |
| 3685 |
case GL_UNSIGNED_BYTE: |
| 3686 |
if (sizeof(GLstencil) == 8) { |
| 3687 |
MEMCPY( dest, source, n ); |
| 3688 |
} |
| 3689 |
else { |
| 3690 |
GLubyte *dst = (GLubyte *) dest; |
| 3691 |
GLuint i; |
| 3692 |
for (i=0;i<n;i++) { |
| 3693 |
dst[i] = (GLubyte) source[i]; |
| 3694 |
} |
| 3695 |
} |
| 3696 |
break; |
| 3697 |
case GL_BYTE: |
| 3698 |
if (sizeof(GLstencil) == 8) { |
| 3699 |
MEMCPY( dest, source, n ); |
| 3700 |
} |
| 3701 |
else { |
| 3702 |
GLbyte *dst = (GLbyte *) dest; |
| 3703 |
GLuint i; |
| 3704 |
for (i=0;i<n;i++) { |
| 3705 |
dst[i] = (GLbyte) source[i]; |
| 3706 |
} |
| 3707 |
} |
| 3708 |
break; |
| 3709 |
case GL_UNSIGNED_SHORT: |
| 3710 |
{ |
| 3711 |
GLushort *dst = (GLushort *) dest; |
| 3712 |
GLuint i; |
| 3713 |
for (i=0;i<n;i++) { |
| 3714 |
dst[i] = (GLushort) source[i]; |
| 3715 |
} |
| 3716 |
if (dstPacking->SwapBytes) { |
| 3717 |
_mesa_swap2( (GLushort *) dst, n ); |
| 3718 |
} |
| 3719 |
} |
| 3720 |
break; |
| 3721 |
case GL_SHORT: |
| 3722 |
{ |
| 3723 |
GLshort *dst = (GLshort *) dest; |
| 3724 |
GLuint i; |
| 3725 |
for (i=0;i<n;i++) { |
| 3726 |
dst[i] = (GLshort) source[i]; |
| 3727 |
} |
| 3728 |
if (dstPacking->SwapBytes) { |
| 3729 |
_mesa_swap2( (GLushort *) dst, n ); |
| 3730 |
} |
| 3731 |
} |
| 3732 |
break; |
| 3733 |
case GL_UNSIGNED_INT: |
| 3734 |
{ |
| 3735 |
GLuint *dst = (GLuint *) dest; |
| 3736 |
GLuint i; |
| 3737 |
for (i=0;i<n;i++) { |
| 3738 |
dst[i] = (GLuint) source[i]; |
| 3739 |
} |
| 3740 |
if (dstPacking->SwapBytes) { |
| 3741 |
_mesa_swap4( (GLuint *) dst, n ); |
| 3742 |
} |
| 3743 |
} |
| 3744 |
break; |
| 3745 |
case GL_INT: |
| 3746 |
{ |
| 3747 |
GLint *dst = (GLint *) dest; |
| 3748 |
GLuint i; |
| 3749 |
for (i=0;i<n;i++) { |
| 3750 |
*dst++ = (GLint) source[i]; |
| 3751 |
} |
| 3752 |
if (dstPacking->SwapBytes) { |
| 3753 |
_mesa_swap4( (GLuint *) dst, n ); |
| 3754 |
} |
| 3755 |
} |
| 3756 |
break; |
| 3757 |
case GL_FLOAT: |
| 3758 |
{ |
| 3759 |
GLfloat *dst = (GLfloat *) dest; |
| 3760 |
GLuint i; |
| 3761 |
for (i=0;i<n;i++) { |
| 3762 |
dst[i] = (GLfloat) source[i]; |
| 3763 |
} |
| 3764 |
if (dstPacking->SwapBytes) { |
| 3765 |
_mesa_swap4( (GLuint *) dst, n ); |
| 3766 |
} |
| 3767 |
} |
| 3768 |
break; |
| 3769 |
case GL_HALF_FLOAT_ARB: |
| 3770 |
{ |
| 3771 |
GLhalfARB *dst = (GLhalfARB *) dest; |
| 3772 |
GLuint i; |
| 3773 |
for (i=0;i<n;i++) { |
| 3774 |
dst[i] = _mesa_float_to_half( (float) source[i] ); |
| 3775 |
} |
| 3776 |
if (dstPacking->SwapBytes) { |
| 3777 |
_mesa_swap2( (GLushort *) dst, n ); |
| 3778 |
} |
| 3779 |
} |
| 3780 |
break; |
| 3781 |
case GL_BITMAP: |
| 3782 |
if (dstPacking->LsbFirst) { |
| 3783 |
GLubyte *dst = (GLubyte *) dest; |
| 3784 |
GLint shift = 0; |
| 3785 |
GLuint i; |
| 3786 |
for (i = 0; i < n; i++) { |
| 3787 |
if (shift == 0) |
| 3788 |
*dst = 0; |
| 3789 |
*dst |= ((source[i] != 0) << shift); |
| 3790 |
shift++; |
| 3791 |
if (shift == 8) { |
| 3792 |
shift = 0; |
| 3793 |
dst++; |
| 3794 |
} |
| 3795 |
} |
| 3796 |
} |
| 3797 |
else { |
| 3798 |
GLubyte *dst = (GLubyte *) dest; |
| 3799 |
GLint shift = 7; |
| 3800 |
GLuint i; |
| 3801 |
for (i = 0; i < n; i++) { |
| 3802 |
if (shift == 7) |
| 3803 |
*dst = 0; |
| 3804 |
*dst |= ((source[i] != 0) << shift); |
| 3805 |
shift--; |
| 3806 |
if (shift < 0) { |
| 3807 |
shift = 7; |
| 3808 |
dst++; |
| 3809 |
} |
| 3810 |
} |
| 3811 |
} |
| 3812 |
break; |
| 3813 |
default: |
| 3814 |
_mesa_problem(ctx, "bad type in _mesa_pack_index_span"); |
| 3815 |
} |
| 3816 |
} |
| 3817 |
|
| 3818 |
|
| 3819 |
void |
| 3820 |
_mesa_unpack_depth_span( const GLcontext *ctx, GLuint n, GLfloat *dest, |
| 3821 |
GLenum srcType, const GLvoid *source, |
| 3822 |
const struct gl_pixelstore_attrib *srcPacking ) |
| 3823 |
{ |
| 3824 |
(void) srcPacking; |
| 3825 |
|
| 3826 |
switch (srcType) { |
| 3827 |
case GL_BYTE: |
| 3828 |
{ |
| 3829 |
GLuint i; |
| 3830 |
const GLubyte *src = (const GLubyte *) source; |
| 3831 |
for (i = 0; i < n; i++) { |
| 3832 |
dest[i] = BYTE_TO_FLOAT(src[i]); |
| 3833 |
} |
| 3834 |
} |
| 3835 |
break; |
| 3836 |
case GL_UNSIGNED_BYTE: |
| 3837 |
{ |
| 3838 |
GLuint i; |
| 3839 |
const GLubyte *src = (const GLubyte *) source; |
| 3840 |
for (i = 0; i < n; i++) { |
| 3841 |
dest[i] = UBYTE_TO_FLOAT(src[i]); |
| 3842 |
} |
| 3843 |
} |
| 3844 |
break; |
| 3845 |
case GL_SHORT: |
| 3846 |
{ |
| 3847 |
GLuint i; |
| 3848 |
const GLshort *src = (const GLshort *) source; |
| 3849 |
for (i = 0; i < n; i++) { |
| 3850 |
dest[i] = SHORT_TO_FLOAT(src[i]); |
| 3851 |
} |
| 3852 |
} |
| 3853 |
break; |
| 3854 |
case GL_UNSIGNED_SHORT: |
| 3855 |
{ |
| 3856 |
GLuint i; |
| 3857 |
const GLushort *src = (const GLushort *) source; |
| 3858 |
for (i = 0; i < n; i++) { |
| 3859 |
dest[i] = USHORT_TO_FLOAT(src[i]); |
| 3860 |
} |
| 3861 |
} |
| 3862 |
break; |
| 3863 |
case GL_INT: |
| 3864 |
{ |
| 3865 |
GLuint i; |
| 3866 |
const GLint *src = (const GLint *) source; |
| 3867 |
for (i = 0; i < n; i++) { |
| 3868 |
dest[i] = INT_TO_FLOAT(src[i]); |
| 3869 |
} |
| 3870 |
} |
| 3871 |
break; |
| 3872 |
case GL_UNSIGNED_INT: |
| 3873 |
{ |
| 3874 |
GLuint i; |
| 3875 |
const GLuint *src = (const GLuint *) source; |
| 3876 |
for (i = 0; i < n; i++) { |
| 3877 |
dest[i] = UINT_TO_FLOAT(src[i]); |
| 3878 |
} |
| 3879 |
} |
| 3880 |
break; |
| 3881 |
case GL_FLOAT: |
| 3882 |
MEMCPY(dest, source, n * sizeof(GLfloat)); |
| 3883 |
break; |
| 3884 |
case GL_HALF_FLOAT_ARB: |
| 3885 |
{ |
| 3886 |
GLuint i; |
| 3887 |
const GLhalfARB *src = (const GLhalfARB *) source; |
| 3888 |
for (i = 0; i < n; i++) { |
| 3889 |
dest[i] = _mesa_half_to_float(src[i]); |
| 3890 |
} |
| 3891 |
} |
| 3892 |
break; |
| 3893 |
default: |
| 3894 |
_mesa_problem(NULL, "bad type in _mesa_unpack_depth_span()"); |
| 3895 |
return; |
| 3896 |
} |
| 3897 |
|
| 3898 |
|
| 3899 |
/* apply depth scale and bias and clamp to [0,1] */ |
| 3900 |
if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) { |
| 3901 |
GLuint i; |
| 3902 |
for (i = 0; i < n; i++) { |
| 3903 |
GLfloat d = dest[i] * ctx->Pixel.DepthScale + ctx->Pixel.DepthBias; |
| 3904 |
dest[i] = CLAMP(d, 0.0F, 1.0F); |
| 3905 |
} |
| 3906 |
} |
| 3907 |
} |
| 3908 |
|
| 3909 |
|
| 3910 |
/* |
| 3911 |
* Pack an array of depth values. The values are floats in [0,1]. |
| 3912 |
*/ |
| 3913 |
void |
| 3914 |
_mesa_pack_depth_span( const GLcontext *ctx, GLuint n, GLvoid *dest, |
| 3915 |
GLenum dstType, const GLfloat *depthSpan, |
| 3916 |
const struct gl_pixelstore_attrib *dstPacking ) |
| 3917 |
{ |
| 3918 |
GLfloat depthCopy[MAX_WIDTH]; |
| 3919 |
const GLboolean bias_or_scale = ctx->Pixel.DepthBias != 0.0 || |
| 3920 |
ctx->Pixel.DepthScale != 1.0; |
| 3921 |
|
| 3922 |
ASSERT(n <= MAX_WIDTH); |
| 3923 |
|
| 3924 |
if (bias_or_scale) { |
| 3925 |
GLuint i; |
| 3926 |
for (i = 0; i < n; i++) { |
| 3927 |
GLfloat d; |
| 3928 |
d = depthSpan[i] * ctx->Pixel.DepthScale + ctx->Pixel.DepthBias; |
| 3929 |
depthCopy[i] = CLAMP(d, 0.0F, 1.0F); |
| 3930 |
} |
| 3931 |
depthSpan = depthCopy; |
| 3932 |
} |
| 3933 |
|
| 3934 |
switch (dstType) { |
| 3935 |
case GL_UNSIGNED_BYTE: |
| 3936 |
{ |
| 3937 |
GLubyte *dst = (GLubyte *) dest; |
| 3938 |
GLuint i; |
| 3939 |
for (i = 0; i < n; i++) { |
| 3940 |
dst[i] = FLOAT_TO_UBYTE( depthSpan[i] ); |
| 3941 |
} |
| 3942 |
} |
| 3943 |
break; |
| 3944 |
case GL_BYTE: |
| 3945 |
{ |
| 3946 |
GLbyte *dst = (GLbyte *) dest; |
| 3947 |
GLuint i; |
| 3948 |
for (i = 0; i < n; i++) { |
| 3949 |
dst[i] = FLOAT_TO_BYTE( depthSpan[i] ); |
| 3950 |
} |
| 3951 |
} |
| 3952 |
break; |
| 3953 |
case GL_UNSIGNED_SHORT: |
| 3954 |
{ |
| 3955 |
GLushort *dst = (GLushort *) dest; |
| 3956 |
GLuint i; |
| 3957 |
for (i = 0; i < n; i++) { |
| 3958 |
CLAMPED_FLOAT_TO_USHORT(dst[i], depthSpan[i]); |
| 3959 |
} |
| 3960 |
if (dstPacking->SwapBytes) { |
| 3961 |
_mesa_swap2( (GLushort *) dst, n ); |
| 3962 |
} |
| 3963 |
} |
| 3964 |
break; |
| 3965 |
case GL_SHORT: |
| 3966 |
{ |
| 3967 |
GLshort *dst = (GLshort *) dest; |
| 3968 |
GLuint i; |
| 3969 |
for (i = 0; i < n; i++) { |
| 3970 |
dst[i] = FLOAT_TO_SHORT( depthSpan[i] ); |
| 3971 |
} |
| 3972 |
if (dstPacking->SwapBytes) { |
| 3973 |
_mesa_swap2( (GLushort *) dst, n ); |
| 3974 |
} |
| 3975 |
} |
| 3976 |
break; |
| 3977 |
case GL_UNSIGNED_INT: |
| 3978 |
{ |
| 3979 |
GLuint *dst = (GLuint *) dest; |
| 3980 |
GLuint i; |
| 3981 |
for (i = 0; i < n; i++) { |
| 3982 |
dst[i] = FLOAT_TO_UINT( depthSpan[i] ); |
| 3983 |
} |
| 3984 |
if (dstPacking->SwapBytes) { |
| 3985 |
_mesa_swap4( (GLuint *) dst, n ); |
| 3986 |
} |
| 3987 |
} |
| 3988 |
break; |
| 3989 |
case GL_INT: |
| 3990 |
{ |
| 3991 |
GLint *dst = (GLint *) dest; |
| 3992 |
GLuint i; |
| 3993 |
for (i = 0; i < n; i++) { |
| 3994 |
dst[i] = FLOAT_TO_INT( depthSpan[i] ); |
| 3995 |
} |
| 3996 |
if (dstPacking->SwapBytes) { |
| 3997 |
_mesa_swap4( (GLuint *) dst, n ); |
| 3998 |
} |
| 3999 |
} |
| 4000 |
break; |
| 4001 |
case GL_FLOAT: |
| 4002 |
{ |
| 4003 |
GLfloat *dst = (GLfloat *) dest; |
| 4004 |
GLuint i; |
| 4005 |
for (i = 0; i < n; i++) { |
| 4006 |
dst[i] = depthSpan[i]; |
| 4007 |
} |
| 4008 |
if (dstPacking->SwapBytes) { |
| 4009 |
_mesa_swap4( (GLuint *) dst, n ); |
| 4010 |
} |
| 4011 |
} |
| 4012 |
break; |
| 4013 |
case GL_HALF_FLOAT_ARB: |
| 4014 |
{ |
| 4015 |
GLhalfARB *dst = (GLhalfARB *) dest; |
| 4016 |
GLuint i; |
| 4017 |
for (i = 0; i < n; i++) { |
| 4018 |
dst[i] = _mesa_float_to_half(depthSpan[i]); |
| 4019 |
} |
| 4020 |
if (dstPacking->SwapBytes) { |
| 4021 |
_mesa_swap2( (GLushort *) dst, n ); |
| 4022 |
} |
| 4023 |
} |
| 4024 |
break; |
| 4025 |
default: |
| 4026 |
_mesa_problem(ctx, "bad type in _mesa_pack_depth_span"); |
| 4027 |
} |
| 4028 |
} |
| 4029 |
|
| 4030 |
|
| 4031 |
/** |
| 4032 |
* Unpack image data. Apply byte swapping, byte flipping (bitmap). |
| 4033 |
* Return all image data in a contiguous block. This is used when we |
| 4034 |
* compile glDrawPixels, glTexImage, etc into a display list. We |
| 4035 |
* need a copy of the data in a standard format. |
| 4036 |
*/ |
| 4037 |
void * |
| 4038 |
_mesa_unpack_image( GLuint dimensions, |
| 4039 |
GLsizei width, GLsizei height, GLsizei depth, |
| 4040 |
GLenum format, GLenum type, const GLvoid *pixels, |
| 4041 |
const struct gl_pixelstore_attrib *unpack ) |
| 4042 |
{ |
| 4043 |
GLint bytesPerRow, compsPerRow; |
| 4044 |
GLboolean flipBytes, swap2, swap4; |
| 4045 |
|
| 4046 |
if (!pixels) |
| 4047 |
return NULL; /* not necessarily an error */ |
| 4048 |
|
| 4049 |
if (width <= 0 || height <= 0 || depth <= 0) |
| 4050 |
return NULL; /* generate error later */ |
| 4051 |
|
| 4052 |
if (format == GL_BITMAP) { |
| 4053 |
bytesPerRow = (width + 7) >> 3; |
| 4054 |
flipBytes = !unpack->LsbFirst; |
| 4055 |
swap2 = swap4 = GL_FALSE; |
| 4056 |
compsPerRow = 0; |
| 4057 |
} |
| 4058 |
else { |
| 4059 |
const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type); |
| 4060 |
const GLint components = _mesa_components_in_format(format); |
| 4061 |
GLint bytesPerComp; |
| 4062 |
if (bytesPerPixel <= 0 || components <= 0) |
| 4063 |
return NULL; /* bad format or type. generate error later */ |
| 4064 |
bytesPerRow = bytesPerPixel * width; |
| 4065 |
bytesPerComp = bytesPerPixel / components; |
| 4066 |
flipBytes = GL_FALSE; |
| 4067 |
swap2 = (bytesPerComp == 2) && unpack->SwapBytes; |
| 4068 |
swap4 = (bytesPerComp == 4) && unpack->SwapBytes; |
| 4069 |
compsPerRow = components * width; |
| 4070 |
assert(compsPerRow >= width); |
| 4071 |
} |
| 4072 |
|
| 4073 |
{ |
| 4074 |
GLubyte *destBuffer = (GLubyte *) MALLOC(bytesPerRow * height * depth); |
| 4075 |
GLubyte *dst; |
| 4076 |
GLint img, row; |
| 4077 |
if (!destBuffer) |
| 4078 |
return NULL; /* generate GL_OUT_OF_MEMORY later */ |
| 4079 |
|
| 4080 |
dst = destBuffer; |
| 4081 |
for (img = 0; img < depth; img++) { |
| 4082 |
for (row = 0; row < height; row++) { |
| 4083 |
const GLvoid *src = _mesa_image_address(dimensions, unpack, pixels, |
| 4084 |
width, height, format, type, img, row, 0); |
| 4085 |
MEMCPY(dst, src, bytesPerRow); |
| 4086 |
/* byte flipping/swapping */ |
| 4087 |
if (flipBytes) { |
| 4088 |
flip_bytes((GLubyte *) dst, bytesPerRow); |
| 4089 |
} |
| 4090 |
else if (swap2) { |
| 4091 |
_mesa_swap2((GLushort*) dst, compsPerRow); |
| 4092 |
} |
| 4093 |
else if (swap4) { |
| 4094 |
_mesa_swap4((GLuint*) dst, compsPerRow); |
| 4095 |
} |
| 4096 |
dst += bytesPerRow; |
| 4097 |
} |
| 4098 |
} |
| 4099 |
return destBuffer; |
| 4100 |
} |
| 4101 |
} |
| 4102 |
|
| 4103 |
#endif |
| 4104 |
|
| 4105 |
|
| 4106 |
/** |
| 4107 |
* Perform clipping for glDrawPixels. The image's window position |
| 4108 |
* and size, and the unpack skipPixels and skipRows are adjusted so |
| 4109 |
* that the image region is entirely within the window and scissor bounds. |
| 4110 |
* NOTE: this will only work when glPixelZoom is (1, 1). |
| 4111 |
* |
| 4112 |
* \return GL_TRUE if image is ready for drawing or |
| 4113 |
* GL_FALSE if image was completely clipped away (draw nothing) |
| 4114 |
*/ |
| 4115 |
GLboolean |
| 4116 |
_mesa_clip_drawpixels(const GLcontext *ctx, |
| 4117 |
GLint *destX, GLint *destY, |
| 4118 |
GLsizei *width, GLsizei *height, |
| 4119 |
GLint *skipPixels, GLint *skipRows) |
| 4120 |
{ |
| 4121 |
const GLframebuffer *buffer = ctx->DrawBuffer; |
| 4122 |
|
| 4123 |
ASSERT(ctx->Pixel.ZoomX == 1.0F && ctx->Pixel.ZoomY == 1.0F); |
| 4124 |
|
| 4125 |
/* left clipping */ |
| 4126 |
if (*destX < buffer->_Xmin) { |
| 4127 |
*skipPixels += (buffer->_Xmin - *destX); |
| 4128 |
*width -= (buffer->_Xmin - *destX); |
| 4129 |
*destX = buffer->_Xmin; |
| 4130 |
} |
| 4131 |
/* right clipping */ |
| 4132 |
if (*destX + *width > buffer->_Xmax) |
| 4133 |
*width -= (*destX + *width - buffer->_Xmax); |
| 4134 |
|
| 4135 |
if (*width <= 0) |
| 4136 |
return GL_FALSE; |
| 4137 |
|
| 4138 |
/* bottom clipping */ |
| 4139 |
if (*destY < buffer->_Ymin) { |
| 4140 |
*skipRows += (buffer->_Ymin - *destY); |
| 4141 |
*height -= (buffer->_Ymin - *destY); |
| 4142 |
*destY = buffer->_Ymin; |
| 4143 |
} |
| 4144 |
/* top clipping */ |
| 4145 |
if (*destY + *height > buffer->_Ymax) |
| 4146 |
*height -= (*destY + *height - buffer->_Ymax); |
| 4147 |
|
| 4148 |
if (*height <= 0) |
| 4149 |
return GL_TRUE; |
| 4150 |
|
| 4151 |
return GL_TRUE; |
| 4152 |
} |
| 4153 |
|
| 4154 |
|
| 4155 |
/** |
| 4156 |
* Perform clipping for glReadPixels. The image's window position |
| 4157 |
* and size, and the pack skipPixels and skipRows are adjusted so |
| 4158 |
* that the image region is entirely within the window bounds. |
| 4159 |
* Note: this is different from _mesa_clip_drawpixels() in that the |
| 4160 |
* scissor box is ignored, and we use the bounds of the current "read" |
| 4161 |
* surface; |
| 4162 |
* |
| 4163 |
* \return GL_TRUE if image is ready for drawing or |
| 4164 |
* GL_FALSE if image was completely clipped away (draw nothing) |
| 4165 |
*/ |
| 4166 |
GLboolean |
| 4167 |
_mesa_clip_readpixels(const GLcontext *ctx, |
| 4168 |
GLint *srcX, GLint *srcY, |
| 4169 |
GLsizei *width, GLsizei *height, |
| 4170 |
GLint *skipPixels, GLint *skipRows) |
| 4171 |
{ |
| 4172 |
const GLframebuffer *buffer = ctx->ReadBuffer; |
| 4173 |
|
| 4174 |
/* left clipping */ |
| 4175 |
if (*srcX < 0) { |
| 4176 |
*skipPixels += (0 - *srcX); |
| 4177 |
*width -= (0 - *srcX); |
| 4178 |
*srcX = 0; |
| 4179 |
} |
| 4180 |
/* right clipping */ |
| 4181 |
if (*srcX + *width > (GLsizei) buffer->Width) |
| 4182 |
*width -= (*srcX + *width - buffer->Width); |
| 4183 |
|
| 4184 |
if (*width <= 0) |
| 4185 |
return GL_FALSE; |
| 4186 |
|
| 4187 |
/* bottom clipping */ |
| 4188 |
if (*srcY < 0) { |
| 4189 |
*skipRows += (0 - *srcY); |
| 4190 |
*height -= (0 - *srcY); |
| 4191 |
*srcY = 0; |
| 4192 |
} |
| 4193 |
/* top clipping */ |
| 4194 |
if (*srcY + *height > (GLsizei) buffer->Height) |
| 4195 |
*height -= (*srcY + *height - buffer->Height); |
| 4196 |
|
| 4197 |
if (*height <= 0) |
| 4198 |
return GL_TRUE; |
| 4199 |
|
| 4200 |
return GL_TRUE; |
| 4201 |
} |
| 4202 |
|