2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
)
107 for (i
= 0; i
< n
; i
++) {
108 b
= (GLuint
) p
[i
]; /* words are often faster than bytes */
109 a
= ((b
& 0x01) << 7) |
123 * Flip the order of the 2 bytes in each word in the given array.
126 * \param n number of words.
129 _mesa_swap2( GLushort
*p
, GLuint n
)
132 for (i
= 0; i
< n
; i
++) {
133 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
140 * Flip the order of the 4 bytes in each word in the given array.
143 _mesa_swap4( GLuint
*p
, GLuint n
)
146 for (i
= 0; i
< n
; i
++) {
149 | ((b
>> 8) & 0xff00)
150 | ((b
<< 8) & 0xff0000)
151 | ((b
<< 24) & 0xff000000);
158 * Get the size of a GL data type.
160 * \param type GL data type.
162 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
163 * if an invalid type enum.
166 _mesa_sizeof_type( GLenum type
)
171 case GL_UNSIGNED_BYTE
:
172 return sizeof(GLubyte
);
174 return sizeof(GLbyte
);
175 case GL_UNSIGNED_SHORT
:
176 return sizeof(GLushort
);
178 return sizeof(GLshort
);
179 case GL_UNSIGNED_INT
:
180 return sizeof(GLuint
);
182 return sizeof(GLint
);
184 return sizeof(GLfloat
);
186 return sizeof(GLdouble
);
187 case GL_HALF_FLOAT_ARB
:
188 return sizeof(GLhalfARB
);
196 * Same as _mesa_sizeof_type() but also accepting the packed pixel
200 _mesa_sizeof_packed_type( GLenum type
)
205 case GL_UNSIGNED_BYTE
:
206 return sizeof(GLubyte
);
208 return sizeof(GLbyte
);
209 case GL_UNSIGNED_SHORT
:
210 return sizeof(GLushort
);
212 return sizeof(GLshort
);
213 case GL_UNSIGNED_INT
:
214 return sizeof(GLuint
);
216 return sizeof(GLint
);
217 case GL_HALF_FLOAT_ARB
:
218 return sizeof(GLhalfARB
);
220 return sizeof(GLfloat
);
221 case GL_UNSIGNED_BYTE_3_3_2
:
222 return sizeof(GLubyte
);
223 case GL_UNSIGNED_BYTE_2_3_3_REV
:
224 return sizeof(GLubyte
);
225 case GL_UNSIGNED_SHORT_5_6_5
:
226 return sizeof(GLushort
);
227 case GL_UNSIGNED_SHORT_5_6_5_REV
:
228 return sizeof(GLushort
);
229 case GL_UNSIGNED_SHORT_4_4_4_4
:
230 return sizeof(GLushort
);
231 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
232 return sizeof(GLushort
);
233 case GL_UNSIGNED_SHORT_5_5_5_1
:
234 return sizeof(GLushort
);
235 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
236 return sizeof(GLushort
);
237 case GL_UNSIGNED_INT_8_8_8_8
:
238 return sizeof(GLuint
);
239 case GL_UNSIGNED_INT_8_8_8_8_REV
:
240 return sizeof(GLuint
);
241 case GL_UNSIGNED_INT_10_10_10_2
:
242 return sizeof(GLuint
);
243 case GL_UNSIGNED_INT_2_10_10_10_REV
:
244 return sizeof(GLuint
);
245 case GL_UNSIGNED_SHORT_8_8_MESA
:
246 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
247 return sizeof(GLushort
);
248 case GL_UNSIGNED_INT_24_8_EXT
:
249 return sizeof(GLuint
);
257 * Get the number of components in a pixel format.
259 * \param format pixel format.
261 * \return the number of components in the given format, or -1 if a bad format.
264 _mesa_components_in_format( GLenum format
)
268 case GL_COLOR_INDEX1_EXT
:
269 case GL_COLOR_INDEX2_EXT
:
270 case GL_COLOR_INDEX4_EXT
:
271 case GL_COLOR_INDEX8_EXT
:
272 case GL_COLOR_INDEX12_EXT
:
273 case GL_COLOR_INDEX16_EXT
:
274 case GL_STENCIL_INDEX
:
275 case GL_DEPTH_COMPONENT
:
283 case GL_LUMINANCE_ALPHA
:
297 case GL_DEPTH_STENCIL_EXT
:
309 * Get the bytes per pixel of pixel format type pair.
311 * \param format pixel format.
312 * \param type pixel type.
314 * \return bytes per pixel, or -1 if a bad format or type was given.
317 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
319 GLint comps
= _mesa_components_in_format( format
);
325 return 0; /* special case */
327 case GL_UNSIGNED_BYTE
:
328 return comps
* sizeof(GLubyte
);
330 case GL_UNSIGNED_SHORT
:
331 return comps
* sizeof(GLshort
);
333 case GL_UNSIGNED_INT
:
334 return comps
* sizeof(GLint
);
336 return comps
* sizeof(GLfloat
);
337 case GL_HALF_FLOAT_ARB
:
338 return comps
* sizeof(GLhalfARB
);
339 case GL_UNSIGNED_BYTE_3_3_2
:
340 case GL_UNSIGNED_BYTE_2_3_3_REV
:
341 if (format
== GL_RGB
|| format
== GL_BGR
)
342 return sizeof(GLubyte
);
344 return -1; /* error */
345 case GL_UNSIGNED_SHORT_5_6_5
:
346 case GL_UNSIGNED_SHORT_5_6_5_REV
:
347 if (format
== GL_RGB
|| format
== GL_BGR
)
348 return sizeof(GLushort
);
350 return -1; /* error */
351 case GL_UNSIGNED_SHORT_4_4_4_4
:
352 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
353 case GL_UNSIGNED_SHORT_5_5_5_1
:
354 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
355 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
356 return sizeof(GLushort
);
359 case GL_UNSIGNED_INT_8_8_8_8
:
360 case GL_UNSIGNED_INT_8_8_8_8_REV
:
361 case GL_UNSIGNED_INT_10_10_10_2
:
362 case GL_UNSIGNED_INT_2_10_10_10_REV
:
363 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
364 return sizeof(GLuint
);
367 case GL_UNSIGNED_SHORT_8_8_MESA
:
368 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
369 if (format
== GL_YCBCR_MESA
)
370 return sizeof(GLushort
);
373 case GL_UNSIGNED_INT_24_8_EXT
:
374 if (format
== GL_DEPTH_STENCIL_EXT
)
375 return sizeof(GLuint
);
385 * Test for a legal pixel format and type.
387 * \param format pixel format.
388 * \param type pixel type.
390 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
394 _mesa_is_legal_format_and_type( GLcontext
*ctx
, GLenum format
, GLenum type
)
398 case GL_STENCIL_INDEX
:
402 case GL_UNSIGNED_BYTE
:
404 case GL_UNSIGNED_SHORT
:
406 case GL_UNSIGNED_INT
:
409 case GL_HALF_FLOAT_ARB
:
410 return ctx
->Extensions
.ARB_half_float_pixel
;
418 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
422 case GL_LUMINANCE_ALPHA
:
423 case GL_DEPTH_COMPONENT
:
426 case GL_UNSIGNED_BYTE
:
428 case GL_UNSIGNED_SHORT
:
430 case GL_UNSIGNED_INT
:
433 case GL_HALF_FLOAT_ARB
:
434 return ctx
->Extensions
.ARB_half_float_pixel
;
441 case GL_UNSIGNED_BYTE
:
443 case GL_UNSIGNED_SHORT
:
445 case GL_UNSIGNED_INT
:
447 case GL_UNSIGNED_BYTE_3_3_2
:
448 case GL_UNSIGNED_BYTE_2_3_3_REV
:
449 case GL_UNSIGNED_SHORT_5_6_5
:
450 case GL_UNSIGNED_SHORT_5_6_5_REV
:
452 case GL_HALF_FLOAT_ARB
:
453 return ctx
->Extensions
.ARB_half_float_pixel
;
459 /* NOTE: no packed types are supported with BGR. That's
460 * intentional, according to the GL spec.
463 case GL_UNSIGNED_BYTE
:
465 case GL_UNSIGNED_SHORT
:
467 case GL_UNSIGNED_INT
:
470 case GL_HALF_FLOAT_ARB
:
471 return ctx
->Extensions
.ARB_half_float_pixel
;
480 case GL_UNSIGNED_BYTE
:
482 case GL_UNSIGNED_SHORT
:
484 case GL_UNSIGNED_INT
:
486 case GL_UNSIGNED_SHORT_4_4_4_4
:
487 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
488 case GL_UNSIGNED_SHORT_5_5_5_1
:
489 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
490 case GL_UNSIGNED_INT_8_8_8_8
:
491 case GL_UNSIGNED_INT_8_8_8_8_REV
:
492 case GL_UNSIGNED_INT_10_10_10_2
:
493 case GL_UNSIGNED_INT_2_10_10_10_REV
:
495 case GL_HALF_FLOAT_ARB
:
496 return ctx
->Extensions
.ARB_half_float_pixel
;
501 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
502 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
506 case GL_DEPTH_STENCIL_EXT
:
507 if (ctx
->Extensions
.EXT_packed_depth_stencil
508 && type
== GL_UNSIGNED_INT_24_8_EXT
)
516 case GL_UNSIGNED_BYTE
:
518 case GL_UNSIGNED_SHORT
:
520 case GL_UNSIGNED_INT
:
534 * Return the address of a specific pixel in an image (1D, 2D or 3D).
536 * Pixel unpacking/packing parameters are observed according to \p packing.
538 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
539 * \param image starting address of image data
540 * \param width the image width
541 * \param height theimage height
542 * \param format the pixel format
543 * \param type the pixel data type
544 * \param packing the pixelstore attributes
545 * \param img which image in the volume (0 for 1D or 2D images)
546 * \param row row of pixel in the image (0 for 1D images)
547 * \param column column of pixel in the image
549 * \return address of pixel on success, or NULL on error.
551 * \sa gl_pixelstore_attrib.
554 _mesa_image_address( GLuint dimensions
,
555 const struct gl_pixelstore_attrib
*packing
,
557 GLsizei width
, GLsizei height
,
558 GLenum format
, GLenum type
,
559 GLint img
, GLint row
, GLint column
)
561 GLint alignment
; /* 1, 2 or 4 */
562 GLint pixels_per_row
;
563 GLint rows_per_image
;
566 GLint skipimages
; /* for 3-D volume images */
569 ASSERT(dimensions
>= 1 && dimensions
<= 3);
571 alignment
= packing
->Alignment
;
572 if (packing
->RowLength
> 0) {
573 pixels_per_row
= packing
->RowLength
;
576 pixels_per_row
= width
;
578 if (packing
->ImageHeight
> 0) {
579 rows_per_image
= packing
->ImageHeight
;
582 rows_per_image
= height
;
585 skippixels
= packing
->SkipPixels
;
586 /* Note: SKIP_ROWS _is_ used for 1D images */
587 skiprows
= packing
->SkipRows
;
588 /* Note: SKIP_IMAGES is only used for 3D images */
589 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
591 if (type
== GL_BITMAP
) {
593 GLint comp_per_pixel
; /* components per pixel */
594 GLint bytes_per_comp
; /* bytes per component */
596 GLint bytes_per_image
;
598 /* Compute bytes per component */
599 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
600 if (bytes_per_comp
< 0) {
604 /* Compute number of components per pixel */
605 comp_per_pixel
= _mesa_components_in_format( format
);
606 if (comp_per_pixel
< 0) {
610 bytes_per_row
= alignment
611 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
613 bytes_per_image
= bytes_per_row
* rows_per_image
;
615 pixel_addr
= (GLubyte
*) image
616 + (skipimages
+ img
) * bytes_per_image
617 + (skiprows
+ row
) * bytes_per_row
618 + (skippixels
+ column
) / 8;
621 /* Non-BITMAP data */
622 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
625 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
627 /* The pixel type and format should have been error checked earlier */
628 assert(bytes_per_pixel
> 0);
630 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
631 remainder
= bytes_per_row
% alignment
;
633 bytes_per_row
+= (alignment
- remainder
);
635 ASSERT(bytes_per_row
% alignment
== 0);
637 bytes_per_image
= bytes_per_row
* rows_per_image
;
639 if (packing
->Invert
) {
640 /* set pixel_addr to the last row */
641 topOfImage
= bytes_per_row
* (height
- 1);
642 bytes_per_row
= -bytes_per_row
;
648 /* compute final pixel address */
649 pixel_addr
= (GLubyte
*) image
650 + (skipimages
+ img
) * bytes_per_image
652 + (skiprows
+ row
) * bytes_per_row
653 + (skippixels
+ column
) * bytes_per_pixel
;
656 return (GLvoid
*) pixel_addr
;
661 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
664 GLenum format
, GLenum type
,
667 return _mesa_image_address(1, packing
, image
, width
, 1,
668 format
, type
, 0, 0, column
);
673 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
675 GLsizei width
, GLsizei height
,
676 GLenum format
, GLenum type
,
677 GLint row
, GLint column
)
679 return _mesa_image_address(2, packing
, image
, width
, height
,
680 format
, type
, 0, row
, column
);
685 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
687 GLsizei width
, GLsizei height
,
688 GLenum format
, GLenum type
,
689 GLint img
, GLint row
, GLint column
)
691 return _mesa_image_address(3, packing
, image
, width
, height
,
692 format
, type
, img
, row
, column
);
698 * Compute the stride (in bytes) between image rows.
700 * \param packing the pixelstore attributes
701 * \param width image width.
702 * \param format pixel format.
703 * \param type pixel data type.
705 * \return the stride in bytes for the given parameters, or -1 if error
708 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
709 GLint width
, GLenum format
, GLenum type
)
711 GLint bytesPerRow
, remainder
;
715 if (type
== GL_BITMAP
) {
716 if (packing
->RowLength
== 0) {
717 bytesPerRow
= (width
+ 7) / 8;
720 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
724 /* Non-BITMAP data */
725 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
726 if (bytesPerPixel
<= 0)
727 return -1; /* error */
728 if (packing
->RowLength
== 0) {
729 bytesPerRow
= bytesPerPixel
* width
;
732 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
736 remainder
= bytesPerRow
% packing
->Alignment
;
738 bytesPerRow
+= (packing
->Alignment
- remainder
);
741 if (packing
->Invert
) {
742 /* negate the bytes per row (negative row stride) */
743 bytesPerRow
= -bytesPerRow
;
753 * Compute the stride between images in a 3D texture (in bytes) for the given
754 * pixel packing parameters and image width, format and type.
757 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
758 GLint width
, GLint height
,
759 GLenum format
, GLenum type
)
761 GLint bytesPerRow
, bytesPerImage
, remainder
;
765 if (type
== GL_BITMAP
) {
766 if (packing
->RowLength
== 0) {
767 bytesPerRow
= (width
+ 7) / 8;
770 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
774 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
776 if (bytesPerPixel
<= 0)
777 return -1; /* error */
778 if (packing
->RowLength
== 0) {
779 bytesPerRow
= bytesPerPixel
* width
;
782 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
786 remainder
= bytesPerRow
% packing
->Alignment
;
788 bytesPerRow
+= (packing
->Alignment
- remainder
);
790 if (packing
->ImageHeight
== 0)
791 bytesPerImage
= bytesPerRow
* height
;
793 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
795 return bytesPerImage
;
800 * Unpack a 32x32 pixel polygon stipple from user memory using the
801 * current pixel unpack settings.
804 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
805 const struct gl_pixelstore_attrib
*unpacking
)
807 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap(32, 32, pattern
, unpacking
);
809 /* Convert pattern from GLubytes to GLuints and handle big/little
814 for (i
= 0; i
< 32; i
++) {
815 dest
[i
] = (p
[0] << 24)
827 * Pack polygon stipple into user memory given current pixel packing
831 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
832 const struct gl_pixelstore_attrib
*packing
)
834 /* Convert pattern from GLuints to GLubytes to handle big/little
835 * endian differences.
839 for (i
= 0; i
< 32; i
++) {
840 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
841 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
842 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
843 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
846 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
851 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
852 * order with row alignment = 1 byte.
855 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
856 const struct gl_pixelstore_attrib
*packing
)
858 GLint bytes
, row
, width_in_bytes
;
859 GLubyte
*buffer
, *dst
;
864 /* Alloc dest storage */
865 bytes
= ((width
+ 7) / 8 * height
);
866 buffer
= (GLubyte
*) _mesa_malloc( bytes
);
870 width_in_bytes
= CEILING( width
, 8 );
872 for (row
= 0; row
< height
; row
++) {
873 const GLubyte
*src
= (const GLubyte
*)
874 _mesa_image_address2d(packing
, pixels
, width
, height
,
875 GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
881 if ((packing
->SkipPixels
& 7) == 0) {
882 _mesa_memcpy( dst
, src
, width_in_bytes
);
883 if (packing
->LsbFirst
) {
884 flip_bytes( dst
, width_in_bytes
);
888 /* handling SkipPixels is a bit tricky (no pun intended!) */
890 if (packing
->LsbFirst
) {
891 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
892 GLubyte dstMask
= 128;
893 const GLubyte
*s
= src
;
896 for (i
= 0; i
< width
; i
++) {
900 if (srcMask
== 128) {
905 srcMask
= srcMask
<< 1;
913 dstMask
= dstMask
>> 1;
918 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
919 GLubyte dstMask
= 128;
920 const GLubyte
*s
= src
;
923 for (i
= 0; i
< width
; i
++) {
932 srcMask
= srcMask
>> 1;
940 dstMask
= dstMask
>> 1;
945 dst
+= width_in_bytes
;
956 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
957 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
959 GLint row
, width_in_bytes
;
965 width_in_bytes
= CEILING( width
, 8 );
967 for (row
= 0; row
< height
; row
++) {
968 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dest
,
969 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
973 if ((packing
->SkipPixels
& 7) == 0) {
974 _mesa_memcpy( dst
, src
, width_in_bytes
);
975 if (packing
->LsbFirst
) {
976 flip_bytes( dst
, width_in_bytes
);
980 /* handling SkipPixels is a bit tricky (no pun intended!) */
982 if (packing
->LsbFirst
) {
983 GLubyte srcMask
= 128;
984 GLubyte dstMask
= 1 << (packing
->SkipPixels
& 0x7);
985 const GLubyte
*s
= src
;
988 for (i
= 0; i
< width
; i
++) {
997 srcMask
= srcMask
>> 1;
999 if (dstMask
== 128) {
1005 dstMask
= dstMask
<< 1;
1010 GLubyte srcMask
= 128;
1011 GLubyte dstMask
= 128 >> (packing
->SkipPixels
& 0x7);
1012 const GLubyte
*s
= src
;
1015 for (i
= 0; i
< width
; i
++) {
1024 srcMask
= srcMask
>> 1;
1032 dstMask
= dstMask
>> 1;
1037 src
+= width_in_bytes
;
1042 /**********************************************************************/
1043 /***** Pixel processing functions ******/
1044 /**********************************************************************/
1047 * Apply scale and bias factors to an array of RGBA pixels.
1050 _mesa_scale_and_bias_rgba(GLuint n
, GLfloat rgba
[][4],
1051 GLfloat rScale
, GLfloat gScale
,
1052 GLfloat bScale
, GLfloat aScale
,
1053 GLfloat rBias
, GLfloat gBias
,
1054 GLfloat bBias
, GLfloat aBias
)
1056 if (rScale
!= 1.0 || rBias
!= 0.0) {
1058 for (i
= 0; i
< n
; i
++) {
1059 rgba
[i
][RCOMP
] = rgba
[i
][RCOMP
] * rScale
+ rBias
;
1062 if (gScale
!= 1.0 || gBias
!= 0.0) {
1064 for (i
= 0; i
< n
; i
++) {
1065 rgba
[i
][GCOMP
] = rgba
[i
][GCOMP
] * gScale
+ gBias
;
1068 if (bScale
!= 1.0 || bBias
!= 0.0) {
1070 for (i
= 0; i
< n
; i
++) {
1071 rgba
[i
][BCOMP
] = rgba
[i
][BCOMP
] * bScale
+ bBias
;
1074 if (aScale
!= 1.0 || aBias
!= 0.0) {
1076 for (i
= 0; i
< n
; i
++) {
1077 rgba
[i
][ACOMP
] = rgba
[i
][ACOMP
] * aScale
+ aBias
;
1084 * Apply pixel mapping to an array of floating point RGBA pixels.
1087 _mesa_map_rgba( const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4] )
1089 const GLfloat rscale
= (GLfloat
) (ctx
->PixelMaps
.RtoR
.Size
- 1);
1090 const GLfloat gscale
= (GLfloat
) (ctx
->PixelMaps
.GtoG
.Size
- 1);
1091 const GLfloat bscale
= (GLfloat
) (ctx
->PixelMaps
.BtoB
.Size
- 1);
1092 const GLfloat ascale
= (GLfloat
) (ctx
->PixelMaps
.AtoA
.Size
- 1);
1093 const GLfloat
*rMap
= ctx
->PixelMaps
.RtoR
.Map
;
1094 const GLfloat
*gMap
= ctx
->PixelMaps
.GtoG
.Map
;
1095 const GLfloat
*bMap
= ctx
->PixelMaps
.BtoB
.Map
;
1096 const GLfloat
*aMap
= ctx
->PixelMaps
.AtoA
.Map
;
1099 GLfloat r
= CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1100 GLfloat g
= CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1101 GLfloat b
= CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1102 GLfloat a
= CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1103 rgba
[i
][RCOMP
] = rMap
[IROUND(r
* rscale
)];
1104 rgba
[i
][GCOMP
] = gMap
[IROUND(g
* gscale
)];
1105 rgba
[i
][BCOMP
] = bMap
[IROUND(b
* bscale
)];
1106 rgba
[i
][ACOMP
] = aMap
[IROUND(a
* ascale
)];
1112 * Apply the color matrix and post color matrix scaling and biasing.
1115 _mesa_transform_rgba(const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4])
1117 const GLfloat rs
= ctx
->Pixel
.PostColorMatrixScale
[0];
1118 const GLfloat rb
= ctx
->Pixel
.PostColorMatrixBias
[0];
1119 const GLfloat gs
= ctx
->Pixel
.PostColorMatrixScale
[1];
1120 const GLfloat gb
= ctx
->Pixel
.PostColorMatrixBias
[1];
1121 const GLfloat bs
= ctx
->Pixel
.PostColorMatrixScale
[2];
1122 const GLfloat bb
= ctx
->Pixel
.PostColorMatrixBias
[2];
1123 const GLfloat as
= ctx
->Pixel
.PostColorMatrixScale
[3];
1124 const GLfloat ab
= ctx
->Pixel
.PostColorMatrixBias
[3];
1125 const GLfloat
*m
= ctx
->ColorMatrixStack
.Top
->m
;
1127 for (i
= 0; i
< n
; i
++) {
1128 const GLfloat r
= rgba
[i
][RCOMP
];
1129 const GLfloat g
= rgba
[i
][GCOMP
];
1130 const GLfloat b
= rgba
[i
][BCOMP
];
1131 const GLfloat a
= rgba
[i
][ACOMP
];
1132 rgba
[i
][RCOMP
] = (m
[0] * r
+ m
[4] * g
+ m
[ 8] * b
+ m
[12] * a
) * rs
+ rb
;
1133 rgba
[i
][GCOMP
] = (m
[1] * r
+ m
[5] * g
+ m
[ 9] * b
+ m
[13] * a
) * gs
+ gb
;
1134 rgba
[i
][BCOMP
] = (m
[2] * r
+ m
[6] * g
+ m
[10] * b
+ m
[14] * a
) * bs
+ bb
;
1135 rgba
[i
][ACOMP
] = (m
[3] * r
+ m
[7] * g
+ m
[11] * b
+ m
[15] * a
) * as
+ ab
;
1141 * Apply a color table lookup to an array of floating point RGBA colors.
1144 _mesa_lookup_rgba_float(const struct gl_color_table
*table
,
1145 GLuint n
, GLfloat rgba
[][4])
1147 const GLint max
= table
->Size
- 1;
1148 const GLfloat scale
= (GLfloat
) max
;
1149 const GLfloat
*lut
= table
->TableF
;
1152 if (!table
->TableF
|| table
->Size
== 0)
1155 switch (table
->_BaseFormat
) {
1157 /* replace RGBA with I */
1158 for (i
= 0; i
< n
; i
++) {
1159 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1160 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1168 /* replace RGB with L */
1169 for (i
= 0; i
< n
; i
++) {
1170 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1171 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1178 /* replace A with A */
1179 for (i
= 0; i
< n
; i
++) {
1180 GLint j
= IROUND(rgba
[i
][ACOMP
] * scale
);
1181 rgba
[i
][ACOMP
] = lut
[CLAMP(j
, 0, max
)];
1184 case GL_LUMINANCE_ALPHA
:
1185 /* replace RGBA with LLLA */
1186 for (i
= 0; i
< n
; i
++) {
1187 GLint jL
= IROUND(rgba
[i
][RCOMP
] * scale
);
1188 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1189 GLfloat luminance
, alpha
;
1190 jL
= CLAMP(jL
, 0, max
);
1191 jA
= CLAMP(jA
, 0, max
);
1192 luminance
= lut
[jL
* 2 + 0];
1193 alpha
= lut
[jA
* 2 + 1];
1196 rgba
[i
][BCOMP
] = luminance
;
1197 rgba
[i
][ACOMP
] = alpha
;;
1201 /* replace RGB with RGB */
1202 for (i
= 0; i
< n
; i
++) {
1203 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1204 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1205 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1206 jR
= CLAMP(jR
, 0, max
);
1207 jG
= CLAMP(jG
, 0, max
);
1208 jB
= CLAMP(jB
, 0, max
);
1209 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1210 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1211 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1215 /* replace RGBA with RGBA */
1216 for (i
= 0; i
< n
; i
++) {
1217 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1218 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1219 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1220 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1221 jR
= CLAMP(jR
, 0, max
);
1222 jG
= CLAMP(jG
, 0, max
);
1223 jB
= CLAMP(jB
, 0, max
);
1224 jA
= CLAMP(jA
, 0, max
);
1225 rgba
[i
][RCOMP
] = lut
[jR
* 4 + 0];
1226 rgba
[i
][GCOMP
] = lut
[jG
* 4 + 1];
1227 rgba
[i
][BCOMP
] = lut
[jB
* 4 + 2];
1228 rgba
[i
][ACOMP
] = lut
[jA
* 4 + 3];
1232 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_float");
1240 * Apply a color table lookup to an array of ubyte/RGBA colors.
1243 _mesa_lookup_rgba_ubyte(const struct gl_color_table
*table
,
1244 GLuint n
, GLubyte rgba
[][4])
1246 const GLubyte
*lut
= table
->TableUB
;
1247 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / (GLfloat
)255.0;
1250 if (!table
->TableUB
|| table
->Size
== 0)
1253 switch (table
->_BaseFormat
) {
1255 /* replace RGBA with I */
1256 if (table
->Size
== 256) {
1257 for (i
= 0; i
< n
; i
++) {
1258 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1266 for (i
= 0; i
< n
; i
++) {
1267 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1271 rgba
[i
][ACOMP
] = lut
[j
];
1276 /* replace RGB with L */
1277 if (table
->Size
== 256) {
1278 for (i
= 0; i
< n
; i
++) {
1279 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1286 for (i
= 0; i
< n
; i
++) {
1287 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1290 rgba
[i
][BCOMP
] = lut
[j
];
1295 /* replace A with A */
1296 if (table
->Size
== 256) {
1297 for (i
= 0; i
< n
; i
++) {
1298 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
]];
1302 for (i
= 0; i
< n
; i
++) {
1303 GLint j
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1304 rgba
[i
][ACOMP
] = lut
[j
];
1308 case GL_LUMINANCE_ALPHA
:
1309 /* replace RGBA with LLLA */
1310 if (table
->Size
== 256) {
1311 for (i
= 0; i
< n
; i
++) {
1312 GLubyte l
= lut
[rgba
[i
][RCOMP
] * 2 + 0];
1313 GLubyte a
= lut
[rgba
[i
][ACOMP
] * 2 + 1];;
1321 for (i
= 0; i
< n
; i
++) {
1322 GLint jL
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1323 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1324 GLubyte luminance
= lut
[jL
* 2 + 0];
1325 GLubyte alpha
= lut
[jA
* 2 + 1];
1328 rgba
[i
][BCOMP
] = luminance
;
1329 rgba
[i
][ACOMP
] = alpha
;
1334 if (table
->Size
== 256) {
1335 for (i
= 0; i
< n
; i
++) {
1336 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 3 + 0];
1337 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 3 + 1];
1338 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 3 + 2];
1342 for (i
= 0; i
< n
; i
++) {
1343 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1344 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1345 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1346 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1347 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1348 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1353 if (table
->Size
== 256) {
1354 for (i
= 0; i
< n
; i
++) {
1355 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 4 + 0];
1356 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 4 + 1];
1357 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 4 + 2];
1358 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
] * 4 + 3];
1362 for (i
= 0; i
< n
; i
++) {
1363 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1364 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1365 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1366 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1367 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][RCOMP
], lut
[jR
* 4 + 0]);
1368 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][GCOMP
], lut
[jG
* 4 + 1]);
1369 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][BCOMP
], lut
[jB
* 4 + 2]);
1370 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][ACOMP
], lut
[jA
* 4 + 3]);
1375 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_chan");
1383 * Map color indexes to float rgba values.
1386 _mesa_map_ci_to_rgba( const GLcontext
*ctx
, GLuint n
,
1387 const GLuint index
[], GLfloat rgba
[][4] )
1389 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1390 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1391 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1392 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1393 const GLfloat
*rMap
= ctx
->PixelMaps
.ItoR
.Map
;
1394 const GLfloat
*gMap
= ctx
->PixelMaps
.ItoG
.Map
;
1395 const GLfloat
*bMap
= ctx
->PixelMaps
.ItoB
.Map
;
1396 const GLfloat
*aMap
= ctx
->PixelMaps
.ItoA
.Map
;
1399 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1400 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1401 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1402 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1408 * Map ubyte color indexes to ubyte/RGBA values.
1411 _mesa_map_ci8_to_rgba8(const GLcontext
*ctx
, GLuint n
, const GLubyte index
[],
1414 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1415 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1416 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1417 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1418 const GLubyte
*rMap
= ctx
->PixelMaps
.ItoR
.Map8
;
1419 const GLubyte
*gMap
= ctx
->PixelMaps
.ItoG
.Map8
;
1420 const GLubyte
*bMap
= ctx
->PixelMaps
.ItoB
.Map8
;
1421 const GLubyte
*aMap
= ctx
->PixelMaps
.ItoA
.Map8
;
1424 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1425 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1426 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1427 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1433 _mesa_scale_and_bias_depth(const GLcontext
*ctx
, GLuint n
,
1434 GLfloat depthValues
[])
1436 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
1437 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
1439 for (i
= 0; i
< n
; i
++) {
1440 GLfloat d
= depthValues
[i
] * scale
+ bias
;
1441 depthValues
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
1447 _mesa_scale_and_bias_depth_uint(const GLcontext
*ctx
, GLuint n
,
1448 GLuint depthValues
[])
1450 const GLdouble max
= (double) 0xffffffff;
1451 const GLdouble scale
= ctx
->Pixel
.DepthScale
;
1452 const GLdouble bias
= ctx
->Pixel
.DepthBias
* max
;
1454 for (i
= 0; i
< n
; i
++) {
1455 GLdouble d
= (GLdouble
) depthValues
[i
] * scale
+ bias
;
1456 d
= CLAMP(d
, 0.0, max
);
1457 depthValues
[i
] = (GLuint
) d
;
1464 * Update the min/max values from an array of fragment colors.
1467 update_minmax(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1470 for (i
= 0; i
< n
; i
++) {
1472 if (rgba
[i
][RCOMP
] < ctx
->MinMax
.Min
[RCOMP
])
1473 ctx
->MinMax
.Min
[RCOMP
] = rgba
[i
][RCOMP
];
1474 if (rgba
[i
][GCOMP
] < ctx
->MinMax
.Min
[GCOMP
])
1475 ctx
->MinMax
.Min
[GCOMP
] = rgba
[i
][GCOMP
];
1476 if (rgba
[i
][BCOMP
] < ctx
->MinMax
.Min
[BCOMP
])
1477 ctx
->MinMax
.Min
[BCOMP
] = rgba
[i
][BCOMP
];
1478 if (rgba
[i
][ACOMP
] < ctx
->MinMax
.Min
[ACOMP
])
1479 ctx
->MinMax
.Min
[ACOMP
] = rgba
[i
][ACOMP
];
1482 if (rgba
[i
][RCOMP
] > ctx
->MinMax
.Max
[RCOMP
])
1483 ctx
->MinMax
.Max
[RCOMP
] = rgba
[i
][RCOMP
];
1484 if (rgba
[i
][GCOMP
] > ctx
->MinMax
.Max
[GCOMP
])
1485 ctx
->MinMax
.Max
[GCOMP
] = rgba
[i
][GCOMP
];
1486 if (rgba
[i
][BCOMP
] > ctx
->MinMax
.Max
[BCOMP
])
1487 ctx
->MinMax
.Max
[BCOMP
] = rgba
[i
][BCOMP
];
1488 if (rgba
[i
][ACOMP
] > ctx
->MinMax
.Max
[ACOMP
])
1489 ctx
->MinMax
.Max
[ACOMP
] = rgba
[i
][ACOMP
];
1495 * Update the histogram values from an array of fragment colors.
1498 update_histogram(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1500 const GLint max
= ctx
->Histogram
.Width
- 1;
1501 GLfloat w
= (GLfloat
) max
;
1504 if (ctx
->Histogram
.Width
== 0)
1507 for (i
= 0; i
< n
; i
++) {
1508 GLint ri
= IROUND(rgba
[i
][RCOMP
] * w
);
1509 GLint gi
= IROUND(rgba
[i
][GCOMP
] * w
);
1510 GLint bi
= IROUND(rgba
[i
][BCOMP
] * w
);
1511 GLint ai
= IROUND(rgba
[i
][ACOMP
] * w
);
1512 ri
= CLAMP(ri
, 0, max
);
1513 gi
= CLAMP(gi
, 0, max
);
1514 bi
= CLAMP(bi
, 0, max
);
1515 ai
= CLAMP(ai
, 0, max
);
1516 ctx
->Histogram
.Count
[ri
][RCOMP
]++;
1517 ctx
->Histogram
.Count
[gi
][GCOMP
]++;
1518 ctx
->Histogram
.Count
[bi
][BCOMP
]++;
1519 ctx
->Histogram
.Count
[ai
][ACOMP
]++;
1525 * Apply various pixel transfer operations to an array of RGBA pixels
1526 * as indicated by the transferOps bitmask
1529 _mesa_apply_rgba_transfer_ops(GLcontext
*ctx
, GLbitfield transferOps
,
1530 GLuint n
, GLfloat rgba
[][4])
1533 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
1534 _mesa_scale_and_bias_rgba(n
, rgba
,
1535 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
1536 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
1537 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
1538 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
1540 /* color map lookup */
1541 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1542 _mesa_map_rgba( ctx
, n
, rgba
);
1544 /* GL_COLOR_TABLE lookup */
1545 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
1546 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
], n
, rgba
);
1549 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
1550 /* this has to be done in the calling code */
1551 _mesa_problem(ctx
, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");
1553 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
1554 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
1555 _mesa_scale_and_bias_rgba(n
, rgba
,
1556 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
1557 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
1558 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
1559 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
1560 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
1561 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
1562 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
1563 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
1565 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
1566 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
1567 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
], n
, rgba
);
1569 /* color matrix transform */
1570 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
1571 _mesa_transform_rgba(ctx
, n
, rgba
);
1573 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
1574 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
1575 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
], n
, rgba
);
1577 /* update histogram count */
1578 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
1579 update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1581 /* update min/max values */
1582 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
1583 update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1585 /* clamping to [0,1] */
1586 if (transferOps
& IMAGE_CLAMP_BIT
) {
1588 for (i
= 0; i
< n
; i
++) {
1589 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1590 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1591 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1592 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1599 * Apply color index shift and offset to an array of pixels.
1602 shift_and_offset_ci( const GLcontext
*ctx
, GLuint n
, GLuint indexes
[] )
1604 GLint shift
= ctx
->Pixel
.IndexShift
;
1605 GLint offset
= ctx
->Pixel
.IndexOffset
;
1609 indexes
[i
] = (indexes
[i
] << shift
) + offset
;
1612 else if (shift
< 0) {
1615 indexes
[i
] = (indexes
[i
] >> shift
) + offset
;
1620 indexes
[i
] = indexes
[i
] + offset
;
1628 * Apply color index shift, offset and table lookup to an array
1632 _mesa_apply_ci_transfer_ops(const GLcontext
*ctx
, GLbitfield transferOps
,
1633 GLuint n
, GLuint indexes
[])
1635 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
1636 shift_and_offset_ci(ctx
, n
, indexes
);
1638 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1639 const GLuint mask
= ctx
->PixelMaps
.ItoI
.Size
- 1;
1641 for (i
= 0; i
< n
; i
++) {
1642 const GLuint j
= indexes
[i
] & mask
;
1643 indexes
[i
] = IROUND(ctx
->PixelMaps
.ItoI
.Map
[j
]);
1650 * Apply stencil index shift, offset and table lookup to an array
1651 * of stencil values.
1654 _mesa_apply_stencil_transfer_ops(const GLcontext
*ctx
, GLuint n
,
1655 GLstencil stencil
[])
1657 if (ctx
->Pixel
.IndexShift
!= 0 || ctx
->Pixel
.IndexOffset
!= 0) {
1658 const GLint offset
= ctx
->Pixel
.IndexOffset
;
1659 GLint shift
= ctx
->Pixel
.IndexShift
;
1662 for (i
= 0; i
< n
; i
++) {
1663 stencil
[i
] = (stencil
[i
] << shift
) + offset
;
1666 else if (shift
< 0) {
1668 for (i
= 0; i
< n
; i
++) {
1669 stencil
[i
] = (stencil
[i
] >> shift
) + offset
;
1673 for (i
= 0; i
< n
; i
++) {
1674 stencil
[i
] = stencil
[i
] + offset
;
1678 if (ctx
->Pixel
.MapStencilFlag
) {
1679 GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
1681 for (i
= 0; i
< n
; i
++) {
1682 stencil
[i
] = (GLstencil
)ctx
->PixelMaps
.StoS
.Map
[ stencil
[i
] & mask
];
1689 * Used to pack an array [][4] of RGBA float colors as specified
1690 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
1691 * glGetConvolutionFilter(), etc.
1692 * Note: the rgba values will be modified by this function when any pixel
1693 * transfer ops are enabled.
1696 _mesa_pack_rgba_span_float(GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4],
1697 GLenum dstFormat
, GLenum dstType
,
1699 const struct gl_pixelstore_attrib
*dstPacking
,
1700 GLbitfield transferOps
)
1702 GLfloat luminance
[MAX_WIDTH
];
1703 const GLint comps
= _mesa_components_in_format(dstFormat
);
1707 * This test should probably go away. Have the caller set/clear the
1708 * IMAGE_CLAMP_BIT as needed.
1710 if (dstType
!= GL_FLOAT
|| ctx
->Color
.ClampReadColor
== GL_TRUE
) {
1711 /* need to clamp to [0, 1] */
1712 transferOps
|= IMAGE_CLAMP_BIT
;
1716 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
1717 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
1722 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
1723 /* compute luminance values */
1724 if (transferOps
& IMAGE_CLAMP_BIT
) {
1725 for (i
= 0; i
< n
; i
++) {
1726 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1727 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
1731 for (i
= 0; i
< n
; i
++) {
1732 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1738 * Pack/store the pixels. Ugh! Lots of cases!!!
1741 case GL_UNSIGNED_BYTE
:
1743 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1744 switch (dstFormat
) {
1747 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1751 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1755 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1759 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1763 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1765 case GL_LUMINANCE_ALPHA
:
1767 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1768 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1773 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1774 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1775 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1780 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1781 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1782 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1783 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1788 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1789 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1790 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1795 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1796 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1797 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1798 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1803 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1804 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1805 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1806 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1812 dst
[i
*2+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1813 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1817 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1823 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1824 switch (dstFormat
) {
1827 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1831 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1835 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1839 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1843 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1845 case GL_LUMINANCE_ALPHA
:
1847 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1848 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1853 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1854 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1855 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1860 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1861 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1862 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1863 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1868 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1869 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1870 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1875 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1876 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1877 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1878 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1883 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1884 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1885 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1886 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1892 dst
[i
*2+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1893 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1897 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1901 case GL_UNSIGNED_SHORT
:
1903 GLushort
*dst
= (GLushort
*) dstAddr
;
1904 switch (dstFormat
) {
1907 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][RCOMP
]);
1911 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][GCOMP
]);
1915 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][BCOMP
]);
1919 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][ACOMP
]);
1923 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
], luminance
[i
]);
1925 case GL_LUMINANCE_ALPHA
:
1927 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
*2+0], luminance
[i
]);
1928 CLAMPED_FLOAT_TO_USHORT(dst
[i
*2+1], rgba
[i
][ACOMP
]);
1933 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][RCOMP
]);
1934 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1935 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][BCOMP
]);
1940 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][RCOMP
]);
1941 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1942 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][BCOMP
]);
1943 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1948 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][BCOMP
]);
1949 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1950 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][RCOMP
]);
1955 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][BCOMP
]);
1956 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1957 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][RCOMP
]);
1958 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1963 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][ACOMP
]);
1964 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][BCOMP
]);
1965 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][GCOMP
]);
1966 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][RCOMP
]);
1972 dst
[i
*2+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1973 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1977 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1983 GLshort
*dst
= (GLshort
*) dstAddr
;
1984 switch (dstFormat
) {
1987 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1991 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1995 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1999 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2003 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
2005 case GL_LUMINANCE_ALPHA
:
2007 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
2008 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2013 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2014 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2015 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2020 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2021 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2022 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2023 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2028 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2029 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2030 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2035 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2036 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2037 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2038 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2043 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2044 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2045 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2046 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2052 dst
[i
*2+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2053 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2057 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2061 case GL_UNSIGNED_INT
:
2063 GLuint
*dst
= (GLuint
*) dstAddr
;
2064 switch (dstFormat
) {
2067 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2071 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2075 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2079 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2083 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
2085 case GL_LUMINANCE_ALPHA
:
2087 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
2088 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2093 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2094 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2095 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2100 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2101 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2102 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2103 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2108 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2109 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2110 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2115 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2116 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2117 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2118 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2123 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2124 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2125 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2126 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2132 dst
[i
*2+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2133 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2137 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2143 GLint
*dst
= (GLint
*) dstAddr
;
2144 switch (dstFormat
) {
2147 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2151 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2155 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2159 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2163 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
2165 case GL_LUMINANCE_ALPHA
:
2167 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
2168 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2173 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2174 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2175 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2180 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2181 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2182 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2183 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2188 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2189 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2190 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2195 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2196 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2197 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2198 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2203 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2204 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2205 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2206 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2212 dst
[i
*2+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2213 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2217 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2223 GLfloat
*dst
= (GLfloat
*) dstAddr
;
2224 switch (dstFormat
) {
2227 dst
[i
] = rgba
[i
][RCOMP
];
2231 dst
[i
] = rgba
[i
][GCOMP
];
2235 dst
[i
] = rgba
[i
][BCOMP
];
2239 dst
[i
] = rgba
[i
][ACOMP
];
2243 dst
[i
] = luminance
[i
];
2245 case GL_LUMINANCE_ALPHA
:
2247 dst
[i
*2+0] = luminance
[i
];
2248 dst
[i
*2+1] = rgba
[i
][ACOMP
];
2253 dst
[i
*3+0] = rgba
[i
][RCOMP
];
2254 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2255 dst
[i
*3+2] = rgba
[i
][BCOMP
];
2260 dst
[i
*4+0] = rgba
[i
][RCOMP
];
2261 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2262 dst
[i
*4+2] = rgba
[i
][BCOMP
];
2263 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2268 dst
[i
*3+0] = rgba
[i
][BCOMP
];
2269 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2270 dst
[i
*3+2] = rgba
[i
][RCOMP
];
2275 dst
[i
*4+0] = rgba
[i
][BCOMP
];
2276 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2277 dst
[i
*4+2] = rgba
[i
][RCOMP
];
2278 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2283 dst
[i
*4+0] = rgba
[i
][ACOMP
];
2284 dst
[i
*4+1] = rgba
[i
][BCOMP
];
2285 dst
[i
*4+2] = rgba
[i
][GCOMP
];
2286 dst
[i
*4+3] = rgba
[i
][RCOMP
];
2292 dst
[i
*2+0] = rgba
[i
][RCOMP
];
2293 dst
[i
*2+1] = rgba
[i
][GCOMP
];
2297 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2301 case GL_HALF_FLOAT_ARB
:
2303 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
2304 switch (dstFormat
) {
2307 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2311 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2315 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2319 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2323 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
2325 case GL_LUMINANCE_ALPHA
:
2327 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
2328 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2333 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2334 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2335 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2340 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2341 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2342 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2343 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2348 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2349 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2350 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2355 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2356 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2357 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2358 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2363 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2364 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2365 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2366 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2372 dst
[i
*2+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2373 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2377 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2381 case GL_UNSIGNED_BYTE_3_3_2
:
2382 if (dstFormat
== GL_RGB
) {
2383 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2385 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 7.0F
) << 5)
2386 | (IROUND(rgba
[i
][GCOMP
] * 7.0F
) << 2)
2387 | (IROUND(rgba
[i
][BCOMP
] * 3.0F
) );
2391 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2392 if (dstFormat
== GL_RGB
) {
2393 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2395 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 7.0F
) )
2396 | (IROUND(rgba
[i
][GCOMP
] * 7.0F
) << 3)
2397 | (IROUND(rgba
[i
][BCOMP
] * 3.0F
) << 6);
2401 case GL_UNSIGNED_SHORT_5_6_5
:
2402 if (dstFormat
== GL_RGB
) {
2403 GLushort
*dst
= (GLushort
*) dstAddr
;
2405 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 11)
2406 | (IROUND(rgba
[i
][GCOMP
] * 63.0F
) << 5)
2407 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) );
2411 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2412 if (dstFormat
== GL_RGB
) {
2413 GLushort
*dst
= (GLushort
*) dstAddr
;
2415 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) )
2416 | (IROUND(rgba
[i
][GCOMP
] * 63.0F
) << 5)
2417 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 11);
2421 case GL_UNSIGNED_SHORT_4_4_4_4
:
2422 if (dstFormat
== GL_RGBA
) {
2423 GLushort
*dst
= (GLushort
*) dstAddr
;
2425 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 12)
2426 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2427 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 4)
2428 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) );
2431 else if (dstFormat
== GL_BGRA
) {
2432 GLushort
*dst
= (GLushort
*) dstAddr
;
2434 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 12)
2435 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2436 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 4)
2437 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) );
2440 else if (dstFormat
== GL_ABGR_EXT
) {
2441 GLushort
*dst
= (GLushort
*) dstAddr
;
2443 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12)
2444 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 8)
2445 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2446 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) );
2450 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2451 if (dstFormat
== GL_RGBA
) {
2452 GLushort
*dst
= (GLushort
*) dstAddr
;
2454 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 15.0F
) )
2455 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2456 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 8)
2457 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12);
2460 else if (dstFormat
== GL_BGRA
) {
2461 GLushort
*dst
= (GLushort
*) dstAddr
;
2463 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 15.0F
) )
2464 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2465 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 8)
2466 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12);
2469 else if (dstFormat
== GL_ABGR_EXT
) {
2470 GLushort
*dst
= (GLushort
*) dstAddr
;
2472 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 15.0F
) )
2473 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 4)
2474 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2475 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 12);
2479 case GL_UNSIGNED_SHORT_5_5_5_1
:
2480 if (dstFormat
== GL_RGBA
) {
2481 GLushort
*dst
= (GLushort
*) dstAddr
;
2483 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 11)
2484 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 6)
2485 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 1)
2486 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) );
2489 else if (dstFormat
== GL_BGRA
) {
2490 GLushort
*dst
= (GLushort
*) dstAddr
;
2492 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 11)
2493 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 6)
2494 | (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 1)
2495 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) );
2498 else if (dstFormat
== GL_ABGR_EXT
) {
2499 GLushort
*dst
= (GLushort
*) dstAddr
;
2501 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 31.0F
) << 11)
2502 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 6)
2503 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 1)
2504 | (IROUND(rgba
[i
][RCOMP
] * 1.0F
) );
2508 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2509 if (dstFormat
== GL_RGBA
) {
2510 GLushort
*dst
= (GLushort
*) dstAddr
;
2512 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) )
2513 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 5)
2514 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 10)
2515 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) << 15);
2518 else if (dstFormat
== GL_BGRA
) {
2519 GLushort
*dst
= (GLushort
*) dstAddr
;
2521 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 31.0F
) )
2522 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 5)
2523 | (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 10)
2524 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) << 15);
2527 else if (dstFormat
== GL_ABGR_EXT
) {
2528 GLushort
*dst
= (GLushort
*) dstAddr
;
2530 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 31.0F
) )
2531 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 5)
2532 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 10)
2533 | (IROUND(rgba
[i
][RCOMP
] * 1.0F
) << 15);
2537 case GL_UNSIGNED_INT_8_8_8_8
:
2538 if (dstFormat
== GL_RGBA
) {
2539 GLuint
*dst
= (GLuint
*) dstAddr
;
2541 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 255.F
) << 24)
2542 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 16)
2543 | (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 8)
2544 | (IROUND(rgba
[i
][ACOMP
] * 255.F
) );
2547 else if (dstFormat
== GL_BGRA
) {
2548 GLuint
*dst
= (GLuint
*) dstAddr
;
2550 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 24)
2551 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 16)
2552 | (IROUND(rgba
[i
][RCOMP
] * 255.F
) << 8)
2553 | (IROUND(rgba
[i
][ACOMP
] * 255.F
) );
2556 else if (dstFormat
== GL_ABGR_EXT
) {
2557 GLuint
*dst
= (GLuint
*) dstAddr
;
2559 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 255.F
) << 24)
2560 | (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 16)
2561 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 8)
2562 | (IROUND(rgba
[i
][RCOMP
] * 255.F
) );
2566 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2567 if (dstFormat
== GL_RGBA
) {
2568 GLuint
*dst
= (GLuint
*) dstAddr
;
2570 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 255.0F
) )
2571 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 8)
2572 | (IROUND(rgba
[i
][BCOMP
] * 255.0F
) << 16)
2573 | (IROUND(rgba
[i
][ACOMP
] * 255.0F
) << 24);
2576 else if (dstFormat
== GL_BGRA
) {
2577 GLuint
*dst
= (GLuint
*) dstAddr
;
2579 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 255.0F
) )
2580 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 8)
2581 | (IROUND(rgba
[i
][RCOMP
] * 255.0F
) << 16)
2582 | (IROUND(rgba
[i
][ACOMP
] * 255.0F
) << 24);
2585 else if (dstFormat
== GL_ABGR_EXT
) {
2586 GLuint
*dst
= (GLuint
*) dstAddr
;
2588 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 255.0F
) )
2589 | (IROUND(rgba
[i
][BCOMP
] * 255.0F
) << 8)
2590 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 16)
2591 | (IROUND(rgba
[i
][RCOMP
] * 255.0F
) << 24);
2595 case GL_UNSIGNED_INT_10_10_10_2
:
2596 if (dstFormat
== GL_RGBA
) {
2597 GLuint
*dst
= (GLuint
*) dstAddr
;
2599 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 22)
2600 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 12)
2601 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 2)
2602 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) );
2605 else if (dstFormat
== GL_BGRA
) {
2606 GLuint
*dst
= (GLuint
*) dstAddr
;
2608 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 22)
2609 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 12)
2610 | (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 2)
2611 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) );
2614 else if (dstFormat
== GL_ABGR_EXT
) {
2615 GLuint
*dst
= (GLuint
*) dstAddr
;
2617 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 1023.0F
) << 22)
2618 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 12)
2619 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 2)
2620 | (IROUND(rgba
[i
][RCOMP
] * 3.0F
) );
2624 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2625 if (dstFormat
== GL_RGBA
) {
2626 GLuint
*dst
= (GLuint
*) dstAddr
;
2628 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) )
2629 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 10)
2630 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 20)
2631 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) << 30);
2634 else if (dstFormat
== GL_BGRA
) {
2635 GLuint
*dst
= (GLuint
*) dstAddr
;
2637 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) )
2638 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 10)
2639 | (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 20)
2640 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) << 30);
2643 else if (dstFormat
== GL_ABGR_EXT
) {
2644 GLuint
*dst
= (GLuint
*) dstAddr
;
2646 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 1023.0F
) )
2647 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 10)
2648 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 20)
2649 | (IROUND(rgba
[i
][RCOMP
] * 3.0F
) << 30);
2654 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
2658 if (dstPacking
->SwapBytes
) {
2659 GLint swapSize
= _mesa_sizeof_packed_type(dstType
);
2660 if (swapSize
== 2) {
2661 if (dstPacking
->SwapBytes
) {
2662 _mesa_swap2((GLushort
*) dstAddr
, n
* comps
);
2665 else if (swapSize
== 4) {
2666 if (dstPacking
->SwapBytes
) {
2667 _mesa_swap4((GLuint
*) dstAddr
, n
* comps
);
2674 #define SWAP2BYTE(VALUE) \
2676 GLubyte *bytes = (GLubyte *) &(VALUE); \
2677 GLubyte tmp = bytes[0]; \
2678 bytes[0] = bytes[1]; \
2682 #define SWAP4BYTE(VALUE) \
2684 GLubyte *bytes = (GLubyte *) &(VALUE); \
2685 GLubyte tmp = bytes[0]; \
2686 bytes[0] = bytes[3]; \
2689 bytes[1] = bytes[2]; \
2695 extract_uint_indexes(GLuint n
, GLuint indexes
[],
2696 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2697 const struct gl_pixelstore_attrib
*unpack
)
2699 ASSERT(srcFormat
== GL_COLOR_INDEX
|| srcFormat
== GL_STENCIL_INDEX
);
2701 ASSERT(srcType
== GL_BITMAP
||
2702 srcType
== GL_UNSIGNED_BYTE
||
2703 srcType
== GL_BYTE
||
2704 srcType
== GL_UNSIGNED_SHORT
||
2705 srcType
== GL_SHORT
||
2706 srcType
== GL_UNSIGNED_INT
||
2707 srcType
== GL_INT
||
2708 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
2709 srcType
== GL_HALF_FLOAT_ARB
||
2710 srcType
== GL_FLOAT
);
2715 GLubyte
*ubsrc
= (GLubyte
*) src
;
2716 if (unpack
->LsbFirst
) {
2717 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
2719 for (i
= 0; i
< n
; i
++) {
2720 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2731 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
2733 for (i
= 0; i
< n
; i
++) {
2734 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2746 case GL_UNSIGNED_BYTE
:
2749 const GLubyte
*s
= (const GLubyte
*) src
;
2750 for (i
= 0; i
< n
; i
++)
2757 const GLbyte
*s
= (const GLbyte
*) src
;
2758 for (i
= 0; i
< n
; i
++)
2762 case GL_UNSIGNED_SHORT
:
2765 const GLushort
*s
= (const GLushort
*) src
;
2766 if (unpack
->SwapBytes
) {
2767 for (i
= 0; i
< n
; i
++) {
2768 GLushort value
= s
[i
];
2774 for (i
= 0; i
< n
; i
++)
2782 const GLshort
*s
= (const GLshort
*) src
;
2783 if (unpack
->SwapBytes
) {
2784 for (i
= 0; i
< n
; i
++) {
2785 GLshort value
= s
[i
];
2791 for (i
= 0; i
< n
; i
++)
2796 case GL_UNSIGNED_INT
:
2799 const GLuint
*s
= (const GLuint
*) src
;
2800 if (unpack
->SwapBytes
) {
2801 for (i
= 0; i
< n
; i
++) {
2802 GLuint value
= s
[i
];
2808 for (i
= 0; i
< n
; i
++)
2816 const GLint
*s
= (const GLint
*) src
;
2817 if (unpack
->SwapBytes
) {
2818 for (i
= 0; i
< n
; i
++) {
2825 for (i
= 0; i
< n
; i
++)
2833 const GLfloat
*s
= (const GLfloat
*) src
;
2834 if (unpack
->SwapBytes
) {
2835 for (i
= 0; i
< n
; i
++) {
2836 GLfloat value
= s
[i
];
2838 indexes
[i
] = (GLuint
) value
;
2842 for (i
= 0; i
< n
; i
++)
2843 indexes
[i
] = (GLuint
) s
[i
];
2847 case GL_HALF_FLOAT_ARB
:
2850 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
2851 if (unpack
->SwapBytes
) {
2852 for (i
= 0; i
< n
; i
++) {
2853 GLhalfARB value
= s
[i
];
2855 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
2859 for (i
= 0; i
< n
; i
++)
2860 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
2864 case GL_UNSIGNED_INT_24_8_EXT
:
2867 const GLuint
*s
= (const GLuint
*) src
;
2868 if (unpack
->SwapBytes
) {
2869 for (i
= 0; i
< n
; i
++) {
2870 GLuint value
= s
[i
];
2872 indexes
[i
] = value
& 0xff; /* lower 8 bits */
2876 for (i
= 0; i
< n
; i
++)
2877 indexes
[i
] = s
[i
] & 0xfff; /* lower 8 bits */
2883 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2890 * This function extracts floating point RGBA values from arbitrary
2891 * image data. srcFormat and srcType are the format and type parameters
2892 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2894 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2895 * implements the "Conversion to floating point", "Conversion to RGB",
2896 * and "Final Expansion to RGBA" operations.
2898 * Args: n - number of pixels
2899 * rgba - output colors
2900 * srcFormat - format of incoming data
2901 * srcType - data type of incoming data
2902 * src - source data pointer
2903 * swapBytes - perform byteswapping of incoming data?
2906 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2907 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2908 GLboolean swapBytes
)
2910 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2912 GLint rComp
, bComp
, gComp
, aComp
;
2914 ASSERT(srcFormat
== GL_RED
||
2915 srcFormat
== GL_GREEN
||
2916 srcFormat
== GL_BLUE
||
2917 srcFormat
== GL_ALPHA
||
2918 srcFormat
== GL_LUMINANCE
||
2919 srcFormat
== GL_LUMINANCE_ALPHA
||
2920 srcFormat
== GL_INTENSITY
||
2921 srcFormat
== GL_RGB
||
2922 srcFormat
== GL_BGR
||
2923 srcFormat
== GL_RGBA
||
2924 srcFormat
== GL_BGRA
||
2925 srcFormat
== GL_ABGR_EXT
||
2926 srcFormat
== GL_DUDV_ATI
);
2928 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2929 srcType
== GL_BYTE
||
2930 srcType
== GL_UNSIGNED_SHORT
||
2931 srcType
== GL_SHORT
||
2932 srcType
== GL_UNSIGNED_INT
||
2933 srcType
== GL_INT
||
2934 srcType
== GL_HALF_FLOAT_ARB
||
2935 srcType
== GL_FLOAT
||
2936 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2937 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2938 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2939 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2940 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2941 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2942 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2943 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2944 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2945 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2946 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2947 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2949 rComp
= gComp
= bComp
= aComp
= -1;
2951 switch (srcFormat
) {
2954 greenIndex
= blueIndex
= alphaIndex
= -1;
2959 redIndex
= blueIndex
= alphaIndex
= -1;
2964 redIndex
= greenIndex
= alphaIndex
= -1;
2968 redIndex
= greenIndex
= blueIndex
= -1;
2973 redIndex
= greenIndex
= blueIndex
= 0;
2977 case GL_LUMINANCE_ALPHA
:
2978 redIndex
= greenIndex
= blueIndex
= 0;
2983 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
3049 _mesa_problem(NULL
, "bad srcFormat in extract float data");
3054 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
3055 if ((INDEX) < 0) { \
3057 for (i = 0; i < n; i++) { \
3058 rgba[i][CHANNEL] = DEFAULT; \
3061 else if (swapBytes) { \
3062 const TYPE *s = (const TYPE *) src; \
3064 for (i = 0; i < n; i++) { \
3065 TYPE value = s[INDEX]; \
3066 if (sizeof(TYPE) == 2) { \
3069 else if (sizeof(TYPE) == 4) { \
3072 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
3077 const TYPE *s = (const TYPE *) src; \
3079 for (i = 0; i < n; i++) { \
3080 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
3086 case GL_UNSIGNED_BYTE
:
3087 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3088 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3089 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3090 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3093 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3094 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3095 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3096 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
3098 case GL_UNSIGNED_SHORT
:
3099 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3100 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3101 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3102 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
3105 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3106 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3107 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3108 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
3110 case GL_UNSIGNED_INT
:
3111 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3112 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3113 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3114 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
3117 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3118 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3119 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3120 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
3123 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3124 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3125 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3126 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
3128 case GL_HALF_FLOAT_ARB
:
3129 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3130 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3131 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3132 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
3134 case GL_UNSIGNED_BYTE_3_3_2
:
3136 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3138 for (i
= 0; i
< n
; i
++) {
3139 GLubyte p
= ubsrc
[i
];
3140 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
3141 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
3142 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
3143 rgba
[i
][aComp
] = 1.0F
;
3147 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3149 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3151 for (i
= 0; i
< n
; i
++) {
3152 GLubyte p
= ubsrc
[i
];
3153 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
3154 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
3155 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
3156 rgba
[i
][aComp
] = 1.0F
;
3160 case GL_UNSIGNED_SHORT_5_6_5
:
3162 const GLushort
*ussrc
= (const GLushort
*) src
;
3164 for (i
= 0; i
< n
; i
++) {
3165 GLushort p
= ussrc
[i
];
3167 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3168 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3169 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3170 rgba
[i
][aComp
] = 1.0F
;
3174 const GLushort
*ussrc
= (const GLushort
*) src
;
3176 for (i
= 0; i
< n
; i
++) {
3177 GLushort p
= ussrc
[i
];
3178 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3179 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3180 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3181 rgba
[i
][aComp
] = 1.0F
;
3185 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3187 const GLushort
*ussrc
= (const GLushort
*) src
;
3189 for (i
= 0; i
< n
; i
++) {
3190 GLushort p
= ussrc
[i
];
3192 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3193 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3194 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3195 rgba
[i
][aComp
] = 1.0F
;
3199 const GLushort
*ussrc
= (const GLushort
*) src
;
3201 for (i
= 0; i
< n
; i
++) {
3202 GLushort p
= ussrc
[i
];
3203 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3204 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3205 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3206 rgba
[i
][aComp
] = 1.0F
;
3210 case GL_UNSIGNED_SHORT_4_4_4_4
:
3212 const GLushort
*ussrc
= (const GLushort
*) src
;
3214 for (i
= 0; i
< n
; i
++) {
3215 GLushort p
= ussrc
[i
];
3217 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3218 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3219 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3220 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3224 const GLushort
*ussrc
= (const GLushort
*) src
;
3226 for (i
= 0; i
< n
; i
++) {
3227 GLushort p
= ussrc
[i
];
3228 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3229 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3230 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3231 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3235 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3237 const GLushort
*ussrc
= (const GLushort
*) src
;
3239 for (i
= 0; i
< n
; i
++) {
3240 GLushort p
= ussrc
[i
];
3242 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3243 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3244 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3245 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3249 const GLushort
*ussrc
= (const GLushort
*) src
;
3251 for (i
= 0; i
< n
; i
++) {
3252 GLushort p
= ussrc
[i
];
3253 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3254 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3255 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3256 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3260 case GL_UNSIGNED_SHORT_5_5_5_1
:
3262 const GLushort
*ussrc
= (const GLushort
*) src
;
3264 for (i
= 0; i
< n
; i
++) {
3265 GLushort p
= ussrc
[i
];
3267 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3268 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3269 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3270 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3274 const GLushort
*ussrc
= (const GLushort
*) src
;
3276 for (i
= 0; i
< n
; i
++) {
3277 GLushort p
= ussrc
[i
];
3278 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3279 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3280 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3281 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3285 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3287 const GLushort
*ussrc
= (const GLushort
*) src
;
3289 for (i
= 0; i
< n
; i
++) {
3290 GLushort p
= ussrc
[i
];
3292 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3293 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3294 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3295 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3299 const GLushort
*ussrc
= (const GLushort
*) src
;
3301 for (i
= 0; i
< n
; i
++) {
3302 GLushort p
= ussrc
[i
];
3303 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3304 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3305 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3306 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3310 case GL_UNSIGNED_INT_8_8_8_8
:
3312 const GLuint
*uisrc
= (const GLuint
*) src
;
3314 for (i
= 0; i
< n
; i
++) {
3315 GLuint p
= uisrc
[i
];
3316 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3317 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3318 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3319 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3323 const GLuint
*uisrc
= (const GLuint
*) src
;
3325 for (i
= 0; i
< n
; i
++) {
3326 GLuint p
= uisrc
[i
];
3327 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3328 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3329 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3330 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3334 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3336 const GLuint
*uisrc
= (const GLuint
*) src
;
3338 for (i
= 0; i
< n
; i
++) {
3339 GLuint p
= uisrc
[i
];
3340 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3341 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3342 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3343 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3347 const GLuint
*uisrc
= (const GLuint
*) src
;
3349 for (i
= 0; i
< n
; i
++) {
3350 GLuint p
= uisrc
[i
];
3351 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3352 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3353 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3354 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3358 case GL_UNSIGNED_INT_10_10_10_2
:
3360 const GLuint
*uisrc
= (const GLuint
*) src
;
3362 for (i
= 0; i
< n
; i
++) {
3363 GLuint p
= uisrc
[i
];
3365 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3366 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3367 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3368 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3372 const GLuint
*uisrc
= (const GLuint
*) src
;
3374 for (i
= 0; i
< n
; i
++) {
3375 GLuint p
= uisrc
[i
];
3376 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3377 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3378 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3379 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3383 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3385 const GLuint
*uisrc
= (const GLuint
*) src
;
3387 for (i
= 0; i
< n
; i
++) {
3388 GLuint p
= uisrc
[i
];
3390 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3391 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3392 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3393 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3397 const GLuint
*uisrc
= (const GLuint
*) src
;
3399 for (i
= 0; i
< n
; i
++) {
3400 GLuint p
= uisrc
[i
];
3401 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3402 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3403 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3404 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3409 _mesa_problem(NULL
, "bad srcType in extract float data");
3416 * Unpack a row of color image data from a client buffer according to
3417 * the pixel unpacking parameters.
3418 * Return GLchan values in the specified dest image format.
3419 * This is used by glDrawPixels and glTexImage?D().
3420 * \param ctx - the context
3421 * n - number of pixels in the span
3422 * dstFormat - format of destination color array
3423 * dest - the destination color array
3424 * srcFormat - source image format
3425 * srcType - source image data type
3426 * source - source image pointer
3427 * srcPacking - pixel unpacking parameters
3428 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
3430 * XXX perhaps expand this to process whole images someday.
3433 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
3434 GLuint n
, GLenum dstFormat
, GLchan dest
[],
3435 GLenum srcFormat
, GLenum srcType
,
3436 const GLvoid
*source
,
3437 const struct gl_pixelstore_attrib
*srcPacking
,
3438 GLbitfield transferOps
)
3440 ASSERT(dstFormat
== GL_ALPHA
||
3441 dstFormat
== GL_LUMINANCE
||
3442 dstFormat
== GL_LUMINANCE_ALPHA
||
3443 dstFormat
== GL_INTENSITY
||
3444 dstFormat
== GL_RGB
||
3445 dstFormat
== GL_RGBA
||
3446 dstFormat
== GL_COLOR_INDEX
);
3448 ASSERT(srcFormat
== GL_RED
||
3449 srcFormat
== GL_GREEN
||
3450 srcFormat
== GL_BLUE
||
3451 srcFormat
== GL_ALPHA
||
3452 srcFormat
== GL_LUMINANCE
||
3453 srcFormat
== GL_LUMINANCE_ALPHA
||
3454 srcFormat
== GL_INTENSITY
||
3455 srcFormat
== GL_RGB
||
3456 srcFormat
== GL_BGR
||
3457 srcFormat
== GL_RGBA
||
3458 srcFormat
== GL_BGRA
||
3459 srcFormat
== GL_ABGR_EXT
||
3460 srcFormat
== GL_COLOR_INDEX
);
3462 ASSERT(srcType
== GL_BITMAP
||
3463 srcType
== GL_UNSIGNED_BYTE
||
3464 srcType
== GL_BYTE
||
3465 srcType
== GL_UNSIGNED_SHORT
||
3466 srcType
== GL_SHORT
||
3467 srcType
== GL_UNSIGNED_INT
||
3468 srcType
== GL_INT
||
3469 srcType
== GL_HALF_FLOAT_ARB
||
3470 srcType
== GL_FLOAT
||
3471 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3472 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3473 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3474 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3475 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3476 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3477 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3478 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3479 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3480 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3481 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3482 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3484 /* Try simple cases first */
3485 if (transferOps
== 0) {
3486 if (srcType
== CHAN_TYPE
) {
3487 if (dstFormat
== GL_RGBA
) {
3488 if (srcFormat
== GL_RGBA
) {
3489 _mesa_memcpy( dest
, source
, n
* 4 * sizeof(GLchan
) );
3492 else if (srcFormat
== GL_RGB
) {
3494 const GLchan
*src
= (const GLchan
*) source
;
3496 for (i
= 0; i
< n
; i
++) {
3507 else if (dstFormat
== GL_RGB
) {
3508 if (srcFormat
== GL_RGB
) {
3509 _mesa_memcpy( dest
, source
, n
* 3 * sizeof(GLchan
) );
3512 else if (srcFormat
== GL_RGBA
) {
3514 const GLchan
*src
= (const GLchan
*) source
;
3516 for (i
= 0; i
< n
; i
++) {
3526 else if (dstFormat
== srcFormat
) {
3527 GLint comps
= _mesa_components_in_format(srcFormat
);
3529 _mesa_memcpy( dest
, source
, n
* comps
* sizeof(GLchan
) );
3534 * Common situation, loading 8bit RGBA/RGB source images
3535 * into 16/32 bit destination. (OSMesa16/32)
3537 else if (srcType
== GL_UNSIGNED_BYTE
) {
3538 if (dstFormat
== GL_RGBA
) {
3539 if (srcFormat
== GL_RGB
) {
3541 const GLubyte
*src
= (const GLubyte
*) source
;
3543 for (i
= 0; i
< n
; i
++) {
3544 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3545 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3546 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3553 else if (srcFormat
== GL_RGBA
) {
3555 const GLubyte
*src
= (const GLubyte
*) source
;
3557 for (i
= 0; i
< n
; i
++) {
3558 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3559 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3560 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3561 dst
[3] = UBYTE_TO_CHAN(src
[3]);
3568 else if (dstFormat
== GL_RGB
) {
3569 if (srcFormat
== GL_RGB
) {
3571 const GLubyte
*src
= (const GLubyte
*) source
;
3573 for (i
= 0; i
< n
; i
++) {
3574 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3575 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3576 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3582 else if (srcFormat
== GL_RGBA
) {
3584 const GLubyte
*src
= (const GLubyte
*) source
;
3586 for (i
= 0; i
< n
; i
++) {
3587 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3588 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3589 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3600 /* general solution begins here */
3602 GLint dstComponents
;
3603 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3604 GLint dstLuminanceIndex
, dstIntensityIndex
;
3605 GLfloat rgba
[MAX_WIDTH
][4];
3607 dstComponents
= _mesa_components_in_format( dstFormat
);
3608 /* source & dest image formats should have been error checked by now */
3609 assert(dstComponents
> 0);
3612 * Extract image data and convert to RGBA floats
3614 assert(n
<= MAX_WIDTH
);
3615 if (srcFormat
== GL_COLOR_INDEX
) {
3616 GLuint indexes
[MAX_WIDTH
];
3617 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3620 if (dstFormat
== GL_COLOR_INDEX
) {
3622 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3623 /* convert to GLchan and return */
3624 for (i
= 0; i
< n
; i
++) {
3625 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3630 /* Convert indexes to RGBA */
3631 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3632 shift_and_offset_ci(ctx
, n
, indexes
);
3634 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3637 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3638 * with color indexes.
3640 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3643 /* non-color index data */
3644 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3645 srcPacking
->SwapBytes
);
3648 /* Need to clamp if returning GLubytes or GLushorts */
3649 #if CHAN_TYPE != GL_FLOAT
3650 transferOps
|= IMAGE_CLAMP_BIT
;
3654 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3657 /* Now determine which color channels we need to produce.
3658 * And determine the dest index (offset) within each color tuple.
3660 switch (dstFormat
) {
3663 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3664 dstLuminanceIndex
= dstIntensityIndex
= -1;
3667 dstLuminanceIndex
= 0;
3668 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3669 dstIntensityIndex
= -1;
3671 case GL_LUMINANCE_ALPHA
:
3672 dstLuminanceIndex
= 0;
3674 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3675 dstIntensityIndex
= -1;
3678 dstIntensityIndex
= 0;
3679 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3680 dstLuminanceIndex
= -1;
3686 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3693 dstLuminanceIndex
= dstIntensityIndex
= -1;
3696 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
3701 /* Now return the GLchan data in the requested dstFormat */
3703 if (dstRedIndex
>= 0) {
3706 for (i
= 0; i
< n
; i
++) {
3707 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
3708 dst
+= dstComponents
;
3712 if (dstGreenIndex
>= 0) {
3715 for (i
= 0; i
< n
; i
++) {
3716 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
3717 dst
+= dstComponents
;
3721 if (dstBlueIndex
>= 0) {
3724 for (i
= 0; i
< n
; i
++) {
3725 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
3726 dst
+= dstComponents
;
3730 if (dstAlphaIndex
>= 0) {
3733 for (i
= 0; i
< n
; i
++) {
3734 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
3735 dst
+= dstComponents
;
3739 if (dstIntensityIndex
>= 0) {
3742 assert(dstIntensityIndex
== 0);
3743 assert(dstComponents
== 1);
3744 for (i
= 0; i
< n
; i
++) {
3745 /* Intensity comes from red channel */
3746 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
3750 if (dstLuminanceIndex
>= 0) {
3753 assert(dstLuminanceIndex
== 0);
3754 for (i
= 0; i
< n
; i
++) {
3755 /* Luminance comes from red channel */
3756 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
3757 dst
+= dstComponents
;
3765 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
3766 * instead of GLchan.
3769 _mesa_unpack_color_span_float( GLcontext
*ctx
,
3770 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
3771 GLenum srcFormat
, GLenum srcType
,
3772 const GLvoid
*source
,
3773 const struct gl_pixelstore_attrib
*srcPacking
,
3774 GLbitfield transferOps
)
3776 ASSERT(dstFormat
== GL_ALPHA
||
3777 dstFormat
== GL_LUMINANCE
||
3778 dstFormat
== GL_LUMINANCE_ALPHA
||
3779 dstFormat
== GL_INTENSITY
||
3780 dstFormat
== GL_RGB
||
3781 dstFormat
== GL_RGBA
||
3782 dstFormat
== GL_COLOR_INDEX
);
3784 ASSERT(srcFormat
== GL_RED
||
3785 srcFormat
== GL_GREEN
||
3786 srcFormat
== GL_BLUE
||
3787 srcFormat
== GL_ALPHA
||
3788 srcFormat
== GL_LUMINANCE
||
3789 srcFormat
== GL_LUMINANCE_ALPHA
||
3790 srcFormat
== GL_INTENSITY
||
3791 srcFormat
== GL_RGB
||
3792 srcFormat
== GL_BGR
||
3793 srcFormat
== GL_RGBA
||
3794 srcFormat
== GL_BGRA
||
3795 srcFormat
== GL_ABGR_EXT
||
3796 srcFormat
== GL_COLOR_INDEX
);
3798 ASSERT(srcType
== GL_BITMAP
||
3799 srcType
== GL_UNSIGNED_BYTE
||
3800 srcType
== GL_BYTE
||
3801 srcType
== GL_UNSIGNED_SHORT
||
3802 srcType
== GL_SHORT
||
3803 srcType
== GL_UNSIGNED_INT
||
3804 srcType
== GL_INT
||
3805 srcType
== GL_HALF_FLOAT_ARB
||
3806 srcType
== GL_FLOAT
||
3807 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3808 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3809 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3810 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3811 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3812 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3813 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3814 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3815 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3816 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3817 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3818 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3820 /* general solution, no special cases, yet */
3822 GLint dstComponents
;
3823 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3824 GLint dstLuminanceIndex
, dstIntensityIndex
;
3825 GLfloat rgba
[MAX_WIDTH
][4];
3827 dstComponents
= _mesa_components_in_format( dstFormat
);
3828 /* source & dest image formats should have been error checked by now */
3829 assert(dstComponents
> 0);
3832 * Extract image data and convert to RGBA floats
3834 assert(n
<= MAX_WIDTH
);
3835 if (srcFormat
== GL_COLOR_INDEX
) {
3836 GLuint indexes
[MAX_WIDTH
];
3837 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3840 if (dstFormat
== GL_COLOR_INDEX
) {
3842 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3843 /* convert to GLchan and return */
3844 for (i
= 0; i
< n
; i
++) {
3845 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3850 /* Convert indexes to RGBA */
3851 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3852 shift_and_offset_ci(ctx
, n
, indexes
);
3854 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3857 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3858 * with color indexes.
3860 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3863 /* non-color index data */
3864 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3865 srcPacking
->SwapBytes
);
3869 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3872 /* Now determine which color channels we need to produce.
3873 * And determine the dest index (offset) within each color tuple.
3875 switch (dstFormat
) {
3878 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3879 dstLuminanceIndex
= dstIntensityIndex
= -1;
3882 dstLuminanceIndex
= 0;
3883 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3884 dstIntensityIndex
= -1;
3886 case GL_LUMINANCE_ALPHA
:
3887 dstLuminanceIndex
= 0;
3889 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3890 dstIntensityIndex
= -1;
3893 dstIntensityIndex
= 0;
3894 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3895 dstLuminanceIndex
= -1;
3901 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3908 dstLuminanceIndex
= dstIntensityIndex
= -1;
3911 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
3915 /* Now pack results in the requested dstFormat */
3916 if (dstRedIndex
>= 0) {
3917 GLfloat
*dst
= dest
;
3919 for (i
= 0; i
< n
; i
++) {
3920 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3921 dst
+= dstComponents
;
3925 if (dstGreenIndex
>= 0) {
3926 GLfloat
*dst
= dest
;
3928 for (i
= 0; i
< n
; i
++) {
3929 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3930 dst
+= dstComponents
;
3934 if (dstBlueIndex
>= 0) {
3935 GLfloat
*dst
= dest
;
3937 for (i
= 0; i
< n
; i
++) {
3938 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3939 dst
+= dstComponents
;
3943 if (dstAlphaIndex
>= 0) {
3944 GLfloat
*dst
= dest
;
3946 for (i
= 0; i
< n
; i
++) {
3947 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3948 dst
+= dstComponents
;
3952 if (dstIntensityIndex
>= 0) {
3953 GLfloat
*dst
= dest
;
3955 assert(dstIntensityIndex
== 0);
3956 assert(dstComponents
== 1);
3957 for (i
= 0; i
< n
; i
++) {
3958 /* Intensity comes from red channel */
3959 dst
[i
] = rgba
[i
][RCOMP
];
3963 if (dstLuminanceIndex
>= 0) {
3964 GLfloat
*dst
= dest
;
3966 assert(dstLuminanceIndex
== 0);
3967 for (i
= 0; i
< n
; i
++) {
3968 /* Luminance comes from red channel */
3969 dst
[0] = rgba
[i
][RCOMP
];
3970 dst
+= dstComponents
;
3977 * Similar to _mesa_unpack_color_span_float(), but for dudv data instead of rgba,
3978 * directly return GLbyte data, no transfer ops apply.
3981 _mesa_unpack_dudv_span_byte( GLcontext
*ctx
,
3982 GLuint n
, GLenum dstFormat
, GLbyte dest
[],
3983 GLenum srcFormat
, GLenum srcType
,
3984 const GLvoid
*source
,
3985 const struct gl_pixelstore_attrib
*srcPacking
,
3986 GLbitfield transferOps
)
3988 ASSERT(dstFormat
== GL_DUDV_ATI
);
3989 ASSERT(srcFormat
== GL_DUDV_ATI
);
3991 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
3992 srcType
== GL_BYTE
||
3993 srcType
== GL_UNSIGNED_SHORT
||
3994 srcType
== GL_SHORT
||
3995 srcType
== GL_UNSIGNED_INT
||
3996 srcType
== GL_INT
||
3997 srcType
== GL_HALF_FLOAT_ARB
||
3998 srcType
== GL_FLOAT
);
4000 /* general solution */
4002 GLint dstComponents
;
4003 GLfloat rgba
[MAX_WIDTH
][4];
4007 dstComponents
= _mesa_components_in_format( dstFormat
);
4008 /* source & dest image formats should have been error checked by now */
4009 assert(dstComponents
> 0);
4012 * Extract image data and convert to RGBA floats
4014 assert(n
<= MAX_WIDTH
);
4015 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
4016 srcPacking
->SwapBytes
);
4019 /* Now determine which color channels we need to produce.
4020 * And determine the dest index (offset) within each color tuple.
4023 /* Now pack results in the requested dstFormat */
4024 for (i
= 0; i
< n
; i
++) {
4025 /* not sure - need clamp[-1,1] here? */
4026 dst
[0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
4027 dst
[1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
4028 dst
+= dstComponents
;
4034 * Unpack a row of color index data from a client buffer according to
4035 * the pixel unpacking parameters.
4036 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
4038 * Args: ctx - the context
4039 * n - number of pixels
4040 * dstType - destination data type
4041 * dest - destination array
4042 * srcType - source pixel type
4043 * source - source data pointer
4044 * srcPacking - pixel unpacking parameters
4045 * transferOps - the pixel transfer operations to apply
4048 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
4049 GLenum dstType
, GLvoid
*dest
,
4050 GLenum srcType
, const GLvoid
*source
,
4051 const struct gl_pixelstore_attrib
*srcPacking
,
4052 GLbitfield transferOps
)
4054 ASSERT(srcType
== GL_BITMAP
||
4055 srcType
== GL_UNSIGNED_BYTE
||
4056 srcType
== GL_BYTE
||
4057 srcType
== GL_UNSIGNED_SHORT
||
4058 srcType
== GL_SHORT
||
4059 srcType
== GL_UNSIGNED_INT
||
4060 srcType
== GL_INT
||
4061 srcType
== GL_HALF_FLOAT_ARB
||
4062 srcType
== GL_FLOAT
);
4064 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4065 dstType
== GL_UNSIGNED_SHORT
||
4066 dstType
== GL_UNSIGNED_INT
);
4069 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4072 * Try simple cases first
4074 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
4075 && dstType
== GL_UNSIGNED_BYTE
) {
4076 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
4078 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
4079 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
4080 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
4086 GLuint indexes
[MAX_WIDTH
];
4087 assert(n
<= MAX_WIDTH
);
4089 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
4093 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4095 /* convert to dest type */
4097 case GL_UNSIGNED_BYTE
:
4099 GLubyte
*dst
= (GLubyte
*) dest
;
4101 for (i
= 0; i
< n
; i
++) {
4102 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4106 case GL_UNSIGNED_SHORT
:
4108 GLuint
*dst
= (GLuint
*) dest
;
4110 for (i
= 0; i
< n
; i
++) {
4111 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4115 case GL_UNSIGNED_INT
:
4116 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4119 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
4126 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
4127 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
4128 const struct gl_pixelstore_attrib
*dstPacking
,
4129 GLbitfield transferOps
)
4131 GLuint indexes
[MAX_WIDTH
];
4133 ASSERT(n
<= MAX_WIDTH
);
4135 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4137 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
4138 /* make a copy of input */
4139 _mesa_memcpy(indexes
, source
, n
* sizeof(GLuint
));
4140 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4145 case GL_UNSIGNED_BYTE
:
4147 GLubyte
*dst
= (GLubyte
*) dest
;
4149 for (i
= 0; i
< n
; i
++) {
4150 *dst
++ = (GLubyte
) source
[i
];
4156 GLbyte
*dst
= (GLbyte
*) dest
;
4158 for (i
= 0; i
< n
; i
++) {
4159 dst
[i
] = (GLbyte
) source
[i
];
4163 case GL_UNSIGNED_SHORT
:
4165 GLushort
*dst
= (GLushort
*) dest
;
4167 for (i
= 0; i
< n
; i
++) {
4168 dst
[i
] = (GLushort
) source
[i
];
4170 if (dstPacking
->SwapBytes
) {
4171 _mesa_swap2( (GLushort
*) dst
, n
);
4177 GLshort
*dst
= (GLshort
*) dest
;
4179 for (i
= 0; i
< n
; i
++) {
4180 dst
[i
] = (GLshort
) source
[i
];
4182 if (dstPacking
->SwapBytes
) {
4183 _mesa_swap2( (GLushort
*) dst
, n
);
4187 case GL_UNSIGNED_INT
:
4189 GLuint
*dst
= (GLuint
*) dest
;
4191 for (i
= 0; i
< n
; i
++) {
4192 dst
[i
] = (GLuint
) source
[i
];
4194 if (dstPacking
->SwapBytes
) {
4195 _mesa_swap4( (GLuint
*) dst
, n
);
4201 GLint
*dst
= (GLint
*) dest
;
4203 for (i
= 0; i
< n
; i
++) {
4204 dst
[i
] = (GLint
) source
[i
];
4206 if (dstPacking
->SwapBytes
) {
4207 _mesa_swap4( (GLuint
*) dst
, n
);
4213 GLfloat
*dst
= (GLfloat
*) dest
;
4215 for (i
= 0; i
< n
; i
++) {
4216 dst
[i
] = (GLfloat
) source
[i
];
4218 if (dstPacking
->SwapBytes
) {
4219 _mesa_swap4( (GLuint
*) dst
, n
);
4223 case GL_HALF_FLOAT_ARB
:
4225 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4227 for (i
= 0; i
< n
; i
++) {
4228 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
4230 if (dstPacking
->SwapBytes
) {
4231 _mesa_swap2( (GLushort
*) dst
, n
);
4236 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4242 * Unpack a row of stencil data from a client buffer according to
4243 * the pixel unpacking parameters.
4244 * This is (or will be) used by glDrawPixels
4246 * Args: ctx - the context
4247 * n - number of pixels
4248 * dstType - destination data type
4249 * dest - destination array
4250 * srcType - source pixel type
4251 * source - source data pointer
4252 * srcPacking - pixel unpacking parameters
4253 * transferOps - apply offset/bias/lookup ops?
4256 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4257 GLenum dstType
, GLvoid
*dest
,
4258 GLenum srcType
, const GLvoid
*source
,
4259 const struct gl_pixelstore_attrib
*srcPacking
,
4260 GLbitfield transferOps
)
4262 ASSERT(srcType
== GL_BITMAP
||
4263 srcType
== GL_UNSIGNED_BYTE
||
4264 srcType
== GL_BYTE
||
4265 srcType
== GL_UNSIGNED_SHORT
||
4266 srcType
== GL_SHORT
||
4267 srcType
== GL_UNSIGNED_INT
||
4268 srcType
== GL_INT
||
4269 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
4270 srcType
== GL_HALF_FLOAT_ARB
||
4271 srcType
== GL_FLOAT
);
4273 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4274 dstType
== GL_UNSIGNED_SHORT
||
4275 dstType
== GL_UNSIGNED_INT
);
4277 /* only shift and offset apply to stencil */
4278 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
4281 * Try simple cases first
4283 if (transferOps
== 0 &&
4284 !ctx
->Pixel
.MapStencilFlag
&&
4285 srcType
== GL_UNSIGNED_BYTE
&&
4286 dstType
== GL_UNSIGNED_BYTE
) {
4287 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
4289 else if (transferOps
== 0 &&
4290 !ctx
->Pixel
.MapStencilFlag
&&
4291 srcType
== GL_UNSIGNED_INT
&&
4292 dstType
== GL_UNSIGNED_INT
&&
4293 !srcPacking
->SwapBytes
) {
4294 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
4300 GLuint indexes
[MAX_WIDTH
];
4301 assert(n
<= MAX_WIDTH
);
4303 extract_uint_indexes(n
, indexes
, GL_STENCIL_INDEX
, srcType
, source
,
4306 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
4307 /* shift and offset indexes */
4308 shift_and_offset_ci(ctx
, n
, indexes
);
4311 if (ctx
->Pixel
.MapStencilFlag
) {
4312 /* Apply stencil lookup table */
4313 const GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
4315 for (i
= 0; i
< n
; i
++) {
4316 indexes
[i
] = (GLuint
)ctx
->PixelMaps
.StoS
.Map
[ indexes
[i
] & mask
];
4320 /* convert to dest type */
4322 case GL_UNSIGNED_BYTE
:
4324 GLubyte
*dst
= (GLubyte
*) dest
;
4326 for (i
= 0; i
< n
; i
++) {
4327 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4331 case GL_UNSIGNED_SHORT
:
4333 GLuint
*dst
= (GLuint
*) dest
;
4335 for (i
= 0; i
< n
; i
++) {
4336 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4340 case GL_UNSIGNED_INT
:
4341 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4344 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
4351 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4352 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
4353 const struct gl_pixelstore_attrib
*dstPacking
)
4355 GLstencil stencil
[MAX_WIDTH
];
4357 ASSERT(n
<= MAX_WIDTH
);
4359 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
4360 ctx
->Pixel
.MapStencilFlag
) {
4361 /* make a copy of input */
4362 _mesa_memcpy(stencil
, source
, n
* sizeof(GLstencil
));
4363 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencil
);
4368 case GL_UNSIGNED_BYTE
:
4369 if (sizeof(GLstencil
) == 1) {
4370 _mesa_memcpy( dest
, source
, n
);
4373 GLubyte
*dst
= (GLubyte
*) dest
;
4376 dst
[i
] = (GLubyte
) source
[i
];
4382 GLbyte
*dst
= (GLbyte
*) dest
;
4385 dst
[i
] = (GLbyte
) (source
[i
] & 0x7f);
4389 case GL_UNSIGNED_SHORT
:
4391 GLushort
*dst
= (GLushort
*) dest
;
4394 dst
[i
] = (GLushort
) source
[i
];
4396 if (dstPacking
->SwapBytes
) {
4397 _mesa_swap2( (GLushort
*) dst
, n
);
4403 GLshort
*dst
= (GLshort
*) dest
;
4406 dst
[i
] = (GLshort
) source
[i
];
4408 if (dstPacking
->SwapBytes
) {
4409 _mesa_swap2( (GLushort
*) dst
, n
);
4413 case GL_UNSIGNED_INT
:
4415 GLuint
*dst
= (GLuint
*) dest
;
4418 dst
[i
] = (GLuint
) source
[i
];
4420 if (dstPacking
->SwapBytes
) {
4421 _mesa_swap4( (GLuint
*) dst
, n
);
4427 GLint
*dst
= (GLint
*) dest
;
4430 dst
[i
] = (GLint
) source
[i
];
4432 if (dstPacking
->SwapBytes
) {
4433 _mesa_swap4( (GLuint
*) dst
, n
);
4439 GLfloat
*dst
= (GLfloat
*) dest
;
4442 dst
[i
] = (GLfloat
) source
[i
];
4444 if (dstPacking
->SwapBytes
) {
4445 _mesa_swap4( (GLuint
*) dst
, n
);
4449 case GL_HALF_FLOAT_ARB
:
4451 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4454 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
4456 if (dstPacking
->SwapBytes
) {
4457 _mesa_swap2( (GLushort
*) dst
, n
);
4462 if (dstPacking
->LsbFirst
) {
4463 GLubyte
*dst
= (GLubyte
*) dest
;
4466 for (i
= 0; i
< n
; i
++) {
4469 *dst
|= ((source
[i
] != 0) << shift
);
4478 GLubyte
*dst
= (GLubyte
*) dest
;
4481 for (i
= 0; i
< n
; i
++) {
4484 *dst
|= ((source
[i
] != 0) << shift
);
4494 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4498 #define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT) \
4501 const GLTYPE *src = (const GLTYPE *)source; \
4502 for (i = 0; i < n; i++) { \
4503 GLTYPE value = src[i]; \
4504 if (srcPacking->SwapBytes) { \
4505 if (sizeof(GLTYPE) == 2) { \
4507 } else if (sizeof(GLTYPE) == 4) { \
4511 depthValues[i] = GLTYPE2FLOAT(value); \
4517 * Unpack a row of depth/z values from memory, returning GLushort, GLuint
4518 * or GLfloat values.
4519 * The glPixelTransfer (scale/bias) params will be applied.
4521 * \param dstType one of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT
4522 * \param depthMax max value for returned GLushort or GLuint values
4523 * (ignored for GLfloat).
4526 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
,
4527 GLenum dstType
, GLvoid
*dest
, GLuint depthMax
,
4528 GLenum srcType
, const GLvoid
*source
,
4529 const struct gl_pixelstore_attrib
*srcPacking
)
4531 GLfloat depthTemp
[MAX_WIDTH
], *depthValues
;
4532 GLboolean needClamp
= GL_FALSE
;
4534 /* Look for special cases first.
4535 * Not only are these faster, they're less prone to numeric conversion
4536 * problems. Otherwise, converting from an int type to a float then
4537 * back to an int type can introduce errors that will show up as
4538 * artifacts in things like depth peeling which uses glCopyTexImage.
4540 if (ctx
->Pixel
.DepthScale
== 1.0 && ctx
->Pixel
.DepthBias
== 0.0) {
4541 if (srcType
== GL_UNSIGNED_INT
&& dstType
== GL_UNSIGNED_SHORT
) {
4542 const GLuint
*src
= (const GLuint
*) source
;
4543 GLushort
*dst
= (GLushort
*) dest
;
4545 for (i
= 0; i
< n
; i
++) {
4546 dst
[i
] = src
[i
] >> 16;
4550 if (srcType
== GL_UNSIGNED_SHORT
4551 && dstType
== GL_UNSIGNED_INT
4552 && depthMax
== 0xffffffff) {
4553 const GLushort
*src
= (const GLushort
*) source
;
4554 GLuint
*dst
= (GLuint
*) dest
;
4556 for (i
= 0; i
< n
; i
++) {
4557 dst
[i
] = src
[i
] | (src
[i
] << 16);
4561 if (srcType
== GL_UNSIGNED_INT_24_8
4562 && dstType
== GL_UNSIGNED_INT
4563 && depthMax
== 0xffffff) {
4564 const GLuint
*src
= (const GLuint
*) source
;
4565 GLuint
*dst
= (GLuint
*) dest
;
4567 for (i
= 0; i
< n
; i
++) {
4568 dst
[i
] = src
[i
] >> 8;
4572 /* XXX may want to add additional cases here someday */
4575 /* general case path follows */
4577 if (dstType
== GL_FLOAT
) {
4578 depthValues
= (GLfloat
*) dest
;
4581 depthValues
= depthTemp
;
4584 /* Convert incoming values to GLfloat. Some conversions will require
4589 DEPTH_VALUES(GLbyte
, BYTE_TO_FLOAT
);
4590 needClamp
= GL_TRUE
;
4592 case GL_UNSIGNED_BYTE
:
4593 DEPTH_VALUES(GLubyte
, UBYTE_TO_FLOAT
);
4596 DEPTH_VALUES(GLshort
, SHORT_TO_FLOAT
);
4597 needClamp
= GL_TRUE
;
4599 case GL_UNSIGNED_SHORT
:
4600 DEPTH_VALUES(GLushort
, USHORT_TO_FLOAT
);
4603 DEPTH_VALUES(GLint
, INT_TO_FLOAT
);
4604 needClamp
= GL_TRUE
;
4606 case GL_UNSIGNED_INT
:
4607 DEPTH_VALUES(GLuint
, UINT_TO_FLOAT
);
4609 case GL_UNSIGNED_INT_24_8_EXT
: /* GL_EXT_packed_depth_stencil */
4610 if (dstType
== GL_UNSIGNED_INT_24_8_EXT
&&
4611 depthMax
== 0xffffff &&
4612 ctx
->Pixel
.DepthScale
== 1.0 &&
4613 ctx
->Pixel
.DepthBias
== 0.0) {
4614 const GLuint
*src
= (const GLuint
*) source
;
4615 GLuint
*zValues
= (GLuint
*) dest
;
4617 for (i
= 0; i
< n
; i
++) {
4618 GLuint value
= src
[i
];
4619 if (srcPacking
->SwapBytes
) {
4622 zValues
[i
] = value
& 0xffffff00;
4627 const GLuint
*src
= (const GLuint
*) source
;
4628 const GLfloat scale
= 1.0f
/ 0xffffff;
4630 for (i
= 0; i
< n
; i
++) {
4631 GLuint value
= src
[i
];
4632 if (srcPacking
->SwapBytes
) {
4635 depthValues
[i
] = (value
>> 8) * scale
;
4640 DEPTH_VALUES(GLfloat
, 1*);
4641 needClamp
= GL_TRUE
;
4643 case GL_HALF_FLOAT_ARB
:
4646 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
4647 for (i
= 0; i
< n
; i
++) {
4648 GLhalfARB value
= src
[i
];
4649 if (srcPacking
->SwapBytes
) {
4652 depthValues
[i
] = _mesa_half_to_float(value
);
4654 needClamp
= GL_TRUE
;
4658 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
4662 /* apply depth scale and bias */
4664 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
4665 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
4666 if (scale
!= 1.0 || bias
!= 0.0) {
4668 for (i
= 0; i
< n
; i
++) {
4669 depthValues
[i
] = depthValues
[i
] * scale
+ bias
;
4671 needClamp
= GL_TRUE
;
4675 /* clamp to [0, 1] */
4678 for (i
= 0; i
< n
; i
++) {
4679 depthValues
[i
] = (GLfloat
)CLAMP(depthValues
[i
], 0.0, 1.0);
4684 * Convert values to dstType
4686 if (dstType
== GL_UNSIGNED_INT
) {
4687 GLuint
*zValues
= (GLuint
*) dest
;
4689 if (depthMax
<= 0xffffff) {
4690 /* no overflow worries */
4691 for (i
= 0; i
< n
; i
++) {
4692 zValues
[i
] = (GLuint
) (depthValues
[i
] * (GLfloat
) depthMax
);
4696 /* need to use double precision to prevent overflow problems */
4697 for (i
= 0; i
< n
; i
++) {
4698 GLdouble z
= depthValues
[i
] * (GLfloat
) depthMax
;
4699 if (z
>= (GLdouble
) 0xffffffff)
4700 zValues
[i
] = 0xffffffff;
4702 zValues
[i
] = (GLuint
) z
;
4706 else if (dstType
== GL_UNSIGNED_SHORT
) {
4707 GLushort
*zValues
= (GLushort
*) dest
;
4709 ASSERT(depthMax
<= 0xffff);
4710 for (i
= 0; i
< n
; i
++) {
4711 zValues
[i
] = (GLushort
) (depthValues
[i
] * (GLfloat
) depthMax
);
4715 ASSERT(dstType
== GL_FLOAT
);
4716 /*ASSERT(depthMax == 1.0F);*/
4722 * Pack an array of depth values. The values are floats in [0,1].
4725 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
4726 GLenum dstType
, const GLfloat
*depthSpan
,
4727 const struct gl_pixelstore_attrib
*dstPacking
)
4729 GLfloat depthCopy
[MAX_WIDTH
];
4731 ASSERT(n
<= MAX_WIDTH
);
4733 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4734 _mesa_memcpy(depthCopy
, depthSpan
, n
* sizeof(GLfloat
));
4735 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4736 depthSpan
= depthCopy
;
4740 case GL_UNSIGNED_BYTE
:
4742 GLubyte
*dst
= (GLubyte
*) dest
;
4744 for (i
= 0; i
< n
; i
++) {
4745 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
4751 GLbyte
*dst
= (GLbyte
*) dest
;
4753 for (i
= 0; i
< n
; i
++) {
4754 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
4758 case GL_UNSIGNED_SHORT
:
4760 GLushort
*dst
= (GLushort
*) dest
;
4762 for (i
= 0; i
< n
; i
++) {
4763 CLAMPED_FLOAT_TO_USHORT(dst
[i
], depthSpan
[i
]);
4765 if (dstPacking
->SwapBytes
) {
4766 _mesa_swap2( (GLushort
*) dst
, n
);
4772 GLshort
*dst
= (GLshort
*) dest
;
4774 for (i
= 0; i
< n
; i
++) {
4775 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
4777 if (dstPacking
->SwapBytes
) {
4778 _mesa_swap2( (GLushort
*) dst
, n
);
4782 case GL_UNSIGNED_INT
:
4784 GLuint
*dst
= (GLuint
*) dest
;
4786 for (i
= 0; i
< n
; i
++) {
4787 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
4789 if (dstPacking
->SwapBytes
) {
4790 _mesa_swap4( (GLuint
*) dst
, n
);
4796 GLint
*dst
= (GLint
*) dest
;
4798 for (i
= 0; i
< n
; i
++) {
4799 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
4801 if (dstPacking
->SwapBytes
) {
4802 _mesa_swap4( (GLuint
*) dst
, n
);
4808 GLfloat
*dst
= (GLfloat
*) dest
;
4810 for (i
= 0; i
< n
; i
++) {
4811 dst
[i
] = depthSpan
[i
];
4813 if (dstPacking
->SwapBytes
) {
4814 _mesa_swap4( (GLuint
*) dst
, n
);
4818 case GL_HALF_FLOAT_ARB
:
4820 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4822 for (i
= 0; i
< n
; i
++) {
4823 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
4825 if (dstPacking
->SwapBytes
) {
4826 _mesa_swap2( (GLushort
*) dst
, n
);
4831 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
4838 * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
4841 _mesa_pack_depth_stencil_span(const GLcontext
*ctx
, GLuint n
, GLuint
*dest
,
4842 const GLfloat
*depthVals
,
4843 const GLstencil
*stencilVals
,
4844 const struct gl_pixelstore_attrib
*dstPacking
)
4846 GLfloat depthCopy
[MAX_WIDTH
];
4847 GLstencil stencilCopy
[MAX_WIDTH
];
4850 ASSERT(n
<= MAX_WIDTH
);
4852 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4853 _mesa_memcpy(depthCopy
, depthVals
, n
* sizeof(GLfloat
));
4854 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4855 depthVals
= depthCopy
;
4858 if (ctx
->Pixel
.IndexShift
||
4859 ctx
->Pixel
.IndexOffset
||
4860 ctx
->Pixel
.MapStencilFlag
) {
4861 _mesa_memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
4862 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencilCopy
);
4863 stencilVals
= stencilCopy
;
4866 for (i
= 0; i
< n
; i
++) {
4867 GLuint z
= (GLuint
) (depthVals
[i
] * 0xffffff);
4868 dest
[i
] = (z
<< 8) | (stencilVals
[i
] & 0xff);
4871 if (dstPacking
->SwapBytes
) {
4872 _mesa_swap4(dest
, n
);
4880 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
4881 * Return all image data in a contiguous block. This is used when we
4882 * compile glDrawPixels, glTexImage, etc into a display list. We
4883 * need a copy of the data in a standard format.
4886 _mesa_unpack_image( GLuint dimensions
,
4887 GLsizei width
, GLsizei height
, GLsizei depth
,
4888 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4889 const struct gl_pixelstore_attrib
*unpack
)
4891 GLint bytesPerRow
, compsPerRow
;
4892 GLboolean flipBytes
, swap2
, swap4
;
4895 return NULL
; /* not necessarily an error */
4897 if (width
<= 0 || height
<= 0 || depth
<= 0)
4898 return NULL
; /* generate error later */
4900 if (type
== GL_BITMAP
) {
4901 bytesPerRow
= (width
+ 7) >> 3;
4902 flipBytes
= unpack
->LsbFirst
;
4903 swap2
= swap4
= GL_FALSE
;
4907 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
4908 GLint components
= _mesa_components_in_format(format
);
4911 if (_mesa_type_is_packed(type
))
4914 if (bytesPerPixel
<= 0 || components
<= 0)
4915 return NULL
; /* bad format or type. generate error later */
4916 bytesPerRow
= bytesPerPixel
* width
;
4917 bytesPerComp
= bytesPerPixel
/ components
;
4918 flipBytes
= GL_FALSE
;
4919 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
4920 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
4921 compsPerRow
= components
* width
;
4922 assert(compsPerRow
>= width
);
4927 = (GLubyte
*) _mesa_malloc(bytesPerRow
* height
* depth
);
4931 return NULL
; /* generate GL_OUT_OF_MEMORY later */
4934 for (img
= 0; img
< depth
; img
++) {
4935 for (row
= 0; row
< height
; row
++) {
4936 const GLvoid
*src
= _mesa_image_address(dimensions
, unpack
, pixels
,
4937 width
, height
, format
, type
, img
, row
, 0);
4939 if ((type
== GL_BITMAP
) && (unpack
->SkipPixels
& 0x7)) {
4941 flipBytes
= GL_FALSE
;
4942 if (unpack
->LsbFirst
) {
4943 GLubyte srcMask
= 1 << (unpack
->SkipPixels
& 0x7);
4944 GLubyte dstMask
= 128;
4945 const GLubyte
*s
= src
;
4948 for (i
= 0; i
< width
; i
++) {
4952 if (srcMask
== 128) {
4957 srcMask
= srcMask
<< 1;
4965 dstMask
= dstMask
>> 1;
4970 GLubyte srcMask
= 128 >> (unpack
->SkipPixels
& 0x7);
4971 GLubyte dstMask
= 128;
4972 const GLubyte
*s
= src
;
4975 for (i
= 0; i
< width
; i
++) {
4984 srcMask
= srcMask
>> 1;
4992 dstMask
= dstMask
>> 1;
4998 _mesa_memcpy(dst
, src
, bytesPerRow
);
5001 /* byte flipping/swapping */
5003 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
5006 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
5009 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
5018 #endif /* _HAVE_FULL_GL */
5023 * Convert an array of RGBA colors from one datatype to another.
5024 * NOTE: src may equal dst. In that case, we use a temporary buffer.
5027 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
5028 GLenum dstType
, GLvoid
*dst
,
5029 GLuint count
, const GLubyte mask
[])
5031 GLuint tempBuffer
[MAX_WIDTH
][4];
5032 const GLboolean useTemp
= (src
== dst
);
5034 ASSERT(srcType
!= dstType
);
5037 case GL_UNSIGNED_BYTE
:
5038 if (dstType
== GL_UNSIGNED_SHORT
) {
5039 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5040 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5042 for (i
= 0; i
< count
; i
++) {
5043 if (!mask
|| mask
[i
]) {
5044 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
5045 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
5046 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
5047 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
5051 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5054 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5055 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5057 ASSERT(dstType
== GL_FLOAT
);
5058 for (i
= 0; i
< count
; i
++) {
5059 if (!mask
|| mask
[i
]) {
5060 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
5061 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
5062 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
5063 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
5067 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5070 case GL_UNSIGNED_SHORT
:
5071 if (dstType
== GL_UNSIGNED_BYTE
) {
5072 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5073 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5075 for (i
= 0; i
< count
; i
++) {
5076 if (!mask
|| mask
[i
]) {
5077 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
5078 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
5079 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
5080 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
5084 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5087 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5088 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5090 ASSERT(dstType
== GL_FLOAT
);
5091 for (i
= 0; i
< count
; i
++) {
5092 if (!mask
|| mask
[i
]) {
5093 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
5094 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
5095 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
5096 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
5100 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5104 if (dstType
== GL_UNSIGNED_BYTE
) {
5105 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5106 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5108 for (i
= 0; i
< count
; i
++) {
5109 if (!mask
|| mask
[i
]) {
5110 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
5111 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
5112 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
5113 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
5117 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5120 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5121 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5123 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
5124 for (i
= 0; i
< count
; i
++) {
5125 if (!mask
|| mask
[i
]) {
5126 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
5127 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
5128 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
5129 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
5133 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5137 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
5145 * Perform basic clipping for glDrawPixels. The image's position and size
5146 * and the unpack SkipPixels and SkipRows are adjusted so that the image
5147 * region is entirely within the window and scissor bounds.
5148 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
5149 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
5150 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
5152 * \return GL_TRUE if image is ready for drawing or
5153 * GL_FALSE if image was completely clipped away (draw nothing)
5156 _mesa_clip_drawpixels(const GLcontext
*ctx
,
5157 GLint
*destX
, GLint
*destY
,
5158 GLsizei
*width
, GLsizei
*height
,
5159 struct gl_pixelstore_attrib
*unpack
)
5161 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
5163 if (unpack
->RowLength
== 0) {
5164 unpack
->RowLength
= *width
;
5167 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
5168 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
5171 if (*destX
< buffer
->_Xmin
) {
5172 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
5173 *width
-= (buffer
->_Xmin
- *destX
);
5174 *destX
= buffer
->_Xmin
;
5176 /* right clipping */
5177 if (*destX
+ *width
> buffer
->_Xmax
)
5178 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
5183 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
5184 /* bottom clipping */
5185 if (*destY
< buffer
->_Ymin
) {
5186 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
5187 *height
-= (buffer
->_Ymin
- *destY
);
5188 *destY
= buffer
->_Ymin
;
5191 if (*destY
+ *height
> buffer
->_Ymax
)
5192 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
5194 else { /* upside down */
5196 if (*destY
> buffer
->_Ymax
) {
5197 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
5198 *height
-= (*destY
- buffer
->_Ymax
);
5199 *destY
= buffer
->_Ymax
;
5201 /* bottom clipping */
5202 if (*destY
- *height
< buffer
->_Ymin
)
5203 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
5204 /* adjust destY so it's the first row to write to */
5216 * Perform clipping for glReadPixels. The image's window position
5217 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
5218 * so that the image region is entirely within the window bounds.
5219 * Note: this is different from _mesa_clip_drawpixels() in that the
5220 * scissor box is ignored, and we use the bounds of the current readbuffer
5223 * \return GL_TRUE if image is ready for drawing or
5224 * GL_FALSE if image was completely clipped away (draw nothing)
5227 _mesa_clip_readpixels(const GLcontext
*ctx
,
5228 GLint
*srcX
, GLint
*srcY
,
5229 GLsizei
*width
, GLsizei
*height
,
5230 struct gl_pixelstore_attrib
*pack
)
5232 const GLframebuffer
*buffer
= ctx
->ReadBuffer
;
5234 if (pack
->RowLength
== 0) {
5235 pack
->RowLength
= *width
;
5240 pack
->SkipPixels
+= (0 - *srcX
);
5241 *width
-= (0 - *srcX
);
5244 /* right clipping */
5245 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
5246 *width
-= (*srcX
+ *width
- buffer
->Width
);
5251 /* bottom clipping */
5253 pack
->SkipRows
+= (0 - *srcY
);
5254 *height
-= (0 - *srcY
);
5258 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
5259 *height
-= (*srcY
+ *height
- buffer
->Height
);
5269 * Do clipping for a glCopyTexSubImage call.
5270 * The framebuffer source region might extend outside the framebuffer
5271 * bounds. Clip the source region against the framebuffer bounds and
5272 * adjust the texture/dest position and size accordingly.
5274 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
5277 _mesa_clip_copytexsubimage(const GLcontext
*ctx
,
5278 GLint
*destX
, GLint
*destY
,
5279 GLint
*srcX
, GLint
*srcY
,
5280 GLsizei
*width
, GLsizei
*height
)
5282 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
5283 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
5285 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
5286 srcX
, srcY
, width
, height
)) {
5287 *destX
= *destX
+ *srcX
- srcX0
;
5288 *destY
= *destY
+ *srcY
- srcY0
;
5300 * Clip the rectangle defined by (x, y, width, height) against the bounds
5301 * specified by [xmin, xmax) and [ymin, ymax).
5302 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
5305 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
5306 GLint xmax
, GLint ymax
,
5308 GLsizei
*width
, GLsizei
*height
)
5312 *width
-= (xmin
- *x
);
5316 /* right clipping */
5317 if (*x
+ *width
> xmax
)
5318 *width
-= (*x
+ *width
- xmax
);
5323 /* bottom (or top) clipping */
5325 *height
-= (ymin
- *y
);
5329 /* top (or bottom) clipping */
5330 if (*y
+ *height
> ymax
)
5331 *height
-= (*y
+ *height
- ymax
);