2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 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.
37 #include "histogram.h"
44 * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
45 * we later convert the float to a packed integer value (such as for
46 * GL_RGB5_A1) because we'll wind up with a non-zero value.
48 * We redefine the macros here so zero is handled correctly.
51 #define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
54 #define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
58 /** Compute ceiling of integer quotient of A divided by B. */
59 #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
63 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
66 _mesa_type_is_packed(GLenum type
)
69 case GL_UNSIGNED_BYTE_3_3_2
:
70 case GL_UNSIGNED_BYTE_2_3_3_REV
:
71 case GL_UNSIGNED_SHORT_5_6_5
:
72 case GL_UNSIGNED_SHORT_5_6_5_REV
:
73 case GL_UNSIGNED_SHORT_4_4_4_4
:
74 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
75 case GL_UNSIGNED_SHORT_5_5_5_1
:
76 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
77 case GL_UNSIGNED_INT_8_8_8_8
:
78 case GL_UNSIGNED_INT_8_8_8_8_REV
:
79 case GL_UNSIGNED_INT_10_10_10_2
:
80 case GL_UNSIGNED_INT_2_10_10_10_REV
:
81 case GL_UNSIGNED_SHORT_8_8_MESA
:
82 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
83 case GL_UNSIGNED_INT_24_8_EXT
:
91 * Flip the 8 bits in each byte of the given array.
94 * \param n number of bytes.
96 * \todo try this trick to flip bytes someday:
98 * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555);
99 * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333);
100 * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f);
104 flip_bytes( GLubyte
*p
, GLuint n
)
106 register GLuint i
, a
, b
;
109 b
= (GLuint
) p
[i
]; /* words are often faster than bytes */
110 a
= ((b
& 0x01) << 7) |
124 * Flip the order of the 2 bytes in each word in the given array.
127 * \param n number of words.
130 _mesa_swap2( GLushort
*p
, GLuint n
)
135 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
142 * Flip the order of the 4 bytes in each word in the given array.
145 _mesa_swap4( GLuint
*p
, GLuint n
)
147 register GLuint i
, a
, b
;
152 | ((b
>> 8) & 0xff00)
153 | ((b
<< 8) & 0xff0000)
154 | ((b
<< 24) & 0xff000000);
161 * Get the size of a GL data type.
163 * \param type GL data type.
165 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
166 * if an invalid type enum.
169 _mesa_sizeof_type( GLenum type
)
174 case GL_UNSIGNED_BYTE
:
175 return sizeof(GLubyte
);
177 return sizeof(GLbyte
);
178 case GL_UNSIGNED_SHORT
:
179 return sizeof(GLushort
);
181 return sizeof(GLshort
);
182 case GL_UNSIGNED_INT
:
183 return sizeof(GLuint
);
185 return sizeof(GLint
);
187 return sizeof(GLfloat
);
188 case GL_HALF_FLOAT_ARB
:
189 return sizeof(GLhalfARB
);
197 * Same as _mesa_sizeof_type() but also accepting the packed pixel
201 _mesa_sizeof_packed_type( GLenum type
)
206 case GL_UNSIGNED_BYTE
:
207 return sizeof(GLubyte
);
209 return sizeof(GLbyte
);
210 case GL_UNSIGNED_SHORT
:
211 return sizeof(GLushort
);
213 return sizeof(GLshort
);
214 case GL_UNSIGNED_INT
:
215 return sizeof(GLuint
);
217 return sizeof(GLint
);
218 case GL_HALF_FLOAT_ARB
:
219 return sizeof(GLhalfARB
);
221 return sizeof(GLfloat
);
222 case GL_UNSIGNED_BYTE_3_3_2
:
223 return sizeof(GLubyte
);
224 case GL_UNSIGNED_BYTE_2_3_3_REV
:
225 return sizeof(GLubyte
);
226 case GL_UNSIGNED_SHORT_5_6_5
:
227 return sizeof(GLushort
);
228 case GL_UNSIGNED_SHORT_5_6_5_REV
:
229 return sizeof(GLushort
);
230 case GL_UNSIGNED_SHORT_4_4_4_4
:
231 return sizeof(GLushort
);
232 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
233 return sizeof(GLushort
);
234 case GL_UNSIGNED_SHORT_5_5_5_1
:
235 return sizeof(GLushort
);
236 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
237 return sizeof(GLushort
);
238 case GL_UNSIGNED_INT_8_8_8_8
:
239 return sizeof(GLuint
);
240 case GL_UNSIGNED_INT_8_8_8_8_REV
:
241 return sizeof(GLuint
);
242 case GL_UNSIGNED_INT_10_10_10_2
:
243 return sizeof(GLuint
);
244 case GL_UNSIGNED_INT_2_10_10_10_REV
:
245 return sizeof(GLuint
);
246 case GL_UNSIGNED_SHORT_8_8_MESA
:
247 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
248 return sizeof(GLushort
);
249 case GL_UNSIGNED_INT_24_8_EXT
:
250 return sizeof(GLuint
);
258 * Get the number of components in a pixel format.
260 * \param format pixel format.
262 * \return the number of components in the given format, or -1 if a bad format.
265 _mesa_components_in_format( GLenum format
)
269 case GL_COLOR_INDEX1_EXT
:
270 case GL_COLOR_INDEX2_EXT
:
271 case GL_COLOR_INDEX4_EXT
:
272 case GL_COLOR_INDEX8_EXT
:
273 case GL_COLOR_INDEX12_EXT
:
274 case GL_COLOR_INDEX16_EXT
:
275 case GL_STENCIL_INDEX
:
276 case GL_DEPTH_COMPONENT
:
284 case GL_LUMINANCE_ALPHA
:
298 case GL_DEPTH_STENCIL_EXT
:
307 * Get the bytes per pixel of pixel format type pair.
309 * \param format pixel format.
310 * \param type pixel type.
312 * \return bytes per pixel, or -1 if a bad format or type was given.
315 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
317 GLint comps
= _mesa_components_in_format( format
);
323 return 0; /* special case */
325 case GL_UNSIGNED_BYTE
:
326 return comps
* sizeof(GLubyte
);
328 case GL_UNSIGNED_SHORT
:
329 return comps
* sizeof(GLshort
);
331 case GL_UNSIGNED_INT
:
332 return comps
* sizeof(GLint
);
334 return comps
* sizeof(GLfloat
);
335 case GL_HALF_FLOAT_ARB
:
336 return comps
* sizeof(GLhalfARB
);
337 case GL_UNSIGNED_BYTE_3_3_2
:
338 case GL_UNSIGNED_BYTE_2_3_3_REV
:
339 if (format
== GL_RGB
|| format
== GL_BGR
)
340 return sizeof(GLubyte
);
342 return -1; /* error */
343 case GL_UNSIGNED_SHORT_5_6_5
:
344 case GL_UNSIGNED_SHORT_5_6_5_REV
:
345 if (format
== GL_RGB
|| format
== GL_BGR
)
346 return sizeof(GLushort
);
348 return -1; /* error */
349 case GL_UNSIGNED_SHORT_4_4_4_4
:
350 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
351 case GL_UNSIGNED_SHORT_5_5_5_1
:
352 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
353 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
354 return sizeof(GLushort
);
357 case GL_UNSIGNED_INT_8_8_8_8
:
358 case GL_UNSIGNED_INT_8_8_8_8_REV
:
359 case GL_UNSIGNED_INT_10_10_10_2
:
360 case GL_UNSIGNED_INT_2_10_10_10_REV
:
361 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
362 return sizeof(GLuint
);
365 case GL_UNSIGNED_SHORT_8_8_MESA
:
366 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
367 if (format
== GL_YCBCR_MESA
)
368 return sizeof(GLushort
);
371 case GL_UNSIGNED_INT_24_8_EXT
:
372 if (format
== GL_DEPTH_STENCIL_EXT
)
373 return sizeof(GLuint
);
383 * Test for a legal pixel format and type.
385 * \param format pixel format.
386 * \param type pixel type.
388 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
392 _mesa_is_legal_format_and_type( GLcontext
*ctx
, GLenum format
, GLenum type
)
396 case GL_STENCIL_INDEX
:
400 case GL_UNSIGNED_BYTE
:
402 case GL_UNSIGNED_SHORT
:
404 case GL_UNSIGNED_INT
:
407 case GL_HALF_FLOAT_ARB
:
408 return ctx
->Extensions
.ARB_half_float_pixel
;
416 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
420 case GL_LUMINANCE_ALPHA
:
421 case GL_DEPTH_COMPONENT
:
424 case GL_UNSIGNED_BYTE
:
426 case GL_UNSIGNED_SHORT
:
428 case GL_UNSIGNED_INT
:
431 case GL_HALF_FLOAT_ARB
:
432 return ctx
->Extensions
.ARB_half_float_pixel
;
439 case GL_UNSIGNED_BYTE
:
441 case GL_UNSIGNED_SHORT
:
443 case GL_UNSIGNED_INT
:
445 case GL_UNSIGNED_BYTE_3_3_2
:
446 case GL_UNSIGNED_BYTE_2_3_3_REV
:
447 case GL_UNSIGNED_SHORT_5_6_5
:
448 case GL_UNSIGNED_SHORT_5_6_5_REV
:
450 case GL_HALF_FLOAT_ARB
:
451 return ctx
->Extensions
.ARB_half_float_pixel
;
457 /* NOTE: no packed types are supported with BGR. That's
458 * intentional, according to the GL spec.
461 case GL_UNSIGNED_BYTE
:
463 case GL_UNSIGNED_SHORT
:
465 case GL_UNSIGNED_INT
:
468 case GL_HALF_FLOAT_ARB
:
469 return ctx
->Extensions
.ARB_half_float_pixel
;
478 case GL_UNSIGNED_BYTE
:
480 case GL_UNSIGNED_SHORT
:
482 case GL_UNSIGNED_INT
:
484 case GL_UNSIGNED_SHORT_4_4_4_4
:
485 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
486 case GL_UNSIGNED_SHORT_5_5_5_1
:
487 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
488 case GL_UNSIGNED_INT_8_8_8_8
:
489 case GL_UNSIGNED_INT_8_8_8_8_REV
:
490 case GL_UNSIGNED_INT_10_10_10_2
:
491 case GL_UNSIGNED_INT_2_10_10_10_REV
:
493 case GL_HALF_FLOAT_ARB
:
494 return ctx
->Extensions
.ARB_half_float_pixel
;
499 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
500 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
504 case GL_DEPTH_STENCIL_EXT
:
505 if (ctx
->Extensions
.EXT_packed_depth_stencil
506 && type
== GL_UNSIGNED_INT_24_8_EXT
)
518 * Return the address of a specific pixel in an image (1D, 2D or 3D).
520 * Pixel unpacking/packing parameters are observed according to \p packing.
522 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
523 * \param image starting address of image data
524 * \param width the image width
525 * \param height theimage height
526 * \param format the pixel format
527 * \param type the pixel data type
528 * \param packing the pixelstore attributes
529 * \param img which image in the volume (0 for 1D or 2D images)
530 * \param row row of pixel in the image (0 for 1D images)
531 * \param column column of pixel in the image
533 * \return address of pixel on success, or NULL on error.
535 * \sa gl_pixelstore_attrib.
538 _mesa_image_address( GLuint dimensions
,
539 const struct gl_pixelstore_attrib
*packing
,
541 GLsizei width
, GLsizei height
,
542 GLenum format
, GLenum type
,
543 GLint img
, GLint row
, GLint column
)
545 GLint alignment
; /* 1, 2 or 4 */
546 GLint pixels_per_row
;
547 GLint rows_per_image
;
550 GLint skipimages
; /* for 3-D volume images */
553 ASSERT(dimensions
>= 1 && dimensions
<= 3);
555 alignment
= packing
->Alignment
;
556 if (packing
->RowLength
> 0) {
557 pixels_per_row
= packing
->RowLength
;
560 pixels_per_row
= width
;
562 if (packing
->ImageHeight
> 0) {
563 rows_per_image
= packing
->ImageHeight
;
566 rows_per_image
= height
;
569 skippixels
= packing
->SkipPixels
;
570 /* Note: SKIP_ROWS _is_ used for 1D images */
571 skiprows
= packing
->SkipRows
;
572 /* Note: SKIP_IMAGES is only used for 3D images */
573 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
575 if (type
== GL_BITMAP
) {
577 GLint comp_per_pixel
; /* components per pixel */
578 GLint bytes_per_comp
; /* bytes per component */
580 GLint bytes_per_image
;
582 /* Compute bytes per component */
583 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
584 if (bytes_per_comp
< 0) {
588 /* Compute number of components per pixel */
589 comp_per_pixel
= _mesa_components_in_format( format
);
590 if (comp_per_pixel
< 0) {
594 bytes_per_row
= alignment
595 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
597 bytes_per_image
= bytes_per_row
* rows_per_image
;
599 pixel_addr
= (GLubyte
*) image
600 + (skipimages
+ img
) * bytes_per_image
601 + (skiprows
+ row
) * bytes_per_row
602 + (skippixels
+ column
) / 8;
605 /* Non-BITMAP data */
606 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
609 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
611 /* The pixel type and format should have been error checked earlier */
612 assert(bytes_per_pixel
> 0);
614 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
615 remainder
= bytes_per_row
% alignment
;
617 bytes_per_row
+= (alignment
- remainder
);
619 ASSERT(bytes_per_row
% alignment
== 0);
621 bytes_per_image
= bytes_per_row
* rows_per_image
;
623 if (packing
->Invert
) {
624 /* set pixel_addr to the last row */
625 topOfImage
= bytes_per_row
* (height
- 1);
626 bytes_per_row
= -bytes_per_row
;
632 /* compute final pixel address */
633 pixel_addr
= (GLubyte
*) image
634 + (skipimages
+ img
) * bytes_per_image
636 + (skiprows
+ row
) * bytes_per_row
637 + (skippixels
+ column
) * bytes_per_pixel
;
640 return (GLvoid
*) pixel_addr
;
645 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
648 GLenum format
, GLenum type
,
651 return _mesa_image_address(1, packing
, image
, width
, 1,
652 format
, type
, 0, 0, column
);
657 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
659 GLsizei width
, GLsizei height
,
660 GLenum format
, GLenum type
,
661 GLint row
, GLint column
)
663 return _mesa_image_address(2, packing
, image
, width
, height
,
664 format
, type
, 0, row
, column
);
669 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
671 GLsizei width
, GLsizei height
,
672 GLenum format
, GLenum type
,
673 GLint img
, GLint row
, GLint column
)
675 return _mesa_image_address(3, packing
, image
, width
, height
,
676 format
, type
, img
, row
, column
);
682 * Compute the stride (in bytes) between image rows.
684 * \param packing the pixelstore attributes
685 * \param width image width.
686 * \param format pixel format.
687 * \param type pixel data type.
689 * \return the stride in bytes for the given parameters, or -1 if error
692 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
693 GLint width
, GLenum format
, GLenum type
)
695 GLint bytesPerRow
, remainder
;
699 if (type
== GL_BITMAP
) {
700 if (packing
->RowLength
== 0) {
701 bytesPerRow
= (width
+ 7) / 8;
704 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
708 /* Non-BITMAP data */
709 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
710 if (bytesPerPixel
<= 0)
711 return -1; /* error */
712 if (packing
->RowLength
== 0) {
713 bytesPerRow
= bytesPerPixel
* width
;
716 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
720 remainder
= bytesPerRow
% packing
->Alignment
;
722 bytesPerRow
+= (packing
->Alignment
- remainder
);
725 if (packing
->Invert
) {
726 /* negate the bytes per row (negative row stride) */
727 bytesPerRow
= -bytesPerRow
;
737 * Compute the stride between images in a 3D texture (in bytes) for the given
738 * pixel packing parameters and image width, format and type.
741 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
742 GLint width
, GLint height
,
743 GLenum format
, GLenum type
)
746 ASSERT(type
!= GL_BITMAP
);
749 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
750 GLint bytesPerRow
, bytesPerImage
, remainder
;
752 if (bytesPerPixel
<= 0)
753 return -1; /* error */
754 if (packing
->RowLength
== 0) {
755 bytesPerRow
= bytesPerPixel
* width
;
758 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
760 remainder
= bytesPerRow
% packing
->Alignment
;
762 bytesPerRow
+= (packing
->Alignment
- remainder
);
764 if (packing
->ImageHeight
== 0)
765 bytesPerImage
= bytesPerRow
* height
;
767 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
769 return bytesPerImage
;
775 * Unpack a 32x32 pixel polygon stipple from user memory using the
776 * current pixel unpack settings.
779 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
780 const struct gl_pixelstore_attrib
*unpacking
)
782 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap(32, 32, pattern
, unpacking
);
784 /* Convert pattern from GLubytes to GLuints and handle big/little
789 for (i
= 0; i
< 32; i
++) {
790 dest
[i
] = (p
[0] << 24)
802 * Pack polygon stipple into user memory given current pixel packing
806 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
807 const struct gl_pixelstore_attrib
*packing
)
809 /* Convert pattern from GLuints to GLubytes to handle big/little
810 * endian differences.
814 for (i
= 0; i
< 32; i
++) {
815 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
816 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
817 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
818 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
821 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
826 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
827 * order with row alignment = 1 byte.
830 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
831 const struct gl_pixelstore_attrib
*packing
)
833 GLint bytes
, row
, width_in_bytes
;
834 GLubyte
*buffer
, *dst
;
839 /* Alloc dest storage */
840 bytes
= ((width
+ 7) / 8 * height
);
841 buffer
= (GLubyte
*) _mesa_malloc( bytes
);
845 width_in_bytes
= CEILING( width
, 8 );
847 for (row
= 0; row
< height
; row
++) {
848 const GLubyte
*src
= (const GLubyte
*)
849 _mesa_image_address2d(packing
, pixels
, width
, height
,
850 GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
856 if (packing
->SkipPixels
== 0) {
857 _mesa_memcpy( dst
, src
, width_in_bytes
);
858 if (packing
->LsbFirst
) {
859 flip_bytes( dst
, width_in_bytes
);
863 /* handling SkipPixels is a bit tricky (no pun intended!) */
865 if (packing
->LsbFirst
) {
866 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
867 GLubyte dstMask
= 128;
868 const GLubyte
*s
= src
;
871 for (i
= 0; i
< width
; i
++) {
875 if (srcMask
== 128) {
880 srcMask
= srcMask
<< 1;
888 dstMask
= dstMask
>> 1;
893 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
894 GLubyte dstMask
= 128;
895 const GLubyte
*s
= src
;
898 for (i
= 0; i
< width
; i
++) {
907 srcMask
= srcMask
>> 1;
915 dstMask
= dstMask
>> 1;
920 dst
+= width_in_bytes
;
931 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
932 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
934 GLint row
, width_in_bytes
;
940 width_in_bytes
= CEILING( width
, 8 );
942 for (row
= 0; row
< height
; row
++) {
943 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dest
,
944 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
948 if (packing
->SkipPixels
== 0) {
949 _mesa_memcpy( dst
, src
, width_in_bytes
);
950 if (packing
->LsbFirst
) {
951 flip_bytes( dst
, width_in_bytes
);
955 /* handling SkipPixels is a bit tricky (no pun intended!) */
957 if (packing
->LsbFirst
) {
958 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
959 GLubyte dstMask
= 128;
960 const GLubyte
*s
= src
;
963 for (i
= 0; i
< width
; i
++) {
967 if (srcMask
== 128) {
972 srcMask
= srcMask
<< 1;
980 dstMask
= dstMask
>> 1;
985 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
986 GLubyte dstMask
= 128;
987 const GLubyte
*s
= src
;
990 for (i
= 0; i
< width
; i
++) {
999 srcMask
= srcMask
>> 1;
1007 dstMask
= dstMask
>> 1;
1012 src
+= width_in_bytes
;
1018 * Apply various pixel transfer operations to an array of RGBA pixels
1019 * as indicated by the transferOps bitmask
1022 _mesa_apply_rgba_transfer_ops(GLcontext
*ctx
, GLbitfield transferOps
,
1023 GLuint n
, GLfloat rgba
[][4])
1026 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
1027 _mesa_scale_and_bias_rgba(n
, rgba
,
1028 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
1029 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
1030 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
1031 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
1033 /* color map lookup */
1034 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1035 _mesa_map_rgba( ctx
, n
, rgba
);
1037 /* GL_COLOR_TABLE lookup */
1038 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
1039 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
], n
, rgba
);
1042 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
1043 /* this has to be done in the calling code */
1044 _mesa_problem(ctx
, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");
1046 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
1047 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
1048 _mesa_scale_and_bias_rgba(n
, rgba
,
1049 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
1050 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
1051 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
1052 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
1053 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
1054 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
1055 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
1056 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
1058 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
1059 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
1060 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
], n
, rgba
);
1062 /* color matrix transform */
1063 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
1064 _mesa_transform_rgba(ctx
, n
, rgba
);
1066 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
1067 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
1068 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
], n
, rgba
);
1070 /* update histogram count */
1071 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
1072 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1074 /* update min/max values */
1075 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
1076 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1078 /* clamping to [0,1] */
1079 if (transferOps
& IMAGE_CLAMP_BIT
) {
1081 for (i
= 0; i
< n
; i
++) {
1082 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1083 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1084 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1085 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1092 * Apply color index shift and offset to an array of pixels.
1095 shift_and_offset_ci( const GLcontext
*ctx
, GLuint n
, GLuint indexes
[] )
1097 GLint shift
= ctx
->Pixel
.IndexShift
;
1098 GLint offset
= ctx
->Pixel
.IndexOffset
;
1102 indexes
[i
] = (indexes
[i
] << shift
) + offset
;
1105 else if (shift
< 0) {
1108 indexes
[i
] = (indexes
[i
] >> shift
) + offset
;
1113 indexes
[i
] = indexes
[i
] + offset
;
1121 * Apply color index shift, offset and table lookup to an array
1125 _mesa_apply_ci_transfer_ops(const GLcontext
*ctx
, GLbitfield transferOps
,
1126 GLuint n
, GLuint indexes
[])
1128 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
1129 shift_and_offset_ci(ctx
, n
, indexes
);
1131 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1132 const GLuint mask
= ctx
->PixelMaps
.ItoI
.Size
- 1;
1134 for (i
= 0; i
< n
; i
++) {
1135 const GLuint j
= indexes
[i
] & mask
;
1136 indexes
[i
] = IROUND(ctx
->PixelMaps
.ItoI
.Map
[j
]);
1143 * Apply stencil index shift, offset and table lookup to an array
1144 * of stencil values.
1147 _mesa_apply_stencil_transfer_ops(const GLcontext
*ctx
, GLuint n
,
1148 GLstencil stencil
[])
1150 if (ctx
->Pixel
.IndexShift
!= 0 || ctx
->Pixel
.IndexOffset
!= 0) {
1151 const GLint offset
= ctx
->Pixel
.IndexOffset
;
1152 GLint shift
= ctx
->Pixel
.IndexShift
;
1155 for (i
= 0; i
< n
; i
++) {
1156 stencil
[i
] = (stencil
[i
] << shift
) + offset
;
1159 else if (shift
< 0) {
1161 for (i
= 0; i
< n
; i
++) {
1162 stencil
[i
] = (stencil
[i
] >> shift
) + offset
;
1166 for (i
= 0; i
< n
; i
++) {
1167 stencil
[i
] = stencil
[i
] + offset
;
1171 if (ctx
->Pixel
.MapStencilFlag
) {
1172 GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
1174 for (i
= 0; i
< n
; i
++) {
1175 stencil
[i
] = ctx
->PixelMaps
.StoS
.Map
[ stencil
[i
] & mask
];
1182 * Used to pack an array [][4] of RGBA float colors as specified
1183 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
1184 * glGetConvolutionFilter(), etc.
1185 * Incoming colors will be clamped to [0,1] if needed.
1186 * Note: the rgba values will be modified by this function when any pixel
1187 * transfer ops are enabled.
1190 _mesa_pack_rgba_span_float(GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4],
1191 GLenum dstFormat
, GLenum dstType
,
1193 const struct gl_pixelstore_attrib
*dstPacking
,
1194 GLbitfield transferOps
)
1196 GLfloat luminance
[MAX_WIDTH
];
1197 const GLint comps
= _mesa_components_in_format(dstFormat
);
1200 if (dstType
!= GL_FLOAT
|| ctx
->Color
.ClampReadColor
== GL_TRUE
) {
1201 /* need to clamp to [0, 1] */
1202 transferOps
|= IMAGE_CLAMP_BIT
;
1206 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
1207 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
1212 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
1213 /* compute luminance values */
1214 if (dstType
!= GL_FLOAT
|| ctx
->Color
.ClampReadColor
== GL_TRUE
) {
1215 for (i
= 0; i
< n
; i
++) {
1216 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1217 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
1221 for (i
= 0; i
< n
; i
++) {
1222 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1228 * Pack/store the pixels. Ugh! Lots of cases!!!
1231 case GL_UNSIGNED_BYTE
:
1233 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1234 switch (dstFormat
) {
1237 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1241 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1245 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1249 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1253 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1255 case GL_LUMINANCE_ALPHA
:
1257 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1258 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1263 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1264 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1265 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1270 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1271 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1272 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1273 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1278 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1279 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1280 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1285 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1286 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1287 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1288 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1293 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1294 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1295 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1296 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1300 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1306 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1307 switch (dstFormat
) {
1310 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1314 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1318 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1322 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1326 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1328 case GL_LUMINANCE_ALPHA
:
1330 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1331 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1336 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1337 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1338 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1343 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1344 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1345 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1346 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1351 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1352 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1353 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1358 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1359 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1360 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1361 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1366 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1367 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1368 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1369 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1373 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1377 case GL_UNSIGNED_SHORT
:
1379 GLushort
*dst
= (GLushort
*) dstAddr
;
1380 switch (dstFormat
) {
1383 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][RCOMP
]);
1387 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][GCOMP
]);
1391 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][BCOMP
]);
1395 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][ACOMP
]);
1399 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
], luminance
[i
]);
1401 case GL_LUMINANCE_ALPHA
:
1403 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
*2+0], luminance
[i
]);
1404 CLAMPED_FLOAT_TO_USHORT(dst
[i
*2+1], rgba
[i
][ACOMP
]);
1409 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][RCOMP
]);
1410 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1411 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][BCOMP
]);
1416 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][RCOMP
]);
1417 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1418 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][BCOMP
]);
1419 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1424 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][BCOMP
]);
1425 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1426 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][RCOMP
]);
1431 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][BCOMP
]);
1432 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1433 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][RCOMP
]);
1434 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1439 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][ACOMP
]);
1440 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][BCOMP
]);
1441 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][GCOMP
]);
1442 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][RCOMP
]);
1446 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1452 GLshort
*dst
= (GLshort
*) dstAddr
;
1453 switch (dstFormat
) {
1456 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1460 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1464 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1468 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1472 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
1474 case GL_LUMINANCE_ALPHA
:
1476 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
1477 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1482 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1483 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1484 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1489 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1490 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1491 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1492 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1497 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1498 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1499 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1504 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1505 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1506 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1507 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1512 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1513 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1514 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1515 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1519 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1523 case GL_UNSIGNED_INT
:
1525 GLuint
*dst
= (GLuint
*) dstAddr
;
1526 switch (dstFormat
) {
1529 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1533 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1537 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1541 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1545 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
1547 case GL_LUMINANCE_ALPHA
:
1549 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
1550 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1555 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1556 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1557 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1562 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1563 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1564 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1565 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1570 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1571 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1572 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1577 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1578 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1579 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1580 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1585 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1586 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1587 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1588 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1592 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1598 GLint
*dst
= (GLint
*) dstAddr
;
1599 switch (dstFormat
) {
1602 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1606 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1610 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1614 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1618 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1620 case GL_LUMINANCE_ALPHA
:
1622 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1623 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1628 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1629 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1630 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1635 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1636 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1637 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1638 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1643 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1644 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1645 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1650 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1651 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1652 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1653 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1658 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1659 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1660 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1661 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1665 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1671 GLfloat
*dst
= (GLfloat
*) dstAddr
;
1672 switch (dstFormat
) {
1675 dst
[i
] = rgba
[i
][RCOMP
];
1679 dst
[i
] = rgba
[i
][GCOMP
];
1683 dst
[i
] = rgba
[i
][BCOMP
];
1687 dst
[i
] = rgba
[i
][ACOMP
];
1691 dst
[i
] = luminance
[i
];
1693 case GL_LUMINANCE_ALPHA
:
1695 dst
[i
*2+0] = luminance
[i
];
1696 dst
[i
*2+1] = rgba
[i
][ACOMP
];
1701 dst
[i
*3+0] = rgba
[i
][RCOMP
];
1702 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1703 dst
[i
*3+2] = rgba
[i
][BCOMP
];
1708 dst
[i
*4+0] = rgba
[i
][RCOMP
];
1709 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1710 dst
[i
*4+2] = rgba
[i
][BCOMP
];
1711 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1716 dst
[i
*3+0] = rgba
[i
][BCOMP
];
1717 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1718 dst
[i
*3+2] = rgba
[i
][RCOMP
];
1723 dst
[i
*4+0] = rgba
[i
][BCOMP
];
1724 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1725 dst
[i
*4+2] = rgba
[i
][RCOMP
];
1726 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1731 dst
[i
*4+0] = rgba
[i
][ACOMP
];
1732 dst
[i
*4+1] = rgba
[i
][BCOMP
];
1733 dst
[i
*4+2] = rgba
[i
][GCOMP
];
1734 dst
[i
*4+3] = rgba
[i
][RCOMP
];
1738 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1742 case GL_HALF_FLOAT_ARB
:
1744 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
1745 switch (dstFormat
) {
1748 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1752 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1756 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1760 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1764 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
1766 case GL_LUMINANCE_ALPHA
:
1768 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
1769 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1774 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1775 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1776 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1781 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1782 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1783 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1784 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1789 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1790 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1791 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1796 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1797 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1798 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1799 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1804 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1805 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1806 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1807 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1811 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1815 case GL_UNSIGNED_BYTE_3_3_2
:
1816 if (dstFormat
== GL_RGB
) {
1817 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1819 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
1820 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
1821 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
1825 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1826 if (dstFormat
== GL_RGB
) {
1827 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1829 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
1830 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
1831 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 6);
1835 case GL_UNSIGNED_SHORT_5_6_5
:
1836 if (dstFormat
== GL_RGB
) {
1837 GLushort
*dst
= (GLushort
*) dstAddr
;
1839 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1840 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1841 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
1845 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1846 if (dstFormat
== GL_RGB
) {
1847 GLushort
*dst
= (GLushort
*) dstAddr
;
1849 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1850 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1851 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
1855 case GL_UNSIGNED_SHORT_4_4_4_4
:
1856 if (dstFormat
== GL_RGBA
) {
1857 GLushort
*dst
= (GLushort
*) dstAddr
;
1859 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
1860 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1861 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1862 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1865 else if (dstFormat
== GL_BGRA
) {
1866 GLushort
*dst
= (GLushort
*) dstAddr
;
1868 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 12)
1869 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1870 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 4)
1871 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1874 else if (dstFormat
== GL_ABGR_EXT
) {
1875 GLushort
*dst
= (GLushort
*) dstAddr
;
1877 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12)
1878 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1879 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1880 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) );
1884 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1885 if (dstFormat
== GL_RGBA
) {
1886 GLushort
*dst
= (GLushort
*) dstAddr
;
1888 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
1889 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1890 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1891 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1894 else if (dstFormat
== GL_BGRA
) {
1895 GLushort
*dst
= (GLushort
*) dstAddr
;
1897 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) )
1898 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1899 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 8)
1900 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1903 else if (dstFormat
== GL_ABGR_EXT
) {
1904 GLushort
*dst
= (GLushort
*) dstAddr
;
1906 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) )
1907 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1908 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1909 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12);
1913 case GL_UNSIGNED_SHORT_5_5_5_1
:
1914 if (dstFormat
== GL_RGBA
) {
1915 GLushort
*dst
= (GLushort
*) dstAddr
;
1917 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1918 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1919 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
1920 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1923 else if (dstFormat
== GL_BGRA
) {
1924 GLushort
*dst
= (GLushort
*) dstAddr
;
1926 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11)
1927 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1928 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 1)
1929 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1932 else if (dstFormat
== GL_ABGR_EXT
) {
1933 GLushort
*dst
= (GLushort
*) dstAddr
;
1935 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) << 11)
1936 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 6)
1937 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 1)
1938 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) );
1942 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1943 if (dstFormat
== GL_RGBA
) {
1944 GLushort
*dst
= (GLushort
*) dstAddr
;
1946 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1947 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1948 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
1949 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1952 else if (dstFormat
== GL_BGRA
) {
1953 GLushort
*dst
= (GLushort
*) dstAddr
;
1955 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) )
1956 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1957 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 10)
1958 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1961 else if (dstFormat
== GL_ABGR_EXT
) {
1962 GLushort
*dst
= (GLushort
*) dstAddr
;
1964 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) )
1965 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 5)
1966 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 10)
1967 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) << 15);
1971 case GL_UNSIGNED_INT_8_8_8_8
:
1972 if (dstFormat
== GL_RGBA
) {
1973 GLuint
*dst
= (GLuint
*) dstAddr
;
1975 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
1976 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1977 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1978 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1981 else if (dstFormat
== GL_BGRA
) {
1982 GLuint
*dst
= (GLuint
*) dstAddr
;
1984 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
1985 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1986 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
1987 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1990 else if (dstFormat
== GL_ABGR_EXT
) {
1991 GLuint
*dst
= (GLuint
*) dstAddr
;
1993 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
1994 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1995 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1996 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
2000 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2001 if (dstFormat
== GL_RGBA
) {
2002 GLuint
*dst
= (GLuint
*) dstAddr
;
2004 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
2005 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
2006 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
2007 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
2010 else if (dstFormat
== GL_BGRA
) {
2011 GLuint
*dst
= (GLuint
*) dstAddr
;
2013 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
2014 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
2015 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
2016 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
2019 else if (dstFormat
== GL_ABGR_EXT
) {
2020 GLuint
*dst
= (GLuint
*) dstAddr
;
2022 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
2023 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
2024 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
2025 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
2029 case GL_UNSIGNED_INT_10_10_10_2
:
2030 if (dstFormat
== GL_RGBA
) {
2031 GLuint
*dst
= (GLuint
*) dstAddr
;
2033 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
2034 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
2035 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
2036 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
2039 else if (dstFormat
== GL_BGRA
) {
2040 GLuint
*dst
= (GLuint
*) dstAddr
;
2042 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
2043 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
2044 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
2045 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
2048 else if (dstFormat
== GL_ABGR_EXT
) {
2049 GLuint
*dst
= (GLuint
*) dstAddr
;
2051 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
2052 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
2053 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
2054 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
2058 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2059 if (dstFormat
== GL_RGBA
) {
2060 GLuint
*dst
= (GLuint
*) dstAddr
;
2062 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
2063 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
2064 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
2065 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
2068 else if (dstFormat
== GL_BGRA
) {
2069 GLuint
*dst
= (GLuint
*) dstAddr
;
2071 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
2072 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
2073 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
2074 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
2077 else if (dstFormat
== GL_ABGR_EXT
) {
2078 GLuint
*dst
= (GLuint
*) dstAddr
;
2080 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
2081 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
2082 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
2083 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
2088 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
2092 if (dstPacking
->SwapBytes
) {
2093 GLint swapSize
= _mesa_sizeof_packed_type(dstType
);
2094 if (swapSize
== 2) {
2095 if (dstPacking
->SwapBytes
) {
2096 _mesa_swap2((GLushort
*) dstAddr
, n
* comps
);
2099 else if (swapSize
== 4) {
2100 if (dstPacking
->SwapBytes
) {
2101 _mesa_swap4((GLuint
*) dstAddr
, n
* comps
);
2108 #define SWAP2BYTE(VALUE) \
2110 GLubyte *bytes = (GLubyte *) &(VALUE); \
2111 GLubyte tmp = bytes[0]; \
2112 bytes[0] = bytes[1]; \
2116 #define SWAP4BYTE(VALUE) \
2118 GLubyte *bytes = (GLubyte *) &(VALUE); \
2119 GLubyte tmp = bytes[0]; \
2120 bytes[0] = bytes[3]; \
2123 bytes[1] = bytes[2]; \
2129 extract_uint_indexes(GLuint n
, GLuint indexes
[],
2130 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2131 const struct gl_pixelstore_attrib
*unpack
)
2133 ASSERT(srcFormat
== GL_COLOR_INDEX
|| srcFormat
== GL_STENCIL_INDEX
);
2135 ASSERT(srcType
== GL_BITMAP
||
2136 srcType
== GL_UNSIGNED_BYTE
||
2137 srcType
== GL_BYTE
||
2138 srcType
== GL_UNSIGNED_SHORT
||
2139 srcType
== GL_SHORT
||
2140 srcType
== GL_UNSIGNED_INT
||
2141 srcType
== GL_INT
||
2142 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
2143 srcType
== GL_HALF_FLOAT_ARB
||
2144 srcType
== GL_FLOAT
);
2149 GLubyte
*ubsrc
= (GLubyte
*) src
;
2150 if (unpack
->LsbFirst
) {
2151 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
2153 for (i
= 0; i
< n
; i
++) {
2154 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2165 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
2167 for (i
= 0; i
< n
; i
++) {
2168 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2180 case GL_UNSIGNED_BYTE
:
2183 const GLubyte
*s
= (const GLubyte
*) src
;
2184 for (i
= 0; i
< n
; i
++)
2191 const GLbyte
*s
= (const GLbyte
*) src
;
2192 for (i
= 0; i
< n
; i
++)
2196 case GL_UNSIGNED_SHORT
:
2199 const GLushort
*s
= (const GLushort
*) src
;
2200 if (unpack
->SwapBytes
) {
2201 for (i
= 0; i
< n
; i
++) {
2202 GLushort value
= s
[i
];
2208 for (i
= 0; i
< n
; i
++)
2216 const GLshort
*s
= (const GLshort
*) src
;
2217 if (unpack
->SwapBytes
) {
2218 for (i
= 0; i
< n
; i
++) {
2219 GLshort value
= s
[i
];
2225 for (i
= 0; i
< n
; i
++)
2230 case GL_UNSIGNED_INT
:
2233 const GLuint
*s
= (const GLuint
*) src
;
2234 if (unpack
->SwapBytes
) {
2235 for (i
= 0; i
< n
; i
++) {
2236 GLuint value
= s
[i
];
2242 for (i
= 0; i
< n
; i
++)
2250 const GLint
*s
= (const GLint
*) src
;
2251 if (unpack
->SwapBytes
) {
2252 for (i
= 0; i
< n
; i
++) {
2259 for (i
= 0; i
< n
; i
++)
2267 const GLfloat
*s
= (const GLfloat
*) src
;
2268 if (unpack
->SwapBytes
) {
2269 for (i
= 0; i
< n
; i
++) {
2270 GLfloat value
= s
[i
];
2272 indexes
[i
] = (GLuint
) value
;
2276 for (i
= 0; i
< n
; i
++)
2277 indexes
[i
] = (GLuint
) s
[i
];
2281 case GL_HALF_FLOAT_ARB
:
2284 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
2285 if (unpack
->SwapBytes
) {
2286 for (i
= 0; i
< n
; i
++) {
2287 GLhalfARB value
= s
[i
];
2289 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
2293 for (i
= 0; i
< n
; i
++)
2294 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
2298 case GL_UNSIGNED_INT_24_8_EXT
:
2301 const GLuint
*s
= (const GLuint
*) src
;
2302 if (unpack
->SwapBytes
) {
2303 for (i
= 0; i
< n
; i
++) {
2304 GLuint value
= s
[i
];
2306 indexes
[i
] = value
& 0xff; /* lower 8 bits */
2310 for (i
= 0; i
< n
; i
++)
2311 indexes
[i
] = s
[i
] & 0xfff; /* lower 8 bits */
2317 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2324 * This function extracts floating point RGBA values from arbitrary
2325 * image data. srcFormat and srcType are the format and type parameters
2326 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2328 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2329 * implements the "Conversion to floating point", "Conversion to RGB",
2330 * and "Final Expansion to RGBA" operations.
2332 * Args: n - number of pixels
2333 * rgba - output colors
2334 * srcFormat - format of incoming data
2335 * srcType - data type of incoming data
2336 * src - source data pointer
2337 * swapBytes - perform byteswapping of incoming data?
2340 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2341 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2342 GLboolean swapBytes
)
2344 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2346 GLint rComp
, bComp
, gComp
, aComp
;
2348 ASSERT(srcFormat
== GL_RED
||
2349 srcFormat
== GL_GREEN
||
2350 srcFormat
== GL_BLUE
||
2351 srcFormat
== GL_ALPHA
||
2352 srcFormat
== GL_LUMINANCE
||
2353 srcFormat
== GL_LUMINANCE_ALPHA
||
2354 srcFormat
== GL_INTENSITY
||
2355 srcFormat
== GL_RGB
||
2356 srcFormat
== GL_BGR
||
2357 srcFormat
== GL_RGBA
||
2358 srcFormat
== GL_BGRA
||
2359 srcFormat
== GL_ABGR_EXT
);
2361 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2362 srcType
== GL_BYTE
||
2363 srcType
== GL_UNSIGNED_SHORT
||
2364 srcType
== GL_SHORT
||
2365 srcType
== GL_UNSIGNED_INT
||
2366 srcType
== GL_INT
||
2367 srcType
== GL_HALF_FLOAT_ARB
||
2368 srcType
== GL_FLOAT
||
2369 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2370 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2371 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2372 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2373 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2374 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2375 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2376 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2377 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2378 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2379 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2380 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2382 rComp
= gComp
= bComp
= aComp
= -1;
2384 switch (srcFormat
) {
2387 greenIndex
= blueIndex
= alphaIndex
= -1;
2392 redIndex
= blueIndex
= alphaIndex
= -1;
2397 redIndex
= greenIndex
= alphaIndex
= -1;
2401 redIndex
= greenIndex
= blueIndex
= -1;
2406 redIndex
= greenIndex
= blueIndex
= 0;
2410 case GL_LUMINANCE_ALPHA
:
2411 redIndex
= greenIndex
= blueIndex
= 0;
2416 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
2475 _mesa_problem(NULL
, "bad srcFormat in extract float data");
2480 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
2481 if ((INDEX) < 0) { \
2483 for (i = 0; i < n; i++) { \
2484 rgba[i][CHANNEL] = DEFAULT; \
2487 else if (swapBytes) { \
2488 const TYPE *s = (const TYPE *) src; \
2490 for (i = 0; i < n; i++) { \
2491 TYPE value = s[INDEX]; \
2492 if (sizeof(TYPE) == 2) { \
2495 else if (sizeof(TYPE) == 4) { \
2498 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
2503 const TYPE *s = (const TYPE *) src; \
2505 for (i = 0; i < n; i++) { \
2506 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
2512 case GL_UNSIGNED_BYTE
:
2513 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2514 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2515 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2516 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2519 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2520 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2521 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2522 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
2524 case GL_UNSIGNED_SHORT
:
2525 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2526 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2527 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2528 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
2531 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2532 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2533 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2534 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
2536 case GL_UNSIGNED_INT
:
2537 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2538 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2539 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2540 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
2543 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2544 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2545 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2546 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
2549 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2550 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2551 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2552 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
2554 case GL_HALF_FLOAT_ARB
:
2555 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2556 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2557 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2558 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
2560 case GL_UNSIGNED_BYTE_3_3_2
:
2562 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2564 for (i
= 0; i
< n
; i
++) {
2565 GLubyte p
= ubsrc
[i
];
2566 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
2567 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
2568 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
2569 rgba
[i
][aComp
] = 1.0F
;
2573 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2575 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2577 for (i
= 0; i
< n
; i
++) {
2578 GLubyte p
= ubsrc
[i
];
2579 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
2580 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
2581 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
2582 rgba
[i
][aComp
] = 1.0F
;
2586 case GL_UNSIGNED_SHORT_5_6_5
:
2588 const GLushort
*ussrc
= (const GLushort
*) src
;
2590 for (i
= 0; i
< n
; i
++) {
2591 GLushort p
= ussrc
[i
];
2593 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2594 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2595 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2596 rgba
[i
][aComp
] = 1.0F
;
2600 const GLushort
*ussrc
= (const GLushort
*) src
;
2602 for (i
= 0; i
< n
; i
++) {
2603 GLushort p
= ussrc
[i
];
2604 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2605 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2606 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2607 rgba
[i
][aComp
] = 1.0F
;
2611 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2613 const GLushort
*ussrc
= (const GLushort
*) src
;
2615 for (i
= 0; i
< n
; i
++) {
2616 GLushort p
= ussrc
[i
];
2618 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2619 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2620 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2621 rgba
[i
][aComp
] = 1.0F
;
2625 const GLushort
*ussrc
= (const GLushort
*) src
;
2627 for (i
= 0; i
< n
; i
++) {
2628 GLushort p
= ussrc
[i
];
2629 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2630 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2631 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2632 rgba
[i
][aComp
] = 1.0F
;
2636 case GL_UNSIGNED_SHORT_4_4_4_4
:
2638 const GLushort
*ussrc
= (const GLushort
*) src
;
2640 for (i
= 0; i
< n
; i
++) {
2641 GLushort p
= ussrc
[i
];
2643 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2644 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2645 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2646 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2650 const GLushort
*ussrc
= (const GLushort
*) src
;
2652 for (i
= 0; i
< n
; i
++) {
2653 GLushort p
= ussrc
[i
];
2654 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2655 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2656 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2657 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2661 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2663 const GLushort
*ussrc
= (const GLushort
*) src
;
2665 for (i
= 0; i
< n
; i
++) {
2666 GLushort p
= ussrc
[i
];
2668 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2669 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2670 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2671 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2675 const GLushort
*ussrc
= (const GLushort
*) src
;
2677 for (i
= 0; i
< n
; i
++) {
2678 GLushort p
= ussrc
[i
];
2679 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2680 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2681 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2682 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2686 case GL_UNSIGNED_SHORT_5_5_5_1
:
2688 const GLushort
*ussrc
= (const GLushort
*) src
;
2690 for (i
= 0; i
< n
; i
++) {
2691 GLushort p
= ussrc
[i
];
2693 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2694 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2695 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2696 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2700 const GLushort
*ussrc
= (const GLushort
*) src
;
2702 for (i
= 0; i
< n
; i
++) {
2703 GLushort p
= ussrc
[i
];
2704 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2705 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2706 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2707 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2711 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2713 const GLushort
*ussrc
= (const GLushort
*) src
;
2715 for (i
= 0; i
< n
; i
++) {
2716 GLushort p
= ussrc
[i
];
2718 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2719 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2720 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2721 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2725 const GLushort
*ussrc
= (const GLushort
*) src
;
2727 for (i
= 0; i
< n
; i
++) {
2728 GLushort p
= ussrc
[i
];
2729 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2730 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2731 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2732 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2736 case GL_UNSIGNED_INT_8_8_8_8
:
2738 const GLuint
*uisrc
= (const GLuint
*) src
;
2740 for (i
= 0; i
< n
; i
++) {
2741 GLuint p
= uisrc
[i
];
2742 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2743 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2744 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2745 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2749 const GLuint
*uisrc
= (const GLuint
*) src
;
2751 for (i
= 0; i
< n
; i
++) {
2752 GLuint p
= uisrc
[i
];
2753 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2754 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2755 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2756 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2760 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2762 const GLuint
*uisrc
= (const GLuint
*) src
;
2764 for (i
= 0; i
< n
; i
++) {
2765 GLuint p
= uisrc
[i
];
2766 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2767 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2768 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2769 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2773 const GLuint
*uisrc
= (const GLuint
*) src
;
2775 for (i
= 0; i
< n
; i
++) {
2776 GLuint p
= uisrc
[i
];
2777 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2778 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2779 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2780 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2784 case GL_UNSIGNED_INT_10_10_10_2
:
2786 const GLuint
*uisrc
= (const GLuint
*) src
;
2788 for (i
= 0; i
< n
; i
++) {
2789 GLuint p
= uisrc
[i
];
2791 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2792 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2793 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2794 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2798 const GLuint
*uisrc
= (const GLuint
*) src
;
2800 for (i
= 0; i
< n
; i
++) {
2801 GLuint p
= uisrc
[i
];
2802 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2803 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2804 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2805 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2809 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2811 const GLuint
*uisrc
= (const GLuint
*) src
;
2813 for (i
= 0; i
< n
; i
++) {
2814 GLuint p
= uisrc
[i
];
2816 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2817 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2818 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2819 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2823 const GLuint
*uisrc
= (const GLuint
*) src
;
2825 for (i
= 0; i
< n
; i
++) {
2826 GLuint p
= uisrc
[i
];
2827 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2828 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2829 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2830 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2835 _mesa_problem(NULL
, "bad srcType in extract float data");
2842 * Unpack a row of color image data from a client buffer according to
2843 * the pixel unpacking parameters.
2844 * Return GLchan values in the specified dest image format.
2845 * This is used by glDrawPixels and glTexImage?D().
2846 * \param ctx - the context
2847 * n - number of pixels in the span
2848 * dstFormat - format of destination color array
2849 * dest - the destination color array
2850 * srcFormat - source image format
2851 * srcType - source image data type
2852 * source - source image pointer
2853 * srcPacking - pixel unpacking parameters
2854 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
2856 * XXX perhaps expand this to process whole images someday.
2859 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
2860 GLuint n
, GLenum dstFormat
, GLchan dest
[],
2861 GLenum srcFormat
, GLenum srcType
,
2862 const GLvoid
*source
,
2863 const struct gl_pixelstore_attrib
*srcPacking
,
2864 GLbitfield transferOps
)
2866 ASSERT(dstFormat
== GL_ALPHA
||
2867 dstFormat
== GL_LUMINANCE
||
2868 dstFormat
== GL_LUMINANCE_ALPHA
||
2869 dstFormat
== GL_INTENSITY
||
2870 dstFormat
== GL_RGB
||
2871 dstFormat
== GL_RGBA
||
2872 dstFormat
== GL_COLOR_INDEX
);
2874 ASSERT(srcFormat
== GL_RED
||
2875 srcFormat
== GL_GREEN
||
2876 srcFormat
== GL_BLUE
||
2877 srcFormat
== GL_ALPHA
||
2878 srcFormat
== GL_LUMINANCE
||
2879 srcFormat
== GL_LUMINANCE_ALPHA
||
2880 srcFormat
== GL_INTENSITY
||
2881 srcFormat
== GL_RGB
||
2882 srcFormat
== GL_BGR
||
2883 srcFormat
== GL_RGBA
||
2884 srcFormat
== GL_BGRA
||
2885 srcFormat
== GL_ABGR_EXT
||
2886 srcFormat
== GL_COLOR_INDEX
);
2888 ASSERT(srcType
== GL_BITMAP
||
2889 srcType
== GL_UNSIGNED_BYTE
||
2890 srcType
== GL_BYTE
||
2891 srcType
== GL_UNSIGNED_SHORT
||
2892 srcType
== GL_SHORT
||
2893 srcType
== GL_UNSIGNED_INT
||
2894 srcType
== GL_INT
||
2895 srcType
== GL_HALF_FLOAT_ARB
||
2896 srcType
== GL_FLOAT
||
2897 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2898 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2899 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2900 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2901 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2902 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2903 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2904 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2905 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2906 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2907 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2908 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2910 /* Try simple cases first */
2911 if (transferOps
== 0) {
2912 if (srcType
== CHAN_TYPE
) {
2913 if (dstFormat
== GL_RGBA
) {
2914 if (srcFormat
== GL_RGBA
) {
2915 _mesa_memcpy( dest
, source
, n
* 4 * sizeof(GLchan
) );
2918 else if (srcFormat
== GL_RGB
) {
2920 const GLchan
*src
= (const GLchan
*) source
;
2922 for (i
= 0; i
< n
; i
++) {
2933 else if (dstFormat
== GL_RGB
) {
2934 if (srcFormat
== GL_RGB
) {
2935 _mesa_memcpy( dest
, source
, n
* 3 * sizeof(GLchan
) );
2938 else if (srcFormat
== GL_RGBA
) {
2940 const GLchan
*src
= (const GLchan
*) source
;
2942 for (i
= 0; i
< n
; i
++) {
2952 else if (dstFormat
== srcFormat
) {
2953 GLint comps
= _mesa_components_in_format(srcFormat
);
2955 _mesa_memcpy( dest
, source
, n
* comps
* sizeof(GLchan
) );
2960 * Common situation, loading 8bit RGBA/RGB source images
2961 * into 16/32 bit destination. (OSMesa16/32)
2963 else if (srcType
== GL_UNSIGNED_BYTE
) {
2964 if (dstFormat
== GL_RGBA
) {
2965 if (srcFormat
== GL_RGB
) {
2967 const GLubyte
*src
= (const GLubyte
*) source
;
2969 for (i
= 0; i
< n
; i
++) {
2970 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2971 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2972 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2979 else if (srcFormat
== GL_RGBA
) {
2981 const GLubyte
*src
= (const GLubyte
*) source
;
2983 for (i
= 0; i
< n
; i
++) {
2984 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2985 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2986 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2987 dst
[3] = UBYTE_TO_CHAN(src
[3]);
2994 else if (dstFormat
== GL_RGB
) {
2995 if (srcFormat
== GL_RGB
) {
2997 const GLubyte
*src
= (const GLubyte
*) source
;
2999 for (i
= 0; i
< n
; i
++) {
3000 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3001 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3002 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3008 else if (srcFormat
== GL_RGBA
) {
3010 const GLubyte
*src
= (const GLubyte
*) source
;
3012 for (i
= 0; i
< n
; i
++) {
3013 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3014 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3015 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3026 /* general solution begins here */
3028 GLint dstComponents
;
3029 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3030 GLint dstLuminanceIndex
, dstIntensityIndex
;
3031 GLfloat rgba
[MAX_WIDTH
][4];
3033 dstComponents
= _mesa_components_in_format( dstFormat
);
3034 /* source & dest image formats should have been error checked by now */
3035 assert(dstComponents
> 0);
3038 * Extract image data and convert to RGBA floats
3040 assert(n
<= MAX_WIDTH
);
3041 if (srcFormat
== GL_COLOR_INDEX
) {
3042 GLuint indexes
[MAX_WIDTH
];
3043 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3046 if (dstFormat
== GL_COLOR_INDEX
) {
3048 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3049 /* convert to GLchan and return */
3050 for (i
= 0; i
< n
; i
++) {
3051 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3056 /* Convert indexes to RGBA */
3057 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3058 shift_and_offset_ci(ctx
, n
, indexes
);
3060 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3063 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3064 * with color indexes.
3066 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3069 /* non-color index data */
3070 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3071 srcPacking
->SwapBytes
);
3074 /* Need to clamp if returning GLubytes or GLushorts */
3075 #if CHAN_TYPE != GL_FLOAT
3076 transferOps
|= IMAGE_CLAMP_BIT
;
3080 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3083 /* Now determine which color channels we need to produce.
3084 * And determine the dest index (offset) within each color tuple.
3086 switch (dstFormat
) {
3089 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3090 dstLuminanceIndex
= dstIntensityIndex
= -1;
3093 dstLuminanceIndex
= 0;
3094 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3095 dstIntensityIndex
= -1;
3097 case GL_LUMINANCE_ALPHA
:
3098 dstLuminanceIndex
= 0;
3100 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3101 dstIntensityIndex
= -1;
3104 dstIntensityIndex
= 0;
3105 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3106 dstLuminanceIndex
= -1;
3112 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3119 dstLuminanceIndex
= dstIntensityIndex
= -1;
3122 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
3127 /* Now return the GLchan data in the requested dstFormat */
3129 if (dstRedIndex
>= 0) {
3132 for (i
= 0; i
< n
; i
++) {
3133 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
3134 dst
+= dstComponents
;
3138 if (dstGreenIndex
>= 0) {
3141 for (i
= 0; i
< n
; i
++) {
3142 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
3143 dst
+= dstComponents
;
3147 if (dstBlueIndex
>= 0) {
3150 for (i
= 0; i
< n
; i
++) {
3151 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
3152 dst
+= dstComponents
;
3156 if (dstAlphaIndex
>= 0) {
3159 for (i
= 0; i
< n
; i
++) {
3160 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
3161 dst
+= dstComponents
;
3165 if (dstIntensityIndex
>= 0) {
3168 assert(dstIntensityIndex
== 0);
3169 assert(dstComponents
== 1);
3170 for (i
= 0; i
< n
; i
++) {
3171 /* Intensity comes from red channel */
3172 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
3176 if (dstLuminanceIndex
>= 0) {
3179 assert(dstLuminanceIndex
== 0);
3180 for (i
= 0; i
< n
; i
++) {
3181 /* Luminance comes from red channel */
3182 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
3183 dst
+= dstComponents
;
3191 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
3192 * instead of GLchan.
3195 _mesa_unpack_color_span_float( GLcontext
*ctx
,
3196 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
3197 GLenum srcFormat
, GLenum srcType
,
3198 const GLvoid
*source
,
3199 const struct gl_pixelstore_attrib
*srcPacking
,
3200 GLbitfield transferOps
)
3202 ASSERT(dstFormat
== GL_ALPHA
||
3203 dstFormat
== GL_LUMINANCE
||
3204 dstFormat
== GL_LUMINANCE_ALPHA
||
3205 dstFormat
== GL_INTENSITY
||
3206 dstFormat
== GL_RGB
||
3207 dstFormat
== GL_RGBA
||
3208 dstFormat
== GL_COLOR_INDEX
);
3210 ASSERT(srcFormat
== GL_RED
||
3211 srcFormat
== GL_GREEN
||
3212 srcFormat
== GL_BLUE
||
3213 srcFormat
== GL_ALPHA
||
3214 srcFormat
== GL_LUMINANCE
||
3215 srcFormat
== GL_LUMINANCE_ALPHA
||
3216 srcFormat
== GL_INTENSITY
||
3217 srcFormat
== GL_RGB
||
3218 srcFormat
== GL_BGR
||
3219 srcFormat
== GL_RGBA
||
3220 srcFormat
== GL_BGRA
||
3221 srcFormat
== GL_ABGR_EXT
||
3222 srcFormat
== GL_COLOR_INDEX
);
3224 ASSERT(srcType
== GL_BITMAP
||
3225 srcType
== GL_UNSIGNED_BYTE
||
3226 srcType
== GL_BYTE
||
3227 srcType
== GL_UNSIGNED_SHORT
||
3228 srcType
== GL_SHORT
||
3229 srcType
== GL_UNSIGNED_INT
||
3230 srcType
== GL_INT
||
3231 srcType
== GL_HALF_FLOAT_ARB
||
3232 srcType
== GL_FLOAT
||
3233 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3234 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3235 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3236 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3237 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3238 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3239 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3240 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3241 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3242 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3243 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3244 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3246 /* general solution, no special cases, yet */
3248 GLint dstComponents
;
3249 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3250 GLint dstLuminanceIndex
, dstIntensityIndex
;
3251 GLfloat rgba
[MAX_WIDTH
][4];
3253 dstComponents
= _mesa_components_in_format( dstFormat
);
3254 /* source & dest image formats should have been error checked by now */
3255 assert(dstComponents
> 0);
3258 * Extract image data and convert to RGBA floats
3260 assert(n
<= MAX_WIDTH
);
3261 if (srcFormat
== GL_COLOR_INDEX
) {
3262 GLuint indexes
[MAX_WIDTH
];
3263 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3266 if (dstFormat
== GL_COLOR_INDEX
) {
3268 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3269 /* convert to GLchan and return */
3270 for (i
= 0; i
< n
; i
++) {
3271 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3276 /* Convert indexes to RGBA */
3277 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3278 shift_and_offset_ci(ctx
, n
, indexes
);
3280 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3283 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3284 * with color indexes.
3286 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3289 /* non-color index data */
3290 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3291 srcPacking
->SwapBytes
);
3295 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3298 /* Now determine which color channels we need to produce.
3299 * And determine the dest index (offset) within each color tuple.
3301 switch (dstFormat
) {
3304 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3305 dstLuminanceIndex
= dstIntensityIndex
= -1;
3308 dstLuminanceIndex
= 0;
3309 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3310 dstIntensityIndex
= -1;
3312 case GL_LUMINANCE_ALPHA
:
3313 dstLuminanceIndex
= 0;
3315 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3316 dstIntensityIndex
= -1;
3319 dstIntensityIndex
= 0;
3320 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3321 dstLuminanceIndex
= -1;
3327 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3334 dstLuminanceIndex
= dstIntensityIndex
= -1;
3337 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
3341 /* Now pack results in the requested dstFormat */
3342 if (dstRedIndex
>= 0) {
3343 GLfloat
*dst
= dest
;
3345 for (i
= 0; i
< n
; i
++) {
3346 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3347 dst
+= dstComponents
;
3351 if (dstGreenIndex
>= 0) {
3352 GLfloat
*dst
= dest
;
3354 for (i
= 0; i
< n
; i
++) {
3355 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3356 dst
+= dstComponents
;
3360 if (dstBlueIndex
>= 0) {
3361 GLfloat
*dst
= dest
;
3363 for (i
= 0; i
< n
; i
++) {
3364 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3365 dst
+= dstComponents
;
3369 if (dstAlphaIndex
>= 0) {
3370 GLfloat
*dst
= dest
;
3372 for (i
= 0; i
< n
; i
++) {
3373 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3374 dst
+= dstComponents
;
3378 if (dstIntensityIndex
>= 0) {
3379 GLfloat
*dst
= dest
;
3381 assert(dstIntensityIndex
== 0);
3382 assert(dstComponents
== 1);
3383 for (i
= 0; i
< n
; i
++) {
3384 /* Intensity comes from red channel */
3385 dst
[i
] = rgba
[i
][RCOMP
];
3389 if (dstLuminanceIndex
>= 0) {
3390 GLfloat
*dst
= dest
;
3392 assert(dstLuminanceIndex
== 0);
3393 for (i
= 0; i
< n
; i
++) {
3394 /* Luminance comes from red channel */
3395 dst
[0] = rgba
[i
][RCOMP
];
3396 dst
+= dstComponents
;
3404 * Unpack a row of color index data from a client buffer according to
3405 * the pixel unpacking parameters.
3406 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
3408 * Args: ctx - the context
3409 * n - number of pixels
3410 * dstType - destination data type
3411 * dest - destination array
3412 * srcType - source pixel type
3413 * source - source data pointer
3414 * srcPacking - pixel unpacking parameters
3415 * transferOps - the pixel transfer operations to apply
3418 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
3419 GLenum dstType
, GLvoid
*dest
,
3420 GLenum srcType
, const GLvoid
*source
,
3421 const struct gl_pixelstore_attrib
*srcPacking
,
3422 GLbitfield transferOps
)
3424 ASSERT(srcType
== GL_BITMAP
||
3425 srcType
== GL_UNSIGNED_BYTE
||
3426 srcType
== GL_BYTE
||
3427 srcType
== GL_UNSIGNED_SHORT
||
3428 srcType
== GL_SHORT
||
3429 srcType
== GL_UNSIGNED_INT
||
3430 srcType
== GL_INT
||
3431 srcType
== GL_HALF_FLOAT_ARB
||
3432 srcType
== GL_FLOAT
);
3434 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3435 dstType
== GL_UNSIGNED_SHORT
||
3436 dstType
== GL_UNSIGNED_INT
);
3439 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3442 * Try simple cases first
3444 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
3445 && dstType
== GL_UNSIGNED_BYTE
) {
3446 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
3448 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
3449 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
3450 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
3456 GLuint indexes
[MAX_WIDTH
];
3457 assert(n
<= MAX_WIDTH
);
3459 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3463 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3465 /* convert to dest type */
3467 case GL_UNSIGNED_BYTE
:
3469 GLubyte
*dst
= (GLubyte
*) dest
;
3471 for (i
= 0; i
< n
; i
++) {
3472 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3476 case GL_UNSIGNED_SHORT
:
3478 GLuint
*dst
= (GLuint
*) dest
;
3480 for (i
= 0; i
< n
; i
++) {
3481 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3485 case GL_UNSIGNED_INT
:
3486 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
3489 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
3496 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
3497 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
3498 const struct gl_pixelstore_attrib
*dstPacking
,
3499 GLbitfield transferOps
)
3501 GLuint indexes
[MAX_WIDTH
];
3503 ASSERT(n
<= MAX_WIDTH
);
3505 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3507 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
3508 /* make a copy of input */
3509 _mesa_memcpy(indexes
, source
, n
* sizeof(GLuint
));
3510 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3515 case GL_UNSIGNED_BYTE
:
3517 GLubyte
*dst
= (GLubyte
*) dest
;
3519 for (i
= 0; i
< n
; i
++) {
3520 *dst
++ = (GLubyte
) source
[i
];
3526 GLbyte
*dst
= (GLbyte
*) dest
;
3528 for (i
= 0; i
< n
; i
++) {
3529 dst
[i
] = (GLbyte
) source
[i
];
3533 case GL_UNSIGNED_SHORT
:
3535 GLushort
*dst
= (GLushort
*) dest
;
3537 for (i
= 0; i
< n
; i
++) {
3538 dst
[i
] = (GLushort
) source
[i
];
3540 if (dstPacking
->SwapBytes
) {
3541 _mesa_swap2( (GLushort
*) dst
, n
);
3547 GLshort
*dst
= (GLshort
*) dest
;
3549 for (i
= 0; i
< n
; i
++) {
3550 dst
[i
] = (GLshort
) source
[i
];
3552 if (dstPacking
->SwapBytes
) {
3553 _mesa_swap2( (GLushort
*) dst
, n
);
3557 case GL_UNSIGNED_INT
:
3559 GLuint
*dst
= (GLuint
*) dest
;
3561 for (i
= 0; i
< n
; i
++) {
3562 dst
[i
] = (GLuint
) source
[i
];
3564 if (dstPacking
->SwapBytes
) {
3565 _mesa_swap4( (GLuint
*) dst
, n
);
3571 GLint
*dst
= (GLint
*) dest
;
3573 for (i
= 0; i
< n
; i
++) {
3574 dst
[i
] = (GLint
) source
[i
];
3576 if (dstPacking
->SwapBytes
) {
3577 _mesa_swap4( (GLuint
*) dst
, n
);
3583 GLfloat
*dst
= (GLfloat
*) dest
;
3585 for (i
= 0; i
< n
; i
++) {
3586 dst
[i
] = (GLfloat
) source
[i
];
3588 if (dstPacking
->SwapBytes
) {
3589 _mesa_swap4( (GLuint
*) dst
, n
);
3593 case GL_HALF_FLOAT_ARB
:
3595 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
3597 for (i
= 0; i
< n
; i
++) {
3598 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
3600 if (dstPacking
->SwapBytes
) {
3601 _mesa_swap2( (GLushort
*) dst
, n
);
3606 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3612 * Unpack a row of stencil data from a client buffer according to
3613 * the pixel unpacking parameters.
3614 * This is (or will be) used by glDrawPixels
3616 * Args: ctx - the context
3617 * n - number of pixels
3618 * dstType - destination data type
3619 * dest - destination array
3620 * srcType - source pixel type
3621 * source - source data pointer
3622 * srcPacking - pixel unpacking parameters
3623 * transferOps - apply offset/bias/lookup ops?
3626 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3627 GLenum dstType
, GLvoid
*dest
,
3628 GLenum srcType
, const GLvoid
*source
,
3629 const struct gl_pixelstore_attrib
*srcPacking
,
3630 GLbitfield transferOps
)
3632 ASSERT(srcType
== GL_BITMAP
||
3633 srcType
== GL_UNSIGNED_BYTE
||
3634 srcType
== GL_BYTE
||
3635 srcType
== GL_UNSIGNED_SHORT
||
3636 srcType
== GL_SHORT
||
3637 srcType
== GL_UNSIGNED_INT
||
3638 srcType
== GL_INT
||
3639 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
3640 srcType
== GL_HALF_FLOAT_ARB
||
3641 srcType
== GL_FLOAT
);
3643 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3644 dstType
== GL_UNSIGNED_SHORT
||
3645 dstType
== GL_UNSIGNED_INT
);
3647 /* only shift and offset apply to stencil */
3648 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
3651 * Try simple cases first
3653 if (transferOps
== 0 &&
3654 srcType
== GL_UNSIGNED_BYTE
&&
3655 dstType
== GL_UNSIGNED_BYTE
) {
3656 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
3658 else if (transferOps
== 0 &&
3659 srcType
== GL_UNSIGNED_INT
&&
3660 dstType
== GL_UNSIGNED_INT
&&
3661 !srcPacking
->SwapBytes
) {
3662 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
3668 GLuint indexes
[MAX_WIDTH
];
3669 assert(n
<= MAX_WIDTH
);
3671 extract_uint_indexes(n
, indexes
, GL_STENCIL_INDEX
, srcType
, source
,
3675 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3676 /* shift and offset indexes */
3677 shift_and_offset_ci(ctx
, n
, indexes
);
3680 if (ctx
->Pixel
.MapStencilFlag
) {
3681 /* Apply stencil lookup table */
3682 GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
3685 indexes
[i
] = ctx
->PixelMaps
.StoS
.Map
[ indexes
[i
] & mask
];
3690 /* convert to dest type */
3692 case GL_UNSIGNED_BYTE
:
3694 GLubyte
*dst
= (GLubyte
*) dest
;
3696 for (i
= 0; i
< n
; i
++) {
3697 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3701 case GL_UNSIGNED_SHORT
:
3703 GLuint
*dst
= (GLuint
*) dest
;
3705 for (i
= 0; i
< n
; i
++) {
3706 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3710 case GL_UNSIGNED_INT
:
3711 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
3714 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
3721 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3722 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
3723 const struct gl_pixelstore_attrib
*dstPacking
)
3725 GLstencil stencil
[MAX_WIDTH
];
3727 ASSERT(n
<= MAX_WIDTH
);
3729 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
3730 ctx
->Pixel
.MapStencilFlag
) {
3731 /* make a copy of input */
3732 _mesa_memcpy(stencil
, source
, n
* sizeof(GLstencil
));
3733 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencil
);
3738 case GL_UNSIGNED_BYTE
:
3739 if (sizeof(GLstencil
) == 8) {
3740 _mesa_memcpy( dest
, source
, n
);
3743 GLubyte
*dst
= (GLubyte
*) dest
;
3746 dst
[i
] = (GLubyte
) source
[i
];
3751 if (sizeof(GLstencil
) == 8) {
3752 _mesa_memcpy( dest
, source
, n
);
3755 GLbyte
*dst
= (GLbyte
*) dest
;
3758 dst
[i
] = (GLbyte
) source
[i
];
3762 case GL_UNSIGNED_SHORT
:
3764 GLushort
*dst
= (GLushort
*) dest
;
3767 dst
[i
] = (GLushort
) source
[i
];
3769 if (dstPacking
->SwapBytes
) {
3770 _mesa_swap2( (GLushort
*) dst
, n
);
3776 GLshort
*dst
= (GLshort
*) dest
;
3779 dst
[i
] = (GLshort
) source
[i
];
3781 if (dstPacking
->SwapBytes
) {
3782 _mesa_swap2( (GLushort
*) dst
, n
);
3786 case GL_UNSIGNED_INT
:
3788 GLuint
*dst
= (GLuint
*) dest
;
3791 dst
[i
] = (GLuint
) source
[i
];
3793 if (dstPacking
->SwapBytes
) {
3794 _mesa_swap4( (GLuint
*) dst
, n
);
3800 GLint
*dst
= (GLint
*) dest
;
3803 *dst
++ = (GLint
) source
[i
];
3805 if (dstPacking
->SwapBytes
) {
3806 _mesa_swap4( (GLuint
*) dst
, n
);
3812 GLfloat
*dst
= (GLfloat
*) dest
;
3815 dst
[i
] = (GLfloat
) source
[i
];
3817 if (dstPacking
->SwapBytes
) {
3818 _mesa_swap4( (GLuint
*) dst
, n
);
3822 case GL_HALF_FLOAT_ARB
:
3824 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
3827 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
3829 if (dstPacking
->SwapBytes
) {
3830 _mesa_swap2( (GLushort
*) dst
, n
);
3835 if (dstPacking
->LsbFirst
) {
3836 GLubyte
*dst
= (GLubyte
*) dest
;
3839 for (i
= 0; i
< n
; i
++) {
3842 *dst
|= ((source
[i
] != 0) << shift
);
3851 GLubyte
*dst
= (GLubyte
*) dest
;
3854 for (i
= 0; i
< n
; i
++) {
3857 *dst
|= ((source
[i
] != 0) << shift
);
3867 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3871 #define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT) \
3874 const GLTYPE *src = (const GLTYPE *)source; \
3875 for (i = 0; i < n; i++) { \
3876 GLTYPE value = src[i]; \
3877 if (srcPacking->SwapBytes) { \
3878 if (sizeof(GLTYPE) == 2) { \
3880 } else if (sizeof(GLTYPE) == 4) { \
3884 depthValues[i] = CLAMP(GLTYPE2FLOAT(value), 0.0F, 1.0F); \
3889 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
,
3890 GLenum dstType
, GLvoid
*dest
, GLfloat depthScale
,
3891 GLenum srcType
, const GLvoid
*source
,
3892 const struct gl_pixelstore_attrib
*srcPacking
)
3894 GLfloat depthTemp
[MAX_WIDTH
], *depthValues
;
3896 if (dstType
== GL_FLOAT
) {
3897 depthValues
= (GLfloat
*) dest
;
3900 depthValues
= depthTemp
;
3903 /* XXX we need to obey srcPacking->SwapBytes here!!! */
3908 DEPTH_VALUES(GLbyte
, BYTE_TO_FLOAT
);
3910 case GL_UNSIGNED_BYTE
:
3911 DEPTH_VALUES(GLubyte
, UBYTE_TO_FLOAT
);
3914 DEPTH_VALUES(GLshort
, SHORT_TO_FLOAT
);
3916 case GL_UNSIGNED_SHORT
:
3917 DEPTH_VALUES(GLushort
, USHORT_TO_FLOAT
);
3920 DEPTH_VALUES(GLint
, INT_TO_FLOAT
);
3922 case GL_UNSIGNED_INT
:
3923 DEPTH_VALUES(GLuint
, UINT_TO_FLOAT
);
3925 case GL_UNSIGNED_INT_24_8_EXT
: /* GL_EXT_packed_depth_stencil */
3926 if (dstType
== GL_UNSIGNED_INT
&&
3927 depthScale
== (GLfloat
) 0xffffff &&
3928 ctx
->Pixel
.DepthScale
== 1.0 &&
3929 ctx
->Pixel
.DepthBias
== 0.0) {
3930 const GLuint
*src
= (const GLuint
*) source
;
3931 GLuint
*zValues
= (GLuint
*) dest
;
3933 for (i
= 0; i
< n
; i
++) {
3934 GLuint value
= src
[i
];
3935 if (srcPacking
->SwapBytes
) {
3938 zValues
[i
] = value
& 0xffffff00;
3943 const GLuint
*src
= (const GLuint
*) source
;
3944 const GLfloat scale
= 1.0f
/ 0xffffff;
3946 for (i
= 0; i
< n
; i
++) {
3947 GLuint value
= src
[i
];
3948 if (srcPacking
->SwapBytes
) {
3951 depthValues
[i
] = (value
>> 8) * scale
;
3956 DEPTH_VALUES(GLfloat
, 1*);
3958 case GL_HALF_FLOAT_ARB
:
3961 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
3962 for (i
= 0; i
< n
; i
++) {
3963 GLhalfARB value
= src
[i
];
3964 if (srcPacking
->SwapBytes
) {
3967 depthValues
[i
] = _mesa_half_to_float(value
);
3972 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
3977 /* apply depth scale and bias and clamp to [0,1] */
3978 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
3979 _mesa_scale_and_bias_depth(ctx
, n
, depthValues
);
3982 if (dstType
== GL_UNSIGNED_INT
) {
3983 GLuint
*zValues
= (GLuint
*) dest
;
3985 if (depthScale
<= (GLfloat
) 0xffffff) {
3986 /* no overflow worries */
3987 for (i
= 0; i
< n
; i
++) {
3988 zValues
[i
] = (GLuint
) (depthValues
[i
] * depthScale
);
3992 /* need to use double precision to prevent overflow problems */
3993 for (i
= 0; i
< n
; i
++) {
3994 GLdouble z
= depthValues
[i
] * depthScale
;
3995 if (z
>= (GLdouble
) 0xffffffff)
3996 zValues
[i
] = 0xffffffff;
3998 zValues
[i
] = (GLuint
) z
;
4002 else if (dstType
== GL_UNSIGNED_SHORT
) {
4003 GLushort
*zValues
= (GLushort
*) dest
;
4005 ASSERT(depthScale
<= 65535.0);
4006 for (i
= 0; i
< n
; i
++) {
4007 zValues
[i
] = (GLushort
) (depthValues
[i
] * depthScale
);
4011 ASSERT(dstType
== GL_FLOAT
);
4012 ASSERT(depthScale
== 1.0F
);
4018 * Pack an array of depth values. The values are floats in [0,1].
4021 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
4022 GLenum dstType
, const GLfloat
*depthSpan
,
4023 const struct gl_pixelstore_attrib
*dstPacking
)
4025 GLfloat depthCopy
[MAX_WIDTH
];
4027 ASSERT(n
<= MAX_WIDTH
);
4029 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4030 _mesa_memcpy(depthCopy
, depthSpan
, n
* sizeof(GLfloat
));
4031 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4032 depthSpan
= depthCopy
;
4036 case GL_UNSIGNED_BYTE
:
4038 GLubyte
*dst
= (GLubyte
*) dest
;
4040 for (i
= 0; i
< n
; i
++) {
4041 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
4047 GLbyte
*dst
= (GLbyte
*) dest
;
4049 for (i
= 0; i
< n
; i
++) {
4050 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
4054 case GL_UNSIGNED_SHORT
:
4056 GLushort
*dst
= (GLushort
*) dest
;
4058 for (i
= 0; i
< n
; i
++) {
4059 CLAMPED_FLOAT_TO_USHORT(dst
[i
], depthSpan
[i
]);
4061 if (dstPacking
->SwapBytes
) {
4062 _mesa_swap2( (GLushort
*) dst
, n
);
4068 GLshort
*dst
= (GLshort
*) dest
;
4070 for (i
= 0; i
< n
; i
++) {
4071 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
4073 if (dstPacking
->SwapBytes
) {
4074 _mesa_swap2( (GLushort
*) dst
, n
);
4078 case GL_UNSIGNED_INT
:
4080 GLuint
*dst
= (GLuint
*) dest
;
4082 for (i
= 0; i
< n
; i
++) {
4083 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
4085 if (dstPacking
->SwapBytes
) {
4086 _mesa_swap4( (GLuint
*) dst
, n
);
4092 GLint
*dst
= (GLint
*) dest
;
4094 for (i
= 0; i
< n
; i
++) {
4095 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
4097 if (dstPacking
->SwapBytes
) {
4098 _mesa_swap4( (GLuint
*) dst
, n
);
4104 GLfloat
*dst
= (GLfloat
*) dest
;
4106 for (i
= 0; i
< n
; i
++) {
4107 dst
[i
] = depthSpan
[i
];
4109 if (dstPacking
->SwapBytes
) {
4110 _mesa_swap4( (GLuint
*) dst
, n
);
4114 case GL_HALF_FLOAT_ARB
:
4116 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4118 for (i
= 0; i
< n
; i
++) {
4119 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
4121 if (dstPacking
->SwapBytes
) {
4122 _mesa_swap2( (GLushort
*) dst
, n
);
4127 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
4134 * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
4137 _mesa_pack_depth_stencil_span(const GLcontext
*ctx
, GLuint n
, GLuint
*dest
,
4138 const GLfloat
*depthVals
,
4139 const GLstencil
*stencilVals
,
4140 const struct gl_pixelstore_attrib
*dstPacking
)
4142 GLfloat depthCopy
[MAX_WIDTH
];
4143 GLstencil stencilCopy
[MAX_WIDTH
];
4146 ASSERT(n
<= MAX_WIDTH
);
4148 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4149 _mesa_memcpy(depthCopy
, depthVals
, n
* sizeof(GLfloat
));
4150 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4151 depthVals
= depthCopy
;
4154 if (ctx
->Pixel
.IndexShift
||
4155 ctx
->Pixel
.IndexOffset
||
4156 ctx
->Pixel
.MapStencilFlag
) {
4157 _mesa_memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
4158 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencilCopy
);
4159 stencilVals
= stencilCopy
;
4162 for (i
= 0; i
< n
; i
++) {
4163 GLuint z
= (GLuint
) (depthVals
[i
] * 0xffffff);
4164 dest
[i
] = (z
<< 8) | (stencilVals
[i
] & 0xff);
4167 if (dstPacking
->SwapBytes
) {
4168 _mesa_swap4(dest
, n
);
4176 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
4177 * Return all image data in a contiguous block. This is used when we
4178 * compile glDrawPixels, glTexImage, etc into a display list. We
4179 * need a copy of the data in a standard format.
4182 _mesa_unpack_image( GLuint dimensions
,
4183 GLsizei width
, GLsizei height
, GLsizei depth
,
4184 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4185 const struct gl_pixelstore_attrib
*unpack
)
4187 GLint bytesPerRow
, compsPerRow
;
4188 GLboolean flipBytes
, swap2
, swap4
;
4191 return NULL
; /* not necessarily an error */
4193 if (width
<= 0 || height
<= 0 || depth
<= 0)
4194 return NULL
; /* generate error later */
4196 if (type
== GL_BITMAP
) {
4197 bytesPerRow
= (width
+ 7) >> 3;
4198 flipBytes
= unpack
->LsbFirst
;
4199 swap2
= swap4
= GL_FALSE
;
4203 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
4204 GLint components
= _mesa_components_in_format(format
);
4207 if (_mesa_type_is_packed(type
))
4210 if (bytesPerPixel
<= 0 || components
<= 0)
4211 return NULL
; /* bad format or type. generate error later */
4212 bytesPerRow
= bytesPerPixel
* width
;
4213 bytesPerComp
= bytesPerPixel
/ components
;
4214 flipBytes
= GL_FALSE
;
4215 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
4216 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
4217 compsPerRow
= components
* width
;
4218 assert(compsPerRow
>= width
);
4223 = (GLubyte
*) _mesa_malloc(bytesPerRow
* height
* depth
);
4227 return NULL
; /* generate GL_OUT_OF_MEMORY later */
4230 for (img
= 0; img
< depth
; img
++) {
4231 for (row
= 0; row
< height
; row
++) {
4232 const GLvoid
*src
= _mesa_image_address(dimensions
, unpack
, pixels
,
4233 width
, height
, format
, type
, img
, row
, 0);
4235 if ((type
== GL_BITMAP
) && (unpack
->SkipPixels
& 0x7)) {
4237 flipBytes
= GL_FALSE
;
4238 if (unpack
->LsbFirst
) {
4239 GLubyte srcMask
= 1 << (unpack
->SkipPixels
& 0x7);
4240 GLubyte dstMask
= 128;
4241 const GLubyte
*s
= src
;
4244 for (i
= 0; i
< width
; i
++) {
4248 if (srcMask
== 128) {
4252 srcMask
= srcMask
<< 1;
4259 dstMask
= dstMask
>> 1;
4263 GLubyte srcMask
= 128 >> (unpack
->SkipPixels
& 0x7);
4264 GLubyte dstMask
= 128;
4265 const GLubyte
*s
= src
;
4268 for (i
= 0; i
< width
; i
++) {
4276 srcMask
= srcMask
>> 1;
4283 dstMask
= dstMask
>> 1;
4288 _mesa_memcpy(dst
, src
, bytesPerRow
);
4289 /* byte flipping/swapping */
4291 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
4294 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
4297 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
4306 #endif /* _HAVE_FULL_GL */
4311 * Convert an array of RGBA colors from one datatype to another.
4312 * NOTE: src may equal dst. In that case, we use a temporary buffer.
4315 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
4316 GLenum dstType
, GLvoid
*dst
,
4317 GLuint count
, const GLubyte mask
[])
4319 GLuint tempBuffer
[MAX_WIDTH
][4];
4320 const GLboolean useTemp
= (src
== dst
);
4322 ASSERT(srcType
!= dstType
);
4325 case GL_UNSIGNED_BYTE
:
4326 if (dstType
== GL_UNSIGNED_SHORT
) {
4327 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
4328 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
4330 for (i
= 0; i
< count
; i
++) {
4331 if (!mask
|| mask
[i
]) {
4332 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
4333 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
4334 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
4335 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
4339 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
4342 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
4343 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
4345 ASSERT(dstType
== GL_FLOAT
);
4346 for (i
= 0; i
< count
; i
++) {
4347 if (!mask
|| mask
[i
]) {
4348 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
4349 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
4350 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
4351 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
4355 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
4358 case GL_UNSIGNED_SHORT
:
4359 if (dstType
== GL_UNSIGNED_BYTE
) {
4360 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
4361 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
4363 for (i
= 0; i
< count
; i
++) {
4364 if (!mask
|| mask
[i
]) {
4365 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
4366 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
4367 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
4368 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
4372 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
4375 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
4376 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
4378 ASSERT(dstType
== GL_FLOAT
);
4379 for (i
= 0; i
< count
; i
++) {
4380 if (!mask
|| mask
[i
]) {
4381 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
4382 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
4383 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
4384 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
4388 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
4392 if (dstType
== GL_UNSIGNED_BYTE
) {
4393 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
4394 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
4396 for (i
= 0; i
< count
; i
++) {
4397 if (!mask
|| mask
[i
]) {
4398 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
4399 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
4400 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
4401 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
4405 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
4408 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
4409 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
4411 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
4412 for (i
= 0; i
< count
; i
++) {
4413 if (!mask
|| mask
[i
]) {
4414 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
4415 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
4416 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
4417 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
4421 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
4425 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
4433 * Perform basic clipping for glDrawPixels. The image's position and size
4434 * and the unpack SkipPixels and SkipRows are adjusted so that the image
4435 * region is entirely within the window and scissor bounds.
4436 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
4437 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
4438 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
4440 * \return GL_TRUE if image is ready for drawing or
4441 * GL_FALSE if image was completely clipped away (draw nothing)
4444 _mesa_clip_drawpixels(const GLcontext
*ctx
,
4445 GLint
*destX
, GLint
*destY
,
4446 GLsizei
*width
, GLsizei
*height
,
4447 struct gl_pixelstore_attrib
*unpack
)
4449 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
4451 if (unpack
->RowLength
== 0) {
4452 unpack
->RowLength
= *width
;
4455 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
4456 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
4459 if (*destX
< buffer
->_Xmin
) {
4460 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
4461 *width
-= (buffer
->_Xmin
- *destX
);
4462 *destX
= buffer
->_Xmin
;
4464 /* right clipping */
4465 if (*destX
+ *width
> buffer
->_Xmax
)
4466 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
4471 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
4472 /* bottom clipping */
4473 if (*destY
< buffer
->_Ymin
) {
4474 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
4475 *height
-= (buffer
->_Ymin
- *destY
);
4476 *destY
= buffer
->_Ymin
;
4479 if (*destY
+ *height
> buffer
->_Ymax
)
4480 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
4482 else { /* upside down */
4484 if (*destY
> buffer
->_Ymax
) {
4485 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
4486 *height
-= (*destY
- buffer
->_Ymax
);
4487 *destY
= buffer
->_Ymax
;
4489 /* bottom clipping */
4490 if (*destY
- *height
< buffer
->_Ymin
)
4491 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
4492 /* adjust destY so it's the first row to write to */
4504 * Perform clipping for glReadPixels. The image's window position
4505 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
4506 * so that the image region is entirely within the window bounds.
4507 * Note: this is different from _mesa_clip_drawpixels() in that the
4508 * scissor box is ignored, and we use the bounds of the current readbuffer
4511 * \return GL_TRUE if image is ready for drawing or
4512 * GL_FALSE if image was completely clipped away (draw nothing)
4515 _mesa_clip_readpixels(const GLcontext
*ctx
,
4516 GLint
*srcX
, GLint
*srcY
,
4517 GLsizei
*width
, GLsizei
*height
,
4518 struct gl_pixelstore_attrib
*pack
)
4520 const GLframebuffer
*buffer
= ctx
->ReadBuffer
;
4522 if (pack
->RowLength
== 0) {
4523 pack
->RowLength
= *width
;
4528 pack
->SkipPixels
+= (0 - *srcX
);
4529 *width
-= (0 - *srcX
);
4532 /* right clipping */
4533 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
4534 *width
-= (*srcX
+ *width
- buffer
->Width
);
4539 /* bottom clipping */
4541 pack
->SkipRows
+= (0 - *srcY
);
4542 *height
-= (0 - *srcY
);
4546 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
4547 *height
-= (*srcY
+ *height
- buffer
->Height
);
4557 * Clip the rectangle defined by (x, y, width, height) against the bounds
4558 * specified by [xmin, xmax) and [ymin, ymax).
4559 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
4562 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
4563 GLint xmax
, GLint ymax
,
4565 GLsizei
*width
, GLsizei
*height
)
4569 *width
-= (xmin
- *x
);
4573 /* right clipping */
4574 if (*x
+ *width
> xmax
)
4575 *width
-= (*x
+ *width
- xmax
- 1);
4580 /* bottom (or top) clipping */
4582 *height
-= (ymin
- *y
);
4586 /* top (or bottom) clipping */
4587 if (*y
+ *height
> ymax
)
4588 *height
-= (*y
+ *height
- ymax
- 1);