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.
43 * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
44 * we later convert the float to a packed integer value (such as for
45 * GL_RGB5_A1) because we'll wind up with a non-zero value.
47 * We redefine the macros here so zero is handled correctly.
50 #define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
53 #define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
57 /** Compute ceiling of integer quotient of A divided by B. */
58 #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
62 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
65 _mesa_type_is_packed(GLenum type
)
68 case GL_UNSIGNED_BYTE_3_3_2
:
69 case GL_UNSIGNED_BYTE_2_3_3_REV
:
70 case GL_UNSIGNED_SHORT_5_6_5
:
71 case GL_UNSIGNED_SHORT_5_6_5_REV
:
72 case GL_UNSIGNED_SHORT_4_4_4_4
:
73 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
74 case GL_UNSIGNED_SHORT_5_5_5_1
:
75 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
76 case GL_UNSIGNED_INT_8_8_8_8
:
77 case GL_UNSIGNED_INT_8_8_8_8_REV
:
78 case GL_UNSIGNED_INT_10_10_10_2
:
79 case GL_UNSIGNED_INT_2_10_10_10_REV
:
80 case GL_UNSIGNED_SHORT_8_8_MESA
:
81 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
82 case GL_UNSIGNED_INT_24_8_EXT
:
90 * Flip the 8 bits in each byte of the given array.
93 * \param n number of bytes.
95 * \todo try this trick to flip bytes someday:
97 * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555);
98 * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333);
99 * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f);
103 flip_bytes( GLubyte
*p
, GLuint n
)
106 for (i
= 0; i
< n
; i
++) {
107 b
= (GLuint
) p
[i
]; /* words are often faster than bytes */
108 a
= ((b
& 0x01) << 7) |
122 * Flip the order of the 2 bytes in each word in the given array.
125 * \param n number of words.
128 _mesa_swap2( GLushort
*p
, GLuint n
)
131 for (i
= 0; i
< n
; i
++) {
132 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
139 * Flip the order of the 4 bytes in each word in the given array.
142 _mesa_swap4( GLuint
*p
, GLuint n
)
145 for (i
= 0; i
< n
; i
++) {
148 | ((b
>> 8) & 0xff00)
149 | ((b
<< 8) & 0xff0000)
150 | ((b
<< 24) & 0xff000000);
157 * Get the size of a GL data type.
159 * \param type GL data type.
161 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
162 * if an invalid type enum.
165 _mesa_sizeof_type( GLenum type
)
170 case GL_UNSIGNED_BYTE
:
171 return sizeof(GLubyte
);
173 return sizeof(GLbyte
);
174 case GL_UNSIGNED_SHORT
:
175 return sizeof(GLushort
);
177 return sizeof(GLshort
);
178 case GL_UNSIGNED_INT
:
179 return sizeof(GLuint
);
181 return sizeof(GLint
);
183 return sizeof(GLfloat
);
185 return sizeof(GLdouble
);
186 case GL_HALF_FLOAT_ARB
:
187 return sizeof(GLhalfARB
);
195 * Same as _mesa_sizeof_type() but also accepting the packed pixel
199 _mesa_sizeof_packed_type( GLenum type
)
204 case GL_UNSIGNED_BYTE
:
205 return sizeof(GLubyte
);
207 return sizeof(GLbyte
);
208 case GL_UNSIGNED_SHORT
:
209 return sizeof(GLushort
);
211 return sizeof(GLshort
);
212 case GL_UNSIGNED_INT
:
213 return sizeof(GLuint
);
215 return sizeof(GLint
);
216 case GL_HALF_FLOAT_ARB
:
217 return sizeof(GLhalfARB
);
219 return sizeof(GLfloat
);
220 case GL_UNSIGNED_BYTE_3_3_2
:
221 return sizeof(GLubyte
);
222 case GL_UNSIGNED_BYTE_2_3_3_REV
:
223 return sizeof(GLubyte
);
224 case GL_UNSIGNED_SHORT_5_6_5
:
225 return sizeof(GLushort
);
226 case GL_UNSIGNED_SHORT_5_6_5_REV
:
227 return sizeof(GLushort
);
228 case GL_UNSIGNED_SHORT_4_4_4_4
:
229 return sizeof(GLushort
);
230 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
231 return sizeof(GLushort
);
232 case GL_UNSIGNED_SHORT_5_5_5_1
:
233 return sizeof(GLushort
);
234 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
235 return sizeof(GLushort
);
236 case GL_UNSIGNED_INT_8_8_8_8
:
237 return sizeof(GLuint
);
238 case GL_UNSIGNED_INT_8_8_8_8_REV
:
239 return sizeof(GLuint
);
240 case GL_UNSIGNED_INT_10_10_10_2
:
241 return sizeof(GLuint
);
242 case GL_UNSIGNED_INT_2_10_10_10_REV
:
243 return sizeof(GLuint
);
244 case GL_UNSIGNED_SHORT_8_8_MESA
:
245 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
246 return sizeof(GLushort
);
247 case GL_UNSIGNED_INT_24_8_EXT
:
248 return sizeof(GLuint
);
256 * Get the number of components in a pixel format.
258 * \param format pixel format.
260 * \return the number of components in the given format, or -1 if a bad format.
263 _mesa_components_in_format( GLenum format
)
267 case GL_COLOR_INDEX1_EXT
:
268 case GL_COLOR_INDEX2_EXT
:
269 case GL_COLOR_INDEX4_EXT
:
270 case GL_COLOR_INDEX8_EXT
:
271 case GL_COLOR_INDEX12_EXT
:
272 case GL_COLOR_INDEX16_EXT
:
273 case GL_STENCIL_INDEX
:
274 case GL_DEPTH_COMPONENT
:
282 case GL_LUMINANCE_ALPHA
:
296 case GL_DEPTH_STENCIL_EXT
:
308 * Get the bytes per pixel of pixel format type pair.
310 * \param format pixel format.
311 * \param type pixel type.
313 * \return bytes per pixel, or -1 if a bad format or type was given.
316 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
318 GLint comps
= _mesa_components_in_format( format
);
324 return 0; /* special case */
326 case GL_UNSIGNED_BYTE
:
327 return comps
* sizeof(GLubyte
);
329 case GL_UNSIGNED_SHORT
:
330 return comps
* sizeof(GLshort
);
332 case GL_UNSIGNED_INT
:
333 return comps
* sizeof(GLint
);
335 return comps
* sizeof(GLfloat
);
336 case GL_HALF_FLOAT_ARB
:
337 return comps
* sizeof(GLhalfARB
);
338 case GL_UNSIGNED_BYTE_3_3_2
:
339 case GL_UNSIGNED_BYTE_2_3_3_REV
:
340 if (format
== GL_RGB
|| format
== GL_BGR
)
341 return sizeof(GLubyte
);
343 return -1; /* error */
344 case GL_UNSIGNED_SHORT_5_6_5
:
345 case GL_UNSIGNED_SHORT_5_6_5_REV
:
346 if (format
== GL_RGB
|| format
== GL_BGR
)
347 return sizeof(GLushort
);
349 return -1; /* error */
350 case GL_UNSIGNED_SHORT_4_4_4_4
:
351 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
352 case GL_UNSIGNED_SHORT_5_5_5_1
:
353 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
354 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
355 return sizeof(GLushort
);
358 case GL_UNSIGNED_INT_8_8_8_8
:
359 case GL_UNSIGNED_INT_8_8_8_8_REV
:
360 case GL_UNSIGNED_INT_10_10_10_2
:
361 case GL_UNSIGNED_INT_2_10_10_10_REV
:
362 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
363 return sizeof(GLuint
);
366 case GL_UNSIGNED_SHORT_8_8_MESA
:
367 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
368 if (format
== GL_YCBCR_MESA
)
369 return sizeof(GLushort
);
372 case GL_UNSIGNED_INT_24_8_EXT
:
373 if (format
== GL_DEPTH_STENCIL_EXT
)
374 return sizeof(GLuint
);
384 * Test for a legal pixel format and type.
386 * \param format pixel format.
387 * \param type pixel type.
389 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
393 _mesa_is_legal_format_and_type( GLcontext
*ctx
, GLenum format
, GLenum type
)
397 case GL_STENCIL_INDEX
:
401 case GL_UNSIGNED_BYTE
:
403 case GL_UNSIGNED_SHORT
:
405 case GL_UNSIGNED_INT
:
408 case GL_HALF_FLOAT_ARB
:
409 return ctx
->Extensions
.ARB_half_float_pixel
;
417 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
421 case GL_LUMINANCE_ALPHA
:
422 case GL_DEPTH_COMPONENT
:
425 case GL_UNSIGNED_BYTE
:
427 case GL_UNSIGNED_SHORT
:
429 case GL_UNSIGNED_INT
:
432 case GL_HALF_FLOAT_ARB
:
433 return ctx
->Extensions
.ARB_half_float_pixel
;
440 case GL_UNSIGNED_BYTE
:
442 case GL_UNSIGNED_SHORT
:
444 case GL_UNSIGNED_INT
:
446 case GL_UNSIGNED_BYTE_3_3_2
:
447 case GL_UNSIGNED_BYTE_2_3_3_REV
:
448 case GL_UNSIGNED_SHORT_5_6_5
:
449 case GL_UNSIGNED_SHORT_5_6_5_REV
:
451 case GL_HALF_FLOAT_ARB
:
452 return ctx
->Extensions
.ARB_half_float_pixel
;
458 /* NOTE: no packed types are supported with BGR. That's
459 * intentional, according to the GL spec.
462 case GL_UNSIGNED_BYTE
:
464 case GL_UNSIGNED_SHORT
:
466 case GL_UNSIGNED_INT
:
469 case GL_HALF_FLOAT_ARB
:
470 return ctx
->Extensions
.ARB_half_float_pixel
;
479 case GL_UNSIGNED_BYTE
:
481 case GL_UNSIGNED_SHORT
:
483 case GL_UNSIGNED_INT
:
485 case GL_UNSIGNED_SHORT_4_4_4_4
:
486 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
487 case GL_UNSIGNED_SHORT_5_5_5_1
:
488 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
489 case GL_UNSIGNED_INT_8_8_8_8
:
490 case GL_UNSIGNED_INT_8_8_8_8_REV
:
491 case GL_UNSIGNED_INT_10_10_10_2
:
492 case GL_UNSIGNED_INT_2_10_10_10_REV
:
494 case GL_HALF_FLOAT_ARB
:
495 return ctx
->Extensions
.ARB_half_float_pixel
;
500 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
501 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
505 case GL_DEPTH_STENCIL_EXT
:
506 if (ctx
->Extensions
.EXT_packed_depth_stencil
507 && type
== GL_UNSIGNED_INT_24_8_EXT
)
515 case GL_UNSIGNED_BYTE
:
517 case GL_UNSIGNED_SHORT
:
519 case GL_UNSIGNED_INT
:
533 * Test if the given image format is a color/RGBA format (i.e., not color
534 * index, depth, stencil, etc).
535 * \param format the image format value (may by an internal texture format)
536 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
539 _mesa_is_color_format(GLenum format
)
557 case GL_LUMINANCE_ALPHA
:
558 case GL_LUMINANCE4_ALPHA4
:
559 case GL_LUMINANCE6_ALPHA2
:
560 case GL_LUMINANCE8_ALPHA8
:
561 case GL_LUMINANCE12_ALPHA4
:
562 case GL_LUMINANCE12_ALPHA12
:
563 case GL_LUMINANCE16_ALPHA16
:
590 /* float texture formats */
591 case GL_ALPHA16F_ARB
:
592 case GL_ALPHA32F_ARB
:
593 case GL_LUMINANCE16F_ARB
:
594 case GL_LUMINANCE32F_ARB
:
595 case GL_LUMINANCE_ALPHA16F_ARB
:
596 case GL_LUMINANCE_ALPHA32F_ARB
:
597 case GL_INTENSITY16F_ARB
:
598 case GL_INTENSITY32F_ARB
:
603 /* compressed formats */
604 case GL_COMPRESSED_ALPHA
:
605 case GL_COMPRESSED_LUMINANCE
:
606 case GL_COMPRESSED_LUMINANCE_ALPHA
:
607 case GL_COMPRESSED_INTENSITY
:
608 case GL_COMPRESSED_RGB
:
609 case GL_COMPRESSED_RGBA
:
614 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
615 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
616 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
617 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
618 case GL_COMPRESSED_RGB_FXT1_3DFX
:
619 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
620 #if FEATURE_EXT_texture_sRGB
623 case GL_SRGB_ALPHA_EXT
:
624 case GL_SRGB8_ALPHA8_EXT
:
625 case GL_SLUMINANCE_ALPHA_EXT
:
626 case GL_SLUMINANCE8_ALPHA8_EXT
:
627 case GL_SLUMINANCE_EXT
:
628 case GL_SLUMINANCE8_EXT
:
629 case GL_COMPRESSED_SRGB_EXT
:
630 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
631 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
632 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
633 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
634 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
635 case GL_COMPRESSED_SLUMINANCE_EXT
:
636 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
637 #endif /* FEATURE_EXT_texture_sRGB */
639 /* signed texture formats */
643 case GL_YCBCR_MESA
: /* not considered to be RGB */
652 * Test if the given image format is a color index format.
655 _mesa_is_index_format(GLenum format
)
659 case GL_COLOR_INDEX1_EXT
:
660 case GL_COLOR_INDEX2_EXT
:
661 case GL_COLOR_INDEX4_EXT
:
662 case GL_COLOR_INDEX8_EXT
:
663 case GL_COLOR_INDEX12_EXT
:
664 case GL_COLOR_INDEX16_EXT
:
673 * Test if the given image format is a depth component format.
676 _mesa_is_depth_format(GLenum format
)
679 case GL_DEPTH_COMPONENT
:
680 case GL_DEPTH_COMPONENT16
:
681 case GL_DEPTH_COMPONENT24
:
682 case GL_DEPTH_COMPONENT32
:
691 * Test if the given image format is a stencil format.
694 _mesa_is_stencil_format(GLenum format
)
697 case GL_STENCIL_INDEX
:
698 case GL_DEPTH_STENCIL
:
707 * Test if the given image format is a YCbCr format.
710 _mesa_is_ycbcr_format(GLenum format
)
722 * Test if the given image format is a depth+stencil format.
725 _mesa_is_depthstencil_format(GLenum format
)
728 case GL_DEPTH24_STENCIL8_EXT
:
729 case GL_DEPTH_STENCIL_EXT
:
737 * Test if the given image format is a dudv format.
740 _mesa_is_dudv_format(GLenum format
)
753 * Return the address of a specific pixel in an image (1D, 2D or 3D).
755 * Pixel unpacking/packing parameters are observed according to \p packing.
757 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
758 * \param image starting address of image data
759 * \param width the image width
760 * \param height theimage height
761 * \param format the pixel format
762 * \param type the pixel data type
763 * \param packing the pixelstore attributes
764 * \param img which image in the volume (0 for 1D or 2D images)
765 * \param row row of pixel in the image (0 for 1D images)
766 * \param column column of pixel in the image
768 * \return address of pixel on success, or NULL on error.
770 * \sa gl_pixelstore_attrib.
773 _mesa_image_address( GLuint dimensions
,
774 const struct gl_pixelstore_attrib
*packing
,
776 GLsizei width
, GLsizei height
,
777 GLenum format
, GLenum type
,
778 GLint img
, GLint row
, GLint column
)
780 GLint alignment
; /* 1, 2 or 4 */
781 GLint pixels_per_row
;
782 GLint rows_per_image
;
785 GLint skipimages
; /* for 3-D volume images */
788 ASSERT(dimensions
>= 1 && dimensions
<= 3);
790 alignment
= packing
->Alignment
;
791 if (packing
->RowLength
> 0) {
792 pixels_per_row
= packing
->RowLength
;
795 pixels_per_row
= width
;
797 if (packing
->ImageHeight
> 0) {
798 rows_per_image
= packing
->ImageHeight
;
801 rows_per_image
= height
;
804 skippixels
= packing
->SkipPixels
;
805 /* Note: SKIP_ROWS _is_ used for 1D images */
806 skiprows
= packing
->SkipRows
;
807 /* Note: SKIP_IMAGES is only used for 3D images */
808 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
810 if (type
== GL_BITMAP
) {
812 GLint comp_per_pixel
; /* components per pixel */
813 GLint bytes_per_comp
; /* bytes per component */
815 GLint bytes_per_image
;
817 /* Compute bytes per component */
818 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
819 if (bytes_per_comp
< 0) {
823 /* Compute number of components per pixel */
824 comp_per_pixel
= _mesa_components_in_format( format
);
825 if (comp_per_pixel
< 0) {
829 bytes_per_row
= alignment
830 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
832 bytes_per_image
= bytes_per_row
* rows_per_image
;
834 pixel_addr
= (GLubyte
*) image
835 + (skipimages
+ img
) * bytes_per_image
836 + (skiprows
+ row
) * bytes_per_row
837 + (skippixels
+ column
) / 8;
840 /* Non-BITMAP data */
841 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
844 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
846 /* The pixel type and format should have been error checked earlier */
847 assert(bytes_per_pixel
> 0);
849 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
850 remainder
= bytes_per_row
% alignment
;
852 bytes_per_row
+= (alignment
- remainder
);
854 ASSERT(bytes_per_row
% alignment
== 0);
856 bytes_per_image
= bytes_per_row
* rows_per_image
;
858 if (packing
->Invert
) {
859 /* set pixel_addr to the last row */
860 topOfImage
= bytes_per_row
* (height
- 1);
861 bytes_per_row
= -bytes_per_row
;
867 /* compute final pixel address */
868 pixel_addr
= (GLubyte
*) image
869 + (skipimages
+ img
) * bytes_per_image
871 + (skiprows
+ row
) * bytes_per_row
872 + (skippixels
+ column
) * bytes_per_pixel
;
875 return (GLvoid
*) pixel_addr
;
880 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
883 GLenum format
, GLenum type
,
886 return _mesa_image_address(1, packing
, image
, width
, 1,
887 format
, type
, 0, 0, column
);
892 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
894 GLsizei width
, GLsizei height
,
895 GLenum format
, GLenum type
,
896 GLint row
, GLint column
)
898 return _mesa_image_address(2, packing
, image
, width
, height
,
899 format
, type
, 0, row
, column
);
904 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
906 GLsizei width
, GLsizei height
,
907 GLenum format
, GLenum type
,
908 GLint img
, GLint row
, GLint column
)
910 return _mesa_image_address(3, packing
, image
, width
, height
,
911 format
, type
, img
, row
, column
);
917 * Compute the stride (in bytes) between image rows.
919 * \param packing the pixelstore attributes
920 * \param width image width.
921 * \param format pixel format.
922 * \param type pixel data type.
924 * \return the stride in bytes for the given parameters, or -1 if error
927 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
928 GLint width
, GLenum format
, GLenum type
)
930 GLint bytesPerRow
, remainder
;
934 if (type
== GL_BITMAP
) {
935 if (packing
->RowLength
== 0) {
936 bytesPerRow
= (width
+ 7) / 8;
939 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
943 /* Non-BITMAP data */
944 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
945 if (bytesPerPixel
<= 0)
946 return -1; /* error */
947 if (packing
->RowLength
== 0) {
948 bytesPerRow
= bytesPerPixel
* width
;
951 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
955 remainder
= bytesPerRow
% packing
->Alignment
;
957 bytesPerRow
+= (packing
->Alignment
- remainder
);
960 if (packing
->Invert
) {
961 /* negate the bytes per row (negative row stride) */
962 bytesPerRow
= -bytesPerRow
;
972 * Compute the stride between images in a 3D texture (in bytes) for the given
973 * pixel packing parameters and image width, format and type.
976 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
977 GLint width
, GLint height
,
978 GLenum format
, GLenum type
)
980 GLint bytesPerRow
, bytesPerImage
, remainder
;
984 if (type
== GL_BITMAP
) {
985 if (packing
->RowLength
== 0) {
986 bytesPerRow
= (width
+ 7) / 8;
989 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
993 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
995 if (bytesPerPixel
<= 0)
996 return -1; /* error */
997 if (packing
->RowLength
== 0) {
998 bytesPerRow
= bytesPerPixel
* width
;
1001 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1005 remainder
= bytesPerRow
% packing
->Alignment
;
1007 bytesPerRow
+= (packing
->Alignment
- remainder
);
1009 if (packing
->ImageHeight
== 0)
1010 bytesPerImage
= bytesPerRow
* height
;
1012 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
1014 return bytesPerImage
;
1019 * Unpack a 32x32 pixel polygon stipple from user memory using the
1020 * current pixel unpack settings.
1023 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
1024 const struct gl_pixelstore_attrib
*unpacking
)
1026 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap(32, 32, pattern
, unpacking
);
1028 /* Convert pattern from GLubytes to GLuints and handle big/little
1029 * endian differences
1033 for (i
= 0; i
< 32; i
++) {
1034 dest
[i
] = (p
[0] << 24)
1046 * Pack polygon stipple into user memory given current pixel packing
1050 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
1051 const struct gl_pixelstore_attrib
*packing
)
1053 /* Convert pattern from GLuints to GLubytes to handle big/little
1054 * endian differences.
1058 for (i
= 0; i
< 32; i
++) {
1059 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
1060 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
1061 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
1062 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
1065 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
1070 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
1071 * order with row alignment = 1 byte.
1074 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
1075 const struct gl_pixelstore_attrib
*packing
)
1077 GLint bytes
, row
, width_in_bytes
;
1078 GLubyte
*buffer
, *dst
;
1083 /* Alloc dest storage */
1084 bytes
= ((width
+ 7) / 8 * height
);
1085 buffer
= (GLubyte
*) _mesa_malloc( bytes
);
1089 width_in_bytes
= CEILING( width
, 8 );
1091 for (row
= 0; row
< height
; row
++) {
1092 const GLubyte
*src
= (const GLubyte
*)
1093 _mesa_image_address2d(packing
, pixels
, width
, height
,
1094 GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
1100 if ((packing
->SkipPixels
& 7) == 0) {
1101 _mesa_memcpy( dst
, src
, width_in_bytes
);
1102 if (packing
->LsbFirst
) {
1103 flip_bytes( dst
, width_in_bytes
);
1107 /* handling SkipPixels is a bit tricky (no pun intended!) */
1109 if (packing
->LsbFirst
) {
1110 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
1111 GLubyte dstMask
= 128;
1112 const GLubyte
*s
= src
;
1115 for (i
= 0; i
< width
; i
++) {
1119 if (srcMask
== 128) {
1124 srcMask
= srcMask
<< 1;
1132 dstMask
= dstMask
>> 1;
1137 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
1138 GLubyte dstMask
= 128;
1139 const GLubyte
*s
= src
;
1142 for (i
= 0; i
< width
; i
++) {
1151 srcMask
= srcMask
>> 1;
1159 dstMask
= dstMask
>> 1;
1164 dst
+= width_in_bytes
;
1175 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
1176 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
1178 GLint row
, width_in_bytes
;
1184 width_in_bytes
= CEILING( width
, 8 );
1186 for (row
= 0; row
< height
; row
++) {
1187 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dest
,
1188 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
1192 if ((packing
->SkipPixels
& 7) == 0) {
1193 _mesa_memcpy( dst
, src
, width_in_bytes
);
1194 if (packing
->LsbFirst
) {
1195 flip_bytes( dst
, width_in_bytes
);
1199 /* handling SkipPixels is a bit tricky (no pun intended!) */
1201 if (packing
->LsbFirst
) {
1202 GLubyte srcMask
= 128;
1203 GLubyte dstMask
= 1 << (packing
->SkipPixels
& 0x7);
1204 const GLubyte
*s
= src
;
1207 for (i
= 0; i
< width
; i
++) {
1216 srcMask
= srcMask
>> 1;
1218 if (dstMask
== 128) {
1224 dstMask
= dstMask
<< 1;
1229 GLubyte srcMask
= 128;
1230 GLubyte dstMask
= 128 >> (packing
->SkipPixels
& 0x7);
1231 const GLubyte
*s
= src
;
1234 for (i
= 0; i
< width
; i
++) {
1243 srcMask
= srcMask
>> 1;
1251 dstMask
= dstMask
>> 1;
1256 src
+= width_in_bytes
;
1262 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1263 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1264 * "On" bits will set texels to \p onValue.
1265 * "Off" bits will not modify texels.
1266 * \param width src bitmap width in pixels
1267 * \param height src bitmap height in pixels
1268 * \param unpack bitmap unpacking state
1269 * \param bitmap the src bitmap data
1270 * \param destBuffer start of dest buffer
1271 * \param destStride row stride in dest buffer
1272 * \param onValue if bit is 1, set destBuffer pixel to this value
1275 _mesa_expand_bitmap(GLsizei width
, GLsizei height
,
1276 const struct gl_pixelstore_attrib
*unpack
,
1277 const GLubyte
*bitmap
,
1278 GLubyte
*destBuffer
, GLint destStride
,
1281 const GLubyte
*srcRow
= (const GLubyte
*)
1282 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
1283 GL_COLOR_INDEX
, GL_BITMAP
, 0, 0);
1284 const GLint srcStride
= _mesa_image_row_stride(unpack
, width
,
1285 GL_COLOR_INDEX
, GL_BITMAP
);
1288 #define SET_PIXEL(COL, ROW) \
1289 destBuffer[(ROW) * destStride + (COL)] = onValue;
1291 for (row
= 0; row
< height
; row
++) {
1292 const GLubyte
*src
= srcRow
;
1294 if (unpack
->LsbFirst
) {
1296 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
1297 for (col
= 0; col
< width
; col
++) {
1300 SET_PIXEL(col
, row
);
1312 /* get ready for next row */
1318 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
1319 for (col
= 0; col
< width
; col
++) {
1322 SET_PIXEL(col
, row
);
1334 /* get ready for next row */
1339 srcRow
+= srcStride
;
1346 /**********************************************************************/
1347 /***** Pixel processing functions ******/
1348 /**********************************************************************/
1351 * Apply scale and bias factors to an array of RGBA pixels.
1354 _mesa_scale_and_bias_rgba(GLuint n
, GLfloat rgba
[][4],
1355 GLfloat rScale
, GLfloat gScale
,
1356 GLfloat bScale
, GLfloat aScale
,
1357 GLfloat rBias
, GLfloat gBias
,
1358 GLfloat bBias
, GLfloat aBias
)
1360 if (rScale
!= 1.0 || rBias
!= 0.0) {
1362 for (i
= 0; i
< n
; i
++) {
1363 rgba
[i
][RCOMP
] = rgba
[i
][RCOMP
] * rScale
+ rBias
;
1366 if (gScale
!= 1.0 || gBias
!= 0.0) {
1368 for (i
= 0; i
< n
; i
++) {
1369 rgba
[i
][GCOMP
] = rgba
[i
][GCOMP
] * gScale
+ gBias
;
1372 if (bScale
!= 1.0 || bBias
!= 0.0) {
1374 for (i
= 0; i
< n
; i
++) {
1375 rgba
[i
][BCOMP
] = rgba
[i
][BCOMP
] * bScale
+ bBias
;
1378 if (aScale
!= 1.0 || aBias
!= 0.0) {
1380 for (i
= 0; i
< n
; i
++) {
1381 rgba
[i
][ACOMP
] = rgba
[i
][ACOMP
] * aScale
+ aBias
;
1388 * Apply pixel mapping to an array of floating point RGBA pixels.
1391 _mesa_map_rgba( const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4] )
1393 const GLfloat rscale
= (GLfloat
) (ctx
->PixelMaps
.RtoR
.Size
- 1);
1394 const GLfloat gscale
= (GLfloat
) (ctx
->PixelMaps
.GtoG
.Size
- 1);
1395 const GLfloat bscale
= (GLfloat
) (ctx
->PixelMaps
.BtoB
.Size
- 1);
1396 const GLfloat ascale
= (GLfloat
) (ctx
->PixelMaps
.AtoA
.Size
- 1);
1397 const GLfloat
*rMap
= ctx
->PixelMaps
.RtoR
.Map
;
1398 const GLfloat
*gMap
= ctx
->PixelMaps
.GtoG
.Map
;
1399 const GLfloat
*bMap
= ctx
->PixelMaps
.BtoB
.Map
;
1400 const GLfloat
*aMap
= ctx
->PixelMaps
.AtoA
.Map
;
1403 GLfloat r
= CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1404 GLfloat g
= CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1405 GLfloat b
= CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1406 GLfloat a
= CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1407 rgba
[i
][RCOMP
] = rMap
[IROUND(r
* rscale
)];
1408 rgba
[i
][GCOMP
] = gMap
[IROUND(g
* gscale
)];
1409 rgba
[i
][BCOMP
] = bMap
[IROUND(b
* bscale
)];
1410 rgba
[i
][ACOMP
] = aMap
[IROUND(a
* ascale
)];
1416 * Apply the color matrix and post color matrix scaling and biasing.
1419 _mesa_transform_rgba(const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4])
1421 const GLfloat rs
= ctx
->Pixel
.PostColorMatrixScale
[0];
1422 const GLfloat rb
= ctx
->Pixel
.PostColorMatrixBias
[0];
1423 const GLfloat gs
= ctx
->Pixel
.PostColorMatrixScale
[1];
1424 const GLfloat gb
= ctx
->Pixel
.PostColorMatrixBias
[1];
1425 const GLfloat bs
= ctx
->Pixel
.PostColorMatrixScale
[2];
1426 const GLfloat bb
= ctx
->Pixel
.PostColorMatrixBias
[2];
1427 const GLfloat as
= ctx
->Pixel
.PostColorMatrixScale
[3];
1428 const GLfloat ab
= ctx
->Pixel
.PostColorMatrixBias
[3];
1429 const GLfloat
*m
= ctx
->ColorMatrixStack
.Top
->m
;
1431 for (i
= 0; i
< n
; i
++) {
1432 const GLfloat r
= rgba
[i
][RCOMP
];
1433 const GLfloat g
= rgba
[i
][GCOMP
];
1434 const GLfloat b
= rgba
[i
][BCOMP
];
1435 const GLfloat a
= rgba
[i
][ACOMP
];
1436 rgba
[i
][RCOMP
] = (m
[0] * r
+ m
[4] * g
+ m
[ 8] * b
+ m
[12] * a
) * rs
+ rb
;
1437 rgba
[i
][GCOMP
] = (m
[1] * r
+ m
[5] * g
+ m
[ 9] * b
+ m
[13] * a
) * gs
+ gb
;
1438 rgba
[i
][BCOMP
] = (m
[2] * r
+ m
[6] * g
+ m
[10] * b
+ m
[14] * a
) * bs
+ bb
;
1439 rgba
[i
][ACOMP
] = (m
[3] * r
+ m
[7] * g
+ m
[11] * b
+ m
[15] * a
) * as
+ ab
;
1445 * Apply a color table lookup to an array of floating point RGBA colors.
1448 _mesa_lookup_rgba_float(const struct gl_color_table
*table
,
1449 GLuint n
, GLfloat rgba
[][4])
1451 const GLint max
= table
->Size
- 1;
1452 const GLfloat scale
= (GLfloat
) max
;
1453 const GLfloat
*lut
= table
->TableF
;
1456 if (!table
->TableF
|| table
->Size
== 0)
1459 switch (table
->_BaseFormat
) {
1461 /* replace RGBA with I */
1462 for (i
= 0; i
< n
; i
++) {
1463 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1464 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1472 /* replace RGB with L */
1473 for (i
= 0; i
< n
; i
++) {
1474 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1475 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1482 /* replace A with A */
1483 for (i
= 0; i
< n
; i
++) {
1484 GLint j
= IROUND(rgba
[i
][ACOMP
] * scale
);
1485 rgba
[i
][ACOMP
] = lut
[CLAMP(j
, 0, max
)];
1488 case GL_LUMINANCE_ALPHA
:
1489 /* replace RGBA with LLLA */
1490 for (i
= 0; i
< n
; i
++) {
1491 GLint jL
= IROUND(rgba
[i
][RCOMP
] * scale
);
1492 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1493 GLfloat luminance
, alpha
;
1494 jL
= CLAMP(jL
, 0, max
);
1495 jA
= CLAMP(jA
, 0, max
);
1496 luminance
= lut
[jL
* 2 + 0];
1497 alpha
= lut
[jA
* 2 + 1];
1500 rgba
[i
][BCOMP
] = luminance
;
1501 rgba
[i
][ACOMP
] = alpha
;;
1505 /* replace RGB with RGB */
1506 for (i
= 0; i
< n
; i
++) {
1507 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1508 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1509 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1510 jR
= CLAMP(jR
, 0, max
);
1511 jG
= CLAMP(jG
, 0, max
);
1512 jB
= CLAMP(jB
, 0, max
);
1513 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1514 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1515 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1519 /* replace RGBA with RGBA */
1520 for (i
= 0; i
< n
; i
++) {
1521 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1522 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1523 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1524 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1525 jR
= CLAMP(jR
, 0, max
);
1526 jG
= CLAMP(jG
, 0, max
);
1527 jB
= CLAMP(jB
, 0, max
);
1528 jA
= CLAMP(jA
, 0, max
);
1529 rgba
[i
][RCOMP
] = lut
[jR
* 4 + 0];
1530 rgba
[i
][GCOMP
] = lut
[jG
* 4 + 1];
1531 rgba
[i
][BCOMP
] = lut
[jB
* 4 + 2];
1532 rgba
[i
][ACOMP
] = lut
[jA
* 4 + 3];
1536 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_float");
1544 * Apply a color table lookup to an array of ubyte/RGBA colors.
1547 _mesa_lookup_rgba_ubyte(const struct gl_color_table
*table
,
1548 GLuint n
, GLubyte rgba
[][4])
1550 const GLubyte
*lut
= table
->TableUB
;
1551 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / (GLfloat
)255.0;
1554 if (!table
->TableUB
|| table
->Size
== 0)
1557 switch (table
->_BaseFormat
) {
1559 /* replace RGBA with I */
1560 if (table
->Size
== 256) {
1561 for (i
= 0; i
< n
; i
++) {
1562 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1570 for (i
= 0; i
< n
; i
++) {
1571 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1575 rgba
[i
][ACOMP
] = lut
[j
];
1580 /* replace RGB with L */
1581 if (table
->Size
== 256) {
1582 for (i
= 0; i
< n
; i
++) {
1583 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1590 for (i
= 0; i
< n
; i
++) {
1591 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1594 rgba
[i
][BCOMP
] = lut
[j
];
1599 /* replace A with A */
1600 if (table
->Size
== 256) {
1601 for (i
= 0; i
< n
; i
++) {
1602 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
]];
1606 for (i
= 0; i
< n
; i
++) {
1607 GLint j
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1608 rgba
[i
][ACOMP
] = lut
[j
];
1612 case GL_LUMINANCE_ALPHA
:
1613 /* replace RGBA with LLLA */
1614 if (table
->Size
== 256) {
1615 for (i
= 0; i
< n
; i
++) {
1616 GLubyte l
= lut
[rgba
[i
][RCOMP
] * 2 + 0];
1617 GLubyte a
= lut
[rgba
[i
][ACOMP
] * 2 + 1];;
1625 for (i
= 0; i
< n
; i
++) {
1626 GLint jL
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1627 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1628 GLubyte luminance
= lut
[jL
* 2 + 0];
1629 GLubyte alpha
= lut
[jA
* 2 + 1];
1632 rgba
[i
][BCOMP
] = luminance
;
1633 rgba
[i
][ACOMP
] = alpha
;
1638 if (table
->Size
== 256) {
1639 for (i
= 0; i
< n
; i
++) {
1640 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 3 + 0];
1641 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 3 + 1];
1642 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 3 + 2];
1646 for (i
= 0; i
< n
; i
++) {
1647 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1648 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1649 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1650 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1651 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1652 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1657 if (table
->Size
== 256) {
1658 for (i
= 0; i
< n
; i
++) {
1659 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 4 + 0];
1660 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 4 + 1];
1661 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 4 + 2];
1662 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
] * 4 + 3];
1666 for (i
= 0; i
< n
; i
++) {
1667 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1668 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1669 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1670 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1671 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][RCOMP
], lut
[jR
* 4 + 0]);
1672 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][GCOMP
], lut
[jG
* 4 + 1]);
1673 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][BCOMP
], lut
[jB
* 4 + 2]);
1674 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][ACOMP
], lut
[jA
* 4 + 3]);
1679 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_chan");
1687 * Map color indexes to float rgba values.
1690 _mesa_map_ci_to_rgba( const GLcontext
*ctx
, GLuint n
,
1691 const GLuint index
[], GLfloat rgba
[][4] )
1693 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1694 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1695 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1696 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1697 const GLfloat
*rMap
= ctx
->PixelMaps
.ItoR
.Map
;
1698 const GLfloat
*gMap
= ctx
->PixelMaps
.ItoG
.Map
;
1699 const GLfloat
*bMap
= ctx
->PixelMaps
.ItoB
.Map
;
1700 const GLfloat
*aMap
= ctx
->PixelMaps
.ItoA
.Map
;
1703 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1704 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1705 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1706 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1712 * Map ubyte color indexes to ubyte/RGBA values.
1715 _mesa_map_ci8_to_rgba8(const GLcontext
*ctx
, GLuint n
, const GLubyte index
[],
1718 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1719 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1720 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1721 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1722 const GLubyte
*rMap
= ctx
->PixelMaps
.ItoR
.Map8
;
1723 const GLubyte
*gMap
= ctx
->PixelMaps
.ItoG
.Map8
;
1724 const GLubyte
*bMap
= ctx
->PixelMaps
.ItoB
.Map8
;
1725 const GLubyte
*aMap
= ctx
->PixelMaps
.ItoA
.Map8
;
1728 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1729 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1730 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1731 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1737 _mesa_scale_and_bias_depth(const GLcontext
*ctx
, GLuint n
,
1738 GLfloat depthValues
[])
1740 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
1741 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
1743 for (i
= 0; i
< n
; i
++) {
1744 GLfloat d
= depthValues
[i
] * scale
+ bias
;
1745 depthValues
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
1751 _mesa_scale_and_bias_depth_uint(const GLcontext
*ctx
, GLuint n
,
1752 GLuint depthValues
[])
1754 const GLdouble max
= (double) 0xffffffff;
1755 const GLdouble scale
= ctx
->Pixel
.DepthScale
;
1756 const GLdouble bias
= ctx
->Pixel
.DepthBias
* max
;
1758 for (i
= 0; i
< n
; i
++) {
1759 GLdouble d
= (GLdouble
) depthValues
[i
] * scale
+ bias
;
1760 d
= CLAMP(d
, 0.0, max
);
1761 depthValues
[i
] = (GLuint
) d
;
1768 * Update the min/max values from an array of fragment colors.
1771 update_minmax(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1774 for (i
= 0; i
< n
; i
++) {
1776 if (rgba
[i
][RCOMP
] < ctx
->MinMax
.Min
[RCOMP
])
1777 ctx
->MinMax
.Min
[RCOMP
] = rgba
[i
][RCOMP
];
1778 if (rgba
[i
][GCOMP
] < ctx
->MinMax
.Min
[GCOMP
])
1779 ctx
->MinMax
.Min
[GCOMP
] = rgba
[i
][GCOMP
];
1780 if (rgba
[i
][BCOMP
] < ctx
->MinMax
.Min
[BCOMP
])
1781 ctx
->MinMax
.Min
[BCOMP
] = rgba
[i
][BCOMP
];
1782 if (rgba
[i
][ACOMP
] < ctx
->MinMax
.Min
[ACOMP
])
1783 ctx
->MinMax
.Min
[ACOMP
] = rgba
[i
][ACOMP
];
1786 if (rgba
[i
][RCOMP
] > ctx
->MinMax
.Max
[RCOMP
])
1787 ctx
->MinMax
.Max
[RCOMP
] = rgba
[i
][RCOMP
];
1788 if (rgba
[i
][GCOMP
] > ctx
->MinMax
.Max
[GCOMP
])
1789 ctx
->MinMax
.Max
[GCOMP
] = rgba
[i
][GCOMP
];
1790 if (rgba
[i
][BCOMP
] > ctx
->MinMax
.Max
[BCOMP
])
1791 ctx
->MinMax
.Max
[BCOMP
] = rgba
[i
][BCOMP
];
1792 if (rgba
[i
][ACOMP
] > ctx
->MinMax
.Max
[ACOMP
])
1793 ctx
->MinMax
.Max
[ACOMP
] = rgba
[i
][ACOMP
];
1799 * Update the histogram values from an array of fragment colors.
1802 update_histogram(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1804 const GLint max
= ctx
->Histogram
.Width
- 1;
1805 GLfloat w
= (GLfloat
) max
;
1808 if (ctx
->Histogram
.Width
== 0)
1811 for (i
= 0; i
< n
; i
++) {
1812 GLint ri
= IROUND(rgba
[i
][RCOMP
] * w
);
1813 GLint gi
= IROUND(rgba
[i
][GCOMP
] * w
);
1814 GLint bi
= IROUND(rgba
[i
][BCOMP
] * w
);
1815 GLint ai
= IROUND(rgba
[i
][ACOMP
] * w
);
1816 ri
= CLAMP(ri
, 0, max
);
1817 gi
= CLAMP(gi
, 0, max
);
1818 bi
= CLAMP(bi
, 0, max
);
1819 ai
= CLAMP(ai
, 0, max
);
1820 ctx
->Histogram
.Count
[ri
][RCOMP
]++;
1821 ctx
->Histogram
.Count
[gi
][GCOMP
]++;
1822 ctx
->Histogram
.Count
[bi
][BCOMP
]++;
1823 ctx
->Histogram
.Count
[ai
][ACOMP
]++;
1829 * Apply various pixel transfer operations to an array of RGBA pixels
1830 * as indicated by the transferOps bitmask
1833 _mesa_apply_rgba_transfer_ops(GLcontext
*ctx
, GLbitfield transferOps
,
1834 GLuint n
, GLfloat rgba
[][4])
1837 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
1838 _mesa_scale_and_bias_rgba(n
, rgba
,
1839 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
1840 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
1841 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
1842 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
1844 /* color map lookup */
1845 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1846 _mesa_map_rgba( ctx
, n
, rgba
);
1848 /* GL_COLOR_TABLE lookup */
1849 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
1850 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
], n
, rgba
);
1853 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
1854 /* this has to be done in the calling code */
1855 _mesa_problem(ctx
, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");
1857 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
1858 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
1859 _mesa_scale_and_bias_rgba(n
, rgba
,
1860 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
1861 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
1862 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
1863 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
1864 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
1865 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
1866 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
1867 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
1869 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
1870 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
1871 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
], n
, rgba
);
1873 /* color matrix transform */
1874 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
1875 _mesa_transform_rgba(ctx
, n
, rgba
);
1877 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
1878 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
1879 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
], n
, rgba
);
1881 /* update histogram count */
1882 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
1883 update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1885 /* update min/max values */
1886 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
1887 update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1889 /* clamping to [0,1] */
1890 if (transferOps
& IMAGE_CLAMP_BIT
) {
1892 for (i
= 0; i
< n
; i
++) {
1893 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1894 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1895 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1896 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1903 * Apply color index shift and offset to an array of pixels.
1906 shift_and_offset_ci( const GLcontext
*ctx
, GLuint n
, GLuint indexes
[] )
1908 GLint shift
= ctx
->Pixel
.IndexShift
;
1909 GLint offset
= ctx
->Pixel
.IndexOffset
;
1913 indexes
[i
] = (indexes
[i
] << shift
) + offset
;
1916 else if (shift
< 0) {
1919 indexes
[i
] = (indexes
[i
] >> shift
) + offset
;
1924 indexes
[i
] = indexes
[i
] + offset
;
1932 * Apply color index shift, offset and table lookup to an array
1936 _mesa_apply_ci_transfer_ops(const GLcontext
*ctx
, GLbitfield transferOps
,
1937 GLuint n
, GLuint indexes
[])
1939 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
1940 shift_and_offset_ci(ctx
, n
, indexes
);
1942 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1943 const GLuint mask
= ctx
->PixelMaps
.ItoI
.Size
- 1;
1945 for (i
= 0; i
< n
; i
++) {
1946 const GLuint j
= indexes
[i
] & mask
;
1947 indexes
[i
] = IROUND(ctx
->PixelMaps
.ItoI
.Map
[j
]);
1954 * Apply stencil index shift, offset and table lookup to an array
1955 * of stencil values.
1958 _mesa_apply_stencil_transfer_ops(const GLcontext
*ctx
, GLuint n
,
1959 GLstencil stencil
[])
1961 if (ctx
->Pixel
.IndexShift
!= 0 || ctx
->Pixel
.IndexOffset
!= 0) {
1962 const GLint offset
= ctx
->Pixel
.IndexOffset
;
1963 GLint shift
= ctx
->Pixel
.IndexShift
;
1966 for (i
= 0; i
< n
; i
++) {
1967 stencil
[i
] = (stencil
[i
] << shift
) + offset
;
1970 else if (shift
< 0) {
1972 for (i
= 0; i
< n
; i
++) {
1973 stencil
[i
] = (stencil
[i
] >> shift
) + offset
;
1977 for (i
= 0; i
< n
; i
++) {
1978 stencil
[i
] = stencil
[i
] + offset
;
1982 if (ctx
->Pixel
.MapStencilFlag
) {
1983 GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
1985 for (i
= 0; i
< n
; i
++) {
1986 stencil
[i
] = (GLstencil
)ctx
->PixelMaps
.StoS
.Map
[ stencil
[i
] & mask
];
1993 * Used to pack an array [][4] of RGBA float colors as specified
1994 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
1995 * glGetConvolutionFilter(), etc.
1996 * Note: the rgba values will be modified by this function when any pixel
1997 * transfer ops are enabled.
2000 _mesa_pack_rgba_span_float(GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4],
2001 GLenum dstFormat
, GLenum dstType
,
2003 const struct gl_pixelstore_attrib
*dstPacking
,
2004 GLbitfield transferOps
)
2006 GLfloat luminance
[MAX_WIDTH
];
2007 const GLint comps
= _mesa_components_in_format(dstFormat
);
2011 * This test should probably go away. Have the caller set/clear the
2012 * IMAGE_CLAMP_BIT as needed.
2014 if (dstType
!= GL_FLOAT
|| ctx
->Color
.ClampReadColor
== GL_TRUE
) {
2015 /* need to clamp to [0, 1] */
2016 transferOps
|= IMAGE_CLAMP_BIT
;
2020 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
2021 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
2026 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
2027 /* compute luminance values */
2028 if (transferOps
& IMAGE_CLAMP_BIT
) {
2029 for (i
= 0; i
< n
; i
++) {
2030 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
2031 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
2035 for (i
= 0; i
< n
; i
++) {
2036 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
2042 * Pack/store the pixels. Ugh! Lots of cases!!!
2045 case GL_UNSIGNED_BYTE
:
2047 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2048 switch (dstFormat
) {
2051 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2055 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2059 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2063 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2067 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
2069 case GL_LUMINANCE_ALPHA
:
2071 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
2072 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2077 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2078 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2079 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2084 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2085 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2086 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2087 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2092 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2093 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2094 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2099 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2100 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2101 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2102 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2107 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2108 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2109 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2110 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2116 dst
[i
*2+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2117 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2121 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2127 GLbyte
*dst
= (GLbyte
*) dstAddr
;
2128 switch (dstFormat
) {
2131 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2135 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2139 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2143 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2147 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
2149 case GL_LUMINANCE_ALPHA
:
2151 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
2152 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2157 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2158 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2159 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2164 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2165 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2166 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2167 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2172 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2173 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2174 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2179 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2180 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2181 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2182 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2187 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2188 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2189 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2190 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2196 dst
[i
*2+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2197 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2201 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2205 case GL_UNSIGNED_SHORT
:
2207 GLushort
*dst
= (GLushort
*) dstAddr
;
2208 switch (dstFormat
) {
2211 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][RCOMP
]);
2215 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][GCOMP
]);
2219 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][BCOMP
]);
2223 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][ACOMP
]);
2227 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
], luminance
[i
]);
2229 case GL_LUMINANCE_ALPHA
:
2231 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
*2+0], luminance
[i
]);
2232 CLAMPED_FLOAT_TO_USHORT(dst
[i
*2+1], rgba
[i
][ACOMP
]);
2237 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][RCOMP
]);
2238 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
2239 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][BCOMP
]);
2244 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][RCOMP
]);
2245 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
2246 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][BCOMP
]);
2247 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
2252 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][BCOMP
]);
2253 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
2254 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][RCOMP
]);
2259 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][BCOMP
]);
2260 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
2261 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][RCOMP
]);
2262 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
2267 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][ACOMP
]);
2268 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][BCOMP
]);
2269 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][GCOMP
]);
2270 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][RCOMP
]);
2276 dst
[i
*2+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
2277 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
2281 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2287 GLshort
*dst
= (GLshort
*) dstAddr
;
2288 switch (dstFormat
) {
2291 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2295 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2299 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2303 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2307 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
2309 case GL_LUMINANCE_ALPHA
:
2311 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
2312 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2317 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2318 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2319 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2324 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2325 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2326 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2327 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2332 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2333 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2334 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2339 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2340 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2341 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2342 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2347 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2348 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2349 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2350 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2356 dst
[i
*2+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2357 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2361 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2365 case GL_UNSIGNED_INT
:
2367 GLuint
*dst
= (GLuint
*) dstAddr
;
2368 switch (dstFormat
) {
2371 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2375 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2379 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2383 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2387 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
2389 case GL_LUMINANCE_ALPHA
:
2391 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
2392 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2397 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2398 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2399 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2404 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2405 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2406 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2407 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2412 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2413 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2414 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2419 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2420 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2421 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2422 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2427 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2428 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2429 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2430 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2436 dst
[i
*2+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2437 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2441 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2447 GLint
*dst
= (GLint
*) dstAddr
;
2448 switch (dstFormat
) {
2451 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2455 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2459 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2463 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2467 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
2469 case GL_LUMINANCE_ALPHA
:
2471 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
2472 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2477 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2478 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2479 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2484 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2485 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2486 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2487 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2492 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2493 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2494 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2499 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2500 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2501 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2502 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2507 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2508 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2509 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2510 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2516 dst
[i
*2+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2517 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2521 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2527 GLfloat
*dst
= (GLfloat
*) dstAddr
;
2528 switch (dstFormat
) {
2531 dst
[i
] = rgba
[i
][RCOMP
];
2535 dst
[i
] = rgba
[i
][GCOMP
];
2539 dst
[i
] = rgba
[i
][BCOMP
];
2543 dst
[i
] = rgba
[i
][ACOMP
];
2547 dst
[i
] = luminance
[i
];
2549 case GL_LUMINANCE_ALPHA
:
2551 dst
[i
*2+0] = luminance
[i
];
2552 dst
[i
*2+1] = rgba
[i
][ACOMP
];
2557 dst
[i
*3+0] = rgba
[i
][RCOMP
];
2558 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2559 dst
[i
*3+2] = rgba
[i
][BCOMP
];
2564 dst
[i
*4+0] = rgba
[i
][RCOMP
];
2565 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2566 dst
[i
*4+2] = rgba
[i
][BCOMP
];
2567 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2572 dst
[i
*3+0] = rgba
[i
][BCOMP
];
2573 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2574 dst
[i
*3+2] = rgba
[i
][RCOMP
];
2579 dst
[i
*4+0] = rgba
[i
][BCOMP
];
2580 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2581 dst
[i
*4+2] = rgba
[i
][RCOMP
];
2582 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2587 dst
[i
*4+0] = rgba
[i
][ACOMP
];
2588 dst
[i
*4+1] = rgba
[i
][BCOMP
];
2589 dst
[i
*4+2] = rgba
[i
][GCOMP
];
2590 dst
[i
*4+3] = rgba
[i
][RCOMP
];
2596 dst
[i
*2+0] = rgba
[i
][RCOMP
];
2597 dst
[i
*2+1] = rgba
[i
][GCOMP
];
2601 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2605 case GL_HALF_FLOAT_ARB
:
2607 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
2608 switch (dstFormat
) {
2611 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2615 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2619 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2623 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2627 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
2629 case GL_LUMINANCE_ALPHA
:
2631 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
2632 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2637 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2638 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2639 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2644 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2645 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2646 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2647 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2652 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2653 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2654 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2659 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2660 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2661 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2662 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2667 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2668 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2669 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2670 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2676 dst
[i
*2+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2677 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2681 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2685 case GL_UNSIGNED_BYTE_3_3_2
:
2686 if (dstFormat
== GL_RGB
) {
2687 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2689 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 7.0F
) << 5)
2690 | (IROUND(rgba
[i
][GCOMP
] * 7.0F
) << 2)
2691 | (IROUND(rgba
[i
][BCOMP
] * 3.0F
) );
2695 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2696 if (dstFormat
== GL_RGB
) {
2697 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2699 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 7.0F
) )
2700 | (IROUND(rgba
[i
][GCOMP
] * 7.0F
) << 3)
2701 | (IROUND(rgba
[i
][BCOMP
] * 3.0F
) << 6);
2705 case GL_UNSIGNED_SHORT_5_6_5
:
2706 if (dstFormat
== GL_RGB
) {
2707 GLushort
*dst
= (GLushort
*) dstAddr
;
2709 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 11)
2710 | (IROUND(rgba
[i
][GCOMP
] * 63.0F
) << 5)
2711 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) );
2715 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2716 if (dstFormat
== GL_RGB
) {
2717 GLushort
*dst
= (GLushort
*) dstAddr
;
2719 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) )
2720 | (IROUND(rgba
[i
][GCOMP
] * 63.0F
) << 5)
2721 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 11);
2725 case GL_UNSIGNED_SHORT_4_4_4_4
:
2726 if (dstFormat
== GL_RGBA
) {
2727 GLushort
*dst
= (GLushort
*) dstAddr
;
2729 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 12)
2730 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2731 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 4)
2732 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) );
2735 else if (dstFormat
== GL_BGRA
) {
2736 GLushort
*dst
= (GLushort
*) dstAddr
;
2738 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 12)
2739 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2740 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 4)
2741 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) );
2744 else if (dstFormat
== GL_ABGR_EXT
) {
2745 GLushort
*dst
= (GLushort
*) dstAddr
;
2747 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12)
2748 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 8)
2749 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2750 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) );
2754 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2755 if (dstFormat
== GL_RGBA
) {
2756 GLushort
*dst
= (GLushort
*) dstAddr
;
2758 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 15.0F
) )
2759 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2760 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 8)
2761 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12);
2764 else if (dstFormat
== GL_BGRA
) {
2765 GLushort
*dst
= (GLushort
*) dstAddr
;
2767 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 15.0F
) )
2768 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2769 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 8)
2770 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12);
2773 else if (dstFormat
== GL_ABGR_EXT
) {
2774 GLushort
*dst
= (GLushort
*) dstAddr
;
2776 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 15.0F
) )
2777 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 4)
2778 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2779 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 12);
2783 case GL_UNSIGNED_SHORT_5_5_5_1
:
2784 if (dstFormat
== GL_RGBA
) {
2785 GLushort
*dst
= (GLushort
*) dstAddr
;
2787 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 11)
2788 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 6)
2789 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 1)
2790 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) );
2793 else if (dstFormat
== GL_BGRA
) {
2794 GLushort
*dst
= (GLushort
*) dstAddr
;
2796 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 11)
2797 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 6)
2798 | (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 1)
2799 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) );
2802 else if (dstFormat
== GL_ABGR_EXT
) {
2803 GLushort
*dst
= (GLushort
*) dstAddr
;
2805 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 31.0F
) << 11)
2806 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 6)
2807 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 1)
2808 | (IROUND(rgba
[i
][RCOMP
] * 1.0F
) );
2812 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2813 if (dstFormat
== GL_RGBA
) {
2814 GLushort
*dst
= (GLushort
*) dstAddr
;
2816 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) )
2817 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 5)
2818 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 10)
2819 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) << 15);
2822 else if (dstFormat
== GL_BGRA
) {
2823 GLushort
*dst
= (GLushort
*) dstAddr
;
2825 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 31.0F
) )
2826 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 5)
2827 | (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 10)
2828 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) << 15);
2831 else if (dstFormat
== GL_ABGR_EXT
) {
2832 GLushort
*dst
= (GLushort
*) dstAddr
;
2834 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 31.0F
) )
2835 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 5)
2836 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 10)
2837 | (IROUND(rgba
[i
][RCOMP
] * 1.0F
) << 15);
2841 case GL_UNSIGNED_INT_8_8_8_8
:
2842 if (dstFormat
== GL_RGBA
) {
2843 GLuint
*dst
= (GLuint
*) dstAddr
;
2845 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 255.F
) << 24)
2846 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 16)
2847 | (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 8)
2848 | (IROUND(rgba
[i
][ACOMP
] * 255.F
) );
2851 else if (dstFormat
== GL_BGRA
) {
2852 GLuint
*dst
= (GLuint
*) dstAddr
;
2854 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 24)
2855 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 16)
2856 | (IROUND(rgba
[i
][RCOMP
] * 255.F
) << 8)
2857 | (IROUND(rgba
[i
][ACOMP
] * 255.F
) );
2860 else if (dstFormat
== GL_ABGR_EXT
) {
2861 GLuint
*dst
= (GLuint
*) dstAddr
;
2863 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 255.F
) << 24)
2864 | (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 16)
2865 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 8)
2866 | (IROUND(rgba
[i
][RCOMP
] * 255.F
) );
2870 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2871 if (dstFormat
== GL_RGBA
) {
2872 GLuint
*dst
= (GLuint
*) dstAddr
;
2874 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 255.0F
) )
2875 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 8)
2876 | (IROUND(rgba
[i
][BCOMP
] * 255.0F
) << 16)
2877 | (IROUND(rgba
[i
][ACOMP
] * 255.0F
) << 24);
2880 else if (dstFormat
== GL_BGRA
) {
2881 GLuint
*dst
= (GLuint
*) dstAddr
;
2883 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 255.0F
) )
2884 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 8)
2885 | (IROUND(rgba
[i
][RCOMP
] * 255.0F
) << 16)
2886 | (IROUND(rgba
[i
][ACOMP
] * 255.0F
) << 24);
2889 else if (dstFormat
== GL_ABGR_EXT
) {
2890 GLuint
*dst
= (GLuint
*) dstAddr
;
2892 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 255.0F
) )
2893 | (IROUND(rgba
[i
][BCOMP
] * 255.0F
) << 8)
2894 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 16)
2895 | (IROUND(rgba
[i
][RCOMP
] * 255.0F
) << 24);
2899 case GL_UNSIGNED_INT_10_10_10_2
:
2900 if (dstFormat
== GL_RGBA
) {
2901 GLuint
*dst
= (GLuint
*) dstAddr
;
2903 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 22)
2904 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 12)
2905 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 2)
2906 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) );
2909 else if (dstFormat
== GL_BGRA
) {
2910 GLuint
*dst
= (GLuint
*) dstAddr
;
2912 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 22)
2913 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 12)
2914 | (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 2)
2915 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) );
2918 else if (dstFormat
== GL_ABGR_EXT
) {
2919 GLuint
*dst
= (GLuint
*) dstAddr
;
2921 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 1023.0F
) << 22)
2922 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 12)
2923 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 2)
2924 | (IROUND(rgba
[i
][RCOMP
] * 3.0F
) );
2928 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2929 if (dstFormat
== GL_RGBA
) {
2930 GLuint
*dst
= (GLuint
*) dstAddr
;
2932 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) )
2933 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 10)
2934 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 20)
2935 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) << 30);
2938 else if (dstFormat
== GL_BGRA
) {
2939 GLuint
*dst
= (GLuint
*) dstAddr
;
2941 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) )
2942 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 10)
2943 | (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 20)
2944 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) << 30);
2947 else if (dstFormat
== GL_ABGR_EXT
) {
2948 GLuint
*dst
= (GLuint
*) dstAddr
;
2950 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 1023.0F
) )
2951 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 10)
2952 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 20)
2953 | (IROUND(rgba
[i
][RCOMP
] * 3.0F
) << 30);
2958 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
2962 if (dstPacking
->SwapBytes
) {
2963 GLint swapSize
= _mesa_sizeof_packed_type(dstType
);
2964 if (swapSize
== 2) {
2965 if (dstPacking
->SwapBytes
) {
2966 _mesa_swap2((GLushort
*) dstAddr
, n
* comps
);
2969 else if (swapSize
== 4) {
2970 if (dstPacking
->SwapBytes
) {
2971 _mesa_swap4((GLuint
*) dstAddr
, n
* comps
);
2978 #define SWAP2BYTE(VALUE) \
2980 GLubyte *bytes = (GLubyte *) &(VALUE); \
2981 GLubyte tmp = bytes[0]; \
2982 bytes[0] = bytes[1]; \
2986 #define SWAP4BYTE(VALUE) \
2988 GLubyte *bytes = (GLubyte *) &(VALUE); \
2989 GLubyte tmp = bytes[0]; \
2990 bytes[0] = bytes[3]; \
2993 bytes[1] = bytes[2]; \
2999 extract_uint_indexes(GLuint n
, GLuint indexes
[],
3000 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
3001 const struct gl_pixelstore_attrib
*unpack
)
3003 ASSERT(srcFormat
== GL_COLOR_INDEX
|| srcFormat
== GL_STENCIL_INDEX
);
3005 ASSERT(srcType
== GL_BITMAP
||
3006 srcType
== GL_UNSIGNED_BYTE
||
3007 srcType
== GL_BYTE
||
3008 srcType
== GL_UNSIGNED_SHORT
||
3009 srcType
== GL_SHORT
||
3010 srcType
== GL_UNSIGNED_INT
||
3011 srcType
== GL_INT
||
3012 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
3013 srcType
== GL_HALF_FLOAT_ARB
||
3014 srcType
== GL_FLOAT
);
3019 GLubyte
*ubsrc
= (GLubyte
*) src
;
3020 if (unpack
->LsbFirst
) {
3021 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
3023 for (i
= 0; i
< n
; i
++) {
3024 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
3035 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
3037 for (i
= 0; i
< n
; i
++) {
3038 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
3050 case GL_UNSIGNED_BYTE
:
3053 const GLubyte
*s
= (const GLubyte
*) src
;
3054 for (i
= 0; i
< n
; i
++)
3061 const GLbyte
*s
= (const GLbyte
*) src
;
3062 for (i
= 0; i
< n
; i
++)
3066 case GL_UNSIGNED_SHORT
:
3069 const GLushort
*s
= (const GLushort
*) src
;
3070 if (unpack
->SwapBytes
) {
3071 for (i
= 0; i
< n
; i
++) {
3072 GLushort value
= s
[i
];
3078 for (i
= 0; i
< n
; i
++)
3086 const GLshort
*s
= (const GLshort
*) src
;
3087 if (unpack
->SwapBytes
) {
3088 for (i
= 0; i
< n
; i
++) {
3089 GLshort value
= s
[i
];
3095 for (i
= 0; i
< n
; i
++)
3100 case GL_UNSIGNED_INT
:
3103 const GLuint
*s
= (const GLuint
*) src
;
3104 if (unpack
->SwapBytes
) {
3105 for (i
= 0; i
< n
; i
++) {
3106 GLuint value
= s
[i
];
3112 for (i
= 0; i
< n
; i
++)
3120 const GLint
*s
= (const GLint
*) src
;
3121 if (unpack
->SwapBytes
) {
3122 for (i
= 0; i
< n
; i
++) {
3129 for (i
= 0; i
< n
; i
++)
3137 const GLfloat
*s
= (const GLfloat
*) src
;
3138 if (unpack
->SwapBytes
) {
3139 for (i
= 0; i
< n
; i
++) {
3140 GLfloat value
= s
[i
];
3142 indexes
[i
] = (GLuint
) value
;
3146 for (i
= 0; i
< n
; i
++)
3147 indexes
[i
] = (GLuint
) s
[i
];
3151 case GL_HALF_FLOAT_ARB
:
3154 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
3155 if (unpack
->SwapBytes
) {
3156 for (i
= 0; i
< n
; i
++) {
3157 GLhalfARB value
= s
[i
];
3159 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
3163 for (i
= 0; i
< n
; i
++)
3164 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
3168 case GL_UNSIGNED_INT_24_8_EXT
:
3171 const GLuint
*s
= (const GLuint
*) src
;
3172 if (unpack
->SwapBytes
) {
3173 for (i
= 0; i
< n
; i
++) {
3174 GLuint value
= s
[i
];
3176 indexes
[i
] = value
& 0xff; /* lower 8 bits */
3180 for (i
= 0; i
< n
; i
++)
3181 indexes
[i
] = s
[i
] & 0xff; /* lower 8 bits */
3187 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
3194 * This function extracts floating point RGBA values from arbitrary
3195 * image data. srcFormat and srcType are the format and type parameters
3196 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
3198 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
3199 * implements the "Conversion to floating point", "Conversion to RGB",
3200 * and "Final Expansion to RGBA" operations.
3202 * Args: n - number of pixels
3203 * rgba - output colors
3204 * srcFormat - format of incoming data
3205 * srcType - data type of incoming data
3206 * src - source data pointer
3207 * swapBytes - perform byteswapping of incoming data?
3210 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
3211 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
3212 GLboolean swapBytes
)
3214 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
3216 GLint rComp
, bComp
, gComp
, aComp
;
3218 ASSERT(srcFormat
== GL_RED
||
3219 srcFormat
== GL_GREEN
||
3220 srcFormat
== GL_BLUE
||
3221 srcFormat
== GL_ALPHA
||
3222 srcFormat
== GL_LUMINANCE
||
3223 srcFormat
== GL_LUMINANCE_ALPHA
||
3224 srcFormat
== GL_INTENSITY
||
3225 srcFormat
== GL_RGB
||
3226 srcFormat
== GL_BGR
||
3227 srcFormat
== GL_RGBA
||
3228 srcFormat
== GL_BGRA
||
3229 srcFormat
== GL_ABGR_EXT
||
3230 srcFormat
== GL_DU8DV8_ATI
||
3231 srcFormat
== GL_DUDV_ATI
);
3233 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
3234 srcType
== GL_BYTE
||
3235 srcType
== GL_UNSIGNED_SHORT
||
3236 srcType
== GL_SHORT
||
3237 srcType
== GL_UNSIGNED_INT
||
3238 srcType
== GL_INT
||
3239 srcType
== GL_HALF_FLOAT_ARB
||
3240 srcType
== GL_FLOAT
||
3241 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3242 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3243 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3244 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3245 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3246 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3247 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3248 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3249 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3250 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3251 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3252 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3254 rComp
= gComp
= bComp
= aComp
= -1;
3256 switch (srcFormat
) {
3259 greenIndex
= blueIndex
= alphaIndex
= -1;
3264 redIndex
= blueIndex
= alphaIndex
= -1;
3269 redIndex
= greenIndex
= alphaIndex
= -1;
3273 redIndex
= greenIndex
= blueIndex
= -1;
3278 redIndex
= greenIndex
= blueIndex
= 0;
3282 case GL_LUMINANCE_ALPHA
:
3283 redIndex
= greenIndex
= blueIndex
= 0;
3288 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
3355 _mesa_problem(NULL
, "bad srcFormat in extract float data");
3360 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
3361 if ((INDEX) < 0) { \
3363 for (i = 0; i < n; i++) { \
3364 rgba[i][CHANNEL] = DEFAULT; \
3367 else if (swapBytes) { \
3368 const TYPE *s = (const TYPE *) src; \
3370 for (i = 0; i < n; i++) { \
3371 TYPE value = s[INDEX]; \
3372 if (sizeof(TYPE) == 2) { \
3375 else if (sizeof(TYPE) == 4) { \
3378 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
3383 const TYPE *s = (const TYPE *) src; \
3385 for (i = 0; i < n; i++) { \
3386 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
3392 case GL_UNSIGNED_BYTE
:
3393 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3394 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3395 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3396 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3399 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3400 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3401 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3402 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
3404 case GL_UNSIGNED_SHORT
:
3405 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3406 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3407 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3408 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
3411 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3412 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3413 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3414 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
3416 case GL_UNSIGNED_INT
:
3417 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3418 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3419 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3420 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
3423 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3424 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3425 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3426 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
3429 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3430 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3431 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3432 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
3434 case GL_HALF_FLOAT_ARB
:
3435 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3436 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3437 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3438 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
3440 case GL_UNSIGNED_BYTE_3_3_2
:
3442 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3444 for (i
= 0; i
< n
; i
++) {
3445 GLubyte p
= ubsrc
[i
];
3446 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
3447 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
3448 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
3449 rgba
[i
][aComp
] = 1.0F
;
3453 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3455 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3457 for (i
= 0; i
< n
; i
++) {
3458 GLubyte p
= ubsrc
[i
];
3459 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
3460 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
3461 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
3462 rgba
[i
][aComp
] = 1.0F
;
3466 case GL_UNSIGNED_SHORT_5_6_5
:
3468 const GLushort
*ussrc
= (const GLushort
*) src
;
3470 for (i
= 0; i
< n
; i
++) {
3471 GLushort p
= ussrc
[i
];
3473 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3474 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3475 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3476 rgba
[i
][aComp
] = 1.0F
;
3480 const GLushort
*ussrc
= (const GLushort
*) src
;
3482 for (i
= 0; i
< n
; i
++) {
3483 GLushort p
= ussrc
[i
];
3484 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3485 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3486 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3487 rgba
[i
][aComp
] = 1.0F
;
3491 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3493 const GLushort
*ussrc
= (const GLushort
*) src
;
3495 for (i
= 0; i
< n
; i
++) {
3496 GLushort p
= ussrc
[i
];
3498 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3499 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3500 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3501 rgba
[i
][aComp
] = 1.0F
;
3505 const GLushort
*ussrc
= (const GLushort
*) src
;
3507 for (i
= 0; i
< n
; i
++) {
3508 GLushort p
= ussrc
[i
];
3509 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3510 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3511 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3512 rgba
[i
][aComp
] = 1.0F
;
3516 case GL_UNSIGNED_SHORT_4_4_4_4
:
3518 const GLushort
*ussrc
= (const GLushort
*) src
;
3520 for (i
= 0; i
< n
; i
++) {
3521 GLushort p
= ussrc
[i
];
3523 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3524 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3525 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3526 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3530 const GLushort
*ussrc
= (const GLushort
*) src
;
3532 for (i
= 0; i
< n
; i
++) {
3533 GLushort p
= ussrc
[i
];
3534 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3535 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3536 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3537 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3541 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3543 const GLushort
*ussrc
= (const GLushort
*) src
;
3545 for (i
= 0; i
< n
; i
++) {
3546 GLushort p
= ussrc
[i
];
3548 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3549 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3550 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3551 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3555 const GLushort
*ussrc
= (const GLushort
*) src
;
3557 for (i
= 0; i
< n
; i
++) {
3558 GLushort p
= ussrc
[i
];
3559 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3560 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3561 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3562 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3566 case GL_UNSIGNED_SHORT_5_5_5_1
:
3568 const GLushort
*ussrc
= (const GLushort
*) src
;
3570 for (i
= 0; i
< n
; i
++) {
3571 GLushort p
= ussrc
[i
];
3573 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3574 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3575 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3576 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3580 const GLushort
*ussrc
= (const GLushort
*) src
;
3582 for (i
= 0; i
< n
; i
++) {
3583 GLushort p
= ussrc
[i
];
3584 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3585 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3586 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3587 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3591 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3593 const GLushort
*ussrc
= (const GLushort
*) src
;
3595 for (i
= 0; i
< n
; i
++) {
3596 GLushort p
= ussrc
[i
];
3598 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3599 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3600 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3601 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3605 const GLushort
*ussrc
= (const GLushort
*) src
;
3607 for (i
= 0; i
< n
; i
++) {
3608 GLushort p
= ussrc
[i
];
3609 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3610 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3611 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3612 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3616 case GL_UNSIGNED_INT_8_8_8_8
:
3618 const GLuint
*uisrc
= (const GLuint
*) src
;
3620 for (i
= 0; i
< n
; i
++) {
3621 GLuint p
= uisrc
[i
];
3622 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3623 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3624 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3625 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3629 const GLuint
*uisrc
= (const GLuint
*) src
;
3631 for (i
= 0; i
< n
; i
++) {
3632 GLuint p
= uisrc
[i
];
3633 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3634 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3635 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3636 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3640 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3642 const GLuint
*uisrc
= (const GLuint
*) src
;
3644 for (i
= 0; i
< n
; i
++) {
3645 GLuint p
= uisrc
[i
];
3646 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3647 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3648 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3649 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3653 const GLuint
*uisrc
= (const GLuint
*) src
;
3655 for (i
= 0; i
< n
; i
++) {
3656 GLuint p
= uisrc
[i
];
3657 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3658 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3659 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3660 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3664 case GL_UNSIGNED_INT_10_10_10_2
:
3666 const GLuint
*uisrc
= (const GLuint
*) src
;
3668 for (i
= 0; i
< n
; i
++) {
3669 GLuint p
= uisrc
[i
];
3671 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3672 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3673 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3674 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3678 const GLuint
*uisrc
= (const GLuint
*) src
;
3680 for (i
= 0; i
< n
; i
++) {
3681 GLuint p
= uisrc
[i
];
3682 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3683 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3684 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3685 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3689 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3691 const GLuint
*uisrc
= (const GLuint
*) src
;
3693 for (i
= 0; i
< n
; i
++) {
3694 GLuint p
= uisrc
[i
];
3696 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3697 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3698 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3699 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3703 const GLuint
*uisrc
= (const GLuint
*) src
;
3705 for (i
= 0; i
< n
; i
++) {
3706 GLuint p
= uisrc
[i
];
3707 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3708 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3709 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3710 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3715 _mesa_problem(NULL
, "bad srcType in extract float data");
3722 * Unpack a row of color image data from a client buffer according to
3723 * the pixel unpacking parameters.
3724 * Return GLchan values in the specified dest image format.
3725 * This is used by glDrawPixels and glTexImage?D().
3726 * \param ctx - the context
3727 * n - number of pixels in the span
3728 * dstFormat - format of destination color array
3729 * dest - the destination color array
3730 * srcFormat - source image format
3731 * srcType - source image data type
3732 * source - source image pointer
3733 * srcPacking - pixel unpacking parameters
3734 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
3736 * XXX perhaps expand this to process whole images someday.
3739 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
3740 GLuint n
, GLenum dstFormat
, GLchan dest
[],
3741 GLenum srcFormat
, GLenum srcType
,
3742 const GLvoid
*source
,
3743 const struct gl_pixelstore_attrib
*srcPacking
,
3744 GLbitfield transferOps
)
3746 ASSERT(dstFormat
== GL_ALPHA
||
3747 dstFormat
== GL_LUMINANCE
||
3748 dstFormat
== GL_LUMINANCE_ALPHA
||
3749 dstFormat
== GL_INTENSITY
||
3750 dstFormat
== GL_RGB
||
3751 dstFormat
== GL_RGBA
||
3752 dstFormat
== GL_COLOR_INDEX
);
3754 ASSERT(srcFormat
== GL_RED
||
3755 srcFormat
== GL_GREEN
||
3756 srcFormat
== GL_BLUE
||
3757 srcFormat
== GL_ALPHA
||
3758 srcFormat
== GL_LUMINANCE
||
3759 srcFormat
== GL_LUMINANCE_ALPHA
||
3760 srcFormat
== GL_INTENSITY
||
3761 srcFormat
== GL_RGB
||
3762 srcFormat
== GL_BGR
||
3763 srcFormat
== GL_RGBA
||
3764 srcFormat
== GL_BGRA
||
3765 srcFormat
== GL_ABGR_EXT
||
3766 srcFormat
== GL_COLOR_INDEX
);
3768 ASSERT(srcType
== GL_BITMAP
||
3769 srcType
== GL_UNSIGNED_BYTE
||
3770 srcType
== GL_BYTE
||
3771 srcType
== GL_UNSIGNED_SHORT
||
3772 srcType
== GL_SHORT
||
3773 srcType
== GL_UNSIGNED_INT
||
3774 srcType
== GL_INT
||
3775 srcType
== GL_HALF_FLOAT_ARB
||
3776 srcType
== GL_FLOAT
||
3777 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3778 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3779 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3780 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3781 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3782 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3783 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3784 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3785 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3786 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3787 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3788 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3790 /* Try simple cases first */
3791 if (transferOps
== 0) {
3792 if (srcType
== CHAN_TYPE
) {
3793 if (dstFormat
== GL_RGBA
) {
3794 if (srcFormat
== GL_RGBA
) {
3795 _mesa_memcpy( dest
, source
, n
* 4 * sizeof(GLchan
) );
3798 else if (srcFormat
== GL_RGB
) {
3800 const GLchan
*src
= (const GLchan
*) source
;
3802 for (i
= 0; i
< n
; i
++) {
3813 else if (dstFormat
== GL_RGB
) {
3814 if (srcFormat
== GL_RGB
) {
3815 _mesa_memcpy( dest
, source
, n
* 3 * sizeof(GLchan
) );
3818 else if (srcFormat
== GL_RGBA
) {
3820 const GLchan
*src
= (const GLchan
*) source
;
3822 for (i
= 0; i
< n
; i
++) {
3832 else if (dstFormat
== srcFormat
) {
3833 GLint comps
= _mesa_components_in_format(srcFormat
);
3835 _mesa_memcpy( dest
, source
, n
* comps
* sizeof(GLchan
) );
3840 * Common situation, loading 8bit RGBA/RGB source images
3841 * into 16/32 bit destination. (OSMesa16/32)
3843 else if (srcType
== GL_UNSIGNED_BYTE
) {
3844 if (dstFormat
== GL_RGBA
) {
3845 if (srcFormat
== GL_RGB
) {
3847 const GLubyte
*src
= (const GLubyte
*) source
;
3849 for (i
= 0; i
< n
; i
++) {
3850 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3851 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3852 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3859 else if (srcFormat
== GL_RGBA
) {
3861 const GLubyte
*src
= (const GLubyte
*) source
;
3863 for (i
= 0; i
< n
; i
++) {
3864 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3865 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3866 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3867 dst
[3] = UBYTE_TO_CHAN(src
[3]);
3874 else if (dstFormat
== GL_RGB
) {
3875 if (srcFormat
== GL_RGB
) {
3877 const GLubyte
*src
= (const GLubyte
*) source
;
3879 for (i
= 0; i
< n
; i
++) {
3880 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3881 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3882 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3888 else if (srcFormat
== GL_RGBA
) {
3890 const GLubyte
*src
= (const GLubyte
*) source
;
3892 for (i
= 0; i
< n
; i
++) {
3893 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3894 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3895 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3906 /* general solution begins here */
3908 GLint dstComponents
;
3909 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3910 GLint dstLuminanceIndex
, dstIntensityIndex
;
3911 GLfloat rgba
[MAX_WIDTH
][4];
3913 dstComponents
= _mesa_components_in_format( dstFormat
);
3914 /* source & dest image formats should have been error checked by now */
3915 assert(dstComponents
> 0);
3918 * Extract image data and convert to RGBA floats
3920 assert(n
<= MAX_WIDTH
);
3921 if (srcFormat
== GL_COLOR_INDEX
) {
3922 GLuint indexes
[MAX_WIDTH
];
3923 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3926 if (dstFormat
== GL_COLOR_INDEX
) {
3928 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3929 /* convert to GLchan and return */
3930 for (i
= 0; i
< n
; i
++) {
3931 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3936 /* Convert indexes to RGBA */
3937 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3938 shift_and_offset_ci(ctx
, n
, indexes
);
3940 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3943 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3944 * with color indexes.
3946 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3949 /* non-color index data */
3950 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3951 srcPacking
->SwapBytes
);
3954 /* Need to clamp if returning GLubytes or GLushorts */
3955 #if CHAN_TYPE != GL_FLOAT
3956 transferOps
|= IMAGE_CLAMP_BIT
;
3960 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3963 /* Now determine which color channels we need to produce.
3964 * And determine the dest index (offset) within each color tuple.
3966 switch (dstFormat
) {
3969 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3970 dstLuminanceIndex
= dstIntensityIndex
= -1;
3973 dstLuminanceIndex
= 0;
3974 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3975 dstIntensityIndex
= -1;
3977 case GL_LUMINANCE_ALPHA
:
3978 dstLuminanceIndex
= 0;
3980 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3981 dstIntensityIndex
= -1;
3984 dstIntensityIndex
= 0;
3985 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3986 dstLuminanceIndex
= -1;
3992 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3999 dstLuminanceIndex
= dstIntensityIndex
= -1;
4002 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
4007 /* Now return the GLchan data in the requested dstFormat */
4009 if (dstRedIndex
>= 0) {
4012 for (i
= 0; i
< n
; i
++) {
4013 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
4014 dst
+= dstComponents
;
4018 if (dstGreenIndex
>= 0) {
4021 for (i
= 0; i
< n
; i
++) {
4022 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
4023 dst
+= dstComponents
;
4027 if (dstBlueIndex
>= 0) {
4030 for (i
= 0; i
< n
; i
++) {
4031 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
4032 dst
+= dstComponents
;
4036 if (dstAlphaIndex
>= 0) {
4039 for (i
= 0; i
< n
; i
++) {
4040 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
4041 dst
+= dstComponents
;
4045 if (dstIntensityIndex
>= 0) {
4048 assert(dstIntensityIndex
== 0);
4049 assert(dstComponents
== 1);
4050 for (i
= 0; i
< n
; i
++) {
4051 /* Intensity comes from red channel */
4052 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
4056 if (dstLuminanceIndex
>= 0) {
4059 assert(dstLuminanceIndex
== 0);
4060 for (i
= 0; i
< n
; i
++) {
4061 /* Luminance comes from red channel */
4062 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
4063 dst
+= dstComponents
;
4071 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
4072 * instead of GLchan.
4075 _mesa_unpack_color_span_float( GLcontext
*ctx
,
4076 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
4077 GLenum srcFormat
, GLenum srcType
,
4078 const GLvoid
*source
,
4079 const struct gl_pixelstore_attrib
*srcPacking
,
4080 GLbitfield transferOps
)
4082 ASSERT(dstFormat
== GL_ALPHA
||
4083 dstFormat
== GL_LUMINANCE
||
4084 dstFormat
== GL_LUMINANCE_ALPHA
||
4085 dstFormat
== GL_INTENSITY
||
4086 dstFormat
== GL_RGB
||
4087 dstFormat
== GL_RGBA
||
4088 dstFormat
== GL_COLOR_INDEX
);
4090 ASSERT(srcFormat
== GL_RED
||
4091 srcFormat
== GL_GREEN
||
4092 srcFormat
== GL_BLUE
||
4093 srcFormat
== GL_ALPHA
||
4094 srcFormat
== GL_LUMINANCE
||
4095 srcFormat
== GL_LUMINANCE_ALPHA
||
4096 srcFormat
== GL_INTENSITY
||
4097 srcFormat
== GL_RGB
||
4098 srcFormat
== GL_BGR
||
4099 srcFormat
== GL_RGBA
||
4100 srcFormat
== GL_BGRA
||
4101 srcFormat
== GL_ABGR_EXT
||
4102 srcFormat
== GL_COLOR_INDEX
);
4104 ASSERT(srcType
== GL_BITMAP
||
4105 srcType
== GL_UNSIGNED_BYTE
||
4106 srcType
== GL_BYTE
||
4107 srcType
== GL_UNSIGNED_SHORT
||
4108 srcType
== GL_SHORT
||
4109 srcType
== GL_UNSIGNED_INT
||
4110 srcType
== GL_INT
||
4111 srcType
== GL_HALF_FLOAT_ARB
||
4112 srcType
== GL_FLOAT
||
4113 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
4114 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
4115 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
4116 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
4117 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
4118 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
4119 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
4120 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
4121 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
4122 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
4123 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
4124 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
4126 /* general solution, no special cases, yet */
4128 GLint dstComponents
;
4129 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
4130 GLint dstLuminanceIndex
, dstIntensityIndex
;
4131 GLfloat rgba
[MAX_WIDTH
][4];
4133 dstComponents
= _mesa_components_in_format( dstFormat
);
4134 /* source & dest image formats should have been error checked by now */
4135 assert(dstComponents
> 0);
4138 * Extract image data and convert to RGBA floats
4140 assert(n
<= MAX_WIDTH
);
4141 if (srcFormat
== GL_COLOR_INDEX
) {
4142 GLuint indexes
[MAX_WIDTH
];
4143 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
4146 if (dstFormat
== GL_COLOR_INDEX
) {
4148 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4149 /* convert to GLchan and return */
4150 for (i
= 0; i
< n
; i
++) {
4151 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
4156 /* Convert indexes to RGBA */
4157 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
4158 shift_and_offset_ci(ctx
, n
, indexes
);
4160 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
4163 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
4164 * with color indexes.
4166 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
4169 /* non-color index data */
4170 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
4171 srcPacking
->SwapBytes
);
4175 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
4178 /* Now determine which color channels we need to produce.
4179 * And determine the dest index (offset) within each color tuple.
4181 switch (dstFormat
) {
4184 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
4185 dstLuminanceIndex
= dstIntensityIndex
= -1;
4188 dstLuminanceIndex
= 0;
4189 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
4190 dstIntensityIndex
= -1;
4192 case GL_LUMINANCE_ALPHA
:
4193 dstLuminanceIndex
= 0;
4195 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
4196 dstIntensityIndex
= -1;
4199 dstIntensityIndex
= 0;
4200 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
4201 dstLuminanceIndex
= -1;
4207 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
4214 dstLuminanceIndex
= dstIntensityIndex
= -1;
4217 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
4221 /* Now pack results in the requested dstFormat */
4222 if (dstRedIndex
>= 0) {
4223 GLfloat
*dst
= dest
;
4225 for (i
= 0; i
< n
; i
++) {
4226 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
4227 dst
+= dstComponents
;
4231 if (dstGreenIndex
>= 0) {
4232 GLfloat
*dst
= dest
;
4234 for (i
= 0; i
< n
; i
++) {
4235 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
4236 dst
+= dstComponents
;
4240 if (dstBlueIndex
>= 0) {
4241 GLfloat
*dst
= dest
;
4243 for (i
= 0; i
< n
; i
++) {
4244 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
4245 dst
+= dstComponents
;
4249 if (dstAlphaIndex
>= 0) {
4250 GLfloat
*dst
= dest
;
4252 for (i
= 0; i
< n
; i
++) {
4253 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
4254 dst
+= dstComponents
;
4258 if (dstIntensityIndex
>= 0) {
4259 GLfloat
*dst
= dest
;
4261 assert(dstIntensityIndex
== 0);
4262 assert(dstComponents
== 1);
4263 for (i
= 0; i
< n
; i
++) {
4264 /* Intensity comes from red channel */
4265 dst
[i
] = rgba
[i
][RCOMP
];
4269 if (dstLuminanceIndex
>= 0) {
4270 GLfloat
*dst
= dest
;
4272 assert(dstLuminanceIndex
== 0);
4273 for (i
= 0; i
< n
; i
++) {
4274 /* Luminance comes from red channel */
4275 dst
[0] = rgba
[i
][RCOMP
];
4276 dst
+= dstComponents
;
4283 * Similar to _mesa_unpack_color_span_float(), but for dudv data instead of rgba,
4284 * directly return GLbyte data, no transfer ops apply.
4287 _mesa_unpack_dudv_span_byte( GLcontext
*ctx
,
4288 GLuint n
, GLenum dstFormat
, GLbyte dest
[],
4289 GLenum srcFormat
, GLenum srcType
,
4290 const GLvoid
*source
,
4291 const struct gl_pixelstore_attrib
*srcPacking
,
4292 GLbitfield transferOps
)
4294 ASSERT(dstFormat
== GL_DUDV_ATI
);
4295 ASSERT(srcFormat
== GL_DUDV_ATI
);
4297 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
4298 srcType
== GL_BYTE
||
4299 srcType
== GL_UNSIGNED_SHORT
||
4300 srcType
== GL_SHORT
||
4301 srcType
== GL_UNSIGNED_INT
||
4302 srcType
== GL_INT
||
4303 srcType
== GL_HALF_FLOAT_ARB
||
4304 srcType
== GL_FLOAT
);
4306 /* general solution */
4308 GLint dstComponents
;
4309 GLfloat rgba
[MAX_WIDTH
][4];
4313 dstComponents
= _mesa_components_in_format( dstFormat
);
4314 /* source & dest image formats should have been error checked by now */
4315 assert(dstComponents
> 0);
4318 * Extract image data and convert to RGBA floats
4320 assert(n
<= MAX_WIDTH
);
4321 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
4322 srcPacking
->SwapBytes
);
4325 /* Now determine which color channels we need to produce.
4326 * And determine the dest index (offset) within each color tuple.
4329 /* Now pack results in the requested dstFormat */
4330 for (i
= 0; i
< n
; i
++) {
4331 /* not sure - need clamp[-1,1] here? */
4332 dst
[0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
4333 dst
[1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
4334 dst
+= dstComponents
;
4340 * Unpack a row of color index data from a client buffer according to
4341 * the pixel unpacking parameters.
4342 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
4344 * Args: ctx - the context
4345 * n - number of pixels
4346 * dstType - destination data type
4347 * dest - destination array
4348 * srcType - source pixel type
4349 * source - source data pointer
4350 * srcPacking - pixel unpacking parameters
4351 * transferOps - the pixel transfer operations to apply
4354 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
4355 GLenum dstType
, GLvoid
*dest
,
4356 GLenum srcType
, const GLvoid
*source
,
4357 const struct gl_pixelstore_attrib
*srcPacking
,
4358 GLbitfield transferOps
)
4360 ASSERT(srcType
== GL_BITMAP
||
4361 srcType
== GL_UNSIGNED_BYTE
||
4362 srcType
== GL_BYTE
||
4363 srcType
== GL_UNSIGNED_SHORT
||
4364 srcType
== GL_SHORT
||
4365 srcType
== GL_UNSIGNED_INT
||
4366 srcType
== GL_INT
||
4367 srcType
== GL_HALF_FLOAT_ARB
||
4368 srcType
== GL_FLOAT
);
4370 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4371 dstType
== GL_UNSIGNED_SHORT
||
4372 dstType
== GL_UNSIGNED_INT
);
4375 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4378 * Try simple cases first
4380 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
4381 && dstType
== GL_UNSIGNED_BYTE
) {
4382 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
4384 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
4385 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
4386 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
4392 GLuint indexes
[MAX_WIDTH
];
4393 assert(n
<= MAX_WIDTH
);
4395 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
4399 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4401 /* convert to dest type */
4403 case GL_UNSIGNED_BYTE
:
4405 GLubyte
*dst
= (GLubyte
*) dest
;
4407 for (i
= 0; i
< n
; i
++) {
4408 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4412 case GL_UNSIGNED_SHORT
:
4414 GLuint
*dst
= (GLuint
*) dest
;
4416 for (i
= 0; i
< n
; i
++) {
4417 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4421 case GL_UNSIGNED_INT
:
4422 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4425 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
4432 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
4433 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
4434 const struct gl_pixelstore_attrib
*dstPacking
,
4435 GLbitfield transferOps
)
4437 GLuint indexes
[MAX_WIDTH
];
4439 ASSERT(n
<= MAX_WIDTH
);
4441 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4443 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
4444 /* make a copy of input */
4445 _mesa_memcpy(indexes
, source
, n
* sizeof(GLuint
));
4446 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4451 case GL_UNSIGNED_BYTE
:
4453 GLubyte
*dst
= (GLubyte
*) dest
;
4455 for (i
= 0; i
< n
; i
++) {
4456 *dst
++ = (GLubyte
) source
[i
];
4462 GLbyte
*dst
= (GLbyte
*) dest
;
4464 for (i
= 0; i
< n
; i
++) {
4465 dst
[i
] = (GLbyte
) source
[i
];
4469 case GL_UNSIGNED_SHORT
:
4471 GLushort
*dst
= (GLushort
*) dest
;
4473 for (i
= 0; i
< n
; i
++) {
4474 dst
[i
] = (GLushort
) source
[i
];
4476 if (dstPacking
->SwapBytes
) {
4477 _mesa_swap2( (GLushort
*) dst
, n
);
4483 GLshort
*dst
= (GLshort
*) dest
;
4485 for (i
= 0; i
< n
; i
++) {
4486 dst
[i
] = (GLshort
) source
[i
];
4488 if (dstPacking
->SwapBytes
) {
4489 _mesa_swap2( (GLushort
*) dst
, n
);
4493 case GL_UNSIGNED_INT
:
4495 GLuint
*dst
= (GLuint
*) dest
;
4497 for (i
= 0; i
< n
; i
++) {
4498 dst
[i
] = (GLuint
) source
[i
];
4500 if (dstPacking
->SwapBytes
) {
4501 _mesa_swap4( (GLuint
*) dst
, n
);
4507 GLint
*dst
= (GLint
*) dest
;
4509 for (i
= 0; i
< n
; i
++) {
4510 dst
[i
] = (GLint
) source
[i
];
4512 if (dstPacking
->SwapBytes
) {
4513 _mesa_swap4( (GLuint
*) dst
, n
);
4519 GLfloat
*dst
= (GLfloat
*) dest
;
4521 for (i
= 0; i
< n
; i
++) {
4522 dst
[i
] = (GLfloat
) source
[i
];
4524 if (dstPacking
->SwapBytes
) {
4525 _mesa_swap4( (GLuint
*) dst
, n
);
4529 case GL_HALF_FLOAT_ARB
:
4531 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4533 for (i
= 0; i
< n
; i
++) {
4534 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
4536 if (dstPacking
->SwapBytes
) {
4537 _mesa_swap2( (GLushort
*) dst
, n
);
4542 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4548 * Unpack a row of stencil data from a client buffer according to
4549 * the pixel unpacking parameters.
4550 * This is (or will be) used by glDrawPixels
4552 * Args: ctx - the context
4553 * n - number of pixels
4554 * dstType - destination data type
4555 * dest - destination array
4556 * srcType - source pixel type
4557 * source - source data pointer
4558 * srcPacking - pixel unpacking parameters
4559 * transferOps - apply offset/bias/lookup ops?
4562 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4563 GLenum dstType
, GLvoid
*dest
,
4564 GLenum srcType
, const GLvoid
*source
,
4565 const struct gl_pixelstore_attrib
*srcPacking
,
4566 GLbitfield transferOps
)
4568 ASSERT(srcType
== GL_BITMAP
||
4569 srcType
== GL_UNSIGNED_BYTE
||
4570 srcType
== GL_BYTE
||
4571 srcType
== GL_UNSIGNED_SHORT
||
4572 srcType
== GL_SHORT
||
4573 srcType
== GL_UNSIGNED_INT
||
4574 srcType
== GL_INT
||
4575 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
4576 srcType
== GL_HALF_FLOAT_ARB
||
4577 srcType
== GL_FLOAT
);
4579 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4580 dstType
== GL_UNSIGNED_SHORT
||
4581 dstType
== GL_UNSIGNED_INT
);
4583 /* only shift and offset apply to stencil */
4584 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
4587 * Try simple cases first
4589 if (transferOps
== 0 &&
4590 !ctx
->Pixel
.MapStencilFlag
&&
4591 srcType
== GL_UNSIGNED_BYTE
&&
4592 dstType
== GL_UNSIGNED_BYTE
) {
4593 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
4595 else if (transferOps
== 0 &&
4596 !ctx
->Pixel
.MapStencilFlag
&&
4597 srcType
== GL_UNSIGNED_INT
&&
4598 dstType
== GL_UNSIGNED_INT
&&
4599 !srcPacking
->SwapBytes
) {
4600 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
4606 GLuint indexes
[MAX_WIDTH
];
4607 assert(n
<= MAX_WIDTH
);
4609 extract_uint_indexes(n
, indexes
, GL_STENCIL_INDEX
, srcType
, source
,
4612 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
4613 /* shift and offset indexes */
4614 shift_and_offset_ci(ctx
, n
, indexes
);
4617 if (ctx
->Pixel
.MapStencilFlag
) {
4618 /* Apply stencil lookup table */
4619 const GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
4621 for (i
= 0; i
< n
; i
++) {
4622 indexes
[i
] = (GLuint
)ctx
->PixelMaps
.StoS
.Map
[ indexes
[i
] & mask
];
4626 /* convert to dest type */
4628 case GL_UNSIGNED_BYTE
:
4630 GLubyte
*dst
= (GLubyte
*) dest
;
4632 for (i
= 0; i
< n
; i
++) {
4633 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4637 case GL_UNSIGNED_SHORT
:
4639 GLuint
*dst
= (GLuint
*) dest
;
4641 for (i
= 0; i
< n
; i
++) {
4642 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4646 case GL_UNSIGNED_INT
:
4647 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4650 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
4657 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4658 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
4659 const struct gl_pixelstore_attrib
*dstPacking
)
4661 GLstencil stencil
[MAX_WIDTH
];
4663 ASSERT(n
<= MAX_WIDTH
);
4665 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
4666 ctx
->Pixel
.MapStencilFlag
) {
4667 /* make a copy of input */
4668 _mesa_memcpy(stencil
, source
, n
* sizeof(GLstencil
));
4669 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencil
);
4674 case GL_UNSIGNED_BYTE
:
4675 if (sizeof(GLstencil
) == 1) {
4676 _mesa_memcpy( dest
, source
, n
);
4679 GLubyte
*dst
= (GLubyte
*) dest
;
4682 dst
[i
] = (GLubyte
) source
[i
];
4688 GLbyte
*dst
= (GLbyte
*) dest
;
4691 dst
[i
] = (GLbyte
) (source
[i
] & 0x7f);
4695 case GL_UNSIGNED_SHORT
:
4697 GLushort
*dst
= (GLushort
*) dest
;
4700 dst
[i
] = (GLushort
) source
[i
];
4702 if (dstPacking
->SwapBytes
) {
4703 _mesa_swap2( (GLushort
*) dst
, n
);
4709 GLshort
*dst
= (GLshort
*) dest
;
4712 dst
[i
] = (GLshort
) source
[i
];
4714 if (dstPacking
->SwapBytes
) {
4715 _mesa_swap2( (GLushort
*) dst
, n
);
4719 case GL_UNSIGNED_INT
:
4721 GLuint
*dst
= (GLuint
*) dest
;
4724 dst
[i
] = (GLuint
) source
[i
];
4726 if (dstPacking
->SwapBytes
) {
4727 _mesa_swap4( (GLuint
*) dst
, n
);
4733 GLint
*dst
= (GLint
*) dest
;
4736 dst
[i
] = (GLint
) source
[i
];
4738 if (dstPacking
->SwapBytes
) {
4739 _mesa_swap4( (GLuint
*) dst
, n
);
4745 GLfloat
*dst
= (GLfloat
*) dest
;
4748 dst
[i
] = (GLfloat
) source
[i
];
4750 if (dstPacking
->SwapBytes
) {
4751 _mesa_swap4( (GLuint
*) dst
, n
);
4755 case GL_HALF_FLOAT_ARB
:
4757 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4760 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
4762 if (dstPacking
->SwapBytes
) {
4763 _mesa_swap2( (GLushort
*) dst
, n
);
4768 if (dstPacking
->LsbFirst
) {
4769 GLubyte
*dst
= (GLubyte
*) dest
;
4772 for (i
= 0; i
< n
; i
++) {
4775 *dst
|= ((source
[i
] != 0) << shift
);
4784 GLubyte
*dst
= (GLubyte
*) dest
;
4787 for (i
= 0; i
< n
; i
++) {
4790 *dst
|= ((source
[i
] != 0) << shift
);
4800 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4804 #define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT) \
4807 const GLTYPE *src = (const GLTYPE *)source; \
4808 for (i = 0; i < n; i++) { \
4809 GLTYPE value = src[i]; \
4810 if (srcPacking->SwapBytes) { \
4811 if (sizeof(GLTYPE) == 2) { \
4813 } else if (sizeof(GLTYPE) == 4) { \
4817 depthValues[i] = GLTYPE2FLOAT(value); \
4823 * Unpack a row of depth/z values from memory, returning GLushort, GLuint
4824 * or GLfloat values.
4825 * The glPixelTransfer (scale/bias) params will be applied.
4827 * \param dstType one of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT
4828 * \param depthMax max value for returned GLushort or GLuint values
4829 * (ignored for GLfloat).
4832 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
,
4833 GLenum dstType
, GLvoid
*dest
, GLuint depthMax
,
4834 GLenum srcType
, const GLvoid
*source
,
4835 const struct gl_pixelstore_attrib
*srcPacking
)
4837 GLfloat depthTemp
[MAX_WIDTH
], *depthValues
;
4838 GLboolean needClamp
= GL_FALSE
;
4840 /* Look for special cases first.
4841 * Not only are these faster, they're less prone to numeric conversion
4842 * problems. Otherwise, converting from an int type to a float then
4843 * back to an int type can introduce errors that will show up as
4844 * artifacts in things like depth peeling which uses glCopyTexImage.
4846 if (ctx
->Pixel
.DepthScale
== 1.0 && ctx
->Pixel
.DepthBias
== 0.0) {
4847 if (srcType
== GL_UNSIGNED_INT
&& dstType
== GL_UNSIGNED_SHORT
) {
4848 const GLuint
*src
= (const GLuint
*) source
;
4849 GLushort
*dst
= (GLushort
*) dest
;
4851 for (i
= 0; i
< n
; i
++) {
4852 dst
[i
] = src
[i
] >> 16;
4856 if (srcType
== GL_UNSIGNED_SHORT
4857 && dstType
== GL_UNSIGNED_INT
4858 && depthMax
== 0xffffffff) {
4859 const GLushort
*src
= (const GLushort
*) source
;
4860 GLuint
*dst
= (GLuint
*) dest
;
4862 for (i
= 0; i
< n
; i
++) {
4863 dst
[i
] = src
[i
] | (src
[i
] << 16);
4867 if (srcType
== GL_UNSIGNED_INT_24_8
4868 && dstType
== GL_UNSIGNED_INT
4869 && depthMax
== 0xffffff) {
4870 const GLuint
*src
= (const GLuint
*) source
;
4871 GLuint
*dst
= (GLuint
*) dest
;
4873 for (i
= 0; i
< n
; i
++) {
4874 dst
[i
] = src
[i
] >> 8;
4878 /* XXX may want to add additional cases here someday */
4881 /* general case path follows */
4883 if (dstType
== GL_FLOAT
) {
4884 depthValues
= (GLfloat
*) dest
;
4887 depthValues
= depthTemp
;
4890 /* Convert incoming values to GLfloat. Some conversions will require
4895 DEPTH_VALUES(GLbyte
, BYTE_TO_FLOAT
);
4896 needClamp
= GL_TRUE
;
4898 case GL_UNSIGNED_BYTE
:
4899 DEPTH_VALUES(GLubyte
, UBYTE_TO_FLOAT
);
4902 DEPTH_VALUES(GLshort
, SHORT_TO_FLOAT
);
4903 needClamp
= GL_TRUE
;
4905 case GL_UNSIGNED_SHORT
:
4906 DEPTH_VALUES(GLushort
, USHORT_TO_FLOAT
);
4909 DEPTH_VALUES(GLint
, INT_TO_FLOAT
);
4910 needClamp
= GL_TRUE
;
4912 case GL_UNSIGNED_INT
:
4913 DEPTH_VALUES(GLuint
, UINT_TO_FLOAT
);
4915 case GL_UNSIGNED_INT_24_8_EXT
: /* GL_EXT_packed_depth_stencil */
4916 if (dstType
== GL_UNSIGNED_INT_24_8_EXT
&&
4917 depthMax
== 0xffffff &&
4918 ctx
->Pixel
.DepthScale
== 1.0 &&
4919 ctx
->Pixel
.DepthBias
== 0.0) {
4920 const GLuint
*src
= (const GLuint
*) source
;
4921 GLuint
*zValues
= (GLuint
*) dest
;
4923 for (i
= 0; i
< n
; i
++) {
4924 GLuint value
= src
[i
];
4925 if (srcPacking
->SwapBytes
) {
4928 zValues
[i
] = value
& 0xffffff00;
4933 const GLuint
*src
= (const GLuint
*) source
;
4934 const GLfloat scale
= 1.0f
/ 0xffffff;
4936 for (i
= 0; i
< n
; i
++) {
4937 GLuint value
= src
[i
];
4938 if (srcPacking
->SwapBytes
) {
4941 depthValues
[i
] = (value
>> 8) * scale
;
4946 DEPTH_VALUES(GLfloat
, 1*);
4947 needClamp
= GL_TRUE
;
4949 case GL_HALF_FLOAT_ARB
:
4952 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
4953 for (i
= 0; i
< n
; i
++) {
4954 GLhalfARB value
= src
[i
];
4955 if (srcPacking
->SwapBytes
) {
4958 depthValues
[i
] = _mesa_half_to_float(value
);
4960 needClamp
= GL_TRUE
;
4964 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
4968 /* apply depth scale and bias */
4970 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
4971 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
4972 if (scale
!= 1.0 || bias
!= 0.0) {
4974 for (i
= 0; i
< n
; i
++) {
4975 depthValues
[i
] = depthValues
[i
] * scale
+ bias
;
4977 needClamp
= GL_TRUE
;
4981 /* clamp to [0, 1] */
4984 for (i
= 0; i
< n
; i
++) {
4985 depthValues
[i
] = (GLfloat
)CLAMP(depthValues
[i
], 0.0, 1.0);
4990 * Convert values to dstType
4992 if (dstType
== GL_UNSIGNED_INT
) {
4993 GLuint
*zValues
= (GLuint
*) dest
;
4995 if (depthMax
<= 0xffffff) {
4996 /* no overflow worries */
4997 for (i
= 0; i
< n
; i
++) {
4998 zValues
[i
] = (GLuint
) (depthValues
[i
] * (GLfloat
) depthMax
);
5002 /* need to use double precision to prevent overflow problems */
5003 for (i
= 0; i
< n
; i
++) {
5004 GLdouble z
= depthValues
[i
] * (GLfloat
) depthMax
;
5005 if (z
>= (GLdouble
) 0xffffffff)
5006 zValues
[i
] = 0xffffffff;
5008 zValues
[i
] = (GLuint
) z
;
5012 else if (dstType
== GL_UNSIGNED_SHORT
) {
5013 GLushort
*zValues
= (GLushort
*) dest
;
5015 ASSERT(depthMax
<= 0xffff);
5016 for (i
= 0; i
< n
; i
++) {
5017 zValues
[i
] = (GLushort
) (depthValues
[i
] * (GLfloat
) depthMax
);
5021 ASSERT(dstType
== GL_FLOAT
);
5022 /*ASSERT(depthMax == 1.0F);*/
5028 * Pack an array of depth values. The values are floats in [0,1].
5031 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
5032 GLenum dstType
, const GLfloat
*depthSpan
,
5033 const struct gl_pixelstore_attrib
*dstPacking
)
5035 GLfloat depthCopy
[MAX_WIDTH
];
5037 ASSERT(n
<= MAX_WIDTH
);
5039 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
5040 _mesa_memcpy(depthCopy
, depthSpan
, n
* sizeof(GLfloat
));
5041 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
5042 depthSpan
= depthCopy
;
5046 case GL_UNSIGNED_BYTE
:
5048 GLubyte
*dst
= (GLubyte
*) dest
;
5050 for (i
= 0; i
< n
; i
++) {
5051 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
5057 GLbyte
*dst
= (GLbyte
*) dest
;
5059 for (i
= 0; i
< n
; i
++) {
5060 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
5064 case GL_UNSIGNED_SHORT
:
5066 GLushort
*dst
= (GLushort
*) dest
;
5068 for (i
= 0; i
< n
; i
++) {
5069 CLAMPED_FLOAT_TO_USHORT(dst
[i
], depthSpan
[i
]);
5071 if (dstPacking
->SwapBytes
) {
5072 _mesa_swap2( (GLushort
*) dst
, n
);
5078 GLshort
*dst
= (GLshort
*) dest
;
5080 for (i
= 0; i
< n
; i
++) {
5081 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
5083 if (dstPacking
->SwapBytes
) {
5084 _mesa_swap2( (GLushort
*) dst
, n
);
5088 case GL_UNSIGNED_INT
:
5090 GLuint
*dst
= (GLuint
*) dest
;
5092 for (i
= 0; i
< n
; i
++) {
5093 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
5095 if (dstPacking
->SwapBytes
) {
5096 _mesa_swap4( (GLuint
*) dst
, n
);
5102 GLint
*dst
= (GLint
*) dest
;
5104 for (i
= 0; i
< n
; i
++) {
5105 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
5107 if (dstPacking
->SwapBytes
) {
5108 _mesa_swap4( (GLuint
*) dst
, n
);
5114 GLfloat
*dst
= (GLfloat
*) dest
;
5116 for (i
= 0; i
< n
; i
++) {
5117 dst
[i
] = depthSpan
[i
];
5119 if (dstPacking
->SwapBytes
) {
5120 _mesa_swap4( (GLuint
*) dst
, n
);
5124 case GL_HALF_FLOAT_ARB
:
5126 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
5128 for (i
= 0; i
< n
; i
++) {
5129 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
5131 if (dstPacking
->SwapBytes
) {
5132 _mesa_swap2( (GLushort
*) dst
, n
);
5137 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
5144 * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
5147 _mesa_pack_depth_stencil_span(const GLcontext
*ctx
, GLuint n
, GLuint
*dest
,
5148 const GLfloat
*depthVals
,
5149 const GLstencil
*stencilVals
,
5150 const struct gl_pixelstore_attrib
*dstPacking
)
5152 GLfloat depthCopy
[MAX_WIDTH
];
5153 GLstencil stencilCopy
[MAX_WIDTH
];
5156 ASSERT(n
<= MAX_WIDTH
);
5158 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
5159 _mesa_memcpy(depthCopy
, depthVals
, n
* sizeof(GLfloat
));
5160 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
5161 depthVals
= depthCopy
;
5164 if (ctx
->Pixel
.IndexShift
||
5165 ctx
->Pixel
.IndexOffset
||
5166 ctx
->Pixel
.MapStencilFlag
) {
5167 _mesa_memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
5168 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencilCopy
);
5169 stencilVals
= stencilCopy
;
5172 for (i
= 0; i
< n
; i
++) {
5173 GLuint z
= (GLuint
) (depthVals
[i
] * 0xffffff);
5174 dest
[i
] = (z
<< 8) | (stencilVals
[i
] & 0xff);
5177 if (dstPacking
->SwapBytes
) {
5178 _mesa_swap4(dest
, n
);
5186 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
5187 * Return all image data in a contiguous block. This is used when we
5188 * compile glDrawPixels, glTexImage, etc into a display list. We
5189 * need a copy of the data in a standard format.
5192 _mesa_unpack_image( GLuint dimensions
,
5193 GLsizei width
, GLsizei height
, GLsizei depth
,
5194 GLenum format
, GLenum type
, const GLvoid
*pixels
,
5195 const struct gl_pixelstore_attrib
*unpack
)
5197 GLint bytesPerRow
, compsPerRow
;
5198 GLboolean flipBytes
, swap2
, swap4
;
5201 return NULL
; /* not necessarily an error */
5203 if (width
<= 0 || height
<= 0 || depth
<= 0)
5204 return NULL
; /* generate error later */
5206 if (type
== GL_BITMAP
) {
5207 bytesPerRow
= (width
+ 7) >> 3;
5208 flipBytes
= unpack
->LsbFirst
;
5209 swap2
= swap4
= GL_FALSE
;
5213 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
5214 GLint components
= _mesa_components_in_format(format
);
5217 if (_mesa_type_is_packed(type
))
5220 if (bytesPerPixel
<= 0 || components
<= 0)
5221 return NULL
; /* bad format or type. generate error later */
5222 bytesPerRow
= bytesPerPixel
* width
;
5223 bytesPerComp
= bytesPerPixel
/ components
;
5224 flipBytes
= GL_FALSE
;
5225 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
5226 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
5227 compsPerRow
= components
* width
;
5228 assert(compsPerRow
>= width
);
5233 = (GLubyte
*) _mesa_malloc(bytesPerRow
* height
* depth
);
5237 return NULL
; /* generate GL_OUT_OF_MEMORY later */
5240 for (img
= 0; img
< depth
; img
++) {
5241 for (row
= 0; row
< height
; row
++) {
5242 const GLvoid
*src
= _mesa_image_address(dimensions
, unpack
, pixels
,
5243 width
, height
, format
, type
, img
, row
, 0);
5245 if ((type
== GL_BITMAP
) && (unpack
->SkipPixels
& 0x7)) {
5247 flipBytes
= GL_FALSE
;
5248 if (unpack
->LsbFirst
) {
5249 GLubyte srcMask
= 1 << (unpack
->SkipPixels
& 0x7);
5250 GLubyte dstMask
= 128;
5251 const GLubyte
*s
= src
;
5254 for (i
= 0; i
< width
; i
++) {
5258 if (srcMask
== 128) {
5263 srcMask
= srcMask
<< 1;
5271 dstMask
= dstMask
>> 1;
5276 GLubyte srcMask
= 128 >> (unpack
->SkipPixels
& 0x7);
5277 GLubyte dstMask
= 128;
5278 const GLubyte
*s
= src
;
5281 for (i
= 0; i
< width
; i
++) {
5290 srcMask
= srcMask
>> 1;
5298 dstMask
= dstMask
>> 1;
5304 _mesa_memcpy(dst
, src
, bytesPerRow
);
5307 /* byte flipping/swapping */
5309 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
5312 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
5315 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
5324 #endif /* _HAVE_FULL_GL */
5329 * Convert an array of RGBA colors from one datatype to another.
5330 * NOTE: src may equal dst. In that case, we use a temporary buffer.
5333 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
5334 GLenum dstType
, GLvoid
*dst
,
5335 GLuint count
, const GLubyte mask
[])
5337 GLuint tempBuffer
[MAX_WIDTH
][4];
5338 const GLboolean useTemp
= (src
== dst
);
5340 ASSERT(srcType
!= dstType
);
5343 case GL_UNSIGNED_BYTE
:
5344 if (dstType
== GL_UNSIGNED_SHORT
) {
5345 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5346 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5348 for (i
= 0; i
< count
; i
++) {
5349 if (!mask
|| mask
[i
]) {
5350 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
5351 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
5352 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
5353 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
5357 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5360 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5361 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5363 ASSERT(dstType
== GL_FLOAT
);
5364 for (i
= 0; i
< count
; i
++) {
5365 if (!mask
|| mask
[i
]) {
5366 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
5367 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
5368 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
5369 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
5373 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5376 case GL_UNSIGNED_SHORT
:
5377 if (dstType
== GL_UNSIGNED_BYTE
) {
5378 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5379 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5381 for (i
= 0; i
< count
; i
++) {
5382 if (!mask
|| mask
[i
]) {
5383 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
5384 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
5385 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
5386 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
5390 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5393 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5394 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5396 ASSERT(dstType
== GL_FLOAT
);
5397 for (i
= 0; i
< count
; i
++) {
5398 if (!mask
|| mask
[i
]) {
5399 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
5400 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
5401 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
5402 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
5406 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5410 if (dstType
== GL_UNSIGNED_BYTE
) {
5411 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5412 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5414 for (i
= 0; i
< count
; i
++) {
5415 if (!mask
|| mask
[i
]) {
5416 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
5417 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
5418 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
5419 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
5423 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5426 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5427 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5429 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
5430 for (i
= 0; i
< count
; i
++) {
5431 if (!mask
|| mask
[i
]) {
5432 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
5433 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
5434 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
5435 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
5439 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5443 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
5451 * Perform basic clipping for glDrawPixels. The image's position and size
5452 * and the unpack SkipPixels and SkipRows are adjusted so that the image
5453 * region is entirely within the window and scissor bounds.
5454 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
5455 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
5456 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
5458 * \return GL_TRUE if image is ready for drawing or
5459 * GL_FALSE if image was completely clipped away (draw nothing)
5462 _mesa_clip_drawpixels(const GLcontext
*ctx
,
5463 GLint
*destX
, GLint
*destY
,
5464 GLsizei
*width
, GLsizei
*height
,
5465 struct gl_pixelstore_attrib
*unpack
)
5467 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
5469 if (unpack
->RowLength
== 0) {
5470 unpack
->RowLength
= *width
;
5473 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
5474 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
5477 if (*destX
< buffer
->_Xmin
) {
5478 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
5479 *width
-= (buffer
->_Xmin
- *destX
);
5480 *destX
= buffer
->_Xmin
;
5482 /* right clipping */
5483 if (*destX
+ *width
> buffer
->_Xmax
)
5484 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
5489 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
5490 /* bottom clipping */
5491 if (*destY
< buffer
->_Ymin
) {
5492 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
5493 *height
-= (buffer
->_Ymin
- *destY
);
5494 *destY
= buffer
->_Ymin
;
5497 if (*destY
+ *height
> buffer
->_Ymax
)
5498 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
5500 else { /* upside down */
5502 if (*destY
> buffer
->_Ymax
) {
5503 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
5504 *height
-= (*destY
- buffer
->_Ymax
);
5505 *destY
= buffer
->_Ymax
;
5507 /* bottom clipping */
5508 if (*destY
- *height
< buffer
->_Ymin
)
5509 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
5510 /* adjust destY so it's the first row to write to */
5522 * Perform clipping for glReadPixels. The image's window position
5523 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
5524 * so that the image region is entirely within the window bounds.
5525 * Note: this is different from _mesa_clip_drawpixels() in that the
5526 * scissor box is ignored, and we use the bounds of the current readbuffer
5529 * \return GL_TRUE if image is ready for drawing or
5530 * GL_FALSE if image was completely clipped away (draw nothing)
5533 _mesa_clip_readpixels(const GLcontext
*ctx
,
5534 GLint
*srcX
, GLint
*srcY
,
5535 GLsizei
*width
, GLsizei
*height
,
5536 struct gl_pixelstore_attrib
*pack
)
5538 const GLframebuffer
*buffer
= ctx
->ReadBuffer
;
5540 if (pack
->RowLength
== 0) {
5541 pack
->RowLength
= *width
;
5546 pack
->SkipPixels
+= (0 - *srcX
);
5547 *width
-= (0 - *srcX
);
5550 /* right clipping */
5551 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
5552 *width
-= (*srcX
+ *width
- buffer
->Width
);
5557 /* bottom clipping */
5559 pack
->SkipRows
+= (0 - *srcY
);
5560 *height
-= (0 - *srcY
);
5564 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
5565 *height
-= (*srcY
+ *height
- buffer
->Height
);
5575 * Do clipping for a glCopyTexSubImage call.
5576 * The framebuffer source region might extend outside the framebuffer
5577 * bounds. Clip the source region against the framebuffer bounds and
5578 * adjust the texture/dest position and size accordingly.
5580 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
5583 _mesa_clip_copytexsubimage(const GLcontext
*ctx
,
5584 GLint
*destX
, GLint
*destY
,
5585 GLint
*srcX
, GLint
*srcY
,
5586 GLsizei
*width
, GLsizei
*height
)
5588 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
5589 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
5591 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
5592 srcX
, srcY
, width
, height
)) {
5593 *destX
= *destX
+ *srcX
- srcX0
;
5594 *destY
= *destY
+ *srcY
- srcY0
;
5606 * Clip the rectangle defined by (x, y, width, height) against the bounds
5607 * specified by [xmin, xmax) and [ymin, ymax).
5608 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
5611 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
5612 GLint xmax
, GLint ymax
,
5614 GLsizei
*width
, GLsizei
*height
)
5618 *width
-= (xmin
- *x
);
5622 /* right clipping */
5623 if (*x
+ *width
> xmax
)
5624 *width
-= (*x
+ *width
- xmax
);
5629 /* bottom (or top) clipping */
5631 *height
-= (ymin
- *y
);
5635 /* top (or bottom) clipping */
5636 if (*y
+ *height
> ymax
)
5637 *height
-= (*y
+ *height
- ymax
);
5647 * Clip dst coords against Xmax (or Ymax).
5650 clip_right_or_top(GLint
*srcX0
, GLint
*srcX1
,
5651 GLint
*dstX0
, GLint
*dstX1
,
5656 if (*dstX1
> maxValue
) {
5657 /* X1 outside right edge */
5658 ASSERT(*dstX0
< maxValue
); /* X0 should be inside right edge */
5659 t
= (GLfloat
) (maxValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
5660 /* chop off [t, 1] part */
5661 ASSERT(t
>= 0.0 && t
<= 1.0);
5663 bias
= (*srcX0
< *srcX1
) ? 0.5 : -0.5;
5664 *srcX1
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
5666 else if (*dstX0
> maxValue
) {
5667 /* X0 outside right edge */
5668 ASSERT(*dstX1
< maxValue
); /* X1 should be inside right edge */
5669 t
= (GLfloat
) (maxValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
5670 /* chop off [t, 1] part */
5671 ASSERT(t
>= 0.0 && t
<= 1.0);
5673 bias
= (*srcX0
< *srcX1
) ? -0.5 : 0.5;
5674 *srcX0
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
5680 * Clip dst coords against Xmin (or Ymin).
5683 clip_left_or_bottom(GLint
*srcX0
, GLint
*srcX1
,
5684 GLint
*dstX0
, GLint
*dstX1
,
5689 if (*dstX0
< minValue
) {
5690 /* X0 outside left edge */
5691 ASSERT(*dstX1
> minValue
); /* X1 should be inside left edge */
5692 t
= (GLfloat
) (minValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
5693 /* chop off [0, t] part */
5694 ASSERT(t
>= 0.0 && t
<= 1.0);
5696 bias
= (*srcX0
< *srcX1
) ? 0.5 : -0.5; /* flipped??? */
5697 *srcX0
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
5699 else if (*dstX1
< minValue
) {
5700 /* X1 outside left edge */
5701 ASSERT(*dstX0
> minValue
); /* X0 should be inside left edge */
5702 t
= (GLfloat
) (minValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
5703 /* chop off [0, t] part */
5704 ASSERT(t
>= 0.0 && t
<= 1.0);
5706 bias
= (*srcX0
< *srcX1
) ? 0.5 : -0.5;
5707 *srcX1
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
5713 * Do clipping of blit src/dest rectangles.
5714 * The dest rect is clipped against both the buffer bounds and scissor bounds.
5715 * The src rect is just clipped against the buffer bounds.
5717 * When either the src or dest rect is clipped, the other is also clipped
5720 * Note that X0 need not be less than X1 (same for Y) for either the source
5721 * and dest rects. That makes the clipping a little trickier.
5723 * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
5726 _mesa_clip_blit(GLcontext
*ctx
,
5727 GLint
*srcX0
, GLint
*srcY0
, GLint
*srcX1
, GLint
*srcY1
,
5728 GLint
*dstX0
, GLint
*dstY0
, GLint
*dstX1
, GLint
*dstY1
)
5730 const GLint srcXmin
= 0;
5731 const GLint srcXmax
= ctx
->ReadBuffer
->Width
;
5732 const GLint srcYmin
= 0;
5733 const GLint srcYmax
= ctx
->ReadBuffer
->Height
;
5735 /* these include scissor bounds */
5736 const GLint dstXmin
= ctx
->DrawBuffer
->_Xmin
;
5737 const GLint dstXmax
= ctx
->DrawBuffer
->_Xmax
;
5738 const GLint dstYmin
= ctx
->DrawBuffer
->_Ymin
;
5739 const GLint dstYmax
= ctx
->DrawBuffer
->_Ymax
;
5742 printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
5743 *srcX0, *srcX1, *dstX0, *dstX1);
5744 printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
5745 *srcY0, *srcY1, *dstY0, *dstY1);
5748 /* trivial rejection tests */
5749 if (*dstX0
== *dstX1
)
5750 return GL_FALSE
; /* no width */
5751 if (*dstX0
<= dstXmin
&& *dstX1
<= dstXmin
)
5752 return GL_FALSE
; /* totally out (left) of bounds */
5753 if (*dstX0
>= dstXmax
&& *dstX1
>= dstXmax
)
5754 return GL_FALSE
; /* totally out (right) of bounds */
5756 if (*dstY0
== *dstY1
)
5758 if (*dstY0
<= dstYmin
&& *dstY1
<= dstYmin
)
5760 if (*dstY0
>= dstYmax
&& *dstY1
>= dstYmax
)
5763 if (*srcX0
== *srcX1
)
5765 if (*srcX0
<= srcXmin
&& *srcX1
<= srcXmin
)
5767 if (*srcX0
>= srcXmax
&& *srcX1
>= srcXmax
)
5770 if (*srcY0
== *srcY1
)
5772 if (*srcY0
<= srcYmin
&& *srcY1
<= srcYmin
)
5774 if (*srcY0
>= srcYmax
&& *srcY1
>= srcYmax
)
5780 clip_right_or_top(srcX0
, srcX1
, dstX0
, dstX1
, dstXmax
);
5781 clip_right_or_top(srcY0
, srcY1
, dstY0
, dstY1
, dstYmax
);
5782 clip_left_or_bottom(srcX0
, srcX1
, dstX0
, dstX1
, dstXmin
);
5783 clip_left_or_bottom(srcY0
, srcY1
, dstY0
, dstY1
, dstYmin
);
5786 * src clip (just swap src/dst values from above)
5788 clip_right_or_top(dstX0
, dstX1
, srcX0
, srcX1
, srcXmax
);
5789 clip_right_or_top(dstY0
, dstY1
, srcY0
, srcY1
, srcYmax
);
5790 clip_left_or_bottom(dstX0
, dstX1
, srcX0
, srcX1
, srcXmin
);
5791 clip_left_or_bottom(dstY0
, dstY1
, srcY0
, srcY1
, srcYmin
);
5794 printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
5795 *srcX0, *srcX1, *dstX0, *dstX1);
5796 printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
5797 *srcY0, *srcY1, *dstY0, *dstY1);
5800 ASSERT(*dstX0
>= dstXmin
);
5801 ASSERT(*dstX0
<= dstXmax
);
5802 ASSERT(*dstX1
>= dstXmin
);
5803 ASSERT(*dstX1
<= dstXmax
);
5805 ASSERT(*dstY0
>= dstYmin
);
5806 ASSERT(*dstY0
<= dstYmax
);
5807 ASSERT(*dstY1
>= dstYmin
);
5808 ASSERT(*dstY1
<= dstYmax
);
5810 ASSERT(*srcX0
>= srcXmin
);
5811 ASSERT(*srcX0
<= srcXmax
);
5812 ASSERT(*srcX1
>= srcXmin
);
5813 ASSERT(*srcX1
<= srcXmax
);
5815 ASSERT(*srcY0
>= srcYmin
);
5816 ASSERT(*srcY0
<= srcYmax
);
5817 ASSERT(*srcY1
>= srcYmin
);
5818 ASSERT(*srcY1
<= srcYmax
);