2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 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.
43 * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
44 * we later convert the float to a packed integer value (such as for
45 * GL_RGB5_A1) because we'll wind up with a non-zero value.
47 * We redefine the macros here so zero is handled correctly.
50 #define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
53 #define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
57 /** Compute ceiling of integer quotient of A divided by B. */
58 #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
62 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
65 _mesa_type_is_packed(GLenum type
)
68 case GL_UNSIGNED_BYTE_3_3_2
:
69 case GL_UNSIGNED_BYTE_2_3_3_REV
:
70 case GL_UNSIGNED_SHORT_5_6_5
:
71 case GL_UNSIGNED_SHORT_5_6_5_REV
:
72 case GL_UNSIGNED_SHORT_4_4_4_4
:
73 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
74 case GL_UNSIGNED_SHORT_5_5_5_1
:
75 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
76 case GL_UNSIGNED_INT_8_8_8_8
:
77 case GL_UNSIGNED_INT_8_8_8_8_REV
:
78 case GL_UNSIGNED_INT_10_10_10_2
:
79 case GL_UNSIGNED_INT_2_10_10_10_REV
:
80 case GL_UNSIGNED_SHORT_8_8_MESA
:
81 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
82 case GL_UNSIGNED_INT_24_8_EXT
:
90 * Flip the 8 bits in each byte of the given array.
93 * \param n number of bytes.
95 * \todo try this trick to flip bytes someday:
97 * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555);
98 * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333);
99 * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f);
103 flip_bytes( GLubyte
*p
, GLuint n
)
106 for (i
= 0; i
< n
; i
++) {
107 b
= (GLuint
) p
[i
]; /* words are often faster than bytes */
108 a
= ((b
& 0x01) << 7) |
122 * Flip the order of the 2 bytes in each word in the given array.
125 * \param n number of words.
128 _mesa_swap2( GLushort
*p
, GLuint n
)
131 for (i
= 0; i
< n
; i
++) {
132 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
139 * Flip the order of the 4 bytes in each word in the given array.
142 _mesa_swap4( GLuint
*p
, GLuint n
)
145 for (i
= 0; i
< n
; i
++) {
148 | ((b
>> 8) & 0xff00)
149 | ((b
<< 8) & 0xff0000)
150 | ((b
<< 24) & 0xff000000);
157 * Get the size of a GL data type.
159 * \param type GL data type.
161 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
162 * if an invalid type enum.
165 _mesa_sizeof_type( GLenum type
)
170 case GL_UNSIGNED_BYTE
:
171 return sizeof(GLubyte
);
173 return sizeof(GLbyte
);
174 case GL_UNSIGNED_SHORT
:
175 return sizeof(GLushort
);
177 return sizeof(GLshort
);
178 case GL_UNSIGNED_INT
:
179 return sizeof(GLuint
);
181 return sizeof(GLint
);
183 return sizeof(GLfloat
);
184 case GL_HALF_FLOAT_ARB
:
185 return sizeof(GLhalfARB
);
193 * Same as _mesa_sizeof_type() but also accepting the packed pixel
197 _mesa_sizeof_packed_type( GLenum type
)
202 case GL_UNSIGNED_BYTE
:
203 return sizeof(GLubyte
);
205 return sizeof(GLbyte
);
206 case GL_UNSIGNED_SHORT
:
207 return sizeof(GLushort
);
209 return sizeof(GLshort
);
210 case GL_UNSIGNED_INT
:
211 return sizeof(GLuint
);
213 return sizeof(GLint
);
214 case GL_HALF_FLOAT_ARB
:
215 return sizeof(GLhalfARB
);
217 return sizeof(GLfloat
);
218 case GL_UNSIGNED_BYTE_3_3_2
:
219 return sizeof(GLubyte
);
220 case GL_UNSIGNED_BYTE_2_3_3_REV
:
221 return sizeof(GLubyte
);
222 case GL_UNSIGNED_SHORT_5_6_5
:
223 return sizeof(GLushort
);
224 case GL_UNSIGNED_SHORT_5_6_5_REV
:
225 return sizeof(GLushort
);
226 case GL_UNSIGNED_SHORT_4_4_4_4
:
227 return sizeof(GLushort
);
228 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
229 return sizeof(GLushort
);
230 case GL_UNSIGNED_SHORT_5_5_5_1
:
231 return sizeof(GLushort
);
232 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
233 return sizeof(GLushort
);
234 case GL_UNSIGNED_INT_8_8_8_8
:
235 return sizeof(GLuint
);
236 case GL_UNSIGNED_INT_8_8_8_8_REV
:
237 return sizeof(GLuint
);
238 case GL_UNSIGNED_INT_10_10_10_2
:
239 return sizeof(GLuint
);
240 case GL_UNSIGNED_INT_2_10_10_10_REV
:
241 return sizeof(GLuint
);
242 case GL_UNSIGNED_SHORT_8_8_MESA
:
243 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
244 return sizeof(GLushort
);
245 case GL_UNSIGNED_INT_24_8_EXT
:
246 return sizeof(GLuint
);
254 * Get the number of components in a pixel format.
256 * \param format pixel format.
258 * \return the number of components in the given format, or -1 if a bad format.
261 _mesa_components_in_format( GLenum format
)
265 case GL_COLOR_INDEX1_EXT
:
266 case GL_COLOR_INDEX2_EXT
:
267 case GL_COLOR_INDEX4_EXT
:
268 case GL_COLOR_INDEX8_EXT
:
269 case GL_COLOR_INDEX12_EXT
:
270 case GL_COLOR_INDEX16_EXT
:
271 case GL_STENCIL_INDEX
:
272 case GL_DEPTH_COMPONENT
:
280 case GL_LUMINANCE_ALPHA
:
294 case GL_DEPTH_STENCIL_EXT
:
306 * Get the bytes per pixel of pixel format type pair.
308 * \param format pixel format.
309 * \param type pixel type.
311 * \return bytes per pixel, or -1 if a bad format or type was given.
314 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
316 GLint comps
= _mesa_components_in_format( format
);
322 return 0; /* special case */
324 case GL_UNSIGNED_BYTE
:
325 return comps
* sizeof(GLubyte
);
327 case GL_UNSIGNED_SHORT
:
328 return comps
* sizeof(GLshort
);
330 case GL_UNSIGNED_INT
:
331 return comps
* sizeof(GLint
);
333 return comps
* sizeof(GLfloat
);
334 case GL_HALF_FLOAT_ARB
:
335 return comps
* sizeof(GLhalfARB
);
336 case GL_UNSIGNED_BYTE_3_3_2
:
337 case GL_UNSIGNED_BYTE_2_3_3_REV
:
338 if (format
== GL_RGB
|| format
== GL_BGR
)
339 return sizeof(GLubyte
);
341 return -1; /* error */
342 case GL_UNSIGNED_SHORT_5_6_5
:
343 case GL_UNSIGNED_SHORT_5_6_5_REV
:
344 if (format
== GL_RGB
|| format
== GL_BGR
)
345 return sizeof(GLushort
);
347 return -1; /* error */
348 case GL_UNSIGNED_SHORT_4_4_4_4
:
349 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
350 case GL_UNSIGNED_SHORT_5_5_5_1
:
351 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
352 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
353 return sizeof(GLushort
);
356 case GL_UNSIGNED_INT_8_8_8_8
:
357 case GL_UNSIGNED_INT_8_8_8_8_REV
:
358 case GL_UNSIGNED_INT_10_10_10_2
:
359 case GL_UNSIGNED_INT_2_10_10_10_REV
:
360 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
361 return sizeof(GLuint
);
364 case GL_UNSIGNED_SHORT_8_8_MESA
:
365 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
366 if (format
== GL_YCBCR_MESA
)
367 return sizeof(GLushort
);
370 case GL_UNSIGNED_INT_24_8_EXT
:
371 if (format
== GL_DEPTH_STENCIL_EXT
)
372 return sizeof(GLuint
);
382 * Test for a legal pixel format and type.
384 * \param format pixel format.
385 * \param type pixel type.
387 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
391 _mesa_is_legal_format_and_type( GLcontext
*ctx
, GLenum format
, GLenum type
)
395 case GL_STENCIL_INDEX
:
399 case GL_UNSIGNED_BYTE
:
401 case GL_UNSIGNED_SHORT
:
403 case GL_UNSIGNED_INT
:
406 case GL_HALF_FLOAT_ARB
:
407 return ctx
->Extensions
.ARB_half_float_pixel
;
415 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
419 case GL_LUMINANCE_ALPHA
:
420 case GL_DEPTH_COMPONENT
:
423 case GL_UNSIGNED_BYTE
:
425 case GL_UNSIGNED_SHORT
:
427 case GL_UNSIGNED_INT
:
430 case GL_HALF_FLOAT_ARB
:
431 return ctx
->Extensions
.ARB_half_float_pixel
;
438 case GL_UNSIGNED_BYTE
:
440 case GL_UNSIGNED_SHORT
:
442 case GL_UNSIGNED_INT
:
444 case GL_UNSIGNED_BYTE_3_3_2
:
445 case GL_UNSIGNED_BYTE_2_3_3_REV
:
446 case GL_UNSIGNED_SHORT_5_6_5
:
447 case GL_UNSIGNED_SHORT_5_6_5_REV
:
449 case GL_HALF_FLOAT_ARB
:
450 return ctx
->Extensions
.ARB_half_float_pixel
;
456 /* NOTE: no packed types are supported with BGR. That's
457 * intentional, according to the GL spec.
460 case GL_UNSIGNED_BYTE
:
462 case GL_UNSIGNED_SHORT
:
464 case GL_UNSIGNED_INT
:
467 case GL_HALF_FLOAT_ARB
:
468 return ctx
->Extensions
.ARB_half_float_pixel
;
477 case GL_UNSIGNED_BYTE
:
479 case GL_UNSIGNED_SHORT
:
481 case GL_UNSIGNED_INT
:
483 case GL_UNSIGNED_SHORT_4_4_4_4
:
484 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
485 case GL_UNSIGNED_SHORT_5_5_5_1
:
486 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
487 case GL_UNSIGNED_INT_8_8_8_8
:
488 case GL_UNSIGNED_INT_8_8_8_8_REV
:
489 case GL_UNSIGNED_INT_10_10_10_2
:
490 case GL_UNSIGNED_INT_2_10_10_10_REV
:
492 case GL_HALF_FLOAT_ARB
:
493 return ctx
->Extensions
.ARB_half_float_pixel
;
498 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
499 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
503 case GL_DEPTH_STENCIL_EXT
:
504 if (ctx
->Extensions
.EXT_packed_depth_stencil
505 && type
== GL_UNSIGNED_INT_24_8_EXT
)
513 case GL_UNSIGNED_BYTE
:
515 case GL_UNSIGNED_SHORT
:
517 case GL_UNSIGNED_INT
:
531 * Return the address of a specific pixel in an image (1D, 2D or 3D).
533 * Pixel unpacking/packing parameters are observed according to \p packing.
535 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
536 * \param image starting address of image data
537 * \param width the image width
538 * \param height theimage height
539 * \param format the pixel format
540 * \param type the pixel data type
541 * \param packing the pixelstore attributes
542 * \param img which image in the volume (0 for 1D or 2D images)
543 * \param row row of pixel in the image (0 for 1D images)
544 * \param column column of pixel in the image
546 * \return address of pixel on success, or NULL on error.
548 * \sa gl_pixelstore_attrib.
551 _mesa_image_address( GLuint dimensions
,
552 const struct gl_pixelstore_attrib
*packing
,
554 GLsizei width
, GLsizei height
,
555 GLenum format
, GLenum type
,
556 GLint img
, GLint row
, GLint column
)
558 GLint alignment
; /* 1, 2 or 4 */
559 GLint pixels_per_row
;
560 GLint rows_per_image
;
563 GLint skipimages
; /* for 3-D volume images */
566 ASSERT(dimensions
>= 1 && dimensions
<= 3);
568 alignment
= packing
->Alignment
;
569 if (packing
->RowLength
> 0) {
570 pixels_per_row
= packing
->RowLength
;
573 pixels_per_row
= width
;
575 if (packing
->ImageHeight
> 0) {
576 rows_per_image
= packing
->ImageHeight
;
579 rows_per_image
= height
;
582 skippixels
= packing
->SkipPixels
;
583 /* Note: SKIP_ROWS _is_ used for 1D images */
584 skiprows
= packing
->SkipRows
;
585 /* Note: SKIP_IMAGES is only used for 3D images */
586 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
588 if (type
== GL_BITMAP
) {
590 GLint comp_per_pixel
; /* components per pixel */
591 GLint bytes_per_comp
; /* bytes per component */
593 GLint bytes_per_image
;
595 /* Compute bytes per component */
596 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
597 if (bytes_per_comp
< 0) {
601 /* Compute number of components per pixel */
602 comp_per_pixel
= _mesa_components_in_format( format
);
603 if (comp_per_pixel
< 0) {
607 bytes_per_row
= alignment
608 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
610 bytes_per_image
= bytes_per_row
* rows_per_image
;
612 pixel_addr
= (GLubyte
*) image
613 + (skipimages
+ img
) * bytes_per_image
614 + (skiprows
+ row
) * bytes_per_row
615 + (skippixels
+ column
) / 8;
618 /* Non-BITMAP data */
619 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
622 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
624 /* The pixel type and format should have been error checked earlier */
625 assert(bytes_per_pixel
> 0);
627 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
628 remainder
= bytes_per_row
% alignment
;
630 bytes_per_row
+= (alignment
- remainder
);
632 ASSERT(bytes_per_row
% alignment
== 0);
634 bytes_per_image
= bytes_per_row
* rows_per_image
;
636 if (packing
->Invert
) {
637 /* set pixel_addr to the last row */
638 topOfImage
= bytes_per_row
* (height
- 1);
639 bytes_per_row
= -bytes_per_row
;
645 /* compute final pixel address */
646 pixel_addr
= (GLubyte
*) image
647 + (skipimages
+ img
) * bytes_per_image
649 + (skiprows
+ row
) * bytes_per_row
650 + (skippixels
+ column
) * bytes_per_pixel
;
653 return (GLvoid
*) pixel_addr
;
658 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
661 GLenum format
, GLenum type
,
664 return _mesa_image_address(1, packing
, image
, width
, 1,
665 format
, type
, 0, 0, column
);
670 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
672 GLsizei width
, GLsizei height
,
673 GLenum format
, GLenum type
,
674 GLint row
, GLint column
)
676 return _mesa_image_address(2, packing
, image
, width
, height
,
677 format
, type
, 0, row
, column
);
682 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
684 GLsizei width
, GLsizei height
,
685 GLenum format
, GLenum type
,
686 GLint img
, GLint row
, GLint column
)
688 return _mesa_image_address(3, packing
, image
, width
, height
,
689 format
, type
, img
, row
, column
);
695 * Compute the stride (in bytes) between image rows.
697 * \param packing the pixelstore attributes
698 * \param width image width.
699 * \param format pixel format.
700 * \param type pixel data type.
702 * \return the stride in bytes for the given parameters, or -1 if error
705 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
706 GLint width
, GLenum format
, GLenum type
)
708 GLint bytesPerRow
, remainder
;
712 if (type
== GL_BITMAP
) {
713 if (packing
->RowLength
== 0) {
714 bytesPerRow
= (width
+ 7) / 8;
717 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
721 /* Non-BITMAP data */
722 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
723 if (bytesPerPixel
<= 0)
724 return -1; /* error */
725 if (packing
->RowLength
== 0) {
726 bytesPerRow
= bytesPerPixel
* width
;
729 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
733 remainder
= bytesPerRow
% packing
->Alignment
;
735 bytesPerRow
+= (packing
->Alignment
- remainder
);
738 if (packing
->Invert
) {
739 /* negate the bytes per row (negative row stride) */
740 bytesPerRow
= -bytesPerRow
;
750 * Compute the stride between images in a 3D texture (in bytes) for the given
751 * pixel packing parameters and image width, format and type.
754 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
755 GLint width
, GLint height
,
756 GLenum format
, GLenum type
)
759 ASSERT(type
!= GL_BITMAP
);
762 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
763 GLint bytesPerRow
, bytesPerImage
, remainder
;
765 if (bytesPerPixel
<= 0)
766 return -1; /* error */
767 if (packing
->RowLength
== 0) {
768 bytesPerRow
= bytesPerPixel
* width
;
771 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
773 remainder
= bytesPerRow
% packing
->Alignment
;
775 bytesPerRow
+= (packing
->Alignment
- remainder
);
777 if (packing
->ImageHeight
== 0)
778 bytesPerImage
= bytesPerRow
* height
;
780 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
782 return bytesPerImage
;
788 * Unpack a 32x32 pixel polygon stipple from user memory using the
789 * current pixel unpack settings.
792 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
793 const struct gl_pixelstore_attrib
*unpacking
)
795 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap(32, 32, pattern
, unpacking
);
797 /* Convert pattern from GLubytes to GLuints and handle big/little
802 for (i
= 0; i
< 32; i
++) {
803 dest
[i
] = (p
[0] << 24)
815 * Pack polygon stipple into user memory given current pixel packing
819 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
820 const struct gl_pixelstore_attrib
*packing
)
822 /* Convert pattern from GLuints to GLubytes to handle big/little
823 * endian differences.
827 for (i
= 0; i
< 32; i
++) {
828 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
829 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
830 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
831 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
834 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
839 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
840 * order with row alignment = 1 byte.
843 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
844 const struct gl_pixelstore_attrib
*packing
)
846 GLint bytes
, row
, width_in_bytes
;
847 GLubyte
*buffer
, *dst
;
852 /* Alloc dest storage */
853 bytes
= ((width
+ 7) / 8 * height
);
854 buffer
= (GLubyte
*) _mesa_malloc( bytes
);
858 width_in_bytes
= CEILING( width
, 8 );
860 for (row
= 0; row
< height
; row
++) {
861 const GLubyte
*src
= (const GLubyte
*)
862 _mesa_image_address2d(packing
, pixels
, width
, height
,
863 GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
869 if ((packing
->SkipPixels
& 7) == 0) {
870 _mesa_memcpy( dst
, src
, width_in_bytes
);
871 if (packing
->LsbFirst
) {
872 flip_bytes( dst
, width_in_bytes
);
876 /* handling SkipPixels is a bit tricky (no pun intended!) */
878 if (packing
->LsbFirst
) {
879 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
880 GLubyte dstMask
= 128;
881 const GLubyte
*s
= src
;
884 for (i
= 0; i
< width
; i
++) {
888 if (srcMask
== 128) {
893 srcMask
= srcMask
<< 1;
901 dstMask
= dstMask
>> 1;
906 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
907 GLubyte dstMask
= 128;
908 const GLubyte
*s
= src
;
911 for (i
= 0; i
< width
; i
++) {
920 srcMask
= srcMask
>> 1;
928 dstMask
= dstMask
>> 1;
933 dst
+= width_in_bytes
;
944 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
945 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
947 GLint row
, width_in_bytes
;
953 width_in_bytes
= CEILING( width
, 8 );
955 for (row
= 0; row
< height
; row
++) {
956 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dest
,
957 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
961 if ((packing
->SkipPixels
& 7) == 0) {
962 _mesa_memcpy( dst
, src
, width_in_bytes
);
963 if (packing
->LsbFirst
) {
964 flip_bytes( dst
, width_in_bytes
);
968 /* handling SkipPixels is a bit tricky (no pun intended!) */
970 if (packing
->LsbFirst
) {
971 GLubyte srcMask
= 128;
972 GLubyte dstMask
= 1 << (packing
->SkipPixels
& 0x7);
973 const GLubyte
*s
= src
;
976 for (i
= 0; i
< width
; i
++) {
985 srcMask
= srcMask
>> 1;
987 if (dstMask
== 128) {
993 dstMask
= dstMask
<< 1;
998 GLubyte srcMask
= 128;
999 GLubyte dstMask
= 128 >> (packing
->SkipPixels
& 0x7);
1000 const GLubyte
*s
= src
;
1003 for (i
= 0; i
< width
; i
++) {
1012 srcMask
= srcMask
>> 1;
1020 dstMask
= dstMask
>> 1;
1025 src
+= width_in_bytes
;
1030 /**********************************************************************/
1031 /***** Pixel processing functions ******/
1032 /**********************************************************************/
1035 * Apply scale and bias factors to an array of RGBA pixels.
1038 _mesa_scale_and_bias_rgba(GLuint n
, GLfloat rgba
[][4],
1039 GLfloat rScale
, GLfloat gScale
,
1040 GLfloat bScale
, GLfloat aScale
,
1041 GLfloat rBias
, GLfloat gBias
,
1042 GLfloat bBias
, GLfloat aBias
)
1044 if (rScale
!= 1.0 || rBias
!= 0.0) {
1046 for (i
= 0; i
< n
; i
++) {
1047 rgba
[i
][RCOMP
] = rgba
[i
][RCOMP
] * rScale
+ rBias
;
1050 if (gScale
!= 1.0 || gBias
!= 0.0) {
1052 for (i
= 0; i
< n
; i
++) {
1053 rgba
[i
][GCOMP
] = rgba
[i
][GCOMP
] * gScale
+ gBias
;
1056 if (bScale
!= 1.0 || bBias
!= 0.0) {
1058 for (i
= 0; i
< n
; i
++) {
1059 rgba
[i
][BCOMP
] = rgba
[i
][BCOMP
] * bScale
+ bBias
;
1062 if (aScale
!= 1.0 || aBias
!= 0.0) {
1064 for (i
= 0; i
< n
; i
++) {
1065 rgba
[i
][ACOMP
] = rgba
[i
][ACOMP
] * aScale
+ aBias
;
1072 * Apply pixel mapping to an array of floating point RGBA pixels.
1075 _mesa_map_rgba( const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4] )
1077 const GLfloat rscale
= (GLfloat
) (ctx
->PixelMaps
.RtoR
.Size
- 1);
1078 const GLfloat gscale
= (GLfloat
) (ctx
->PixelMaps
.GtoG
.Size
- 1);
1079 const GLfloat bscale
= (GLfloat
) (ctx
->PixelMaps
.BtoB
.Size
- 1);
1080 const GLfloat ascale
= (GLfloat
) (ctx
->PixelMaps
.AtoA
.Size
- 1);
1081 const GLfloat
*rMap
= ctx
->PixelMaps
.RtoR
.Map
;
1082 const GLfloat
*gMap
= ctx
->PixelMaps
.GtoG
.Map
;
1083 const GLfloat
*bMap
= ctx
->PixelMaps
.BtoB
.Map
;
1084 const GLfloat
*aMap
= ctx
->PixelMaps
.AtoA
.Map
;
1087 GLfloat r
= CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1088 GLfloat g
= CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1089 GLfloat b
= CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1090 GLfloat a
= CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1091 rgba
[i
][RCOMP
] = rMap
[IROUND(r
* rscale
)];
1092 rgba
[i
][GCOMP
] = gMap
[IROUND(g
* gscale
)];
1093 rgba
[i
][BCOMP
] = bMap
[IROUND(b
* bscale
)];
1094 rgba
[i
][ACOMP
] = aMap
[IROUND(a
* ascale
)];
1100 * Apply the color matrix and post color matrix scaling and biasing.
1103 _mesa_transform_rgba(const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4])
1105 const GLfloat rs
= ctx
->Pixel
.PostColorMatrixScale
[0];
1106 const GLfloat rb
= ctx
->Pixel
.PostColorMatrixBias
[0];
1107 const GLfloat gs
= ctx
->Pixel
.PostColorMatrixScale
[1];
1108 const GLfloat gb
= ctx
->Pixel
.PostColorMatrixBias
[1];
1109 const GLfloat bs
= ctx
->Pixel
.PostColorMatrixScale
[2];
1110 const GLfloat bb
= ctx
->Pixel
.PostColorMatrixBias
[2];
1111 const GLfloat as
= ctx
->Pixel
.PostColorMatrixScale
[3];
1112 const GLfloat ab
= ctx
->Pixel
.PostColorMatrixBias
[3];
1113 const GLfloat
*m
= ctx
->ColorMatrixStack
.Top
->m
;
1115 for (i
= 0; i
< n
; i
++) {
1116 const GLfloat r
= rgba
[i
][RCOMP
];
1117 const GLfloat g
= rgba
[i
][GCOMP
];
1118 const GLfloat b
= rgba
[i
][BCOMP
];
1119 const GLfloat a
= rgba
[i
][ACOMP
];
1120 rgba
[i
][RCOMP
] = (m
[0] * r
+ m
[4] * g
+ m
[ 8] * b
+ m
[12] * a
) * rs
+ rb
;
1121 rgba
[i
][GCOMP
] = (m
[1] * r
+ m
[5] * g
+ m
[ 9] * b
+ m
[13] * a
) * gs
+ gb
;
1122 rgba
[i
][BCOMP
] = (m
[2] * r
+ m
[6] * g
+ m
[10] * b
+ m
[14] * a
) * bs
+ bb
;
1123 rgba
[i
][ACOMP
] = (m
[3] * r
+ m
[7] * g
+ m
[11] * b
+ m
[15] * a
) * as
+ ab
;
1129 * Apply a color table lookup to an array of floating point RGBA colors.
1132 _mesa_lookup_rgba_float(const struct gl_color_table
*table
,
1133 GLuint n
, GLfloat rgba
[][4])
1135 const GLint max
= table
->Size
- 1;
1136 const GLfloat scale
= (GLfloat
) max
;
1137 const GLfloat
*lut
= table
->TableF
;
1140 if (!table
->TableF
|| table
->Size
== 0)
1143 switch (table
->_BaseFormat
) {
1145 /* replace RGBA with I */
1146 for (i
= 0; i
< n
; i
++) {
1147 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1148 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1156 /* replace RGB with L */
1157 for (i
= 0; i
< n
; i
++) {
1158 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1159 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1166 /* replace A with A */
1167 for (i
= 0; i
< n
; i
++) {
1168 GLint j
= IROUND(rgba
[i
][ACOMP
] * scale
);
1169 rgba
[i
][ACOMP
] = lut
[CLAMP(j
, 0, max
)];
1172 case GL_LUMINANCE_ALPHA
:
1173 /* replace RGBA with LLLA */
1174 for (i
= 0; i
< n
; i
++) {
1175 GLint jL
= IROUND(rgba
[i
][RCOMP
] * scale
);
1176 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1177 GLfloat luminance
, alpha
;
1178 jL
= CLAMP(jL
, 0, max
);
1179 jA
= CLAMP(jA
, 0, max
);
1180 luminance
= lut
[jL
* 2 + 0];
1181 alpha
= lut
[jA
* 2 + 1];
1184 rgba
[i
][BCOMP
] = luminance
;
1185 rgba
[i
][ACOMP
] = alpha
;;
1189 /* replace RGB with RGB */
1190 for (i
= 0; i
< n
; i
++) {
1191 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1192 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1193 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1194 jR
= CLAMP(jR
, 0, max
);
1195 jG
= CLAMP(jG
, 0, max
);
1196 jB
= CLAMP(jB
, 0, max
);
1197 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1198 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1199 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1203 /* replace RGBA with RGBA */
1204 for (i
= 0; i
< n
; i
++) {
1205 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1206 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1207 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1208 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1209 jR
= CLAMP(jR
, 0, max
);
1210 jG
= CLAMP(jG
, 0, max
);
1211 jB
= CLAMP(jB
, 0, max
);
1212 jA
= CLAMP(jA
, 0, max
);
1213 rgba
[i
][RCOMP
] = lut
[jR
* 4 + 0];
1214 rgba
[i
][GCOMP
] = lut
[jG
* 4 + 1];
1215 rgba
[i
][BCOMP
] = lut
[jB
* 4 + 2];
1216 rgba
[i
][ACOMP
] = lut
[jA
* 4 + 3];
1220 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_float");
1228 * Apply a color table lookup to an array of ubyte/RGBA colors.
1231 _mesa_lookup_rgba_ubyte(const struct gl_color_table
*table
,
1232 GLuint n
, GLubyte rgba
[][4])
1234 const GLubyte
*lut
= table
->TableUB
;
1235 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / (GLfloat
)255.0;
1238 if (!table
->TableUB
|| table
->Size
== 0)
1241 switch (table
->_BaseFormat
) {
1243 /* replace RGBA with I */
1244 if (table
->Size
== 256) {
1245 for (i
= 0; i
< n
; i
++) {
1246 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1254 for (i
= 0; i
< n
; i
++) {
1255 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1259 rgba
[i
][ACOMP
] = lut
[j
];
1264 /* replace RGB with L */
1265 if (table
->Size
== 256) {
1266 for (i
= 0; i
< n
; i
++) {
1267 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1274 for (i
= 0; i
< n
; i
++) {
1275 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1278 rgba
[i
][BCOMP
] = lut
[j
];
1283 /* replace A with A */
1284 if (table
->Size
== 256) {
1285 for (i
= 0; i
< n
; i
++) {
1286 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
]];
1290 for (i
= 0; i
< n
; i
++) {
1291 GLint j
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1292 rgba
[i
][ACOMP
] = lut
[j
];
1296 case GL_LUMINANCE_ALPHA
:
1297 /* replace RGBA with LLLA */
1298 if (table
->Size
== 256) {
1299 for (i
= 0; i
< n
; i
++) {
1300 GLubyte l
= lut
[rgba
[i
][RCOMP
] * 2 + 0];
1301 GLubyte a
= lut
[rgba
[i
][ACOMP
] * 2 + 1];;
1309 for (i
= 0; i
< n
; i
++) {
1310 GLint jL
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1311 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1312 GLubyte luminance
= lut
[jL
* 2 + 0];
1313 GLubyte alpha
= lut
[jA
* 2 + 1];
1316 rgba
[i
][BCOMP
] = luminance
;
1317 rgba
[i
][ACOMP
] = alpha
;
1322 if (table
->Size
== 256) {
1323 for (i
= 0; i
< n
; i
++) {
1324 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 3 + 0];
1325 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 3 + 1];
1326 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 3 + 2];
1330 for (i
= 0; i
< n
; i
++) {
1331 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1332 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1333 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1334 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1335 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1336 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1341 if (table
->Size
== 256) {
1342 for (i
= 0; i
< n
; i
++) {
1343 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 4 + 0];
1344 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 4 + 1];
1345 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 4 + 2];
1346 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
] * 4 + 3];
1350 for (i
= 0; i
< n
; i
++) {
1351 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1352 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1353 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1354 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1355 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][RCOMP
], lut
[jR
* 4 + 0]);
1356 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][GCOMP
], lut
[jG
* 4 + 1]);
1357 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][BCOMP
], lut
[jB
* 4 + 2]);
1358 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][ACOMP
], lut
[jA
* 4 + 3]);
1363 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_chan");
1371 * Map color indexes to float rgba values.
1374 _mesa_map_ci_to_rgba( const GLcontext
*ctx
, GLuint n
,
1375 const GLuint index
[], GLfloat rgba
[][4] )
1377 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1378 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1379 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1380 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1381 const GLfloat
*rMap
= ctx
->PixelMaps
.ItoR
.Map
;
1382 const GLfloat
*gMap
= ctx
->PixelMaps
.ItoG
.Map
;
1383 const GLfloat
*bMap
= ctx
->PixelMaps
.ItoB
.Map
;
1384 const GLfloat
*aMap
= ctx
->PixelMaps
.ItoA
.Map
;
1387 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1388 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1389 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1390 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1396 * Map ubyte color indexes to ubyte/RGBA values.
1399 _mesa_map_ci8_to_rgba8(const GLcontext
*ctx
, GLuint n
, const GLubyte index
[],
1402 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1403 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1404 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1405 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1406 const GLubyte
*rMap
= ctx
->PixelMaps
.ItoR
.Map8
;
1407 const GLubyte
*gMap
= ctx
->PixelMaps
.ItoG
.Map8
;
1408 const GLubyte
*bMap
= ctx
->PixelMaps
.ItoB
.Map8
;
1409 const GLubyte
*aMap
= ctx
->PixelMaps
.ItoA
.Map8
;
1412 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1413 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1414 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1415 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1421 _mesa_scale_and_bias_depth(const GLcontext
*ctx
, GLuint n
,
1422 GLfloat depthValues
[])
1424 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
1425 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
1427 for (i
= 0; i
< n
; i
++) {
1428 GLfloat d
= depthValues
[i
] * scale
+ bias
;
1429 depthValues
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
1435 _mesa_scale_and_bias_depth_uint(const GLcontext
*ctx
, GLuint n
,
1436 GLuint depthValues
[])
1438 const GLdouble max
= (double) 0xffffffff;
1439 const GLdouble scale
= ctx
->Pixel
.DepthScale
;
1440 const GLdouble bias
= ctx
->Pixel
.DepthBias
* max
;
1442 for (i
= 0; i
< n
; i
++) {
1443 GLdouble d
= (GLdouble
) depthValues
[i
] * scale
+ bias
;
1444 d
= CLAMP(d
, 0.0, max
);
1445 depthValues
[i
] = (GLuint
) d
;
1452 * Update the min/max values from an array of fragment colors.
1455 update_minmax(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1458 for (i
= 0; i
< n
; i
++) {
1460 if (rgba
[i
][RCOMP
] < ctx
->MinMax
.Min
[RCOMP
])
1461 ctx
->MinMax
.Min
[RCOMP
] = rgba
[i
][RCOMP
];
1462 if (rgba
[i
][GCOMP
] < ctx
->MinMax
.Min
[GCOMP
])
1463 ctx
->MinMax
.Min
[GCOMP
] = rgba
[i
][GCOMP
];
1464 if (rgba
[i
][BCOMP
] < ctx
->MinMax
.Min
[BCOMP
])
1465 ctx
->MinMax
.Min
[BCOMP
] = rgba
[i
][BCOMP
];
1466 if (rgba
[i
][ACOMP
] < ctx
->MinMax
.Min
[ACOMP
])
1467 ctx
->MinMax
.Min
[ACOMP
] = rgba
[i
][ACOMP
];
1470 if (rgba
[i
][RCOMP
] > ctx
->MinMax
.Max
[RCOMP
])
1471 ctx
->MinMax
.Max
[RCOMP
] = rgba
[i
][RCOMP
];
1472 if (rgba
[i
][GCOMP
] > ctx
->MinMax
.Max
[GCOMP
])
1473 ctx
->MinMax
.Max
[GCOMP
] = rgba
[i
][GCOMP
];
1474 if (rgba
[i
][BCOMP
] > ctx
->MinMax
.Max
[BCOMP
])
1475 ctx
->MinMax
.Max
[BCOMP
] = rgba
[i
][BCOMP
];
1476 if (rgba
[i
][ACOMP
] > ctx
->MinMax
.Max
[ACOMP
])
1477 ctx
->MinMax
.Max
[ACOMP
] = rgba
[i
][ACOMP
];
1483 * Update the histogram values from an array of fragment colors.
1486 update_histogram(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1488 const GLint max
= ctx
->Histogram
.Width
- 1;
1489 GLfloat w
= (GLfloat
) max
;
1492 if (ctx
->Histogram
.Width
== 0)
1495 for (i
= 0; i
< n
; i
++) {
1496 GLint ri
= IROUND(rgba
[i
][RCOMP
] * w
);
1497 GLint gi
= IROUND(rgba
[i
][GCOMP
] * w
);
1498 GLint bi
= IROUND(rgba
[i
][BCOMP
] * w
);
1499 GLint ai
= IROUND(rgba
[i
][ACOMP
] * w
);
1500 ri
= CLAMP(ri
, 0, max
);
1501 gi
= CLAMP(gi
, 0, max
);
1502 bi
= CLAMP(bi
, 0, max
);
1503 ai
= CLAMP(ai
, 0, max
);
1504 ctx
->Histogram
.Count
[ri
][RCOMP
]++;
1505 ctx
->Histogram
.Count
[gi
][GCOMP
]++;
1506 ctx
->Histogram
.Count
[bi
][BCOMP
]++;
1507 ctx
->Histogram
.Count
[ai
][ACOMP
]++;
1513 * Apply various pixel transfer operations to an array of RGBA pixels
1514 * as indicated by the transferOps bitmask
1517 _mesa_apply_rgba_transfer_ops(GLcontext
*ctx
, GLbitfield transferOps
,
1518 GLuint n
, GLfloat rgba
[][4])
1521 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
1522 _mesa_scale_and_bias_rgba(n
, rgba
,
1523 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
1524 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
1525 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
1526 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
1528 /* color map lookup */
1529 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1530 _mesa_map_rgba( ctx
, n
, rgba
);
1532 /* GL_COLOR_TABLE lookup */
1533 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
1534 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
], n
, rgba
);
1537 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
1538 /* this has to be done in the calling code */
1539 _mesa_problem(ctx
, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");
1541 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
1542 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
1543 _mesa_scale_and_bias_rgba(n
, rgba
,
1544 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
1545 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
1546 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
1547 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
1548 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
1549 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
1550 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
1551 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
1553 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
1554 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
1555 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
], n
, rgba
);
1557 /* color matrix transform */
1558 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
1559 _mesa_transform_rgba(ctx
, n
, rgba
);
1561 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
1562 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
1563 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
], n
, rgba
);
1565 /* update histogram count */
1566 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
1567 update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1569 /* update min/max values */
1570 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
1571 update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1573 /* clamping to [0,1] */
1574 if (transferOps
& IMAGE_CLAMP_BIT
) {
1576 for (i
= 0; i
< n
; i
++) {
1577 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1578 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1579 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1580 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1587 * Apply color index shift and offset to an array of pixels.
1590 shift_and_offset_ci( const GLcontext
*ctx
, GLuint n
, GLuint indexes
[] )
1592 GLint shift
= ctx
->Pixel
.IndexShift
;
1593 GLint offset
= ctx
->Pixel
.IndexOffset
;
1597 indexes
[i
] = (indexes
[i
] << shift
) + offset
;
1600 else if (shift
< 0) {
1603 indexes
[i
] = (indexes
[i
] >> shift
) + offset
;
1608 indexes
[i
] = indexes
[i
] + offset
;
1616 * Apply color index shift, offset and table lookup to an array
1620 _mesa_apply_ci_transfer_ops(const GLcontext
*ctx
, GLbitfield transferOps
,
1621 GLuint n
, GLuint indexes
[])
1623 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
1624 shift_and_offset_ci(ctx
, n
, indexes
);
1626 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1627 const GLuint mask
= ctx
->PixelMaps
.ItoI
.Size
- 1;
1629 for (i
= 0; i
< n
; i
++) {
1630 const GLuint j
= indexes
[i
] & mask
;
1631 indexes
[i
] = IROUND(ctx
->PixelMaps
.ItoI
.Map
[j
]);
1638 * Apply stencil index shift, offset and table lookup to an array
1639 * of stencil values.
1642 _mesa_apply_stencil_transfer_ops(const GLcontext
*ctx
, GLuint n
,
1643 GLstencil stencil
[])
1645 if (ctx
->Pixel
.IndexShift
!= 0 || ctx
->Pixel
.IndexOffset
!= 0) {
1646 const GLint offset
= ctx
->Pixel
.IndexOffset
;
1647 GLint shift
= ctx
->Pixel
.IndexShift
;
1650 for (i
= 0; i
< n
; i
++) {
1651 stencil
[i
] = (stencil
[i
] << shift
) + offset
;
1654 else if (shift
< 0) {
1656 for (i
= 0; i
< n
; i
++) {
1657 stencil
[i
] = (stencil
[i
] >> shift
) + offset
;
1661 for (i
= 0; i
< n
; i
++) {
1662 stencil
[i
] = stencil
[i
] + offset
;
1666 if (ctx
->Pixel
.MapStencilFlag
) {
1667 GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
1669 for (i
= 0; i
< n
; i
++) {
1670 stencil
[i
] = (GLstencil
)ctx
->PixelMaps
.StoS
.Map
[ stencil
[i
] & mask
];
1677 * Used to pack an array [][4] of RGBA float colors as specified
1678 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
1679 * glGetConvolutionFilter(), etc.
1680 * Incoming colors will be clamped to [0,1] if needed.
1681 * Note: the rgba values will be modified by this function when any pixel
1682 * transfer ops are enabled.
1685 _mesa_pack_rgba_span_float(GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4],
1686 GLenum dstFormat
, GLenum dstType
,
1688 const struct gl_pixelstore_attrib
*dstPacking
,
1689 GLbitfield transferOps
)
1691 GLfloat luminance
[MAX_WIDTH
];
1692 const GLint comps
= _mesa_components_in_format(dstFormat
);
1694 /* clamping only applies to colors, not the dudv values, but still need
1695 it if converting to unsigned values (which doesn't make much sense) */
1696 if (dstFormat
== GL_DUDV_ATI
|| dstFormat
== GL_DU8DV8_ATI
) {
1698 case GL_UNSIGNED_BYTE
:
1699 case GL_UNSIGNED_SHORT
:
1700 case GL_UNSIGNED_INT
:
1701 transferOps
|= IMAGE_CLAMP_BIT
;
1703 /* actually might want clamp to [-1,1] otherwise but shouldn't matter? */
1706 else if (dstType
!= GL_FLOAT
|| ctx
->Color
.ClampReadColor
== GL_TRUE
) {
1707 /* need to clamp to [0, 1] */
1708 transferOps
|= IMAGE_CLAMP_BIT
;
1712 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
1713 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
1718 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
1719 /* compute luminance values */
1720 if (transferOps
& IMAGE_CLAMP_BIT
) {
1721 for (i
= 0; i
< n
; i
++) {
1722 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1723 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
1727 for (i
= 0; i
< n
; i
++) {
1728 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1734 * Pack/store the pixels. Ugh! Lots of cases!!!
1737 case GL_UNSIGNED_BYTE
:
1739 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1740 switch (dstFormat
) {
1743 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1747 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1751 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1755 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1759 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1761 case GL_LUMINANCE_ALPHA
:
1763 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1764 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1769 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1770 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1771 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1776 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1777 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1778 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1779 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1784 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1785 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1786 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1791 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1792 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1793 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1794 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1799 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1800 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1801 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1802 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1808 dst
[i
*2+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1809 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1813 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1819 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1820 switch (dstFormat
) {
1823 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1827 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1831 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1835 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1839 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1841 case GL_LUMINANCE_ALPHA
:
1843 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1844 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1849 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1850 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1851 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1856 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1857 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1858 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1859 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1864 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1865 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1866 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1871 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1872 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1873 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1874 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1879 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1880 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1881 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1882 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1888 dst
[i
*2+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1889 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1893 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1897 case GL_UNSIGNED_SHORT
:
1899 GLushort
*dst
= (GLushort
*) dstAddr
;
1900 switch (dstFormat
) {
1903 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][RCOMP
]);
1907 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][GCOMP
]);
1911 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][BCOMP
]);
1915 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][ACOMP
]);
1919 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
], luminance
[i
]);
1921 case GL_LUMINANCE_ALPHA
:
1923 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
*2+0], luminance
[i
]);
1924 CLAMPED_FLOAT_TO_USHORT(dst
[i
*2+1], rgba
[i
][ACOMP
]);
1929 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][RCOMP
]);
1930 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1931 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][BCOMP
]);
1936 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][RCOMP
]);
1937 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1938 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][BCOMP
]);
1939 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1944 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][BCOMP
]);
1945 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1946 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][RCOMP
]);
1951 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][BCOMP
]);
1952 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1953 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][RCOMP
]);
1954 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1959 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][ACOMP
]);
1960 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][BCOMP
]);
1961 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][GCOMP
]);
1962 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][RCOMP
]);
1968 dst
[i
*2+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1969 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1973 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1979 GLshort
*dst
= (GLshort
*) dstAddr
;
1980 switch (dstFormat
) {
1983 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1987 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1991 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1995 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1999 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
2001 case GL_LUMINANCE_ALPHA
:
2003 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
2004 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2009 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2010 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2011 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2016 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2017 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2018 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2019 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2024 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2025 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2026 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2031 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2032 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2033 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2034 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2039 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2040 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2041 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2042 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2048 dst
[i
*2+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2049 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2053 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2057 case GL_UNSIGNED_INT
:
2059 GLuint
*dst
= (GLuint
*) dstAddr
;
2060 switch (dstFormat
) {
2063 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2067 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2071 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2075 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2079 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
2081 case GL_LUMINANCE_ALPHA
:
2083 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
2084 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2089 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2090 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2091 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2096 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2097 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2098 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2099 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2104 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2105 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2106 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2111 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2112 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2113 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2114 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2119 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2120 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2121 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2122 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2128 dst
[i
*2+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2129 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2133 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2139 GLint
*dst
= (GLint
*) dstAddr
;
2140 switch (dstFormat
) {
2143 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2147 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2151 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2155 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2159 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
2161 case GL_LUMINANCE_ALPHA
:
2163 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
2164 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2169 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2170 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2171 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2176 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2177 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2178 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2179 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2184 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2185 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2186 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2191 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2192 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2193 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2194 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2199 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2200 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2201 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2202 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2208 dst
[i
*2+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2209 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2213 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2219 GLfloat
*dst
= (GLfloat
*) dstAddr
;
2220 switch (dstFormat
) {
2223 dst
[i
] = rgba
[i
][RCOMP
];
2227 dst
[i
] = rgba
[i
][GCOMP
];
2231 dst
[i
] = rgba
[i
][BCOMP
];
2235 dst
[i
] = rgba
[i
][ACOMP
];
2239 dst
[i
] = luminance
[i
];
2241 case GL_LUMINANCE_ALPHA
:
2243 dst
[i
*2+0] = luminance
[i
];
2244 dst
[i
*2+1] = rgba
[i
][ACOMP
];
2249 dst
[i
*3+0] = rgba
[i
][RCOMP
];
2250 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2251 dst
[i
*3+2] = rgba
[i
][BCOMP
];
2256 dst
[i
*4+0] = rgba
[i
][RCOMP
];
2257 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2258 dst
[i
*4+2] = rgba
[i
][BCOMP
];
2259 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2264 dst
[i
*3+0] = rgba
[i
][BCOMP
];
2265 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2266 dst
[i
*3+2] = rgba
[i
][RCOMP
];
2271 dst
[i
*4+0] = rgba
[i
][BCOMP
];
2272 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2273 dst
[i
*4+2] = rgba
[i
][RCOMP
];
2274 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2279 dst
[i
*4+0] = rgba
[i
][ACOMP
];
2280 dst
[i
*4+1] = rgba
[i
][BCOMP
];
2281 dst
[i
*4+2] = rgba
[i
][GCOMP
];
2282 dst
[i
*4+3] = rgba
[i
][RCOMP
];
2288 dst
[i
*2+0] = rgba
[i
][RCOMP
];
2289 dst
[i
*2+1] = rgba
[i
][GCOMP
];
2293 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2297 case GL_HALF_FLOAT_ARB
:
2299 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
2300 switch (dstFormat
) {
2303 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2307 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2311 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2315 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2319 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
2321 case GL_LUMINANCE_ALPHA
:
2323 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
2324 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2329 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2330 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2331 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2336 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2337 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2338 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2339 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2344 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2345 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2346 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2351 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2352 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2353 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2354 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2359 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2360 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2361 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2362 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2368 dst
[i
*2+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2369 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2373 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2377 case GL_UNSIGNED_BYTE_3_3_2
:
2378 if (dstFormat
== GL_RGB
) {
2379 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2381 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
2382 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
2383 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
2387 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2388 if (dstFormat
== GL_RGB
) {
2389 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2391 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
2392 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
2393 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 6);
2397 case GL_UNSIGNED_SHORT_5_6_5
:
2398 if (dstFormat
== GL_RGB
) {
2399 GLushort
*dst
= (GLushort
*) dstAddr
;
2401 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
2402 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
2403 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
2407 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2408 if (dstFormat
== GL_RGB
) {
2409 GLushort
*dst
= (GLushort
*) dstAddr
;
2411 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
2412 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
2413 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
2417 case GL_UNSIGNED_SHORT_4_4_4_4
:
2418 if (dstFormat
== GL_RGBA
) {
2419 GLushort
*dst
= (GLushort
*) dstAddr
;
2421 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
2422 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
2423 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
2424 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
2427 else if (dstFormat
== GL_BGRA
) {
2428 GLushort
*dst
= (GLushort
*) dstAddr
;
2430 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 12)
2431 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
2432 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 4)
2433 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
2436 else if (dstFormat
== GL_ABGR_EXT
) {
2437 GLushort
*dst
= (GLushort
*) dstAddr
;
2439 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12)
2440 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
2441 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
2442 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) );
2446 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2447 if (dstFormat
== GL_RGBA
) {
2448 GLushort
*dst
= (GLushort
*) dstAddr
;
2450 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
2451 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
2452 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
2453 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
2456 else if (dstFormat
== GL_BGRA
) {
2457 GLushort
*dst
= (GLushort
*) dstAddr
;
2459 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) )
2460 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
2461 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 8)
2462 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
2465 else if (dstFormat
== GL_ABGR_EXT
) {
2466 GLushort
*dst
= (GLushort
*) dstAddr
;
2468 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) )
2469 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
2470 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
2471 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12);
2475 case GL_UNSIGNED_SHORT_5_5_5_1
:
2476 if (dstFormat
== GL_RGBA
) {
2477 GLushort
*dst
= (GLushort
*) dstAddr
;
2479 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
2480 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
2481 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
2482 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
2485 else if (dstFormat
== GL_BGRA
) {
2486 GLushort
*dst
= (GLushort
*) dstAddr
;
2488 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11)
2489 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
2490 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 1)
2491 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
2494 else if (dstFormat
== GL_ABGR_EXT
) {
2495 GLushort
*dst
= (GLushort
*) dstAddr
;
2497 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) << 11)
2498 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 6)
2499 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 1)
2500 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) );
2504 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2505 if (dstFormat
== GL_RGBA
) {
2506 GLushort
*dst
= (GLushort
*) dstAddr
;
2508 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
2509 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
2510 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
2511 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
2514 else if (dstFormat
== GL_BGRA
) {
2515 GLushort
*dst
= (GLushort
*) dstAddr
;
2517 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) )
2518 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
2519 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 10)
2520 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
2523 else if (dstFormat
== GL_ABGR_EXT
) {
2524 GLushort
*dst
= (GLushort
*) dstAddr
;
2526 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) )
2527 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 5)
2528 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 10)
2529 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) << 15);
2533 case GL_UNSIGNED_INT_8_8_8_8
:
2534 if (dstFormat
== GL_RGBA
) {
2535 GLuint
*dst
= (GLuint
*) dstAddr
;
2537 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
2538 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
2539 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
2540 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
2543 else if (dstFormat
== GL_BGRA
) {
2544 GLuint
*dst
= (GLuint
*) dstAddr
;
2546 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
2547 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
2548 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
2549 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
2552 else if (dstFormat
== GL_ABGR_EXT
) {
2553 GLuint
*dst
= (GLuint
*) dstAddr
;
2555 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
2556 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
2557 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
2558 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
2562 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2563 if (dstFormat
== GL_RGBA
) {
2564 GLuint
*dst
= (GLuint
*) dstAddr
;
2566 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
2567 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
2568 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
2569 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
2572 else if (dstFormat
== GL_BGRA
) {
2573 GLuint
*dst
= (GLuint
*) dstAddr
;
2575 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
2576 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
2577 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
2578 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
2581 else if (dstFormat
== GL_ABGR_EXT
) {
2582 GLuint
*dst
= (GLuint
*) dstAddr
;
2584 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
2585 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
2586 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
2587 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
2591 case GL_UNSIGNED_INT_10_10_10_2
:
2592 if (dstFormat
== GL_RGBA
) {
2593 GLuint
*dst
= (GLuint
*) dstAddr
;
2595 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
2596 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
2597 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
2598 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
2601 else if (dstFormat
== GL_BGRA
) {
2602 GLuint
*dst
= (GLuint
*) dstAddr
;
2604 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
2605 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
2606 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
2607 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
2610 else if (dstFormat
== GL_ABGR_EXT
) {
2611 GLuint
*dst
= (GLuint
*) dstAddr
;
2613 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
2614 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
2615 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
2616 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
2620 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2621 if (dstFormat
== GL_RGBA
) {
2622 GLuint
*dst
= (GLuint
*) dstAddr
;
2624 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
2625 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
2626 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
2627 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
2630 else if (dstFormat
== GL_BGRA
) {
2631 GLuint
*dst
= (GLuint
*) dstAddr
;
2633 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
2634 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
2635 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
2636 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
2639 else if (dstFormat
== GL_ABGR_EXT
) {
2640 GLuint
*dst
= (GLuint
*) dstAddr
;
2642 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
2643 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
2644 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
2645 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
2650 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
2654 if (dstPacking
->SwapBytes
) {
2655 GLint swapSize
= _mesa_sizeof_packed_type(dstType
);
2656 if (swapSize
== 2) {
2657 if (dstPacking
->SwapBytes
) {
2658 _mesa_swap2((GLushort
*) dstAddr
, n
* comps
);
2661 else if (swapSize
== 4) {
2662 if (dstPacking
->SwapBytes
) {
2663 _mesa_swap4((GLuint
*) dstAddr
, n
* comps
);
2670 #define SWAP2BYTE(VALUE) \
2672 GLubyte *bytes = (GLubyte *) &(VALUE); \
2673 GLubyte tmp = bytes[0]; \
2674 bytes[0] = bytes[1]; \
2678 #define SWAP4BYTE(VALUE) \
2680 GLubyte *bytes = (GLubyte *) &(VALUE); \
2681 GLubyte tmp = bytes[0]; \
2682 bytes[0] = bytes[3]; \
2685 bytes[1] = bytes[2]; \
2691 extract_uint_indexes(GLuint n
, GLuint indexes
[],
2692 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2693 const struct gl_pixelstore_attrib
*unpack
)
2695 ASSERT(srcFormat
== GL_COLOR_INDEX
|| srcFormat
== GL_STENCIL_INDEX
);
2697 ASSERT(srcType
== GL_BITMAP
||
2698 srcType
== GL_UNSIGNED_BYTE
||
2699 srcType
== GL_BYTE
||
2700 srcType
== GL_UNSIGNED_SHORT
||
2701 srcType
== GL_SHORT
||
2702 srcType
== GL_UNSIGNED_INT
||
2703 srcType
== GL_INT
||
2704 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
2705 srcType
== GL_HALF_FLOAT_ARB
||
2706 srcType
== GL_FLOAT
);
2711 GLubyte
*ubsrc
= (GLubyte
*) src
;
2712 if (unpack
->LsbFirst
) {
2713 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
2715 for (i
= 0; i
< n
; i
++) {
2716 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2727 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
2729 for (i
= 0; i
< n
; i
++) {
2730 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2742 case GL_UNSIGNED_BYTE
:
2745 const GLubyte
*s
= (const GLubyte
*) src
;
2746 for (i
= 0; i
< n
; i
++)
2753 const GLbyte
*s
= (const GLbyte
*) src
;
2754 for (i
= 0; i
< n
; i
++)
2758 case GL_UNSIGNED_SHORT
:
2761 const GLushort
*s
= (const GLushort
*) src
;
2762 if (unpack
->SwapBytes
) {
2763 for (i
= 0; i
< n
; i
++) {
2764 GLushort value
= s
[i
];
2770 for (i
= 0; i
< n
; i
++)
2778 const GLshort
*s
= (const GLshort
*) src
;
2779 if (unpack
->SwapBytes
) {
2780 for (i
= 0; i
< n
; i
++) {
2781 GLshort value
= s
[i
];
2787 for (i
= 0; i
< n
; i
++)
2792 case GL_UNSIGNED_INT
:
2795 const GLuint
*s
= (const GLuint
*) src
;
2796 if (unpack
->SwapBytes
) {
2797 for (i
= 0; i
< n
; i
++) {
2798 GLuint value
= s
[i
];
2804 for (i
= 0; i
< n
; i
++)
2812 const GLint
*s
= (const GLint
*) src
;
2813 if (unpack
->SwapBytes
) {
2814 for (i
= 0; i
< n
; i
++) {
2821 for (i
= 0; i
< n
; i
++)
2829 const GLfloat
*s
= (const GLfloat
*) src
;
2830 if (unpack
->SwapBytes
) {
2831 for (i
= 0; i
< n
; i
++) {
2832 GLfloat value
= s
[i
];
2834 indexes
[i
] = (GLuint
) value
;
2838 for (i
= 0; i
< n
; i
++)
2839 indexes
[i
] = (GLuint
) s
[i
];
2843 case GL_HALF_FLOAT_ARB
:
2846 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
2847 if (unpack
->SwapBytes
) {
2848 for (i
= 0; i
< n
; i
++) {
2849 GLhalfARB value
= s
[i
];
2851 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
2855 for (i
= 0; i
< n
; i
++)
2856 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
2860 case GL_UNSIGNED_INT_24_8_EXT
:
2863 const GLuint
*s
= (const GLuint
*) src
;
2864 if (unpack
->SwapBytes
) {
2865 for (i
= 0; i
< n
; i
++) {
2866 GLuint value
= s
[i
];
2868 indexes
[i
] = value
& 0xff; /* lower 8 bits */
2872 for (i
= 0; i
< n
; i
++)
2873 indexes
[i
] = s
[i
] & 0xfff; /* lower 8 bits */
2879 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2886 * This function extracts floating point RGBA values from arbitrary
2887 * image data. srcFormat and srcType are the format and type parameters
2888 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2890 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2891 * implements the "Conversion to floating point", "Conversion to RGB",
2892 * and "Final Expansion to RGBA" operations.
2894 * Args: n - number of pixels
2895 * rgba - output colors
2896 * srcFormat - format of incoming data
2897 * srcType - data type of incoming data
2898 * src - source data pointer
2899 * swapBytes - perform byteswapping of incoming data?
2902 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2903 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2904 GLboolean swapBytes
)
2906 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2908 GLint rComp
, bComp
, gComp
, aComp
;
2910 ASSERT(srcFormat
== GL_RED
||
2911 srcFormat
== GL_GREEN
||
2912 srcFormat
== GL_BLUE
||
2913 srcFormat
== GL_ALPHA
||
2914 srcFormat
== GL_LUMINANCE
||
2915 srcFormat
== GL_LUMINANCE_ALPHA
||
2916 srcFormat
== GL_INTENSITY
||
2917 srcFormat
== GL_RGB
||
2918 srcFormat
== GL_BGR
||
2919 srcFormat
== GL_RGBA
||
2920 srcFormat
== GL_BGRA
||
2921 srcFormat
== GL_ABGR_EXT
||
2922 srcFormat
== GL_DUDV_ATI
);
2924 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2925 srcType
== GL_BYTE
||
2926 srcType
== GL_UNSIGNED_SHORT
||
2927 srcType
== GL_SHORT
||
2928 srcType
== GL_UNSIGNED_INT
||
2929 srcType
== GL_INT
||
2930 srcType
== GL_HALF_FLOAT_ARB
||
2931 srcType
== GL_FLOAT
||
2932 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2933 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2934 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2935 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2936 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2937 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2938 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2939 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2940 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2941 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2942 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2943 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2945 rComp
= gComp
= bComp
= aComp
= -1;
2947 switch (srcFormat
) {
2950 greenIndex
= blueIndex
= alphaIndex
= -1;
2955 redIndex
= blueIndex
= alphaIndex
= -1;
2960 redIndex
= greenIndex
= alphaIndex
= -1;
2964 redIndex
= greenIndex
= blueIndex
= -1;
2969 redIndex
= greenIndex
= blueIndex
= 0;
2973 case GL_LUMINANCE_ALPHA
:
2974 redIndex
= greenIndex
= blueIndex
= 0;
2979 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
3045 _mesa_problem(NULL
, "bad srcFormat in extract float data");
3050 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
3051 if ((INDEX) < 0) { \
3053 for (i = 0; i < n; i++) { \
3054 rgba[i][CHANNEL] = DEFAULT; \
3057 else if (swapBytes) { \
3058 const TYPE *s = (const TYPE *) src; \
3060 for (i = 0; i < n; i++) { \
3061 TYPE value = s[INDEX]; \
3062 if (sizeof(TYPE) == 2) { \
3065 else if (sizeof(TYPE) == 4) { \
3068 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
3073 const TYPE *s = (const TYPE *) src; \
3075 for (i = 0; i < n; i++) { \
3076 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
3082 case GL_UNSIGNED_BYTE
:
3083 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3084 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3085 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3086 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3089 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3090 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3091 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3092 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
3094 case GL_UNSIGNED_SHORT
:
3095 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3096 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3097 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3098 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
3101 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3102 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3103 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3104 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
3106 case GL_UNSIGNED_INT
:
3107 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3108 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3109 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3110 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
3113 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3114 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3115 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3116 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
3119 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3120 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3121 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3122 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
3124 case GL_HALF_FLOAT_ARB
:
3125 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3126 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3127 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3128 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
3130 case GL_UNSIGNED_BYTE_3_3_2
:
3132 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3134 for (i
= 0; i
< n
; i
++) {
3135 GLubyte p
= ubsrc
[i
];
3136 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
3137 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
3138 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
3139 rgba
[i
][aComp
] = 1.0F
;
3143 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3145 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3147 for (i
= 0; i
< n
; i
++) {
3148 GLubyte p
= ubsrc
[i
];
3149 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
3150 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
3151 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
3152 rgba
[i
][aComp
] = 1.0F
;
3156 case GL_UNSIGNED_SHORT_5_6_5
:
3158 const GLushort
*ussrc
= (const GLushort
*) src
;
3160 for (i
= 0; i
< n
; i
++) {
3161 GLushort p
= ussrc
[i
];
3163 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3164 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3165 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3166 rgba
[i
][aComp
] = 1.0F
;
3170 const GLushort
*ussrc
= (const GLushort
*) src
;
3172 for (i
= 0; i
< n
; i
++) {
3173 GLushort p
= ussrc
[i
];
3174 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3175 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3176 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3177 rgba
[i
][aComp
] = 1.0F
;
3181 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3183 const GLushort
*ussrc
= (const GLushort
*) src
;
3185 for (i
= 0; i
< n
; i
++) {
3186 GLushort p
= ussrc
[i
];
3188 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3189 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3190 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3191 rgba
[i
][aComp
] = 1.0F
;
3195 const GLushort
*ussrc
= (const GLushort
*) src
;
3197 for (i
= 0; i
< n
; i
++) {
3198 GLushort p
= ussrc
[i
];
3199 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3200 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3201 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3202 rgba
[i
][aComp
] = 1.0F
;
3206 case GL_UNSIGNED_SHORT_4_4_4_4
:
3208 const GLushort
*ussrc
= (const GLushort
*) src
;
3210 for (i
= 0; i
< n
; i
++) {
3211 GLushort p
= ussrc
[i
];
3213 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3214 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3215 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3216 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3220 const GLushort
*ussrc
= (const GLushort
*) src
;
3222 for (i
= 0; i
< n
; i
++) {
3223 GLushort p
= ussrc
[i
];
3224 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3225 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3226 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3227 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3231 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3233 const GLushort
*ussrc
= (const GLushort
*) src
;
3235 for (i
= 0; i
< n
; i
++) {
3236 GLushort p
= ussrc
[i
];
3238 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3239 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3240 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3241 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3245 const GLushort
*ussrc
= (const GLushort
*) src
;
3247 for (i
= 0; i
< n
; i
++) {
3248 GLushort p
= ussrc
[i
];
3249 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3250 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3251 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3252 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3256 case GL_UNSIGNED_SHORT_5_5_5_1
:
3258 const GLushort
*ussrc
= (const GLushort
*) src
;
3260 for (i
= 0; i
< n
; i
++) {
3261 GLushort p
= ussrc
[i
];
3263 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3264 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3265 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3266 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3270 const GLushort
*ussrc
= (const GLushort
*) src
;
3272 for (i
= 0; i
< n
; i
++) {
3273 GLushort p
= ussrc
[i
];
3274 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3275 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3276 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3277 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3281 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3283 const GLushort
*ussrc
= (const GLushort
*) src
;
3285 for (i
= 0; i
< n
; i
++) {
3286 GLushort p
= ussrc
[i
];
3288 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3289 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3290 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3291 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3295 const GLushort
*ussrc
= (const GLushort
*) src
;
3297 for (i
= 0; i
< n
; i
++) {
3298 GLushort p
= ussrc
[i
];
3299 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3300 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3301 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3302 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3306 case GL_UNSIGNED_INT_8_8_8_8
:
3308 const GLuint
*uisrc
= (const GLuint
*) src
;
3310 for (i
= 0; i
< n
; i
++) {
3311 GLuint p
= uisrc
[i
];
3312 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3313 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3314 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3315 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3319 const GLuint
*uisrc
= (const GLuint
*) src
;
3321 for (i
= 0; i
< n
; i
++) {
3322 GLuint p
= uisrc
[i
];
3323 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3324 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3325 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3326 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3330 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3332 const GLuint
*uisrc
= (const GLuint
*) src
;
3334 for (i
= 0; i
< n
; i
++) {
3335 GLuint p
= uisrc
[i
];
3336 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3337 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3338 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3339 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3343 const GLuint
*uisrc
= (const GLuint
*) src
;
3345 for (i
= 0; i
< n
; i
++) {
3346 GLuint p
= uisrc
[i
];
3347 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3348 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3349 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3350 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3354 case GL_UNSIGNED_INT_10_10_10_2
:
3356 const GLuint
*uisrc
= (const GLuint
*) src
;
3358 for (i
= 0; i
< n
; i
++) {
3359 GLuint p
= uisrc
[i
];
3361 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3362 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3363 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3364 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3368 const GLuint
*uisrc
= (const GLuint
*) src
;
3370 for (i
= 0; i
< n
; i
++) {
3371 GLuint p
= uisrc
[i
];
3372 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3373 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3374 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3375 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3379 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3381 const GLuint
*uisrc
= (const GLuint
*) src
;
3383 for (i
= 0; i
< n
; i
++) {
3384 GLuint p
= uisrc
[i
];
3386 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3387 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3388 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3389 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3393 const GLuint
*uisrc
= (const GLuint
*) src
;
3395 for (i
= 0; i
< n
; i
++) {
3396 GLuint p
= uisrc
[i
];
3397 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3398 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3399 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3400 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3405 _mesa_problem(NULL
, "bad srcType in extract float data");
3412 * Unpack a row of color image data from a client buffer according to
3413 * the pixel unpacking parameters.
3414 * Return GLchan values in the specified dest image format.
3415 * This is used by glDrawPixels and glTexImage?D().
3416 * \param ctx - the context
3417 * n - number of pixels in the span
3418 * dstFormat - format of destination color array
3419 * dest - the destination color array
3420 * srcFormat - source image format
3421 * srcType - source image data type
3422 * source - source image pointer
3423 * srcPacking - pixel unpacking parameters
3424 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
3426 * XXX perhaps expand this to process whole images someday.
3429 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
3430 GLuint n
, GLenum dstFormat
, GLchan dest
[],
3431 GLenum srcFormat
, GLenum srcType
,
3432 const GLvoid
*source
,
3433 const struct gl_pixelstore_attrib
*srcPacking
,
3434 GLbitfield transferOps
)
3436 ASSERT(dstFormat
== GL_ALPHA
||
3437 dstFormat
== GL_LUMINANCE
||
3438 dstFormat
== GL_LUMINANCE_ALPHA
||
3439 dstFormat
== GL_INTENSITY
||
3440 dstFormat
== GL_RGB
||
3441 dstFormat
== GL_RGBA
||
3442 dstFormat
== GL_COLOR_INDEX
);
3444 ASSERT(srcFormat
== GL_RED
||
3445 srcFormat
== GL_GREEN
||
3446 srcFormat
== GL_BLUE
||
3447 srcFormat
== GL_ALPHA
||
3448 srcFormat
== GL_LUMINANCE
||
3449 srcFormat
== GL_LUMINANCE_ALPHA
||
3450 srcFormat
== GL_INTENSITY
||
3451 srcFormat
== GL_RGB
||
3452 srcFormat
== GL_BGR
||
3453 srcFormat
== GL_RGBA
||
3454 srcFormat
== GL_BGRA
||
3455 srcFormat
== GL_ABGR_EXT
||
3456 srcFormat
== GL_COLOR_INDEX
);
3458 ASSERT(srcType
== GL_BITMAP
||
3459 srcType
== GL_UNSIGNED_BYTE
||
3460 srcType
== GL_BYTE
||
3461 srcType
== GL_UNSIGNED_SHORT
||
3462 srcType
== GL_SHORT
||
3463 srcType
== GL_UNSIGNED_INT
||
3464 srcType
== GL_INT
||
3465 srcType
== GL_HALF_FLOAT_ARB
||
3466 srcType
== GL_FLOAT
||
3467 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3468 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3469 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3470 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3471 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3472 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3473 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3474 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3475 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3476 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3477 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3478 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3480 /* Try simple cases first */
3481 if (transferOps
== 0) {
3482 if (srcType
== CHAN_TYPE
) {
3483 if (dstFormat
== GL_RGBA
) {
3484 if (srcFormat
== GL_RGBA
) {
3485 _mesa_memcpy( dest
, source
, n
* 4 * sizeof(GLchan
) );
3488 else if (srcFormat
== GL_RGB
) {
3490 const GLchan
*src
= (const GLchan
*) source
;
3492 for (i
= 0; i
< n
; i
++) {
3503 else if (dstFormat
== GL_RGB
) {
3504 if (srcFormat
== GL_RGB
) {
3505 _mesa_memcpy( dest
, source
, n
* 3 * sizeof(GLchan
) );
3508 else if (srcFormat
== GL_RGBA
) {
3510 const GLchan
*src
= (const GLchan
*) source
;
3512 for (i
= 0; i
< n
; i
++) {
3522 else if (dstFormat
== srcFormat
) {
3523 GLint comps
= _mesa_components_in_format(srcFormat
);
3525 _mesa_memcpy( dest
, source
, n
* comps
* sizeof(GLchan
) );
3530 * Common situation, loading 8bit RGBA/RGB source images
3531 * into 16/32 bit destination. (OSMesa16/32)
3533 else if (srcType
== GL_UNSIGNED_BYTE
) {
3534 if (dstFormat
== GL_RGBA
) {
3535 if (srcFormat
== GL_RGB
) {
3537 const GLubyte
*src
= (const GLubyte
*) source
;
3539 for (i
= 0; i
< n
; i
++) {
3540 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3541 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3542 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3549 else if (srcFormat
== GL_RGBA
) {
3551 const GLubyte
*src
= (const GLubyte
*) source
;
3553 for (i
= 0; i
< n
; i
++) {
3554 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3555 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3556 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3557 dst
[3] = UBYTE_TO_CHAN(src
[3]);
3564 else if (dstFormat
== GL_RGB
) {
3565 if (srcFormat
== GL_RGB
) {
3567 const GLubyte
*src
= (const GLubyte
*) source
;
3569 for (i
= 0; i
< n
; i
++) {
3570 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3571 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3572 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3578 else if (srcFormat
== GL_RGBA
) {
3580 const GLubyte
*src
= (const GLubyte
*) source
;
3582 for (i
= 0; i
< n
; i
++) {
3583 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3584 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3585 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3596 /* general solution begins here */
3598 GLint dstComponents
;
3599 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3600 GLint dstLuminanceIndex
, dstIntensityIndex
;
3601 GLfloat rgba
[MAX_WIDTH
][4];
3603 dstComponents
= _mesa_components_in_format( dstFormat
);
3604 /* source & dest image formats should have been error checked by now */
3605 assert(dstComponents
> 0);
3608 * Extract image data and convert to RGBA floats
3610 assert(n
<= MAX_WIDTH
);
3611 if (srcFormat
== GL_COLOR_INDEX
) {
3612 GLuint indexes
[MAX_WIDTH
];
3613 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3616 if (dstFormat
== GL_COLOR_INDEX
) {
3618 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3619 /* convert to GLchan and return */
3620 for (i
= 0; i
< n
; i
++) {
3621 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3626 /* Convert indexes to RGBA */
3627 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3628 shift_and_offset_ci(ctx
, n
, indexes
);
3630 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3633 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3634 * with color indexes.
3636 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3639 /* non-color index data */
3640 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3641 srcPacking
->SwapBytes
);
3644 /* Need to clamp if returning GLubytes or GLushorts */
3645 #if CHAN_TYPE != GL_FLOAT
3646 transferOps
|= IMAGE_CLAMP_BIT
;
3650 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3653 /* Now determine which color channels we need to produce.
3654 * And determine the dest index (offset) within each color tuple.
3656 switch (dstFormat
) {
3659 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3660 dstLuminanceIndex
= dstIntensityIndex
= -1;
3663 dstLuminanceIndex
= 0;
3664 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3665 dstIntensityIndex
= -1;
3667 case GL_LUMINANCE_ALPHA
:
3668 dstLuminanceIndex
= 0;
3670 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3671 dstIntensityIndex
= -1;
3674 dstIntensityIndex
= 0;
3675 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3676 dstLuminanceIndex
= -1;
3682 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3689 dstLuminanceIndex
= dstIntensityIndex
= -1;
3692 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
3697 /* Now return the GLchan data in the requested dstFormat */
3699 if (dstRedIndex
>= 0) {
3702 for (i
= 0; i
< n
; i
++) {
3703 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
3704 dst
+= dstComponents
;
3708 if (dstGreenIndex
>= 0) {
3711 for (i
= 0; i
< n
; i
++) {
3712 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
3713 dst
+= dstComponents
;
3717 if (dstBlueIndex
>= 0) {
3720 for (i
= 0; i
< n
; i
++) {
3721 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
3722 dst
+= dstComponents
;
3726 if (dstAlphaIndex
>= 0) {
3729 for (i
= 0; i
< n
; i
++) {
3730 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
3731 dst
+= dstComponents
;
3735 if (dstIntensityIndex
>= 0) {
3738 assert(dstIntensityIndex
== 0);
3739 assert(dstComponents
== 1);
3740 for (i
= 0; i
< n
; i
++) {
3741 /* Intensity comes from red channel */
3742 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
3746 if (dstLuminanceIndex
>= 0) {
3749 assert(dstLuminanceIndex
== 0);
3750 for (i
= 0; i
< n
; i
++) {
3751 /* Luminance comes from red channel */
3752 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
3753 dst
+= dstComponents
;
3761 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
3762 * instead of GLchan.
3765 _mesa_unpack_color_span_float( GLcontext
*ctx
,
3766 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
3767 GLenum srcFormat
, GLenum srcType
,
3768 const GLvoid
*source
,
3769 const struct gl_pixelstore_attrib
*srcPacking
,
3770 GLbitfield transferOps
)
3772 ASSERT(dstFormat
== GL_ALPHA
||
3773 dstFormat
== GL_LUMINANCE
||
3774 dstFormat
== GL_LUMINANCE_ALPHA
||
3775 dstFormat
== GL_INTENSITY
||
3776 dstFormat
== GL_RGB
||
3777 dstFormat
== GL_RGBA
||
3778 dstFormat
== GL_COLOR_INDEX
);
3780 ASSERT(srcFormat
== GL_RED
||
3781 srcFormat
== GL_GREEN
||
3782 srcFormat
== GL_BLUE
||
3783 srcFormat
== GL_ALPHA
||
3784 srcFormat
== GL_LUMINANCE
||
3785 srcFormat
== GL_LUMINANCE_ALPHA
||
3786 srcFormat
== GL_INTENSITY
||
3787 srcFormat
== GL_RGB
||
3788 srcFormat
== GL_BGR
||
3789 srcFormat
== GL_RGBA
||
3790 srcFormat
== GL_BGRA
||
3791 srcFormat
== GL_ABGR_EXT
||
3792 srcFormat
== GL_COLOR_INDEX
);
3794 ASSERT(srcType
== GL_BITMAP
||
3795 srcType
== GL_UNSIGNED_BYTE
||
3796 srcType
== GL_BYTE
||
3797 srcType
== GL_UNSIGNED_SHORT
||
3798 srcType
== GL_SHORT
||
3799 srcType
== GL_UNSIGNED_INT
||
3800 srcType
== GL_INT
||
3801 srcType
== GL_HALF_FLOAT_ARB
||
3802 srcType
== GL_FLOAT
||
3803 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3804 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3805 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3806 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3807 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3808 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3809 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3810 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3811 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3812 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3813 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3814 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3816 /* general solution, no special cases, yet */
3818 GLint dstComponents
;
3819 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3820 GLint dstLuminanceIndex
, dstIntensityIndex
;
3821 GLfloat rgba
[MAX_WIDTH
][4];
3823 dstComponents
= _mesa_components_in_format( dstFormat
);
3824 /* source & dest image formats should have been error checked by now */
3825 assert(dstComponents
> 0);
3828 * Extract image data and convert to RGBA floats
3830 assert(n
<= MAX_WIDTH
);
3831 if (srcFormat
== GL_COLOR_INDEX
) {
3832 GLuint indexes
[MAX_WIDTH
];
3833 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3836 if (dstFormat
== GL_COLOR_INDEX
) {
3838 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3839 /* convert to GLchan and return */
3840 for (i
= 0; i
< n
; i
++) {
3841 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3846 /* Convert indexes to RGBA */
3847 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3848 shift_and_offset_ci(ctx
, n
, indexes
);
3850 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3853 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3854 * with color indexes.
3856 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3859 /* non-color index data */
3860 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3861 srcPacking
->SwapBytes
);
3865 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3868 /* Now determine which color channels we need to produce.
3869 * And determine the dest index (offset) within each color tuple.
3871 switch (dstFormat
) {
3874 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3875 dstLuminanceIndex
= dstIntensityIndex
= -1;
3878 dstLuminanceIndex
= 0;
3879 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3880 dstIntensityIndex
= -1;
3882 case GL_LUMINANCE_ALPHA
:
3883 dstLuminanceIndex
= 0;
3885 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3886 dstIntensityIndex
= -1;
3889 dstIntensityIndex
= 0;
3890 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3891 dstLuminanceIndex
= -1;
3897 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3904 dstLuminanceIndex
= dstIntensityIndex
= -1;
3907 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
3911 /* Now pack results in the requested dstFormat */
3912 if (dstRedIndex
>= 0) {
3913 GLfloat
*dst
= dest
;
3915 for (i
= 0; i
< n
; i
++) {
3916 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3917 dst
+= dstComponents
;
3921 if (dstGreenIndex
>= 0) {
3922 GLfloat
*dst
= dest
;
3924 for (i
= 0; i
< n
; i
++) {
3925 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3926 dst
+= dstComponents
;
3930 if (dstBlueIndex
>= 0) {
3931 GLfloat
*dst
= dest
;
3933 for (i
= 0; i
< n
; i
++) {
3934 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3935 dst
+= dstComponents
;
3939 if (dstAlphaIndex
>= 0) {
3940 GLfloat
*dst
= dest
;
3942 for (i
= 0; i
< n
; i
++) {
3943 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3944 dst
+= dstComponents
;
3948 if (dstIntensityIndex
>= 0) {
3949 GLfloat
*dst
= dest
;
3951 assert(dstIntensityIndex
== 0);
3952 assert(dstComponents
== 1);
3953 for (i
= 0; i
< n
; i
++) {
3954 /* Intensity comes from red channel */
3955 dst
[i
] = rgba
[i
][RCOMP
];
3959 if (dstLuminanceIndex
>= 0) {
3960 GLfloat
*dst
= dest
;
3962 assert(dstLuminanceIndex
== 0);
3963 for (i
= 0; i
< n
; i
++) {
3964 /* Luminance comes from red channel */
3965 dst
[0] = rgba
[i
][RCOMP
];
3966 dst
+= dstComponents
;
3973 * Similar to _mesa_unpack_color_span_float(), but for dudv data instead of rgba,
3974 * directly return GLbyte data, no transfer ops apply.
3977 _mesa_unpack_dudv_span_byte( GLcontext
*ctx
,
3978 GLuint n
, GLenum dstFormat
, GLbyte dest
[],
3979 GLenum srcFormat
, GLenum srcType
,
3980 const GLvoid
*source
,
3981 const struct gl_pixelstore_attrib
*srcPacking
,
3982 GLbitfield transferOps
)
3984 ASSERT(dstFormat
== GL_DUDV_ATI
);
3985 ASSERT(srcFormat
== GL_DUDV_ATI
);
3987 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
3988 srcType
== GL_BYTE
||
3989 srcType
== GL_UNSIGNED_SHORT
||
3990 srcType
== GL_SHORT
||
3991 srcType
== GL_UNSIGNED_INT
||
3992 srcType
== GL_INT
||
3993 srcType
== GL_HALF_FLOAT_ARB
||
3994 srcType
== GL_FLOAT
);
3996 /* general solution */
3998 GLint dstComponents
;
3999 GLfloat rgba
[MAX_WIDTH
][4];
4003 dstComponents
= _mesa_components_in_format( dstFormat
);
4004 /* source & dest image formats should have been error checked by now */
4005 assert(dstComponents
> 0);
4008 * Extract image data and convert to RGBA floats
4010 assert(n
<= MAX_WIDTH
);
4011 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
4012 srcPacking
->SwapBytes
);
4015 /* Now determine which color channels we need to produce.
4016 * And determine the dest index (offset) within each color tuple.
4019 /* Now pack results in the requested dstFormat */
4020 for (i
= 0; i
< n
; i
++) {
4021 /* not sure - need clamp[-1,1] here? */
4022 dst
[0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
4023 dst
[1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
4024 dst
+= dstComponents
;
4030 * Unpack a row of color index data from a client buffer according to
4031 * the pixel unpacking parameters.
4032 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
4034 * Args: ctx - the context
4035 * n - number of pixels
4036 * dstType - destination data type
4037 * dest - destination array
4038 * srcType - source pixel type
4039 * source - source data pointer
4040 * srcPacking - pixel unpacking parameters
4041 * transferOps - the pixel transfer operations to apply
4044 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
4045 GLenum dstType
, GLvoid
*dest
,
4046 GLenum srcType
, const GLvoid
*source
,
4047 const struct gl_pixelstore_attrib
*srcPacking
,
4048 GLbitfield transferOps
)
4050 ASSERT(srcType
== GL_BITMAP
||
4051 srcType
== GL_UNSIGNED_BYTE
||
4052 srcType
== GL_BYTE
||
4053 srcType
== GL_UNSIGNED_SHORT
||
4054 srcType
== GL_SHORT
||
4055 srcType
== GL_UNSIGNED_INT
||
4056 srcType
== GL_INT
||
4057 srcType
== GL_HALF_FLOAT_ARB
||
4058 srcType
== GL_FLOAT
);
4060 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4061 dstType
== GL_UNSIGNED_SHORT
||
4062 dstType
== GL_UNSIGNED_INT
);
4065 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4068 * Try simple cases first
4070 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
4071 && dstType
== GL_UNSIGNED_BYTE
) {
4072 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
4074 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
4075 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
4076 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
4082 GLuint indexes
[MAX_WIDTH
];
4083 assert(n
<= MAX_WIDTH
);
4085 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
4089 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4091 /* convert to dest type */
4093 case GL_UNSIGNED_BYTE
:
4095 GLubyte
*dst
= (GLubyte
*) dest
;
4097 for (i
= 0; i
< n
; i
++) {
4098 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4102 case GL_UNSIGNED_SHORT
:
4104 GLuint
*dst
= (GLuint
*) dest
;
4106 for (i
= 0; i
< n
; i
++) {
4107 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4111 case GL_UNSIGNED_INT
:
4112 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4115 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
4122 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
4123 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
4124 const struct gl_pixelstore_attrib
*dstPacking
,
4125 GLbitfield transferOps
)
4127 GLuint indexes
[MAX_WIDTH
];
4129 ASSERT(n
<= MAX_WIDTH
);
4131 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4133 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
4134 /* make a copy of input */
4135 _mesa_memcpy(indexes
, source
, n
* sizeof(GLuint
));
4136 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4141 case GL_UNSIGNED_BYTE
:
4143 GLubyte
*dst
= (GLubyte
*) dest
;
4145 for (i
= 0; i
< n
; i
++) {
4146 *dst
++ = (GLubyte
) source
[i
];
4152 GLbyte
*dst
= (GLbyte
*) dest
;
4154 for (i
= 0; i
< n
; i
++) {
4155 dst
[i
] = (GLbyte
) source
[i
];
4159 case GL_UNSIGNED_SHORT
:
4161 GLushort
*dst
= (GLushort
*) dest
;
4163 for (i
= 0; i
< n
; i
++) {
4164 dst
[i
] = (GLushort
) source
[i
];
4166 if (dstPacking
->SwapBytes
) {
4167 _mesa_swap2( (GLushort
*) dst
, n
);
4173 GLshort
*dst
= (GLshort
*) dest
;
4175 for (i
= 0; i
< n
; i
++) {
4176 dst
[i
] = (GLshort
) source
[i
];
4178 if (dstPacking
->SwapBytes
) {
4179 _mesa_swap2( (GLushort
*) dst
, n
);
4183 case GL_UNSIGNED_INT
:
4185 GLuint
*dst
= (GLuint
*) dest
;
4187 for (i
= 0; i
< n
; i
++) {
4188 dst
[i
] = (GLuint
) source
[i
];
4190 if (dstPacking
->SwapBytes
) {
4191 _mesa_swap4( (GLuint
*) dst
, n
);
4197 GLint
*dst
= (GLint
*) dest
;
4199 for (i
= 0; i
< n
; i
++) {
4200 dst
[i
] = (GLint
) source
[i
];
4202 if (dstPacking
->SwapBytes
) {
4203 _mesa_swap4( (GLuint
*) dst
, n
);
4209 GLfloat
*dst
= (GLfloat
*) dest
;
4211 for (i
= 0; i
< n
; i
++) {
4212 dst
[i
] = (GLfloat
) source
[i
];
4214 if (dstPacking
->SwapBytes
) {
4215 _mesa_swap4( (GLuint
*) dst
, n
);
4219 case GL_HALF_FLOAT_ARB
:
4221 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4223 for (i
= 0; i
< n
; i
++) {
4224 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
4226 if (dstPacking
->SwapBytes
) {
4227 _mesa_swap2( (GLushort
*) dst
, n
);
4232 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4238 * Unpack a row of stencil data from a client buffer according to
4239 * the pixel unpacking parameters.
4240 * This is (or will be) used by glDrawPixels
4242 * Args: ctx - the context
4243 * n - number of pixels
4244 * dstType - destination data type
4245 * dest - destination array
4246 * srcType - source pixel type
4247 * source - source data pointer
4248 * srcPacking - pixel unpacking parameters
4249 * transferOps - apply offset/bias/lookup ops?
4252 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4253 GLenum dstType
, GLvoid
*dest
,
4254 GLenum srcType
, const GLvoid
*source
,
4255 const struct gl_pixelstore_attrib
*srcPacking
,
4256 GLbitfield transferOps
)
4258 ASSERT(srcType
== GL_BITMAP
||
4259 srcType
== GL_UNSIGNED_BYTE
||
4260 srcType
== GL_BYTE
||
4261 srcType
== GL_UNSIGNED_SHORT
||
4262 srcType
== GL_SHORT
||
4263 srcType
== GL_UNSIGNED_INT
||
4264 srcType
== GL_INT
||
4265 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
4266 srcType
== GL_HALF_FLOAT_ARB
||
4267 srcType
== GL_FLOAT
);
4269 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4270 dstType
== GL_UNSIGNED_SHORT
||
4271 dstType
== GL_UNSIGNED_INT
);
4273 /* only shift and offset apply to stencil */
4274 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
4277 * Try simple cases first
4279 if (transferOps
== 0 &&
4280 !ctx
->Pixel
.MapStencilFlag
&&
4281 srcType
== GL_UNSIGNED_BYTE
&&
4282 dstType
== GL_UNSIGNED_BYTE
) {
4283 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
4285 else if (transferOps
== 0 &&
4286 !ctx
->Pixel
.MapStencilFlag
&&
4287 srcType
== GL_UNSIGNED_INT
&&
4288 dstType
== GL_UNSIGNED_INT
&&
4289 !srcPacking
->SwapBytes
) {
4290 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
4296 GLuint indexes
[MAX_WIDTH
];
4297 assert(n
<= MAX_WIDTH
);
4299 extract_uint_indexes(n
, indexes
, GL_STENCIL_INDEX
, srcType
, source
,
4302 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
4303 /* shift and offset indexes */
4304 shift_and_offset_ci(ctx
, n
, indexes
);
4307 if (ctx
->Pixel
.MapStencilFlag
) {
4308 /* Apply stencil lookup table */
4309 const GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
4311 for (i
= 0; i
< n
; i
++) {
4312 indexes
[i
] = (GLuint
)ctx
->PixelMaps
.StoS
.Map
[ indexes
[i
] & mask
];
4316 /* convert to dest type */
4318 case GL_UNSIGNED_BYTE
:
4320 GLubyte
*dst
= (GLubyte
*) dest
;
4322 for (i
= 0; i
< n
; i
++) {
4323 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4327 case GL_UNSIGNED_SHORT
:
4329 GLuint
*dst
= (GLuint
*) dest
;
4331 for (i
= 0; i
< n
; i
++) {
4332 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4336 case GL_UNSIGNED_INT
:
4337 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4340 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
4347 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4348 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
4349 const struct gl_pixelstore_attrib
*dstPacking
)
4351 GLstencil stencil
[MAX_WIDTH
];
4353 ASSERT(n
<= MAX_WIDTH
);
4355 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
4356 ctx
->Pixel
.MapStencilFlag
) {
4357 /* make a copy of input */
4358 _mesa_memcpy(stencil
, source
, n
* sizeof(GLstencil
));
4359 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencil
);
4364 case GL_UNSIGNED_BYTE
:
4365 if (sizeof(GLstencil
) == 1) {
4366 _mesa_memcpy( dest
, source
, n
);
4369 GLubyte
*dst
= (GLubyte
*) dest
;
4372 dst
[i
] = (GLubyte
) source
[i
];
4378 GLbyte
*dst
= (GLbyte
*) dest
;
4381 dst
[i
] = (GLbyte
) (source
[i
] & 0x7f);
4385 case GL_UNSIGNED_SHORT
:
4387 GLushort
*dst
= (GLushort
*) dest
;
4390 dst
[i
] = (GLushort
) source
[i
];
4392 if (dstPacking
->SwapBytes
) {
4393 _mesa_swap2( (GLushort
*) dst
, n
);
4399 GLshort
*dst
= (GLshort
*) dest
;
4402 dst
[i
] = (GLshort
) source
[i
];
4404 if (dstPacking
->SwapBytes
) {
4405 _mesa_swap2( (GLushort
*) dst
, n
);
4409 case GL_UNSIGNED_INT
:
4411 GLuint
*dst
= (GLuint
*) dest
;
4414 dst
[i
] = (GLuint
) source
[i
];
4416 if (dstPacking
->SwapBytes
) {
4417 _mesa_swap4( (GLuint
*) dst
, n
);
4423 GLint
*dst
= (GLint
*) dest
;
4426 dst
[i
] = (GLint
) source
[i
];
4428 if (dstPacking
->SwapBytes
) {
4429 _mesa_swap4( (GLuint
*) dst
, n
);
4435 GLfloat
*dst
= (GLfloat
*) dest
;
4438 dst
[i
] = (GLfloat
) source
[i
];
4440 if (dstPacking
->SwapBytes
) {
4441 _mesa_swap4( (GLuint
*) dst
, n
);
4445 case GL_HALF_FLOAT_ARB
:
4447 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4450 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
4452 if (dstPacking
->SwapBytes
) {
4453 _mesa_swap2( (GLushort
*) dst
, n
);
4458 if (dstPacking
->LsbFirst
) {
4459 GLubyte
*dst
= (GLubyte
*) dest
;
4462 for (i
= 0; i
< n
; i
++) {
4465 *dst
|= ((source
[i
] != 0) << shift
);
4474 GLubyte
*dst
= (GLubyte
*) dest
;
4477 for (i
= 0; i
< n
; i
++) {
4480 *dst
|= ((source
[i
] != 0) << shift
);
4490 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4494 #define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT) \
4497 const GLTYPE *src = (const GLTYPE *)source; \
4498 for (i = 0; i < n; i++) { \
4499 GLTYPE value = src[i]; \
4500 if (srcPacking->SwapBytes) { \
4501 if (sizeof(GLTYPE) == 2) { \
4503 } else if (sizeof(GLTYPE) == 4) { \
4507 depthValues[i] = GLTYPE2FLOAT(value); \
4513 * Unpack a row of depth/z values from memory, returning GLushort, GLuint
4514 * or GLfloat values.
4515 * The glPixelTransfer (scale/bias) params will be applied.
4517 * \param dstType one of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT
4518 * \param depthMax max value for returned GLushort or GLuint values
4519 * (ignored for GLfloat).
4522 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
,
4523 GLenum dstType
, GLvoid
*dest
, GLuint depthMax
,
4524 GLenum srcType
, const GLvoid
*source
,
4525 const struct gl_pixelstore_attrib
*srcPacking
)
4527 GLfloat depthTemp
[MAX_WIDTH
], *depthValues
;
4528 GLboolean needClamp
= GL_FALSE
;
4530 /* Look for special cases first.
4531 * Not only are these faster, they're less prone to numeric conversion
4532 * problems. Otherwise, converting from an int type to a float then
4533 * back to an int type can introduce errors that will show up as
4534 * artifacts in things like depth peeling which uses glCopyTexImage.
4536 if (ctx
->Pixel
.DepthScale
== 1.0 && ctx
->Pixel
.DepthBias
== 0.0) {
4537 if (srcType
== GL_UNSIGNED_INT
&& dstType
== GL_UNSIGNED_SHORT
) {
4538 const GLuint
*src
= (const GLuint
*) source
;
4539 GLushort
*dst
= (GLushort
*) dest
;
4541 for (i
= 0; i
< n
; i
++) {
4542 dst
[i
] = src
[i
] >> 16;
4546 if (srcType
== GL_UNSIGNED_SHORT
4547 && dstType
== GL_UNSIGNED_INT
4548 && depthMax
== 0xffffffff) {
4549 const GLushort
*src
= (const GLushort
*) source
;
4550 GLuint
*dst
= (GLuint
*) dest
;
4552 for (i
= 0; i
< n
; i
++) {
4553 dst
[i
] = src
[i
] | (src
[i
] << 16);
4557 /* XXX may want to add additional cases here someday */
4560 /* general case path follows */
4562 if (dstType
== GL_FLOAT
) {
4563 depthValues
= (GLfloat
*) dest
;
4566 depthValues
= depthTemp
;
4569 /* Convert incoming values to GLfloat. Some conversions will require
4574 DEPTH_VALUES(GLbyte
, BYTE_TO_FLOAT
);
4575 needClamp
= GL_TRUE
;
4577 case GL_UNSIGNED_BYTE
:
4578 DEPTH_VALUES(GLubyte
, UBYTE_TO_FLOAT
);
4581 DEPTH_VALUES(GLshort
, SHORT_TO_FLOAT
);
4582 needClamp
= GL_TRUE
;
4584 case GL_UNSIGNED_SHORT
:
4585 DEPTH_VALUES(GLushort
, USHORT_TO_FLOAT
);
4588 DEPTH_VALUES(GLint
, INT_TO_FLOAT
);
4589 needClamp
= GL_TRUE
;
4591 case GL_UNSIGNED_INT
:
4592 DEPTH_VALUES(GLuint
, UINT_TO_FLOAT
);
4594 case GL_UNSIGNED_INT_24_8_EXT
: /* GL_EXT_packed_depth_stencil */
4595 if (dstType
== GL_UNSIGNED_INT_24_8_EXT
&&
4596 depthMax
== 0xffffff &&
4597 ctx
->Pixel
.DepthScale
== 1.0 &&
4598 ctx
->Pixel
.DepthBias
== 0.0) {
4599 const GLuint
*src
= (const GLuint
*) source
;
4600 GLuint
*zValues
= (GLuint
*) dest
;
4602 for (i
= 0; i
< n
; i
++) {
4603 GLuint value
= src
[i
];
4604 if (srcPacking
->SwapBytes
) {
4607 zValues
[i
] = value
& 0xffffff00;
4612 const GLuint
*src
= (const GLuint
*) source
;
4613 const GLfloat scale
= 1.0f
/ 0xffffff;
4615 for (i
= 0; i
< n
; i
++) {
4616 GLuint value
= src
[i
];
4617 if (srcPacking
->SwapBytes
) {
4620 depthValues
[i
] = (value
>> 8) * scale
;
4625 DEPTH_VALUES(GLfloat
, 1*);
4626 needClamp
= GL_TRUE
;
4628 case GL_HALF_FLOAT_ARB
:
4631 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
4632 for (i
= 0; i
< n
; i
++) {
4633 GLhalfARB value
= src
[i
];
4634 if (srcPacking
->SwapBytes
) {
4637 depthValues
[i
] = _mesa_half_to_float(value
);
4639 needClamp
= GL_TRUE
;
4643 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
4647 /* apply depth scale and bias */
4649 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
4650 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
4651 if (scale
!= 1.0 || bias
!= 0.0) {
4653 for (i
= 0; i
< n
; i
++) {
4654 depthValues
[i
] = depthValues
[i
] * scale
+ bias
;
4656 needClamp
= GL_TRUE
;
4660 /* clamp to [0, 1] */
4663 for (i
= 0; i
< n
; i
++) {
4664 depthValues
[i
] = (GLfloat
)CLAMP(depthValues
[i
], 0.0, 1.0);
4669 * Convert values to dstType
4671 if (dstType
== GL_UNSIGNED_INT
) {
4672 GLuint
*zValues
= (GLuint
*) dest
;
4674 if (depthMax
<= 0xffffff) {
4675 /* no overflow worries */
4676 for (i
= 0; i
< n
; i
++) {
4677 zValues
[i
] = (GLuint
) (depthValues
[i
] * (GLfloat
) depthMax
);
4681 /* need to use double precision to prevent overflow problems */
4682 for (i
= 0; i
< n
; i
++) {
4683 GLdouble z
= depthValues
[i
] * (GLfloat
) depthMax
;
4684 if (z
>= (GLdouble
) 0xffffffff)
4685 zValues
[i
] = 0xffffffff;
4687 zValues
[i
] = (GLuint
) z
;
4691 else if (dstType
== GL_UNSIGNED_SHORT
) {
4692 GLushort
*zValues
= (GLushort
*) dest
;
4694 ASSERT(depthMax
<= 0xffff);
4695 for (i
= 0; i
< n
; i
++) {
4696 zValues
[i
] = (GLushort
) (depthValues
[i
] * (GLfloat
) depthMax
);
4700 ASSERT(dstType
== GL_FLOAT
);
4701 /*ASSERT(depthMax == 1.0F);*/
4707 * Pack an array of depth values. The values are floats in [0,1].
4710 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
4711 GLenum dstType
, const GLfloat
*depthSpan
,
4712 const struct gl_pixelstore_attrib
*dstPacking
)
4714 GLfloat depthCopy
[MAX_WIDTH
];
4716 ASSERT(n
<= MAX_WIDTH
);
4718 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4719 _mesa_memcpy(depthCopy
, depthSpan
, n
* sizeof(GLfloat
));
4720 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4721 depthSpan
= depthCopy
;
4725 case GL_UNSIGNED_BYTE
:
4727 GLubyte
*dst
= (GLubyte
*) dest
;
4729 for (i
= 0; i
< n
; i
++) {
4730 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
4736 GLbyte
*dst
= (GLbyte
*) dest
;
4738 for (i
= 0; i
< n
; i
++) {
4739 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
4743 case GL_UNSIGNED_SHORT
:
4745 GLushort
*dst
= (GLushort
*) dest
;
4747 for (i
= 0; i
< n
; i
++) {
4748 CLAMPED_FLOAT_TO_USHORT(dst
[i
], depthSpan
[i
]);
4750 if (dstPacking
->SwapBytes
) {
4751 _mesa_swap2( (GLushort
*) dst
, n
);
4757 GLshort
*dst
= (GLshort
*) dest
;
4759 for (i
= 0; i
< n
; i
++) {
4760 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
4762 if (dstPacking
->SwapBytes
) {
4763 _mesa_swap2( (GLushort
*) dst
, n
);
4767 case GL_UNSIGNED_INT
:
4769 GLuint
*dst
= (GLuint
*) dest
;
4771 for (i
= 0; i
< n
; i
++) {
4772 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
4774 if (dstPacking
->SwapBytes
) {
4775 _mesa_swap4( (GLuint
*) dst
, n
);
4781 GLint
*dst
= (GLint
*) dest
;
4783 for (i
= 0; i
< n
; i
++) {
4784 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
4786 if (dstPacking
->SwapBytes
) {
4787 _mesa_swap4( (GLuint
*) dst
, n
);
4793 GLfloat
*dst
= (GLfloat
*) dest
;
4795 for (i
= 0; i
< n
; i
++) {
4796 dst
[i
] = depthSpan
[i
];
4798 if (dstPacking
->SwapBytes
) {
4799 _mesa_swap4( (GLuint
*) dst
, n
);
4803 case GL_HALF_FLOAT_ARB
:
4805 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4807 for (i
= 0; i
< n
; i
++) {
4808 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
4810 if (dstPacking
->SwapBytes
) {
4811 _mesa_swap2( (GLushort
*) dst
, n
);
4816 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
4823 * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
4826 _mesa_pack_depth_stencil_span(const GLcontext
*ctx
, GLuint n
, GLuint
*dest
,
4827 const GLfloat
*depthVals
,
4828 const GLstencil
*stencilVals
,
4829 const struct gl_pixelstore_attrib
*dstPacking
)
4831 GLfloat depthCopy
[MAX_WIDTH
];
4832 GLstencil stencilCopy
[MAX_WIDTH
];
4835 ASSERT(n
<= MAX_WIDTH
);
4837 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4838 _mesa_memcpy(depthCopy
, depthVals
, n
* sizeof(GLfloat
));
4839 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4840 depthVals
= depthCopy
;
4843 if (ctx
->Pixel
.IndexShift
||
4844 ctx
->Pixel
.IndexOffset
||
4845 ctx
->Pixel
.MapStencilFlag
) {
4846 _mesa_memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
4847 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencilCopy
);
4848 stencilVals
= stencilCopy
;
4851 for (i
= 0; i
< n
; i
++) {
4852 GLuint z
= (GLuint
) (depthVals
[i
] * 0xffffff);
4853 dest
[i
] = (z
<< 8) | (stencilVals
[i
] & 0xff);
4856 if (dstPacking
->SwapBytes
) {
4857 _mesa_swap4(dest
, n
);
4865 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
4866 * Return all image data in a contiguous block. This is used when we
4867 * compile glDrawPixels, glTexImage, etc into a display list. We
4868 * need a copy of the data in a standard format.
4871 _mesa_unpack_image( GLuint dimensions
,
4872 GLsizei width
, GLsizei height
, GLsizei depth
,
4873 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4874 const struct gl_pixelstore_attrib
*unpack
)
4876 GLint bytesPerRow
, compsPerRow
;
4877 GLboolean flipBytes
, swap2
, swap4
;
4880 return NULL
; /* not necessarily an error */
4882 if (width
<= 0 || height
<= 0 || depth
<= 0)
4883 return NULL
; /* generate error later */
4885 if (type
== GL_BITMAP
) {
4886 bytesPerRow
= (width
+ 7) >> 3;
4887 flipBytes
= unpack
->LsbFirst
;
4888 swap2
= swap4
= GL_FALSE
;
4892 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
4893 GLint components
= _mesa_components_in_format(format
);
4896 if (_mesa_type_is_packed(type
))
4899 if (bytesPerPixel
<= 0 || components
<= 0)
4900 return NULL
; /* bad format or type. generate error later */
4901 bytesPerRow
= bytesPerPixel
* width
;
4902 bytesPerComp
= bytesPerPixel
/ components
;
4903 flipBytes
= GL_FALSE
;
4904 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
4905 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
4906 compsPerRow
= components
* width
;
4907 assert(compsPerRow
>= width
);
4912 = (GLubyte
*) _mesa_malloc(bytesPerRow
* height
* depth
);
4916 return NULL
; /* generate GL_OUT_OF_MEMORY later */
4919 for (img
= 0; img
< depth
; img
++) {
4920 for (row
= 0; row
< height
; row
++) {
4921 const GLvoid
*src
= _mesa_image_address(dimensions
, unpack
, pixels
,
4922 width
, height
, format
, type
, img
, row
, 0);
4924 if ((type
== GL_BITMAP
) && (unpack
->SkipPixels
& 0x7)) {
4926 flipBytes
= GL_FALSE
;
4927 if (unpack
->LsbFirst
) {
4928 GLubyte srcMask
= 1 << (unpack
->SkipPixels
& 0x7);
4929 GLubyte dstMask
= 128;
4930 const GLubyte
*s
= src
;
4933 for (i
= 0; i
< width
; i
++) {
4937 if (srcMask
== 128) {
4942 srcMask
= srcMask
<< 1;
4950 dstMask
= dstMask
>> 1;
4955 GLubyte srcMask
= 128 >> (unpack
->SkipPixels
& 0x7);
4956 GLubyte dstMask
= 128;
4957 const GLubyte
*s
= src
;
4960 for (i
= 0; i
< width
; i
++) {
4969 srcMask
= srcMask
>> 1;
4977 dstMask
= dstMask
>> 1;
4983 _mesa_memcpy(dst
, src
, bytesPerRow
);
4986 /* byte flipping/swapping */
4988 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
4991 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
4994 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
5003 #endif /* _HAVE_FULL_GL */
5008 * Convert an array of RGBA colors from one datatype to another.
5009 * NOTE: src may equal dst. In that case, we use a temporary buffer.
5012 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
5013 GLenum dstType
, GLvoid
*dst
,
5014 GLuint count
, const GLubyte mask
[])
5016 GLuint tempBuffer
[MAX_WIDTH
][4];
5017 const GLboolean useTemp
= (src
== dst
);
5019 ASSERT(srcType
!= dstType
);
5022 case GL_UNSIGNED_BYTE
:
5023 if (dstType
== GL_UNSIGNED_SHORT
) {
5024 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5025 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5027 for (i
= 0; i
< count
; i
++) {
5028 if (!mask
|| mask
[i
]) {
5029 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
5030 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
5031 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
5032 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
5036 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5039 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5040 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5042 ASSERT(dstType
== GL_FLOAT
);
5043 for (i
= 0; i
< count
; i
++) {
5044 if (!mask
|| mask
[i
]) {
5045 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
5046 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
5047 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
5048 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
5052 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5055 case GL_UNSIGNED_SHORT
:
5056 if (dstType
== GL_UNSIGNED_BYTE
) {
5057 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5058 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5060 for (i
= 0; i
< count
; i
++) {
5061 if (!mask
|| mask
[i
]) {
5062 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
5063 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
5064 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
5065 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
5069 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5072 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5073 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5075 ASSERT(dstType
== GL_FLOAT
);
5076 for (i
= 0; i
< count
; i
++) {
5077 if (!mask
|| mask
[i
]) {
5078 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
5079 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
5080 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
5081 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
5085 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5089 if (dstType
== GL_UNSIGNED_BYTE
) {
5090 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5091 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5093 for (i
= 0; i
< count
; i
++) {
5094 if (!mask
|| mask
[i
]) {
5095 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
5096 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
5097 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
5098 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
5102 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5105 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5106 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5108 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
5109 for (i
= 0; i
< count
; i
++) {
5110 if (!mask
|| mask
[i
]) {
5111 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
5112 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
5113 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
5114 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
5118 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5122 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
5130 * Perform basic clipping for glDrawPixels. The image's position and size
5131 * and the unpack SkipPixels and SkipRows are adjusted so that the image
5132 * region is entirely within the window and scissor bounds.
5133 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
5134 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
5135 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
5137 * \return GL_TRUE if image is ready for drawing or
5138 * GL_FALSE if image was completely clipped away (draw nothing)
5141 _mesa_clip_drawpixels(const GLcontext
*ctx
,
5142 GLint
*destX
, GLint
*destY
,
5143 GLsizei
*width
, GLsizei
*height
,
5144 struct gl_pixelstore_attrib
*unpack
)
5146 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
5148 if (unpack
->RowLength
== 0) {
5149 unpack
->RowLength
= *width
;
5152 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
5153 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
5156 if (*destX
< buffer
->_Xmin
) {
5157 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
5158 *width
-= (buffer
->_Xmin
- *destX
);
5159 *destX
= buffer
->_Xmin
;
5161 /* right clipping */
5162 if (*destX
+ *width
> buffer
->_Xmax
)
5163 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
5168 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
5169 /* bottom clipping */
5170 if (*destY
< buffer
->_Ymin
) {
5171 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
5172 *height
-= (buffer
->_Ymin
- *destY
);
5173 *destY
= buffer
->_Ymin
;
5176 if (*destY
+ *height
> buffer
->_Ymax
)
5177 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
5179 else { /* upside down */
5181 if (*destY
> buffer
->_Ymax
) {
5182 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
5183 *height
-= (*destY
- buffer
->_Ymax
);
5184 *destY
= buffer
->_Ymax
;
5186 /* bottom clipping */
5187 if (*destY
- *height
< buffer
->_Ymin
)
5188 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
5189 /* adjust destY so it's the first row to write to */
5201 * Perform clipping for glReadPixels. The image's window position
5202 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
5203 * so that the image region is entirely within the window bounds.
5204 * Note: this is different from _mesa_clip_drawpixels() in that the
5205 * scissor box is ignored, and we use the bounds of the current readbuffer
5208 * \return GL_TRUE if image is ready for drawing or
5209 * GL_FALSE if image was completely clipped away (draw nothing)
5212 _mesa_clip_readpixels(const GLcontext
*ctx
,
5213 GLint
*srcX
, GLint
*srcY
,
5214 GLsizei
*width
, GLsizei
*height
,
5215 struct gl_pixelstore_attrib
*pack
)
5217 const GLframebuffer
*buffer
= ctx
->ReadBuffer
;
5219 if (pack
->RowLength
== 0) {
5220 pack
->RowLength
= *width
;
5225 pack
->SkipPixels
+= (0 - *srcX
);
5226 *width
-= (0 - *srcX
);
5229 /* right clipping */
5230 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
5231 *width
-= (*srcX
+ *width
- buffer
->Width
);
5236 /* bottom clipping */
5238 pack
->SkipRows
+= (0 - *srcY
);
5239 *height
-= (0 - *srcY
);
5243 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
5244 *height
-= (*srcY
+ *height
- buffer
->Height
);
5254 * Do clipping for a glCopyTexSubImage call.
5255 * The framebuffer source region might extend outside the framebuffer
5256 * bounds. Clip the source region against the framebuffer bounds and
5257 * adjust the texture/dest position and size accordingly.
5259 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
5262 _mesa_clip_copytexsubimage(const GLcontext
*ctx
,
5263 GLint
*destX
, GLint
*destY
,
5264 GLint
*srcX
, GLint
*srcY
,
5265 GLsizei
*width
, GLsizei
*height
)
5267 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
5268 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
5270 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
5271 srcX
, srcY
, width
, height
)) {
5272 *destX
= *destX
+ *srcX
- srcX0
;
5273 *destY
= *destY
+ *srcY
- srcY0
;
5285 * Clip the rectangle defined by (x, y, width, height) against the bounds
5286 * specified by [xmin, xmax) and [ymin, ymax).
5287 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
5290 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
5291 GLint xmax
, GLint ymax
,
5293 GLsizei
*width
, GLsizei
*height
)
5297 *width
-= (xmin
- *x
);
5301 /* right clipping */
5302 if (*x
+ *width
> xmax
)
5303 *width
-= (*x
+ *width
- xmax
);
5308 /* bottom (or top) clipping */
5310 *height
-= (ymin
- *y
);
5314 /* top (or bottom) clipping */
5315 if (*y
+ *height
> ymax
)
5316 *height
-= (*y
+ *height
- ymax
);