1 /* $Id: image.c,v 1.37 2000/08/29 14:25:30 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 * These are the image packing parameters for Mesa's internal images.
46 * That is, _mesa_unpack_image() returns image data in this format.
47 * When we execute image commands (glDrawPixels, glTexImage, etc)
48 * from within display lists we have to be sure to set the current
49 * unpacking params to these values!
51 const struct gl_pixelstore_attrib _mesa_native_packing
= {
58 GL_FALSE
, /* SwapBytes */
59 GL_FALSE
/* LsbFirst */
65 * Flip the 8 bits in each byte of the given array.
68 flip_bytes( GLubyte
*p
, GLuint n
)
70 register GLuint i
, a
, b
;
74 a
= ((b
& 0x01) << 7) |
88 * Flip the order of the 2 bytes in each word in the given array.
91 _mesa_swap2( GLushort
*p
, GLuint n
)
96 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
103 * Flip the order of the 4 bytes in each word in the given array.
106 _mesa_swap4( GLuint
*p
, GLuint n
)
108 register GLuint i
, a
, b
;
113 | ((b
>> 8) & 0xff00)
114 | ((b
<< 8) & 0xff0000)
115 | ((b
<< 24) & 0xff000000);
124 * Return the size, in bytes, of the given GL datatype.
125 * Return 0 if GL_BITMAP.
126 * Return -1 if invalid type enum.
128 GLint
_mesa_sizeof_type( GLenum type
)
133 case GL_UNSIGNED_BYTE
:
134 return sizeof(GLubyte
);
136 return sizeof(GLbyte
);
137 case GL_UNSIGNED_SHORT
:
138 return sizeof(GLushort
);
140 return sizeof(GLshort
);
141 case GL_UNSIGNED_INT
:
142 return sizeof(GLuint
);
144 return sizeof(GLint
);
146 return sizeof(GLfloat
);
154 * Same as _mesa_sizeof_packed_type() but we also accept the
155 * packed pixel format datatypes.
157 GLint
_mesa_sizeof_packed_type( GLenum type
)
162 case GL_UNSIGNED_BYTE
:
163 return sizeof(GLubyte
);
165 return sizeof(GLbyte
);
166 case GL_UNSIGNED_SHORT
:
167 return sizeof(GLushort
);
169 return sizeof(GLshort
);
170 case GL_UNSIGNED_INT
:
171 return sizeof(GLuint
);
173 return sizeof(GLint
);
175 return sizeof(GLfloat
);
176 case GL_UNSIGNED_BYTE_3_3_2
:
177 return sizeof(GLubyte
);
178 case GL_UNSIGNED_BYTE_2_3_3_REV
:
179 return sizeof(GLubyte
);
180 case GL_UNSIGNED_SHORT_5_6_5
:
181 return sizeof(GLshort
);
182 case GL_UNSIGNED_SHORT_5_6_5_REV
:
183 return sizeof(GLshort
);
184 case GL_UNSIGNED_SHORT_4_4_4_4
:
185 return sizeof(GLshort
);
186 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
187 return sizeof(GLshort
);
188 case GL_UNSIGNED_SHORT_5_5_5_1
:
189 return sizeof(GLshort
);
190 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
191 return sizeof(GLshort
);
192 case GL_UNSIGNED_INT_8_8_8_8
:
193 return sizeof(GLuint
);
194 case GL_UNSIGNED_INT_8_8_8_8_REV
:
195 return sizeof(GLuint
);
196 case GL_UNSIGNED_INT_10_10_10_2
:
197 return sizeof(GLuint
);
198 case GL_UNSIGNED_INT_2_10_10_10_REV
:
199 return sizeof(GLuint
);
208 * Return the number of components in a GL enum pixel type.
209 * Return -1 if bad format.
211 GLint
_mesa_components_in_format( GLenum format
)
215 case GL_COLOR_INDEX1_EXT
:
216 case GL_COLOR_INDEX2_EXT
:
217 case GL_COLOR_INDEX4_EXT
:
218 case GL_COLOR_INDEX8_EXT
:
219 case GL_COLOR_INDEX12_EXT
:
220 case GL_COLOR_INDEX16_EXT
:
221 case GL_STENCIL_INDEX
:
222 case GL_DEPTH_COMPONENT
:
230 case GL_LUMINANCE_ALPHA
:
249 * Return bytes per pixel for given format and type
250 * Return -1 if bad format or type.
252 GLint
_mesa_bytes_per_pixel( GLenum format
, GLenum type
)
254 GLint comps
= _mesa_components_in_format( format
);
260 return 0; /* special case */
262 case GL_UNSIGNED_BYTE
:
263 return comps
* sizeof(GLubyte
);
265 case GL_UNSIGNED_SHORT
:
266 return comps
* sizeof(GLshort
);
268 case GL_UNSIGNED_INT
:
269 return comps
* sizeof(GLint
);
271 return comps
* sizeof(GLfloat
);
272 case GL_UNSIGNED_BYTE_3_3_2
:
273 case GL_UNSIGNED_BYTE_2_3_3_REV
:
274 if (format
== GL_RGB
|| format
== GL_BGR
)
275 return sizeof(GLubyte
);
277 return -1; /* error */
278 case GL_UNSIGNED_SHORT_5_6_5
:
279 case GL_UNSIGNED_SHORT_5_6_5_REV
:
280 if (format
== GL_RGB
|| format
== GL_BGR
)
281 return sizeof(GLshort
);
283 return -1; /* error */
284 case GL_UNSIGNED_SHORT_4_4_4_4
:
285 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
286 case GL_UNSIGNED_SHORT_5_5_5_1
:
287 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
288 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
289 return sizeof(GLushort
);
292 case GL_UNSIGNED_INT_8_8_8_8
:
293 case GL_UNSIGNED_INT_8_8_8_8_REV
:
294 case GL_UNSIGNED_INT_10_10_10_2
:
295 case GL_UNSIGNED_INT_2_10_10_10_REV
:
296 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
297 return sizeof(GLuint
);
307 * Test if the given pixel format and type are legal.
308 * Return GL_TRUE for legal, GL_FALSE for illegal.
311 _mesa_is_legal_format_and_type( GLenum format
, GLenum type
)
315 case GL_STENCIL_INDEX
:
319 case GL_UNSIGNED_BYTE
:
321 case GL_UNSIGNED_SHORT
:
323 case GL_UNSIGNED_INT
:
335 case GL_LUMINANCE_ALPHA
:
336 case GL_DEPTH_COMPONENT
:
340 case GL_UNSIGNED_BYTE
:
342 case GL_UNSIGNED_SHORT
:
344 case GL_UNSIGNED_INT
:
353 case GL_UNSIGNED_BYTE
:
355 case GL_UNSIGNED_SHORT
:
357 case GL_UNSIGNED_INT
:
359 case GL_UNSIGNED_BYTE_3_3_2
:
360 case GL_UNSIGNED_BYTE_2_3_3_REV
:
361 case GL_UNSIGNED_SHORT_5_6_5
:
362 case GL_UNSIGNED_SHORT_5_6_5_REV
:
372 case GL_UNSIGNED_BYTE
:
374 case GL_UNSIGNED_SHORT
:
376 case GL_UNSIGNED_INT
:
378 case GL_UNSIGNED_SHORT_4_4_4_4
:
379 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
380 case GL_UNSIGNED_SHORT_5_5_5_1
:
381 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
382 case GL_UNSIGNED_INT_8_8_8_8
:
383 case GL_UNSIGNED_INT_8_8_8_8_REV
:
384 case GL_UNSIGNED_INT_10_10_10_2
:
385 case GL_UNSIGNED_INT_2_10_10_10_REV
:
399 * Return the address of a pixel in an image (actually a volume).
400 * Pixel unpacking/packing parameters are observed according to 'packing'.
401 * Input: image - start of image data
402 * width, height - size of image
403 * format - image format
404 * type - pixel component type
405 * packing - the pixelstore attributes
406 * img - which image in the volume (0 for 1D or 2D images)
407 * row, column - location of pixel in the image
408 * Return: address of pixel at (image,row,column) in image or NULL if error.
411 _mesa_image_address( const struct gl_pixelstore_attrib
*packing
,
412 const GLvoid
*image
, GLsizei width
,
413 GLsizei height
, GLenum format
, GLenum type
,
414 GLint img
, GLint row
, GLint column
)
416 GLint alignment
; /* 1, 2 or 4 */
417 GLint pixels_per_row
;
418 GLint rows_per_image
;
421 GLint skipimages
; /* for 3-D volume images */
424 alignment
= packing
->Alignment
;
425 if (packing
->RowLength
> 0) {
426 pixels_per_row
= packing
->RowLength
;
429 pixels_per_row
= width
;
431 if (packing
->ImageHeight
> 0) {
432 rows_per_image
= packing
->ImageHeight
;
435 rows_per_image
= height
;
437 skiprows
= packing
->SkipRows
;
438 skippixels
= packing
->SkipPixels
;
439 skipimages
= packing
->SkipImages
;
441 if (type
==GL_BITMAP
) {
443 GLint comp_per_pixel
; /* components per pixel */
444 GLint bytes_per_comp
; /* bytes per component */
446 GLint bytes_per_image
;
448 /* Compute bytes per component */
449 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
450 if (bytes_per_comp
<0) {
454 /* Compute number of components per pixel */
455 comp_per_pixel
= _mesa_components_in_format( format
);
456 if (comp_per_pixel
<0 && type
!= GL_BITMAP
) {
460 bytes_per_row
= alignment
461 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
463 bytes_per_image
= bytes_per_row
* rows_per_image
;
465 pixel_addr
= (GLubyte
*) image
466 + (skipimages
+ img
) * bytes_per_image
467 + (skiprows
+ row
) * bytes_per_row
468 + (skippixels
+ column
) / 8;
471 /* Non-BITMAP data */
472 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
474 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
476 /* The pixel type and format should have been error checked earlier */
477 assert(bytes_per_pixel
> 0);
479 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
480 remainder
= bytes_per_row
% alignment
;
482 bytes_per_row
+= (alignment
- remainder
);
484 ASSERT(bytes_per_row
% alignment
== 0);
486 bytes_per_image
= bytes_per_row
* rows_per_image
;
488 /* compute final pixel address */
489 pixel_addr
= (GLubyte
*) image
490 + (skipimages
+ img
) * bytes_per_image
491 + (skiprows
+ row
) * bytes_per_row
492 + (skippixels
+ column
) * bytes_per_pixel
;
495 return (GLvoid
*) pixel_addr
;
501 * Compute the stride between image rows (in bytes) for the given
502 * pixel packing parameters and image width, format and type.
505 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
506 GLint width
, GLenum format
, GLenum type
)
509 if (type
== GL_BITMAP
) {
511 if (packing
->RowLength
== 0) {
512 GLint bytes
= (width
+ 7) / 8;
516 GLint bytes
= (packing
->RowLength
+ 7) / 8;
521 /* Non-BITMAP data */
522 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
523 GLint bytesPerRow
, remainder
;
524 if (bytesPerPixel
<= 0)
525 return -1; /* error */
526 if (packing
->RowLength
== 0) {
527 bytesPerRow
= bytesPerPixel
* width
;
530 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
532 remainder
= bytesPerRow
% packing
->Alignment
;
534 bytesPerRow
+= (packing
->Alignment
- remainder
);
542 * Unpack a 32x32 pixel polygon stipple from user memory using the
543 * current pixel unpack settings.
546 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
547 const struct gl_pixelstore_attrib
*unpacking
)
549 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap( 32, 32, pattern
, unpacking
);
551 /* Convert pattern from GLubytes to GLuints and handle big/little
556 for (i
= 0; i
< 32; i
++) {
557 dest
[i
] = (p
[0] << 24)
570 * Pack polygon stipple into user memory given current pixel packing
574 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
575 const struct gl_pixelstore_attrib
*packing
)
577 /* Convert pattern from GLuints to GLubytes to handle big/little
578 * endian differences.
582 for (i
= 0; i
< 32; i
++) {
583 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
584 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
585 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
586 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
589 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
595 * Pack the given RGBA span into client memory at 'dest' address
596 * in the given pixel format and type.
597 * Optionally apply the enabled pixel transfer ops.
598 * Pack into memory using the given packing params struct.
599 * This is used by glReadPixels and glGetTexImage?D()
600 * Input: ctx - the context
601 * n - number of pixels in the span
603 * format - dest packing format
604 * type - dest packing datatype
605 * destination - destination packing address
606 * packing - pixel packing parameters
607 * transferOps - bitmask of IMAGE_*_BIT operations to apply
610 _mesa_pack_rgba_span( GLcontext
*ctx
,
611 GLuint n
, CONST GLubyte srcRgba
[][4],
612 GLenum format
, GLenum type
, GLvoid
*destination
,
613 const struct gl_pixelstore_attrib
*packing
,
616 ASSERT(ctx
->ImageTransferState
!= UPDATE_IMAGE_TRANSFER_STATE
);
618 /* Test for optimized case first */
619 if (transferOps
== 0 && format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
620 /* common simple case */
621 MEMCPY( destination
, srcRgba
, n
* 4 * sizeof(GLubyte
) );
623 else if (transferOps
== 0 && format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
624 /* common simple case */
626 GLubyte
*dest
= (GLubyte
*) destination
;
627 for (i
= 0; i
< n
; i
++) {
628 dest
[0] = srcRgba
[i
][RCOMP
];
629 dest
[1] = srcRgba
[i
][GCOMP
];
630 dest
[2] = srcRgba
[i
][BCOMP
];
635 /* general solution */
636 GLfloat rgba
[MAX_WIDTH
][4], luminance
[MAX_WIDTH
];
637 const GLfloat rscale
= 1.0F
/ 255.0F
;
638 const GLfloat gscale
= 1.0F
/ 255.0F
;
639 const GLfloat bscale
= 1.0F
/ 255.0F
;
640 const GLfloat ascale
= 1.0F
/ 255.0F
;
641 const GLint comps
= _mesa_components_in_format(format
);
644 assert(n
<= MAX_WIDTH
);
646 /* convert color components to floating point */
648 rgba
[i
][RCOMP
] = srcRgba
[i
][RCOMP
] * rscale
;
649 rgba
[i
][GCOMP
] = srcRgba
[i
][GCOMP
] * gscale
;
650 rgba
[i
][BCOMP
] = srcRgba
[i
][BCOMP
] * bscale
;
651 rgba
[i
][ACOMP
] = srcRgba
[i
][ACOMP
] * ascale
;
655 * Apply scale, bias and lookup-tables if enabled.
659 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
660 _mesa_scale_and_bias_rgba( ctx
, n
, rgba
);
662 /* color map lookup */
663 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
664 _mesa_map_rgba( ctx
, n
, rgba
);
666 /* GL_COLOR_TABLE lookup */
667 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
668 _mesa_lookup_rgba(&ctx
->ColorTable
, n
, rgba
);
671 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
672 /* this has to be done in the calling code */
674 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
675 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
676 _mesa_lookup_rgba(&ctx
->PostConvolutionColorTable
, n
, rgba
);
678 /* color matrix transform */
679 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
680 _mesa_transform_rgba(ctx
, n
, rgba
);
682 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
683 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
684 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
686 /* update histogram count */
687 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
688 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
691 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
692 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
693 if (ctx
->MinMax
.Sink
)
698 /* XXX clamp rgba to [0,1]? */
701 if (format
== GL_LUMINANCE
|| format
== GL_LUMINANCE_ALPHA
) {
702 for (i
= 0; i
< n
; i
++) {
703 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
704 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
709 * Pack/store the pixels. Ugh! Lots of cases!!!
712 case GL_UNSIGNED_BYTE
:
714 GLubyte
*dst
= (GLubyte
*) destination
;
718 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
722 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
726 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
730 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
734 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
736 case GL_LUMINANCE_ALPHA
:
738 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
739 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
744 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
745 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
746 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
751 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
752 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
753 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
754 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
759 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
760 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
761 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
766 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
767 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
768 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
769 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
774 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
775 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
776 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
777 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
781 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
787 GLbyte
*dst
= (GLbyte
*) destination
;
791 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
795 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
799 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
803 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
807 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
809 case GL_LUMINANCE_ALPHA
:
811 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
812 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
817 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
818 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
819 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
824 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
825 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
826 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
827 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
832 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
833 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
834 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
839 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
840 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
841 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
842 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
846 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
847 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
848 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
849 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
853 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
857 case GL_UNSIGNED_SHORT
:
859 GLushort
*dst
= (GLushort
*) destination
;
863 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
867 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
871 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
875 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
879 dst
[i
] = FLOAT_TO_USHORT(luminance
[i
]);
881 case GL_LUMINANCE_ALPHA
:
883 dst
[i
*2+0] = FLOAT_TO_USHORT(luminance
[i
]);
884 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
889 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
890 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
891 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
896 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
897 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
898 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
899 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
904 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
905 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
906 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
911 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
912 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
913 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
914 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
919 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
920 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
921 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
922 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
926 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
928 if (packing
->SwapBytes
) {
929 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
935 GLshort
*dst
= (GLshort
*) destination
;
939 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
943 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
947 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
951 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
955 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
957 case GL_LUMINANCE_ALPHA
:
959 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
960 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
965 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
966 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
967 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
972 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
973 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
974 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
975 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
980 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
981 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
982 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
987 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
988 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
989 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
990 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
994 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
995 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
996 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
997 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1001 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1003 if (packing
->SwapBytes
) {
1004 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1008 case GL_UNSIGNED_INT
:
1010 GLuint
*dst
= (GLuint
*) destination
;
1014 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1018 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1022 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1026 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1030 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
1032 case GL_LUMINANCE_ALPHA
:
1034 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
1035 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1040 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1041 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1042 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1047 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1048 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1049 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1050 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1055 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1056 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1057 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1062 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1063 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1064 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1065 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1070 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1071 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1072 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1073 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1077 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1079 if (packing
->SwapBytes
) {
1080 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1086 GLint
*dst
= (GLint
*) destination
;
1090 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1094 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1098 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1102 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1106 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1108 case GL_LUMINANCE_ALPHA
:
1110 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1111 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1116 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1117 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1118 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1123 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1124 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1125 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1126 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1131 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1132 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1133 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1138 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1139 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1140 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1141 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1146 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1147 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1148 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1149 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1153 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1155 if (packing
->SwapBytes
) {
1156 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1162 GLfloat
*dst
= (GLfloat
*) destination
;
1166 dst
[i
] = rgba
[i
][RCOMP
];
1170 dst
[i
] = rgba
[i
][GCOMP
];
1174 dst
[i
] = rgba
[i
][BCOMP
];
1178 dst
[i
] = rgba
[i
][ACOMP
];
1182 dst
[i
] = luminance
[i
];
1184 case GL_LUMINANCE_ALPHA
:
1186 dst
[i
*2+0] = luminance
[i
];
1187 dst
[i
*2+1] = rgba
[i
][ACOMP
];
1192 dst
[i
*3+0] = rgba
[i
][RCOMP
];
1193 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1194 dst
[i
*3+2] = rgba
[i
][BCOMP
];
1199 dst
[i
*4+0] = rgba
[i
][RCOMP
];
1200 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1201 dst
[i
*4+2] = rgba
[i
][BCOMP
];
1202 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1207 dst
[i
*3+0] = rgba
[i
][BCOMP
];
1208 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1209 dst
[i
*3+2] = rgba
[i
][RCOMP
];
1214 dst
[i
*4+0] = rgba
[i
][BCOMP
];
1215 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1216 dst
[i
*4+2] = rgba
[i
][RCOMP
];
1217 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1222 dst
[i
*4+0] = rgba
[i
][ACOMP
];
1223 dst
[i
*4+1] = rgba
[i
][BCOMP
];
1224 dst
[i
*4+2] = rgba
[i
][GCOMP
];
1225 dst
[i
*4+3] = rgba
[i
][RCOMP
];
1229 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1231 if (packing
->SwapBytes
) {
1232 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1236 case GL_UNSIGNED_BYTE_3_3_2
:
1237 if (format
== GL_RGB
) {
1238 GLubyte
*dst
= (GLubyte
*) destination
;
1240 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
1241 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
1242 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
1246 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1247 if (format
== GL_RGB
) {
1248 GLubyte
*dst
= (GLubyte
*) destination
;
1250 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
1251 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
1252 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 5);
1256 case GL_UNSIGNED_SHORT_5_6_5
:
1257 if (format
== GL_RGB
) {
1258 GLushort
*dst
= (GLushort
*) destination
;
1260 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1261 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1262 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
1266 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1267 if (format
== GL_RGB
) {
1268 GLushort
*dst
= (GLushort
*) destination
;
1270 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1271 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1272 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
1276 case GL_UNSIGNED_SHORT_4_4_4_4
:
1277 if (format
== GL_RGB
) {
1278 GLushort
*dst
= (GLushort
*) destination
;
1280 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
1281 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1282 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1283 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1287 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1288 if (format
== GL_RGB
) {
1289 GLushort
*dst
= (GLushort
*) destination
;
1291 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
1292 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1293 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1294 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1298 case GL_UNSIGNED_SHORT_5_5_5_1
:
1299 if (format
== GL_RGB
) {
1300 GLushort
*dst
= (GLushort
*) destination
;
1302 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1303 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1304 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
1305 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1309 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1310 if (format
== GL_RGB
) {
1311 GLushort
*dst
= (GLushort
*) destination
;
1313 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1314 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1315 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
1316 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1320 case GL_UNSIGNED_INT_8_8_8_8
:
1321 if (format
== GL_RGBA
) {
1322 GLuint
*dst
= (GLuint
*) destination
;
1324 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
1325 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1326 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1327 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1330 else if (format
== GL_BGRA
) {
1331 GLuint
*dst
= (GLuint
*) destination
;
1333 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
1334 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1335 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
1336 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1339 else if (format
== GL_ABGR_EXT
) {
1340 GLuint
*dst
= (GLuint
*) destination
;
1342 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
1343 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1344 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1345 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
1349 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1350 if (format
== GL_RGBA
) {
1351 GLuint
*dst
= (GLuint
*) destination
;
1353 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
1354 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1355 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1356 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1359 else if (format
== GL_BGRA
) {
1360 GLuint
*dst
= (GLuint
*) destination
;
1362 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
1363 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1364 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
1365 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1368 else if (format
== GL_ABGR_EXT
) {
1369 GLuint
*dst
= (GLuint
*) destination
;
1371 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
1372 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1373 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1374 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
1378 case GL_UNSIGNED_INT_10_10_10_2
:
1379 if (format
== GL_RGBA
) {
1380 GLuint
*dst
= (GLuint
*) destination
;
1382 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
1383 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1384 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
1385 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1388 else if (format
== GL_BGRA
) {
1389 GLuint
*dst
= (GLuint
*) destination
;
1391 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
1392 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1393 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
1394 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1397 else if (format
== GL_ABGR_EXT
) {
1398 GLuint
*dst
= (GLuint
*) destination
;
1400 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
1401 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
1402 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
1403 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
1407 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1408 if (format
== GL_RGBA
) {
1409 GLuint
*dst
= (GLuint
*) destination
;
1411 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
1412 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1413 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
1414 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1417 else if (format
== GL_BGRA
) {
1418 GLuint
*dst
= (GLuint
*) destination
;
1420 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
1421 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1422 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
1423 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1426 else if (format
== GL_ABGR_EXT
) {
1427 GLuint
*dst
= (GLuint
*) destination
;
1429 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
1430 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
1431 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
1432 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
1437 gl_problem( ctx
, "bad type in _mesa_pack_rgba_span" );
1444 #define SWAP2BYTE(VALUE) \
1446 GLubyte *bytes = (GLubyte *) &(VALUE); \
1447 GLubyte tmp = bytes[0]; \
1448 bytes[0] = bytes[1]; \
1452 #define SWAP4BYTE(VALUE) \
1454 GLubyte *bytes = (GLubyte *) &(VALUE); \
1455 GLubyte tmp = bytes[0]; \
1456 bytes[0] = bytes[3]; \
1459 bytes[1] = bytes[2]; \
1465 extract_uint_indexes(GLuint n
, GLuint indexes
[],
1466 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
1467 const struct gl_pixelstore_attrib
*unpack
)
1469 assert(srcFormat
== GL_COLOR_INDEX
);
1471 ASSERT(srcType
== GL_BITMAP
||
1472 srcType
== GL_UNSIGNED_BYTE
||
1473 srcType
== GL_BYTE
||
1474 srcType
== GL_UNSIGNED_SHORT
||
1475 srcType
== GL_SHORT
||
1476 srcType
== GL_UNSIGNED_INT
||
1477 srcType
== GL_INT
||
1478 srcType
== GL_FLOAT
);
1483 GLubyte
*ubsrc
= (GLubyte
*) src
;
1484 if (unpack
->LsbFirst
) {
1485 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
1487 for (i
= 0; i
< n
; i
++) {
1488 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
1499 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
1501 for (i
= 0; i
< n
; i
++) {
1502 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
1514 case GL_UNSIGNED_BYTE
:
1517 const GLubyte
*s
= (const GLubyte
*) src
;
1518 for (i
= 0; i
< n
; i
++)
1525 const GLbyte
*s
= (const GLbyte
*) src
;
1526 for (i
= 0; i
< n
; i
++)
1530 case GL_UNSIGNED_SHORT
:
1533 const GLushort
*s
= (const GLushort
*) src
;
1534 if (unpack
->SwapBytes
) {
1535 for (i
= 0; i
< n
; i
++) {
1536 GLushort value
= s
[i
];
1542 for (i
= 0; i
< n
; i
++)
1550 const GLshort
*s
= (const GLshort
*) src
;
1551 if (unpack
->SwapBytes
) {
1552 for (i
= 0; i
< n
; i
++) {
1553 GLshort value
= s
[i
];
1559 for (i
= 0; i
< n
; i
++)
1564 case GL_UNSIGNED_INT
:
1567 const GLuint
*s
= (const GLuint
*) src
;
1568 if (unpack
->SwapBytes
) {
1569 for (i
= 0; i
< n
; i
++) {
1570 GLuint value
= s
[i
];
1576 for (i
= 0; i
< n
; i
++)
1584 const GLint
*s
= (const GLint
*) src
;
1585 if (unpack
->SwapBytes
) {
1586 for (i
= 0; i
< n
; i
++) {
1593 for (i
= 0; i
< n
; i
++)
1601 const GLfloat
*s
= (const GLfloat
*) src
;
1602 if (unpack
->SwapBytes
) {
1603 for (i
= 0; i
< n
; i
++) {
1604 GLfloat value
= s
[i
];
1606 indexes
[i
] = (GLuint
) value
;
1610 for (i
= 0; i
< n
; i
++)
1611 indexes
[i
] = (GLuint
) s
[i
];
1616 gl_problem(NULL
, "bad srcType in extract_uint_indexes");
1624 * This function extracts floating point RGBA values from arbitrary
1625 * image data. srcFormat and srcType are the format and type parameters
1626 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
1628 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
1629 * implements the "Conversion to floating point", "Conversion to RGB",
1630 * and "Final Expansion to RGBA" operations.
1632 * Args: n - number of pixels
1633 * rgba - output colors
1634 * srcFormat - format of incoming data
1635 * srcType - datatype of incoming data
1636 * src - source data pointer
1637 * swapBytes - perform byteswapping of incoming data?
1640 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
1641 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
1642 GLboolean swapBytes
)
1644 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
1646 GLint rComp
, bComp
, gComp
, aComp
;
1648 ASSERT(srcFormat
== GL_RED
||
1649 srcFormat
== GL_GREEN
||
1650 srcFormat
== GL_BLUE
||
1651 srcFormat
== GL_ALPHA
||
1652 srcFormat
== GL_LUMINANCE
||
1653 srcFormat
== GL_LUMINANCE_ALPHA
||
1654 srcFormat
== GL_INTENSITY
||
1655 srcFormat
== GL_RGB
||
1656 srcFormat
== GL_BGR
||
1657 srcFormat
== GL_RGBA
||
1658 srcFormat
== GL_BGRA
||
1659 srcFormat
== GL_ABGR_EXT
);
1661 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
1662 srcType
== GL_BYTE
||
1663 srcType
== GL_UNSIGNED_SHORT
||
1664 srcType
== GL_SHORT
||
1665 srcType
== GL_UNSIGNED_INT
||
1666 srcType
== GL_INT
||
1667 srcType
== GL_FLOAT
||
1668 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
1669 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
1670 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
1671 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
1672 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
1673 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
1674 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
1675 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
1676 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1677 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
1678 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
1679 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1681 rComp
= gComp
= bComp
= aComp
= -1;
1683 switch (srcFormat
) {
1686 greenIndex
= blueIndex
= alphaIndex
= -1;
1691 redIndex
= blueIndex
= alphaIndex
= -1;
1696 redIndex
= greenIndex
= alphaIndex
= -1;
1700 redIndex
= greenIndex
= blueIndex
= -1;
1705 redIndex
= greenIndex
= blueIndex
= 0;
1709 case GL_LUMINANCE_ALPHA
:
1710 redIndex
= greenIndex
= blueIndex
= 0;
1716 greenIndex
= blueIndex
= alphaIndex
= -1;
1767 gl_problem(NULL
, "bad srcFormat in extract float data");
1772 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
1773 if ((INDEX) < 0) { \
1775 for (i = 0; i < n; i++) { \
1776 rgba[i][CHANNEL] = DEFAULT; \
1779 else if (swapBytes) { \
1780 const TYPE *s = (const TYPE *) src; \
1782 for (i = 0; i < n; i++) { \
1783 TYPE value = s[INDEX]; \
1784 if (sizeof(TYPE) == 2) { \
1787 else if (sizeof(TYPE) == 4) { \
1790 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
1795 const TYPE *s = (const TYPE *) src; \
1797 for (i = 0; i < n; i++) { \
1798 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
1804 case GL_UNSIGNED_BYTE
:
1805 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1806 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1807 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1808 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1811 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1812 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1813 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1814 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
1816 case GL_UNSIGNED_SHORT
:
1817 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1818 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1819 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1820 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
1823 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1824 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1825 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1826 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
1828 case GL_UNSIGNED_INT
:
1829 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1830 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1831 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1832 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
1835 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1836 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1837 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1838 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
1841 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1842 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1843 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1844 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
1846 case GL_UNSIGNED_BYTE_3_3_2
:
1848 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
1850 for (i
= 0; i
< n
; i
++) {
1851 GLubyte p
= ubsrc
[i
];
1852 rgba
[i
][RCOMP
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
1853 rgba
[i
][GCOMP
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
1854 rgba
[i
][BCOMP
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
1855 rgba
[i
][ACOMP
] = 1.0F
;
1859 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1861 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
1863 for (i
= 0; i
< n
; i
++) {
1864 GLubyte p
= ubsrc
[i
];
1865 rgba
[i
][RCOMP
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
1866 rgba
[i
][GCOMP
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
1867 rgba
[i
][BCOMP
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
1868 rgba
[i
][ACOMP
] = 1.0F
;
1872 case GL_UNSIGNED_SHORT_5_6_5
:
1874 const GLushort
*ussrc
= (const GLushort
*) src
;
1876 for (i
= 0; i
< n
; i
++) {
1877 GLushort p
= ussrc
[i
];
1879 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1880 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1881 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1882 rgba
[i
][ACOMP
] = 1.0F
;
1886 const GLushort
*ussrc
= (const GLushort
*) src
;
1888 for (i
= 0; i
< n
; i
++) {
1889 GLushort p
= ussrc
[i
];
1890 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1891 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1892 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1893 rgba
[i
][ACOMP
] = 1.0F
;
1897 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1899 const GLushort
*ussrc
= (const GLushort
*) src
;
1901 for (i
= 0; i
< n
; i
++) {
1902 GLushort p
= ussrc
[i
];
1904 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1905 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1906 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1907 rgba
[i
][ACOMP
] = 1.0F
;
1911 const GLushort
*ussrc
= (const GLushort
*) src
;
1913 for (i
= 0; i
< n
; i
++) {
1914 GLushort p
= ussrc
[i
];
1915 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1916 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1917 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1918 rgba
[i
][ACOMP
] = 1.0F
;
1922 case GL_UNSIGNED_SHORT_4_4_4_4
:
1924 const GLushort
*ussrc
= (const GLushort
*) src
;
1926 for (i
= 0; i
< n
; i
++) {
1927 GLushort p
= ussrc
[i
];
1929 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1930 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1931 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1932 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1936 const GLushort
*ussrc
= (const GLushort
*) src
;
1938 for (i
= 0; i
< n
; i
++) {
1939 GLushort p
= ussrc
[i
];
1940 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1941 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1942 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1943 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1947 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1949 const GLushort
*ussrc
= (const GLushort
*) src
;
1951 for (i
= 0; i
< n
; i
++) {
1952 GLushort p
= ussrc
[i
];
1954 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1955 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1956 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1957 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1961 const GLushort
*ussrc
= (const GLushort
*) src
;
1963 for (i
= 0; i
< n
; i
++) {
1964 GLushort p
= ussrc
[i
];
1965 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1966 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1967 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1968 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1972 case GL_UNSIGNED_SHORT_5_5_5_1
:
1974 const GLushort
*ussrc
= (const GLushort
*) src
;
1976 for (i
= 0; i
< n
; i
++) {
1977 GLushort p
= ussrc
[i
];
1979 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1980 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
1981 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
1982 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
1986 const GLushort
*ussrc
= (const GLushort
*) src
;
1988 for (i
= 0; i
< n
; i
++) {
1989 GLushort p
= ussrc
[i
];
1990 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1991 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
1992 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
1993 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
1997 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1999 const GLushort
*ussrc
= (const GLushort
*) src
;
2001 for (i
= 0; i
< n
; i
++) {
2002 GLushort p
= ussrc
[i
];
2004 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2005 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2006 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2007 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2011 const GLushort
*ussrc
= (const GLushort
*) src
;
2013 for (i
= 0; i
< n
; i
++) {
2014 GLushort p
= ussrc
[i
];
2015 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2016 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2017 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2018 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2022 case GL_UNSIGNED_INT_8_8_8_8
:
2024 const GLuint
*uisrc
= (const GLuint
*) src
;
2026 for (i
= 0; i
< n
; i
++) {
2027 GLuint p
= uisrc
[i
];
2028 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2029 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2030 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2031 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2035 const GLuint
*uisrc
= (const GLuint
*) src
;
2037 for (i
= 0; i
< n
; i
++) {
2038 GLuint p
= uisrc
[i
];
2039 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2040 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2041 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2042 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2046 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2048 const GLuint
*uisrc
= (const GLuint
*) src
;
2050 for (i
= 0; i
< n
; i
++) {
2051 GLuint p
= uisrc
[i
];
2052 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2053 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2054 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2055 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2059 const GLuint
*uisrc
= (const GLuint
*) src
;
2061 for (i
= 0; i
< n
; i
++) {
2062 GLuint p
= uisrc
[i
];
2063 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2064 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2065 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2066 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2070 case GL_UNSIGNED_INT_10_10_10_2
:
2072 const GLuint
*uisrc
= (const GLuint
*) src
;
2074 for (i
= 0; i
< n
; i
++) {
2075 GLuint p
= uisrc
[i
];
2077 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2078 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2079 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2080 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2084 const GLuint
*uisrc
= (const GLuint
*) src
;
2086 for (i
= 0; i
< n
; i
++) {
2087 GLuint p
= uisrc
[i
];
2088 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2089 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2090 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2091 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2095 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2097 const GLuint
*uisrc
= (const GLuint
*) src
;
2099 for (i
= 0; i
< n
; i
++) {
2100 GLuint p
= uisrc
[i
];
2102 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2103 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2104 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2105 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2109 const GLuint
*uisrc
= (const GLuint
*) src
;
2111 for (i
= 0; i
< n
; i
++) {
2112 GLuint p
= uisrc
[i
];
2113 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2114 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2115 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2116 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2121 gl_problem(NULL
, "bad srcType in extract float data");
2129 * Unpack a row of color image data from a client buffer according to
2130 * the pixel unpacking parameters.
2131 * Return GLubyte values in the specified dest image format.
2132 * This is (or will be) used by glDrawPixels and glTexImage?D().
2133 * Input: ctx - the context
2134 * n - number of pixels in the span
2135 * dstFormat - format of destination color array
2136 * dest - the destination color array
2137 * srcFormat - source image format
2138 * srcType - source image datatype
2139 * source - source image pointer
2140 * unpacking - pixel unpacking parameters
2141 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
2143 * XXX perhaps expand this to process whole images someday.
2146 _mesa_unpack_ubyte_color_span( GLcontext
*ctx
,
2147 GLuint n
, GLenum dstFormat
, GLubyte dest
[],
2148 GLenum srcFormat
, GLenum srcType
,
2149 const GLvoid
*source
,
2150 const struct gl_pixelstore_attrib
*unpacking
,
2151 GLuint transferOps
)
2153 ASSERT(dstFormat
== GL_ALPHA
||
2154 dstFormat
== GL_LUMINANCE
||
2155 dstFormat
== GL_LUMINANCE_ALPHA
||
2156 dstFormat
== GL_INTENSITY
||
2157 dstFormat
== GL_RGB
||
2158 dstFormat
== GL_RGBA
||
2159 dstFormat
== GL_COLOR_INDEX
);
2161 ASSERT(srcFormat
== GL_RED
||
2162 srcFormat
== GL_GREEN
||
2163 srcFormat
== GL_BLUE
||
2164 srcFormat
== GL_ALPHA
||
2165 srcFormat
== GL_LUMINANCE
||
2166 srcFormat
== GL_LUMINANCE_ALPHA
||
2167 srcFormat
== GL_INTENSITY
||
2168 srcFormat
== GL_RGB
||
2169 srcFormat
== GL_BGR
||
2170 srcFormat
== GL_RGBA
||
2171 srcFormat
== GL_BGRA
||
2172 srcFormat
== GL_ABGR_EXT
||
2173 srcFormat
== GL_COLOR_INDEX
);
2175 ASSERT(srcType
== GL_BITMAP
||
2176 srcType
== GL_UNSIGNED_BYTE
||
2177 srcType
== GL_BYTE
||
2178 srcType
== GL_UNSIGNED_SHORT
||
2179 srcType
== GL_SHORT
||
2180 srcType
== GL_UNSIGNED_INT
||
2181 srcType
== GL_INT
||
2182 srcType
== GL_FLOAT
||
2183 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2184 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2185 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2186 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2187 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2188 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2189 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2190 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2191 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2192 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2193 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2194 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2196 /* this is intended for RGBA mode only */
2197 assert(ctx
->Visual
->RGBAflag
);
2199 /* Try simple cases first */
2200 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
) {
2201 if (dstFormat
== GL_RGBA
) {
2202 if (srcFormat
== GL_RGBA
) {
2203 MEMCPY( dest
, source
, n
* 4 * sizeof(GLubyte
) );
2206 else if (srcFormat
== GL_RGB
) {
2208 const GLubyte
*src
= (const GLubyte
*) source
;
2209 GLubyte
*dst
= dest
;
2210 for (i
= 0; i
< n
; i
++) {
2221 else if (dstFormat
== GL_RGB
) {
2222 if (srcFormat
== GL_RGB
) {
2223 MEMCPY( dest
, source
, n
* 3 * sizeof(GLubyte
) );
2226 else if (srcFormat
== GL_RGBA
) {
2228 const GLubyte
*src
= (const GLubyte
*) source
;
2229 GLubyte
*dst
= dest
;
2230 for (i
= 0; i
< n
; i
++) {
2240 else if (dstFormat
== srcFormat
) {
2241 GLint comps
= _mesa_components_in_format(srcFormat
);
2243 MEMCPY( dest
, source
, n
* comps
* sizeof(GLubyte
) );
2249 /* general solution begins here */
2251 GLfloat rgba
[MAX_WIDTH
][4];
2252 GLint dstComponents
;
2253 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2254 GLint dstLuminanceIndex
, dstIntensityIndex
;
2256 dstComponents
= _mesa_components_in_format( dstFormat
);
2257 /* source & dest image formats should have been error checked by now */
2258 assert(dstComponents
> 0);
2261 * Extract image data and convert to RGBA floats
2263 assert(n
<= MAX_WIDTH
);
2264 if (srcFormat
== GL_COLOR_INDEX
) {
2265 GLuint indexes
[MAX_WIDTH
];
2266 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2269 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
2270 _mesa_map_ci(ctx
, n
, indexes
);
2272 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
2273 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2276 if (dstFormat
== GL_COLOR_INDEX
) {
2277 /* convert to GLubyte and return */
2279 for (i
= 0; i
< n
; i
++) {
2280 dest
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2285 /* Convert indexes to RGBA */
2286 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
2290 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2291 unpacking
->SwapBytes
);
2293 /* scale and bias colors */
2294 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
2295 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
);
2297 /* color map lookup */
2298 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
2299 _mesa_map_rgba(ctx
, n
, rgba
);
2304 /* GL_COLOR_TABLE lookup */
2305 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
2306 _mesa_lookup_rgba(&ctx
->ColorTable
, n
, rgba
);
2309 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
2310 /* this has to be done in the calling code */
2312 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
2313 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
2314 _mesa_lookup_rgba(&ctx
->PostConvolutionColorTable
, n
, rgba
);
2316 /* color matrix transform */
2317 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
2318 _mesa_transform_rgba(ctx
, n
, rgba
);
2320 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
2321 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
2322 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
2324 /* update histogram count */
2325 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
2326 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
2329 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
2330 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
2334 /* clamp to [0,1] */
2337 for (i
= 0; i
< n
; i
++) {
2338 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
2339 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
2340 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
2341 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
2345 /* Now determine which color channels we need to produce.
2346 * And determine the dest index (offset) within each color tuple.
2348 switch (dstFormat
) {
2351 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2352 dstLuminanceIndex
= dstIntensityIndex
= -1;
2355 dstLuminanceIndex
= 0;
2356 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2357 dstIntensityIndex
= -1;
2359 case GL_LUMINANCE_ALPHA
:
2360 dstLuminanceIndex
= 0;
2362 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2363 dstIntensityIndex
= -1;
2366 dstIntensityIndex
= 0;
2367 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2368 dstLuminanceIndex
= -1;
2374 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
2381 dstLuminanceIndex
= dstIntensityIndex
= -1;
2384 gl_problem(ctx
, "bad dstFormat in _mesa_unpack_ubyte_span()");
2389 /* Now return the GLubyte data in the requested dstFormat */
2391 if (dstRedIndex
>= 0) {
2392 GLubyte
*dst
= dest
;
2394 for (i
= 0; i
< n
; i
++) {
2395 dst
[dstRedIndex
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2396 dst
+= dstComponents
;
2400 if (dstGreenIndex
>= 0) {
2401 GLubyte
*dst
= dest
;
2403 for (i
= 0; i
< n
; i
++) {
2404 dst
[dstGreenIndex
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2405 dst
+= dstComponents
;
2409 if (dstBlueIndex
>= 0) {
2410 GLubyte
*dst
= dest
;
2412 for (i
= 0; i
< n
; i
++) {
2413 dst
[dstBlueIndex
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2414 dst
+= dstComponents
;
2418 if (dstAlphaIndex
>= 0) {
2419 GLubyte
*dst
= dest
;
2421 for (i
= 0; i
< n
; i
++) {
2422 dst
[dstAlphaIndex
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2423 dst
+= dstComponents
;
2427 if (dstIntensityIndex
>= 0) {
2428 GLubyte
*dst
= dest
;
2430 assert(dstIntensityIndex
== 0);
2431 assert(dstComponents
== 1);
2432 for (i
= 0; i
< n
; i
++) {
2433 /* Intensity comes from red channel */
2434 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2438 if (dstLuminanceIndex
>= 0) {
2439 GLubyte
*dst
= dest
;
2441 assert(dstLuminanceIndex
== 0);
2442 for (i
= 0; i
< n
; i
++) {
2443 /* Luminance comes from red channel */
2444 dst
[0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2445 dst
+= dstComponents
;
2453 _mesa_unpack_float_color_span( GLcontext
*ctx
,
2454 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
2455 GLenum srcFormat
, GLenum srcType
,
2456 const GLvoid
*source
,
2457 const struct gl_pixelstore_attrib
*unpacking
,
2458 GLuint transferOps
, GLboolean clamp
)
2460 ASSERT(dstFormat
== GL_ALPHA
||
2461 dstFormat
== GL_LUMINANCE
||
2462 dstFormat
== GL_LUMINANCE_ALPHA
||
2463 dstFormat
== GL_INTENSITY
||
2464 dstFormat
== GL_RGB
||
2465 dstFormat
== GL_RGBA
||
2466 dstFormat
== GL_COLOR_INDEX
);
2468 ASSERT(srcFormat
== GL_RED
||
2469 srcFormat
== GL_GREEN
||
2470 srcFormat
== GL_BLUE
||
2471 srcFormat
== GL_ALPHA
||
2472 srcFormat
== GL_LUMINANCE
||
2473 srcFormat
== GL_LUMINANCE_ALPHA
||
2474 srcFormat
== GL_INTENSITY
||
2475 srcFormat
== GL_RGB
||
2476 srcFormat
== GL_BGR
||
2477 srcFormat
== GL_RGBA
||
2478 srcFormat
== GL_BGRA
||
2479 srcFormat
== GL_ABGR_EXT
||
2480 srcFormat
== GL_COLOR_INDEX
);
2482 ASSERT(srcType
== GL_BITMAP
||
2483 srcType
== GL_UNSIGNED_BYTE
||
2484 srcType
== GL_BYTE
||
2485 srcType
== GL_UNSIGNED_SHORT
||
2486 srcType
== GL_SHORT
||
2487 srcType
== GL_UNSIGNED_INT
||
2488 srcType
== GL_INT
||
2489 srcType
== GL_FLOAT
||
2490 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2491 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2492 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2493 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2494 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2495 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2496 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2497 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2498 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2499 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2500 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2501 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2503 /* this is intended for RGBA mode only */
2504 assert(ctx
->Visual
->RGBAflag
);
2506 /* general solution, no special cases, yet */
2508 GLfloat rgba
[MAX_WIDTH
][4];
2509 GLint dstComponents
;
2510 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2511 GLint dstLuminanceIndex
, dstIntensityIndex
;
2513 dstComponents
= _mesa_components_in_format( dstFormat
);
2514 /* source & dest image formats should have been error checked by now */
2515 assert(dstComponents
> 0);
2518 * Extract image data and convert to RGBA floats
2520 assert(n
<= MAX_WIDTH
);
2521 if (srcFormat
== GL_COLOR_INDEX
) {
2522 GLuint indexes
[MAX_WIDTH
];
2523 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2526 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
2527 _mesa_map_ci(ctx
, n
, indexes
);
2529 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
2530 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2533 if (dstFormat
== GL_COLOR_INDEX
) {
2534 /* convert to GLubyte and return */
2536 for (i
= 0; i
< n
; i
++) {
2537 dest
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2542 /* Convert indexes to RGBA */
2543 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
2547 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2548 unpacking
->SwapBytes
);
2550 /* scale and bias colors */
2551 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
2552 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
);
2554 /* color map lookup */
2555 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
2556 _mesa_map_rgba(ctx
, n
, rgba
);
2561 /* GL_COLOR_TABLE lookup */
2562 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
2563 _mesa_lookup_rgba(&ctx
->ColorTable
, n
, rgba
);
2566 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
2569 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
2570 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
2571 _mesa_lookup_rgba(&ctx
->PostConvolutionColorTable
, n
, rgba
);
2573 /* color matrix transform */
2574 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
2575 _mesa_transform_rgba(ctx
, n
, rgba
);
2577 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
2578 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
2579 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
2581 /* update histogram count */
2582 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
2583 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
2586 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
2587 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
2591 /* clamp to [0,1] */
2594 for (i
= 0; i
< n
; i
++) {
2595 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
2596 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
2597 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
2598 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
2602 /* Now determine which color channels we need to produce.
2603 * And determine the dest index (offset) within each color tuple.
2605 switch (dstFormat
) {
2608 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2609 dstLuminanceIndex
= dstIntensityIndex
= -1;
2612 dstLuminanceIndex
= 0;
2613 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2614 dstIntensityIndex
= -1;
2616 case GL_LUMINANCE_ALPHA
:
2617 dstLuminanceIndex
= 0;
2619 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2620 dstIntensityIndex
= -1;
2623 dstIntensityIndex
= 0;
2624 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2625 dstLuminanceIndex
= -1;
2631 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
2638 dstLuminanceIndex
= dstIntensityIndex
= -1;
2641 gl_problem(ctx
, "bad dstFormat in _mesa_unpack_float_color_span()");
2645 /* Now pack results in the requested dstFormat */
2646 if (dstRedIndex
>= 0) {
2647 GLfloat
*dst
= dest
;
2649 for (i
= 0; i
< n
; i
++) {
2650 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
2651 dst
+= dstComponents
;
2655 if (dstGreenIndex
>= 0) {
2656 GLfloat
*dst
= dest
;
2658 for (i
= 0; i
< n
; i
++) {
2659 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
2660 dst
+= dstComponents
;
2664 if (dstBlueIndex
>= 0) {
2665 GLfloat
*dst
= dest
;
2667 for (i
= 0; i
< n
; i
++) {
2668 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
2669 dst
+= dstComponents
;
2673 if (dstAlphaIndex
>= 0) {
2674 GLfloat
*dst
= dest
;
2676 for (i
= 0; i
< n
; i
++) {
2677 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
2678 dst
+= dstComponents
;
2682 if (dstIntensityIndex
>= 0) {
2683 GLfloat
*dst
= dest
;
2685 assert(dstIntensityIndex
== 0);
2686 assert(dstComponents
== 1);
2687 for (i
= 0; i
< n
; i
++) {
2688 /* Intensity comes from red channel */
2689 dst
[i
] = rgba
[i
][RCOMP
];
2693 if (dstLuminanceIndex
>= 0) {
2694 GLfloat
*dst
= dest
;
2696 assert(dstLuminanceIndex
== 0);
2697 for (i
= 0; i
< n
; i
++) {
2698 /* Luminance comes from red channel */
2699 dst
[0] = rgba
[i
][RCOMP
];
2700 dst
+= dstComponents
;
2710 * Unpack a row of color index data from a client buffer according to
2711 * the pixel unpacking parameters.
2712 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
2714 * Args: ctx - the context
2715 * n - number of pixels
2716 * dstType - destination datatype
2717 * dest - destination array
2718 * srcType - source pixel type
2719 * source - source data pointer
2720 * unpacking - pixel unpacking parameters
2721 * transferOps - the pixel transfer operations to apply
2724 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
2725 GLenum dstType
, GLvoid
*dest
,
2726 GLenum srcType
, const GLvoid
*source
,
2727 const struct gl_pixelstore_attrib
*unpacking
,
2728 GLuint transferOps
)
2730 ASSERT(srcType
== GL_BITMAP
||
2731 srcType
== GL_UNSIGNED_BYTE
||
2732 srcType
== GL_BYTE
||
2733 srcType
== GL_UNSIGNED_SHORT
||
2734 srcType
== GL_SHORT
||
2735 srcType
== GL_UNSIGNED_INT
||
2736 srcType
== GL_INT
||
2737 srcType
== GL_FLOAT
);
2739 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
2740 dstType
== GL_UNSIGNED_SHORT
||
2741 dstType
== GL_UNSIGNED_INT
);
2744 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
2747 * Try simple cases first
2749 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
2750 && dstType
== GL_UNSIGNED_BYTE
) {
2751 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
2753 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
2754 && dstType
== GL_UNSIGNED_INT
&& !unpacking
->SwapBytes
) {
2755 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
2761 GLuint indexes
[MAX_WIDTH
];
2762 assert(n
<= MAX_WIDTH
);
2764 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
2767 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
2768 /* shift and offset indexes */
2769 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2771 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
2772 /* Apply lookup table */
2773 _mesa_map_ci(ctx
, n
, indexes
);
2776 /* convert to dest type */
2778 case GL_UNSIGNED_BYTE
:
2780 GLubyte
*dst
= (GLubyte
*) dest
;
2782 for (i
= 0; i
< n
; i
++) {
2783 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2787 case GL_UNSIGNED_SHORT
:
2789 GLuint
*dst
= (GLuint
*) dest
;
2791 for (i
= 0; i
< n
; i
++) {
2792 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
2796 case GL_UNSIGNED_INT
:
2797 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
2800 gl_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
2807 * Unpack a row of stencil data from a client buffer according to
2808 * the pixel unpacking parameters.
2809 * This is (or will be) used by glDrawPixels
2811 * Args: ctx - the context
2812 * n - number of pixels
2813 * dstType - destination datatype
2814 * dest - destination array
2815 * srcType - source pixel type
2816 * source - source data pointer
2817 * unpacking - pixel unpacking parameters
2818 * transferOps - apply offset/bias/lookup ops?
2821 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
2822 GLenum dstType
, GLvoid
*dest
,
2823 GLenum srcType
, const GLvoid
*source
,
2824 const struct gl_pixelstore_attrib
*unpacking
,
2825 GLuint transferOps
)
2827 ASSERT(srcType
== GL_BITMAP
||
2828 srcType
== GL_UNSIGNED_BYTE
||
2829 srcType
== GL_BYTE
||
2830 srcType
== GL_UNSIGNED_SHORT
||
2831 srcType
== GL_SHORT
||
2832 srcType
== GL_UNSIGNED_INT
||
2833 srcType
== GL_INT
||
2834 srcType
== GL_FLOAT
);
2836 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
2837 dstType
== GL_UNSIGNED_SHORT
||
2838 dstType
== GL_UNSIGNED_INT
);
2840 /* only shift and offset apply to stencil */
2841 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
2844 * Try simple cases first
2846 if (transferOps
== 0 &&
2847 srcType
== GL_UNSIGNED_BYTE
&&
2848 dstType
== GL_UNSIGNED_BYTE
) {
2849 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
2851 else if (transferOps
== 0 &&
2852 srcType
== GL_UNSIGNED_INT
&&
2853 dstType
== GL_UNSIGNED_INT
&&
2854 !unpacking
->SwapBytes
) {
2855 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
2861 GLuint indexes
[MAX_WIDTH
];
2862 assert(n
<= MAX_WIDTH
);
2864 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
2868 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
2869 /* shift and offset indexes */
2870 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2873 if (ctx
->Pixel
.MapStencilFlag
) {
2874 /* Apply stencil lookup table */
2875 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
2878 indexes
[i
] = ctx
->Pixel
.MapStoS
[ indexes
[i
] & mask
];
2883 /* convert to dest type */
2885 case GL_UNSIGNED_BYTE
:
2887 GLubyte
*dst
= (GLubyte
*) dest
;
2889 for (i
= 0; i
< n
; i
++) {
2890 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2894 case GL_UNSIGNED_SHORT
:
2896 GLuint
*dst
= (GLuint
*) dest
;
2898 for (i
= 0; i
< n
; i
++) {
2899 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
2903 case GL_UNSIGNED_INT
:
2904 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
2907 gl_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
2915 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
, GLdepth
*dest
,
2916 GLenum srcType
, const GLvoid
*source
,
2917 const struct gl_pixelstore_attrib
*unpacking
,
2918 GLuint transferOps
)
2920 GLfloat
*depth
= MALLOC(n
* sizeof(GLfloat
));
2928 const GLubyte
*src
= (const GLubyte
*) source
;
2929 for (i
= 0; i
< n
; i
++) {
2930 depth
[i
] = BYTE_TO_FLOAT(src
[i
]);
2934 case GL_UNSIGNED_BYTE
:
2937 const GLubyte
*src
= (const GLubyte
*) source
;
2938 for (i
= 0; i
< n
; i
++) {
2939 depth
[i
] = UBYTE_TO_FLOAT(src
[i
]);
2946 const GLshort
*src
= (const GLshort
*) source
;
2947 for (i
= 0; i
< n
; i
++) {
2948 depth
[i
] = SHORT_TO_FLOAT(src
[i
]);
2952 case GL_UNSIGNED_SHORT
:
2955 const GLushort
*src
= (const GLushort
*) source
;
2956 for (i
= 0; i
< n
; i
++) {
2957 depth
[i
] = USHORT_TO_FLOAT(src
[i
]);
2964 const GLint
*src
= (const GLint
*) source
;
2965 for (i
= 0; i
< n
; i
++) {
2966 depth
[i
] = INT_TO_FLOAT(src
[i
]);
2970 case GL_UNSIGNED_INT
:
2973 const GLuint
*src
= (const GLuint
*) source
;
2974 for (i
= 0; i
< n
; i
++) {
2975 depth
[i
] = UINT_TO_FLOAT(src
[i
]);
2980 MEMCPY(depth
, source
, n
* sizeof(GLfloat
));
2983 gl_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
2989 /* apply depth scale and bias */
2990 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
2992 for (i
= 0; i
< n
; i
++) {
2993 depth
[i
] = depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
2997 /* clamp depth values to [0,1] and convert from floats to integers */
2999 const GLfloat zs
= ctx
->Visual
->DepthMaxF
;
3001 for (i
= 0; i
< n
; i
++) {
3002 dest
[i
] = (GLdepth
) (CLAMP(depth
[i
], 0.0F
, 1.0F
) * zs
);
3012 * Unpack image data. Apply byteswapping, byte flipping (bitmap).
3013 * Return all image data in a contiguous block.
3016 _mesa_unpack_image( GLsizei width
, GLsizei height
, GLsizei depth
,
3017 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3018 const struct gl_pixelstore_attrib
*unpack
)
3020 GLint bytesPerRow
, compsPerRow
;
3021 GLboolean flipBytes
, swap2
, swap4
;
3024 return NULL
; /* not necessarily an error */
3026 if (width
<= 0 || height
<= 0 || depth
<= 0)
3027 return NULL
; /* generate error later */
3029 if (format
== GL_BITMAP
) {
3030 bytesPerRow
= (width
+ 7) >> 3;
3031 flipBytes
= !unpack
->LsbFirst
;
3032 swap2
= swap4
= GL_FALSE
;
3036 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
3037 const GLint components
= _mesa_components_in_format(format
);
3039 if (bytesPerPixel
<= 0 || components
<= 0)
3040 return NULL
; /* bad format or type. generate error later */
3041 bytesPerRow
= bytesPerPixel
* width
;
3042 bytesPerComp
= bytesPerPixel
/ components
;
3043 flipBytes
= GL_FALSE
;
3044 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
3045 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
3046 compsPerRow
= components
* width
;
3047 assert(compsPerRow
>= width
);
3051 GLubyte
*destBuffer
= MALLOC(bytesPerRow
* height
* depth
);
3055 return NULL
; /* generate GL_OUT_OF_MEMORY later */
3058 for (img
= 0; img
< depth
; img
++) {
3059 for (row
= 0; row
< height
; row
++) {
3060 const GLvoid
*src
= _mesa_image_address(unpack
, pixels
,
3061 width
, height
, format
, type
, img
, row
, 0);
3062 MEMCPY(dst
, src
, bytesPerRow
);
3063 /* byte flipping/swapping */
3065 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
3068 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
3071 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
3082 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
3083 * order with row alignment = 1 byte.
3086 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
3087 const struct gl_pixelstore_attrib
*packing
)
3089 GLint bytes
, row
, width_in_bytes
;
3090 GLubyte
*buffer
, *dst
;
3095 /* Alloc dest storage */
3096 bytes
= ((width
+ 7) / 8 * height
);
3097 buffer
= (GLubyte
*) MALLOC( bytes
);
3102 width_in_bytes
= CEILING( width
, 8 );
3104 for (row
= 0; row
< height
; row
++) {
3105 GLubyte
*src
= _mesa_image_address( packing
, pixels
, width
, height
,
3106 GL_COLOR_INDEX
, GL_BITMAP
,
3113 if (packing
->SkipPixels
== 0) {
3114 MEMCPY( dst
, src
, width_in_bytes
);
3115 if (packing
->LsbFirst
) {
3116 flip_bytes( dst
, width_in_bytes
);
3120 /* handling SkipPixels is a bit tricky (no pun intended!) */
3122 if (packing
->LsbFirst
) {
3123 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
3124 GLubyte dstMask
= 128;
3128 for (i
= 0; i
< width
; i
++) {
3132 if (srcMask
== 128) {
3137 srcMask
= srcMask
<< 1;
3145 dstMask
= dstMask
>> 1;
3150 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
3151 GLubyte dstMask
= 128;
3155 for (i
= 0; i
< width
; i
++) {
3164 srcMask
= srcMask
>> 1;
3172 dstMask
= dstMask
>> 1;
3177 dst
+= width_in_bytes
;
3188 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
3189 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
3191 GLint row
, width_in_bytes
;
3197 width_in_bytes
= CEILING( width
, 8 );
3199 for (row
= 0; row
< height
; row
++) {
3200 GLubyte
*dst
= _mesa_image_address( packing
, dest
, width
, height
,
3201 GL_COLOR_INDEX
, GL_BITMAP
,
3206 if (packing
->SkipPixels
== 0) {
3207 MEMCPY( dst
, src
, width_in_bytes
);
3208 if (packing
->LsbFirst
) {
3209 flip_bytes( dst
, width_in_bytes
);
3213 /* handling SkipPixels is a bit tricky (no pun intended!) */
3215 if (packing
->LsbFirst
) {
3216 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
3217 GLubyte dstMask
= 128;
3218 const GLubyte
*s
= src
;
3221 for (i
= 0; i
< width
; i
++) {
3225 if (srcMask
== 128) {
3230 srcMask
= srcMask
<< 1;
3238 dstMask
= dstMask
>> 1;
3243 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
3244 GLubyte dstMask
= 128;
3245 const GLubyte
*s
= src
;
3248 for (i
= 0; i
< width
; i
++) {
3257 srcMask
= srcMask
>> 1;
3265 dstMask
= dstMask
>> 1;
3270 src
+= width_in_bytes
;