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
, GLboolean noClamp
)
1691 GLfloat luminance
[MAX_WIDTH
];
1692 const GLint comps
= _mesa_components_in_format(dstFormat
);
1695 if ((!noClamp
) && (dstType
!= GL_FLOAT
|| ctx
->Color
.ClampReadColor
== GL_TRUE
)) {
1696 /* need to clamp to [0, 1] */
1697 transferOps
|= IMAGE_CLAMP_BIT
;
1701 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
1702 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
1707 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
1708 /* compute luminance values */
1709 if (transferOps
& IMAGE_CLAMP_BIT
) {
1710 for (i
= 0; i
< n
; i
++) {
1711 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1712 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
1716 for (i
= 0; i
< n
; i
++) {
1717 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1723 * Pack/store the pixels. Ugh! Lots of cases!!!
1726 case GL_UNSIGNED_BYTE
:
1728 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1729 switch (dstFormat
) {
1732 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1736 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1740 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1744 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1748 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1750 case GL_LUMINANCE_ALPHA
:
1752 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1753 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1758 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1759 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1760 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1765 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1766 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1767 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1768 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1773 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1774 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1775 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1780 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1781 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1782 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1783 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1788 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1789 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1790 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1791 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1797 dst
[i
*2+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1798 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1802 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1808 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1809 switch (dstFormat
) {
1812 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1816 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1820 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1824 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1828 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1830 case GL_LUMINANCE_ALPHA
:
1832 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1833 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1838 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1839 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1840 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1845 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1846 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1847 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1848 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1853 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1854 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1855 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1860 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1861 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1862 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1863 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1868 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1869 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1870 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1871 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1877 dst
[i
*2+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1878 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1882 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1886 case GL_UNSIGNED_SHORT
:
1888 GLushort
*dst
= (GLushort
*) dstAddr
;
1889 switch (dstFormat
) {
1892 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][RCOMP
]);
1896 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][GCOMP
]);
1900 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][BCOMP
]);
1904 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][ACOMP
]);
1908 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
], luminance
[i
]);
1910 case GL_LUMINANCE_ALPHA
:
1912 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
*2+0], luminance
[i
]);
1913 CLAMPED_FLOAT_TO_USHORT(dst
[i
*2+1], rgba
[i
][ACOMP
]);
1918 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][RCOMP
]);
1919 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1920 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][BCOMP
]);
1925 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][RCOMP
]);
1926 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1927 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][BCOMP
]);
1928 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1933 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][BCOMP
]);
1934 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1935 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][RCOMP
]);
1940 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][BCOMP
]);
1941 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1942 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][RCOMP
]);
1943 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1948 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][ACOMP
]);
1949 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][BCOMP
]);
1950 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][GCOMP
]);
1951 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][RCOMP
]);
1957 dst
[i
*2+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1958 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1962 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1968 GLshort
*dst
= (GLshort
*) dstAddr
;
1969 switch (dstFormat
) {
1972 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1976 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1980 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1984 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1988 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
1990 case GL_LUMINANCE_ALPHA
:
1992 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
1993 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1998 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1999 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2000 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2005 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2006 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2007 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2008 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2013 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2014 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2015 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2020 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2021 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2022 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2023 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2028 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2029 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2030 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2031 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2037 dst
[i
*2+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2038 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2042 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2046 case GL_UNSIGNED_INT
:
2048 GLuint
*dst
= (GLuint
*) dstAddr
;
2049 switch (dstFormat
) {
2052 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2056 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2060 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2064 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2068 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
2070 case GL_LUMINANCE_ALPHA
:
2072 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
2073 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2078 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2079 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2080 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2085 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2086 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2087 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2088 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2093 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2094 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2095 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2100 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2101 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2102 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2103 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2108 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2109 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2110 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2111 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2117 dst
[i
*2+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2118 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2122 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2128 GLint
*dst
= (GLint
*) dstAddr
;
2129 switch (dstFormat
) {
2132 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2136 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2140 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2144 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2148 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
2150 case GL_LUMINANCE_ALPHA
:
2152 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
2153 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2158 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2159 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2160 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2165 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2166 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2167 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2168 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2173 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2174 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2175 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2180 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2181 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2182 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2183 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2188 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2189 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2190 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2191 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2197 dst
[i
*2+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2198 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2202 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2208 GLfloat
*dst
= (GLfloat
*) dstAddr
;
2209 switch (dstFormat
) {
2212 dst
[i
] = rgba
[i
][RCOMP
];
2216 dst
[i
] = rgba
[i
][GCOMP
];
2220 dst
[i
] = rgba
[i
][BCOMP
];
2224 dst
[i
] = rgba
[i
][ACOMP
];
2228 dst
[i
] = luminance
[i
];
2230 case GL_LUMINANCE_ALPHA
:
2232 dst
[i
*2+0] = luminance
[i
];
2233 dst
[i
*2+1] = rgba
[i
][ACOMP
];
2238 dst
[i
*3+0] = rgba
[i
][RCOMP
];
2239 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2240 dst
[i
*3+2] = rgba
[i
][BCOMP
];
2245 dst
[i
*4+0] = rgba
[i
][RCOMP
];
2246 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2247 dst
[i
*4+2] = rgba
[i
][BCOMP
];
2248 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2253 dst
[i
*3+0] = rgba
[i
][BCOMP
];
2254 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2255 dst
[i
*3+2] = rgba
[i
][RCOMP
];
2260 dst
[i
*4+0] = rgba
[i
][BCOMP
];
2261 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2262 dst
[i
*4+2] = rgba
[i
][RCOMP
];
2263 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2268 dst
[i
*4+0] = rgba
[i
][ACOMP
];
2269 dst
[i
*4+1] = rgba
[i
][BCOMP
];
2270 dst
[i
*4+2] = rgba
[i
][GCOMP
];
2271 dst
[i
*4+3] = rgba
[i
][RCOMP
];
2277 dst
[i
*2+0] = rgba
[i
][RCOMP
];
2278 dst
[i
*2+1] = rgba
[i
][GCOMP
];
2282 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2286 case GL_HALF_FLOAT_ARB
:
2288 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
2289 switch (dstFormat
) {
2292 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2296 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2300 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2304 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2308 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
2310 case GL_LUMINANCE_ALPHA
:
2312 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
2313 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2318 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2319 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2320 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2325 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2326 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2327 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2328 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2333 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2334 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2335 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2340 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2341 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2342 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2343 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2348 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2349 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2350 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2351 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2357 dst
[i
*2+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2358 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2362 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2366 case GL_UNSIGNED_BYTE_3_3_2
:
2367 if (dstFormat
== GL_RGB
) {
2368 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2370 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 7.0F
) << 5)
2371 | (IROUND(rgba
[i
][GCOMP
] * 7.0F
) << 2)
2372 | (IROUND(rgba
[i
][BCOMP
] * 3.0F
) );
2376 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2377 if (dstFormat
== GL_RGB
) {
2378 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2380 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 7.0F
) )
2381 | (IROUND(rgba
[i
][GCOMP
] * 7.0F
) << 3)
2382 | (IROUND(rgba
[i
][BCOMP
] * 3.0F
) << 6);
2386 case GL_UNSIGNED_SHORT_5_6_5
:
2387 if (dstFormat
== GL_RGB
) {
2388 GLushort
*dst
= (GLushort
*) dstAddr
;
2390 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 11)
2391 | (IROUND(rgba
[i
][GCOMP
] * 63.0F
) << 5)
2392 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) );
2396 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2397 if (dstFormat
== GL_RGB
) {
2398 GLushort
*dst
= (GLushort
*) dstAddr
;
2400 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) )
2401 | (IROUND(rgba
[i
][GCOMP
] * 63.0F
) << 5)
2402 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 11);
2406 case GL_UNSIGNED_SHORT_4_4_4_4
:
2407 if (dstFormat
== GL_RGBA
) {
2408 GLushort
*dst
= (GLushort
*) dstAddr
;
2410 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 12)
2411 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2412 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 4)
2413 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) );
2416 else if (dstFormat
== GL_BGRA
) {
2417 GLushort
*dst
= (GLushort
*) dstAddr
;
2419 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 12)
2420 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2421 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 4)
2422 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) );
2425 else if (dstFormat
== GL_ABGR_EXT
) {
2426 GLushort
*dst
= (GLushort
*) dstAddr
;
2428 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12)
2429 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 8)
2430 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2431 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) );
2435 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2436 if (dstFormat
== GL_RGBA
) {
2437 GLushort
*dst
= (GLushort
*) dstAddr
;
2439 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 15.0F
) )
2440 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2441 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 8)
2442 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12);
2445 else if (dstFormat
== GL_BGRA
) {
2446 GLushort
*dst
= (GLushort
*) dstAddr
;
2448 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 15.0F
) )
2449 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2450 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 8)
2451 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12);
2454 else if (dstFormat
== GL_ABGR_EXT
) {
2455 GLushort
*dst
= (GLushort
*) dstAddr
;
2457 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 15.0F
) )
2458 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 4)
2459 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2460 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 12);
2464 case GL_UNSIGNED_SHORT_5_5_5_1
:
2465 if (dstFormat
== GL_RGBA
) {
2466 GLushort
*dst
= (GLushort
*) dstAddr
;
2468 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 11)
2469 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 6)
2470 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 1)
2471 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) );
2474 else if (dstFormat
== GL_BGRA
) {
2475 GLushort
*dst
= (GLushort
*) dstAddr
;
2477 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 11)
2478 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 6)
2479 | (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 1)
2480 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) );
2483 else if (dstFormat
== GL_ABGR_EXT
) {
2484 GLushort
*dst
= (GLushort
*) dstAddr
;
2486 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 31.0F
) << 11)
2487 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 6)
2488 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 1)
2489 | (IROUND(rgba
[i
][RCOMP
] * 1.0F
) );
2493 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2494 if (dstFormat
== GL_RGBA
) {
2495 GLushort
*dst
= (GLushort
*) dstAddr
;
2497 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) )
2498 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 5)
2499 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 10)
2500 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) << 15);
2503 else if (dstFormat
== GL_BGRA
) {
2504 GLushort
*dst
= (GLushort
*) dstAddr
;
2506 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 31.0F
) )
2507 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 5)
2508 | (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 10)
2509 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) << 15);
2512 else if (dstFormat
== GL_ABGR_EXT
) {
2513 GLushort
*dst
= (GLushort
*) dstAddr
;
2515 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 31.0F
) )
2516 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 5)
2517 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 10)
2518 | (IROUND(rgba
[i
][RCOMP
] * 1.0F
) << 15);
2522 case GL_UNSIGNED_INT_8_8_8_8
:
2523 if (dstFormat
== GL_RGBA
) {
2524 GLuint
*dst
= (GLuint
*) dstAddr
;
2526 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 255.F
) << 24)
2527 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 16)
2528 | (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 8)
2529 | (IROUND(rgba
[i
][ACOMP
] * 255.F
) );
2532 else if (dstFormat
== GL_BGRA
) {
2533 GLuint
*dst
= (GLuint
*) dstAddr
;
2535 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 24)
2536 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 16)
2537 | (IROUND(rgba
[i
][RCOMP
] * 255.F
) << 8)
2538 | (IROUND(rgba
[i
][ACOMP
] * 255.F
) );
2541 else if (dstFormat
== GL_ABGR_EXT
) {
2542 GLuint
*dst
= (GLuint
*) dstAddr
;
2544 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 255.F
) << 24)
2545 | (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 16)
2546 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 8)
2547 | (IROUND(rgba
[i
][RCOMP
] * 255.F
) );
2551 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2552 if (dstFormat
== GL_RGBA
) {
2553 GLuint
*dst
= (GLuint
*) dstAddr
;
2555 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 255.0F
) )
2556 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 8)
2557 | (IROUND(rgba
[i
][BCOMP
] * 255.0F
) << 16)
2558 | (IROUND(rgba
[i
][ACOMP
] * 255.0F
) << 24);
2561 else if (dstFormat
== GL_BGRA
) {
2562 GLuint
*dst
= (GLuint
*) dstAddr
;
2564 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 255.0F
) )
2565 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 8)
2566 | (IROUND(rgba
[i
][RCOMP
] * 255.0F
) << 16)
2567 | (IROUND(rgba
[i
][ACOMP
] * 255.0F
) << 24);
2570 else if (dstFormat
== GL_ABGR_EXT
) {
2571 GLuint
*dst
= (GLuint
*) dstAddr
;
2573 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 255.0F
) )
2574 | (IROUND(rgba
[i
][BCOMP
] * 255.0F
) << 8)
2575 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 16)
2576 | (IROUND(rgba
[i
][RCOMP
] * 255.0F
) << 24);
2580 case GL_UNSIGNED_INT_10_10_10_2
:
2581 if (dstFormat
== GL_RGBA
) {
2582 GLuint
*dst
= (GLuint
*) dstAddr
;
2584 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 22)
2585 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 12)
2586 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 2)
2587 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) );
2590 else if (dstFormat
== GL_BGRA
) {
2591 GLuint
*dst
= (GLuint
*) dstAddr
;
2593 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 22)
2594 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 12)
2595 | (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 2)
2596 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) );
2599 else if (dstFormat
== GL_ABGR_EXT
) {
2600 GLuint
*dst
= (GLuint
*) dstAddr
;
2602 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 1023.0F
) << 22)
2603 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 12)
2604 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 2)
2605 | (IROUND(rgba
[i
][RCOMP
] * 3.0F
) );
2609 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2610 if (dstFormat
== GL_RGBA
) {
2611 GLuint
*dst
= (GLuint
*) dstAddr
;
2613 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) )
2614 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 10)
2615 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 20)
2616 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) << 30);
2619 else if (dstFormat
== GL_BGRA
) {
2620 GLuint
*dst
= (GLuint
*) dstAddr
;
2622 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) )
2623 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 10)
2624 | (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 20)
2625 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) << 30);
2628 else if (dstFormat
== GL_ABGR_EXT
) {
2629 GLuint
*dst
= (GLuint
*) dstAddr
;
2631 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 1023.0F
) )
2632 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 10)
2633 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 20)
2634 | (IROUND(rgba
[i
][RCOMP
] * 3.0F
) << 30);
2639 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
2643 if (dstPacking
->SwapBytes
) {
2644 GLint swapSize
= _mesa_sizeof_packed_type(dstType
);
2645 if (swapSize
== 2) {
2646 if (dstPacking
->SwapBytes
) {
2647 _mesa_swap2((GLushort
*) dstAddr
, n
* comps
);
2650 else if (swapSize
== 4) {
2651 if (dstPacking
->SwapBytes
) {
2652 _mesa_swap4((GLuint
*) dstAddr
, n
* comps
);
2659 #define SWAP2BYTE(VALUE) \
2661 GLubyte *bytes = (GLubyte *) &(VALUE); \
2662 GLubyte tmp = bytes[0]; \
2663 bytes[0] = bytes[1]; \
2667 #define SWAP4BYTE(VALUE) \
2669 GLubyte *bytes = (GLubyte *) &(VALUE); \
2670 GLubyte tmp = bytes[0]; \
2671 bytes[0] = bytes[3]; \
2674 bytes[1] = bytes[2]; \
2680 extract_uint_indexes(GLuint n
, GLuint indexes
[],
2681 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2682 const struct gl_pixelstore_attrib
*unpack
)
2684 ASSERT(srcFormat
== GL_COLOR_INDEX
|| srcFormat
== GL_STENCIL_INDEX
);
2686 ASSERT(srcType
== GL_BITMAP
||
2687 srcType
== GL_UNSIGNED_BYTE
||
2688 srcType
== GL_BYTE
||
2689 srcType
== GL_UNSIGNED_SHORT
||
2690 srcType
== GL_SHORT
||
2691 srcType
== GL_UNSIGNED_INT
||
2692 srcType
== GL_INT
||
2693 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
2694 srcType
== GL_HALF_FLOAT_ARB
||
2695 srcType
== GL_FLOAT
);
2700 GLubyte
*ubsrc
= (GLubyte
*) src
;
2701 if (unpack
->LsbFirst
) {
2702 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
2704 for (i
= 0; i
< n
; i
++) {
2705 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2716 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
2718 for (i
= 0; i
< n
; i
++) {
2719 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2731 case GL_UNSIGNED_BYTE
:
2734 const GLubyte
*s
= (const GLubyte
*) src
;
2735 for (i
= 0; i
< n
; i
++)
2742 const GLbyte
*s
= (const GLbyte
*) src
;
2743 for (i
= 0; i
< n
; i
++)
2747 case GL_UNSIGNED_SHORT
:
2750 const GLushort
*s
= (const GLushort
*) src
;
2751 if (unpack
->SwapBytes
) {
2752 for (i
= 0; i
< n
; i
++) {
2753 GLushort value
= s
[i
];
2759 for (i
= 0; i
< n
; i
++)
2767 const GLshort
*s
= (const GLshort
*) src
;
2768 if (unpack
->SwapBytes
) {
2769 for (i
= 0; i
< n
; i
++) {
2770 GLshort value
= s
[i
];
2776 for (i
= 0; i
< n
; i
++)
2781 case GL_UNSIGNED_INT
:
2784 const GLuint
*s
= (const GLuint
*) src
;
2785 if (unpack
->SwapBytes
) {
2786 for (i
= 0; i
< n
; i
++) {
2787 GLuint value
= s
[i
];
2793 for (i
= 0; i
< n
; i
++)
2801 const GLint
*s
= (const GLint
*) src
;
2802 if (unpack
->SwapBytes
) {
2803 for (i
= 0; i
< n
; i
++) {
2810 for (i
= 0; i
< n
; i
++)
2818 const GLfloat
*s
= (const GLfloat
*) src
;
2819 if (unpack
->SwapBytes
) {
2820 for (i
= 0; i
< n
; i
++) {
2821 GLfloat value
= s
[i
];
2823 indexes
[i
] = (GLuint
) value
;
2827 for (i
= 0; i
< n
; i
++)
2828 indexes
[i
] = (GLuint
) s
[i
];
2832 case GL_HALF_FLOAT_ARB
:
2835 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
2836 if (unpack
->SwapBytes
) {
2837 for (i
= 0; i
< n
; i
++) {
2838 GLhalfARB value
= s
[i
];
2840 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
2844 for (i
= 0; i
< n
; i
++)
2845 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
2849 case GL_UNSIGNED_INT_24_8_EXT
:
2852 const GLuint
*s
= (const GLuint
*) src
;
2853 if (unpack
->SwapBytes
) {
2854 for (i
= 0; i
< n
; i
++) {
2855 GLuint value
= s
[i
];
2857 indexes
[i
] = value
& 0xff; /* lower 8 bits */
2861 for (i
= 0; i
< n
; i
++)
2862 indexes
[i
] = s
[i
] & 0xfff; /* lower 8 bits */
2868 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2875 * This function extracts floating point RGBA values from arbitrary
2876 * image data. srcFormat and srcType are the format and type parameters
2877 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2879 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2880 * implements the "Conversion to floating point", "Conversion to RGB",
2881 * and "Final Expansion to RGBA" operations.
2883 * Args: n - number of pixels
2884 * rgba - output colors
2885 * srcFormat - format of incoming data
2886 * srcType - data type of incoming data
2887 * src - source data pointer
2888 * swapBytes - perform byteswapping of incoming data?
2891 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2892 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2893 GLboolean swapBytes
)
2895 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2897 GLint rComp
, bComp
, gComp
, aComp
;
2899 ASSERT(srcFormat
== GL_RED
||
2900 srcFormat
== GL_GREEN
||
2901 srcFormat
== GL_BLUE
||
2902 srcFormat
== GL_ALPHA
||
2903 srcFormat
== GL_LUMINANCE
||
2904 srcFormat
== GL_LUMINANCE_ALPHA
||
2905 srcFormat
== GL_INTENSITY
||
2906 srcFormat
== GL_RGB
||
2907 srcFormat
== GL_BGR
||
2908 srcFormat
== GL_RGBA
||
2909 srcFormat
== GL_BGRA
||
2910 srcFormat
== GL_ABGR_EXT
||
2911 srcFormat
== GL_DUDV_ATI
);
2913 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2914 srcType
== GL_BYTE
||
2915 srcType
== GL_UNSIGNED_SHORT
||
2916 srcType
== GL_SHORT
||
2917 srcType
== GL_UNSIGNED_INT
||
2918 srcType
== GL_INT
||
2919 srcType
== GL_HALF_FLOAT_ARB
||
2920 srcType
== GL_FLOAT
||
2921 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2922 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2923 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2924 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2925 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2926 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2927 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2928 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2929 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2930 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2931 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2932 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2934 rComp
= gComp
= bComp
= aComp
= -1;
2936 switch (srcFormat
) {
2939 greenIndex
= blueIndex
= alphaIndex
= -1;
2944 redIndex
= blueIndex
= alphaIndex
= -1;
2949 redIndex
= greenIndex
= alphaIndex
= -1;
2953 redIndex
= greenIndex
= blueIndex
= -1;
2958 redIndex
= greenIndex
= blueIndex
= 0;
2962 case GL_LUMINANCE_ALPHA
:
2963 redIndex
= greenIndex
= blueIndex
= 0;
2968 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
3034 _mesa_problem(NULL
, "bad srcFormat in extract float data");
3039 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
3040 if ((INDEX) < 0) { \
3042 for (i = 0; i < n; i++) { \
3043 rgba[i][CHANNEL] = DEFAULT; \
3046 else if (swapBytes) { \
3047 const TYPE *s = (const TYPE *) src; \
3049 for (i = 0; i < n; i++) { \
3050 TYPE value = s[INDEX]; \
3051 if (sizeof(TYPE) == 2) { \
3054 else if (sizeof(TYPE) == 4) { \
3057 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
3062 const TYPE *s = (const TYPE *) src; \
3064 for (i = 0; i < n; i++) { \
3065 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
3071 case GL_UNSIGNED_BYTE
:
3072 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3073 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3074 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3075 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3078 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3079 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3080 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3081 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
3083 case GL_UNSIGNED_SHORT
:
3084 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3085 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3086 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3087 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
3090 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3091 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3092 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3093 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
3095 case GL_UNSIGNED_INT
:
3096 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3097 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3098 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3099 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
3102 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3103 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3104 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3105 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
3108 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3109 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3110 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3111 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
3113 case GL_HALF_FLOAT_ARB
:
3114 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3115 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3116 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3117 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
3119 case GL_UNSIGNED_BYTE_3_3_2
:
3121 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3123 for (i
= 0; i
< n
; i
++) {
3124 GLubyte p
= ubsrc
[i
];
3125 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
3126 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
3127 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
3128 rgba
[i
][aComp
] = 1.0F
;
3132 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3134 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3136 for (i
= 0; i
< n
; i
++) {
3137 GLubyte p
= ubsrc
[i
];
3138 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
3139 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
3140 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
3141 rgba
[i
][aComp
] = 1.0F
;
3145 case GL_UNSIGNED_SHORT_5_6_5
:
3147 const GLushort
*ussrc
= (const GLushort
*) src
;
3149 for (i
= 0; i
< n
; i
++) {
3150 GLushort p
= ussrc
[i
];
3152 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3153 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3154 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3155 rgba
[i
][aComp
] = 1.0F
;
3159 const GLushort
*ussrc
= (const GLushort
*) src
;
3161 for (i
= 0; i
< n
; i
++) {
3162 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 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3172 const GLushort
*ussrc
= (const GLushort
*) src
;
3174 for (i
= 0; i
< n
; i
++) {
3175 GLushort p
= ussrc
[i
];
3177 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3178 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3179 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3180 rgba
[i
][aComp
] = 1.0F
;
3184 const GLushort
*ussrc
= (const GLushort
*) src
;
3186 for (i
= 0; i
< n
; i
++) {
3187 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 case GL_UNSIGNED_SHORT_4_4_4_4
:
3197 const GLushort
*ussrc
= (const GLushort
*) src
;
3199 for (i
= 0; i
< n
; i
++) {
3200 GLushort p
= ussrc
[i
];
3202 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3203 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3204 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3205 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3209 const GLushort
*ussrc
= (const GLushort
*) src
;
3211 for (i
= 0; i
< n
; i
++) {
3212 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 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3222 const GLushort
*ussrc
= (const GLushort
*) src
;
3224 for (i
= 0; i
< n
; i
++) {
3225 GLushort p
= ussrc
[i
];
3227 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3228 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3229 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3230 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3234 const GLushort
*ussrc
= (const GLushort
*) src
;
3236 for (i
= 0; i
< n
; i
++) {
3237 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 case GL_UNSIGNED_SHORT_5_5_5_1
:
3247 const GLushort
*ussrc
= (const GLushort
*) src
;
3249 for (i
= 0; i
< n
; i
++) {
3250 GLushort p
= ussrc
[i
];
3252 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3253 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3254 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3255 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3259 const GLushort
*ussrc
= (const GLushort
*) src
;
3261 for (i
= 0; i
< n
; i
++) {
3262 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 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3272 const GLushort
*ussrc
= (const GLushort
*) src
;
3274 for (i
= 0; i
< n
; i
++) {
3275 GLushort p
= ussrc
[i
];
3277 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3278 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3279 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3280 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3284 const GLushort
*ussrc
= (const GLushort
*) src
;
3286 for (i
= 0; i
< n
; i
++) {
3287 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 case GL_UNSIGNED_INT_8_8_8_8
:
3297 const GLuint
*uisrc
= (const GLuint
*) src
;
3299 for (i
= 0; i
< n
; i
++) {
3300 GLuint p
= uisrc
[i
];
3301 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3302 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3303 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3304 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
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
>> 24) );
3313 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3314 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3315 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3319 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3321 const GLuint
*uisrc
= (const GLuint
*) src
;
3323 for (i
= 0; i
< n
; i
++) {
3324 GLuint p
= uisrc
[i
];
3325 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3326 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3327 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3328 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
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
) & 0xff);
3337 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3338 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3339 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3343 case GL_UNSIGNED_INT_10_10_10_2
:
3345 const GLuint
*uisrc
= (const GLuint
*) src
;
3347 for (i
= 0; i
< n
; i
++) {
3348 GLuint p
= uisrc
[i
];
3350 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3351 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3352 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3353 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3357 const GLuint
*uisrc
= (const GLuint
*) src
;
3359 for (i
= 0; i
< n
; i
++) {
3360 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 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3370 const GLuint
*uisrc
= (const GLuint
*) src
;
3372 for (i
= 0; i
< n
; i
++) {
3373 GLuint p
= uisrc
[i
];
3375 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3376 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3377 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3378 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3382 const GLuint
*uisrc
= (const GLuint
*) src
;
3384 for (i
= 0; i
< n
; i
++) {
3385 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
);
3394 _mesa_problem(NULL
, "bad srcType in extract float data");
3401 * Unpack a row of color image data from a client buffer according to
3402 * the pixel unpacking parameters.
3403 * Return GLchan values in the specified dest image format.
3404 * This is used by glDrawPixels and glTexImage?D().
3405 * \param ctx - the context
3406 * n - number of pixels in the span
3407 * dstFormat - format of destination color array
3408 * dest - the destination color array
3409 * srcFormat - source image format
3410 * srcType - source image data type
3411 * source - source image pointer
3412 * srcPacking - pixel unpacking parameters
3413 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
3415 * XXX perhaps expand this to process whole images someday.
3418 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
3419 GLuint n
, GLenum dstFormat
, GLchan dest
[],
3420 GLenum srcFormat
, GLenum srcType
,
3421 const GLvoid
*source
,
3422 const struct gl_pixelstore_attrib
*srcPacking
,
3423 GLbitfield transferOps
)
3425 ASSERT(dstFormat
== GL_ALPHA
||
3426 dstFormat
== GL_LUMINANCE
||
3427 dstFormat
== GL_LUMINANCE_ALPHA
||
3428 dstFormat
== GL_INTENSITY
||
3429 dstFormat
== GL_RGB
||
3430 dstFormat
== GL_RGBA
||
3431 dstFormat
== GL_COLOR_INDEX
);
3433 ASSERT(srcFormat
== GL_RED
||
3434 srcFormat
== GL_GREEN
||
3435 srcFormat
== GL_BLUE
||
3436 srcFormat
== GL_ALPHA
||
3437 srcFormat
== GL_LUMINANCE
||
3438 srcFormat
== GL_LUMINANCE_ALPHA
||
3439 srcFormat
== GL_INTENSITY
||
3440 srcFormat
== GL_RGB
||
3441 srcFormat
== GL_BGR
||
3442 srcFormat
== GL_RGBA
||
3443 srcFormat
== GL_BGRA
||
3444 srcFormat
== GL_ABGR_EXT
||
3445 srcFormat
== GL_COLOR_INDEX
);
3447 ASSERT(srcType
== GL_BITMAP
||
3448 srcType
== GL_UNSIGNED_BYTE
||
3449 srcType
== GL_BYTE
||
3450 srcType
== GL_UNSIGNED_SHORT
||
3451 srcType
== GL_SHORT
||
3452 srcType
== GL_UNSIGNED_INT
||
3453 srcType
== GL_INT
||
3454 srcType
== GL_HALF_FLOAT_ARB
||
3455 srcType
== GL_FLOAT
||
3456 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3457 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3458 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3459 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3460 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3461 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3462 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3463 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3464 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3465 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3466 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3467 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3469 /* Try simple cases first */
3470 if (transferOps
== 0) {
3471 if (srcType
== CHAN_TYPE
) {
3472 if (dstFormat
== GL_RGBA
) {
3473 if (srcFormat
== GL_RGBA
) {
3474 _mesa_memcpy( dest
, source
, n
* 4 * sizeof(GLchan
) );
3477 else if (srcFormat
== GL_RGB
) {
3479 const GLchan
*src
= (const GLchan
*) source
;
3481 for (i
= 0; i
< n
; i
++) {
3492 else if (dstFormat
== GL_RGB
) {
3493 if (srcFormat
== GL_RGB
) {
3494 _mesa_memcpy( dest
, source
, n
* 3 * sizeof(GLchan
) );
3497 else if (srcFormat
== GL_RGBA
) {
3499 const GLchan
*src
= (const GLchan
*) source
;
3501 for (i
= 0; i
< n
; i
++) {
3511 else if (dstFormat
== srcFormat
) {
3512 GLint comps
= _mesa_components_in_format(srcFormat
);
3514 _mesa_memcpy( dest
, source
, n
* comps
* sizeof(GLchan
) );
3519 * Common situation, loading 8bit RGBA/RGB source images
3520 * into 16/32 bit destination. (OSMesa16/32)
3522 else if (srcType
== GL_UNSIGNED_BYTE
) {
3523 if (dstFormat
== GL_RGBA
) {
3524 if (srcFormat
== GL_RGB
) {
3526 const GLubyte
*src
= (const GLubyte
*) source
;
3528 for (i
= 0; i
< n
; i
++) {
3529 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3530 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3531 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3538 else if (srcFormat
== GL_RGBA
) {
3540 const GLubyte
*src
= (const GLubyte
*) source
;
3542 for (i
= 0; i
< n
; i
++) {
3543 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3544 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3545 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3546 dst
[3] = UBYTE_TO_CHAN(src
[3]);
3553 else if (dstFormat
== GL_RGB
) {
3554 if (srcFormat
== GL_RGB
) {
3556 const GLubyte
*src
= (const GLubyte
*) source
;
3558 for (i
= 0; i
< n
; i
++) {
3559 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3560 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3561 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3567 else if (srcFormat
== GL_RGBA
) {
3569 const GLubyte
*src
= (const GLubyte
*) source
;
3571 for (i
= 0; i
< n
; i
++) {
3572 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3573 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3574 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3585 /* general solution begins here */
3587 GLint dstComponents
;
3588 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3589 GLint dstLuminanceIndex
, dstIntensityIndex
;
3590 GLfloat rgba
[MAX_WIDTH
][4];
3592 dstComponents
= _mesa_components_in_format( dstFormat
);
3593 /* source & dest image formats should have been error checked by now */
3594 assert(dstComponents
> 0);
3597 * Extract image data and convert to RGBA floats
3599 assert(n
<= MAX_WIDTH
);
3600 if (srcFormat
== GL_COLOR_INDEX
) {
3601 GLuint indexes
[MAX_WIDTH
];
3602 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3605 if (dstFormat
== GL_COLOR_INDEX
) {
3607 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3608 /* convert to GLchan and return */
3609 for (i
= 0; i
< n
; i
++) {
3610 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3615 /* Convert indexes to RGBA */
3616 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3617 shift_and_offset_ci(ctx
, n
, indexes
);
3619 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3622 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3623 * with color indexes.
3625 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3628 /* non-color index data */
3629 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3630 srcPacking
->SwapBytes
);
3633 /* Need to clamp if returning GLubytes or GLushorts */
3634 #if CHAN_TYPE != GL_FLOAT
3635 transferOps
|= IMAGE_CLAMP_BIT
;
3639 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3642 /* Now determine which color channels we need to produce.
3643 * And determine the dest index (offset) within each color tuple.
3645 switch (dstFormat
) {
3648 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3649 dstLuminanceIndex
= dstIntensityIndex
= -1;
3652 dstLuminanceIndex
= 0;
3653 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3654 dstIntensityIndex
= -1;
3656 case GL_LUMINANCE_ALPHA
:
3657 dstLuminanceIndex
= 0;
3659 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3660 dstIntensityIndex
= -1;
3663 dstIntensityIndex
= 0;
3664 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3665 dstLuminanceIndex
= -1;
3671 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3678 dstLuminanceIndex
= dstIntensityIndex
= -1;
3681 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
3686 /* Now return the GLchan data in the requested dstFormat */
3688 if (dstRedIndex
>= 0) {
3691 for (i
= 0; i
< n
; i
++) {
3692 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
3693 dst
+= dstComponents
;
3697 if (dstGreenIndex
>= 0) {
3700 for (i
= 0; i
< n
; i
++) {
3701 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
3702 dst
+= dstComponents
;
3706 if (dstBlueIndex
>= 0) {
3709 for (i
= 0; i
< n
; i
++) {
3710 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
3711 dst
+= dstComponents
;
3715 if (dstAlphaIndex
>= 0) {
3718 for (i
= 0; i
< n
; i
++) {
3719 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
3720 dst
+= dstComponents
;
3724 if (dstIntensityIndex
>= 0) {
3727 assert(dstIntensityIndex
== 0);
3728 assert(dstComponents
== 1);
3729 for (i
= 0; i
< n
; i
++) {
3730 /* Intensity comes from red channel */
3731 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
3735 if (dstLuminanceIndex
>= 0) {
3738 assert(dstLuminanceIndex
== 0);
3739 for (i
= 0; i
< n
; i
++) {
3740 /* Luminance comes from red channel */
3741 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
3742 dst
+= dstComponents
;
3750 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
3751 * instead of GLchan.
3754 _mesa_unpack_color_span_float( GLcontext
*ctx
,
3755 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
3756 GLenum srcFormat
, GLenum srcType
,
3757 const GLvoid
*source
,
3758 const struct gl_pixelstore_attrib
*srcPacking
,
3759 GLbitfield transferOps
)
3761 ASSERT(dstFormat
== GL_ALPHA
||
3762 dstFormat
== GL_LUMINANCE
||
3763 dstFormat
== GL_LUMINANCE_ALPHA
||
3764 dstFormat
== GL_INTENSITY
||
3765 dstFormat
== GL_RGB
||
3766 dstFormat
== GL_RGBA
||
3767 dstFormat
== GL_COLOR_INDEX
);
3769 ASSERT(srcFormat
== GL_RED
||
3770 srcFormat
== GL_GREEN
||
3771 srcFormat
== GL_BLUE
||
3772 srcFormat
== GL_ALPHA
||
3773 srcFormat
== GL_LUMINANCE
||
3774 srcFormat
== GL_LUMINANCE_ALPHA
||
3775 srcFormat
== GL_INTENSITY
||
3776 srcFormat
== GL_RGB
||
3777 srcFormat
== GL_BGR
||
3778 srcFormat
== GL_RGBA
||
3779 srcFormat
== GL_BGRA
||
3780 srcFormat
== GL_ABGR_EXT
||
3781 srcFormat
== GL_COLOR_INDEX
);
3783 ASSERT(srcType
== GL_BITMAP
||
3784 srcType
== GL_UNSIGNED_BYTE
||
3785 srcType
== GL_BYTE
||
3786 srcType
== GL_UNSIGNED_SHORT
||
3787 srcType
== GL_SHORT
||
3788 srcType
== GL_UNSIGNED_INT
||
3789 srcType
== GL_INT
||
3790 srcType
== GL_HALF_FLOAT_ARB
||
3791 srcType
== GL_FLOAT
||
3792 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3793 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3794 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3795 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3796 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3797 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3798 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3799 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3800 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3801 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3802 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3803 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3805 /* general solution, no special cases, yet */
3807 GLint dstComponents
;
3808 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3809 GLint dstLuminanceIndex
, dstIntensityIndex
;
3810 GLfloat rgba
[MAX_WIDTH
][4];
3812 dstComponents
= _mesa_components_in_format( dstFormat
);
3813 /* source & dest image formats should have been error checked by now */
3814 assert(dstComponents
> 0);
3817 * Extract image data and convert to RGBA floats
3819 assert(n
<= MAX_WIDTH
);
3820 if (srcFormat
== GL_COLOR_INDEX
) {
3821 GLuint indexes
[MAX_WIDTH
];
3822 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3825 if (dstFormat
== GL_COLOR_INDEX
) {
3827 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3828 /* convert to GLchan and return */
3829 for (i
= 0; i
< n
; i
++) {
3830 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3835 /* Convert indexes to RGBA */
3836 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3837 shift_and_offset_ci(ctx
, n
, indexes
);
3839 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3842 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3843 * with color indexes.
3845 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3848 /* non-color index data */
3849 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3850 srcPacking
->SwapBytes
);
3854 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3857 /* Now determine which color channels we need to produce.
3858 * And determine the dest index (offset) within each color tuple.
3860 switch (dstFormat
) {
3863 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3864 dstLuminanceIndex
= dstIntensityIndex
= -1;
3867 dstLuminanceIndex
= 0;
3868 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3869 dstIntensityIndex
= -1;
3871 case GL_LUMINANCE_ALPHA
:
3872 dstLuminanceIndex
= 0;
3874 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3875 dstIntensityIndex
= -1;
3878 dstIntensityIndex
= 0;
3879 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3880 dstLuminanceIndex
= -1;
3886 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3893 dstLuminanceIndex
= dstIntensityIndex
= -1;
3896 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
3900 /* Now pack results in the requested dstFormat */
3901 if (dstRedIndex
>= 0) {
3902 GLfloat
*dst
= dest
;
3904 for (i
= 0; i
< n
; i
++) {
3905 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3906 dst
+= dstComponents
;
3910 if (dstGreenIndex
>= 0) {
3911 GLfloat
*dst
= dest
;
3913 for (i
= 0; i
< n
; i
++) {
3914 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3915 dst
+= dstComponents
;
3919 if (dstBlueIndex
>= 0) {
3920 GLfloat
*dst
= dest
;
3922 for (i
= 0; i
< n
; i
++) {
3923 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3924 dst
+= dstComponents
;
3928 if (dstAlphaIndex
>= 0) {
3929 GLfloat
*dst
= dest
;
3931 for (i
= 0; i
< n
; i
++) {
3932 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3933 dst
+= dstComponents
;
3937 if (dstIntensityIndex
>= 0) {
3938 GLfloat
*dst
= dest
;
3940 assert(dstIntensityIndex
== 0);
3941 assert(dstComponents
== 1);
3942 for (i
= 0; i
< n
; i
++) {
3943 /* Intensity comes from red channel */
3944 dst
[i
] = rgba
[i
][RCOMP
];
3948 if (dstLuminanceIndex
>= 0) {
3949 GLfloat
*dst
= dest
;
3951 assert(dstLuminanceIndex
== 0);
3952 for (i
= 0; i
< n
; i
++) {
3953 /* Luminance comes from red channel */
3954 dst
[0] = rgba
[i
][RCOMP
];
3955 dst
+= dstComponents
;
3962 * Similar to _mesa_unpack_color_span_float(), but for dudv data instead of rgba,
3963 * directly return GLbyte data, no transfer ops apply.
3966 _mesa_unpack_dudv_span_byte( GLcontext
*ctx
,
3967 GLuint n
, GLenum dstFormat
, GLbyte dest
[],
3968 GLenum srcFormat
, GLenum srcType
,
3969 const GLvoid
*source
,
3970 const struct gl_pixelstore_attrib
*srcPacking
,
3971 GLbitfield transferOps
)
3973 ASSERT(dstFormat
== GL_DUDV_ATI
);
3974 ASSERT(srcFormat
== GL_DUDV_ATI
);
3976 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
3977 srcType
== GL_BYTE
||
3978 srcType
== GL_UNSIGNED_SHORT
||
3979 srcType
== GL_SHORT
||
3980 srcType
== GL_UNSIGNED_INT
||
3981 srcType
== GL_INT
||
3982 srcType
== GL_HALF_FLOAT_ARB
||
3983 srcType
== GL_FLOAT
);
3985 /* general solution */
3987 GLint dstComponents
;
3988 GLfloat rgba
[MAX_WIDTH
][4];
3992 dstComponents
= _mesa_components_in_format( dstFormat
);
3993 /* source & dest image formats should have been error checked by now */
3994 assert(dstComponents
> 0);
3997 * Extract image data and convert to RGBA floats
3999 assert(n
<= MAX_WIDTH
);
4000 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
4001 srcPacking
->SwapBytes
);
4004 /* Now determine which color channels we need to produce.
4005 * And determine the dest index (offset) within each color tuple.
4008 /* Now pack results in the requested dstFormat */
4009 for (i
= 0; i
< n
; i
++) {
4010 /* not sure - need clamp[-1,1] here? */
4011 dst
[0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
4012 dst
[1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
4013 dst
+= dstComponents
;
4019 * Unpack a row of color index data from a client buffer according to
4020 * the pixel unpacking parameters.
4021 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
4023 * Args: ctx - the context
4024 * n - number of pixels
4025 * dstType - destination data type
4026 * dest - destination array
4027 * srcType - source pixel type
4028 * source - source data pointer
4029 * srcPacking - pixel unpacking parameters
4030 * transferOps - the pixel transfer operations to apply
4033 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
4034 GLenum dstType
, GLvoid
*dest
,
4035 GLenum srcType
, const GLvoid
*source
,
4036 const struct gl_pixelstore_attrib
*srcPacking
,
4037 GLbitfield transferOps
)
4039 ASSERT(srcType
== GL_BITMAP
||
4040 srcType
== GL_UNSIGNED_BYTE
||
4041 srcType
== GL_BYTE
||
4042 srcType
== GL_UNSIGNED_SHORT
||
4043 srcType
== GL_SHORT
||
4044 srcType
== GL_UNSIGNED_INT
||
4045 srcType
== GL_INT
||
4046 srcType
== GL_HALF_FLOAT_ARB
||
4047 srcType
== GL_FLOAT
);
4049 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4050 dstType
== GL_UNSIGNED_SHORT
||
4051 dstType
== GL_UNSIGNED_INT
);
4054 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4057 * Try simple cases first
4059 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
4060 && dstType
== GL_UNSIGNED_BYTE
) {
4061 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
4063 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
4064 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
4065 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
4071 GLuint indexes
[MAX_WIDTH
];
4072 assert(n
<= MAX_WIDTH
);
4074 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
4078 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4080 /* convert to dest type */
4082 case GL_UNSIGNED_BYTE
:
4084 GLubyte
*dst
= (GLubyte
*) dest
;
4086 for (i
= 0; i
< n
; i
++) {
4087 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4091 case GL_UNSIGNED_SHORT
:
4093 GLuint
*dst
= (GLuint
*) dest
;
4095 for (i
= 0; i
< n
; i
++) {
4096 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4100 case GL_UNSIGNED_INT
:
4101 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4104 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
4111 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
4112 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
4113 const struct gl_pixelstore_attrib
*dstPacking
,
4114 GLbitfield transferOps
)
4116 GLuint indexes
[MAX_WIDTH
];
4118 ASSERT(n
<= MAX_WIDTH
);
4120 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4122 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
4123 /* make a copy of input */
4124 _mesa_memcpy(indexes
, source
, n
* sizeof(GLuint
));
4125 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4130 case GL_UNSIGNED_BYTE
:
4132 GLubyte
*dst
= (GLubyte
*) dest
;
4134 for (i
= 0; i
< n
; i
++) {
4135 *dst
++ = (GLubyte
) source
[i
];
4141 GLbyte
*dst
= (GLbyte
*) dest
;
4143 for (i
= 0; i
< n
; i
++) {
4144 dst
[i
] = (GLbyte
) source
[i
];
4148 case GL_UNSIGNED_SHORT
:
4150 GLushort
*dst
= (GLushort
*) dest
;
4152 for (i
= 0; i
< n
; i
++) {
4153 dst
[i
] = (GLushort
) source
[i
];
4155 if (dstPacking
->SwapBytes
) {
4156 _mesa_swap2( (GLushort
*) dst
, n
);
4162 GLshort
*dst
= (GLshort
*) dest
;
4164 for (i
= 0; i
< n
; i
++) {
4165 dst
[i
] = (GLshort
) source
[i
];
4167 if (dstPacking
->SwapBytes
) {
4168 _mesa_swap2( (GLushort
*) dst
, n
);
4172 case GL_UNSIGNED_INT
:
4174 GLuint
*dst
= (GLuint
*) dest
;
4176 for (i
= 0; i
< n
; i
++) {
4177 dst
[i
] = (GLuint
) source
[i
];
4179 if (dstPacking
->SwapBytes
) {
4180 _mesa_swap4( (GLuint
*) dst
, n
);
4186 GLint
*dst
= (GLint
*) dest
;
4188 for (i
= 0; i
< n
; i
++) {
4189 dst
[i
] = (GLint
) source
[i
];
4191 if (dstPacking
->SwapBytes
) {
4192 _mesa_swap4( (GLuint
*) dst
, n
);
4198 GLfloat
*dst
= (GLfloat
*) dest
;
4200 for (i
= 0; i
< n
; i
++) {
4201 dst
[i
] = (GLfloat
) source
[i
];
4203 if (dstPacking
->SwapBytes
) {
4204 _mesa_swap4( (GLuint
*) dst
, n
);
4208 case GL_HALF_FLOAT_ARB
:
4210 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4212 for (i
= 0; i
< n
; i
++) {
4213 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
4215 if (dstPacking
->SwapBytes
) {
4216 _mesa_swap2( (GLushort
*) dst
, n
);
4221 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4227 * Unpack a row of stencil data from a client buffer according to
4228 * the pixel unpacking parameters.
4229 * This is (or will be) used by glDrawPixels
4231 * Args: ctx - the context
4232 * n - number of pixels
4233 * dstType - destination data type
4234 * dest - destination array
4235 * srcType - source pixel type
4236 * source - source data pointer
4237 * srcPacking - pixel unpacking parameters
4238 * transferOps - apply offset/bias/lookup ops?
4241 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4242 GLenum dstType
, GLvoid
*dest
,
4243 GLenum srcType
, const GLvoid
*source
,
4244 const struct gl_pixelstore_attrib
*srcPacking
,
4245 GLbitfield transferOps
)
4247 ASSERT(srcType
== GL_BITMAP
||
4248 srcType
== GL_UNSIGNED_BYTE
||
4249 srcType
== GL_BYTE
||
4250 srcType
== GL_UNSIGNED_SHORT
||
4251 srcType
== GL_SHORT
||
4252 srcType
== GL_UNSIGNED_INT
||
4253 srcType
== GL_INT
||
4254 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
4255 srcType
== GL_HALF_FLOAT_ARB
||
4256 srcType
== GL_FLOAT
);
4258 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4259 dstType
== GL_UNSIGNED_SHORT
||
4260 dstType
== GL_UNSIGNED_INT
);
4262 /* only shift and offset apply to stencil */
4263 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
4266 * Try simple cases first
4268 if (transferOps
== 0 &&
4269 !ctx
->Pixel
.MapStencilFlag
&&
4270 srcType
== GL_UNSIGNED_BYTE
&&
4271 dstType
== GL_UNSIGNED_BYTE
) {
4272 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
4274 else if (transferOps
== 0 &&
4275 !ctx
->Pixel
.MapStencilFlag
&&
4276 srcType
== GL_UNSIGNED_INT
&&
4277 dstType
== GL_UNSIGNED_INT
&&
4278 !srcPacking
->SwapBytes
) {
4279 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
4285 GLuint indexes
[MAX_WIDTH
];
4286 assert(n
<= MAX_WIDTH
);
4288 extract_uint_indexes(n
, indexes
, GL_STENCIL_INDEX
, srcType
, source
,
4291 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
4292 /* shift and offset indexes */
4293 shift_and_offset_ci(ctx
, n
, indexes
);
4296 if (ctx
->Pixel
.MapStencilFlag
) {
4297 /* Apply stencil lookup table */
4298 const GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
4300 for (i
= 0; i
< n
; i
++) {
4301 indexes
[i
] = (GLuint
)ctx
->PixelMaps
.StoS
.Map
[ indexes
[i
] & mask
];
4305 /* convert to dest type */
4307 case GL_UNSIGNED_BYTE
:
4309 GLubyte
*dst
= (GLubyte
*) dest
;
4311 for (i
= 0; i
< n
; i
++) {
4312 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4316 case GL_UNSIGNED_SHORT
:
4318 GLuint
*dst
= (GLuint
*) dest
;
4320 for (i
= 0; i
< n
; i
++) {
4321 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4325 case GL_UNSIGNED_INT
:
4326 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4329 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
4336 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4337 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
4338 const struct gl_pixelstore_attrib
*dstPacking
)
4340 GLstencil stencil
[MAX_WIDTH
];
4342 ASSERT(n
<= MAX_WIDTH
);
4344 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
4345 ctx
->Pixel
.MapStencilFlag
) {
4346 /* make a copy of input */
4347 _mesa_memcpy(stencil
, source
, n
* sizeof(GLstencil
));
4348 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencil
);
4353 case GL_UNSIGNED_BYTE
:
4354 if (sizeof(GLstencil
) == 1) {
4355 _mesa_memcpy( dest
, source
, n
);
4358 GLubyte
*dst
= (GLubyte
*) dest
;
4361 dst
[i
] = (GLubyte
) source
[i
];
4367 GLbyte
*dst
= (GLbyte
*) dest
;
4370 dst
[i
] = (GLbyte
) (source
[i
] & 0x7f);
4374 case GL_UNSIGNED_SHORT
:
4376 GLushort
*dst
= (GLushort
*) dest
;
4379 dst
[i
] = (GLushort
) source
[i
];
4381 if (dstPacking
->SwapBytes
) {
4382 _mesa_swap2( (GLushort
*) dst
, n
);
4388 GLshort
*dst
= (GLshort
*) dest
;
4391 dst
[i
] = (GLshort
) source
[i
];
4393 if (dstPacking
->SwapBytes
) {
4394 _mesa_swap2( (GLushort
*) dst
, n
);
4398 case GL_UNSIGNED_INT
:
4400 GLuint
*dst
= (GLuint
*) dest
;
4403 dst
[i
] = (GLuint
) source
[i
];
4405 if (dstPacking
->SwapBytes
) {
4406 _mesa_swap4( (GLuint
*) dst
, n
);
4412 GLint
*dst
= (GLint
*) dest
;
4415 dst
[i
] = (GLint
) source
[i
];
4417 if (dstPacking
->SwapBytes
) {
4418 _mesa_swap4( (GLuint
*) dst
, n
);
4424 GLfloat
*dst
= (GLfloat
*) dest
;
4427 dst
[i
] = (GLfloat
) source
[i
];
4429 if (dstPacking
->SwapBytes
) {
4430 _mesa_swap4( (GLuint
*) dst
, n
);
4434 case GL_HALF_FLOAT_ARB
:
4436 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4439 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
4441 if (dstPacking
->SwapBytes
) {
4442 _mesa_swap2( (GLushort
*) dst
, n
);
4447 if (dstPacking
->LsbFirst
) {
4448 GLubyte
*dst
= (GLubyte
*) dest
;
4451 for (i
= 0; i
< n
; i
++) {
4454 *dst
|= ((source
[i
] != 0) << shift
);
4463 GLubyte
*dst
= (GLubyte
*) dest
;
4466 for (i
= 0; i
< n
; i
++) {
4469 *dst
|= ((source
[i
] != 0) << shift
);
4479 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4483 #define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT) \
4486 const GLTYPE *src = (const GLTYPE *)source; \
4487 for (i = 0; i < n; i++) { \
4488 GLTYPE value = src[i]; \
4489 if (srcPacking->SwapBytes) { \
4490 if (sizeof(GLTYPE) == 2) { \
4492 } else if (sizeof(GLTYPE) == 4) { \
4496 depthValues[i] = GLTYPE2FLOAT(value); \
4502 * Unpack a row of depth/z values from memory, returning GLushort, GLuint
4503 * or GLfloat values.
4504 * The glPixelTransfer (scale/bias) params will be applied.
4506 * \param dstType one of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT
4507 * \param depthMax max value for returned GLushort or GLuint values
4508 * (ignored for GLfloat).
4511 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
,
4512 GLenum dstType
, GLvoid
*dest
, GLuint depthMax
,
4513 GLenum srcType
, const GLvoid
*source
,
4514 const struct gl_pixelstore_attrib
*srcPacking
)
4516 GLfloat depthTemp
[MAX_WIDTH
], *depthValues
;
4517 GLboolean needClamp
= GL_FALSE
;
4519 /* Look for special cases first.
4520 * Not only are these faster, they're less prone to numeric conversion
4521 * problems. Otherwise, converting from an int type to a float then
4522 * back to an int type can introduce errors that will show up as
4523 * artifacts in things like depth peeling which uses glCopyTexImage.
4525 if (ctx
->Pixel
.DepthScale
== 1.0 && ctx
->Pixel
.DepthBias
== 0.0) {
4526 if (srcType
== GL_UNSIGNED_INT
&& dstType
== GL_UNSIGNED_SHORT
) {
4527 const GLuint
*src
= (const GLuint
*) source
;
4528 GLushort
*dst
= (GLushort
*) dest
;
4530 for (i
= 0; i
< n
; i
++) {
4531 dst
[i
] = src
[i
] >> 16;
4535 if (srcType
== GL_UNSIGNED_SHORT
4536 && dstType
== GL_UNSIGNED_INT
4537 && depthMax
== 0xffffffff) {
4538 const GLushort
*src
= (const GLushort
*) source
;
4539 GLuint
*dst
= (GLuint
*) dest
;
4541 for (i
= 0; i
< n
; i
++) {
4542 dst
[i
] = src
[i
] | (src
[i
] << 16);
4546 /* XXX may want to add additional cases here someday */
4549 /* general case path follows */
4551 if (dstType
== GL_FLOAT
) {
4552 depthValues
= (GLfloat
*) dest
;
4555 depthValues
= depthTemp
;
4558 /* Convert incoming values to GLfloat. Some conversions will require
4563 DEPTH_VALUES(GLbyte
, BYTE_TO_FLOAT
);
4564 needClamp
= GL_TRUE
;
4566 case GL_UNSIGNED_BYTE
:
4567 DEPTH_VALUES(GLubyte
, UBYTE_TO_FLOAT
);
4570 DEPTH_VALUES(GLshort
, SHORT_TO_FLOAT
);
4571 needClamp
= GL_TRUE
;
4573 case GL_UNSIGNED_SHORT
:
4574 DEPTH_VALUES(GLushort
, USHORT_TO_FLOAT
);
4577 DEPTH_VALUES(GLint
, INT_TO_FLOAT
);
4578 needClamp
= GL_TRUE
;
4580 case GL_UNSIGNED_INT
:
4581 DEPTH_VALUES(GLuint
, UINT_TO_FLOAT
);
4583 case GL_UNSIGNED_INT_24_8_EXT
: /* GL_EXT_packed_depth_stencil */
4584 if (dstType
== GL_UNSIGNED_INT_24_8_EXT
&&
4585 depthMax
== 0xffffff &&
4586 ctx
->Pixel
.DepthScale
== 1.0 &&
4587 ctx
->Pixel
.DepthBias
== 0.0) {
4588 const GLuint
*src
= (const GLuint
*) source
;
4589 GLuint
*zValues
= (GLuint
*) dest
;
4591 for (i
= 0; i
< n
; i
++) {
4592 GLuint value
= src
[i
];
4593 if (srcPacking
->SwapBytes
) {
4596 zValues
[i
] = value
& 0xffffff00;
4601 const GLuint
*src
= (const GLuint
*) source
;
4602 const GLfloat scale
= 1.0f
/ 0xffffff;
4604 for (i
= 0; i
< n
; i
++) {
4605 GLuint value
= src
[i
];
4606 if (srcPacking
->SwapBytes
) {
4609 depthValues
[i
] = (value
>> 8) * scale
;
4614 DEPTH_VALUES(GLfloat
, 1*);
4615 needClamp
= GL_TRUE
;
4617 case GL_HALF_FLOAT_ARB
:
4620 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
4621 for (i
= 0; i
< n
; i
++) {
4622 GLhalfARB value
= src
[i
];
4623 if (srcPacking
->SwapBytes
) {
4626 depthValues
[i
] = _mesa_half_to_float(value
);
4628 needClamp
= GL_TRUE
;
4632 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
4636 /* apply depth scale and bias */
4638 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
4639 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
4640 if (scale
!= 1.0 || bias
!= 0.0) {
4642 for (i
= 0; i
< n
; i
++) {
4643 depthValues
[i
] = depthValues
[i
] * scale
+ bias
;
4645 needClamp
= GL_TRUE
;
4649 /* clamp to [0, 1] */
4652 for (i
= 0; i
< n
; i
++) {
4653 depthValues
[i
] = (GLfloat
)CLAMP(depthValues
[i
], 0.0, 1.0);
4658 * Convert values to dstType
4660 if (dstType
== GL_UNSIGNED_INT
) {
4661 GLuint
*zValues
= (GLuint
*) dest
;
4663 if (depthMax
<= 0xffffff) {
4664 /* no overflow worries */
4665 for (i
= 0; i
< n
; i
++) {
4666 zValues
[i
] = (GLuint
) (depthValues
[i
] * (GLfloat
) depthMax
);
4670 /* need to use double precision to prevent overflow problems */
4671 for (i
= 0; i
< n
; i
++) {
4672 GLdouble z
= depthValues
[i
] * (GLfloat
) depthMax
;
4673 if (z
>= (GLdouble
) 0xffffffff)
4674 zValues
[i
] = 0xffffffff;
4676 zValues
[i
] = (GLuint
) z
;
4680 else if (dstType
== GL_UNSIGNED_SHORT
) {
4681 GLushort
*zValues
= (GLushort
*) dest
;
4683 ASSERT(depthMax
<= 0xffff);
4684 for (i
= 0; i
< n
; i
++) {
4685 zValues
[i
] = (GLushort
) (depthValues
[i
] * (GLfloat
) depthMax
);
4689 ASSERT(dstType
== GL_FLOAT
);
4690 /*ASSERT(depthMax == 1.0F);*/
4696 * Pack an array of depth values. The values are floats in [0,1].
4699 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
4700 GLenum dstType
, const GLfloat
*depthSpan
,
4701 const struct gl_pixelstore_attrib
*dstPacking
)
4703 GLfloat depthCopy
[MAX_WIDTH
];
4705 ASSERT(n
<= MAX_WIDTH
);
4707 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4708 _mesa_memcpy(depthCopy
, depthSpan
, n
* sizeof(GLfloat
));
4709 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4710 depthSpan
= depthCopy
;
4714 case GL_UNSIGNED_BYTE
:
4716 GLubyte
*dst
= (GLubyte
*) dest
;
4718 for (i
= 0; i
< n
; i
++) {
4719 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
4725 GLbyte
*dst
= (GLbyte
*) dest
;
4727 for (i
= 0; i
< n
; i
++) {
4728 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
4732 case GL_UNSIGNED_SHORT
:
4734 GLushort
*dst
= (GLushort
*) dest
;
4736 for (i
= 0; i
< n
; i
++) {
4737 CLAMPED_FLOAT_TO_USHORT(dst
[i
], depthSpan
[i
]);
4739 if (dstPacking
->SwapBytes
) {
4740 _mesa_swap2( (GLushort
*) dst
, n
);
4746 GLshort
*dst
= (GLshort
*) dest
;
4748 for (i
= 0; i
< n
; i
++) {
4749 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
4751 if (dstPacking
->SwapBytes
) {
4752 _mesa_swap2( (GLushort
*) dst
, n
);
4756 case GL_UNSIGNED_INT
:
4758 GLuint
*dst
= (GLuint
*) dest
;
4760 for (i
= 0; i
< n
; i
++) {
4761 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
4763 if (dstPacking
->SwapBytes
) {
4764 _mesa_swap4( (GLuint
*) dst
, n
);
4770 GLint
*dst
= (GLint
*) dest
;
4772 for (i
= 0; i
< n
; i
++) {
4773 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
4775 if (dstPacking
->SwapBytes
) {
4776 _mesa_swap4( (GLuint
*) dst
, n
);
4782 GLfloat
*dst
= (GLfloat
*) dest
;
4784 for (i
= 0; i
< n
; i
++) {
4785 dst
[i
] = depthSpan
[i
];
4787 if (dstPacking
->SwapBytes
) {
4788 _mesa_swap4( (GLuint
*) dst
, n
);
4792 case GL_HALF_FLOAT_ARB
:
4794 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4796 for (i
= 0; i
< n
; i
++) {
4797 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
4799 if (dstPacking
->SwapBytes
) {
4800 _mesa_swap2( (GLushort
*) dst
, n
);
4805 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
4812 * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
4815 _mesa_pack_depth_stencil_span(const GLcontext
*ctx
, GLuint n
, GLuint
*dest
,
4816 const GLfloat
*depthVals
,
4817 const GLstencil
*stencilVals
,
4818 const struct gl_pixelstore_attrib
*dstPacking
)
4820 GLfloat depthCopy
[MAX_WIDTH
];
4821 GLstencil stencilCopy
[MAX_WIDTH
];
4824 ASSERT(n
<= MAX_WIDTH
);
4826 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4827 _mesa_memcpy(depthCopy
, depthVals
, n
* sizeof(GLfloat
));
4828 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4829 depthVals
= depthCopy
;
4832 if (ctx
->Pixel
.IndexShift
||
4833 ctx
->Pixel
.IndexOffset
||
4834 ctx
->Pixel
.MapStencilFlag
) {
4835 _mesa_memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
4836 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencilCopy
);
4837 stencilVals
= stencilCopy
;
4840 for (i
= 0; i
< n
; i
++) {
4841 GLuint z
= (GLuint
) (depthVals
[i
] * 0xffffff);
4842 dest
[i
] = (z
<< 8) | (stencilVals
[i
] & 0xff);
4845 if (dstPacking
->SwapBytes
) {
4846 _mesa_swap4(dest
, n
);
4854 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
4855 * Return all image data in a contiguous block. This is used when we
4856 * compile glDrawPixels, glTexImage, etc into a display list. We
4857 * need a copy of the data in a standard format.
4860 _mesa_unpack_image( GLuint dimensions
,
4861 GLsizei width
, GLsizei height
, GLsizei depth
,
4862 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4863 const struct gl_pixelstore_attrib
*unpack
)
4865 GLint bytesPerRow
, compsPerRow
;
4866 GLboolean flipBytes
, swap2
, swap4
;
4869 return NULL
; /* not necessarily an error */
4871 if (width
<= 0 || height
<= 0 || depth
<= 0)
4872 return NULL
; /* generate error later */
4874 if (type
== GL_BITMAP
) {
4875 bytesPerRow
= (width
+ 7) >> 3;
4876 flipBytes
= unpack
->LsbFirst
;
4877 swap2
= swap4
= GL_FALSE
;
4881 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
4882 GLint components
= _mesa_components_in_format(format
);
4885 if (_mesa_type_is_packed(type
))
4888 if (bytesPerPixel
<= 0 || components
<= 0)
4889 return NULL
; /* bad format or type. generate error later */
4890 bytesPerRow
= bytesPerPixel
* width
;
4891 bytesPerComp
= bytesPerPixel
/ components
;
4892 flipBytes
= GL_FALSE
;
4893 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
4894 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
4895 compsPerRow
= components
* width
;
4896 assert(compsPerRow
>= width
);
4901 = (GLubyte
*) _mesa_malloc(bytesPerRow
* height
* depth
);
4905 return NULL
; /* generate GL_OUT_OF_MEMORY later */
4908 for (img
= 0; img
< depth
; img
++) {
4909 for (row
= 0; row
< height
; row
++) {
4910 const GLvoid
*src
= _mesa_image_address(dimensions
, unpack
, pixels
,
4911 width
, height
, format
, type
, img
, row
, 0);
4913 if ((type
== GL_BITMAP
) && (unpack
->SkipPixels
& 0x7)) {
4915 flipBytes
= GL_FALSE
;
4916 if (unpack
->LsbFirst
) {
4917 GLubyte srcMask
= 1 << (unpack
->SkipPixels
& 0x7);
4918 GLubyte dstMask
= 128;
4919 const GLubyte
*s
= src
;
4922 for (i
= 0; i
< width
; i
++) {
4926 if (srcMask
== 128) {
4931 srcMask
= srcMask
<< 1;
4939 dstMask
= dstMask
>> 1;
4944 GLubyte srcMask
= 128 >> (unpack
->SkipPixels
& 0x7);
4945 GLubyte dstMask
= 128;
4946 const GLubyte
*s
= src
;
4949 for (i
= 0; i
< width
; i
++) {
4958 srcMask
= srcMask
>> 1;
4966 dstMask
= dstMask
>> 1;
4972 _mesa_memcpy(dst
, src
, bytesPerRow
);
4975 /* byte flipping/swapping */
4977 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
4980 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
4983 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
4992 #endif /* _HAVE_FULL_GL */
4997 * Convert an array of RGBA colors from one datatype to another.
4998 * NOTE: src may equal dst. In that case, we use a temporary buffer.
5001 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
5002 GLenum dstType
, GLvoid
*dst
,
5003 GLuint count
, const GLubyte mask
[])
5005 GLuint tempBuffer
[MAX_WIDTH
][4];
5006 const GLboolean useTemp
= (src
== dst
);
5008 ASSERT(srcType
!= dstType
);
5011 case GL_UNSIGNED_BYTE
:
5012 if (dstType
== GL_UNSIGNED_SHORT
) {
5013 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5014 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5016 for (i
= 0; i
< count
; i
++) {
5017 if (!mask
|| mask
[i
]) {
5018 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
5019 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
5020 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
5021 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
5025 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5028 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5029 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5031 ASSERT(dstType
== GL_FLOAT
);
5032 for (i
= 0; i
< count
; i
++) {
5033 if (!mask
|| mask
[i
]) {
5034 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
5035 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
5036 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
5037 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
5041 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5044 case GL_UNSIGNED_SHORT
:
5045 if (dstType
== GL_UNSIGNED_BYTE
) {
5046 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5047 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5049 for (i
= 0; i
< count
; i
++) {
5050 if (!mask
|| mask
[i
]) {
5051 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
5052 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
5053 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
5054 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
5058 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5061 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5062 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5064 ASSERT(dstType
== GL_FLOAT
);
5065 for (i
= 0; i
< count
; i
++) {
5066 if (!mask
|| mask
[i
]) {
5067 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
5068 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
5069 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
5070 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
5074 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5078 if (dstType
== GL_UNSIGNED_BYTE
) {
5079 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5080 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5082 for (i
= 0; i
< count
; i
++) {
5083 if (!mask
|| mask
[i
]) {
5084 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
5085 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
5086 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
5087 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
5091 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5094 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5095 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5097 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
5098 for (i
= 0; i
< count
; i
++) {
5099 if (!mask
|| mask
[i
]) {
5100 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
5101 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
5102 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
5103 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
5107 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5111 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
5119 * Perform basic clipping for glDrawPixels. The image's position and size
5120 * and the unpack SkipPixels and SkipRows are adjusted so that the image
5121 * region is entirely within the window and scissor bounds.
5122 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
5123 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
5124 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
5126 * \return GL_TRUE if image is ready for drawing or
5127 * GL_FALSE if image was completely clipped away (draw nothing)
5130 _mesa_clip_drawpixels(const GLcontext
*ctx
,
5131 GLint
*destX
, GLint
*destY
,
5132 GLsizei
*width
, GLsizei
*height
,
5133 struct gl_pixelstore_attrib
*unpack
)
5135 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
5137 if (unpack
->RowLength
== 0) {
5138 unpack
->RowLength
= *width
;
5141 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
5142 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
5145 if (*destX
< buffer
->_Xmin
) {
5146 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
5147 *width
-= (buffer
->_Xmin
- *destX
);
5148 *destX
= buffer
->_Xmin
;
5150 /* right clipping */
5151 if (*destX
+ *width
> buffer
->_Xmax
)
5152 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
5157 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
5158 /* bottom clipping */
5159 if (*destY
< buffer
->_Ymin
) {
5160 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
5161 *height
-= (buffer
->_Ymin
- *destY
);
5162 *destY
= buffer
->_Ymin
;
5165 if (*destY
+ *height
> buffer
->_Ymax
)
5166 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
5168 else { /* upside down */
5170 if (*destY
> buffer
->_Ymax
) {
5171 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
5172 *height
-= (*destY
- buffer
->_Ymax
);
5173 *destY
= buffer
->_Ymax
;
5175 /* bottom clipping */
5176 if (*destY
- *height
< buffer
->_Ymin
)
5177 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
5178 /* adjust destY so it's the first row to write to */
5190 * Perform clipping for glReadPixels. The image's window position
5191 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
5192 * so that the image region is entirely within the window bounds.
5193 * Note: this is different from _mesa_clip_drawpixels() in that the
5194 * scissor box is ignored, and we use the bounds of the current readbuffer
5197 * \return GL_TRUE if image is ready for drawing or
5198 * GL_FALSE if image was completely clipped away (draw nothing)
5201 _mesa_clip_readpixels(const GLcontext
*ctx
,
5202 GLint
*srcX
, GLint
*srcY
,
5203 GLsizei
*width
, GLsizei
*height
,
5204 struct gl_pixelstore_attrib
*pack
)
5206 const GLframebuffer
*buffer
= ctx
->ReadBuffer
;
5208 if (pack
->RowLength
== 0) {
5209 pack
->RowLength
= *width
;
5214 pack
->SkipPixels
+= (0 - *srcX
);
5215 *width
-= (0 - *srcX
);
5218 /* right clipping */
5219 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
5220 *width
-= (*srcX
+ *width
- buffer
->Width
);
5225 /* bottom clipping */
5227 pack
->SkipRows
+= (0 - *srcY
);
5228 *height
-= (0 - *srcY
);
5232 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
5233 *height
-= (*srcY
+ *height
- buffer
->Height
);
5243 * Do clipping for a glCopyTexSubImage call.
5244 * The framebuffer source region might extend outside the framebuffer
5245 * bounds. Clip the source region against the framebuffer bounds and
5246 * adjust the texture/dest position and size accordingly.
5248 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
5251 _mesa_clip_copytexsubimage(const GLcontext
*ctx
,
5252 GLint
*destX
, GLint
*destY
,
5253 GLint
*srcX
, GLint
*srcY
,
5254 GLsizei
*width
, GLsizei
*height
)
5256 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
5257 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
5259 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
5260 srcX
, srcY
, width
, height
)) {
5261 *destX
= *destX
+ *srcX
- srcX0
;
5262 *destY
= *destY
+ *srcY
- srcY0
;
5274 * Clip the rectangle defined by (x, y, width, height) against the bounds
5275 * specified by [xmin, xmax) and [ymin, ymax).
5276 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
5279 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
5280 GLint xmax
, GLint ymax
,
5282 GLsizei
*width
, GLsizei
*height
)
5286 *width
-= (xmin
- *x
);
5290 /* right clipping */
5291 if (*x
+ *width
> xmax
)
5292 *width
-= (*x
+ *width
- xmax
);
5297 /* bottom (or top) clipping */
5299 *height
-= (ymin
- *y
);
5303 /* top (or bottom) clipping */
5304 if (*y
+ *height
> ymax
)
5305 *height
-= (*y
+ *height
- ymax
);