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
:
305 * Get the bytes per pixel of pixel format type pair.
307 * \param format pixel format.
308 * \param type pixel type.
310 * \return bytes per pixel, or -1 if a bad format or type was given.
313 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
315 GLint comps
= _mesa_components_in_format( format
);
321 return 0; /* special case */
323 case GL_UNSIGNED_BYTE
:
324 return comps
* sizeof(GLubyte
);
326 case GL_UNSIGNED_SHORT
:
327 return comps
* sizeof(GLshort
);
329 case GL_UNSIGNED_INT
:
330 return comps
* sizeof(GLint
);
332 return comps
* sizeof(GLfloat
);
333 case GL_HALF_FLOAT_ARB
:
334 return comps
* sizeof(GLhalfARB
);
335 case GL_UNSIGNED_BYTE_3_3_2
:
336 case GL_UNSIGNED_BYTE_2_3_3_REV
:
337 if (format
== GL_RGB
|| format
== GL_BGR
)
338 return sizeof(GLubyte
);
340 return -1; /* error */
341 case GL_UNSIGNED_SHORT_5_6_5
:
342 case GL_UNSIGNED_SHORT_5_6_5_REV
:
343 if (format
== GL_RGB
|| format
== GL_BGR
)
344 return sizeof(GLushort
);
346 return -1; /* error */
347 case GL_UNSIGNED_SHORT_4_4_4_4
:
348 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
349 case GL_UNSIGNED_SHORT_5_5_5_1
:
350 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
351 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
352 return sizeof(GLushort
);
355 case GL_UNSIGNED_INT_8_8_8_8
:
356 case GL_UNSIGNED_INT_8_8_8_8_REV
:
357 case GL_UNSIGNED_INT_10_10_10_2
:
358 case GL_UNSIGNED_INT_2_10_10_10_REV
:
359 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
360 return sizeof(GLuint
);
363 case GL_UNSIGNED_SHORT_8_8_MESA
:
364 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
365 if (format
== GL_YCBCR_MESA
)
366 return sizeof(GLushort
);
369 case GL_UNSIGNED_INT_24_8_EXT
:
370 if (format
== GL_DEPTH_STENCIL_EXT
)
371 return sizeof(GLuint
);
381 * Test for a legal pixel format and type.
383 * \param format pixel format.
384 * \param type pixel type.
386 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
390 _mesa_is_legal_format_and_type( GLcontext
*ctx
, GLenum format
, GLenum type
)
394 case GL_STENCIL_INDEX
:
398 case GL_UNSIGNED_BYTE
:
400 case GL_UNSIGNED_SHORT
:
402 case GL_UNSIGNED_INT
:
405 case GL_HALF_FLOAT_ARB
:
406 return ctx
->Extensions
.ARB_half_float_pixel
;
414 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
418 case GL_LUMINANCE_ALPHA
:
419 case GL_DEPTH_COMPONENT
:
422 case GL_UNSIGNED_BYTE
:
424 case GL_UNSIGNED_SHORT
:
426 case GL_UNSIGNED_INT
:
429 case GL_HALF_FLOAT_ARB
:
430 return ctx
->Extensions
.ARB_half_float_pixel
;
437 case GL_UNSIGNED_BYTE
:
439 case GL_UNSIGNED_SHORT
:
441 case GL_UNSIGNED_INT
:
443 case GL_UNSIGNED_BYTE_3_3_2
:
444 case GL_UNSIGNED_BYTE_2_3_3_REV
:
445 case GL_UNSIGNED_SHORT_5_6_5
:
446 case GL_UNSIGNED_SHORT_5_6_5_REV
:
448 case GL_HALF_FLOAT_ARB
:
449 return ctx
->Extensions
.ARB_half_float_pixel
;
455 /* NOTE: no packed types are supported with BGR. That's
456 * intentional, according to the GL spec.
459 case GL_UNSIGNED_BYTE
:
461 case GL_UNSIGNED_SHORT
:
463 case GL_UNSIGNED_INT
:
466 case GL_HALF_FLOAT_ARB
:
467 return ctx
->Extensions
.ARB_half_float_pixel
;
476 case GL_UNSIGNED_BYTE
:
478 case GL_UNSIGNED_SHORT
:
480 case GL_UNSIGNED_INT
:
482 case GL_UNSIGNED_SHORT_4_4_4_4
:
483 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
484 case GL_UNSIGNED_SHORT_5_5_5_1
:
485 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
486 case GL_UNSIGNED_INT_8_8_8_8
:
487 case GL_UNSIGNED_INT_8_8_8_8_REV
:
488 case GL_UNSIGNED_INT_10_10_10_2
:
489 case GL_UNSIGNED_INT_2_10_10_10_REV
:
491 case GL_HALF_FLOAT_ARB
:
492 return ctx
->Extensions
.ARB_half_float_pixel
;
497 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
498 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
502 case GL_DEPTH_STENCIL_EXT
:
503 if (ctx
->Extensions
.EXT_packed_depth_stencil
504 && type
== GL_UNSIGNED_INT_24_8_EXT
)
512 case GL_UNSIGNED_BYTE
:
514 case GL_UNSIGNED_SHORT
:
516 case GL_UNSIGNED_INT
:
530 * Return the address of a specific pixel in an image (1D, 2D or 3D).
532 * Pixel unpacking/packing parameters are observed according to \p packing.
534 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
535 * \param image starting address of image data
536 * \param width the image width
537 * \param height theimage height
538 * \param format the pixel format
539 * \param type the pixel data type
540 * \param packing the pixelstore attributes
541 * \param img which image in the volume (0 for 1D or 2D images)
542 * \param row row of pixel in the image (0 for 1D images)
543 * \param column column of pixel in the image
545 * \return address of pixel on success, or NULL on error.
547 * \sa gl_pixelstore_attrib.
550 _mesa_image_address( GLuint dimensions
,
551 const struct gl_pixelstore_attrib
*packing
,
553 GLsizei width
, GLsizei height
,
554 GLenum format
, GLenum type
,
555 GLint img
, GLint row
, GLint column
)
557 GLint alignment
; /* 1, 2 or 4 */
558 GLint pixels_per_row
;
559 GLint rows_per_image
;
562 GLint skipimages
; /* for 3-D volume images */
565 ASSERT(dimensions
>= 1 && dimensions
<= 3);
567 alignment
= packing
->Alignment
;
568 if (packing
->RowLength
> 0) {
569 pixels_per_row
= packing
->RowLength
;
572 pixels_per_row
= width
;
574 if (packing
->ImageHeight
> 0) {
575 rows_per_image
= packing
->ImageHeight
;
578 rows_per_image
= height
;
581 skippixels
= packing
->SkipPixels
;
582 /* Note: SKIP_ROWS _is_ used for 1D images */
583 skiprows
= packing
->SkipRows
;
584 /* Note: SKIP_IMAGES is only used for 3D images */
585 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
587 if (type
== GL_BITMAP
) {
589 GLint comp_per_pixel
; /* components per pixel */
590 GLint bytes_per_comp
; /* bytes per component */
592 GLint bytes_per_image
;
594 /* Compute bytes per component */
595 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
596 if (bytes_per_comp
< 0) {
600 /* Compute number of components per pixel */
601 comp_per_pixel
= _mesa_components_in_format( format
);
602 if (comp_per_pixel
< 0) {
606 bytes_per_row
= alignment
607 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
609 bytes_per_image
= bytes_per_row
* rows_per_image
;
611 pixel_addr
= (GLubyte
*) image
612 + (skipimages
+ img
) * bytes_per_image
613 + (skiprows
+ row
) * bytes_per_row
614 + (skippixels
+ column
) / 8;
617 /* Non-BITMAP data */
618 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
621 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
623 /* The pixel type and format should have been error checked earlier */
624 assert(bytes_per_pixel
> 0);
626 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
627 remainder
= bytes_per_row
% alignment
;
629 bytes_per_row
+= (alignment
- remainder
);
631 ASSERT(bytes_per_row
% alignment
== 0);
633 bytes_per_image
= bytes_per_row
* rows_per_image
;
635 if (packing
->Invert
) {
636 /* set pixel_addr to the last row */
637 topOfImage
= bytes_per_row
* (height
- 1);
638 bytes_per_row
= -bytes_per_row
;
644 /* compute final pixel address */
645 pixel_addr
= (GLubyte
*) image
646 + (skipimages
+ img
) * bytes_per_image
648 + (skiprows
+ row
) * bytes_per_row
649 + (skippixels
+ column
) * bytes_per_pixel
;
652 return (GLvoid
*) pixel_addr
;
657 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
660 GLenum format
, GLenum type
,
663 return _mesa_image_address(1, packing
, image
, width
, 1,
664 format
, type
, 0, 0, column
);
669 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
671 GLsizei width
, GLsizei height
,
672 GLenum format
, GLenum type
,
673 GLint row
, GLint column
)
675 return _mesa_image_address(2, packing
, image
, width
, height
,
676 format
, type
, 0, row
, column
);
681 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
683 GLsizei width
, GLsizei height
,
684 GLenum format
, GLenum type
,
685 GLint img
, GLint row
, GLint column
)
687 return _mesa_image_address(3, packing
, image
, width
, height
,
688 format
, type
, img
, row
, column
);
694 * Compute the stride (in bytes) between image rows.
696 * \param packing the pixelstore attributes
697 * \param width image width.
698 * \param format pixel format.
699 * \param type pixel data type.
701 * \return the stride in bytes for the given parameters, or -1 if error
704 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
705 GLint width
, GLenum format
, GLenum type
)
707 GLint bytesPerRow
, remainder
;
711 if (type
== GL_BITMAP
) {
712 if (packing
->RowLength
== 0) {
713 bytesPerRow
= (width
+ 7) / 8;
716 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
720 /* Non-BITMAP data */
721 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
722 if (bytesPerPixel
<= 0)
723 return -1; /* error */
724 if (packing
->RowLength
== 0) {
725 bytesPerRow
= bytesPerPixel
* width
;
728 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
732 remainder
= bytesPerRow
% packing
->Alignment
;
734 bytesPerRow
+= (packing
->Alignment
- remainder
);
737 if (packing
->Invert
) {
738 /* negate the bytes per row (negative row stride) */
739 bytesPerRow
= -bytesPerRow
;
749 * Compute the stride between images in a 3D texture (in bytes) for the given
750 * pixel packing parameters and image width, format and type.
753 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
754 GLint width
, GLint height
,
755 GLenum format
, GLenum type
)
758 ASSERT(type
!= GL_BITMAP
);
761 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
762 GLint bytesPerRow
, bytesPerImage
, remainder
;
764 if (bytesPerPixel
<= 0)
765 return -1; /* error */
766 if (packing
->RowLength
== 0) {
767 bytesPerRow
= bytesPerPixel
* width
;
770 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
772 remainder
= bytesPerRow
% packing
->Alignment
;
774 bytesPerRow
+= (packing
->Alignment
- remainder
);
776 if (packing
->ImageHeight
== 0)
777 bytesPerImage
= bytesPerRow
* height
;
779 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
781 return bytesPerImage
;
787 * Unpack a 32x32 pixel polygon stipple from user memory using the
788 * current pixel unpack settings.
791 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
792 const struct gl_pixelstore_attrib
*unpacking
)
794 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap(32, 32, pattern
, unpacking
);
796 /* Convert pattern from GLubytes to GLuints and handle big/little
801 for (i
= 0; i
< 32; i
++) {
802 dest
[i
] = (p
[0] << 24)
814 * Pack polygon stipple into user memory given current pixel packing
818 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
819 const struct gl_pixelstore_attrib
*packing
)
821 /* Convert pattern from GLuints to GLubytes to handle big/little
822 * endian differences.
826 for (i
= 0; i
< 32; i
++) {
827 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
828 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
829 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
830 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
833 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
838 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
839 * order with row alignment = 1 byte.
842 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
843 const struct gl_pixelstore_attrib
*packing
)
845 GLint bytes
, row
, width_in_bytes
;
846 GLubyte
*buffer
, *dst
;
851 /* Alloc dest storage */
852 bytes
= ((width
+ 7) / 8 * height
);
853 buffer
= (GLubyte
*) _mesa_malloc( bytes
);
857 width_in_bytes
= CEILING( width
, 8 );
859 for (row
= 0; row
< height
; row
++) {
860 const GLubyte
*src
= (const GLubyte
*)
861 _mesa_image_address2d(packing
, pixels
, width
, height
,
862 GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
868 if ((packing
->SkipPixels
& 7) == 0) {
869 _mesa_memcpy( dst
, src
, width_in_bytes
);
870 if (packing
->LsbFirst
) {
871 flip_bytes( dst
, width_in_bytes
);
875 /* handling SkipPixels is a bit tricky (no pun intended!) */
877 if (packing
->LsbFirst
) {
878 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
879 GLubyte dstMask
= 128;
880 const GLubyte
*s
= src
;
883 for (i
= 0; i
< width
; i
++) {
887 if (srcMask
== 128) {
892 srcMask
= srcMask
<< 1;
900 dstMask
= dstMask
>> 1;
905 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
906 GLubyte dstMask
= 128;
907 const GLubyte
*s
= src
;
910 for (i
= 0; i
< width
; i
++) {
919 srcMask
= srcMask
>> 1;
927 dstMask
= dstMask
>> 1;
932 dst
+= width_in_bytes
;
943 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
944 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
946 GLint row
, width_in_bytes
;
952 width_in_bytes
= CEILING( width
, 8 );
954 for (row
= 0; row
< height
; row
++) {
955 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dest
,
956 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
960 if ((packing
->SkipPixels
& 7) == 0) {
961 _mesa_memcpy( dst
, src
, width_in_bytes
);
962 if (packing
->LsbFirst
) {
963 flip_bytes( dst
, width_in_bytes
);
967 /* handling SkipPixels is a bit tricky (no pun intended!) */
969 if (packing
->LsbFirst
) {
970 GLubyte srcMask
= 128;
971 GLubyte dstMask
= 1 << (packing
->SkipPixels
& 0x7);
972 const GLubyte
*s
= src
;
975 for (i
= 0; i
< width
; i
++) {
984 srcMask
= srcMask
>> 1;
986 if (dstMask
== 128) {
992 dstMask
= dstMask
<< 1;
997 GLubyte srcMask
= 128;
998 GLubyte dstMask
= 128 >> (packing
->SkipPixels
& 0x7);
999 const GLubyte
*s
= src
;
1002 for (i
= 0; i
< width
; i
++) {
1011 srcMask
= srcMask
>> 1;
1019 dstMask
= dstMask
>> 1;
1024 src
+= width_in_bytes
;
1029 /**********************************************************************/
1030 /***** Pixel processing functions ******/
1031 /**********************************************************************/
1034 * Apply scale and bias factors to an array of RGBA pixels.
1037 _mesa_scale_and_bias_rgba(GLuint n
, GLfloat rgba
[][4],
1038 GLfloat rScale
, GLfloat gScale
,
1039 GLfloat bScale
, GLfloat aScale
,
1040 GLfloat rBias
, GLfloat gBias
,
1041 GLfloat bBias
, GLfloat aBias
)
1043 if (rScale
!= 1.0 || rBias
!= 0.0) {
1045 for (i
= 0; i
< n
; i
++) {
1046 rgba
[i
][RCOMP
] = rgba
[i
][RCOMP
] * rScale
+ rBias
;
1049 if (gScale
!= 1.0 || gBias
!= 0.0) {
1051 for (i
= 0; i
< n
; i
++) {
1052 rgba
[i
][GCOMP
] = rgba
[i
][GCOMP
] * gScale
+ gBias
;
1055 if (bScale
!= 1.0 || bBias
!= 0.0) {
1057 for (i
= 0; i
< n
; i
++) {
1058 rgba
[i
][BCOMP
] = rgba
[i
][BCOMP
] * bScale
+ bBias
;
1061 if (aScale
!= 1.0 || aBias
!= 0.0) {
1063 for (i
= 0; i
< n
; i
++) {
1064 rgba
[i
][ACOMP
] = rgba
[i
][ACOMP
] * aScale
+ aBias
;
1071 * Apply pixel mapping to an array of floating point RGBA pixels.
1074 _mesa_map_rgba( const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4] )
1076 const GLfloat rscale
= (GLfloat
) (ctx
->PixelMaps
.RtoR
.Size
- 1);
1077 const GLfloat gscale
= (GLfloat
) (ctx
->PixelMaps
.GtoG
.Size
- 1);
1078 const GLfloat bscale
= (GLfloat
) (ctx
->PixelMaps
.BtoB
.Size
- 1);
1079 const GLfloat ascale
= (GLfloat
) (ctx
->PixelMaps
.AtoA
.Size
- 1);
1080 const GLfloat
*rMap
= ctx
->PixelMaps
.RtoR
.Map
;
1081 const GLfloat
*gMap
= ctx
->PixelMaps
.GtoG
.Map
;
1082 const GLfloat
*bMap
= ctx
->PixelMaps
.BtoB
.Map
;
1083 const GLfloat
*aMap
= ctx
->PixelMaps
.AtoA
.Map
;
1086 GLfloat r
= CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1087 GLfloat g
= CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1088 GLfloat b
= CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1089 GLfloat a
= CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1090 rgba
[i
][RCOMP
] = rMap
[IROUND(r
* rscale
)];
1091 rgba
[i
][GCOMP
] = gMap
[IROUND(g
* gscale
)];
1092 rgba
[i
][BCOMP
] = bMap
[IROUND(b
* bscale
)];
1093 rgba
[i
][ACOMP
] = aMap
[IROUND(a
* ascale
)];
1099 * Apply the color matrix and post color matrix scaling and biasing.
1102 _mesa_transform_rgba(const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4])
1104 const GLfloat rs
= ctx
->Pixel
.PostColorMatrixScale
[0];
1105 const GLfloat rb
= ctx
->Pixel
.PostColorMatrixBias
[0];
1106 const GLfloat gs
= ctx
->Pixel
.PostColorMatrixScale
[1];
1107 const GLfloat gb
= ctx
->Pixel
.PostColorMatrixBias
[1];
1108 const GLfloat bs
= ctx
->Pixel
.PostColorMatrixScale
[2];
1109 const GLfloat bb
= ctx
->Pixel
.PostColorMatrixBias
[2];
1110 const GLfloat as
= ctx
->Pixel
.PostColorMatrixScale
[3];
1111 const GLfloat ab
= ctx
->Pixel
.PostColorMatrixBias
[3];
1112 const GLfloat
*m
= ctx
->ColorMatrixStack
.Top
->m
;
1114 for (i
= 0; i
< n
; i
++) {
1115 const GLfloat r
= rgba
[i
][RCOMP
];
1116 const GLfloat g
= rgba
[i
][GCOMP
];
1117 const GLfloat b
= rgba
[i
][BCOMP
];
1118 const GLfloat a
= rgba
[i
][ACOMP
];
1119 rgba
[i
][RCOMP
] = (m
[0] * r
+ m
[4] * g
+ m
[ 8] * b
+ m
[12] * a
) * rs
+ rb
;
1120 rgba
[i
][GCOMP
] = (m
[1] * r
+ m
[5] * g
+ m
[ 9] * b
+ m
[13] * a
) * gs
+ gb
;
1121 rgba
[i
][BCOMP
] = (m
[2] * r
+ m
[6] * g
+ m
[10] * b
+ m
[14] * a
) * bs
+ bb
;
1122 rgba
[i
][ACOMP
] = (m
[3] * r
+ m
[7] * g
+ m
[11] * b
+ m
[15] * a
) * as
+ ab
;
1128 * Apply a color table lookup to an array of floating point RGBA colors.
1131 _mesa_lookup_rgba_float(const struct gl_color_table
*table
,
1132 GLuint n
, GLfloat rgba
[][4])
1134 const GLint max
= table
->Size
- 1;
1135 const GLfloat scale
= (GLfloat
) max
;
1136 const GLfloat
*lut
= table
->TableF
;
1139 if (!table
->TableF
|| table
->Size
== 0)
1142 switch (table
->_BaseFormat
) {
1144 /* replace RGBA with I */
1145 for (i
= 0; i
< n
; i
++) {
1146 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1147 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1155 /* replace RGB with L */
1156 for (i
= 0; i
< n
; i
++) {
1157 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1158 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1165 /* replace A with A */
1166 for (i
= 0; i
< n
; i
++) {
1167 GLint j
= IROUND(rgba
[i
][ACOMP
] * scale
);
1168 rgba
[i
][ACOMP
] = lut
[CLAMP(j
, 0, max
)];
1171 case GL_LUMINANCE_ALPHA
:
1172 /* replace RGBA with LLLA */
1173 for (i
= 0; i
< n
; i
++) {
1174 GLint jL
= IROUND(rgba
[i
][RCOMP
] * scale
);
1175 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1176 GLfloat luminance
, alpha
;
1177 jL
= CLAMP(jL
, 0, max
);
1178 jA
= CLAMP(jA
, 0, max
);
1179 luminance
= lut
[jL
* 2 + 0];
1180 alpha
= lut
[jA
* 2 + 1];
1183 rgba
[i
][BCOMP
] = luminance
;
1184 rgba
[i
][ACOMP
] = alpha
;;
1188 /* replace RGB with RGB */
1189 for (i
= 0; i
< n
; i
++) {
1190 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1191 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1192 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1193 jR
= CLAMP(jR
, 0, max
);
1194 jG
= CLAMP(jG
, 0, max
);
1195 jB
= CLAMP(jB
, 0, max
);
1196 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1197 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1198 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1202 /* replace RGBA with RGBA */
1203 for (i
= 0; i
< n
; i
++) {
1204 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1205 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1206 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1207 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1208 jR
= CLAMP(jR
, 0, max
);
1209 jG
= CLAMP(jG
, 0, max
);
1210 jB
= CLAMP(jB
, 0, max
);
1211 jA
= CLAMP(jA
, 0, max
);
1212 rgba
[i
][RCOMP
] = lut
[jR
* 4 + 0];
1213 rgba
[i
][GCOMP
] = lut
[jG
* 4 + 1];
1214 rgba
[i
][BCOMP
] = lut
[jB
* 4 + 2];
1215 rgba
[i
][ACOMP
] = lut
[jA
* 4 + 3];
1219 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_float");
1227 * Apply a color table lookup to an array of ubyte/RGBA colors.
1230 _mesa_lookup_rgba_ubyte(const struct gl_color_table
*table
,
1231 GLuint n
, GLubyte rgba
[][4])
1233 const GLubyte
*lut
= table
->TableUB
;
1234 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / (GLfloat
)255.0;
1237 if (!table
->TableUB
|| table
->Size
== 0)
1240 switch (table
->_BaseFormat
) {
1242 /* replace RGBA with I */
1243 if (table
->Size
== 256) {
1244 for (i
= 0; i
< n
; i
++) {
1245 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1253 for (i
= 0; i
< n
; i
++) {
1254 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1258 rgba
[i
][ACOMP
] = lut
[j
];
1263 /* replace RGB with L */
1264 if (table
->Size
== 256) {
1265 for (i
= 0; i
< n
; i
++) {
1266 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1273 for (i
= 0; i
< n
; i
++) {
1274 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1277 rgba
[i
][BCOMP
] = lut
[j
];
1282 /* replace A with A */
1283 if (table
->Size
== 256) {
1284 for (i
= 0; i
< n
; i
++) {
1285 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
]];
1289 for (i
= 0; i
< n
; i
++) {
1290 GLint j
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1291 rgba
[i
][ACOMP
] = lut
[j
];
1295 case GL_LUMINANCE_ALPHA
:
1296 /* replace RGBA with LLLA */
1297 if (table
->Size
== 256) {
1298 for (i
= 0; i
< n
; i
++) {
1299 GLubyte l
= lut
[rgba
[i
][RCOMP
] * 2 + 0];
1300 GLubyte a
= lut
[rgba
[i
][ACOMP
] * 2 + 1];;
1308 for (i
= 0; i
< n
; i
++) {
1309 GLint jL
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1310 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1311 GLubyte luminance
= lut
[jL
* 2 + 0];
1312 GLubyte alpha
= lut
[jA
* 2 + 1];
1315 rgba
[i
][BCOMP
] = luminance
;
1316 rgba
[i
][ACOMP
] = alpha
;
1321 if (table
->Size
== 256) {
1322 for (i
= 0; i
< n
; i
++) {
1323 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 3 + 0];
1324 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 3 + 1];
1325 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 3 + 2];
1329 for (i
= 0; i
< n
; i
++) {
1330 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1331 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1332 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1333 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1334 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1335 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1340 if (table
->Size
== 256) {
1341 for (i
= 0; i
< n
; i
++) {
1342 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 4 + 0];
1343 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 4 + 1];
1344 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 4 + 2];
1345 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
] * 4 + 3];
1349 for (i
= 0; i
< n
; i
++) {
1350 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1351 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1352 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1353 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1354 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][RCOMP
], lut
[jR
* 4 + 0]);
1355 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][GCOMP
], lut
[jG
* 4 + 1]);
1356 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][BCOMP
], lut
[jB
* 4 + 2]);
1357 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][ACOMP
], lut
[jA
* 4 + 3]);
1362 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_chan");
1370 * Map color indexes to float rgba values.
1373 _mesa_map_ci_to_rgba( const GLcontext
*ctx
, GLuint n
,
1374 const GLuint index
[], GLfloat rgba
[][4] )
1376 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1377 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1378 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1379 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1380 const GLfloat
*rMap
= ctx
->PixelMaps
.ItoR
.Map
;
1381 const GLfloat
*gMap
= ctx
->PixelMaps
.ItoG
.Map
;
1382 const GLfloat
*bMap
= ctx
->PixelMaps
.ItoB
.Map
;
1383 const GLfloat
*aMap
= ctx
->PixelMaps
.ItoA
.Map
;
1386 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1387 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1388 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1389 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1395 * Map ubyte color indexes to ubyte/RGBA values.
1398 _mesa_map_ci8_to_rgba8(const GLcontext
*ctx
, GLuint n
, const GLubyte index
[],
1401 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1402 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1403 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1404 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1405 const GLubyte
*rMap
= ctx
->PixelMaps
.ItoR
.Map8
;
1406 const GLubyte
*gMap
= ctx
->PixelMaps
.ItoG
.Map8
;
1407 const GLubyte
*bMap
= ctx
->PixelMaps
.ItoB
.Map8
;
1408 const GLubyte
*aMap
= ctx
->PixelMaps
.ItoA
.Map8
;
1411 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1412 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1413 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1414 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1420 _mesa_scale_and_bias_depth(const GLcontext
*ctx
, GLuint n
,
1421 GLfloat depthValues
[])
1423 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
1424 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
1426 for (i
= 0; i
< n
; i
++) {
1427 GLfloat d
= depthValues
[i
] * scale
+ bias
;
1428 depthValues
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
1434 _mesa_scale_and_bias_depth_uint(const GLcontext
*ctx
, GLuint n
,
1435 GLuint depthValues
[])
1437 const GLdouble max
= (double) 0xffffffff;
1438 const GLdouble scale
= ctx
->Pixel
.DepthScale
;
1439 const GLdouble bias
= ctx
->Pixel
.DepthBias
* max
;
1441 for (i
= 0; i
< n
; i
++) {
1442 GLdouble d
= (GLdouble
) depthValues
[i
] * scale
+ bias
;
1443 d
= CLAMP(d
, 0.0, max
);
1444 depthValues
[i
] = (GLuint
) d
;
1451 * Update the min/max values from an array of fragment colors.
1454 update_minmax(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1457 for (i
= 0; i
< n
; i
++) {
1459 if (rgba
[i
][RCOMP
] < ctx
->MinMax
.Min
[RCOMP
])
1460 ctx
->MinMax
.Min
[RCOMP
] = rgba
[i
][RCOMP
];
1461 if (rgba
[i
][GCOMP
] < ctx
->MinMax
.Min
[GCOMP
])
1462 ctx
->MinMax
.Min
[GCOMP
] = rgba
[i
][GCOMP
];
1463 if (rgba
[i
][BCOMP
] < ctx
->MinMax
.Min
[BCOMP
])
1464 ctx
->MinMax
.Min
[BCOMP
] = rgba
[i
][BCOMP
];
1465 if (rgba
[i
][ACOMP
] < ctx
->MinMax
.Min
[ACOMP
])
1466 ctx
->MinMax
.Min
[ACOMP
] = rgba
[i
][ACOMP
];
1469 if (rgba
[i
][RCOMP
] > ctx
->MinMax
.Max
[RCOMP
])
1470 ctx
->MinMax
.Max
[RCOMP
] = rgba
[i
][RCOMP
];
1471 if (rgba
[i
][GCOMP
] > ctx
->MinMax
.Max
[GCOMP
])
1472 ctx
->MinMax
.Max
[GCOMP
] = rgba
[i
][GCOMP
];
1473 if (rgba
[i
][BCOMP
] > ctx
->MinMax
.Max
[BCOMP
])
1474 ctx
->MinMax
.Max
[BCOMP
] = rgba
[i
][BCOMP
];
1475 if (rgba
[i
][ACOMP
] > ctx
->MinMax
.Max
[ACOMP
])
1476 ctx
->MinMax
.Max
[ACOMP
] = rgba
[i
][ACOMP
];
1482 * Update the histogram values from an array of fragment colors.
1485 update_histogram(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1487 const GLint max
= ctx
->Histogram
.Width
- 1;
1488 GLfloat w
= (GLfloat
) max
;
1491 if (ctx
->Histogram
.Width
== 0)
1494 for (i
= 0; i
< n
; i
++) {
1495 GLint ri
= IROUND(rgba
[i
][RCOMP
] * w
);
1496 GLint gi
= IROUND(rgba
[i
][GCOMP
] * w
);
1497 GLint bi
= IROUND(rgba
[i
][BCOMP
] * w
);
1498 GLint ai
= IROUND(rgba
[i
][ACOMP
] * w
);
1499 ri
= CLAMP(ri
, 0, max
);
1500 gi
= CLAMP(gi
, 0, max
);
1501 bi
= CLAMP(bi
, 0, max
);
1502 ai
= CLAMP(ai
, 0, max
);
1503 ctx
->Histogram
.Count
[ri
][RCOMP
]++;
1504 ctx
->Histogram
.Count
[gi
][GCOMP
]++;
1505 ctx
->Histogram
.Count
[bi
][BCOMP
]++;
1506 ctx
->Histogram
.Count
[ai
][ACOMP
]++;
1512 * Apply various pixel transfer operations to an array of RGBA pixels
1513 * as indicated by the transferOps bitmask
1516 _mesa_apply_rgba_transfer_ops(GLcontext
*ctx
, GLbitfield transferOps
,
1517 GLuint n
, GLfloat rgba
[][4])
1520 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
1521 _mesa_scale_and_bias_rgba(n
, rgba
,
1522 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
1523 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
1524 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
1525 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
1527 /* color map lookup */
1528 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1529 _mesa_map_rgba( ctx
, n
, rgba
);
1531 /* GL_COLOR_TABLE lookup */
1532 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
1533 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
], n
, rgba
);
1536 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
1537 /* this has to be done in the calling code */
1538 _mesa_problem(ctx
, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");
1540 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
1541 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
1542 _mesa_scale_and_bias_rgba(n
, rgba
,
1543 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
1544 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
1545 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
1546 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
1547 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
1548 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
1549 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
1550 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
1552 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
1553 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
1554 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
], n
, rgba
);
1556 /* color matrix transform */
1557 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
1558 _mesa_transform_rgba(ctx
, n
, rgba
);
1560 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
1561 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
1562 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
], n
, rgba
);
1564 /* update histogram count */
1565 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
1566 update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1568 /* update min/max values */
1569 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
1570 update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1572 /* clamping to [0,1] */
1573 if (transferOps
& IMAGE_CLAMP_BIT
) {
1575 for (i
= 0; i
< n
; i
++) {
1576 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1577 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1578 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1579 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1586 * Apply color index shift and offset to an array of pixels.
1589 shift_and_offset_ci( const GLcontext
*ctx
, GLuint n
, GLuint indexes
[] )
1591 GLint shift
= ctx
->Pixel
.IndexShift
;
1592 GLint offset
= ctx
->Pixel
.IndexOffset
;
1596 indexes
[i
] = (indexes
[i
] << shift
) + offset
;
1599 else if (shift
< 0) {
1602 indexes
[i
] = (indexes
[i
] >> shift
) + offset
;
1607 indexes
[i
] = indexes
[i
] + offset
;
1615 * Apply color index shift, offset and table lookup to an array
1619 _mesa_apply_ci_transfer_ops(const GLcontext
*ctx
, GLbitfield transferOps
,
1620 GLuint n
, GLuint indexes
[])
1622 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
1623 shift_and_offset_ci(ctx
, n
, indexes
);
1625 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1626 const GLuint mask
= ctx
->PixelMaps
.ItoI
.Size
- 1;
1628 for (i
= 0; i
< n
; i
++) {
1629 const GLuint j
= indexes
[i
] & mask
;
1630 indexes
[i
] = IROUND(ctx
->PixelMaps
.ItoI
.Map
[j
]);
1637 * Apply stencil index shift, offset and table lookup to an array
1638 * of stencil values.
1641 _mesa_apply_stencil_transfer_ops(const GLcontext
*ctx
, GLuint n
,
1642 GLstencil stencil
[])
1644 if (ctx
->Pixel
.IndexShift
!= 0 || ctx
->Pixel
.IndexOffset
!= 0) {
1645 const GLint offset
= ctx
->Pixel
.IndexOffset
;
1646 GLint shift
= ctx
->Pixel
.IndexShift
;
1649 for (i
= 0; i
< n
; i
++) {
1650 stencil
[i
] = (stencil
[i
] << shift
) + offset
;
1653 else if (shift
< 0) {
1655 for (i
= 0; i
< n
; i
++) {
1656 stencil
[i
] = (stencil
[i
] >> shift
) + offset
;
1660 for (i
= 0; i
< n
; i
++) {
1661 stencil
[i
] = stencil
[i
] + offset
;
1665 if (ctx
->Pixel
.MapStencilFlag
) {
1666 GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
1668 for (i
= 0; i
< n
; i
++) {
1669 stencil
[i
] = (GLstencil
)ctx
->PixelMaps
.StoS
.Map
[ stencil
[i
] & mask
];
1676 * Used to pack an array [][4] of RGBA float colors as specified
1677 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
1678 * glGetConvolutionFilter(), etc.
1679 * Incoming colors will be clamped to [0,1] if needed.
1680 * Note: the rgba values will be modified by this function when any pixel
1681 * transfer ops are enabled.
1684 _mesa_pack_rgba_span_float(GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4],
1685 GLenum dstFormat
, GLenum dstType
,
1687 const struct gl_pixelstore_attrib
*dstPacking
,
1688 GLbitfield transferOps
)
1690 GLfloat luminance
[MAX_WIDTH
];
1691 const GLint comps
= _mesa_components_in_format(dstFormat
);
1693 /* clamping only applies to colors, not the dudv values, but still need
1694 it if converting to unsigned values (which doesn't make much sense) */
1695 if (dstFormat
== GL_DUDV_ATI
|| dstFormat
== GL_DU8DV8_ATI
) {
1697 case GL_UNSIGNED_BYTE
:
1698 case GL_UNSIGNED_SHORT
:
1699 case GL_UNSIGNED_INT
:
1700 transferOps
|= IMAGE_CLAMP_BIT
;
1702 /* actually might want clamp to [-1,1] otherwise but shouldn't matter? */
1705 else if (dstType
!= GL_FLOAT
|| ctx
->Color
.ClampReadColor
== GL_TRUE
) {
1706 /* need to clamp to [0, 1] */
1707 transferOps
|= IMAGE_CLAMP_BIT
;
1711 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
1712 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
1717 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
1718 /* compute luminance values */
1719 if (transferOps
& IMAGE_CLAMP_BIT
) {
1720 for (i
= 0; i
< n
; i
++) {
1721 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1722 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
1726 for (i
= 0; i
< n
; i
++) {
1727 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1733 * Pack/store the pixels. Ugh! Lots of cases!!!
1736 case GL_UNSIGNED_BYTE
:
1738 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1739 switch (dstFormat
) {
1742 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1746 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1750 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1754 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1758 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1760 case GL_LUMINANCE_ALPHA
:
1762 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1763 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1768 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1769 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1770 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1775 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1776 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1777 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1778 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1783 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1784 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1785 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1790 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1791 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1792 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1793 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1798 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1799 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1800 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1801 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1807 dst
[i
*2+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1808 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1812 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1818 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1819 switch (dstFormat
) {
1822 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1826 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1830 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1834 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1838 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1840 case GL_LUMINANCE_ALPHA
:
1842 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1843 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1848 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1849 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1850 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1855 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1856 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1857 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1858 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1863 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1864 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1865 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1870 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1871 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1872 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1873 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1878 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1879 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1880 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1881 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1887 dst
[i
*2+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1888 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1892 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1896 case GL_UNSIGNED_SHORT
:
1898 GLushort
*dst
= (GLushort
*) dstAddr
;
1899 switch (dstFormat
) {
1902 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][RCOMP
]);
1906 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][GCOMP
]);
1910 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][BCOMP
]);
1914 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][ACOMP
]);
1918 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
], luminance
[i
]);
1920 case GL_LUMINANCE_ALPHA
:
1922 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
*2+0], luminance
[i
]);
1923 CLAMPED_FLOAT_TO_USHORT(dst
[i
*2+1], rgba
[i
][ACOMP
]);
1928 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][RCOMP
]);
1929 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1930 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][BCOMP
]);
1935 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][RCOMP
]);
1936 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1937 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][BCOMP
]);
1938 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1943 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][BCOMP
]);
1944 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1945 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][RCOMP
]);
1950 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][BCOMP
]);
1951 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1952 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][RCOMP
]);
1953 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1958 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][ACOMP
]);
1959 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][BCOMP
]);
1960 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][GCOMP
]);
1961 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][RCOMP
]);
1967 dst
[i
*2+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1968 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1972 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1978 GLshort
*dst
= (GLshort
*) dstAddr
;
1979 switch (dstFormat
) {
1982 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1986 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1990 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1994 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1998 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
2000 case GL_LUMINANCE_ALPHA
:
2002 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
2003 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2008 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2009 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2010 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2015 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2016 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2017 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2018 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2023 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2024 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2025 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2030 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2031 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2032 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2033 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2038 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2039 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2040 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2041 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2047 dst
[i
*2+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2048 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2052 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2056 case GL_UNSIGNED_INT
:
2058 GLuint
*dst
= (GLuint
*) dstAddr
;
2059 switch (dstFormat
) {
2062 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2066 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2070 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2074 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2078 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
2080 case GL_LUMINANCE_ALPHA
:
2082 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
2083 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2088 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2089 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2090 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2095 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2096 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2097 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2098 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2103 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2104 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2105 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2110 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2111 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2112 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2113 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2118 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2119 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2120 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2121 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2127 dst
[i
*2+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2128 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2132 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2138 GLint
*dst
= (GLint
*) dstAddr
;
2139 switch (dstFormat
) {
2142 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2146 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2150 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2154 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2158 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
2160 case GL_LUMINANCE_ALPHA
:
2162 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
2163 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2168 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2169 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2170 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2175 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2176 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2177 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2178 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2183 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2184 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2185 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2190 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2191 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2192 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2193 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2198 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2199 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2200 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2201 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2207 dst
[i
*2+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2208 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2212 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2218 GLfloat
*dst
= (GLfloat
*) dstAddr
;
2219 switch (dstFormat
) {
2222 dst
[i
] = rgba
[i
][RCOMP
];
2226 dst
[i
] = rgba
[i
][GCOMP
];
2230 dst
[i
] = rgba
[i
][BCOMP
];
2234 dst
[i
] = rgba
[i
][ACOMP
];
2238 dst
[i
] = luminance
[i
];
2240 case GL_LUMINANCE_ALPHA
:
2242 dst
[i
*2+0] = luminance
[i
];
2243 dst
[i
*2+1] = rgba
[i
][ACOMP
];
2248 dst
[i
*3+0] = rgba
[i
][RCOMP
];
2249 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2250 dst
[i
*3+2] = rgba
[i
][BCOMP
];
2255 dst
[i
*4+0] = rgba
[i
][RCOMP
];
2256 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2257 dst
[i
*4+2] = rgba
[i
][BCOMP
];
2258 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2263 dst
[i
*3+0] = rgba
[i
][BCOMP
];
2264 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2265 dst
[i
*3+2] = rgba
[i
][RCOMP
];
2270 dst
[i
*4+0] = rgba
[i
][BCOMP
];
2271 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2272 dst
[i
*4+2] = rgba
[i
][RCOMP
];
2273 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2278 dst
[i
*4+0] = rgba
[i
][ACOMP
];
2279 dst
[i
*4+1] = rgba
[i
][BCOMP
];
2280 dst
[i
*4+2] = rgba
[i
][GCOMP
];
2281 dst
[i
*4+3] = rgba
[i
][RCOMP
];
2287 dst
[i
*2+0] = rgba
[i
][RCOMP
];
2288 dst
[i
*2+1] = rgba
[i
][GCOMP
];
2292 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2296 case GL_HALF_FLOAT_ARB
:
2298 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
2299 switch (dstFormat
) {
2302 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2306 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2310 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2314 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2318 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
2320 case GL_LUMINANCE_ALPHA
:
2322 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
2323 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2328 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2329 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2330 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2335 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2336 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2337 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2338 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2343 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2344 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2345 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2350 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2351 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2352 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2353 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2358 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2359 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2360 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2361 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2367 dst
[i
*2+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2368 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2372 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2376 case GL_UNSIGNED_BYTE_3_3_2
:
2377 if (dstFormat
== GL_RGB
) {
2378 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2380 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
2381 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
2382 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
2386 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2387 if (dstFormat
== GL_RGB
) {
2388 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2390 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
2391 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
2392 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 6);
2396 case GL_UNSIGNED_SHORT_5_6_5
:
2397 if (dstFormat
== GL_RGB
) {
2398 GLushort
*dst
= (GLushort
*) dstAddr
;
2400 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
2401 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
2402 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
2406 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2407 if (dstFormat
== GL_RGB
) {
2408 GLushort
*dst
= (GLushort
*) dstAddr
;
2410 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
2411 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
2412 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
2416 case GL_UNSIGNED_SHORT_4_4_4_4
:
2417 if (dstFormat
== GL_RGBA
) {
2418 GLushort
*dst
= (GLushort
*) dstAddr
;
2420 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
2421 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
2422 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
2423 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
2426 else if (dstFormat
== GL_BGRA
) {
2427 GLushort
*dst
= (GLushort
*) dstAddr
;
2429 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 12)
2430 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
2431 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 4)
2432 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
2435 else if (dstFormat
== GL_ABGR_EXT
) {
2436 GLushort
*dst
= (GLushort
*) dstAddr
;
2438 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12)
2439 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
2440 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
2441 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) );
2445 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2446 if (dstFormat
== GL_RGBA
) {
2447 GLushort
*dst
= (GLushort
*) dstAddr
;
2449 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
2450 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
2451 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
2452 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
2455 else if (dstFormat
== GL_BGRA
) {
2456 GLushort
*dst
= (GLushort
*) dstAddr
;
2458 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) )
2459 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
2460 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 8)
2461 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
2464 else if (dstFormat
== GL_ABGR_EXT
) {
2465 GLushort
*dst
= (GLushort
*) dstAddr
;
2467 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) )
2468 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
2469 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
2470 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12);
2474 case GL_UNSIGNED_SHORT_5_5_5_1
:
2475 if (dstFormat
== GL_RGBA
) {
2476 GLushort
*dst
= (GLushort
*) dstAddr
;
2478 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
2479 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
2480 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
2481 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
2484 else if (dstFormat
== GL_BGRA
) {
2485 GLushort
*dst
= (GLushort
*) dstAddr
;
2487 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11)
2488 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
2489 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 1)
2490 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
2493 else if (dstFormat
== GL_ABGR_EXT
) {
2494 GLushort
*dst
= (GLushort
*) dstAddr
;
2496 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) << 11)
2497 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 6)
2498 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 1)
2499 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) );
2503 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2504 if (dstFormat
== GL_RGBA
) {
2505 GLushort
*dst
= (GLushort
*) dstAddr
;
2507 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
2508 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
2509 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
2510 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
2513 else if (dstFormat
== GL_BGRA
) {
2514 GLushort
*dst
= (GLushort
*) dstAddr
;
2516 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) )
2517 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
2518 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 10)
2519 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
2522 else if (dstFormat
== GL_ABGR_EXT
) {
2523 GLushort
*dst
= (GLushort
*) dstAddr
;
2525 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) )
2526 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 5)
2527 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 10)
2528 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) << 15);
2532 case GL_UNSIGNED_INT_8_8_8_8
:
2533 if (dstFormat
== GL_RGBA
) {
2534 GLuint
*dst
= (GLuint
*) dstAddr
;
2536 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
2537 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
2538 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
2539 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
2542 else if (dstFormat
== GL_BGRA
) {
2543 GLuint
*dst
= (GLuint
*) dstAddr
;
2545 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
2546 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
2547 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
2548 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
2551 else if (dstFormat
== GL_ABGR_EXT
) {
2552 GLuint
*dst
= (GLuint
*) dstAddr
;
2554 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
2555 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
2556 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
2557 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
2561 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2562 if (dstFormat
== GL_RGBA
) {
2563 GLuint
*dst
= (GLuint
*) dstAddr
;
2565 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
2566 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
2567 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
2568 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
2571 else if (dstFormat
== GL_BGRA
) {
2572 GLuint
*dst
= (GLuint
*) dstAddr
;
2574 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
2575 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
2576 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
2577 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
2580 else if (dstFormat
== GL_ABGR_EXT
) {
2581 GLuint
*dst
= (GLuint
*) dstAddr
;
2583 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
2584 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
2585 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
2586 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
2590 case GL_UNSIGNED_INT_10_10_10_2
:
2591 if (dstFormat
== GL_RGBA
) {
2592 GLuint
*dst
= (GLuint
*) dstAddr
;
2594 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
2595 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
2596 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
2597 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
2600 else if (dstFormat
== GL_BGRA
) {
2601 GLuint
*dst
= (GLuint
*) dstAddr
;
2603 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
2604 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
2605 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
2606 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
2609 else if (dstFormat
== GL_ABGR_EXT
) {
2610 GLuint
*dst
= (GLuint
*) dstAddr
;
2612 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
2613 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
2614 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
2615 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
2619 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2620 if (dstFormat
== GL_RGBA
) {
2621 GLuint
*dst
= (GLuint
*) dstAddr
;
2623 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
2624 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
2625 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
2626 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
2629 else if (dstFormat
== GL_BGRA
) {
2630 GLuint
*dst
= (GLuint
*) dstAddr
;
2632 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
2633 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
2634 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
2635 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
2638 else if (dstFormat
== GL_ABGR_EXT
) {
2639 GLuint
*dst
= (GLuint
*) dstAddr
;
2641 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
2642 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
2643 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
2644 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
2649 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
2653 if (dstPacking
->SwapBytes
) {
2654 GLint swapSize
= _mesa_sizeof_packed_type(dstType
);
2655 if (swapSize
== 2) {
2656 if (dstPacking
->SwapBytes
) {
2657 _mesa_swap2((GLushort
*) dstAddr
, n
* comps
);
2660 else if (swapSize
== 4) {
2661 if (dstPacking
->SwapBytes
) {
2662 _mesa_swap4((GLuint
*) dstAddr
, n
* comps
);
2669 #define SWAP2BYTE(VALUE) \
2671 GLubyte *bytes = (GLubyte *) &(VALUE); \
2672 GLubyte tmp = bytes[0]; \
2673 bytes[0] = bytes[1]; \
2677 #define SWAP4BYTE(VALUE) \
2679 GLubyte *bytes = (GLubyte *) &(VALUE); \
2680 GLubyte tmp = bytes[0]; \
2681 bytes[0] = bytes[3]; \
2684 bytes[1] = bytes[2]; \
2690 extract_uint_indexes(GLuint n
, GLuint indexes
[],
2691 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2692 const struct gl_pixelstore_attrib
*unpack
)
2694 ASSERT(srcFormat
== GL_COLOR_INDEX
|| srcFormat
== GL_STENCIL_INDEX
);
2696 ASSERT(srcType
== GL_BITMAP
||
2697 srcType
== GL_UNSIGNED_BYTE
||
2698 srcType
== GL_BYTE
||
2699 srcType
== GL_UNSIGNED_SHORT
||
2700 srcType
== GL_SHORT
||
2701 srcType
== GL_UNSIGNED_INT
||
2702 srcType
== GL_INT
||
2703 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
2704 srcType
== GL_HALF_FLOAT_ARB
||
2705 srcType
== GL_FLOAT
);
2710 GLubyte
*ubsrc
= (GLubyte
*) src
;
2711 if (unpack
->LsbFirst
) {
2712 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
2714 for (i
= 0; i
< n
; i
++) {
2715 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2726 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
2728 for (i
= 0; i
< n
; i
++) {
2729 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2741 case GL_UNSIGNED_BYTE
:
2744 const GLubyte
*s
= (const GLubyte
*) src
;
2745 for (i
= 0; i
< n
; i
++)
2752 const GLbyte
*s
= (const GLbyte
*) src
;
2753 for (i
= 0; i
< n
; i
++)
2757 case GL_UNSIGNED_SHORT
:
2760 const GLushort
*s
= (const GLushort
*) src
;
2761 if (unpack
->SwapBytes
) {
2762 for (i
= 0; i
< n
; i
++) {
2763 GLushort value
= s
[i
];
2769 for (i
= 0; i
< n
; i
++)
2777 const GLshort
*s
= (const GLshort
*) src
;
2778 if (unpack
->SwapBytes
) {
2779 for (i
= 0; i
< n
; i
++) {
2780 GLshort value
= s
[i
];
2786 for (i
= 0; i
< n
; i
++)
2791 case GL_UNSIGNED_INT
:
2794 const GLuint
*s
= (const GLuint
*) src
;
2795 if (unpack
->SwapBytes
) {
2796 for (i
= 0; i
< n
; i
++) {
2797 GLuint value
= s
[i
];
2803 for (i
= 0; i
< n
; i
++)
2811 const GLint
*s
= (const GLint
*) src
;
2812 if (unpack
->SwapBytes
) {
2813 for (i
= 0; i
< n
; i
++) {
2820 for (i
= 0; i
< n
; i
++)
2828 const GLfloat
*s
= (const GLfloat
*) src
;
2829 if (unpack
->SwapBytes
) {
2830 for (i
= 0; i
< n
; i
++) {
2831 GLfloat value
= s
[i
];
2833 indexes
[i
] = (GLuint
) value
;
2837 for (i
= 0; i
< n
; i
++)
2838 indexes
[i
] = (GLuint
) s
[i
];
2842 case GL_HALF_FLOAT_ARB
:
2845 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
2846 if (unpack
->SwapBytes
) {
2847 for (i
= 0; i
< n
; i
++) {
2848 GLhalfARB value
= s
[i
];
2850 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
2854 for (i
= 0; i
< n
; i
++)
2855 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
2859 case GL_UNSIGNED_INT_24_8_EXT
:
2862 const GLuint
*s
= (const GLuint
*) src
;
2863 if (unpack
->SwapBytes
) {
2864 for (i
= 0; i
< n
; i
++) {
2865 GLuint value
= s
[i
];
2867 indexes
[i
] = value
& 0xff; /* lower 8 bits */
2871 for (i
= 0; i
< n
; i
++)
2872 indexes
[i
] = s
[i
] & 0xfff; /* lower 8 bits */
2878 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2885 * This function extracts floating point RGBA values from arbitrary
2886 * image data. srcFormat and srcType are the format and type parameters
2887 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2889 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2890 * implements the "Conversion to floating point", "Conversion to RGB",
2891 * and "Final Expansion to RGBA" operations.
2893 * Args: n - number of pixels
2894 * rgba - output colors
2895 * srcFormat - format of incoming data
2896 * srcType - data type of incoming data
2897 * src - source data pointer
2898 * swapBytes - perform byteswapping of incoming data?
2901 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2902 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2903 GLboolean swapBytes
)
2905 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2907 GLint rComp
, bComp
, gComp
, aComp
;
2909 ASSERT(srcFormat
== GL_RED
||
2910 srcFormat
== GL_GREEN
||
2911 srcFormat
== GL_BLUE
||
2912 srcFormat
== GL_ALPHA
||
2913 srcFormat
== GL_LUMINANCE
||
2914 srcFormat
== GL_LUMINANCE_ALPHA
||
2915 srcFormat
== GL_INTENSITY
||
2916 srcFormat
== GL_RGB
||
2917 srcFormat
== GL_BGR
||
2918 srcFormat
== GL_RGBA
||
2919 srcFormat
== GL_BGRA
||
2920 srcFormat
== GL_ABGR_EXT
||
2921 srcFormat
== GL_DUDV_ATI
);
2923 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2924 srcType
== GL_BYTE
||
2925 srcType
== GL_UNSIGNED_SHORT
||
2926 srcType
== GL_SHORT
||
2927 srcType
== GL_UNSIGNED_INT
||
2928 srcType
== GL_INT
||
2929 srcType
== GL_HALF_FLOAT_ARB
||
2930 srcType
== GL_FLOAT
||
2931 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2932 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2933 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2934 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2935 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2936 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2937 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2938 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2939 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2940 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2941 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2942 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2944 rComp
= gComp
= bComp
= aComp
= -1;
2946 switch (srcFormat
) {
2949 greenIndex
= blueIndex
= alphaIndex
= -1;
2954 redIndex
= blueIndex
= alphaIndex
= -1;
2959 redIndex
= greenIndex
= alphaIndex
= -1;
2963 redIndex
= greenIndex
= blueIndex
= -1;
2968 redIndex
= greenIndex
= blueIndex
= 0;
2972 case GL_LUMINANCE_ALPHA
:
2973 redIndex
= greenIndex
= blueIndex
= 0;
2978 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
3044 _mesa_problem(NULL
, "bad srcFormat in extract float data");
3049 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
3050 if ((INDEX) < 0) { \
3052 for (i = 0; i < n; i++) { \
3053 rgba[i][CHANNEL] = DEFAULT; \
3056 else if (swapBytes) { \
3057 const TYPE *s = (const TYPE *) src; \
3059 for (i = 0; i < n; i++) { \
3060 TYPE value = s[INDEX]; \
3061 if (sizeof(TYPE) == 2) { \
3064 else if (sizeof(TYPE) == 4) { \
3067 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
3072 const TYPE *s = (const TYPE *) src; \
3074 for (i = 0; i < n; i++) { \
3075 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
3081 case GL_UNSIGNED_BYTE
:
3082 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3083 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3084 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3085 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3088 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3089 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3090 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3091 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
3093 case GL_UNSIGNED_SHORT
:
3094 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3095 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3096 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3097 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
3100 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3101 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3102 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3103 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
3105 case GL_UNSIGNED_INT
:
3106 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3107 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3108 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3109 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
3112 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3113 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3114 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3115 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
3118 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3119 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3120 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3121 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
3123 case GL_HALF_FLOAT_ARB
:
3124 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3125 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3126 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3127 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
3129 case GL_UNSIGNED_BYTE_3_3_2
:
3131 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3133 for (i
= 0; i
< n
; i
++) {
3134 GLubyte p
= ubsrc
[i
];
3135 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
3136 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
3137 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
3138 rgba
[i
][aComp
] = 1.0F
;
3142 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3144 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3146 for (i
= 0; i
< n
; i
++) {
3147 GLubyte p
= ubsrc
[i
];
3148 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
3149 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
3150 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
3151 rgba
[i
][aComp
] = 1.0F
;
3155 case GL_UNSIGNED_SHORT_5_6_5
:
3157 const GLushort
*ussrc
= (const GLushort
*) src
;
3159 for (i
= 0; i
< n
; i
++) {
3160 GLushort p
= ussrc
[i
];
3162 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3163 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3164 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3165 rgba
[i
][aComp
] = 1.0F
;
3169 const GLushort
*ussrc
= (const GLushort
*) src
;
3171 for (i
= 0; i
< n
; i
++) {
3172 GLushort p
= ussrc
[i
];
3173 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3174 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3175 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3176 rgba
[i
][aComp
] = 1.0F
;
3180 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3182 const GLushort
*ussrc
= (const GLushort
*) src
;
3184 for (i
= 0; i
< n
; i
++) {
3185 GLushort p
= ussrc
[i
];
3187 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3188 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3189 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3190 rgba
[i
][aComp
] = 1.0F
;
3194 const GLushort
*ussrc
= (const GLushort
*) src
;
3196 for (i
= 0; i
< n
; i
++) {
3197 GLushort p
= ussrc
[i
];
3198 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3199 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3200 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3201 rgba
[i
][aComp
] = 1.0F
;
3205 case GL_UNSIGNED_SHORT_4_4_4_4
:
3207 const GLushort
*ussrc
= (const GLushort
*) src
;
3209 for (i
= 0; i
< n
; i
++) {
3210 GLushort p
= ussrc
[i
];
3212 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3213 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3214 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3215 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3219 const GLushort
*ussrc
= (const GLushort
*) src
;
3221 for (i
= 0; i
< n
; i
++) {
3222 GLushort p
= ussrc
[i
];
3223 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3224 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3225 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3226 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3230 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3232 const GLushort
*ussrc
= (const GLushort
*) src
;
3234 for (i
= 0; i
< n
; i
++) {
3235 GLushort p
= ussrc
[i
];
3237 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3238 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3239 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3240 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3244 const GLushort
*ussrc
= (const GLushort
*) src
;
3246 for (i
= 0; i
< n
; i
++) {
3247 GLushort p
= ussrc
[i
];
3248 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3249 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3250 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3251 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3255 case GL_UNSIGNED_SHORT_5_5_5_1
:
3257 const GLushort
*ussrc
= (const GLushort
*) src
;
3259 for (i
= 0; i
< n
; i
++) {
3260 GLushort p
= ussrc
[i
];
3262 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3263 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3264 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3265 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3269 const GLushort
*ussrc
= (const GLushort
*) src
;
3271 for (i
= 0; i
< n
; i
++) {
3272 GLushort p
= ussrc
[i
];
3273 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3274 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3275 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3276 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3280 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3282 const GLushort
*ussrc
= (const GLushort
*) src
;
3284 for (i
= 0; i
< n
; i
++) {
3285 GLushort p
= ussrc
[i
];
3287 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3288 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3289 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3290 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3294 const GLushort
*ussrc
= (const GLushort
*) src
;
3296 for (i
= 0; i
< n
; i
++) {
3297 GLushort p
= ussrc
[i
];
3298 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3299 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3300 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3301 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3305 case GL_UNSIGNED_INT_8_8_8_8
:
3307 const GLuint
*uisrc
= (const GLuint
*) src
;
3309 for (i
= 0; i
< n
; i
++) {
3310 GLuint p
= uisrc
[i
];
3311 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3312 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3313 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3314 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3318 const GLuint
*uisrc
= (const GLuint
*) src
;
3320 for (i
= 0; i
< n
; i
++) {
3321 GLuint p
= uisrc
[i
];
3322 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3323 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3324 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3325 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3329 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3331 const GLuint
*uisrc
= (const GLuint
*) src
;
3333 for (i
= 0; i
< n
; i
++) {
3334 GLuint p
= uisrc
[i
];
3335 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3336 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3337 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3338 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3342 const GLuint
*uisrc
= (const GLuint
*) src
;
3344 for (i
= 0; i
< n
; i
++) {
3345 GLuint p
= uisrc
[i
];
3346 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3347 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3348 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3349 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3353 case GL_UNSIGNED_INT_10_10_10_2
:
3355 const GLuint
*uisrc
= (const GLuint
*) src
;
3357 for (i
= 0; i
< n
; i
++) {
3358 GLuint p
= uisrc
[i
];
3360 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3361 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3362 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3363 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3367 const GLuint
*uisrc
= (const GLuint
*) src
;
3369 for (i
= 0; i
< n
; i
++) {
3370 GLuint p
= uisrc
[i
];
3371 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3372 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3373 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3374 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3378 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3380 const GLuint
*uisrc
= (const GLuint
*) src
;
3382 for (i
= 0; i
< n
; i
++) {
3383 GLuint p
= uisrc
[i
];
3385 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3386 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3387 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3388 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3392 const GLuint
*uisrc
= (const GLuint
*) src
;
3394 for (i
= 0; i
< n
; i
++) {
3395 GLuint p
= uisrc
[i
];
3396 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3397 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3398 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3399 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3404 _mesa_problem(NULL
, "bad srcType in extract float data");
3411 * Unpack a row of color image data from a client buffer according to
3412 * the pixel unpacking parameters.
3413 * Return GLchan values in the specified dest image format.
3414 * This is used by glDrawPixels and glTexImage?D().
3415 * \param ctx - the context
3416 * n - number of pixels in the span
3417 * dstFormat - format of destination color array
3418 * dest - the destination color array
3419 * srcFormat - source image format
3420 * srcType - source image data type
3421 * source - source image pointer
3422 * srcPacking - pixel unpacking parameters
3423 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
3425 * XXX perhaps expand this to process whole images someday.
3428 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
3429 GLuint n
, GLenum dstFormat
, GLchan dest
[],
3430 GLenum srcFormat
, GLenum srcType
,
3431 const GLvoid
*source
,
3432 const struct gl_pixelstore_attrib
*srcPacking
,
3433 GLbitfield transferOps
)
3435 ASSERT(dstFormat
== GL_ALPHA
||
3436 dstFormat
== GL_LUMINANCE
||
3437 dstFormat
== GL_LUMINANCE_ALPHA
||
3438 dstFormat
== GL_INTENSITY
||
3439 dstFormat
== GL_RGB
||
3440 dstFormat
== GL_RGBA
||
3441 dstFormat
== GL_COLOR_INDEX
);
3443 ASSERT(srcFormat
== GL_RED
||
3444 srcFormat
== GL_GREEN
||
3445 srcFormat
== GL_BLUE
||
3446 srcFormat
== GL_ALPHA
||
3447 srcFormat
== GL_LUMINANCE
||
3448 srcFormat
== GL_LUMINANCE_ALPHA
||
3449 srcFormat
== GL_INTENSITY
||
3450 srcFormat
== GL_RGB
||
3451 srcFormat
== GL_BGR
||
3452 srcFormat
== GL_RGBA
||
3453 srcFormat
== GL_BGRA
||
3454 srcFormat
== GL_ABGR_EXT
||
3455 srcFormat
== GL_COLOR_INDEX
);
3457 ASSERT(srcType
== GL_BITMAP
||
3458 srcType
== GL_UNSIGNED_BYTE
||
3459 srcType
== GL_BYTE
||
3460 srcType
== GL_UNSIGNED_SHORT
||
3461 srcType
== GL_SHORT
||
3462 srcType
== GL_UNSIGNED_INT
||
3463 srcType
== GL_INT
||
3464 srcType
== GL_HALF_FLOAT_ARB
||
3465 srcType
== GL_FLOAT
||
3466 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3467 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3468 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3469 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3470 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3471 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3472 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3473 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3474 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3475 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3476 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3477 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3479 /* Try simple cases first */
3480 if (transferOps
== 0) {
3481 if (srcType
== CHAN_TYPE
) {
3482 if (dstFormat
== GL_RGBA
) {
3483 if (srcFormat
== GL_RGBA
) {
3484 _mesa_memcpy( dest
, source
, n
* 4 * sizeof(GLchan
) );
3487 else if (srcFormat
== GL_RGB
) {
3489 const GLchan
*src
= (const GLchan
*) source
;
3491 for (i
= 0; i
< n
; i
++) {
3502 else if (dstFormat
== GL_RGB
) {
3503 if (srcFormat
== GL_RGB
) {
3504 _mesa_memcpy( dest
, source
, n
* 3 * sizeof(GLchan
) );
3507 else if (srcFormat
== GL_RGBA
) {
3509 const GLchan
*src
= (const GLchan
*) source
;
3511 for (i
= 0; i
< n
; i
++) {
3521 else if (dstFormat
== srcFormat
) {
3522 GLint comps
= _mesa_components_in_format(srcFormat
);
3524 _mesa_memcpy( dest
, source
, n
* comps
* sizeof(GLchan
) );
3529 * Common situation, loading 8bit RGBA/RGB source images
3530 * into 16/32 bit destination. (OSMesa16/32)
3532 else if (srcType
== GL_UNSIGNED_BYTE
) {
3533 if (dstFormat
== GL_RGBA
) {
3534 if (srcFormat
== GL_RGB
) {
3536 const GLubyte
*src
= (const GLubyte
*) source
;
3538 for (i
= 0; i
< n
; i
++) {
3539 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3540 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3541 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3548 else if (srcFormat
== GL_RGBA
) {
3550 const GLubyte
*src
= (const GLubyte
*) source
;
3552 for (i
= 0; i
< n
; i
++) {
3553 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3554 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3555 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3556 dst
[3] = UBYTE_TO_CHAN(src
[3]);
3563 else if (dstFormat
== GL_RGB
) {
3564 if (srcFormat
== GL_RGB
) {
3566 const GLubyte
*src
= (const GLubyte
*) source
;
3568 for (i
= 0; i
< n
; i
++) {
3569 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3570 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3571 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3577 else if (srcFormat
== GL_RGBA
) {
3579 const GLubyte
*src
= (const GLubyte
*) source
;
3581 for (i
= 0; i
< n
; i
++) {
3582 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3583 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3584 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3595 /* general solution begins here */
3597 GLint dstComponents
;
3598 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3599 GLint dstLuminanceIndex
, dstIntensityIndex
;
3600 GLfloat rgba
[MAX_WIDTH
][4];
3602 dstComponents
= _mesa_components_in_format( dstFormat
);
3603 /* source & dest image formats should have been error checked by now */
3604 assert(dstComponents
> 0);
3607 * Extract image data and convert to RGBA floats
3609 assert(n
<= MAX_WIDTH
);
3610 if (srcFormat
== GL_COLOR_INDEX
) {
3611 GLuint indexes
[MAX_WIDTH
];
3612 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3615 if (dstFormat
== GL_COLOR_INDEX
) {
3617 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3618 /* convert to GLchan and return */
3619 for (i
= 0; i
< n
; i
++) {
3620 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3625 /* Convert indexes to RGBA */
3626 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3627 shift_and_offset_ci(ctx
, n
, indexes
);
3629 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3632 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3633 * with color indexes.
3635 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3638 /* non-color index data */
3639 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3640 srcPacking
->SwapBytes
);
3643 /* Need to clamp if returning GLubytes or GLushorts */
3644 #if CHAN_TYPE != GL_FLOAT
3645 transferOps
|= IMAGE_CLAMP_BIT
;
3649 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3652 /* Now determine which color channels we need to produce.
3653 * And determine the dest index (offset) within each color tuple.
3655 switch (dstFormat
) {
3658 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3659 dstLuminanceIndex
= dstIntensityIndex
= -1;
3662 dstLuminanceIndex
= 0;
3663 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3664 dstIntensityIndex
= -1;
3666 case GL_LUMINANCE_ALPHA
:
3667 dstLuminanceIndex
= 0;
3669 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3670 dstIntensityIndex
= -1;
3673 dstIntensityIndex
= 0;
3674 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3675 dstLuminanceIndex
= -1;
3681 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3688 dstLuminanceIndex
= dstIntensityIndex
= -1;
3691 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
3696 /* Now return the GLchan data in the requested dstFormat */
3698 if (dstRedIndex
>= 0) {
3701 for (i
= 0; i
< n
; i
++) {
3702 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
3703 dst
+= dstComponents
;
3707 if (dstGreenIndex
>= 0) {
3710 for (i
= 0; i
< n
; i
++) {
3711 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
3712 dst
+= dstComponents
;
3716 if (dstBlueIndex
>= 0) {
3719 for (i
= 0; i
< n
; i
++) {
3720 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
3721 dst
+= dstComponents
;
3725 if (dstAlphaIndex
>= 0) {
3728 for (i
= 0; i
< n
; i
++) {
3729 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
3730 dst
+= dstComponents
;
3734 if (dstIntensityIndex
>= 0) {
3737 assert(dstIntensityIndex
== 0);
3738 assert(dstComponents
== 1);
3739 for (i
= 0; i
< n
; i
++) {
3740 /* Intensity comes from red channel */
3741 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
3745 if (dstLuminanceIndex
>= 0) {
3748 assert(dstLuminanceIndex
== 0);
3749 for (i
= 0; i
< n
; i
++) {
3750 /* Luminance comes from red channel */
3751 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
3752 dst
+= dstComponents
;
3760 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
3761 * instead of GLchan.
3764 _mesa_unpack_color_span_float( GLcontext
*ctx
,
3765 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
3766 GLenum srcFormat
, GLenum srcType
,
3767 const GLvoid
*source
,
3768 const struct gl_pixelstore_attrib
*srcPacking
,
3769 GLbitfield transferOps
)
3771 ASSERT(dstFormat
== GL_ALPHA
||
3772 dstFormat
== GL_LUMINANCE
||
3773 dstFormat
== GL_LUMINANCE_ALPHA
||
3774 dstFormat
== GL_INTENSITY
||
3775 dstFormat
== GL_RGB
||
3776 dstFormat
== GL_RGBA
||
3777 dstFormat
== GL_COLOR_INDEX
);
3779 ASSERT(srcFormat
== GL_RED
||
3780 srcFormat
== GL_GREEN
||
3781 srcFormat
== GL_BLUE
||
3782 srcFormat
== GL_ALPHA
||
3783 srcFormat
== GL_LUMINANCE
||
3784 srcFormat
== GL_LUMINANCE_ALPHA
||
3785 srcFormat
== GL_INTENSITY
||
3786 srcFormat
== GL_RGB
||
3787 srcFormat
== GL_BGR
||
3788 srcFormat
== GL_RGBA
||
3789 srcFormat
== GL_BGRA
||
3790 srcFormat
== GL_ABGR_EXT
||
3791 srcFormat
== GL_COLOR_INDEX
);
3793 ASSERT(srcType
== GL_BITMAP
||
3794 srcType
== GL_UNSIGNED_BYTE
||
3795 srcType
== GL_BYTE
||
3796 srcType
== GL_UNSIGNED_SHORT
||
3797 srcType
== GL_SHORT
||
3798 srcType
== GL_UNSIGNED_INT
||
3799 srcType
== GL_INT
||
3800 srcType
== GL_HALF_FLOAT_ARB
||
3801 srcType
== GL_FLOAT
||
3802 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3803 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3804 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3805 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3806 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3807 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3808 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3809 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3810 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3811 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3812 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3813 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3815 /* general solution, no special cases, yet */
3817 GLint dstComponents
;
3818 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3819 GLint dstLuminanceIndex
, dstIntensityIndex
;
3820 GLfloat rgba
[MAX_WIDTH
][4];
3822 dstComponents
= _mesa_components_in_format( dstFormat
);
3823 /* source & dest image formats should have been error checked by now */
3824 assert(dstComponents
> 0);
3827 * Extract image data and convert to RGBA floats
3829 assert(n
<= MAX_WIDTH
);
3830 if (srcFormat
== GL_COLOR_INDEX
) {
3831 GLuint indexes
[MAX_WIDTH
];
3832 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3835 if (dstFormat
== GL_COLOR_INDEX
) {
3837 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3838 /* convert to GLchan and return */
3839 for (i
= 0; i
< n
; i
++) {
3840 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3845 /* Convert indexes to RGBA */
3846 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3847 shift_and_offset_ci(ctx
, n
, indexes
);
3849 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3852 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3853 * with color indexes.
3855 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3858 /* non-color index data */
3859 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3860 srcPacking
->SwapBytes
);
3864 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3867 /* Now determine which color channels we need to produce.
3868 * And determine the dest index (offset) within each color tuple.
3870 switch (dstFormat
) {
3873 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3874 dstLuminanceIndex
= dstIntensityIndex
= -1;
3877 dstLuminanceIndex
= 0;
3878 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3879 dstIntensityIndex
= -1;
3881 case GL_LUMINANCE_ALPHA
:
3882 dstLuminanceIndex
= 0;
3884 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3885 dstIntensityIndex
= -1;
3888 dstIntensityIndex
= 0;
3889 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3890 dstLuminanceIndex
= -1;
3896 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3903 dstLuminanceIndex
= dstIntensityIndex
= -1;
3906 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
3910 /* Now pack results in the requested dstFormat */
3911 if (dstRedIndex
>= 0) {
3912 GLfloat
*dst
= dest
;
3914 for (i
= 0; i
< n
; i
++) {
3915 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3916 dst
+= dstComponents
;
3920 if (dstGreenIndex
>= 0) {
3921 GLfloat
*dst
= dest
;
3923 for (i
= 0; i
< n
; i
++) {
3924 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3925 dst
+= dstComponents
;
3929 if (dstBlueIndex
>= 0) {
3930 GLfloat
*dst
= dest
;
3932 for (i
= 0; i
< n
; i
++) {
3933 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3934 dst
+= dstComponents
;
3938 if (dstAlphaIndex
>= 0) {
3939 GLfloat
*dst
= dest
;
3941 for (i
= 0; i
< n
; i
++) {
3942 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3943 dst
+= dstComponents
;
3947 if (dstIntensityIndex
>= 0) {
3948 GLfloat
*dst
= dest
;
3950 assert(dstIntensityIndex
== 0);
3951 assert(dstComponents
== 1);
3952 for (i
= 0; i
< n
; i
++) {
3953 /* Intensity comes from red channel */
3954 dst
[i
] = rgba
[i
][RCOMP
];
3958 if (dstLuminanceIndex
>= 0) {
3959 GLfloat
*dst
= dest
;
3961 assert(dstLuminanceIndex
== 0);
3962 for (i
= 0; i
< n
; i
++) {
3963 /* Luminance comes from red channel */
3964 dst
[0] = rgba
[i
][RCOMP
];
3965 dst
+= dstComponents
;
3972 * Similar to _mesa_unpack_color_span_float(), but for dudv data instead of rgba,
3973 * directly return GLbyte data, no transfer ops apply.
3976 _mesa_unpack_dudv_span_byte( GLcontext
*ctx
,
3977 GLuint n
, GLenum dstFormat
, GLbyte dest
[],
3978 GLenum srcFormat
, GLenum srcType
,
3979 const GLvoid
*source
,
3980 const struct gl_pixelstore_attrib
*srcPacking
,
3981 GLbitfield transferOps
)
3983 ASSERT(dstFormat
== GL_DUDV_ATI
);
3984 ASSERT(srcFormat
== GL_DUDV_ATI
);
3986 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
3987 srcType
== GL_BYTE
||
3988 srcType
== GL_UNSIGNED_SHORT
||
3989 srcType
== GL_SHORT
||
3990 srcType
== GL_UNSIGNED_INT
||
3991 srcType
== GL_INT
||
3992 srcType
== GL_HALF_FLOAT_ARB
||
3993 srcType
== GL_FLOAT
);
3995 /* general solution */
3997 GLint dstComponents
;
3998 GLfloat rgba
[MAX_WIDTH
][4];
4000 dstComponents
= _mesa_components_in_format( dstFormat
);
4001 /* source & dest image formats should have been error checked by now */
4002 assert(dstComponents
> 0);
4005 * Extract image data and convert to RGBA floats
4007 assert(n
<= MAX_WIDTH
);
4008 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
4009 srcPacking
->SwapBytes
);
4012 /* Now determine which color channels we need to produce.
4013 * And determine the dest index (offset) within each color tuple.
4016 /* Now pack results in the requested dstFormat */
4019 for (i
= 0; i
< n
; i
++) {
4020 /* not sure - need clamp[-1,1] here? */
4021 dst
[0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
4022 dst
[1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
4023 dst
+= dstComponents
;
4029 * Unpack a row of color index data from a client buffer according to
4030 * the pixel unpacking parameters.
4031 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
4033 * Args: ctx - the context
4034 * n - number of pixels
4035 * dstType - destination data type
4036 * dest - destination array
4037 * srcType - source pixel type
4038 * source - source data pointer
4039 * srcPacking - pixel unpacking parameters
4040 * transferOps - the pixel transfer operations to apply
4043 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
4044 GLenum dstType
, GLvoid
*dest
,
4045 GLenum srcType
, const GLvoid
*source
,
4046 const struct gl_pixelstore_attrib
*srcPacking
,
4047 GLbitfield transferOps
)
4049 ASSERT(srcType
== GL_BITMAP
||
4050 srcType
== GL_UNSIGNED_BYTE
||
4051 srcType
== GL_BYTE
||
4052 srcType
== GL_UNSIGNED_SHORT
||
4053 srcType
== GL_SHORT
||
4054 srcType
== GL_UNSIGNED_INT
||
4055 srcType
== GL_INT
||
4056 srcType
== GL_HALF_FLOAT_ARB
||
4057 srcType
== GL_FLOAT
);
4059 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4060 dstType
== GL_UNSIGNED_SHORT
||
4061 dstType
== GL_UNSIGNED_INT
);
4064 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4067 * Try simple cases first
4069 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
4070 && dstType
== GL_UNSIGNED_BYTE
) {
4071 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
4073 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
4074 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
4075 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
4081 GLuint indexes
[MAX_WIDTH
];
4082 assert(n
<= MAX_WIDTH
);
4084 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
4088 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4090 /* convert to dest type */
4092 case GL_UNSIGNED_BYTE
:
4094 GLubyte
*dst
= (GLubyte
*) dest
;
4096 for (i
= 0; i
< n
; i
++) {
4097 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4101 case GL_UNSIGNED_SHORT
:
4103 GLuint
*dst
= (GLuint
*) dest
;
4105 for (i
= 0; i
< n
; i
++) {
4106 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4110 case GL_UNSIGNED_INT
:
4111 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4114 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
4121 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
4122 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
4123 const struct gl_pixelstore_attrib
*dstPacking
,
4124 GLbitfield transferOps
)
4126 GLuint indexes
[MAX_WIDTH
];
4128 ASSERT(n
<= MAX_WIDTH
);
4130 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4132 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
4133 /* make a copy of input */
4134 _mesa_memcpy(indexes
, source
, n
* sizeof(GLuint
));
4135 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4140 case GL_UNSIGNED_BYTE
:
4142 GLubyte
*dst
= (GLubyte
*) dest
;
4144 for (i
= 0; i
< n
; i
++) {
4145 *dst
++ = (GLubyte
) source
[i
];
4151 GLbyte
*dst
= (GLbyte
*) dest
;
4153 for (i
= 0; i
< n
; i
++) {
4154 dst
[i
] = (GLbyte
) source
[i
];
4158 case GL_UNSIGNED_SHORT
:
4160 GLushort
*dst
= (GLushort
*) dest
;
4162 for (i
= 0; i
< n
; i
++) {
4163 dst
[i
] = (GLushort
) source
[i
];
4165 if (dstPacking
->SwapBytes
) {
4166 _mesa_swap2( (GLushort
*) dst
, n
);
4172 GLshort
*dst
= (GLshort
*) dest
;
4174 for (i
= 0; i
< n
; i
++) {
4175 dst
[i
] = (GLshort
) source
[i
];
4177 if (dstPacking
->SwapBytes
) {
4178 _mesa_swap2( (GLushort
*) dst
, n
);
4182 case GL_UNSIGNED_INT
:
4184 GLuint
*dst
= (GLuint
*) dest
;
4186 for (i
= 0; i
< n
; i
++) {
4187 dst
[i
] = (GLuint
) source
[i
];
4189 if (dstPacking
->SwapBytes
) {
4190 _mesa_swap4( (GLuint
*) dst
, n
);
4196 GLint
*dst
= (GLint
*) dest
;
4198 for (i
= 0; i
< n
; i
++) {
4199 dst
[i
] = (GLint
) source
[i
];
4201 if (dstPacking
->SwapBytes
) {
4202 _mesa_swap4( (GLuint
*) dst
, n
);
4208 GLfloat
*dst
= (GLfloat
*) dest
;
4210 for (i
= 0; i
< n
; i
++) {
4211 dst
[i
] = (GLfloat
) source
[i
];
4213 if (dstPacking
->SwapBytes
) {
4214 _mesa_swap4( (GLuint
*) dst
, n
);
4218 case GL_HALF_FLOAT_ARB
:
4220 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4222 for (i
= 0; i
< n
; i
++) {
4223 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
4225 if (dstPacking
->SwapBytes
) {
4226 _mesa_swap2( (GLushort
*) dst
, n
);
4231 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4237 * Unpack a row of stencil data from a client buffer according to
4238 * the pixel unpacking parameters.
4239 * This is (or will be) used by glDrawPixels
4241 * Args: ctx - the context
4242 * n - number of pixels
4243 * dstType - destination data type
4244 * dest - destination array
4245 * srcType - source pixel type
4246 * source - source data pointer
4247 * srcPacking - pixel unpacking parameters
4248 * transferOps - apply offset/bias/lookup ops?
4251 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4252 GLenum dstType
, GLvoid
*dest
,
4253 GLenum srcType
, const GLvoid
*source
,
4254 const struct gl_pixelstore_attrib
*srcPacking
,
4255 GLbitfield transferOps
)
4257 ASSERT(srcType
== GL_BITMAP
||
4258 srcType
== GL_UNSIGNED_BYTE
||
4259 srcType
== GL_BYTE
||
4260 srcType
== GL_UNSIGNED_SHORT
||
4261 srcType
== GL_SHORT
||
4262 srcType
== GL_UNSIGNED_INT
||
4263 srcType
== GL_INT
||
4264 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
4265 srcType
== GL_HALF_FLOAT_ARB
||
4266 srcType
== GL_FLOAT
);
4268 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4269 dstType
== GL_UNSIGNED_SHORT
||
4270 dstType
== GL_UNSIGNED_INT
);
4272 /* only shift and offset apply to stencil */
4273 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
4276 * Try simple cases first
4278 if (transferOps
== 0 &&
4279 !ctx
->Pixel
.MapStencilFlag
&&
4280 srcType
== GL_UNSIGNED_BYTE
&&
4281 dstType
== GL_UNSIGNED_BYTE
) {
4282 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
4284 else if (transferOps
== 0 &&
4285 !ctx
->Pixel
.MapStencilFlag
&&
4286 srcType
== GL_UNSIGNED_INT
&&
4287 dstType
== GL_UNSIGNED_INT
&&
4288 !srcPacking
->SwapBytes
) {
4289 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
4295 GLuint indexes
[MAX_WIDTH
];
4296 assert(n
<= MAX_WIDTH
);
4298 extract_uint_indexes(n
, indexes
, GL_STENCIL_INDEX
, srcType
, source
,
4301 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
4302 /* shift and offset indexes */
4303 shift_and_offset_ci(ctx
, n
, indexes
);
4306 if (ctx
->Pixel
.MapStencilFlag
) {
4307 /* Apply stencil lookup table */
4308 const GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
4310 for (i
= 0; i
< n
; i
++) {
4311 indexes
[i
] = (GLuint
)ctx
->PixelMaps
.StoS
.Map
[ indexes
[i
] & mask
];
4315 /* convert to dest type */
4317 case GL_UNSIGNED_BYTE
:
4319 GLubyte
*dst
= (GLubyte
*) dest
;
4321 for (i
= 0; i
< n
; i
++) {
4322 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4326 case GL_UNSIGNED_SHORT
:
4328 GLuint
*dst
= (GLuint
*) dest
;
4330 for (i
= 0; i
< n
; i
++) {
4331 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4335 case GL_UNSIGNED_INT
:
4336 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4339 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
4346 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4347 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
4348 const struct gl_pixelstore_attrib
*dstPacking
)
4350 GLstencil stencil
[MAX_WIDTH
];
4352 ASSERT(n
<= MAX_WIDTH
);
4354 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
4355 ctx
->Pixel
.MapStencilFlag
) {
4356 /* make a copy of input */
4357 _mesa_memcpy(stencil
, source
, n
* sizeof(GLstencil
));
4358 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencil
);
4363 case GL_UNSIGNED_BYTE
:
4364 if (sizeof(GLstencil
) == 1) {
4365 _mesa_memcpy( dest
, source
, n
);
4368 GLubyte
*dst
= (GLubyte
*) dest
;
4371 dst
[i
] = (GLubyte
) source
[i
];
4377 GLbyte
*dst
= (GLbyte
*) dest
;
4380 dst
[i
] = (GLbyte
) (source
[i
] & 0x7f);
4384 case GL_UNSIGNED_SHORT
:
4386 GLushort
*dst
= (GLushort
*) dest
;
4389 dst
[i
] = (GLushort
) source
[i
];
4391 if (dstPacking
->SwapBytes
) {
4392 _mesa_swap2( (GLushort
*) dst
, n
);
4398 GLshort
*dst
= (GLshort
*) dest
;
4401 dst
[i
] = (GLshort
) source
[i
];
4403 if (dstPacking
->SwapBytes
) {
4404 _mesa_swap2( (GLushort
*) dst
, n
);
4408 case GL_UNSIGNED_INT
:
4410 GLuint
*dst
= (GLuint
*) dest
;
4413 dst
[i
] = (GLuint
) source
[i
];
4415 if (dstPacking
->SwapBytes
) {
4416 _mesa_swap4( (GLuint
*) dst
, n
);
4422 GLint
*dst
= (GLint
*) dest
;
4425 dst
[i
] = (GLint
) source
[i
];
4427 if (dstPacking
->SwapBytes
) {
4428 _mesa_swap4( (GLuint
*) dst
, n
);
4434 GLfloat
*dst
= (GLfloat
*) dest
;
4437 dst
[i
] = (GLfloat
) source
[i
];
4439 if (dstPacking
->SwapBytes
) {
4440 _mesa_swap4( (GLuint
*) dst
, n
);
4444 case GL_HALF_FLOAT_ARB
:
4446 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4449 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
4451 if (dstPacking
->SwapBytes
) {
4452 _mesa_swap2( (GLushort
*) dst
, n
);
4457 if (dstPacking
->LsbFirst
) {
4458 GLubyte
*dst
= (GLubyte
*) dest
;
4461 for (i
= 0; i
< n
; i
++) {
4464 *dst
|= ((source
[i
] != 0) << shift
);
4473 GLubyte
*dst
= (GLubyte
*) dest
;
4476 for (i
= 0; i
< n
; i
++) {
4479 *dst
|= ((source
[i
] != 0) << shift
);
4489 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4493 #define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT) \
4496 const GLTYPE *src = (const GLTYPE *)source; \
4497 for (i = 0; i < n; i++) { \
4498 GLTYPE value = src[i]; \
4499 if (srcPacking->SwapBytes) { \
4500 if (sizeof(GLTYPE) == 2) { \
4502 } else if (sizeof(GLTYPE) == 4) { \
4506 depthValues[i] = GLTYPE2FLOAT(value); \
4512 * Unpack a row of depth/z values from memory, returning GLushort, GLuint
4513 * or GLfloat values.
4514 * The glPixelTransfer (scale/bias) params will be applied.
4516 * \param dstType one of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT
4517 * \param depthMax max value for returned GLushort or GLuint values
4518 * (ignored for GLfloat).
4521 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
,
4522 GLenum dstType
, GLvoid
*dest
, GLuint depthMax
,
4523 GLenum srcType
, const GLvoid
*source
,
4524 const struct gl_pixelstore_attrib
*srcPacking
)
4526 GLfloat depthTemp
[MAX_WIDTH
], *depthValues
;
4527 GLboolean needClamp
= GL_FALSE
;
4529 /* Look for special cases first.
4530 * Not only are these faster, they're less prone to numeric conversion
4531 * problems. Otherwise, converting from an int type to a float then
4532 * back to an int type can introduce errors that will show up as
4533 * artifacts in things like depth peeling which uses glCopyTexImage.
4535 if (ctx
->Pixel
.DepthScale
== 1.0 && ctx
->Pixel
.DepthBias
== 0.0) {
4536 if (srcType
== GL_UNSIGNED_INT
&& dstType
== GL_UNSIGNED_SHORT
) {
4537 const GLuint
*src
= (const GLuint
*) source
;
4538 GLushort
*dst
= (GLushort
*) dest
;
4540 for (i
= 0; i
< n
; i
++) {
4541 dst
[i
] = src
[i
] >> 16;
4545 if (srcType
== GL_UNSIGNED_SHORT
4546 && dstType
== GL_UNSIGNED_INT
4547 && depthMax
== 0xffffffff) {
4548 const GLushort
*src
= (const GLushort
*) source
;
4549 GLuint
*dst
= (GLuint
*) dest
;
4551 for (i
= 0; i
< n
; i
++) {
4552 dst
[i
] = src
[i
] | (src
[i
] << 16);
4556 /* XXX may want to add additional cases here someday */
4559 /* general case path follows */
4561 if (dstType
== GL_FLOAT
) {
4562 depthValues
= (GLfloat
*) dest
;
4565 depthValues
= depthTemp
;
4568 /* Convert incoming values to GLfloat. Some conversions will require
4573 DEPTH_VALUES(GLbyte
, BYTE_TO_FLOAT
);
4574 needClamp
= GL_TRUE
;
4576 case GL_UNSIGNED_BYTE
:
4577 DEPTH_VALUES(GLubyte
, UBYTE_TO_FLOAT
);
4580 DEPTH_VALUES(GLshort
, SHORT_TO_FLOAT
);
4581 needClamp
= GL_TRUE
;
4583 case GL_UNSIGNED_SHORT
:
4584 DEPTH_VALUES(GLushort
, USHORT_TO_FLOAT
);
4587 DEPTH_VALUES(GLint
, INT_TO_FLOAT
);
4588 needClamp
= GL_TRUE
;
4590 case GL_UNSIGNED_INT
:
4591 DEPTH_VALUES(GLuint
, UINT_TO_FLOAT
);
4593 case GL_UNSIGNED_INT_24_8_EXT
: /* GL_EXT_packed_depth_stencil */
4594 if (dstType
== GL_UNSIGNED_INT_24_8_EXT
&&
4595 depthMax
== 0xffffff &&
4596 ctx
->Pixel
.DepthScale
== 1.0 &&
4597 ctx
->Pixel
.DepthBias
== 0.0) {
4598 const GLuint
*src
= (const GLuint
*) source
;
4599 GLuint
*zValues
= (GLuint
*) dest
;
4601 for (i
= 0; i
< n
; i
++) {
4602 GLuint value
= src
[i
];
4603 if (srcPacking
->SwapBytes
) {
4606 zValues
[i
] = value
& 0xffffff00;
4611 const GLuint
*src
= (const GLuint
*) source
;
4612 const GLfloat scale
= 1.0f
/ 0xffffff;
4614 for (i
= 0; i
< n
; i
++) {
4615 GLuint value
= src
[i
];
4616 if (srcPacking
->SwapBytes
) {
4619 depthValues
[i
] = (value
>> 8) * scale
;
4624 DEPTH_VALUES(GLfloat
, 1*);
4625 needClamp
= GL_TRUE
;
4627 case GL_HALF_FLOAT_ARB
:
4630 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
4631 for (i
= 0; i
< n
; i
++) {
4632 GLhalfARB value
= src
[i
];
4633 if (srcPacking
->SwapBytes
) {
4636 depthValues
[i
] = _mesa_half_to_float(value
);
4638 needClamp
= GL_TRUE
;
4642 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
4646 /* apply depth scale and bias */
4648 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
4649 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
4650 if (scale
!= 1.0 || bias
!= 0.0) {
4652 for (i
= 0; i
< n
; i
++) {
4653 depthValues
[i
] = depthValues
[i
] * scale
+ bias
;
4655 needClamp
= GL_TRUE
;
4659 /* clamp to [0, 1] */
4662 for (i
= 0; i
< n
; i
++) {
4663 depthValues
[i
] = (GLfloat
)CLAMP(depthValues
[i
], 0.0, 1.0);
4668 * Convert values to dstType
4670 if (dstType
== GL_UNSIGNED_INT
) {
4671 GLuint
*zValues
= (GLuint
*) dest
;
4673 if (depthMax
<= 0xffffff) {
4674 /* no overflow worries */
4675 for (i
= 0; i
< n
; i
++) {
4676 zValues
[i
] = (GLuint
) (depthValues
[i
] * (GLfloat
) depthMax
);
4680 /* need to use double precision to prevent overflow problems */
4681 for (i
= 0; i
< n
; i
++) {
4682 GLdouble z
= depthValues
[i
] * (GLfloat
) depthMax
;
4683 if (z
>= (GLdouble
) 0xffffffff)
4684 zValues
[i
] = 0xffffffff;
4686 zValues
[i
] = (GLuint
) z
;
4690 else if (dstType
== GL_UNSIGNED_SHORT
) {
4691 GLushort
*zValues
= (GLushort
*) dest
;
4693 ASSERT(depthMax
<= 0xffff);
4694 for (i
= 0; i
< n
; i
++) {
4695 zValues
[i
] = (GLushort
) (depthValues
[i
] * (GLfloat
) depthMax
);
4699 ASSERT(dstType
== GL_FLOAT
);
4700 /*ASSERT(depthMax == 1.0F);*/
4706 * Pack an array of depth values. The values are floats in [0,1].
4709 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
4710 GLenum dstType
, const GLfloat
*depthSpan
,
4711 const struct gl_pixelstore_attrib
*dstPacking
)
4713 GLfloat depthCopy
[MAX_WIDTH
];
4715 ASSERT(n
<= MAX_WIDTH
);
4717 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4718 _mesa_memcpy(depthCopy
, depthSpan
, n
* sizeof(GLfloat
));
4719 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4720 depthSpan
= depthCopy
;
4724 case GL_UNSIGNED_BYTE
:
4726 GLubyte
*dst
= (GLubyte
*) dest
;
4728 for (i
= 0; i
< n
; i
++) {
4729 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
4735 GLbyte
*dst
= (GLbyte
*) dest
;
4737 for (i
= 0; i
< n
; i
++) {
4738 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
4742 case GL_UNSIGNED_SHORT
:
4744 GLushort
*dst
= (GLushort
*) dest
;
4746 for (i
= 0; i
< n
; i
++) {
4747 CLAMPED_FLOAT_TO_USHORT(dst
[i
], depthSpan
[i
]);
4749 if (dstPacking
->SwapBytes
) {
4750 _mesa_swap2( (GLushort
*) dst
, n
);
4756 GLshort
*dst
= (GLshort
*) dest
;
4758 for (i
= 0; i
< n
; i
++) {
4759 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
4761 if (dstPacking
->SwapBytes
) {
4762 _mesa_swap2( (GLushort
*) dst
, n
);
4766 case GL_UNSIGNED_INT
:
4768 GLuint
*dst
= (GLuint
*) dest
;
4770 for (i
= 0; i
< n
; i
++) {
4771 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
4773 if (dstPacking
->SwapBytes
) {
4774 _mesa_swap4( (GLuint
*) dst
, n
);
4780 GLint
*dst
= (GLint
*) dest
;
4782 for (i
= 0; i
< n
; i
++) {
4783 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
4785 if (dstPacking
->SwapBytes
) {
4786 _mesa_swap4( (GLuint
*) dst
, n
);
4792 GLfloat
*dst
= (GLfloat
*) dest
;
4794 for (i
= 0; i
< n
; i
++) {
4795 dst
[i
] = depthSpan
[i
];
4797 if (dstPacking
->SwapBytes
) {
4798 _mesa_swap4( (GLuint
*) dst
, n
);
4802 case GL_HALF_FLOAT_ARB
:
4804 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4806 for (i
= 0; i
< n
; i
++) {
4807 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
4809 if (dstPacking
->SwapBytes
) {
4810 _mesa_swap2( (GLushort
*) dst
, n
);
4815 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
4822 * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
4825 _mesa_pack_depth_stencil_span(const GLcontext
*ctx
, GLuint n
, GLuint
*dest
,
4826 const GLfloat
*depthVals
,
4827 const GLstencil
*stencilVals
,
4828 const struct gl_pixelstore_attrib
*dstPacking
)
4830 GLfloat depthCopy
[MAX_WIDTH
];
4831 GLstencil stencilCopy
[MAX_WIDTH
];
4834 ASSERT(n
<= MAX_WIDTH
);
4836 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4837 _mesa_memcpy(depthCopy
, depthVals
, n
* sizeof(GLfloat
));
4838 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4839 depthVals
= depthCopy
;
4842 if (ctx
->Pixel
.IndexShift
||
4843 ctx
->Pixel
.IndexOffset
||
4844 ctx
->Pixel
.MapStencilFlag
) {
4845 _mesa_memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
4846 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencilCopy
);
4847 stencilVals
= stencilCopy
;
4850 for (i
= 0; i
< n
; i
++) {
4851 GLuint z
= (GLuint
) (depthVals
[i
] * 0xffffff);
4852 dest
[i
] = (z
<< 8) | (stencilVals
[i
] & 0xff);
4855 if (dstPacking
->SwapBytes
) {
4856 _mesa_swap4(dest
, n
);
4864 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
4865 * Return all image data in a contiguous block. This is used when we
4866 * compile glDrawPixels, glTexImage, etc into a display list. We
4867 * need a copy of the data in a standard format.
4870 _mesa_unpack_image( GLuint dimensions
,
4871 GLsizei width
, GLsizei height
, GLsizei depth
,
4872 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4873 const struct gl_pixelstore_attrib
*unpack
)
4875 GLint bytesPerRow
, compsPerRow
;
4876 GLboolean flipBytes
, swap2
, swap4
;
4879 return NULL
; /* not necessarily an error */
4881 if (width
<= 0 || height
<= 0 || depth
<= 0)
4882 return NULL
; /* generate error later */
4884 if (type
== GL_BITMAP
) {
4885 bytesPerRow
= (width
+ 7) >> 3;
4886 flipBytes
= unpack
->LsbFirst
;
4887 swap2
= swap4
= GL_FALSE
;
4891 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
4892 GLint components
= _mesa_components_in_format(format
);
4895 if (_mesa_type_is_packed(type
))
4898 if (bytesPerPixel
<= 0 || components
<= 0)
4899 return NULL
; /* bad format or type. generate error later */
4900 bytesPerRow
= bytesPerPixel
* width
;
4901 bytesPerComp
= bytesPerPixel
/ components
;
4902 flipBytes
= GL_FALSE
;
4903 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
4904 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
4905 compsPerRow
= components
* width
;
4906 assert(compsPerRow
>= width
);
4911 = (GLubyte
*) _mesa_malloc(bytesPerRow
* height
* depth
);
4915 return NULL
; /* generate GL_OUT_OF_MEMORY later */
4918 for (img
= 0; img
< depth
; img
++) {
4919 for (row
= 0; row
< height
; row
++) {
4920 const GLvoid
*src
= _mesa_image_address(dimensions
, unpack
, pixels
,
4921 width
, height
, format
, type
, img
, row
, 0);
4923 if ((type
== GL_BITMAP
) && (unpack
->SkipPixels
& 0x7)) {
4925 flipBytes
= GL_FALSE
;
4926 if (unpack
->LsbFirst
) {
4927 GLubyte srcMask
= 1 << (unpack
->SkipPixels
& 0x7);
4928 GLubyte dstMask
= 128;
4929 const GLubyte
*s
= src
;
4932 for (i
= 0; i
< width
; i
++) {
4936 if (srcMask
== 128) {
4941 srcMask
= srcMask
<< 1;
4949 dstMask
= dstMask
>> 1;
4954 GLubyte srcMask
= 128 >> (unpack
->SkipPixels
& 0x7);
4955 GLubyte dstMask
= 128;
4956 const GLubyte
*s
= src
;
4959 for (i
= 0; i
< width
; i
++) {
4968 srcMask
= srcMask
>> 1;
4976 dstMask
= dstMask
>> 1;
4982 _mesa_memcpy(dst
, src
, bytesPerRow
);
4985 /* byte flipping/swapping */
4987 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
4990 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
4993 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
5002 #endif /* _HAVE_FULL_GL */
5007 * Convert an array of RGBA colors from one datatype to another.
5008 * NOTE: src may equal dst. In that case, we use a temporary buffer.
5011 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
5012 GLenum dstType
, GLvoid
*dst
,
5013 GLuint count
, const GLubyte mask
[])
5015 GLuint tempBuffer
[MAX_WIDTH
][4];
5016 const GLboolean useTemp
= (src
== dst
);
5018 ASSERT(srcType
!= dstType
);
5021 case GL_UNSIGNED_BYTE
:
5022 if (dstType
== GL_UNSIGNED_SHORT
) {
5023 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5024 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5026 for (i
= 0; i
< count
; i
++) {
5027 if (!mask
|| mask
[i
]) {
5028 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
5029 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
5030 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
5031 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
5035 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5038 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5039 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5041 ASSERT(dstType
== GL_FLOAT
);
5042 for (i
= 0; i
< count
; i
++) {
5043 if (!mask
|| mask
[i
]) {
5044 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
5045 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
5046 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
5047 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
5051 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5054 case GL_UNSIGNED_SHORT
:
5055 if (dstType
== GL_UNSIGNED_BYTE
) {
5056 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5057 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5059 for (i
= 0; i
< count
; i
++) {
5060 if (!mask
|| mask
[i
]) {
5061 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
5062 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
5063 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
5064 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
5068 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5071 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5072 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5074 ASSERT(dstType
== GL_FLOAT
);
5075 for (i
= 0; i
< count
; i
++) {
5076 if (!mask
|| mask
[i
]) {
5077 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
5078 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
5079 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
5080 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
5084 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5088 if (dstType
== GL_UNSIGNED_BYTE
) {
5089 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5090 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5092 for (i
= 0; i
< count
; i
++) {
5093 if (!mask
|| mask
[i
]) {
5094 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
5095 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
5096 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
5097 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
5101 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5104 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5105 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5107 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
5108 for (i
= 0; i
< count
; i
++) {
5109 if (!mask
|| mask
[i
]) {
5110 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
5111 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
5112 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
5113 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
5117 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5121 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
5129 * Perform basic clipping for glDrawPixels. The image's position and size
5130 * and the unpack SkipPixels and SkipRows are adjusted so that the image
5131 * region is entirely within the window and scissor bounds.
5132 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
5133 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
5134 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
5136 * \return GL_TRUE if image is ready for drawing or
5137 * GL_FALSE if image was completely clipped away (draw nothing)
5140 _mesa_clip_drawpixels(const GLcontext
*ctx
,
5141 GLint
*destX
, GLint
*destY
,
5142 GLsizei
*width
, GLsizei
*height
,
5143 struct gl_pixelstore_attrib
*unpack
)
5145 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
5147 if (unpack
->RowLength
== 0) {
5148 unpack
->RowLength
= *width
;
5151 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
5152 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
5155 if (*destX
< buffer
->_Xmin
) {
5156 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
5157 *width
-= (buffer
->_Xmin
- *destX
);
5158 *destX
= buffer
->_Xmin
;
5160 /* right clipping */
5161 if (*destX
+ *width
> buffer
->_Xmax
)
5162 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
5167 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
5168 /* bottom clipping */
5169 if (*destY
< buffer
->_Ymin
) {
5170 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
5171 *height
-= (buffer
->_Ymin
- *destY
);
5172 *destY
= buffer
->_Ymin
;
5175 if (*destY
+ *height
> buffer
->_Ymax
)
5176 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
5178 else { /* upside down */
5180 if (*destY
> buffer
->_Ymax
) {
5181 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
5182 *height
-= (*destY
- buffer
->_Ymax
);
5183 *destY
= buffer
->_Ymax
;
5185 /* bottom clipping */
5186 if (*destY
- *height
< buffer
->_Ymin
)
5187 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
5188 /* adjust destY so it's the first row to write to */
5200 * Perform clipping for glReadPixels. The image's window position
5201 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
5202 * so that the image region is entirely within the window bounds.
5203 * Note: this is different from _mesa_clip_drawpixels() in that the
5204 * scissor box is ignored, and we use the bounds of the current readbuffer
5207 * \return GL_TRUE if image is ready for drawing or
5208 * GL_FALSE if image was completely clipped away (draw nothing)
5211 _mesa_clip_readpixels(const GLcontext
*ctx
,
5212 GLint
*srcX
, GLint
*srcY
,
5213 GLsizei
*width
, GLsizei
*height
,
5214 struct gl_pixelstore_attrib
*pack
)
5216 const GLframebuffer
*buffer
= ctx
->ReadBuffer
;
5218 if (pack
->RowLength
== 0) {
5219 pack
->RowLength
= *width
;
5224 pack
->SkipPixels
+= (0 - *srcX
);
5225 *width
-= (0 - *srcX
);
5228 /* right clipping */
5229 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
5230 *width
-= (*srcX
+ *width
- buffer
->Width
);
5235 /* bottom clipping */
5237 pack
->SkipRows
+= (0 - *srcY
);
5238 *height
-= (0 - *srcY
);
5242 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
5243 *height
-= (*srcY
+ *height
- buffer
->Height
);
5253 * Do clipping for a glCopyTexSubImage call.
5254 * The framebuffer source region might extend outside the framebuffer
5255 * bounds. Clip the source region against the framebuffer bounds and
5256 * adjust the texture/dest position and size accordingly.
5258 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
5261 _mesa_clip_copytexsubimage(const GLcontext
*ctx
,
5262 GLint
*destX
, GLint
*destY
,
5263 GLint
*srcX
, GLint
*srcY
,
5264 GLsizei
*width
, GLsizei
*height
)
5266 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
5267 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
5269 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
5270 srcX
, srcY
, width
, height
)) {
5271 *destX
= *destX
+ *srcX
- srcX0
;
5272 *destY
= *destY
+ *srcY
- srcY0
;
5284 * Clip the rectangle defined by (x, y, width, height) against the bounds
5285 * specified by [xmin, xmax) and [ymin, ymax).
5286 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
5289 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
5290 GLint xmax
, GLint ymax
,
5292 GLsizei
*width
, GLsizei
*height
)
5296 *width
-= (xmin
- *x
);
5300 /* right clipping */
5301 if (*x
+ *width
> xmax
)
5302 *width
-= (*x
+ *width
- xmax
);
5307 /* bottom (or top) clipping */
5309 *height
-= (ymin
- *y
);
5313 /* top (or bottom) clipping */
5314 if (*y
+ *height
> ymax
)
5315 *height
-= (*y
+ *height
- ymax
);