2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
33 #include "bufferobj.h"
38 #include "histogram.h"
44 /** Compute ceiling of integer quotient of A divided by B. */
45 #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
49 * Flip the 8 bits in each byte of the given array.
52 * \param n number of bytes.
54 * \todo try this trick to flip bytes someday:
56 * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555);
57 * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333);
58 * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f);
62 flip_bytes( GLubyte
*p
, GLuint n
)
64 register GLuint i
, a
, b
;
67 b
= (GLuint
) p
[i
]; /* words are often faster than bytes */
68 a
= ((b
& 0x01) << 7) |
82 * Flip the order of the 2 bytes in each word in the given array.
85 * \param n number of words.
88 _mesa_swap2( GLushort
*p
, GLuint n
)
93 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
100 * Flip the order of the 4 bytes in each word in the given array.
103 _mesa_swap4( GLuint
*p
, GLuint n
)
105 register GLuint i
, a
, b
;
110 | ((b
>> 8) & 0xff00)
111 | ((b
<< 8) & 0xff0000)
112 | ((b
<< 24) & 0xff000000);
119 * Get the size of a GL data type.
121 * \param type GL data type.
123 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
124 * if an invalid type enum.
126 GLint
_mesa_sizeof_type( GLenum type
)
131 case GL_UNSIGNED_BYTE
:
132 return sizeof(GLubyte
);
134 return sizeof(GLbyte
);
135 case GL_UNSIGNED_SHORT
:
136 return sizeof(GLushort
);
138 return sizeof(GLshort
);
139 case GL_UNSIGNED_INT
:
140 return sizeof(GLuint
);
142 return sizeof(GLint
);
144 return sizeof(GLfloat
);
145 case GL_HALF_FLOAT_ARB
:
146 return sizeof(GLhalfARB
);
154 * Same as _mesa_sizeof_type() but also accepting the packed pixel
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
);
174 case GL_HALF_FLOAT_ARB
:
175 return sizeof(GLhalfARB
);
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
);
212 * Get the number of components in a pixel format.
214 * \param format pixel format.
216 * \return the number of components in the given format, or -1 if a bad format.
218 GLint
_mesa_components_in_format( GLenum format
)
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
:
237 case GL_LUMINANCE_ALPHA
:
258 * Get the bytes per pixel of pixel format type pair.
260 * \param format pixel format.
261 * \param type pixel type.
263 * \return bytes per pixel, or -1 if a bad format or type was given.
265 GLint
_mesa_bytes_per_pixel( GLenum format
, GLenum type
)
267 GLint comps
= _mesa_components_in_format( format
);
273 return 0; /* special case */
275 case GL_UNSIGNED_BYTE
:
276 return comps
* sizeof(GLubyte
);
278 case GL_UNSIGNED_SHORT
:
279 return comps
* sizeof(GLshort
);
281 case GL_UNSIGNED_INT
:
282 return comps
* sizeof(GLint
);
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
);
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
);
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
);
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
);
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
);
328 * Test for a legal pixel format and type.
330 * \param format pixel format.
331 * \param type pixel type.
333 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
337 _mesa_is_legal_format_and_type( GLcontext
*ctx
, GLenum format
, GLenum type
)
341 case GL_STENCIL_INDEX
:
345 case GL_UNSIGNED_BYTE
:
347 case GL_UNSIGNED_SHORT
:
349 case GL_UNSIGNED_INT
:
352 case GL_HALF_FLOAT_ARB
:
353 return ctx
->Extensions
.ARB_half_float_pixel
;
361 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
365 case GL_LUMINANCE_ALPHA
:
366 case GL_DEPTH_COMPONENT
:
369 case GL_UNSIGNED_BYTE
:
371 case GL_UNSIGNED_SHORT
:
373 case GL_UNSIGNED_INT
:
376 case GL_HALF_FLOAT_ARB
:
377 return ctx
->Extensions
.ARB_half_float_pixel
;
384 case GL_UNSIGNED_BYTE
:
386 case GL_UNSIGNED_SHORT
:
388 case GL_UNSIGNED_INT
:
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
:
395 case GL_HALF_FLOAT_ARB
:
396 return ctx
->Extensions
.ARB_half_float_pixel
;
403 case GL_UNSIGNED_BYTE
:
405 case GL_UNSIGNED_SHORT
:
407 case GL_UNSIGNED_INT
:
410 case GL_HALF_FLOAT_ARB
:
411 return ctx
->Extensions
.ARB_half_float_pixel
;
420 case GL_UNSIGNED_BYTE
:
422 case GL_UNSIGNED_SHORT
:
424 case GL_UNSIGNED_INT
:
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
:
435 case GL_HALF_FLOAT_ARB
:
436 return ctx
->Extensions
.ARB_half_float_pixel
;
441 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
442 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
454 * Get the address of a pixel in an image (actually a volume).
456 * Pixel unpacking/packing parameters are observed according to \p packing.
458 * \param image start of image data.
459 * \param width image width.
460 * \param height image height.
461 * \param format pixel format.
462 * \param type pixel data type.
463 * \param packing the pixelstore attributes
464 * \param img which image in the volume (0 for 1D or 2D images)
465 * \param row of pixel in the image
466 * \param column of pixel in the image
468 * \return address of pixel on success, or NULL on error.
470 * According to the \p packing information calculates the number of pixel/bytes
471 * per row/image and refers it.
473 * \sa gl_pixelstore_attrib.
476 _mesa_image_address( const struct gl_pixelstore_attrib
*packing
,
477 const GLvoid
*image
, GLsizei width
,
478 GLsizei height
, GLenum format
, GLenum type
,
479 GLint img
, GLint row
, GLint column
)
481 GLint alignment
; /* 1, 2 or 4 */
482 GLint pixels_per_row
;
483 GLint rows_per_image
;
486 GLint skipimages
; /* for 3-D volume images */
489 alignment
= packing
->Alignment
;
490 if (packing
->RowLength
> 0) {
491 pixels_per_row
= packing
->RowLength
;
494 pixels_per_row
= width
;
496 if (packing
->ImageHeight
> 0) {
497 rows_per_image
= packing
->ImageHeight
;
500 rows_per_image
= height
;
502 skiprows
= packing
->SkipRows
;
503 skippixels
= packing
->SkipPixels
;
504 skipimages
= packing
->SkipImages
;
506 if (type
==GL_BITMAP
) {
508 GLint comp_per_pixel
; /* components per pixel */
509 GLint bytes_per_comp
; /* bytes per component */
511 GLint bytes_per_image
;
513 /* Compute bytes per component */
514 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
515 if (bytes_per_comp
<0) {
519 /* Compute number of components per pixel */
520 comp_per_pixel
= _mesa_components_in_format( format
);
521 if (comp_per_pixel
<0 && type
!= GL_BITMAP
) {
525 bytes_per_row
= alignment
526 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
528 bytes_per_image
= bytes_per_row
* rows_per_image
;
530 pixel_addr
= (GLubyte
*) image
531 + (skipimages
+ img
) * bytes_per_image
532 + (skiprows
+ row
) * bytes_per_row
533 + (skippixels
+ column
) / 8;
536 /* Non-BITMAP data */
537 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
540 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
542 /* The pixel type and format should have been error checked earlier */
543 assert(bytes_per_pixel
> 0);
545 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
546 remainder
= bytes_per_row
% alignment
;
548 bytes_per_row
+= (alignment
- remainder
);
550 ASSERT(bytes_per_row
% alignment
== 0);
552 bytes_per_image
= bytes_per_row
* rows_per_image
;
554 if (packing
->Invert
) {
555 /* set pixel_addr to the last row */
556 topOfImage
= bytes_per_row
* (height
- 1);
557 bytes_per_row
= -bytes_per_row
;
563 /* compute final pixel address */
564 pixel_addr
= (GLubyte
*) image
565 + (skipimages
+ img
) * bytes_per_image
567 + (skiprows
+ row
) * bytes_per_row
568 + (skippixels
+ column
) * bytes_per_pixel
;
571 return (GLvoid
*) pixel_addr
;
576 * Compute the stride between image rows.
578 * \param packing the pixelstore attributes
579 * \param width image width.
580 * \param format pixel format.
581 * \param type pixel data type.
583 * \return the stride in bytes for the given parameters.
585 * Computes the number of bytes per pixel and row and compensates for alignment.
587 * \sa gl_pixelstore_attrib.
590 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
591 GLint width
, GLenum format
, GLenum type
)
594 if (type
== GL_BITMAP
) {
597 if (packing
->RowLength
== 0) {
598 bytes
= (width
+ 7) / 8;
601 bytes
= (packing
->RowLength
+ 7) / 8;
603 if (packing
->Invert
) {
604 /* negate the bytes per row (negative row stride) */
610 /* Non-BITMAP data */
611 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
612 GLint bytesPerRow
, remainder
;
613 if (bytesPerPixel
<= 0)
614 return -1; /* error */
615 if (packing
->RowLength
== 0) {
616 bytesPerRow
= bytesPerPixel
* width
;
619 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
621 remainder
= bytesPerRow
% packing
->Alignment
;
623 bytesPerRow
+= (packing
->Alignment
- remainder
);
625 bytesPerRow
= -bytesPerRow
;
634 * Compute the stride between images in a 3D texture (in bytes) for the given
635 * pixel packing parameters and image width, format and type.
638 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
639 GLint width
, GLint height
,
640 GLenum format
, GLenum type
)
643 ASSERT(type
!= GL_BITMAP
);
646 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
647 GLint bytesPerRow
, bytesPerImage
, remainder
;
649 if (bytesPerPixel
<= 0)
650 return -1; /* error */
651 if (packing
->RowLength
== 0) {
652 bytesPerRow
= bytesPerPixel
* width
;
655 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
657 remainder
= bytesPerRow
% packing
->Alignment
;
659 bytesPerRow
+= (packing
->Alignment
- remainder
);
661 if (packing
->ImageHeight
== 0)
662 bytesPerImage
= bytesPerRow
* height
;
664 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
666 return bytesPerImage
;
672 * Unpack a 32x32 pixel polygon stipple from user memory using the
673 * current pixel unpack settings.
676 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
677 const struct gl_pixelstore_attrib
*unpacking
)
679 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap( 32, 32, pattern
, unpacking
);
681 /* Convert pattern from GLubytes to GLuints and handle big/little
686 for (i
= 0; i
< 32; i
++) {
687 dest
[i
] = (p
[0] << 24)
699 * Pack polygon stipple into user memory given current pixel packing
703 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
704 const struct gl_pixelstore_attrib
*packing
)
706 /* Convert pattern from GLuints to GLubytes to handle big/little
707 * endian differences.
711 for (i
= 0; i
< 32; i
++) {
712 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
713 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
714 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
715 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
718 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
723 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
724 * order with row alignment = 1 byte.
727 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
728 const struct gl_pixelstore_attrib
*packing
)
730 GLint bytes
, row
, width_in_bytes
;
731 GLubyte
*buffer
, *dst
;
736 /* Alloc dest storage */
737 bytes
= ((width
+ 7) / 8 * height
);
738 buffer
= (GLubyte
*) MALLOC( bytes
);
743 width_in_bytes
= CEILING( width
, 8 );
745 for (row
= 0; row
< height
; row
++) {
746 const GLubyte
*src
= (const GLubyte
*)
747 _mesa_image_address(packing
, pixels
, width
, height
,
748 GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0);
754 if (packing
->SkipPixels
== 0) {
755 MEMCPY( dst
, src
, width_in_bytes
);
756 if (packing
->LsbFirst
) {
757 flip_bytes( dst
, width_in_bytes
);
761 /* handling SkipPixels is a bit tricky (no pun intended!) */
763 if (packing
->LsbFirst
) {
764 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
765 GLubyte dstMask
= 128;
766 const GLubyte
*s
= src
;
769 for (i
= 0; i
< width
; i
++) {
773 if (srcMask
== 128) {
778 srcMask
= srcMask
<< 1;
786 dstMask
= dstMask
>> 1;
791 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
792 GLubyte dstMask
= 128;
793 const GLubyte
*s
= src
;
796 for (i
= 0; i
< width
; i
++) {
805 srcMask
= srcMask
>> 1;
813 dstMask
= dstMask
>> 1;
818 dst
+= width_in_bytes
;
829 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
830 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
832 GLint row
, width_in_bytes
;
838 width_in_bytes
= CEILING( width
, 8 );
840 for (row
= 0; row
< height
; row
++) {
841 GLubyte
*dst
= (GLubyte
*) _mesa_image_address( packing
, dest
,
842 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
846 if (packing
->SkipPixels
== 0) {
847 MEMCPY( dst
, src
, width_in_bytes
);
848 if (packing
->LsbFirst
) {
849 flip_bytes( dst
, width_in_bytes
);
853 /* handling SkipPixels is a bit tricky (no pun intended!) */
855 if (packing
->LsbFirst
) {
856 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
857 GLubyte dstMask
= 128;
858 const GLubyte
*s
= src
;
861 for (i
= 0; i
< width
; i
++) {
865 if (srcMask
== 128) {
870 srcMask
= srcMask
<< 1;
878 dstMask
= dstMask
>> 1;
883 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
884 GLubyte dstMask
= 128;
885 const GLubyte
*s
= src
;
888 for (i
= 0; i
< width
; i
++) {
897 srcMask
= srcMask
>> 1;
905 dstMask
= dstMask
>> 1;
910 src
+= width_in_bytes
;
916 * Apply various pixel transfer operations to an array of RGBA pixels
917 * as indicated by the transferOps bitmask
920 _mesa_apply_rgba_transfer_ops(GLcontext
*ctx
, GLuint transferOps
,
921 GLuint n
, GLfloat rgba
[][4])
924 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
925 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
,
926 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
927 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
928 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
929 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
931 /* color map lookup */
932 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
933 _mesa_map_rgba( ctx
, n
, rgba
);
935 /* GL_COLOR_TABLE lookup */
936 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
937 _mesa_lookup_rgba_float(&ctx
->ColorTable
, n
, rgba
);
940 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
941 /* this has to be done in the calling code */
942 _mesa_problem(ctx
, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");
944 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
945 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
946 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
,
947 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
948 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
949 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
950 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
951 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
952 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
953 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
954 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
956 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
957 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
958 _mesa_lookup_rgba_float(&ctx
->PostConvolutionColorTable
, n
, rgba
);
960 /* color matrix transform */
961 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
962 _mesa_transform_rgba(ctx
, n
, rgba
);
964 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
965 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
966 _mesa_lookup_rgba_float(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
968 /* update histogram count */
969 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
970 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
972 /* update min/max values */
973 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
974 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
976 /* clamping to [0,1] */
977 if (transferOps
& IMAGE_CLAMP_BIT
) {
979 for (i
= 0; i
< n
; i
++) {
980 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
981 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
982 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
983 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
991 * Used to pack an array [][4] of RGBA float colors as specified
992 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
993 * glGetConvolutionFilter(), etc.
996 _mesa_pack_rgba_span_float( GLcontext
*ctx
,
997 GLuint n
, CONST GLfloat rgbaIn
[][4],
998 GLenum dstFormat
, GLenum dstType
,
1000 const struct gl_pixelstore_attrib
*dstPacking
,
1001 GLuint transferOps
)
1003 const GLint comps
= _mesa_components_in_format(dstFormat
);
1004 GLfloat luminance
[MAX_WIDTH
];
1005 const GLfloat (*rgba
)[4];
1009 /* make copy of incoming data */
1010 DEFMARRAY(GLfloat
, rgbaCopy
, MAX_WIDTH
, 4); /* mac 32k limitation */
1011 CHECKARRAY(rgbaCopy
, return); /* mac 32k limitation */
1013 _mesa_memcpy(rgbaCopy
, rgbaIn
, n
* 4 * sizeof(GLfloat
));
1014 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgbaCopy
);
1015 rgba
= (const GLfloat (*)[4]) rgbaCopy
;
1017 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
1018 UNDEFARRAY(rgbaCopy
); /* mac 32k limitation */
1021 UNDEFARRAY(rgbaCopy
); /* mac 32k limitation */
1024 /* use incoming data, not a copy */
1025 rgba
= (const GLfloat (*)[4]) rgbaIn
;
1028 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
1029 /* compute luminance values */
1030 if (ctx
->ClampFragmentColors
) {
1031 for (i
= 0; i
< n
; i
++) {
1032 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1033 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
1037 for (i
= 0; i
< n
; i
++) {
1038 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1044 * Pack/store the pixels. Ugh! Lots of cases!!!
1047 case GL_UNSIGNED_BYTE
:
1049 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1050 switch (dstFormat
) {
1053 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1057 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1061 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1065 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1069 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1071 case GL_LUMINANCE_ALPHA
:
1073 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1074 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1079 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1080 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1081 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1086 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1087 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1088 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1089 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1094 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1095 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1096 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1101 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1102 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1103 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1104 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1109 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1110 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1111 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1112 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1116 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1122 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1123 switch (dstFormat
) {
1126 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1130 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1134 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1138 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1142 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1144 case GL_LUMINANCE_ALPHA
:
1146 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1147 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1152 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1153 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1154 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1159 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1160 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1161 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1162 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1167 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1168 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1169 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1174 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1175 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1176 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1177 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1181 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1182 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1183 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1184 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1188 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1192 case GL_UNSIGNED_SHORT
:
1194 GLushort
*dst
= (GLushort
*) dstAddr
;
1195 switch (dstFormat
) {
1198 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1202 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1206 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1210 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1214 dst
[i
] = FLOAT_TO_USHORT(luminance
[i
]);
1216 case GL_LUMINANCE_ALPHA
:
1218 dst
[i
*2+0] = FLOAT_TO_USHORT(luminance
[i
]);
1219 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1224 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1225 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1226 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1231 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1232 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1233 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1234 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1239 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1240 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1241 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1246 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1247 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1248 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1249 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1254 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1255 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1256 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1257 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1261 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1263 if (dstPacking
->SwapBytes
) {
1264 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1270 GLshort
*dst
= (GLshort
*) dstAddr
;
1271 switch (dstFormat
) {
1274 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1278 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1282 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1286 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1290 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
1292 case GL_LUMINANCE_ALPHA
:
1294 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
1295 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1300 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1301 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1302 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1307 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1308 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1309 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1310 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1315 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1316 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1317 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1322 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1323 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1324 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1325 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1329 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1330 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1331 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1332 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1336 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1338 if (dstPacking
->SwapBytes
) {
1339 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1343 case GL_UNSIGNED_INT
:
1345 GLuint
*dst
= (GLuint
*) dstAddr
;
1346 switch (dstFormat
) {
1349 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1353 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1357 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1361 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1365 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
1367 case GL_LUMINANCE_ALPHA
:
1369 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
1370 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1375 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1376 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1377 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1382 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1383 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1384 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1385 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1390 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1391 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1392 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1397 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1398 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1399 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1400 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1405 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1406 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1407 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1408 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1412 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1414 if (dstPacking
->SwapBytes
) {
1415 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1421 GLint
*dst
= (GLint
*) dstAddr
;
1422 switch (dstFormat
) {
1425 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1429 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1433 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1437 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1441 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1443 case GL_LUMINANCE_ALPHA
:
1445 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1446 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1451 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1452 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1453 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1458 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1459 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1460 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1461 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1466 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1467 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1468 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1473 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1474 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1475 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1476 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1481 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1482 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1483 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1484 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1488 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1490 if (dstPacking
->SwapBytes
) {
1491 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1497 GLfloat
*dst
= (GLfloat
*) dstAddr
;
1498 switch (dstFormat
) {
1501 dst
[i
] = rgba
[i
][RCOMP
];
1505 dst
[i
] = rgba
[i
][GCOMP
];
1509 dst
[i
] = rgba
[i
][BCOMP
];
1513 dst
[i
] = rgba
[i
][ACOMP
];
1517 dst
[i
] = luminance
[i
];
1519 case GL_LUMINANCE_ALPHA
:
1521 dst
[i
*2+0] = luminance
[i
];
1522 dst
[i
*2+1] = rgba
[i
][ACOMP
];
1527 dst
[i
*3+0] = rgba
[i
][RCOMP
];
1528 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1529 dst
[i
*3+2] = rgba
[i
][BCOMP
];
1534 dst
[i
*4+0] = rgba
[i
][RCOMP
];
1535 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1536 dst
[i
*4+2] = rgba
[i
][BCOMP
];
1537 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1542 dst
[i
*3+0] = rgba
[i
][BCOMP
];
1543 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1544 dst
[i
*3+2] = rgba
[i
][RCOMP
];
1549 dst
[i
*4+0] = rgba
[i
][BCOMP
];
1550 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1551 dst
[i
*4+2] = rgba
[i
][RCOMP
];
1552 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1557 dst
[i
*4+0] = rgba
[i
][ACOMP
];
1558 dst
[i
*4+1] = rgba
[i
][BCOMP
];
1559 dst
[i
*4+2] = rgba
[i
][GCOMP
];
1560 dst
[i
*4+3] = rgba
[i
][RCOMP
];
1564 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1566 if (dstPacking
->SwapBytes
) {
1567 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1571 case GL_HALF_FLOAT_ARB
:
1573 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
1574 switch (dstFormat
) {
1577 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1581 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1585 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1589 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1593 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
1595 case GL_LUMINANCE_ALPHA
:
1597 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
1598 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1603 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1604 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1605 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1610 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1611 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1612 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1613 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1618 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1619 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1620 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1625 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1626 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1627 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1628 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1633 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1634 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1635 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1636 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1640 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1642 if (dstPacking
->SwapBytes
) {
1643 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1647 case GL_UNSIGNED_BYTE_3_3_2
:
1648 if (dstFormat
== GL_RGB
) {
1649 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1651 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
1652 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
1653 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
1657 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1658 if (dstFormat
== GL_RGB
) {
1659 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1661 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
1662 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
1663 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 5);
1667 case GL_UNSIGNED_SHORT_5_6_5
:
1668 if (dstFormat
== GL_RGB
) {
1669 GLushort
*dst
= (GLushort
*) dstAddr
;
1671 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1672 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1673 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
1677 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1678 if (dstFormat
== GL_RGB
) {
1679 GLushort
*dst
= (GLushort
*) dstAddr
;
1681 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1682 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1683 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
1687 case GL_UNSIGNED_SHORT_4_4_4_4
:
1688 if (dstFormat
== GL_RGBA
) {
1689 GLushort
*dst
= (GLushort
*) dstAddr
;
1691 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
1692 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1693 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1694 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1697 else if (dstFormat
== GL_BGRA
) {
1698 GLushort
*dst
= (GLushort
*) dstAddr
;
1700 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 12)
1701 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1702 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 4)
1703 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1706 else if (dstFormat
== GL_ABGR_EXT
) {
1707 GLushort
*dst
= (GLushort
*) dstAddr
;
1709 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 4)
1710 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1711 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 12)
1712 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) );
1716 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1717 if (dstFormat
== GL_RGBA
) {
1718 GLushort
*dst
= (GLushort
*) dstAddr
;
1720 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
1721 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1722 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1723 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1726 else if (dstFormat
== GL_BGRA
) {
1727 GLushort
*dst
= (GLushort
*) dstAddr
;
1729 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) )
1730 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1731 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 8)
1732 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1735 else if (dstFormat
== GL_ABGR_EXT
) {
1736 GLushort
*dst
= (GLushort
*) dstAddr
;
1738 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) )
1739 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1740 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1741 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12);
1745 case GL_UNSIGNED_SHORT_5_5_5_1
:
1746 if (dstFormat
== GL_RGBA
) {
1747 GLushort
*dst
= (GLushort
*) dstAddr
;
1749 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1750 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1751 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
1752 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1755 else if (dstFormat
== GL_BGRA
) {
1756 GLushort
*dst
= (GLushort
*) dstAddr
;
1758 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11)
1759 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1760 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 1)
1761 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1764 else if (dstFormat
== GL_ABGR_EXT
) {
1765 GLushort
*dst
= (GLushort
*) dstAddr
;
1767 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) << 11)
1768 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 6)
1769 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 1)
1770 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) );
1774 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1775 if (dstFormat
== GL_RGBA
) {
1776 GLushort
*dst
= (GLushort
*) dstAddr
;
1778 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1779 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1780 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
1781 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1784 else if (dstFormat
== GL_BGRA
) {
1785 GLushort
*dst
= (GLushort
*) dstAddr
;
1787 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) )
1788 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1789 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 10)
1790 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1793 else if (dstFormat
== GL_ABGR_EXT
) {
1794 GLushort
*dst
= (GLushort
*) dstAddr
;
1796 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) )
1797 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 5)
1798 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 10)
1799 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) << 15);
1803 case GL_UNSIGNED_INT_8_8_8_8
:
1804 if (dstFormat
== GL_RGBA
) {
1805 GLuint
*dst
= (GLuint
*) dstAddr
;
1807 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
1808 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1809 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1810 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1813 else if (dstFormat
== GL_BGRA
) {
1814 GLuint
*dst
= (GLuint
*) dstAddr
;
1816 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
1817 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1818 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
1819 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1822 else if (dstFormat
== GL_ABGR_EXT
) {
1823 GLuint
*dst
= (GLuint
*) dstAddr
;
1825 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
1826 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1827 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1828 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
1832 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1833 if (dstFormat
== GL_RGBA
) {
1834 GLuint
*dst
= (GLuint
*) dstAddr
;
1836 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
1837 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1838 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1839 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1842 else if (dstFormat
== GL_BGRA
) {
1843 GLuint
*dst
= (GLuint
*) dstAddr
;
1845 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
1846 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1847 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
1848 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1851 else if (dstFormat
== GL_ABGR_EXT
) {
1852 GLuint
*dst
= (GLuint
*) dstAddr
;
1854 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
1855 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1856 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1857 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
1861 case GL_UNSIGNED_INT_10_10_10_2
:
1862 if (dstFormat
== GL_RGBA
) {
1863 GLuint
*dst
= (GLuint
*) dstAddr
;
1865 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
1866 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1867 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
1868 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1871 else if (dstFormat
== GL_BGRA
) {
1872 GLuint
*dst
= (GLuint
*) dstAddr
;
1874 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
1875 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1876 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
1877 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1880 else if (dstFormat
== GL_ABGR_EXT
) {
1881 GLuint
*dst
= (GLuint
*) dstAddr
;
1883 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
1884 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
1885 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
1886 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
1890 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1891 if (dstFormat
== GL_RGBA
) {
1892 GLuint
*dst
= (GLuint
*) dstAddr
;
1894 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
1895 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1896 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
1897 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1900 else if (dstFormat
== GL_BGRA
) {
1901 GLuint
*dst
= (GLuint
*) dstAddr
;
1903 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
1904 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1905 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
1906 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1909 else if (dstFormat
== GL_ABGR_EXT
) {
1910 GLuint
*dst
= (GLuint
*) dstAddr
;
1912 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
1913 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
1914 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
1915 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
1920 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
1926 * Pack the given RGBA span into client memory at 'dest' address
1927 * in the given pixel format and type.
1928 * Optionally apply the enabled pixel transfer ops.
1929 * Pack into memory using the given packing params struct.
1930 * This is used by glReadPixels and glGetTexImage?D()
1931 * \param ctx - the context
1932 * n - number of pixels in the span
1934 * format - dest packing format
1935 * type - dest packing data type
1936 * destination - destination packing address
1937 * packing - pixel packing parameters
1938 * transferOps - bitmask of IMAGE_*_BIT operations to apply
1941 _mesa_pack_rgba_span_chan( GLcontext
*ctx
,
1942 GLuint n
, CONST GLchan srcRgba
[][4],
1943 GLenum dstFormat
, GLenum dstType
,
1945 const struct gl_pixelstore_attrib
*dstPacking
,
1948 ASSERT((ctx
->NewState
& _NEW_PIXEL
) == 0 || transferOps
== 0);
1950 /* Test for optimized case first */
1951 if (transferOps
== 0 && dstFormat
== GL_RGBA
&& dstType
== CHAN_TYPE
) {
1952 /* common simple case */
1953 MEMCPY(dstAddr
, srcRgba
, n
* 4 * sizeof(GLchan
));
1955 else if (transferOps
== 0 && dstFormat
== GL_RGB
&& dstType
== CHAN_TYPE
) {
1956 /* common simple case */
1958 GLchan
*dest
= (GLchan
*) dstAddr
;
1959 for (i
= 0; i
< n
; i
++) {
1960 dest
[0] = srcRgba
[i
][RCOMP
];
1961 dest
[1] = srcRgba
[i
][GCOMP
];
1962 dest
[2] = srcRgba
[i
][BCOMP
];
1966 else if (transferOps
== 0 && dstFormat
== GL_RGBA
&& dstType
== GL_UNSIGNED_BYTE
) {
1967 /* common simple case */
1969 GLubyte
*dest
= (GLubyte
*) dstAddr
;
1970 for (i
= 0; i
< n
; i
++) {
1971 dest
[0] = CHAN_TO_UBYTE(srcRgba
[i
][RCOMP
]);
1972 dest
[1] = CHAN_TO_UBYTE(srcRgba
[i
][GCOMP
]);
1973 dest
[2] = CHAN_TO_UBYTE(srcRgba
[i
][BCOMP
]);
1974 dest
[3] = CHAN_TO_UBYTE(srcRgba
[i
][ACOMP
]);
1979 /* general solution */
1981 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
1982 CHECKARRAY(rgba
, return); /* mac 32k limitation */
1984 assert(n
<= MAX_WIDTH
);
1985 /* convert color components to floating point */
1986 for (i
= 0; i
< n
; i
++) {
1987 rgba
[i
][RCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][RCOMP
]);
1988 rgba
[i
][GCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][GCOMP
]);
1989 rgba
[i
][BCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][BCOMP
]);
1990 rgba
[i
][ACOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][ACOMP
]);
1992 _mesa_pack_rgba_span_float(ctx
, n
, (const GLfloat (*)[4]) rgba
,
1993 dstFormat
, dstType
, dstAddr
,
1994 dstPacking
, transferOps
);
1995 UNDEFARRAY(rgba
); /* mac 32k limitation */
2000 #define SWAP2BYTE(VALUE) \
2002 GLubyte *bytes = (GLubyte *) &(VALUE); \
2003 GLubyte tmp = bytes[0]; \
2004 bytes[0] = bytes[1]; \
2008 #define SWAP4BYTE(VALUE) \
2010 GLubyte *bytes = (GLubyte *) &(VALUE); \
2011 GLubyte tmp = bytes[0]; \
2012 bytes[0] = bytes[3]; \
2015 bytes[1] = bytes[2]; \
2021 extract_uint_indexes(GLuint n
, GLuint indexes
[],
2022 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2023 const struct gl_pixelstore_attrib
*unpack
)
2025 assert(srcFormat
== GL_COLOR_INDEX
);
2027 ASSERT(srcType
== GL_BITMAP
||
2028 srcType
== GL_UNSIGNED_BYTE
||
2029 srcType
== GL_BYTE
||
2030 srcType
== GL_UNSIGNED_SHORT
||
2031 srcType
== GL_SHORT
||
2032 srcType
== GL_UNSIGNED_INT
||
2033 srcType
== GL_INT
||
2034 srcType
== GL_HALF_FLOAT_ARB
||
2035 srcType
== GL_FLOAT
);
2040 GLubyte
*ubsrc
= (GLubyte
*) src
;
2041 if (unpack
->LsbFirst
) {
2042 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
2044 for (i
= 0; i
< n
; i
++) {
2045 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2056 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
2058 for (i
= 0; i
< n
; i
++) {
2059 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2071 case GL_UNSIGNED_BYTE
:
2074 const GLubyte
*s
= (const GLubyte
*) src
;
2075 for (i
= 0; i
< n
; i
++)
2082 const GLbyte
*s
= (const GLbyte
*) src
;
2083 for (i
= 0; i
< n
; i
++)
2087 case GL_UNSIGNED_SHORT
:
2090 const GLushort
*s
= (const GLushort
*) src
;
2091 if (unpack
->SwapBytes
) {
2092 for (i
= 0; i
< n
; i
++) {
2093 GLushort value
= s
[i
];
2099 for (i
= 0; i
< n
; i
++)
2107 const GLshort
*s
= (const GLshort
*) src
;
2108 if (unpack
->SwapBytes
) {
2109 for (i
= 0; i
< n
; i
++) {
2110 GLshort value
= s
[i
];
2116 for (i
= 0; i
< n
; i
++)
2121 case GL_UNSIGNED_INT
:
2124 const GLuint
*s
= (const GLuint
*) src
;
2125 if (unpack
->SwapBytes
) {
2126 for (i
= 0; i
< n
; i
++) {
2127 GLuint value
= s
[i
];
2133 for (i
= 0; i
< n
; i
++)
2141 const GLint
*s
= (const GLint
*) src
;
2142 if (unpack
->SwapBytes
) {
2143 for (i
= 0; i
< n
; i
++) {
2150 for (i
= 0; i
< n
; i
++)
2158 const GLfloat
*s
= (const GLfloat
*) src
;
2159 if (unpack
->SwapBytes
) {
2160 for (i
= 0; i
< n
; i
++) {
2161 GLfloat value
= s
[i
];
2163 indexes
[i
] = (GLuint
) value
;
2167 for (i
= 0; i
< n
; i
++)
2168 indexes
[i
] = (GLuint
) s
[i
];
2172 case GL_HALF_FLOAT_ARB
:
2175 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
2176 if (unpack
->SwapBytes
) {
2177 for (i
= 0; i
< n
; i
++) {
2178 GLhalfARB value
= s
[i
];
2180 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
2184 for (i
= 0; i
< n
; i
++)
2185 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
2190 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2197 * This function extracts floating point RGBA values from arbitrary
2198 * image data. srcFormat and srcType are the format and type parameters
2199 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2201 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2202 * implements the "Conversion to floating point", "Conversion to RGB",
2203 * and "Final Expansion to RGBA" operations.
2205 * Args: n - number of pixels
2206 * rgba - output colors
2207 * srcFormat - format of incoming data
2208 * srcType - data type of incoming data
2209 * src - source data pointer
2210 * swapBytes - perform byteswapping of incoming data?
2213 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2214 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2215 GLboolean swapBytes
)
2217 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2219 GLint rComp
, bComp
, gComp
, aComp
;
2221 ASSERT(srcFormat
== GL_RED
||
2222 srcFormat
== GL_GREEN
||
2223 srcFormat
== GL_BLUE
||
2224 srcFormat
== GL_ALPHA
||
2225 srcFormat
== GL_LUMINANCE
||
2226 srcFormat
== GL_LUMINANCE_ALPHA
||
2227 srcFormat
== GL_INTENSITY
||
2228 srcFormat
== GL_RGB
||
2229 srcFormat
== GL_BGR
||
2230 srcFormat
== GL_RGBA
||
2231 srcFormat
== GL_BGRA
||
2232 srcFormat
== GL_ABGR_EXT
);
2234 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2235 srcType
== GL_BYTE
||
2236 srcType
== GL_UNSIGNED_SHORT
||
2237 srcType
== GL_SHORT
||
2238 srcType
== GL_UNSIGNED_INT
||
2239 srcType
== GL_INT
||
2240 srcType
== GL_HALF_FLOAT_ARB
||
2241 srcType
== GL_FLOAT
||
2242 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2243 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2244 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2245 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2246 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2247 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2248 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2249 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2250 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2251 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2252 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2253 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2255 rComp
= gComp
= bComp
= aComp
= -1;
2257 switch (srcFormat
) {
2260 greenIndex
= blueIndex
= alphaIndex
= -1;
2265 redIndex
= blueIndex
= alphaIndex
= -1;
2270 redIndex
= greenIndex
= alphaIndex
= -1;
2274 redIndex
= greenIndex
= blueIndex
= -1;
2279 redIndex
= greenIndex
= blueIndex
= 0;
2283 case GL_LUMINANCE_ALPHA
:
2284 redIndex
= greenIndex
= blueIndex
= 0;
2289 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
2348 _mesa_problem(NULL
, "bad srcFormat in extract float data");
2353 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
2354 if ((INDEX) < 0) { \
2356 for (i = 0; i < n; i++) { \
2357 rgba[i][CHANNEL] = DEFAULT; \
2360 else if (swapBytes) { \
2361 const TYPE *s = (const TYPE *) src; \
2363 for (i = 0; i < n; i++) { \
2364 TYPE value = s[INDEX]; \
2365 if (sizeof(TYPE) == 2) { \
2368 else if (sizeof(TYPE) == 4) { \
2371 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
2376 const TYPE *s = (const TYPE *) src; \
2378 for (i = 0; i < n; i++) { \
2379 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
2385 case GL_UNSIGNED_BYTE
:
2386 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2387 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2388 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2389 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2392 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2393 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2394 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2395 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
2397 case GL_UNSIGNED_SHORT
:
2398 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2399 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2400 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2401 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
2404 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2405 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2406 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2407 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
2409 case GL_UNSIGNED_INT
:
2410 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2411 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2412 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2413 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
2416 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2417 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2418 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2419 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
2422 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2423 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2424 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2425 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
2427 case GL_HALF_FLOAT_ARB
:
2428 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2429 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2430 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2431 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
2433 case GL_UNSIGNED_BYTE_3_3_2
:
2435 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2437 for (i
= 0; i
< n
; i
++) {
2438 GLubyte p
= ubsrc
[i
];
2439 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
2440 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
2441 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
2442 rgba
[i
][aComp
] = 1.0F
;
2446 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2448 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2450 for (i
= 0; i
< n
; i
++) {
2451 GLubyte p
= ubsrc
[i
];
2452 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
2453 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
2454 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
2455 rgba
[i
][aComp
] = 1.0F
;
2459 case GL_UNSIGNED_SHORT_5_6_5
:
2461 const GLushort
*ussrc
= (const GLushort
*) src
;
2463 for (i
= 0; i
< n
; i
++) {
2464 GLushort p
= ussrc
[i
];
2466 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2467 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2468 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2469 rgba
[i
][aComp
] = 1.0F
;
2473 const GLushort
*ussrc
= (const GLushort
*) src
;
2475 for (i
= 0; i
< n
; i
++) {
2476 GLushort p
= ussrc
[i
];
2477 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2478 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2479 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2480 rgba
[i
][aComp
] = 1.0F
;
2484 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2486 const GLushort
*ussrc
= (const GLushort
*) src
;
2488 for (i
= 0; i
< n
; i
++) {
2489 GLushort p
= ussrc
[i
];
2491 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2492 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2493 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2494 rgba
[i
][aComp
] = 1.0F
;
2498 const GLushort
*ussrc
= (const GLushort
*) src
;
2500 for (i
= 0; i
< n
; i
++) {
2501 GLushort p
= ussrc
[i
];
2502 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2503 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2504 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2505 rgba
[i
][aComp
] = 1.0F
;
2509 case GL_UNSIGNED_SHORT_4_4_4_4
:
2511 const GLushort
*ussrc
= (const GLushort
*) src
;
2513 for (i
= 0; i
< n
; i
++) {
2514 GLushort p
= ussrc
[i
];
2516 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2517 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2518 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2519 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2523 const GLushort
*ussrc
= (const GLushort
*) src
;
2525 for (i
= 0; i
< n
; i
++) {
2526 GLushort p
= ussrc
[i
];
2527 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2528 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2529 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2530 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2534 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2536 const GLushort
*ussrc
= (const GLushort
*) src
;
2538 for (i
= 0; i
< n
; i
++) {
2539 GLushort p
= ussrc
[i
];
2541 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2542 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2543 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2544 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2548 const GLushort
*ussrc
= (const GLushort
*) src
;
2550 for (i
= 0; i
< n
; i
++) {
2551 GLushort p
= ussrc
[i
];
2552 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2553 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2554 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2555 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2559 case GL_UNSIGNED_SHORT_5_5_5_1
:
2561 const GLushort
*ussrc
= (const GLushort
*) src
;
2563 for (i
= 0; i
< n
; i
++) {
2564 GLushort p
= ussrc
[i
];
2566 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2567 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2568 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2569 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2573 const GLushort
*ussrc
= (const GLushort
*) src
;
2575 for (i
= 0; i
< n
; i
++) {
2576 GLushort p
= ussrc
[i
];
2577 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2578 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2579 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2580 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2584 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2586 const GLushort
*ussrc
= (const GLushort
*) src
;
2588 for (i
= 0; i
< n
; i
++) {
2589 GLushort p
= ussrc
[i
];
2591 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2592 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2593 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2594 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2598 const GLushort
*ussrc
= (const GLushort
*) src
;
2600 for (i
= 0; i
< n
; i
++) {
2601 GLushort p
= ussrc
[i
];
2602 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2603 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2604 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2605 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2609 case GL_UNSIGNED_INT_8_8_8_8
:
2611 const GLuint
*uisrc
= (const GLuint
*) src
;
2613 for (i
= 0; i
< n
; i
++) {
2614 GLuint p
= uisrc
[i
];
2615 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2616 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2617 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2618 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2622 const GLuint
*uisrc
= (const GLuint
*) src
;
2624 for (i
= 0; i
< n
; i
++) {
2625 GLuint p
= uisrc
[i
];
2626 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2627 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2628 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2629 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2633 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2635 const GLuint
*uisrc
= (const GLuint
*) src
;
2637 for (i
= 0; i
< n
; i
++) {
2638 GLuint p
= uisrc
[i
];
2639 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2640 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2641 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2642 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2646 const GLuint
*uisrc
= (const GLuint
*) src
;
2648 for (i
= 0; i
< n
; i
++) {
2649 GLuint p
= uisrc
[i
];
2650 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2651 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2652 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2653 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2657 case GL_UNSIGNED_INT_10_10_10_2
:
2659 const GLuint
*uisrc
= (const GLuint
*) src
;
2661 for (i
= 0; i
< n
; i
++) {
2662 GLuint p
= uisrc
[i
];
2664 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2665 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2666 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2667 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2671 const GLuint
*uisrc
= (const GLuint
*) src
;
2673 for (i
= 0; i
< n
; i
++) {
2674 GLuint p
= uisrc
[i
];
2675 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2676 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2677 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2678 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2682 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2684 const GLuint
*uisrc
= (const GLuint
*) src
;
2686 for (i
= 0; i
< n
; i
++) {
2687 GLuint p
= uisrc
[i
];
2689 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2690 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2691 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2692 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2696 const GLuint
*uisrc
= (const GLuint
*) src
;
2698 for (i
= 0; i
< n
; i
++) {
2699 GLuint p
= uisrc
[i
];
2700 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2701 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2702 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2703 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2708 _mesa_problem(NULL
, "bad srcType in extract float data");
2715 * Unpack a row of color image data from a client buffer according to
2716 * the pixel unpacking parameters.
2717 * Return GLchan values in the specified dest image format.
2718 * This is used by glDrawPixels and glTexImage?D().
2719 * \param ctx - the context
2720 * n - number of pixels in the span
2721 * dstFormat - format of destination color array
2722 * dest - the destination color array
2723 * srcFormat - source image format
2724 * srcType - source image data type
2725 * source - source image pointer
2726 * srcPacking - pixel unpacking parameters
2727 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
2729 * XXX perhaps expand this to process whole images someday.
2732 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
2733 GLuint n
, GLenum dstFormat
, GLchan dest
[],
2734 GLenum srcFormat
, GLenum srcType
,
2735 const GLvoid
*source
,
2736 const struct gl_pixelstore_attrib
*srcPacking
,
2737 GLuint transferOps
)
2739 ASSERT(dstFormat
== GL_ALPHA
||
2740 dstFormat
== GL_LUMINANCE
||
2741 dstFormat
== GL_LUMINANCE_ALPHA
||
2742 dstFormat
== GL_INTENSITY
||
2743 dstFormat
== GL_RGB
||
2744 dstFormat
== GL_RGBA
||
2745 dstFormat
== GL_COLOR_INDEX
);
2747 ASSERT(srcFormat
== GL_RED
||
2748 srcFormat
== GL_GREEN
||
2749 srcFormat
== GL_BLUE
||
2750 srcFormat
== GL_ALPHA
||
2751 srcFormat
== GL_LUMINANCE
||
2752 srcFormat
== GL_LUMINANCE_ALPHA
||
2753 srcFormat
== GL_INTENSITY
||
2754 srcFormat
== GL_RGB
||
2755 srcFormat
== GL_BGR
||
2756 srcFormat
== GL_RGBA
||
2757 srcFormat
== GL_BGRA
||
2758 srcFormat
== GL_ABGR_EXT
||
2759 srcFormat
== GL_COLOR_INDEX
);
2761 ASSERT(srcType
== GL_BITMAP
||
2762 srcType
== GL_UNSIGNED_BYTE
||
2763 srcType
== GL_BYTE
||
2764 srcType
== GL_UNSIGNED_SHORT
||
2765 srcType
== GL_SHORT
||
2766 srcType
== GL_UNSIGNED_INT
||
2767 srcType
== GL_INT
||
2768 srcType
== GL_HALF_FLOAT_ARB
||
2769 srcType
== GL_FLOAT
||
2770 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2771 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2772 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2773 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2774 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2775 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2776 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2777 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2778 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2779 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2780 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2781 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2783 /* Try simple cases first */
2784 if (transferOps
== 0) {
2785 if (srcType
== CHAN_TYPE
) {
2786 if (dstFormat
== GL_RGBA
) {
2787 if (srcFormat
== GL_RGBA
) {
2788 MEMCPY( dest
, source
, n
* 4 * sizeof(GLchan
) );
2791 else if (srcFormat
== GL_RGB
) {
2793 const GLchan
*src
= (const GLchan
*) source
;
2795 for (i
= 0; i
< n
; i
++) {
2806 else if (dstFormat
== GL_RGB
) {
2807 if (srcFormat
== GL_RGB
) {
2808 MEMCPY( dest
, source
, n
* 3 * sizeof(GLchan
) );
2811 else if (srcFormat
== GL_RGBA
) {
2813 const GLchan
*src
= (const GLchan
*) source
;
2815 for (i
= 0; i
< n
; i
++) {
2825 else if (dstFormat
== srcFormat
) {
2826 GLint comps
= _mesa_components_in_format(srcFormat
);
2828 MEMCPY( dest
, source
, n
* comps
* sizeof(GLchan
) );
2833 * Common situation, loading 8bit RGBA/RGB source images
2834 * into 16/32 bit destination. (OSMesa16/32)
2836 else if (srcType
== GL_UNSIGNED_BYTE
) {
2837 if (dstFormat
== GL_RGBA
) {
2838 if (srcFormat
== GL_RGB
) {
2840 const GLubyte
*src
= (const GLubyte
*) source
;
2842 for (i
= 0; i
< n
; i
++) {
2843 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2844 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2845 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2852 else if (srcFormat
== GL_RGBA
) {
2854 const GLubyte
*src
= (const GLubyte
*) source
;
2856 for (i
= 0; i
< n
; i
++) {
2857 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2858 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2859 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2860 dst
[3] = UBYTE_TO_CHAN(src
[3]);
2867 else if (dstFormat
== GL_RGB
) {
2868 if (srcFormat
== GL_RGB
) {
2870 const GLubyte
*src
= (const GLubyte
*) source
;
2872 for (i
= 0; i
< n
; i
++) {
2873 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2874 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2875 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2881 else if (srcFormat
== GL_RGBA
) {
2883 const GLubyte
*src
= (const GLubyte
*) source
;
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]);
2899 /* general solution begins here */
2901 GLint dstComponents
;
2902 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2903 GLint dstLuminanceIndex
, dstIntensityIndex
;
2904 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
2905 CHECKARRAY(rgba
, return); /* mac 32k limitation */
2907 dstComponents
= _mesa_components_in_format( dstFormat
);
2908 /* source & dest image formats should have been error checked by now */
2909 assert(dstComponents
> 0);
2912 * Extract image data and convert to RGBA floats
2914 assert(n
<= MAX_WIDTH
);
2915 if (srcFormat
== GL_COLOR_INDEX
) {
2916 GLuint indexes
[MAX_WIDTH
];
2917 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2920 if (dstFormat
== GL_COLOR_INDEX
2921 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
2922 _mesa_map_ci(ctx
, n
, indexes
);
2924 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
2925 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2928 if (dstFormat
== GL_COLOR_INDEX
) {
2929 /* convert to GLchan and return */
2931 for (i
= 0; i
< n
; i
++) {
2932 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
2934 UNDEFARRAY(rgba
); /* mac 32k limitation */
2938 /* Convert indexes to RGBA */
2939 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
2942 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
2943 * with color indexes.
2945 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
2948 /* non-color index data */
2949 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2950 srcPacking
->SwapBytes
);
2953 /* Need to clamp if returning GLubytes or GLushorts */
2954 #if CHAN_TYPE != GL_FLOAT
2955 transferOps
|= IMAGE_CLAMP_BIT
;
2959 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
2962 /* Now determine which color channels we need to produce.
2963 * And determine the dest index (offset) within each color tuple.
2965 switch (dstFormat
) {
2968 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2969 dstLuminanceIndex
= dstIntensityIndex
= -1;
2972 dstLuminanceIndex
= 0;
2973 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2974 dstIntensityIndex
= -1;
2976 case GL_LUMINANCE_ALPHA
:
2977 dstLuminanceIndex
= 0;
2979 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2980 dstIntensityIndex
= -1;
2983 dstIntensityIndex
= 0;
2984 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2985 dstLuminanceIndex
= -1;
2991 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
2998 dstLuminanceIndex
= dstIntensityIndex
= -1;
3001 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
3002 UNDEFARRAY(rgba
); /* mac 32k limitation */
3007 /* Now return the GLchan data in the requested dstFormat */
3009 if (dstRedIndex
>= 0) {
3012 for (i
= 0; i
< n
; i
++) {
3013 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
3014 dst
+= dstComponents
;
3018 if (dstGreenIndex
>= 0) {
3021 for (i
= 0; i
< n
; i
++) {
3022 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
3023 dst
+= dstComponents
;
3027 if (dstBlueIndex
>= 0) {
3030 for (i
= 0; i
< n
; i
++) {
3031 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
3032 dst
+= dstComponents
;
3036 if (dstAlphaIndex
>= 0) {
3039 for (i
= 0; i
< n
; i
++) {
3040 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
3041 dst
+= dstComponents
;
3045 if (dstIntensityIndex
>= 0) {
3048 assert(dstIntensityIndex
== 0);
3049 assert(dstComponents
== 1);
3050 for (i
= 0; i
< n
; i
++) {
3051 /* Intensity comes from red channel */
3052 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
3056 if (dstLuminanceIndex
>= 0) {
3059 assert(dstLuminanceIndex
== 0);
3060 for (i
= 0; i
< n
; i
++) {
3061 /* Luminance comes from red channel */
3062 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
3063 dst
+= dstComponents
;
3066 UNDEFARRAY(rgba
); /* mac 32k limitation */
3072 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
3073 * instead of GLchan.
3076 _mesa_unpack_color_span_float( GLcontext
*ctx
,
3077 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
3078 GLenum srcFormat
, GLenum srcType
,
3079 const GLvoid
*source
,
3080 const struct gl_pixelstore_attrib
*srcPacking
,
3081 GLuint transferOps
)
3083 ASSERT(dstFormat
== GL_ALPHA
||
3084 dstFormat
== GL_LUMINANCE
||
3085 dstFormat
== GL_LUMINANCE_ALPHA
||
3086 dstFormat
== GL_INTENSITY
||
3087 dstFormat
== GL_RGB
||
3088 dstFormat
== GL_RGBA
||
3089 dstFormat
== GL_COLOR_INDEX
);
3091 ASSERT(srcFormat
== GL_RED
||
3092 srcFormat
== GL_GREEN
||
3093 srcFormat
== GL_BLUE
||
3094 srcFormat
== GL_ALPHA
||
3095 srcFormat
== GL_LUMINANCE
||
3096 srcFormat
== GL_LUMINANCE_ALPHA
||
3097 srcFormat
== GL_INTENSITY
||
3098 srcFormat
== GL_RGB
||
3099 srcFormat
== GL_BGR
||
3100 srcFormat
== GL_RGBA
||
3101 srcFormat
== GL_BGRA
||
3102 srcFormat
== GL_ABGR_EXT
||
3103 srcFormat
== GL_COLOR_INDEX
);
3105 ASSERT(srcType
== GL_BITMAP
||
3106 srcType
== GL_UNSIGNED_BYTE
||
3107 srcType
== GL_BYTE
||
3108 srcType
== GL_UNSIGNED_SHORT
||
3109 srcType
== GL_SHORT
||
3110 srcType
== GL_UNSIGNED_INT
||
3111 srcType
== GL_INT
||
3112 srcType
== GL_HALF_FLOAT_ARB
||
3113 srcType
== GL_FLOAT
||
3114 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3115 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3116 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3117 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3118 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3119 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3120 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3121 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3122 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3123 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3124 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3125 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3127 /* general solution, no special cases, yet */
3129 GLint dstComponents
;
3130 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3131 GLint dstLuminanceIndex
, dstIntensityIndex
;
3132 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
3133 CHECKARRAY(rgba
, return); /* mac 32k limitation */
3135 dstComponents
= _mesa_components_in_format( dstFormat
);
3136 /* source & dest image formats should have been error checked by now */
3137 assert(dstComponents
> 0);
3140 * Extract image data and convert to RGBA floats
3142 assert(n
<= MAX_WIDTH
);
3143 if (srcFormat
== GL_COLOR_INDEX
) {
3144 GLuint indexes
[MAX_WIDTH
];
3145 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3148 if (dstFormat
== GL_COLOR_INDEX
3149 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
3150 _mesa_map_ci(ctx
, n
, indexes
);
3152 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3153 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3156 if (dstFormat
== GL_COLOR_INDEX
) {
3157 /* convert to GLchan and return */
3159 for (i
= 0; i
< n
; i
++) {
3160 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3162 UNDEFARRAY(rgba
); /* mac 32k limitation */
3166 /* Convert indexes to RGBA */
3167 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3170 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3171 * with color indexes.
3173 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3176 /* non-color index data */
3177 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3178 srcPacking
->SwapBytes
);
3182 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3185 /* Now determine which color channels we need to produce.
3186 * And determine the dest index (offset) within each color tuple.
3188 switch (dstFormat
) {
3191 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3192 dstLuminanceIndex
= dstIntensityIndex
= -1;
3195 dstLuminanceIndex
= 0;
3196 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3197 dstIntensityIndex
= -1;
3199 case GL_LUMINANCE_ALPHA
:
3200 dstLuminanceIndex
= 0;
3202 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3203 dstIntensityIndex
= -1;
3206 dstIntensityIndex
= 0;
3207 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3208 dstLuminanceIndex
= -1;
3214 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3221 dstLuminanceIndex
= dstIntensityIndex
= -1;
3224 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
3225 UNDEFARRAY(rgba
); /* mac 32k limitation */
3229 /* Now pack results in the requested dstFormat */
3230 if (dstRedIndex
>= 0) {
3231 GLfloat
*dst
= dest
;
3233 for (i
= 0; i
< n
; i
++) {
3234 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3235 dst
+= dstComponents
;
3239 if (dstGreenIndex
>= 0) {
3240 GLfloat
*dst
= dest
;
3242 for (i
= 0; i
< n
; i
++) {
3243 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3244 dst
+= dstComponents
;
3248 if (dstBlueIndex
>= 0) {
3249 GLfloat
*dst
= dest
;
3251 for (i
= 0; i
< n
; i
++) {
3252 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3253 dst
+= dstComponents
;
3257 if (dstAlphaIndex
>= 0) {
3258 GLfloat
*dst
= dest
;
3260 for (i
= 0; i
< n
; i
++) {
3261 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3262 dst
+= dstComponents
;
3266 if (dstIntensityIndex
>= 0) {
3267 GLfloat
*dst
= dest
;
3269 assert(dstIntensityIndex
== 0);
3270 assert(dstComponents
== 1);
3271 for (i
= 0; i
< n
; i
++) {
3272 /* Intensity comes from red channel */
3273 dst
[i
] = rgba
[i
][RCOMP
];
3277 if (dstLuminanceIndex
>= 0) {
3278 GLfloat
*dst
= dest
;
3280 assert(dstLuminanceIndex
== 0);
3281 for (i
= 0; i
< n
; i
++) {
3282 /* Luminance comes from red channel */
3283 dst
[0] = rgba
[i
][RCOMP
];
3284 dst
+= dstComponents
;
3287 UNDEFARRAY(rgba
); /* mac 32k limitation */
3293 * Unpack a row of color index data from a client buffer according to
3294 * the pixel unpacking parameters.
3295 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
3297 * Args: ctx - the context
3298 * n - number of pixels
3299 * dstType - destination data type
3300 * dest - destination array
3301 * srcType - source pixel type
3302 * source - source data pointer
3303 * srcPacking - pixel unpacking parameters
3304 * transferOps - the pixel transfer operations to apply
3307 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
3308 GLenum dstType
, GLvoid
*dest
,
3309 GLenum srcType
, const GLvoid
*source
,
3310 const struct gl_pixelstore_attrib
*srcPacking
,
3311 GLuint transferOps
)
3313 ASSERT(srcType
== GL_BITMAP
||
3314 srcType
== GL_UNSIGNED_BYTE
||
3315 srcType
== GL_BYTE
||
3316 srcType
== GL_UNSIGNED_SHORT
||
3317 srcType
== GL_SHORT
||
3318 srcType
== GL_UNSIGNED_INT
||
3319 srcType
== GL_INT
||
3320 srcType
== GL_HALF_FLOAT_ARB
||
3321 srcType
== GL_FLOAT
);
3323 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3324 dstType
== GL_UNSIGNED_SHORT
||
3325 dstType
== GL_UNSIGNED_INT
);
3328 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3331 * Try simple cases first
3333 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
3334 && dstType
== GL_UNSIGNED_BYTE
) {
3335 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
3337 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
3338 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
3339 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
3345 GLuint indexes
[MAX_WIDTH
];
3346 assert(n
<= MAX_WIDTH
);
3348 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3351 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3352 /* shift and offset indexes */
3353 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3355 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3356 /* Apply lookup table */
3357 _mesa_map_ci(ctx
, n
, indexes
);
3360 /* convert to dest type */
3362 case GL_UNSIGNED_BYTE
:
3364 GLubyte
*dst
= (GLubyte
*) dest
;
3366 for (i
= 0; i
< n
; i
++) {
3367 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3371 case GL_UNSIGNED_SHORT
:
3373 GLuint
*dst
= (GLuint
*) dest
;
3375 for (i
= 0; i
< n
; i
++) {
3376 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3380 case GL_UNSIGNED_INT
:
3381 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
3384 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
3391 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
3392 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
3393 const struct gl_pixelstore_attrib
*dstPacking
,
3394 GLuint transferOps
)
3396 GLuint indexes
[MAX_WIDTH
];
3398 ASSERT(n
<= MAX_WIDTH
);
3400 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3402 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
3403 /* make a copy of input */
3404 MEMCPY(indexes
, source
, n
* sizeof(GLuint
));
3405 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3406 _mesa_shift_and_offset_ci( ctx
, n
, indexes
);
3408 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3409 _mesa_map_ci(ctx
, n
, indexes
);
3415 case GL_UNSIGNED_BYTE
:
3417 GLubyte
*dst
= (GLubyte
*) dest
;
3419 for (i
= 0; i
< n
; i
++) {
3420 *dst
++ = (GLubyte
) source
[i
];
3426 GLbyte
*dst
= (GLbyte
*) dest
;
3428 for (i
= 0; i
< n
; i
++) {
3429 dst
[i
] = (GLbyte
) source
[i
];
3433 case GL_UNSIGNED_SHORT
:
3435 GLushort
*dst
= (GLushort
*) dest
;
3437 for (i
= 0; i
< n
; i
++) {
3438 dst
[i
] = (GLushort
) source
[i
];
3440 if (dstPacking
->SwapBytes
) {
3441 _mesa_swap2( (GLushort
*) dst
, n
);
3447 GLshort
*dst
= (GLshort
*) dest
;
3449 for (i
= 0; i
< n
; i
++) {
3450 dst
[i
] = (GLshort
) source
[i
];
3452 if (dstPacking
->SwapBytes
) {
3453 _mesa_swap2( (GLushort
*) dst
, n
);
3457 case GL_UNSIGNED_INT
:
3459 GLuint
*dst
= (GLuint
*) dest
;
3461 for (i
= 0; i
< n
; i
++) {
3462 dst
[i
] = (GLuint
) source
[i
];
3464 if (dstPacking
->SwapBytes
) {
3465 _mesa_swap4( (GLuint
*) dst
, n
);
3471 GLint
*dst
= (GLint
*) dest
;
3473 for (i
= 0; i
< n
; i
++) {
3474 dst
[i
] = (GLint
) source
[i
];
3476 if (dstPacking
->SwapBytes
) {
3477 _mesa_swap4( (GLuint
*) dst
, n
);
3483 GLfloat
*dst
= (GLfloat
*) dest
;
3485 for (i
= 0; i
< n
; i
++) {
3486 dst
[i
] = (GLfloat
) source
[i
];
3488 if (dstPacking
->SwapBytes
) {
3489 _mesa_swap4( (GLuint
*) dst
, n
);
3493 case GL_HALF_FLOAT_ARB
:
3495 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
3497 for (i
= 0; i
< n
; i
++) {
3498 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
3500 if (dstPacking
->SwapBytes
) {
3501 _mesa_swap2( (GLushort
*) dst
, n
);
3506 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3512 * Unpack a row of stencil data from a client buffer according to
3513 * the pixel unpacking parameters.
3514 * This is (or will be) used by glDrawPixels
3516 * Args: ctx - the context
3517 * n - number of pixels
3518 * dstType - destination data type
3519 * dest - destination array
3520 * srcType - source pixel type
3521 * source - source data pointer
3522 * srcPacking - pixel unpacking parameters
3523 * transferOps - apply offset/bias/lookup ops?
3526 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3527 GLenum dstType
, GLvoid
*dest
,
3528 GLenum srcType
, const GLvoid
*source
,
3529 const struct gl_pixelstore_attrib
*srcPacking
,
3530 GLuint transferOps
)
3532 ASSERT(srcType
== GL_BITMAP
||
3533 srcType
== GL_UNSIGNED_BYTE
||
3534 srcType
== GL_BYTE
||
3535 srcType
== GL_UNSIGNED_SHORT
||
3536 srcType
== GL_SHORT
||
3537 srcType
== GL_UNSIGNED_INT
||
3538 srcType
== GL_INT
||
3539 srcType
== GL_HALF_FLOAT_ARB
||
3540 srcType
== GL_FLOAT
);
3542 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3543 dstType
== GL_UNSIGNED_SHORT
||
3544 dstType
== GL_UNSIGNED_INT
);
3546 /* only shift and offset apply to stencil */
3547 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
3550 * Try simple cases first
3552 if (transferOps
== 0 &&
3553 srcType
== GL_UNSIGNED_BYTE
&&
3554 dstType
== GL_UNSIGNED_BYTE
) {
3555 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
3557 else if (transferOps
== 0 &&
3558 srcType
== GL_UNSIGNED_INT
&&
3559 dstType
== GL_UNSIGNED_INT
&&
3560 !srcPacking
->SwapBytes
) {
3561 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
3567 GLuint indexes
[MAX_WIDTH
];
3568 assert(n
<= MAX_WIDTH
);
3570 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3574 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3575 /* shift and offset indexes */
3576 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3579 if (ctx
->Pixel
.MapStencilFlag
) {
3580 /* Apply stencil lookup table */
3581 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
3584 indexes
[i
] = ctx
->Pixel
.MapStoS
[ indexes
[i
] & mask
];
3589 /* convert to dest type */
3591 case GL_UNSIGNED_BYTE
:
3593 GLubyte
*dst
= (GLubyte
*) dest
;
3595 for (i
= 0; i
< n
; i
++) {
3596 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3600 case GL_UNSIGNED_SHORT
:
3602 GLuint
*dst
= (GLuint
*) dest
;
3604 for (i
= 0; i
< n
; i
++) {
3605 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3609 case GL_UNSIGNED_INT
:
3610 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
3613 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
3620 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3621 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
3622 const struct gl_pixelstore_attrib
*dstPacking
)
3624 GLstencil stencil
[MAX_WIDTH
];
3626 ASSERT(n
<= MAX_WIDTH
);
3628 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
3629 ctx
->Pixel
.MapStencilFlag
) {
3630 /* make a copy of input */
3631 MEMCPY(stencil
, source
, n
* sizeof(GLstencil
));
3632 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
3633 _mesa_shift_and_offset_stencil( ctx
, n
, stencil
);
3635 if (ctx
->Pixel
.MapStencilFlag
) {
3636 _mesa_map_stencil( ctx
, n
, stencil
);
3642 case GL_UNSIGNED_BYTE
:
3643 if (sizeof(GLstencil
) == 8) {
3644 MEMCPY( dest
, source
, n
);
3647 GLubyte
*dst
= (GLubyte
*) dest
;
3650 dst
[i
] = (GLubyte
) source
[i
];
3655 if (sizeof(GLstencil
) == 8) {
3656 MEMCPY( dest
, source
, n
);
3659 GLbyte
*dst
= (GLbyte
*) dest
;
3662 dst
[i
] = (GLbyte
) source
[i
];
3666 case GL_UNSIGNED_SHORT
:
3668 GLushort
*dst
= (GLushort
*) dest
;
3671 dst
[i
] = (GLushort
) source
[i
];
3673 if (dstPacking
->SwapBytes
) {
3674 _mesa_swap2( (GLushort
*) dst
, n
);
3680 GLshort
*dst
= (GLshort
*) dest
;
3683 dst
[i
] = (GLshort
) source
[i
];
3685 if (dstPacking
->SwapBytes
) {
3686 _mesa_swap2( (GLushort
*) dst
, n
);
3690 case GL_UNSIGNED_INT
:
3692 GLuint
*dst
= (GLuint
*) dest
;
3695 dst
[i
] = (GLuint
) source
[i
];
3697 if (dstPacking
->SwapBytes
) {
3698 _mesa_swap4( (GLuint
*) dst
, n
);
3704 GLint
*dst
= (GLint
*) dest
;
3707 *dst
++ = (GLint
) source
[i
];
3709 if (dstPacking
->SwapBytes
) {
3710 _mesa_swap4( (GLuint
*) dst
, n
);
3716 GLfloat
*dst
= (GLfloat
*) dest
;
3719 dst
[i
] = (GLfloat
) source
[i
];
3721 if (dstPacking
->SwapBytes
) {
3722 _mesa_swap4( (GLuint
*) dst
, n
);
3726 case GL_HALF_FLOAT_ARB
:
3728 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
3731 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
3733 if (dstPacking
->SwapBytes
) {
3734 _mesa_swap2( (GLushort
*) dst
, n
);
3739 if (dstPacking
->LsbFirst
) {
3740 GLubyte
*dst
= (GLubyte
*) dest
;
3743 for (i
= 0; i
< n
; i
++) {
3746 *dst
|= ((source
[i
] != 0) << shift
);
3755 GLubyte
*dst
= (GLubyte
*) dest
;
3758 for (i
= 0; i
< n
; i
++) {
3761 *dst
|= ((source
[i
] != 0) << shift
);
3771 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3777 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
, GLfloat
*dest
,
3778 GLenum srcType
, const GLvoid
*source
,
3779 const struct gl_pixelstore_attrib
*srcPacking
)
3787 const GLubyte
*src
= (const GLubyte
*) source
;
3788 for (i
= 0; i
< n
; i
++) {
3789 dest
[i
] = BYTE_TO_FLOAT(src
[i
]);
3793 case GL_UNSIGNED_BYTE
:
3796 const GLubyte
*src
= (const GLubyte
*) source
;
3797 for (i
= 0; i
< n
; i
++) {
3798 dest
[i
] = UBYTE_TO_FLOAT(src
[i
]);
3805 const GLshort
*src
= (const GLshort
*) source
;
3806 for (i
= 0; i
< n
; i
++) {
3807 dest
[i
] = SHORT_TO_FLOAT(src
[i
]);
3811 case GL_UNSIGNED_SHORT
:
3814 const GLushort
*src
= (const GLushort
*) source
;
3815 for (i
= 0; i
< n
; i
++) {
3816 dest
[i
] = USHORT_TO_FLOAT(src
[i
]);
3823 const GLint
*src
= (const GLint
*) source
;
3824 for (i
= 0; i
< n
; i
++) {
3825 dest
[i
] = INT_TO_FLOAT(src
[i
]);
3829 case GL_UNSIGNED_INT
:
3832 const GLuint
*src
= (const GLuint
*) source
;
3833 for (i
= 0; i
< n
; i
++) {
3834 dest
[i
] = UINT_TO_FLOAT(src
[i
]);
3839 MEMCPY(dest
, source
, n
* sizeof(GLfloat
));
3841 case GL_HALF_FLOAT_ARB
:
3844 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
3845 for (i
= 0; i
< n
; i
++) {
3846 dest
[i
] = _mesa_half_to_float(src
[i
]);
3851 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
3856 /* apply depth scale and bias and clamp to [0,1] */
3857 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
3859 for (i
= 0; i
< n
; i
++) {
3860 GLfloat d
= dest
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
3861 dest
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
3868 * Pack an array of depth values. The values are floats in [0,1].
3871 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
3872 GLenum dstType
, const GLfloat
*depthSpan
,
3873 const struct gl_pixelstore_attrib
*dstPacking
)
3875 GLfloat depthCopy
[MAX_WIDTH
];
3876 const GLboolean bias_or_scale
= ctx
->Pixel
.DepthBias
!= 0.0 ||
3877 ctx
->Pixel
.DepthScale
!= 1.0;
3879 ASSERT(n
<= MAX_WIDTH
);
3881 if (bias_or_scale
) {
3883 for (i
= 0; i
< n
; i
++) {
3885 d
= depthSpan
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
3886 depthCopy
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
3888 depthSpan
= depthCopy
;
3892 case GL_UNSIGNED_BYTE
:
3894 GLubyte
*dst
= (GLubyte
*) dest
;
3896 for (i
= 0; i
< n
; i
++) {
3897 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
3903 GLbyte
*dst
= (GLbyte
*) dest
;
3905 for (i
= 0; i
< n
; i
++) {
3906 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
3910 case GL_UNSIGNED_SHORT
:
3912 GLushort
*dst
= (GLushort
*) dest
;
3914 for (i
= 0; i
< n
; i
++) {
3915 dst
[i
] = FLOAT_TO_USHORT( depthSpan
[i
] );
3917 if (dstPacking
->SwapBytes
) {
3918 _mesa_swap2( (GLushort
*) dst
, n
);
3924 GLshort
*dst
= (GLshort
*) dest
;
3926 for (i
= 0; i
< n
; i
++) {
3927 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
3929 if (dstPacking
->SwapBytes
) {
3930 _mesa_swap2( (GLushort
*) dst
, n
);
3934 case GL_UNSIGNED_INT
:
3936 GLuint
*dst
= (GLuint
*) dest
;
3938 for (i
= 0; i
< n
; i
++) {
3939 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
3941 if (dstPacking
->SwapBytes
) {
3942 _mesa_swap4( (GLuint
*) dst
, n
);
3948 GLint
*dst
= (GLint
*) dest
;
3950 for (i
= 0; i
< n
; i
++) {
3951 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
3953 if (dstPacking
->SwapBytes
) {
3954 _mesa_swap4( (GLuint
*) dst
, n
);
3960 GLfloat
*dst
= (GLfloat
*) dest
;
3962 for (i
= 0; i
< n
; i
++) {
3963 dst
[i
] = depthSpan
[i
];
3965 if (dstPacking
->SwapBytes
) {
3966 _mesa_swap4( (GLuint
*) dst
, n
);
3970 case GL_HALF_FLOAT_ARB
:
3972 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
3974 for (i
= 0; i
< n
; i
++) {
3975 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
3977 if (dstPacking
->SwapBytes
) {
3978 _mesa_swap2( (GLushort
*) dst
, n
);
3983 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
3989 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
3990 * Return all image data in a contiguous block. This is used when we
3991 * compile glDrawPixels, glTexImage, etc into a display list. We
3992 * need a copy of the data in a standard format.
3995 _mesa_unpack_image( GLsizei width
, GLsizei height
, GLsizei depth
,
3996 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3997 const struct gl_pixelstore_attrib
*unpack
)
3999 GLint bytesPerRow
, compsPerRow
;
4000 GLboolean flipBytes
, swap2
, swap4
;
4003 return NULL
; /* not necessarily an error */
4005 if (width
<= 0 || height
<= 0 || depth
<= 0)
4006 return NULL
; /* generate error later */
4008 if (format
== GL_BITMAP
) {
4009 bytesPerRow
= (width
+ 7) >> 3;
4010 flipBytes
= !unpack
->LsbFirst
;
4011 swap2
= swap4
= GL_FALSE
;
4015 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
4016 const GLint components
= _mesa_components_in_format(format
);
4018 if (bytesPerPixel
<= 0 || components
<= 0)
4019 return NULL
; /* bad format or type. generate error later */
4020 bytesPerRow
= bytesPerPixel
* width
;
4021 bytesPerComp
= bytesPerPixel
/ components
;
4022 flipBytes
= GL_FALSE
;
4023 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
4024 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
4025 compsPerRow
= components
* width
;
4026 assert(compsPerRow
>= width
);
4030 GLubyte
*destBuffer
= (GLubyte
*) MALLOC(bytesPerRow
* height
* depth
);
4034 return NULL
; /* generate GL_OUT_OF_MEMORY later */
4037 for (img
= 0; img
< depth
; img
++) {
4038 for (row
= 0; row
< height
; row
++) {
4039 const GLvoid
*src
= _mesa_image_address(unpack
, pixels
,
4040 width
, height
, format
, type
, img
, row
, 0);
4041 MEMCPY(dst
, src
, bytesPerRow
);
4042 /* byte flipping/swapping */
4044 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
4047 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
4050 _mesa_swap4((GLuint
*) dst
, compsPerRow
);