2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
45 * we later convert the float to a packed integer value (such as for
46 * GL_RGB5_A1) because we'll wind up with a non-zero value.
48 * We redefine the macros here so zero is handled correctly.
51 #define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
54 #define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
58 /** Compute ceiling of integer quotient of A divided by B. */
59 #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
63 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
66 _mesa_type_is_packed(GLenum type
)
69 case GL_UNSIGNED_BYTE_3_3_2
:
70 case GL_UNSIGNED_BYTE_2_3_3_REV
:
71 case GL_UNSIGNED_SHORT_5_6_5
:
72 case GL_UNSIGNED_SHORT_5_6_5_REV
:
73 case GL_UNSIGNED_SHORT_4_4_4_4
:
74 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
75 case GL_UNSIGNED_SHORT_5_5_5_1
:
76 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
77 case GL_UNSIGNED_INT_8_8_8_8
:
78 case GL_UNSIGNED_INT_8_8_8_8_REV
:
79 case GL_UNSIGNED_INT_10_10_10_2
:
80 case GL_UNSIGNED_INT_2_10_10_10_REV
:
81 case GL_UNSIGNED_SHORT_8_8_MESA
:
82 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
83 case GL_UNSIGNED_INT_24_8_EXT
:
91 * Flip the 8 bits in each byte of the given array.
94 * \param n number of bytes.
96 * \todo try this trick to flip bytes someday:
98 * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555);
99 * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333);
100 * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f);
104 flip_bytes( GLubyte
*p
, GLuint n
)
107 for (i
= 0; i
< n
; i
++) {
108 b
= (GLuint
) p
[i
]; /* words are often faster than bytes */
109 a
= ((b
& 0x01) << 7) |
123 * Flip the order of the 2 bytes in each word in the given array.
126 * \param n number of words.
129 _mesa_swap2( GLushort
*p
, GLuint n
)
132 for (i
= 0; i
< n
; i
++) {
133 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
140 * Flip the order of the 4 bytes in each word in the given array.
143 _mesa_swap4( GLuint
*p
, GLuint n
)
146 for (i
= 0; i
< n
; i
++) {
149 | ((b
>> 8) & 0xff00)
150 | ((b
<< 8) & 0xff0000)
151 | ((b
<< 24) & 0xff000000);
158 * Get the size of a GL data type.
160 * \param type GL data type.
162 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
163 * if an invalid type enum.
166 _mesa_sizeof_type( GLenum type
)
171 case GL_UNSIGNED_BYTE
:
172 return sizeof(GLubyte
);
174 return sizeof(GLbyte
);
175 case GL_UNSIGNED_SHORT
:
176 return sizeof(GLushort
);
178 return sizeof(GLshort
);
179 case GL_UNSIGNED_INT
:
180 return sizeof(GLuint
);
182 return sizeof(GLint
);
184 return sizeof(GLfloat
);
186 return sizeof(GLdouble
);
187 case GL_HALF_FLOAT_ARB
:
188 return sizeof(GLhalfARB
);
196 * Same as _mesa_sizeof_type() but also accepting the packed pixel
200 _mesa_sizeof_packed_type( GLenum type
)
205 case GL_UNSIGNED_BYTE
:
206 return sizeof(GLubyte
);
208 return sizeof(GLbyte
);
209 case GL_UNSIGNED_SHORT
:
210 return sizeof(GLushort
);
212 return sizeof(GLshort
);
213 case GL_UNSIGNED_INT
:
214 return sizeof(GLuint
);
216 return sizeof(GLint
);
217 case GL_HALF_FLOAT_ARB
:
218 return sizeof(GLhalfARB
);
220 return sizeof(GLfloat
);
221 case GL_UNSIGNED_BYTE_3_3_2
:
222 return sizeof(GLubyte
);
223 case GL_UNSIGNED_BYTE_2_3_3_REV
:
224 return sizeof(GLubyte
);
225 case GL_UNSIGNED_SHORT_5_6_5
:
226 return sizeof(GLushort
);
227 case GL_UNSIGNED_SHORT_5_6_5_REV
:
228 return sizeof(GLushort
);
229 case GL_UNSIGNED_SHORT_4_4_4_4
:
230 return sizeof(GLushort
);
231 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
232 return sizeof(GLushort
);
233 case GL_UNSIGNED_SHORT_5_5_5_1
:
234 return sizeof(GLushort
);
235 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
236 return sizeof(GLushort
);
237 case GL_UNSIGNED_INT_8_8_8_8
:
238 return sizeof(GLuint
);
239 case GL_UNSIGNED_INT_8_8_8_8_REV
:
240 return sizeof(GLuint
);
241 case GL_UNSIGNED_INT_10_10_10_2
:
242 return sizeof(GLuint
);
243 case GL_UNSIGNED_INT_2_10_10_10_REV
:
244 return sizeof(GLuint
);
245 case GL_UNSIGNED_SHORT_8_8_MESA
:
246 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
247 return sizeof(GLushort
);
248 case GL_UNSIGNED_INT_24_8_EXT
:
249 return sizeof(GLuint
);
257 * Get the number of components in a pixel format.
259 * \param format pixel format.
261 * \return the number of components in the given format, or -1 if a bad format.
264 _mesa_components_in_format( GLenum format
)
268 case GL_COLOR_INDEX1_EXT
:
269 case GL_COLOR_INDEX2_EXT
:
270 case GL_COLOR_INDEX4_EXT
:
271 case GL_COLOR_INDEX8_EXT
:
272 case GL_COLOR_INDEX12_EXT
:
273 case GL_COLOR_INDEX16_EXT
:
274 case GL_STENCIL_INDEX
:
275 case GL_DEPTH_COMPONENT
:
283 case GL_LUMINANCE_ALPHA
:
297 case GL_DEPTH_STENCIL_EXT
:
309 * Get the bytes per pixel of pixel format type pair.
311 * \param format pixel format.
312 * \param type pixel type.
314 * \return bytes per pixel, or -1 if a bad format or type was given.
317 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
319 GLint comps
= _mesa_components_in_format( format
);
325 return 0; /* special case */
327 case GL_UNSIGNED_BYTE
:
328 return comps
* sizeof(GLubyte
);
330 case GL_UNSIGNED_SHORT
:
331 return comps
* sizeof(GLshort
);
333 case GL_UNSIGNED_INT
:
334 return comps
* sizeof(GLint
);
336 return comps
* sizeof(GLfloat
);
337 case GL_HALF_FLOAT_ARB
:
338 return comps
* sizeof(GLhalfARB
);
339 case GL_UNSIGNED_BYTE_3_3_2
:
340 case GL_UNSIGNED_BYTE_2_3_3_REV
:
341 if (format
== GL_RGB
|| format
== GL_BGR
)
342 return sizeof(GLubyte
);
344 return -1; /* error */
345 case GL_UNSIGNED_SHORT_5_6_5
:
346 case GL_UNSIGNED_SHORT_5_6_5_REV
:
347 if (format
== GL_RGB
|| format
== GL_BGR
)
348 return sizeof(GLushort
);
350 return -1; /* error */
351 case GL_UNSIGNED_SHORT_4_4_4_4
:
352 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
353 case GL_UNSIGNED_SHORT_5_5_5_1
:
354 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
355 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
356 return sizeof(GLushort
);
359 case GL_UNSIGNED_INT_8_8_8_8
:
360 case GL_UNSIGNED_INT_8_8_8_8_REV
:
361 case GL_UNSIGNED_INT_10_10_10_2
:
362 case GL_UNSIGNED_INT_2_10_10_10_REV
:
363 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
364 return sizeof(GLuint
);
367 case GL_UNSIGNED_SHORT_8_8_MESA
:
368 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
369 if (format
== GL_YCBCR_MESA
)
370 return sizeof(GLushort
);
373 case GL_UNSIGNED_INT_24_8_EXT
:
374 if (format
== GL_DEPTH_STENCIL_EXT
)
375 return sizeof(GLuint
);
385 * Test for a legal pixel format and type.
387 * \param format pixel format.
388 * \param type pixel type.
390 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
394 _mesa_is_legal_format_and_type( GLcontext
*ctx
, GLenum format
, GLenum type
)
398 case GL_STENCIL_INDEX
:
402 case GL_UNSIGNED_BYTE
:
404 case GL_UNSIGNED_SHORT
:
406 case GL_UNSIGNED_INT
:
409 case GL_HALF_FLOAT_ARB
:
410 return ctx
->Extensions
.ARB_half_float_pixel
;
418 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
422 case GL_LUMINANCE_ALPHA
:
423 case GL_DEPTH_COMPONENT
:
426 case GL_UNSIGNED_BYTE
:
428 case GL_UNSIGNED_SHORT
:
430 case GL_UNSIGNED_INT
:
433 case GL_HALF_FLOAT_ARB
:
434 return ctx
->Extensions
.ARB_half_float_pixel
;
441 case GL_UNSIGNED_BYTE
:
443 case GL_UNSIGNED_SHORT
:
445 case GL_UNSIGNED_INT
:
447 case GL_UNSIGNED_BYTE_3_3_2
:
448 case GL_UNSIGNED_BYTE_2_3_3_REV
:
449 case GL_UNSIGNED_SHORT_5_6_5
:
450 case GL_UNSIGNED_SHORT_5_6_5_REV
:
452 case GL_HALF_FLOAT_ARB
:
453 return ctx
->Extensions
.ARB_half_float_pixel
;
459 /* NOTE: no packed types are supported with BGR. That's
460 * intentional, according to the GL spec.
463 case GL_UNSIGNED_BYTE
:
465 case GL_UNSIGNED_SHORT
:
467 case GL_UNSIGNED_INT
:
470 case GL_HALF_FLOAT_ARB
:
471 return ctx
->Extensions
.ARB_half_float_pixel
;
480 case GL_UNSIGNED_BYTE
:
482 case GL_UNSIGNED_SHORT
:
484 case GL_UNSIGNED_INT
:
486 case GL_UNSIGNED_SHORT_4_4_4_4
:
487 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
488 case GL_UNSIGNED_SHORT_5_5_5_1
:
489 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
490 case GL_UNSIGNED_INT_8_8_8_8
:
491 case GL_UNSIGNED_INT_8_8_8_8_REV
:
492 case GL_UNSIGNED_INT_10_10_10_2
:
493 case GL_UNSIGNED_INT_2_10_10_10_REV
:
495 case GL_HALF_FLOAT_ARB
:
496 return ctx
->Extensions
.ARB_half_float_pixel
;
501 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
502 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
506 case GL_DEPTH_STENCIL_EXT
:
507 if (ctx
->Extensions
.EXT_packed_depth_stencil
508 && type
== GL_UNSIGNED_INT_24_8_EXT
)
516 case GL_UNSIGNED_BYTE
:
518 case GL_UNSIGNED_SHORT
:
520 case GL_UNSIGNED_INT
:
534 * Test if the given image format is a color/RGBA format (i.e., not color
535 * index, depth, stencil, etc).
536 * \param format the image format value (may by an internal texture format)
537 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
540 _mesa_is_color_format(GLenum format
)
558 case GL_LUMINANCE_ALPHA
:
559 case GL_LUMINANCE4_ALPHA4
:
560 case GL_LUMINANCE6_ALPHA2
:
561 case GL_LUMINANCE8_ALPHA8
:
562 case GL_LUMINANCE12_ALPHA4
:
563 case GL_LUMINANCE12_ALPHA12
:
564 case GL_LUMINANCE16_ALPHA16
:
591 /* float texture formats */
592 case GL_ALPHA16F_ARB
:
593 case GL_ALPHA32F_ARB
:
594 case GL_LUMINANCE16F_ARB
:
595 case GL_LUMINANCE32F_ARB
:
596 case GL_LUMINANCE_ALPHA16F_ARB
:
597 case GL_LUMINANCE_ALPHA32F_ARB
:
598 case GL_INTENSITY16F_ARB
:
599 case GL_INTENSITY32F_ARB
:
604 /* compressed formats */
605 case GL_COMPRESSED_ALPHA
:
606 case GL_COMPRESSED_LUMINANCE
:
607 case GL_COMPRESSED_LUMINANCE_ALPHA
:
608 case GL_COMPRESSED_INTENSITY
:
609 case GL_COMPRESSED_RGB
:
610 case GL_COMPRESSED_RGBA
:
615 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
616 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
617 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
618 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
619 case GL_COMPRESSED_RGB_FXT1_3DFX
:
620 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
621 #if FEATURE_EXT_texture_sRGB
624 case GL_SRGB_ALPHA_EXT
:
625 case GL_SRGB8_ALPHA8_EXT
:
626 case GL_SLUMINANCE_ALPHA_EXT
:
627 case GL_SLUMINANCE8_ALPHA8_EXT
:
628 case GL_SLUMINANCE_EXT
:
629 case GL_SLUMINANCE8_EXT
:
630 case GL_COMPRESSED_SRGB_EXT
:
631 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
632 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
633 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
634 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
635 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
636 case GL_COMPRESSED_SLUMINANCE_EXT
:
637 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
638 #endif /* FEATURE_EXT_texture_sRGB */
640 /* signed texture formats */
644 case GL_YCBCR_MESA
: /* not considered to be RGB */
653 * Test if the given image format is a color index format.
656 _mesa_is_index_format(GLenum format
)
660 case GL_COLOR_INDEX1_EXT
:
661 case GL_COLOR_INDEX2_EXT
:
662 case GL_COLOR_INDEX4_EXT
:
663 case GL_COLOR_INDEX8_EXT
:
664 case GL_COLOR_INDEX12_EXT
:
665 case GL_COLOR_INDEX16_EXT
:
674 * Test if the given image format is a depth component format.
677 _mesa_is_depth_format(GLenum format
)
680 case GL_DEPTH_COMPONENT
:
681 case GL_DEPTH_COMPONENT16
:
682 case GL_DEPTH_COMPONENT24
:
683 case GL_DEPTH_COMPONENT32
:
692 * Test if the given image format is a stencil format.
695 _mesa_is_stencil_format(GLenum format
)
698 case GL_STENCIL_INDEX
:
699 case GL_DEPTH_STENCIL
:
708 * Test if the given image format is a YCbCr format.
711 _mesa_is_ycbcr_format(GLenum format
)
723 * Test if the given image format is a depth+stencil format.
726 _mesa_is_depthstencil_format(GLenum format
)
729 case GL_DEPTH24_STENCIL8_EXT
:
730 case GL_DEPTH_STENCIL_EXT
:
739 * Test if the given image format is a depth or stencil format.
742 _mesa_is_depth_or_stencil_format(GLenum format
)
745 case GL_DEPTH_COMPONENT
:
746 case GL_DEPTH_COMPONENT16
:
747 case GL_DEPTH_COMPONENT24
:
748 case GL_DEPTH_COMPONENT32
:
749 case GL_STENCIL_INDEX
:
750 case GL_STENCIL_INDEX1_EXT
:
751 case GL_STENCIL_INDEX4_EXT
:
752 case GL_STENCIL_INDEX8_EXT
:
753 case GL_STENCIL_INDEX16_EXT
:
754 case GL_DEPTH_STENCIL_EXT
:
755 case GL_DEPTH24_STENCIL8_EXT
:
764 * Test if the given image format is a dudv format.
767 _mesa_is_dudv_format(GLenum format
)
780 * Test if an image format is a supported compressed format.
781 * \param format the internal format token provided by the user.
782 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
785 _mesa_is_compressed_format(GLcontext
*ctx
, GLenum format
)
788 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
789 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
790 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
791 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
792 return ctx
->Extensions
.EXT_texture_compression_s3tc
;
797 return ctx
->Extensions
.S3_s3tc
;
798 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
799 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
800 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
801 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
802 return ctx
->Extensions
.EXT_texture_sRGB
803 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
804 case GL_COMPRESSED_RGB_FXT1_3DFX
:
805 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
806 return ctx
->Extensions
.TDFX_texture_compression_FXT1
;
814 * Return the address of a specific pixel in an image (1D, 2D or 3D).
816 * Pixel unpacking/packing parameters are observed according to \p packing.
818 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
819 * \param image starting address of image data
820 * \param width the image width
821 * \param height theimage height
822 * \param format the pixel format
823 * \param type the pixel data type
824 * \param packing the pixelstore attributes
825 * \param img which image in the volume (0 for 1D or 2D images)
826 * \param row row of pixel in the image (0 for 1D images)
827 * \param column column of pixel in the image
829 * \return address of pixel on success, or NULL on error.
831 * \sa gl_pixelstore_attrib.
834 _mesa_image_address( GLuint dimensions
,
835 const struct gl_pixelstore_attrib
*packing
,
837 GLsizei width
, GLsizei height
,
838 GLenum format
, GLenum type
,
839 GLint img
, GLint row
, GLint column
)
841 GLint alignment
; /* 1, 2 or 4 */
842 GLint pixels_per_row
;
843 GLint rows_per_image
;
846 GLint skipimages
; /* for 3-D volume images */
849 ASSERT(dimensions
>= 1 && dimensions
<= 3);
851 alignment
= packing
->Alignment
;
852 if (packing
->RowLength
> 0) {
853 pixels_per_row
= packing
->RowLength
;
856 pixels_per_row
= width
;
858 if (packing
->ImageHeight
> 0) {
859 rows_per_image
= packing
->ImageHeight
;
862 rows_per_image
= height
;
865 skippixels
= packing
->SkipPixels
;
866 /* Note: SKIP_ROWS _is_ used for 1D images */
867 skiprows
= packing
->SkipRows
;
868 /* Note: SKIP_IMAGES is only used for 3D images */
869 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
871 if (type
== GL_BITMAP
) {
873 GLint comp_per_pixel
; /* components per pixel */
874 GLint bytes_per_comp
; /* bytes per component */
876 GLint bytes_per_image
;
878 /* Compute bytes per component */
879 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
880 if (bytes_per_comp
< 0) {
884 /* Compute number of components per pixel */
885 comp_per_pixel
= _mesa_components_in_format( format
);
886 if (comp_per_pixel
< 0) {
890 bytes_per_row
= alignment
891 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
893 bytes_per_image
= bytes_per_row
* rows_per_image
;
895 pixel_addr
= (GLubyte
*) image
896 + (skipimages
+ img
) * bytes_per_image
897 + (skiprows
+ row
) * bytes_per_row
898 + (skippixels
+ column
) / 8;
901 /* Non-BITMAP data */
902 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
905 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
907 /* The pixel type and format should have been error checked earlier */
908 assert(bytes_per_pixel
> 0);
910 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
911 remainder
= bytes_per_row
% alignment
;
913 bytes_per_row
+= (alignment
- remainder
);
915 ASSERT(bytes_per_row
% alignment
== 0);
917 bytes_per_image
= bytes_per_row
* rows_per_image
;
919 if (packing
->Invert
) {
920 /* set pixel_addr to the last row */
921 topOfImage
= bytes_per_row
* (height
- 1);
922 bytes_per_row
= -bytes_per_row
;
928 /* compute final pixel address */
929 pixel_addr
= (GLubyte
*) image
930 + (skipimages
+ img
) * bytes_per_image
932 + (skiprows
+ row
) * bytes_per_row
933 + (skippixels
+ column
) * bytes_per_pixel
;
936 return (GLvoid
*) pixel_addr
;
941 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
944 GLenum format
, GLenum type
,
947 return _mesa_image_address(1, packing
, image
, width
, 1,
948 format
, type
, 0, 0, column
);
953 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
955 GLsizei width
, GLsizei height
,
956 GLenum format
, GLenum type
,
957 GLint row
, GLint column
)
959 return _mesa_image_address(2, packing
, image
, width
, height
,
960 format
, type
, 0, row
, column
);
965 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
967 GLsizei width
, GLsizei height
,
968 GLenum format
, GLenum type
,
969 GLint img
, GLint row
, GLint column
)
971 return _mesa_image_address(3, packing
, image
, width
, height
,
972 format
, type
, img
, row
, column
);
978 * Compute the stride (in bytes) between image rows.
980 * \param packing the pixelstore attributes
981 * \param width image width.
982 * \param format pixel format.
983 * \param type pixel data type.
985 * \return the stride in bytes for the given parameters, or -1 if error
988 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
989 GLint width
, GLenum format
, GLenum type
)
991 GLint bytesPerRow
, remainder
;
995 if (type
== GL_BITMAP
) {
996 if (packing
->RowLength
== 0) {
997 bytesPerRow
= (width
+ 7) / 8;
1000 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1004 /* Non-BITMAP data */
1005 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1006 if (bytesPerPixel
<= 0)
1007 return -1; /* error */
1008 if (packing
->RowLength
== 0) {
1009 bytesPerRow
= bytesPerPixel
* width
;
1012 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1016 remainder
= bytesPerRow
% packing
->Alignment
;
1017 if (remainder
> 0) {
1018 bytesPerRow
+= (packing
->Alignment
- remainder
);
1021 if (packing
->Invert
) {
1022 /* negate the bytes per row (negative row stride) */
1023 bytesPerRow
= -bytesPerRow
;
1033 * Compute the stride between images in a 3D texture (in bytes) for the given
1034 * pixel packing parameters and image width, format and type.
1037 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
1038 GLint width
, GLint height
,
1039 GLenum format
, GLenum type
)
1041 GLint bytesPerRow
, bytesPerImage
, remainder
;
1045 if (type
== GL_BITMAP
) {
1046 if (packing
->RowLength
== 0) {
1047 bytesPerRow
= (width
+ 7) / 8;
1050 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1054 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1056 if (bytesPerPixel
<= 0)
1057 return -1; /* error */
1058 if (packing
->RowLength
== 0) {
1059 bytesPerRow
= bytesPerPixel
* width
;
1062 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1066 remainder
= bytesPerRow
% packing
->Alignment
;
1068 bytesPerRow
+= (packing
->Alignment
- remainder
);
1070 if (packing
->ImageHeight
== 0)
1071 bytesPerImage
= bytesPerRow
* height
;
1073 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
1075 return bytesPerImage
;
1080 * Unpack a 32x32 pixel polygon stipple from user memory using the
1081 * current pixel unpack settings.
1084 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
1085 const struct gl_pixelstore_attrib
*unpacking
)
1087 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap(32, 32, pattern
, unpacking
);
1089 /* Convert pattern from GLubytes to GLuints and handle big/little
1090 * endian differences
1094 for (i
= 0; i
< 32; i
++) {
1095 dest
[i
] = (p
[0] << 24)
1107 * Pack polygon stipple into user memory given current pixel packing
1111 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
1112 const struct gl_pixelstore_attrib
*packing
)
1114 /* Convert pattern from GLuints to GLubytes to handle big/little
1115 * endian differences.
1119 for (i
= 0; i
< 32; i
++) {
1120 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
1121 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
1122 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
1123 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
1126 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
1131 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
1132 * order with row alignment = 1 byte.
1135 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
1136 const struct gl_pixelstore_attrib
*packing
)
1138 GLint bytes
, row
, width_in_bytes
;
1139 GLubyte
*buffer
, *dst
;
1144 /* Alloc dest storage */
1145 bytes
= ((width
+ 7) / 8 * height
);
1146 buffer
= (GLubyte
*) malloc( bytes
);
1150 width_in_bytes
= CEILING( width
, 8 );
1152 for (row
= 0; row
< height
; row
++) {
1153 const GLubyte
*src
= (const GLubyte
*)
1154 _mesa_image_address2d(packing
, pixels
, width
, height
,
1155 GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
1161 if ((packing
->SkipPixels
& 7) == 0) {
1162 memcpy( dst
, src
, width_in_bytes
);
1163 if (packing
->LsbFirst
) {
1164 flip_bytes( dst
, width_in_bytes
);
1168 /* handling SkipPixels is a bit tricky (no pun intended!) */
1170 if (packing
->LsbFirst
) {
1171 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
1172 GLubyte dstMask
= 128;
1173 const GLubyte
*s
= src
;
1176 for (i
= 0; i
< width
; i
++) {
1180 if (srcMask
== 128) {
1185 srcMask
= srcMask
<< 1;
1193 dstMask
= dstMask
>> 1;
1198 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
1199 GLubyte dstMask
= 128;
1200 const GLubyte
*s
= src
;
1203 for (i
= 0; i
< width
; i
++) {
1212 srcMask
= srcMask
>> 1;
1220 dstMask
= dstMask
>> 1;
1225 dst
+= width_in_bytes
;
1236 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
1237 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
1239 GLint row
, width_in_bytes
;
1245 width_in_bytes
= CEILING( width
, 8 );
1247 for (row
= 0; row
< height
; row
++) {
1248 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dest
,
1249 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
1253 if ((packing
->SkipPixels
& 7) == 0) {
1254 memcpy( dst
, src
, width_in_bytes
);
1255 if (packing
->LsbFirst
) {
1256 flip_bytes( dst
, width_in_bytes
);
1260 /* handling SkipPixels is a bit tricky (no pun intended!) */
1262 if (packing
->LsbFirst
) {
1263 GLubyte srcMask
= 128;
1264 GLubyte dstMask
= 1 << (packing
->SkipPixels
& 0x7);
1265 const GLubyte
*s
= src
;
1268 for (i
= 0; i
< width
; i
++) {
1277 srcMask
= srcMask
>> 1;
1279 if (dstMask
== 128) {
1285 dstMask
= dstMask
<< 1;
1290 GLubyte srcMask
= 128;
1291 GLubyte dstMask
= 128 >> (packing
->SkipPixels
& 0x7);
1292 const GLubyte
*s
= src
;
1295 for (i
= 0; i
< width
; i
++) {
1304 srcMask
= srcMask
>> 1;
1312 dstMask
= dstMask
>> 1;
1317 src
+= width_in_bytes
;
1323 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1324 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1325 * "On" bits will set texels to \p onValue.
1326 * "Off" bits will not modify texels.
1327 * \param width src bitmap width in pixels
1328 * \param height src bitmap height in pixels
1329 * \param unpack bitmap unpacking state
1330 * \param bitmap the src bitmap data
1331 * \param destBuffer start of dest buffer
1332 * \param destStride row stride in dest buffer
1333 * \param onValue if bit is 1, set destBuffer pixel to this value
1336 _mesa_expand_bitmap(GLsizei width
, GLsizei height
,
1337 const struct gl_pixelstore_attrib
*unpack
,
1338 const GLubyte
*bitmap
,
1339 GLubyte
*destBuffer
, GLint destStride
,
1342 const GLubyte
*srcRow
= (const GLubyte
*)
1343 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
1344 GL_COLOR_INDEX
, GL_BITMAP
, 0, 0);
1345 const GLint srcStride
= _mesa_image_row_stride(unpack
, width
,
1346 GL_COLOR_INDEX
, GL_BITMAP
);
1349 #define SET_PIXEL(COL, ROW) \
1350 destBuffer[(ROW) * destStride + (COL)] = onValue;
1352 for (row
= 0; row
< height
; row
++) {
1353 const GLubyte
*src
= srcRow
;
1355 if (unpack
->LsbFirst
) {
1357 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
1358 for (col
= 0; col
< width
; col
++) {
1361 SET_PIXEL(col
, row
);
1373 /* get ready for next row */
1379 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
1380 for (col
= 0; col
< width
; col
++) {
1383 SET_PIXEL(col
, row
);
1395 /* get ready for next row */
1400 srcRow
+= srcStride
;
1407 /**********************************************************************/
1408 /***** Pixel processing functions ******/
1409 /**********************************************************************/
1412 * Apply scale and bias factors to an array of RGBA pixels.
1415 _mesa_scale_and_bias_rgba(GLuint n
, GLfloat rgba
[][4],
1416 GLfloat rScale
, GLfloat gScale
,
1417 GLfloat bScale
, GLfloat aScale
,
1418 GLfloat rBias
, GLfloat gBias
,
1419 GLfloat bBias
, GLfloat aBias
)
1421 if (rScale
!= 1.0 || rBias
!= 0.0) {
1423 for (i
= 0; i
< n
; i
++) {
1424 rgba
[i
][RCOMP
] = rgba
[i
][RCOMP
] * rScale
+ rBias
;
1427 if (gScale
!= 1.0 || gBias
!= 0.0) {
1429 for (i
= 0; i
< n
; i
++) {
1430 rgba
[i
][GCOMP
] = rgba
[i
][GCOMP
] * gScale
+ gBias
;
1433 if (bScale
!= 1.0 || bBias
!= 0.0) {
1435 for (i
= 0; i
< n
; i
++) {
1436 rgba
[i
][BCOMP
] = rgba
[i
][BCOMP
] * bScale
+ bBias
;
1439 if (aScale
!= 1.0 || aBias
!= 0.0) {
1441 for (i
= 0; i
< n
; i
++) {
1442 rgba
[i
][ACOMP
] = rgba
[i
][ACOMP
] * aScale
+ aBias
;
1449 * Apply pixel mapping to an array of floating point RGBA pixels.
1452 _mesa_map_rgba( const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4] )
1454 const GLfloat rscale
= (GLfloat
) (ctx
->PixelMaps
.RtoR
.Size
- 1);
1455 const GLfloat gscale
= (GLfloat
) (ctx
->PixelMaps
.GtoG
.Size
- 1);
1456 const GLfloat bscale
= (GLfloat
) (ctx
->PixelMaps
.BtoB
.Size
- 1);
1457 const GLfloat ascale
= (GLfloat
) (ctx
->PixelMaps
.AtoA
.Size
- 1);
1458 const GLfloat
*rMap
= ctx
->PixelMaps
.RtoR
.Map
;
1459 const GLfloat
*gMap
= ctx
->PixelMaps
.GtoG
.Map
;
1460 const GLfloat
*bMap
= ctx
->PixelMaps
.BtoB
.Map
;
1461 const GLfloat
*aMap
= ctx
->PixelMaps
.AtoA
.Map
;
1464 GLfloat r
= CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1465 GLfloat g
= CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1466 GLfloat b
= CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1467 GLfloat a
= CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1468 rgba
[i
][RCOMP
] = rMap
[IROUND(r
* rscale
)];
1469 rgba
[i
][GCOMP
] = gMap
[IROUND(g
* gscale
)];
1470 rgba
[i
][BCOMP
] = bMap
[IROUND(b
* bscale
)];
1471 rgba
[i
][ACOMP
] = aMap
[IROUND(a
* ascale
)];
1477 * Apply the color matrix and post color matrix scaling and biasing.
1480 _mesa_transform_rgba(const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4])
1482 const GLfloat rs
= ctx
->Pixel
.PostColorMatrixScale
[0];
1483 const GLfloat rb
= ctx
->Pixel
.PostColorMatrixBias
[0];
1484 const GLfloat gs
= ctx
->Pixel
.PostColorMatrixScale
[1];
1485 const GLfloat gb
= ctx
->Pixel
.PostColorMatrixBias
[1];
1486 const GLfloat bs
= ctx
->Pixel
.PostColorMatrixScale
[2];
1487 const GLfloat bb
= ctx
->Pixel
.PostColorMatrixBias
[2];
1488 const GLfloat as
= ctx
->Pixel
.PostColorMatrixScale
[3];
1489 const GLfloat ab
= ctx
->Pixel
.PostColorMatrixBias
[3];
1490 const GLfloat
*m
= ctx
->ColorMatrixStack
.Top
->m
;
1492 for (i
= 0; i
< n
; i
++) {
1493 const GLfloat r
= rgba
[i
][RCOMP
];
1494 const GLfloat g
= rgba
[i
][GCOMP
];
1495 const GLfloat b
= rgba
[i
][BCOMP
];
1496 const GLfloat a
= rgba
[i
][ACOMP
];
1497 rgba
[i
][RCOMP
] = (m
[0] * r
+ m
[4] * g
+ m
[ 8] * b
+ m
[12] * a
) * rs
+ rb
;
1498 rgba
[i
][GCOMP
] = (m
[1] * r
+ m
[5] * g
+ m
[ 9] * b
+ m
[13] * a
) * gs
+ gb
;
1499 rgba
[i
][BCOMP
] = (m
[2] * r
+ m
[6] * g
+ m
[10] * b
+ m
[14] * a
) * bs
+ bb
;
1500 rgba
[i
][ACOMP
] = (m
[3] * r
+ m
[7] * g
+ m
[11] * b
+ m
[15] * a
) * as
+ ab
;
1506 * Apply a color table lookup to an array of floating point RGBA colors.
1509 _mesa_lookup_rgba_float(const struct gl_color_table
*table
,
1510 GLuint n
, GLfloat rgba
[][4])
1512 const GLint max
= table
->Size
- 1;
1513 const GLfloat scale
= (GLfloat
) max
;
1514 const GLfloat
*lut
= table
->TableF
;
1517 if (!table
->TableF
|| table
->Size
== 0)
1520 switch (table
->_BaseFormat
) {
1522 /* replace RGBA with I */
1523 for (i
= 0; i
< n
; i
++) {
1524 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1525 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1533 /* replace RGB with L */
1534 for (i
= 0; i
< n
; i
++) {
1535 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1536 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1543 /* replace A with A */
1544 for (i
= 0; i
< n
; i
++) {
1545 GLint j
= IROUND(rgba
[i
][ACOMP
] * scale
);
1546 rgba
[i
][ACOMP
] = lut
[CLAMP(j
, 0, max
)];
1549 case GL_LUMINANCE_ALPHA
:
1550 /* replace RGBA with LLLA */
1551 for (i
= 0; i
< n
; i
++) {
1552 GLint jL
= IROUND(rgba
[i
][RCOMP
] * scale
);
1553 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1554 GLfloat luminance
, alpha
;
1555 jL
= CLAMP(jL
, 0, max
);
1556 jA
= CLAMP(jA
, 0, max
);
1557 luminance
= lut
[jL
* 2 + 0];
1558 alpha
= lut
[jA
* 2 + 1];
1561 rgba
[i
][BCOMP
] = luminance
;
1562 rgba
[i
][ACOMP
] = alpha
;;
1566 /* replace RGB with RGB */
1567 for (i
= 0; i
< n
; i
++) {
1568 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1569 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1570 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1571 jR
= CLAMP(jR
, 0, max
);
1572 jG
= CLAMP(jG
, 0, max
);
1573 jB
= CLAMP(jB
, 0, max
);
1574 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1575 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1576 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1580 /* replace RGBA with RGBA */
1581 for (i
= 0; i
< n
; i
++) {
1582 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1583 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1584 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1585 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1586 jR
= CLAMP(jR
, 0, max
);
1587 jG
= CLAMP(jG
, 0, max
);
1588 jB
= CLAMP(jB
, 0, max
);
1589 jA
= CLAMP(jA
, 0, max
);
1590 rgba
[i
][RCOMP
] = lut
[jR
* 4 + 0];
1591 rgba
[i
][GCOMP
] = lut
[jG
* 4 + 1];
1592 rgba
[i
][BCOMP
] = lut
[jB
* 4 + 2];
1593 rgba
[i
][ACOMP
] = lut
[jA
* 4 + 3];
1597 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_float");
1605 * Apply a color table lookup to an array of ubyte/RGBA colors.
1608 _mesa_lookup_rgba_ubyte(const struct gl_color_table
*table
,
1609 GLuint n
, GLubyte rgba
[][4])
1611 const GLubyte
*lut
= table
->TableUB
;
1612 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / (GLfloat
)255.0;
1615 if (!table
->TableUB
|| table
->Size
== 0)
1618 switch (table
->_BaseFormat
) {
1620 /* replace RGBA with I */
1621 if (table
->Size
== 256) {
1622 for (i
= 0; i
< n
; i
++) {
1623 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1631 for (i
= 0; i
< n
; i
++) {
1632 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1636 rgba
[i
][ACOMP
] = lut
[j
];
1641 /* replace RGB with L */
1642 if (table
->Size
== 256) {
1643 for (i
= 0; i
< n
; i
++) {
1644 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1651 for (i
= 0; i
< n
; i
++) {
1652 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1655 rgba
[i
][BCOMP
] = lut
[j
];
1660 /* replace A with A */
1661 if (table
->Size
== 256) {
1662 for (i
= 0; i
< n
; i
++) {
1663 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
]];
1667 for (i
= 0; i
< n
; i
++) {
1668 GLint j
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1669 rgba
[i
][ACOMP
] = lut
[j
];
1673 case GL_LUMINANCE_ALPHA
:
1674 /* replace RGBA with LLLA */
1675 if (table
->Size
== 256) {
1676 for (i
= 0; i
< n
; i
++) {
1677 GLubyte l
= lut
[rgba
[i
][RCOMP
] * 2 + 0];
1678 GLubyte a
= lut
[rgba
[i
][ACOMP
] * 2 + 1];;
1686 for (i
= 0; i
< n
; i
++) {
1687 GLint jL
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1688 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1689 GLubyte luminance
= lut
[jL
* 2 + 0];
1690 GLubyte alpha
= lut
[jA
* 2 + 1];
1693 rgba
[i
][BCOMP
] = luminance
;
1694 rgba
[i
][ACOMP
] = alpha
;
1699 if (table
->Size
== 256) {
1700 for (i
= 0; i
< n
; i
++) {
1701 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 3 + 0];
1702 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 3 + 1];
1703 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 3 + 2];
1707 for (i
= 0; i
< n
; i
++) {
1708 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1709 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1710 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1711 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1712 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1713 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1718 if (table
->Size
== 256) {
1719 for (i
= 0; i
< n
; i
++) {
1720 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 4 + 0];
1721 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 4 + 1];
1722 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 4 + 2];
1723 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
] * 4 + 3];
1727 for (i
= 0; i
< n
; i
++) {
1728 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1729 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1730 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1731 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1732 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][RCOMP
], lut
[jR
* 4 + 0]);
1733 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][GCOMP
], lut
[jG
* 4 + 1]);
1734 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][BCOMP
], lut
[jB
* 4 + 2]);
1735 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][ACOMP
], lut
[jA
* 4 + 3]);
1740 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_chan");
1748 * Map color indexes to float rgba values.
1751 _mesa_map_ci_to_rgba( const GLcontext
*ctx
, GLuint n
,
1752 const GLuint index
[], GLfloat rgba
[][4] )
1754 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1755 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1756 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1757 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1758 const GLfloat
*rMap
= ctx
->PixelMaps
.ItoR
.Map
;
1759 const GLfloat
*gMap
= ctx
->PixelMaps
.ItoG
.Map
;
1760 const GLfloat
*bMap
= ctx
->PixelMaps
.ItoB
.Map
;
1761 const GLfloat
*aMap
= ctx
->PixelMaps
.ItoA
.Map
;
1764 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1765 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1766 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1767 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1773 * Map ubyte color indexes to ubyte/RGBA values.
1776 _mesa_map_ci8_to_rgba8(const GLcontext
*ctx
, GLuint n
, const GLubyte index
[],
1779 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1780 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1781 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1782 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1783 const GLubyte
*rMap
= ctx
->PixelMaps
.ItoR
.Map8
;
1784 const GLubyte
*gMap
= ctx
->PixelMaps
.ItoG
.Map8
;
1785 const GLubyte
*bMap
= ctx
->PixelMaps
.ItoB
.Map8
;
1786 const GLubyte
*aMap
= ctx
->PixelMaps
.ItoA
.Map8
;
1789 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1790 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1791 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1792 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1798 _mesa_scale_and_bias_depth(const GLcontext
*ctx
, GLuint n
,
1799 GLfloat depthValues
[])
1801 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
1802 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
1804 for (i
= 0; i
< n
; i
++) {
1805 GLfloat d
= depthValues
[i
] * scale
+ bias
;
1806 depthValues
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
1812 _mesa_scale_and_bias_depth_uint(const GLcontext
*ctx
, GLuint n
,
1813 GLuint depthValues
[])
1815 const GLdouble max
= (double) 0xffffffff;
1816 const GLdouble scale
= ctx
->Pixel
.DepthScale
;
1817 const GLdouble bias
= ctx
->Pixel
.DepthBias
* max
;
1819 for (i
= 0; i
< n
; i
++) {
1820 GLdouble d
= (GLdouble
) depthValues
[i
] * scale
+ bias
;
1821 d
= CLAMP(d
, 0.0, max
);
1822 depthValues
[i
] = (GLuint
) d
;
1829 * Update the min/max values from an array of fragment colors.
1832 update_minmax(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1835 for (i
= 0; i
< n
; i
++) {
1837 if (rgba
[i
][RCOMP
] < ctx
->MinMax
.Min
[RCOMP
])
1838 ctx
->MinMax
.Min
[RCOMP
] = rgba
[i
][RCOMP
];
1839 if (rgba
[i
][GCOMP
] < ctx
->MinMax
.Min
[GCOMP
])
1840 ctx
->MinMax
.Min
[GCOMP
] = rgba
[i
][GCOMP
];
1841 if (rgba
[i
][BCOMP
] < ctx
->MinMax
.Min
[BCOMP
])
1842 ctx
->MinMax
.Min
[BCOMP
] = rgba
[i
][BCOMP
];
1843 if (rgba
[i
][ACOMP
] < ctx
->MinMax
.Min
[ACOMP
])
1844 ctx
->MinMax
.Min
[ACOMP
] = rgba
[i
][ACOMP
];
1847 if (rgba
[i
][RCOMP
] > ctx
->MinMax
.Max
[RCOMP
])
1848 ctx
->MinMax
.Max
[RCOMP
] = rgba
[i
][RCOMP
];
1849 if (rgba
[i
][GCOMP
] > ctx
->MinMax
.Max
[GCOMP
])
1850 ctx
->MinMax
.Max
[GCOMP
] = rgba
[i
][GCOMP
];
1851 if (rgba
[i
][BCOMP
] > ctx
->MinMax
.Max
[BCOMP
])
1852 ctx
->MinMax
.Max
[BCOMP
] = rgba
[i
][BCOMP
];
1853 if (rgba
[i
][ACOMP
] > ctx
->MinMax
.Max
[ACOMP
])
1854 ctx
->MinMax
.Max
[ACOMP
] = rgba
[i
][ACOMP
];
1860 * Update the histogram values from an array of fragment colors.
1863 update_histogram(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1865 const GLint max
= ctx
->Histogram
.Width
- 1;
1866 GLfloat w
= (GLfloat
) max
;
1869 if (ctx
->Histogram
.Width
== 0)
1872 for (i
= 0; i
< n
; i
++) {
1873 GLint ri
= IROUND(rgba
[i
][RCOMP
] * w
);
1874 GLint gi
= IROUND(rgba
[i
][GCOMP
] * w
);
1875 GLint bi
= IROUND(rgba
[i
][BCOMP
] * w
);
1876 GLint ai
= IROUND(rgba
[i
][ACOMP
] * w
);
1877 ri
= CLAMP(ri
, 0, max
);
1878 gi
= CLAMP(gi
, 0, max
);
1879 bi
= CLAMP(bi
, 0, max
);
1880 ai
= CLAMP(ai
, 0, max
);
1881 ctx
->Histogram
.Count
[ri
][RCOMP
]++;
1882 ctx
->Histogram
.Count
[gi
][GCOMP
]++;
1883 ctx
->Histogram
.Count
[bi
][BCOMP
]++;
1884 ctx
->Histogram
.Count
[ai
][ACOMP
]++;
1890 * Apply various pixel transfer operations to an array of RGBA pixels
1891 * as indicated by the transferOps bitmask
1894 _mesa_apply_rgba_transfer_ops(GLcontext
*ctx
, GLbitfield transferOps
,
1895 GLuint n
, GLfloat rgba
[][4])
1898 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
1899 _mesa_scale_and_bias_rgba(n
, rgba
,
1900 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
1901 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
1902 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
1903 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
1905 /* color map lookup */
1906 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1907 _mesa_map_rgba( ctx
, n
, rgba
);
1909 /* GL_COLOR_TABLE lookup */
1910 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
1911 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
], n
, rgba
);
1914 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
1915 /* this has to be done in the calling code */
1916 _mesa_problem(ctx
, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");
1918 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
1919 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
1920 _mesa_scale_and_bias_rgba(n
, rgba
,
1921 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
1922 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
1923 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
1924 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
1925 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
1926 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
1927 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
1928 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
1930 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
1931 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
1932 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
], n
, rgba
);
1934 /* color matrix transform */
1935 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
1936 _mesa_transform_rgba(ctx
, n
, rgba
);
1938 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
1939 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
1940 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
], n
, rgba
);
1942 /* update histogram count */
1943 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
1944 update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1946 /* update min/max values */
1947 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
1948 update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1950 /* clamping to [0,1] */
1951 if (transferOps
& IMAGE_CLAMP_BIT
) {
1953 for (i
= 0; i
< n
; i
++) {
1954 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1955 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1956 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1957 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1964 * Apply color index shift and offset to an array of pixels.
1967 shift_and_offset_ci( const GLcontext
*ctx
, GLuint n
, GLuint indexes
[] )
1969 GLint shift
= ctx
->Pixel
.IndexShift
;
1970 GLint offset
= ctx
->Pixel
.IndexOffset
;
1974 indexes
[i
] = (indexes
[i
] << shift
) + offset
;
1977 else if (shift
< 0) {
1980 indexes
[i
] = (indexes
[i
] >> shift
) + offset
;
1985 indexes
[i
] = indexes
[i
] + offset
;
1993 * Apply color index shift, offset and table lookup to an array
1997 _mesa_apply_ci_transfer_ops(const GLcontext
*ctx
, GLbitfield transferOps
,
1998 GLuint n
, GLuint indexes
[])
2000 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
2001 shift_and_offset_ci(ctx
, n
, indexes
);
2003 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
2004 const GLuint mask
= ctx
->PixelMaps
.ItoI
.Size
- 1;
2006 for (i
= 0; i
< n
; i
++) {
2007 const GLuint j
= indexes
[i
] & mask
;
2008 indexes
[i
] = IROUND(ctx
->PixelMaps
.ItoI
.Map
[j
]);
2015 * Apply stencil index shift, offset and table lookup to an array
2016 * of stencil values.
2019 _mesa_apply_stencil_transfer_ops(const GLcontext
*ctx
, GLuint n
,
2020 GLstencil stencil
[])
2022 if (ctx
->Pixel
.IndexShift
!= 0 || ctx
->Pixel
.IndexOffset
!= 0) {
2023 const GLint offset
= ctx
->Pixel
.IndexOffset
;
2024 GLint shift
= ctx
->Pixel
.IndexShift
;
2027 for (i
= 0; i
< n
; i
++) {
2028 stencil
[i
] = (stencil
[i
] << shift
) + offset
;
2031 else if (shift
< 0) {
2033 for (i
= 0; i
< n
; i
++) {
2034 stencil
[i
] = (stencil
[i
] >> shift
) + offset
;
2038 for (i
= 0; i
< n
; i
++) {
2039 stencil
[i
] = stencil
[i
] + offset
;
2043 if (ctx
->Pixel
.MapStencilFlag
) {
2044 GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
2046 for (i
= 0; i
< n
; i
++) {
2047 stencil
[i
] = (GLstencil
)ctx
->PixelMaps
.StoS
.Map
[ stencil
[i
] & mask
];
2054 * Used to pack an array [][4] of RGBA float colors as specified
2055 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
2056 * glGetConvolutionFilter(), etc.
2057 * Note: the rgba values will be modified by this function when any pixel
2058 * transfer ops are enabled.
2061 _mesa_pack_rgba_span_float(GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4],
2062 GLenum dstFormat
, GLenum dstType
,
2064 const struct gl_pixelstore_attrib
*dstPacking
,
2065 GLbitfield transferOps
)
2067 GLfloat luminance
[MAX_WIDTH
];
2068 const GLint comps
= _mesa_components_in_format(dstFormat
);
2072 * This test should probably go away. Have the caller set/clear the
2073 * IMAGE_CLAMP_BIT as needed.
2075 if (dstType
!= GL_FLOAT
|| ctx
->Color
.ClampReadColor
== GL_TRUE
) {
2076 /* need to clamp to [0, 1] */
2077 transferOps
|= IMAGE_CLAMP_BIT
;
2081 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
2082 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
2087 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
2088 /* compute luminance values */
2089 if (transferOps
& IMAGE_CLAMP_BIT
) {
2090 for (i
= 0; i
< n
; i
++) {
2091 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
2092 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
2096 for (i
= 0; i
< n
; i
++) {
2097 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
2103 * Pack/store the pixels. Ugh! Lots of cases!!!
2106 case GL_UNSIGNED_BYTE
:
2108 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2109 switch (dstFormat
) {
2112 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2116 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2120 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2124 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2128 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
2130 case GL_LUMINANCE_ALPHA
:
2132 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
2133 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2138 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2139 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2140 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2145 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2146 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2147 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2148 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2153 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2154 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2155 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2160 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2161 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2162 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2163 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2168 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2169 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2170 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2171 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2177 dst
[i
*2+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2178 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2182 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2188 GLbyte
*dst
= (GLbyte
*) dstAddr
;
2189 switch (dstFormat
) {
2192 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2196 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2200 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2204 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2208 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
2210 case GL_LUMINANCE_ALPHA
:
2212 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
2213 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2218 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2219 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2220 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2225 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2226 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2227 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2228 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2233 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2234 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2235 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2240 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2241 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2242 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2243 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2248 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2249 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2250 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2251 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2257 dst
[i
*2+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2258 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2262 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2266 case GL_UNSIGNED_SHORT
:
2268 GLushort
*dst
= (GLushort
*) dstAddr
;
2269 switch (dstFormat
) {
2272 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][RCOMP
]);
2276 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][GCOMP
]);
2280 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][BCOMP
]);
2284 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][ACOMP
]);
2288 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
], luminance
[i
]);
2290 case GL_LUMINANCE_ALPHA
:
2292 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
*2+0], luminance
[i
]);
2293 CLAMPED_FLOAT_TO_USHORT(dst
[i
*2+1], rgba
[i
][ACOMP
]);
2298 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][RCOMP
]);
2299 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
2300 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][BCOMP
]);
2305 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][RCOMP
]);
2306 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
2307 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][BCOMP
]);
2308 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
2313 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][BCOMP
]);
2314 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
2315 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][RCOMP
]);
2320 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][BCOMP
]);
2321 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
2322 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][RCOMP
]);
2323 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
2328 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][ACOMP
]);
2329 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][BCOMP
]);
2330 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][GCOMP
]);
2331 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][RCOMP
]);
2337 dst
[i
*2+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
2338 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
2342 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2348 GLshort
*dst
= (GLshort
*) dstAddr
;
2349 switch (dstFormat
) {
2352 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2356 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2360 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2364 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2368 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
2370 case GL_LUMINANCE_ALPHA
:
2372 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
2373 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2378 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2379 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2380 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2385 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2386 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2387 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2388 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2393 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2394 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2395 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2400 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2401 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2402 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2403 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2408 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2409 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2410 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2411 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2417 dst
[i
*2+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2418 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2422 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2426 case GL_UNSIGNED_INT
:
2428 GLuint
*dst
= (GLuint
*) dstAddr
;
2429 switch (dstFormat
) {
2432 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2436 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2440 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2444 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2448 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
2450 case GL_LUMINANCE_ALPHA
:
2452 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
2453 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2458 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2459 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2460 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2465 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2466 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2467 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2468 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2473 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2474 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2475 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2480 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2481 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2482 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2483 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2488 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2489 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2490 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2491 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2497 dst
[i
*2+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2498 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2502 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2508 GLint
*dst
= (GLint
*) dstAddr
;
2509 switch (dstFormat
) {
2512 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2516 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2520 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2524 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2528 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
2530 case GL_LUMINANCE_ALPHA
:
2532 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
2533 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2538 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2539 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2540 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2545 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2546 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2547 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2548 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2553 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2554 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2555 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2560 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2561 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2562 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2563 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2568 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2569 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2570 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2571 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2577 dst
[i
*2+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2578 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2582 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2588 GLfloat
*dst
= (GLfloat
*) dstAddr
;
2589 switch (dstFormat
) {
2592 dst
[i
] = rgba
[i
][RCOMP
];
2596 dst
[i
] = rgba
[i
][GCOMP
];
2600 dst
[i
] = rgba
[i
][BCOMP
];
2604 dst
[i
] = rgba
[i
][ACOMP
];
2608 dst
[i
] = luminance
[i
];
2610 case GL_LUMINANCE_ALPHA
:
2612 dst
[i
*2+0] = luminance
[i
];
2613 dst
[i
*2+1] = rgba
[i
][ACOMP
];
2618 dst
[i
*3+0] = rgba
[i
][RCOMP
];
2619 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2620 dst
[i
*3+2] = rgba
[i
][BCOMP
];
2625 dst
[i
*4+0] = rgba
[i
][RCOMP
];
2626 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2627 dst
[i
*4+2] = rgba
[i
][BCOMP
];
2628 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2633 dst
[i
*3+0] = rgba
[i
][BCOMP
];
2634 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2635 dst
[i
*3+2] = rgba
[i
][RCOMP
];
2640 dst
[i
*4+0] = rgba
[i
][BCOMP
];
2641 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2642 dst
[i
*4+2] = rgba
[i
][RCOMP
];
2643 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2648 dst
[i
*4+0] = rgba
[i
][ACOMP
];
2649 dst
[i
*4+1] = rgba
[i
][BCOMP
];
2650 dst
[i
*4+2] = rgba
[i
][GCOMP
];
2651 dst
[i
*4+3] = rgba
[i
][RCOMP
];
2657 dst
[i
*2+0] = rgba
[i
][RCOMP
];
2658 dst
[i
*2+1] = rgba
[i
][GCOMP
];
2662 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2666 case GL_HALF_FLOAT_ARB
:
2668 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
2669 switch (dstFormat
) {
2672 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2676 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2680 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2684 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2688 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
2690 case GL_LUMINANCE_ALPHA
:
2692 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
2693 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2698 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2699 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2700 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2705 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2706 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2707 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2708 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2713 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2714 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2715 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2720 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2721 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2722 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2723 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2728 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2729 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2730 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2731 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2737 dst
[i
*2+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2738 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2742 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2746 case GL_UNSIGNED_BYTE_3_3_2
:
2747 if (dstFormat
== GL_RGB
) {
2748 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2750 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 7.0F
) << 5)
2751 | (IROUND(rgba
[i
][GCOMP
] * 7.0F
) << 2)
2752 | (IROUND(rgba
[i
][BCOMP
] * 3.0F
) );
2756 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2757 if (dstFormat
== GL_RGB
) {
2758 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2760 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 7.0F
) )
2761 | (IROUND(rgba
[i
][GCOMP
] * 7.0F
) << 3)
2762 | (IROUND(rgba
[i
][BCOMP
] * 3.0F
) << 6);
2766 case GL_UNSIGNED_SHORT_5_6_5
:
2767 if (dstFormat
== GL_RGB
) {
2768 GLushort
*dst
= (GLushort
*) dstAddr
;
2770 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 11)
2771 | (IROUND(rgba
[i
][GCOMP
] * 63.0F
) << 5)
2772 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) );
2776 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2777 if (dstFormat
== GL_RGB
) {
2778 GLushort
*dst
= (GLushort
*) dstAddr
;
2780 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) )
2781 | (IROUND(rgba
[i
][GCOMP
] * 63.0F
) << 5)
2782 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 11);
2786 case GL_UNSIGNED_SHORT_4_4_4_4
:
2787 if (dstFormat
== GL_RGBA
) {
2788 GLushort
*dst
= (GLushort
*) dstAddr
;
2790 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 12)
2791 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2792 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 4)
2793 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) );
2796 else if (dstFormat
== GL_BGRA
) {
2797 GLushort
*dst
= (GLushort
*) dstAddr
;
2799 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 12)
2800 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2801 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 4)
2802 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) );
2805 else if (dstFormat
== GL_ABGR_EXT
) {
2806 GLushort
*dst
= (GLushort
*) dstAddr
;
2808 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12)
2809 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 8)
2810 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2811 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) );
2815 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2816 if (dstFormat
== GL_RGBA
) {
2817 GLushort
*dst
= (GLushort
*) dstAddr
;
2819 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 15.0F
) )
2820 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2821 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 8)
2822 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12);
2825 else if (dstFormat
== GL_BGRA
) {
2826 GLushort
*dst
= (GLushort
*) dstAddr
;
2828 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 15.0F
) )
2829 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2830 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 8)
2831 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12);
2834 else if (dstFormat
== GL_ABGR_EXT
) {
2835 GLushort
*dst
= (GLushort
*) dstAddr
;
2837 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 15.0F
) )
2838 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 4)
2839 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2840 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 12);
2844 case GL_UNSIGNED_SHORT_5_5_5_1
:
2845 if (dstFormat
== GL_RGBA
) {
2846 GLushort
*dst
= (GLushort
*) dstAddr
;
2848 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 11)
2849 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 6)
2850 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 1)
2851 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) );
2854 else if (dstFormat
== GL_BGRA
) {
2855 GLushort
*dst
= (GLushort
*) dstAddr
;
2857 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 11)
2858 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 6)
2859 | (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 1)
2860 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) );
2863 else if (dstFormat
== GL_ABGR_EXT
) {
2864 GLushort
*dst
= (GLushort
*) dstAddr
;
2866 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 31.0F
) << 11)
2867 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 6)
2868 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 1)
2869 | (IROUND(rgba
[i
][RCOMP
] * 1.0F
) );
2873 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2874 if (dstFormat
== GL_RGBA
) {
2875 GLushort
*dst
= (GLushort
*) dstAddr
;
2877 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) )
2878 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 5)
2879 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 10)
2880 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) << 15);
2883 else if (dstFormat
== GL_BGRA
) {
2884 GLushort
*dst
= (GLushort
*) dstAddr
;
2886 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 31.0F
) )
2887 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 5)
2888 | (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 10)
2889 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) << 15);
2892 else if (dstFormat
== GL_ABGR_EXT
) {
2893 GLushort
*dst
= (GLushort
*) dstAddr
;
2895 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 31.0F
) )
2896 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 5)
2897 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 10)
2898 | (IROUND(rgba
[i
][RCOMP
] * 1.0F
) << 15);
2902 case GL_UNSIGNED_INT_8_8_8_8
:
2903 if (dstFormat
== GL_RGBA
) {
2904 GLuint
*dst
= (GLuint
*) dstAddr
;
2906 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 255.F
) << 24)
2907 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 16)
2908 | (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 8)
2909 | (IROUND(rgba
[i
][ACOMP
] * 255.F
) );
2912 else if (dstFormat
== GL_BGRA
) {
2913 GLuint
*dst
= (GLuint
*) dstAddr
;
2915 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 24)
2916 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 16)
2917 | (IROUND(rgba
[i
][RCOMP
] * 255.F
) << 8)
2918 | (IROUND(rgba
[i
][ACOMP
] * 255.F
) );
2921 else if (dstFormat
== GL_ABGR_EXT
) {
2922 GLuint
*dst
= (GLuint
*) dstAddr
;
2924 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 255.F
) << 24)
2925 | (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 16)
2926 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 8)
2927 | (IROUND(rgba
[i
][RCOMP
] * 255.F
) );
2931 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2932 if (dstFormat
== GL_RGBA
) {
2933 GLuint
*dst
= (GLuint
*) dstAddr
;
2935 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 255.0F
) )
2936 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 8)
2937 | (IROUND(rgba
[i
][BCOMP
] * 255.0F
) << 16)
2938 | (IROUND(rgba
[i
][ACOMP
] * 255.0F
) << 24);
2941 else if (dstFormat
== GL_BGRA
) {
2942 GLuint
*dst
= (GLuint
*) dstAddr
;
2944 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 255.0F
) )
2945 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 8)
2946 | (IROUND(rgba
[i
][RCOMP
] * 255.0F
) << 16)
2947 | (IROUND(rgba
[i
][ACOMP
] * 255.0F
) << 24);
2950 else if (dstFormat
== GL_ABGR_EXT
) {
2951 GLuint
*dst
= (GLuint
*) dstAddr
;
2953 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 255.0F
) )
2954 | (IROUND(rgba
[i
][BCOMP
] * 255.0F
) << 8)
2955 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 16)
2956 | (IROUND(rgba
[i
][RCOMP
] * 255.0F
) << 24);
2960 case GL_UNSIGNED_INT_10_10_10_2
:
2961 if (dstFormat
== GL_RGBA
) {
2962 GLuint
*dst
= (GLuint
*) dstAddr
;
2964 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 22)
2965 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 12)
2966 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 2)
2967 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) );
2970 else if (dstFormat
== GL_BGRA
) {
2971 GLuint
*dst
= (GLuint
*) dstAddr
;
2973 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 22)
2974 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 12)
2975 | (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 2)
2976 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) );
2979 else if (dstFormat
== GL_ABGR_EXT
) {
2980 GLuint
*dst
= (GLuint
*) dstAddr
;
2982 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 1023.0F
) << 22)
2983 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 12)
2984 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 2)
2985 | (IROUND(rgba
[i
][RCOMP
] * 3.0F
) );
2989 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2990 if (dstFormat
== GL_RGBA
) {
2991 GLuint
*dst
= (GLuint
*) dstAddr
;
2993 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) )
2994 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 10)
2995 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 20)
2996 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) << 30);
2999 else if (dstFormat
== GL_BGRA
) {
3000 GLuint
*dst
= (GLuint
*) dstAddr
;
3002 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) )
3003 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 10)
3004 | (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 20)
3005 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) << 30);
3008 else if (dstFormat
== GL_ABGR_EXT
) {
3009 GLuint
*dst
= (GLuint
*) dstAddr
;
3011 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 1023.0F
) )
3012 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 10)
3013 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 20)
3014 | (IROUND(rgba
[i
][RCOMP
] * 3.0F
) << 30);
3019 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
3023 if (dstPacking
->SwapBytes
) {
3024 GLint swapSize
= _mesa_sizeof_packed_type(dstType
);
3025 if (swapSize
== 2) {
3026 if (dstPacking
->SwapBytes
) {
3027 _mesa_swap2((GLushort
*) dstAddr
, n
* comps
);
3030 else if (swapSize
== 4) {
3031 if (dstPacking
->SwapBytes
) {
3032 _mesa_swap4((GLuint
*) dstAddr
, n
* comps
);
3039 #define SWAP2BYTE(VALUE) \
3041 GLubyte *bytes = (GLubyte *) &(VALUE); \
3042 GLubyte tmp = bytes[0]; \
3043 bytes[0] = bytes[1]; \
3047 #define SWAP4BYTE(VALUE) \
3049 GLubyte *bytes = (GLubyte *) &(VALUE); \
3050 GLubyte tmp = bytes[0]; \
3051 bytes[0] = bytes[3]; \
3054 bytes[1] = bytes[2]; \
3060 extract_uint_indexes(GLuint n
, GLuint indexes
[],
3061 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
3062 const struct gl_pixelstore_attrib
*unpack
)
3064 ASSERT(srcFormat
== GL_COLOR_INDEX
|| srcFormat
== GL_STENCIL_INDEX
);
3066 ASSERT(srcType
== GL_BITMAP
||
3067 srcType
== GL_UNSIGNED_BYTE
||
3068 srcType
== GL_BYTE
||
3069 srcType
== GL_UNSIGNED_SHORT
||
3070 srcType
== GL_SHORT
||
3071 srcType
== GL_UNSIGNED_INT
||
3072 srcType
== GL_INT
||
3073 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
3074 srcType
== GL_HALF_FLOAT_ARB
||
3075 srcType
== GL_FLOAT
);
3080 GLubyte
*ubsrc
= (GLubyte
*) src
;
3081 if (unpack
->LsbFirst
) {
3082 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
3084 for (i
= 0; i
< n
; i
++) {
3085 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
3096 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
3098 for (i
= 0; i
< n
; i
++) {
3099 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
3111 case GL_UNSIGNED_BYTE
:
3114 const GLubyte
*s
= (const GLubyte
*) src
;
3115 for (i
= 0; i
< n
; i
++)
3122 const GLbyte
*s
= (const GLbyte
*) src
;
3123 for (i
= 0; i
< n
; i
++)
3127 case GL_UNSIGNED_SHORT
:
3130 const GLushort
*s
= (const GLushort
*) src
;
3131 if (unpack
->SwapBytes
) {
3132 for (i
= 0; i
< n
; i
++) {
3133 GLushort value
= s
[i
];
3139 for (i
= 0; i
< n
; i
++)
3147 const GLshort
*s
= (const GLshort
*) src
;
3148 if (unpack
->SwapBytes
) {
3149 for (i
= 0; i
< n
; i
++) {
3150 GLshort value
= s
[i
];
3156 for (i
= 0; i
< n
; i
++)
3161 case GL_UNSIGNED_INT
:
3164 const GLuint
*s
= (const GLuint
*) src
;
3165 if (unpack
->SwapBytes
) {
3166 for (i
= 0; i
< n
; i
++) {
3167 GLuint value
= s
[i
];
3173 for (i
= 0; i
< n
; i
++)
3181 const GLint
*s
= (const GLint
*) src
;
3182 if (unpack
->SwapBytes
) {
3183 for (i
= 0; i
< n
; i
++) {
3190 for (i
= 0; i
< n
; i
++)
3198 const GLfloat
*s
= (const GLfloat
*) src
;
3199 if (unpack
->SwapBytes
) {
3200 for (i
= 0; i
< n
; i
++) {
3201 GLfloat value
= s
[i
];
3203 indexes
[i
] = (GLuint
) value
;
3207 for (i
= 0; i
< n
; i
++)
3208 indexes
[i
] = (GLuint
) s
[i
];
3212 case GL_HALF_FLOAT_ARB
:
3215 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
3216 if (unpack
->SwapBytes
) {
3217 for (i
= 0; i
< n
; i
++) {
3218 GLhalfARB value
= s
[i
];
3220 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
3224 for (i
= 0; i
< n
; i
++)
3225 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
3229 case GL_UNSIGNED_INT_24_8_EXT
:
3232 const GLuint
*s
= (const GLuint
*) src
;
3233 if (unpack
->SwapBytes
) {
3234 for (i
= 0; i
< n
; i
++) {
3235 GLuint value
= s
[i
];
3237 indexes
[i
] = value
& 0xff; /* lower 8 bits */
3241 for (i
= 0; i
< n
; i
++)
3242 indexes
[i
] = s
[i
] & 0xff; /* lower 8 bits */
3248 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
3255 * This function extracts floating point RGBA values from arbitrary
3256 * image data. srcFormat and srcType are the format and type parameters
3257 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
3259 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
3260 * implements the "Conversion to floating point", "Conversion to RGB",
3261 * and "Final Expansion to RGBA" operations.
3263 * Args: n - number of pixels
3264 * rgba - output colors
3265 * srcFormat - format of incoming data
3266 * srcType - data type of incoming data
3267 * src - source data pointer
3268 * swapBytes - perform byteswapping of incoming data?
3271 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
3272 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
3273 GLboolean swapBytes
)
3275 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
3277 GLint rComp
, bComp
, gComp
, aComp
;
3279 ASSERT(srcFormat
== GL_RED
||
3280 srcFormat
== GL_GREEN
||
3281 srcFormat
== GL_BLUE
||
3282 srcFormat
== GL_ALPHA
||
3283 srcFormat
== GL_LUMINANCE
||
3284 srcFormat
== GL_LUMINANCE_ALPHA
||
3285 srcFormat
== GL_INTENSITY
||
3286 srcFormat
== GL_RGB
||
3287 srcFormat
== GL_BGR
||
3288 srcFormat
== GL_RGBA
||
3289 srcFormat
== GL_BGRA
||
3290 srcFormat
== GL_ABGR_EXT
||
3291 srcFormat
== GL_DU8DV8_ATI
||
3292 srcFormat
== GL_DUDV_ATI
);
3294 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
3295 srcType
== GL_BYTE
||
3296 srcType
== GL_UNSIGNED_SHORT
||
3297 srcType
== GL_SHORT
||
3298 srcType
== GL_UNSIGNED_INT
||
3299 srcType
== GL_INT
||
3300 srcType
== GL_HALF_FLOAT_ARB
||
3301 srcType
== GL_FLOAT
||
3302 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3303 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3304 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3305 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3306 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3307 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3308 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3309 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3310 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3311 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3312 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3313 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3315 rComp
= gComp
= bComp
= aComp
= -1;
3317 switch (srcFormat
) {
3320 greenIndex
= blueIndex
= alphaIndex
= -1;
3325 redIndex
= blueIndex
= alphaIndex
= -1;
3330 redIndex
= greenIndex
= alphaIndex
= -1;
3334 redIndex
= greenIndex
= blueIndex
= -1;
3339 redIndex
= greenIndex
= blueIndex
= 0;
3343 case GL_LUMINANCE_ALPHA
:
3344 redIndex
= greenIndex
= blueIndex
= 0;
3349 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
3416 _mesa_problem(NULL
, "bad srcFormat %s in extract float data",
3417 _mesa_lookup_enum_by_nr(srcFormat
));
3422 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
3423 if ((INDEX) < 0) { \
3425 for (i = 0; i < n; i++) { \
3426 rgba[i][CHANNEL] = DEFAULT; \
3429 else if (swapBytes) { \
3430 const TYPE *s = (const TYPE *) src; \
3432 for (i = 0; i < n; i++) { \
3433 TYPE value = s[INDEX]; \
3434 if (sizeof(TYPE) == 2) { \
3437 else if (sizeof(TYPE) == 4) { \
3440 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
3445 const TYPE *s = (const TYPE *) src; \
3447 for (i = 0; i < n; i++) { \
3448 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
3454 case GL_UNSIGNED_BYTE
:
3455 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3456 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3457 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3458 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3461 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3462 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3463 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3464 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
3466 case GL_UNSIGNED_SHORT
:
3467 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3468 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3469 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3470 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
3473 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3474 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3475 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3476 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
3478 case GL_UNSIGNED_INT
:
3479 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3480 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3481 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3482 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
3485 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3486 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3487 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3488 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
3491 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3492 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3493 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3494 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
3496 case GL_HALF_FLOAT_ARB
:
3497 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3498 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3499 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3500 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
3502 case GL_UNSIGNED_BYTE_3_3_2
:
3504 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3506 for (i
= 0; i
< n
; i
++) {
3507 GLubyte p
= ubsrc
[i
];
3508 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
3509 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
3510 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
3511 rgba
[i
][aComp
] = 1.0F
;
3515 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3517 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3519 for (i
= 0; i
< n
; i
++) {
3520 GLubyte p
= ubsrc
[i
];
3521 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
3522 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
3523 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
3524 rgba
[i
][aComp
] = 1.0F
;
3528 case GL_UNSIGNED_SHORT_5_6_5
:
3530 const GLushort
*ussrc
= (const GLushort
*) src
;
3532 for (i
= 0; i
< n
; i
++) {
3533 GLushort p
= ussrc
[i
];
3535 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3536 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3537 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3538 rgba
[i
][aComp
] = 1.0F
;
3542 const GLushort
*ussrc
= (const GLushort
*) src
;
3544 for (i
= 0; i
< n
; i
++) {
3545 GLushort p
= ussrc
[i
];
3546 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3547 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3548 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3549 rgba
[i
][aComp
] = 1.0F
;
3553 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3555 const GLushort
*ussrc
= (const GLushort
*) src
;
3557 for (i
= 0; i
< n
; i
++) {
3558 GLushort p
= ussrc
[i
];
3560 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3561 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3562 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3563 rgba
[i
][aComp
] = 1.0F
;
3567 const GLushort
*ussrc
= (const GLushort
*) src
;
3569 for (i
= 0; i
< n
; i
++) {
3570 GLushort p
= ussrc
[i
];
3571 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3572 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3573 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3574 rgba
[i
][aComp
] = 1.0F
;
3578 case GL_UNSIGNED_SHORT_4_4_4_4
:
3580 const GLushort
*ussrc
= (const GLushort
*) src
;
3582 for (i
= 0; i
< n
; i
++) {
3583 GLushort p
= ussrc
[i
];
3585 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3586 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3587 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3588 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3592 const GLushort
*ussrc
= (const GLushort
*) src
;
3594 for (i
= 0; i
< n
; i
++) {
3595 GLushort p
= ussrc
[i
];
3596 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3597 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3598 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3599 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3603 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3605 const GLushort
*ussrc
= (const GLushort
*) src
;
3607 for (i
= 0; i
< n
; i
++) {
3608 GLushort p
= ussrc
[i
];
3610 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3611 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3612 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3613 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3617 const GLushort
*ussrc
= (const GLushort
*) src
;
3619 for (i
= 0; i
< n
; i
++) {
3620 GLushort p
= ussrc
[i
];
3621 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3622 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3623 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3624 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3628 case GL_UNSIGNED_SHORT_5_5_5_1
:
3630 const GLushort
*ussrc
= (const GLushort
*) src
;
3632 for (i
= 0; i
< n
; i
++) {
3633 GLushort p
= ussrc
[i
];
3635 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3636 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3637 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3638 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3642 const GLushort
*ussrc
= (const GLushort
*) src
;
3644 for (i
= 0; i
< n
; i
++) {
3645 GLushort p
= ussrc
[i
];
3646 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3647 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3648 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3649 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3653 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3655 const GLushort
*ussrc
= (const GLushort
*) src
;
3657 for (i
= 0; i
< n
; i
++) {
3658 GLushort p
= ussrc
[i
];
3660 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3661 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3662 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3663 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3667 const GLushort
*ussrc
= (const GLushort
*) src
;
3669 for (i
= 0; i
< n
; i
++) {
3670 GLushort p
= ussrc
[i
];
3671 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3672 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3673 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3674 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3678 case GL_UNSIGNED_INT_8_8_8_8
:
3680 const GLuint
*uisrc
= (const GLuint
*) src
;
3682 for (i
= 0; i
< n
; i
++) {
3683 GLuint p
= uisrc
[i
];
3684 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3685 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3686 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3687 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3691 const GLuint
*uisrc
= (const GLuint
*) src
;
3693 for (i
= 0; i
< n
; i
++) {
3694 GLuint p
= uisrc
[i
];
3695 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3696 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3697 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3698 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3702 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3704 const GLuint
*uisrc
= (const GLuint
*) src
;
3706 for (i
= 0; i
< n
; i
++) {
3707 GLuint p
= uisrc
[i
];
3708 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3709 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3710 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3711 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3715 const GLuint
*uisrc
= (const GLuint
*) src
;
3717 for (i
= 0; i
< n
; i
++) {
3718 GLuint p
= uisrc
[i
];
3719 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3720 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3721 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3722 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3726 case GL_UNSIGNED_INT_10_10_10_2
:
3728 const GLuint
*uisrc
= (const GLuint
*) src
;
3730 for (i
= 0; i
< n
; i
++) {
3731 GLuint p
= uisrc
[i
];
3733 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3734 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3735 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3736 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3740 const GLuint
*uisrc
= (const GLuint
*) src
;
3742 for (i
= 0; i
< n
; i
++) {
3743 GLuint p
= uisrc
[i
];
3744 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3745 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3746 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3747 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3751 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3753 const GLuint
*uisrc
= (const GLuint
*) src
;
3755 for (i
= 0; i
< n
; i
++) {
3756 GLuint p
= uisrc
[i
];
3758 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3759 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3760 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3761 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3765 const GLuint
*uisrc
= (const GLuint
*) src
;
3767 for (i
= 0; i
< n
; i
++) {
3768 GLuint p
= uisrc
[i
];
3769 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3770 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3771 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3772 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3777 _mesa_problem(NULL
, "bad srcType in extract float data");
3784 * Unpack a row of color image data from a client buffer according to
3785 * the pixel unpacking parameters.
3786 * Return GLchan values in the specified dest image format.
3787 * This is used by glDrawPixels and glTexImage?D().
3788 * \param ctx - the context
3789 * n - number of pixels in the span
3790 * dstFormat - format of destination color array
3791 * dest - the destination color array
3792 * srcFormat - source image format
3793 * srcType - source image data type
3794 * source - source image pointer
3795 * srcPacking - pixel unpacking parameters
3796 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
3798 * XXX perhaps expand this to process whole images someday.
3801 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
3802 GLuint n
, GLenum dstFormat
, GLchan dest
[],
3803 GLenum srcFormat
, GLenum srcType
,
3804 const GLvoid
*source
,
3805 const struct gl_pixelstore_attrib
*srcPacking
,
3806 GLbitfield transferOps
)
3808 ASSERT(dstFormat
== GL_ALPHA
||
3809 dstFormat
== GL_LUMINANCE
||
3810 dstFormat
== GL_LUMINANCE_ALPHA
||
3811 dstFormat
== GL_INTENSITY
||
3812 dstFormat
== GL_RGB
||
3813 dstFormat
== GL_RGBA
||
3814 dstFormat
== GL_COLOR_INDEX
);
3816 ASSERT(srcFormat
== GL_RED
||
3817 srcFormat
== GL_GREEN
||
3818 srcFormat
== GL_BLUE
||
3819 srcFormat
== GL_ALPHA
||
3820 srcFormat
== GL_LUMINANCE
||
3821 srcFormat
== GL_LUMINANCE_ALPHA
||
3822 srcFormat
== GL_INTENSITY
||
3823 srcFormat
== GL_RGB
||
3824 srcFormat
== GL_BGR
||
3825 srcFormat
== GL_RGBA
||
3826 srcFormat
== GL_BGRA
||
3827 srcFormat
== GL_ABGR_EXT
||
3828 srcFormat
== GL_COLOR_INDEX
);
3830 ASSERT(srcType
== GL_BITMAP
||
3831 srcType
== GL_UNSIGNED_BYTE
||
3832 srcType
== GL_BYTE
||
3833 srcType
== GL_UNSIGNED_SHORT
||
3834 srcType
== GL_SHORT
||
3835 srcType
== GL_UNSIGNED_INT
||
3836 srcType
== GL_INT
||
3837 srcType
== GL_HALF_FLOAT_ARB
||
3838 srcType
== GL_FLOAT
||
3839 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3840 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3841 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3842 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3843 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3844 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3845 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3846 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3847 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3848 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3849 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3850 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3852 /* Try simple cases first */
3853 if (transferOps
== 0) {
3854 if (srcType
== CHAN_TYPE
) {
3855 if (dstFormat
== GL_RGBA
) {
3856 if (srcFormat
== GL_RGBA
) {
3857 memcpy( dest
, source
, n
* 4 * sizeof(GLchan
) );
3860 else if (srcFormat
== GL_RGB
) {
3862 const GLchan
*src
= (const GLchan
*) source
;
3864 for (i
= 0; i
< n
; i
++) {
3875 else if (dstFormat
== GL_RGB
) {
3876 if (srcFormat
== GL_RGB
) {
3877 memcpy( dest
, source
, n
* 3 * sizeof(GLchan
) );
3880 else if (srcFormat
== GL_RGBA
) {
3882 const GLchan
*src
= (const GLchan
*) source
;
3884 for (i
= 0; i
< n
; i
++) {
3894 else if (dstFormat
== srcFormat
) {
3895 GLint comps
= _mesa_components_in_format(srcFormat
);
3897 memcpy( dest
, source
, n
* comps
* sizeof(GLchan
) );
3902 * Common situation, loading 8bit RGBA/RGB source images
3903 * into 16/32 bit destination. (OSMesa16/32)
3905 else if (srcType
== GL_UNSIGNED_BYTE
) {
3906 if (dstFormat
== GL_RGBA
) {
3907 if (srcFormat
== GL_RGB
) {
3909 const GLubyte
*src
= (const GLubyte
*) source
;
3911 for (i
= 0; i
< n
; i
++) {
3912 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3913 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3914 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3921 else if (srcFormat
== GL_RGBA
) {
3923 const GLubyte
*src
= (const GLubyte
*) source
;
3925 for (i
= 0; i
< n
; i
++) {
3926 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3927 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3928 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3929 dst
[3] = UBYTE_TO_CHAN(src
[3]);
3936 else if (dstFormat
== GL_RGB
) {
3937 if (srcFormat
== GL_RGB
) {
3939 const GLubyte
*src
= (const GLubyte
*) source
;
3941 for (i
= 0; i
< n
; i
++) {
3942 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3943 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3944 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3950 else if (srcFormat
== GL_RGBA
) {
3952 const GLubyte
*src
= (const GLubyte
*) source
;
3954 for (i
= 0; i
< n
; i
++) {
3955 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3956 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3957 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3968 /* general solution begins here */
3970 GLint dstComponents
;
3971 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3972 GLint dstLuminanceIndex
, dstIntensityIndex
;
3973 GLfloat rgba
[MAX_WIDTH
][4];
3975 dstComponents
= _mesa_components_in_format( dstFormat
);
3976 /* source & dest image formats should have been error checked by now */
3977 assert(dstComponents
> 0);
3980 * Extract image data and convert to RGBA floats
3982 assert(n
<= MAX_WIDTH
);
3983 if (srcFormat
== GL_COLOR_INDEX
) {
3984 GLuint indexes
[MAX_WIDTH
];
3985 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3988 if (dstFormat
== GL_COLOR_INDEX
) {
3990 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3991 /* convert to GLchan and return */
3992 for (i
= 0; i
< n
; i
++) {
3993 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3998 /* Convert indexes to RGBA */
3999 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
4000 shift_and_offset_ci(ctx
, n
, indexes
);
4002 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
4005 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
4006 * with color indexes.
4008 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
4011 /* non-color index data */
4012 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
4013 srcPacking
->SwapBytes
);
4016 /* Need to clamp if returning GLubytes or GLushorts */
4017 #if CHAN_TYPE != GL_FLOAT
4018 transferOps
|= IMAGE_CLAMP_BIT
;
4022 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
4025 /* Now determine which color channels we need to produce.
4026 * And determine the dest index (offset) within each color tuple.
4028 switch (dstFormat
) {
4031 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
4032 dstLuminanceIndex
= dstIntensityIndex
= -1;
4035 dstLuminanceIndex
= 0;
4036 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
4037 dstIntensityIndex
= -1;
4039 case GL_LUMINANCE_ALPHA
:
4040 dstLuminanceIndex
= 0;
4042 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
4043 dstIntensityIndex
= -1;
4046 dstIntensityIndex
= 0;
4047 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
4048 dstLuminanceIndex
= -1;
4054 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
4061 dstLuminanceIndex
= dstIntensityIndex
= -1;
4064 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
4069 /* Now return the GLchan data in the requested dstFormat */
4071 if (dstRedIndex
>= 0) {
4074 for (i
= 0; i
< n
; i
++) {
4075 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
4076 dst
+= dstComponents
;
4080 if (dstGreenIndex
>= 0) {
4083 for (i
= 0; i
< n
; i
++) {
4084 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
4085 dst
+= dstComponents
;
4089 if (dstBlueIndex
>= 0) {
4092 for (i
= 0; i
< n
; i
++) {
4093 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
4094 dst
+= dstComponents
;
4098 if (dstAlphaIndex
>= 0) {
4101 for (i
= 0; i
< n
; i
++) {
4102 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
4103 dst
+= dstComponents
;
4107 if (dstIntensityIndex
>= 0) {
4110 assert(dstIntensityIndex
== 0);
4111 assert(dstComponents
== 1);
4112 for (i
= 0; i
< n
; i
++) {
4113 /* Intensity comes from red channel */
4114 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
4118 if (dstLuminanceIndex
>= 0) {
4121 assert(dstLuminanceIndex
== 0);
4122 for (i
= 0; i
< n
; i
++) {
4123 /* Luminance comes from red channel */
4124 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
4125 dst
+= dstComponents
;
4133 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
4134 * instead of GLchan.
4137 _mesa_unpack_color_span_float( GLcontext
*ctx
,
4138 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
4139 GLenum srcFormat
, GLenum srcType
,
4140 const GLvoid
*source
,
4141 const struct gl_pixelstore_attrib
*srcPacking
,
4142 GLbitfield transferOps
)
4144 ASSERT(dstFormat
== GL_ALPHA
||
4145 dstFormat
== GL_LUMINANCE
||
4146 dstFormat
== GL_LUMINANCE_ALPHA
||
4147 dstFormat
== GL_INTENSITY
||
4148 dstFormat
== GL_RGB
||
4149 dstFormat
== GL_RGBA
||
4150 dstFormat
== GL_COLOR_INDEX
);
4152 ASSERT(srcFormat
== GL_RED
||
4153 srcFormat
== GL_GREEN
||
4154 srcFormat
== GL_BLUE
||
4155 srcFormat
== GL_ALPHA
||
4156 srcFormat
== GL_LUMINANCE
||
4157 srcFormat
== GL_LUMINANCE_ALPHA
||
4158 srcFormat
== GL_INTENSITY
||
4159 srcFormat
== GL_RGB
||
4160 srcFormat
== GL_BGR
||
4161 srcFormat
== GL_RGBA
||
4162 srcFormat
== GL_BGRA
||
4163 srcFormat
== GL_ABGR_EXT
||
4164 srcFormat
== GL_COLOR_INDEX
);
4166 ASSERT(srcType
== GL_BITMAP
||
4167 srcType
== GL_UNSIGNED_BYTE
||
4168 srcType
== GL_BYTE
||
4169 srcType
== GL_UNSIGNED_SHORT
||
4170 srcType
== GL_SHORT
||
4171 srcType
== GL_UNSIGNED_INT
||
4172 srcType
== GL_INT
||
4173 srcType
== GL_HALF_FLOAT_ARB
||
4174 srcType
== GL_FLOAT
||
4175 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
4176 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
4177 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
4178 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
4179 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
4180 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
4181 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
4182 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
4183 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
4184 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
4185 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
4186 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
4188 /* general solution, no special cases, yet */
4190 GLint dstComponents
;
4191 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
4192 GLint dstLuminanceIndex
, dstIntensityIndex
;
4193 GLfloat rgba
[MAX_WIDTH
][4];
4195 dstComponents
= _mesa_components_in_format( dstFormat
);
4196 /* source & dest image formats should have been error checked by now */
4197 assert(dstComponents
> 0);
4200 * Extract image data and convert to RGBA floats
4202 assert(n
<= MAX_WIDTH
);
4203 if (srcFormat
== GL_COLOR_INDEX
) {
4204 GLuint indexes
[MAX_WIDTH
];
4205 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
4208 if (dstFormat
== GL_COLOR_INDEX
) {
4210 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4211 /* convert to GLchan and return */
4212 for (i
= 0; i
< n
; i
++) {
4213 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
4218 /* Convert indexes to RGBA */
4219 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
4220 shift_and_offset_ci(ctx
, n
, indexes
);
4222 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
4225 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
4226 * with color indexes.
4228 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
4231 /* non-color index data */
4232 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
4233 srcPacking
->SwapBytes
);
4237 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
4240 /* Now determine which color channels we need to produce.
4241 * And determine the dest index (offset) within each color tuple.
4243 switch (dstFormat
) {
4246 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
4247 dstLuminanceIndex
= dstIntensityIndex
= -1;
4250 dstLuminanceIndex
= 0;
4251 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
4252 dstIntensityIndex
= -1;
4254 case GL_LUMINANCE_ALPHA
:
4255 dstLuminanceIndex
= 0;
4257 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
4258 dstIntensityIndex
= -1;
4261 dstIntensityIndex
= 0;
4262 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
4263 dstLuminanceIndex
= -1;
4269 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
4276 dstLuminanceIndex
= dstIntensityIndex
= -1;
4279 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
4283 /* Now pack results in the requested dstFormat */
4284 if (dstRedIndex
>= 0) {
4285 GLfloat
*dst
= dest
;
4287 for (i
= 0; i
< n
; i
++) {
4288 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
4289 dst
+= dstComponents
;
4293 if (dstGreenIndex
>= 0) {
4294 GLfloat
*dst
= dest
;
4296 for (i
= 0; i
< n
; i
++) {
4297 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
4298 dst
+= dstComponents
;
4302 if (dstBlueIndex
>= 0) {
4303 GLfloat
*dst
= dest
;
4305 for (i
= 0; i
< n
; i
++) {
4306 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
4307 dst
+= dstComponents
;
4311 if (dstAlphaIndex
>= 0) {
4312 GLfloat
*dst
= dest
;
4314 for (i
= 0; i
< n
; i
++) {
4315 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
4316 dst
+= dstComponents
;
4320 if (dstIntensityIndex
>= 0) {
4321 GLfloat
*dst
= dest
;
4323 assert(dstIntensityIndex
== 0);
4324 assert(dstComponents
== 1);
4325 for (i
= 0; i
< n
; i
++) {
4326 /* Intensity comes from red channel */
4327 dst
[i
] = rgba
[i
][RCOMP
];
4331 if (dstLuminanceIndex
>= 0) {
4332 GLfloat
*dst
= dest
;
4334 assert(dstLuminanceIndex
== 0);
4335 for (i
= 0; i
< n
; i
++) {
4336 /* Luminance comes from red channel */
4337 dst
[0] = rgba
[i
][RCOMP
];
4338 dst
+= dstComponents
;
4345 * Similar to _mesa_unpack_color_span_float(), but for dudv data instead of rgba,
4346 * directly return GLbyte data, no transfer ops apply.
4349 _mesa_unpack_dudv_span_byte( GLcontext
*ctx
,
4350 GLuint n
, GLenum dstFormat
, GLbyte dest
[],
4351 GLenum srcFormat
, GLenum srcType
,
4352 const GLvoid
*source
,
4353 const struct gl_pixelstore_attrib
*srcPacking
,
4354 GLbitfield transferOps
)
4356 ASSERT(dstFormat
== GL_DUDV_ATI
);
4357 ASSERT(srcFormat
== GL_DUDV_ATI
);
4359 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
4360 srcType
== GL_BYTE
||
4361 srcType
== GL_UNSIGNED_SHORT
||
4362 srcType
== GL_SHORT
||
4363 srcType
== GL_UNSIGNED_INT
||
4364 srcType
== GL_INT
||
4365 srcType
== GL_HALF_FLOAT_ARB
||
4366 srcType
== GL_FLOAT
);
4368 /* general solution */
4370 GLint dstComponents
;
4371 GLfloat rgba
[MAX_WIDTH
][4];
4375 dstComponents
= _mesa_components_in_format( dstFormat
);
4376 /* source & dest image formats should have been error checked by now */
4377 assert(dstComponents
> 0);
4380 * Extract image data and convert to RGBA floats
4382 assert(n
<= MAX_WIDTH
);
4383 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
4384 srcPacking
->SwapBytes
);
4387 /* Now determine which color channels we need to produce.
4388 * And determine the dest index (offset) within each color tuple.
4391 /* Now pack results in the requested dstFormat */
4392 for (i
= 0; i
< n
; i
++) {
4393 /* not sure - need clamp[-1,1] here? */
4394 dst
[0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
4395 dst
[1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
4396 dst
+= dstComponents
;
4402 * Unpack a row of color index data from a client buffer according to
4403 * the pixel unpacking parameters.
4404 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
4406 * Args: ctx - the context
4407 * n - number of pixels
4408 * dstType - destination data type
4409 * dest - destination array
4410 * srcType - source pixel type
4411 * source - source data pointer
4412 * srcPacking - pixel unpacking parameters
4413 * transferOps - the pixel transfer operations to apply
4416 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
4417 GLenum dstType
, GLvoid
*dest
,
4418 GLenum srcType
, const GLvoid
*source
,
4419 const struct gl_pixelstore_attrib
*srcPacking
,
4420 GLbitfield transferOps
)
4422 ASSERT(srcType
== GL_BITMAP
||
4423 srcType
== GL_UNSIGNED_BYTE
||
4424 srcType
== GL_BYTE
||
4425 srcType
== GL_UNSIGNED_SHORT
||
4426 srcType
== GL_SHORT
||
4427 srcType
== GL_UNSIGNED_INT
||
4428 srcType
== GL_INT
||
4429 srcType
== GL_HALF_FLOAT_ARB
||
4430 srcType
== GL_FLOAT
);
4432 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4433 dstType
== GL_UNSIGNED_SHORT
||
4434 dstType
== GL_UNSIGNED_INT
);
4437 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4440 * Try simple cases first
4442 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
4443 && dstType
== GL_UNSIGNED_BYTE
) {
4444 memcpy(dest
, source
, n
* sizeof(GLubyte
));
4446 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
4447 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
4448 memcpy(dest
, source
, n
* sizeof(GLuint
));
4454 GLuint indexes
[MAX_WIDTH
];
4455 assert(n
<= MAX_WIDTH
);
4457 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
4461 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4463 /* convert to dest type */
4465 case GL_UNSIGNED_BYTE
:
4467 GLubyte
*dst
= (GLubyte
*) dest
;
4469 for (i
= 0; i
< n
; i
++) {
4470 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4474 case GL_UNSIGNED_SHORT
:
4476 GLuint
*dst
= (GLuint
*) dest
;
4478 for (i
= 0; i
< n
; i
++) {
4479 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4483 case GL_UNSIGNED_INT
:
4484 memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4487 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
4494 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
4495 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
4496 const struct gl_pixelstore_attrib
*dstPacking
,
4497 GLbitfield transferOps
)
4499 GLuint indexes
[MAX_WIDTH
];
4501 ASSERT(n
<= MAX_WIDTH
);
4503 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4505 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
4506 /* make a copy of input */
4507 memcpy(indexes
, source
, n
* sizeof(GLuint
));
4508 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4513 case GL_UNSIGNED_BYTE
:
4515 GLubyte
*dst
= (GLubyte
*) dest
;
4517 for (i
= 0; i
< n
; i
++) {
4518 *dst
++ = (GLubyte
) source
[i
];
4524 GLbyte
*dst
= (GLbyte
*) dest
;
4526 for (i
= 0; i
< n
; i
++) {
4527 dst
[i
] = (GLbyte
) source
[i
];
4531 case GL_UNSIGNED_SHORT
:
4533 GLushort
*dst
= (GLushort
*) dest
;
4535 for (i
= 0; i
< n
; i
++) {
4536 dst
[i
] = (GLushort
) source
[i
];
4538 if (dstPacking
->SwapBytes
) {
4539 _mesa_swap2( (GLushort
*) dst
, n
);
4545 GLshort
*dst
= (GLshort
*) dest
;
4547 for (i
= 0; i
< n
; i
++) {
4548 dst
[i
] = (GLshort
) source
[i
];
4550 if (dstPacking
->SwapBytes
) {
4551 _mesa_swap2( (GLushort
*) dst
, n
);
4555 case GL_UNSIGNED_INT
:
4557 GLuint
*dst
= (GLuint
*) dest
;
4559 for (i
= 0; i
< n
; i
++) {
4560 dst
[i
] = (GLuint
) source
[i
];
4562 if (dstPacking
->SwapBytes
) {
4563 _mesa_swap4( (GLuint
*) dst
, n
);
4569 GLint
*dst
= (GLint
*) dest
;
4571 for (i
= 0; i
< n
; i
++) {
4572 dst
[i
] = (GLint
) source
[i
];
4574 if (dstPacking
->SwapBytes
) {
4575 _mesa_swap4( (GLuint
*) dst
, n
);
4581 GLfloat
*dst
= (GLfloat
*) dest
;
4583 for (i
= 0; i
< n
; i
++) {
4584 dst
[i
] = (GLfloat
) source
[i
];
4586 if (dstPacking
->SwapBytes
) {
4587 _mesa_swap4( (GLuint
*) dst
, n
);
4591 case GL_HALF_FLOAT_ARB
:
4593 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4595 for (i
= 0; i
< n
; i
++) {
4596 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
4598 if (dstPacking
->SwapBytes
) {
4599 _mesa_swap2( (GLushort
*) dst
, n
);
4604 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4610 * Unpack a row of stencil data from a client buffer according to
4611 * the pixel unpacking parameters.
4612 * This is (or will be) used by glDrawPixels
4614 * Args: ctx - the context
4615 * n - number of pixels
4616 * dstType - destination data type
4617 * dest - destination array
4618 * srcType - source pixel type
4619 * source - source data pointer
4620 * srcPacking - pixel unpacking parameters
4621 * transferOps - apply offset/bias/lookup ops?
4624 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4625 GLenum dstType
, GLvoid
*dest
,
4626 GLenum srcType
, const GLvoid
*source
,
4627 const struct gl_pixelstore_attrib
*srcPacking
,
4628 GLbitfield transferOps
)
4630 ASSERT(srcType
== GL_BITMAP
||
4631 srcType
== GL_UNSIGNED_BYTE
||
4632 srcType
== GL_BYTE
||
4633 srcType
== GL_UNSIGNED_SHORT
||
4634 srcType
== GL_SHORT
||
4635 srcType
== GL_UNSIGNED_INT
||
4636 srcType
== GL_INT
||
4637 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
4638 srcType
== GL_HALF_FLOAT_ARB
||
4639 srcType
== GL_FLOAT
);
4641 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4642 dstType
== GL_UNSIGNED_SHORT
||
4643 dstType
== GL_UNSIGNED_INT
);
4645 /* only shift and offset apply to stencil */
4646 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
4649 * Try simple cases first
4651 if (transferOps
== 0 &&
4652 !ctx
->Pixel
.MapStencilFlag
&&
4653 srcType
== GL_UNSIGNED_BYTE
&&
4654 dstType
== GL_UNSIGNED_BYTE
) {
4655 memcpy(dest
, source
, n
* sizeof(GLubyte
));
4657 else if (transferOps
== 0 &&
4658 !ctx
->Pixel
.MapStencilFlag
&&
4659 srcType
== GL_UNSIGNED_INT
&&
4660 dstType
== GL_UNSIGNED_INT
&&
4661 !srcPacking
->SwapBytes
) {
4662 memcpy(dest
, source
, n
* sizeof(GLuint
));
4668 GLuint indexes
[MAX_WIDTH
];
4669 assert(n
<= MAX_WIDTH
);
4671 extract_uint_indexes(n
, indexes
, GL_STENCIL_INDEX
, srcType
, source
,
4674 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
4675 /* shift and offset indexes */
4676 shift_and_offset_ci(ctx
, n
, indexes
);
4679 if (ctx
->Pixel
.MapStencilFlag
) {
4680 /* Apply stencil lookup table */
4681 const GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
4683 for (i
= 0; i
< n
; i
++) {
4684 indexes
[i
] = (GLuint
)ctx
->PixelMaps
.StoS
.Map
[ indexes
[i
] & mask
];
4688 /* convert to dest type */
4690 case GL_UNSIGNED_BYTE
:
4692 GLubyte
*dst
= (GLubyte
*) dest
;
4694 for (i
= 0; i
< n
; i
++) {
4695 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4699 case GL_UNSIGNED_SHORT
:
4701 GLuint
*dst
= (GLuint
*) dest
;
4703 for (i
= 0; i
< n
; i
++) {
4704 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4708 case GL_UNSIGNED_INT
:
4709 memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4712 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
4719 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4720 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
4721 const struct gl_pixelstore_attrib
*dstPacking
)
4723 GLstencil stencil
[MAX_WIDTH
];
4725 ASSERT(n
<= MAX_WIDTH
);
4727 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
4728 ctx
->Pixel
.MapStencilFlag
) {
4729 /* make a copy of input */
4730 memcpy(stencil
, source
, n
* sizeof(GLstencil
));
4731 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencil
);
4736 case GL_UNSIGNED_BYTE
:
4737 if (sizeof(GLstencil
) == 1) {
4738 memcpy( dest
, source
, n
);
4741 GLubyte
*dst
= (GLubyte
*) dest
;
4744 dst
[i
] = (GLubyte
) source
[i
];
4750 GLbyte
*dst
= (GLbyte
*) dest
;
4753 dst
[i
] = (GLbyte
) (source
[i
] & 0x7f);
4757 case GL_UNSIGNED_SHORT
:
4759 GLushort
*dst
= (GLushort
*) dest
;
4762 dst
[i
] = (GLushort
) source
[i
];
4764 if (dstPacking
->SwapBytes
) {
4765 _mesa_swap2( (GLushort
*) dst
, n
);
4771 GLshort
*dst
= (GLshort
*) dest
;
4774 dst
[i
] = (GLshort
) source
[i
];
4776 if (dstPacking
->SwapBytes
) {
4777 _mesa_swap2( (GLushort
*) dst
, n
);
4781 case GL_UNSIGNED_INT
:
4783 GLuint
*dst
= (GLuint
*) dest
;
4786 dst
[i
] = (GLuint
) source
[i
];
4788 if (dstPacking
->SwapBytes
) {
4789 _mesa_swap4( (GLuint
*) dst
, n
);
4795 GLint
*dst
= (GLint
*) dest
;
4798 dst
[i
] = (GLint
) source
[i
];
4800 if (dstPacking
->SwapBytes
) {
4801 _mesa_swap4( (GLuint
*) dst
, n
);
4807 GLfloat
*dst
= (GLfloat
*) dest
;
4810 dst
[i
] = (GLfloat
) source
[i
];
4812 if (dstPacking
->SwapBytes
) {
4813 _mesa_swap4( (GLuint
*) dst
, n
);
4817 case GL_HALF_FLOAT_ARB
:
4819 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4822 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
4824 if (dstPacking
->SwapBytes
) {
4825 _mesa_swap2( (GLushort
*) dst
, n
);
4830 if (dstPacking
->LsbFirst
) {
4831 GLubyte
*dst
= (GLubyte
*) dest
;
4834 for (i
= 0; i
< n
; i
++) {
4837 *dst
|= ((source
[i
] != 0) << shift
);
4846 GLubyte
*dst
= (GLubyte
*) dest
;
4849 for (i
= 0; i
< n
; i
++) {
4852 *dst
|= ((source
[i
] != 0) << shift
);
4862 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4866 #define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT) \
4869 const GLTYPE *src = (const GLTYPE *)source; \
4870 for (i = 0; i < n; i++) { \
4871 GLTYPE value = src[i]; \
4872 if (srcPacking->SwapBytes) { \
4873 if (sizeof(GLTYPE) == 2) { \
4875 } else if (sizeof(GLTYPE) == 4) { \
4879 depthValues[i] = GLTYPE2FLOAT(value); \
4885 * Unpack a row of depth/z values from memory, returning GLushort, GLuint
4886 * or GLfloat values.
4887 * The glPixelTransfer (scale/bias) params will be applied.
4889 * \param dstType one of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT
4890 * \param depthMax max value for returned GLushort or GLuint values
4891 * (ignored for GLfloat).
4894 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
,
4895 GLenum dstType
, GLvoid
*dest
, GLuint depthMax
,
4896 GLenum srcType
, const GLvoid
*source
,
4897 const struct gl_pixelstore_attrib
*srcPacking
)
4899 GLfloat depthTemp
[MAX_WIDTH
], *depthValues
;
4900 GLboolean needClamp
= GL_FALSE
;
4902 /* Look for special cases first.
4903 * Not only are these faster, they're less prone to numeric conversion
4904 * problems. Otherwise, converting from an int type to a float then
4905 * back to an int type can introduce errors that will show up as
4906 * artifacts in things like depth peeling which uses glCopyTexImage.
4908 if (ctx
->Pixel
.DepthScale
== 1.0 && ctx
->Pixel
.DepthBias
== 0.0) {
4909 if (srcType
== GL_UNSIGNED_INT
&& dstType
== GL_UNSIGNED_SHORT
) {
4910 const GLuint
*src
= (const GLuint
*) source
;
4911 GLushort
*dst
= (GLushort
*) dest
;
4913 for (i
= 0; i
< n
; i
++) {
4914 dst
[i
] = src
[i
] >> 16;
4918 if (srcType
== GL_UNSIGNED_SHORT
4919 && dstType
== GL_UNSIGNED_INT
4920 && depthMax
== 0xffffffff) {
4921 const GLushort
*src
= (const GLushort
*) source
;
4922 GLuint
*dst
= (GLuint
*) dest
;
4924 for (i
= 0; i
< n
; i
++) {
4925 dst
[i
] = src
[i
] | (src
[i
] << 16);
4929 if (srcType
== GL_UNSIGNED_INT_24_8
4930 && dstType
== GL_UNSIGNED_INT
4931 && depthMax
== 0xffffff) {
4932 const GLuint
*src
= (const GLuint
*) source
;
4933 GLuint
*dst
= (GLuint
*) dest
;
4935 for (i
= 0; i
< n
; i
++) {
4936 dst
[i
] = src
[i
] >> 8;
4940 /* XXX may want to add additional cases here someday */
4943 /* general case path follows */
4945 if (dstType
== GL_FLOAT
) {
4946 depthValues
= (GLfloat
*) dest
;
4949 depthValues
= depthTemp
;
4952 /* Convert incoming values to GLfloat. Some conversions will require
4957 DEPTH_VALUES(GLbyte
, BYTE_TO_FLOAT
);
4958 needClamp
= GL_TRUE
;
4960 case GL_UNSIGNED_BYTE
:
4961 DEPTH_VALUES(GLubyte
, UBYTE_TO_FLOAT
);
4964 DEPTH_VALUES(GLshort
, SHORT_TO_FLOAT
);
4965 needClamp
= GL_TRUE
;
4967 case GL_UNSIGNED_SHORT
:
4968 DEPTH_VALUES(GLushort
, USHORT_TO_FLOAT
);
4971 DEPTH_VALUES(GLint
, INT_TO_FLOAT
);
4972 needClamp
= GL_TRUE
;
4974 case GL_UNSIGNED_INT
:
4975 DEPTH_VALUES(GLuint
, UINT_TO_FLOAT
);
4977 case GL_UNSIGNED_INT_24_8_EXT
: /* GL_EXT_packed_depth_stencil */
4978 if (dstType
== GL_UNSIGNED_INT_24_8_EXT
&&
4979 depthMax
== 0xffffff &&
4980 ctx
->Pixel
.DepthScale
== 1.0 &&
4981 ctx
->Pixel
.DepthBias
== 0.0) {
4982 const GLuint
*src
= (const GLuint
*) source
;
4983 GLuint
*zValues
= (GLuint
*) dest
;
4985 for (i
= 0; i
< n
; i
++) {
4986 GLuint value
= src
[i
];
4987 if (srcPacking
->SwapBytes
) {
4990 zValues
[i
] = value
& 0xffffff00;
4995 const GLuint
*src
= (const GLuint
*) source
;
4996 const GLfloat scale
= 1.0f
/ 0xffffff;
4998 for (i
= 0; i
< n
; i
++) {
4999 GLuint value
= src
[i
];
5000 if (srcPacking
->SwapBytes
) {
5003 depthValues
[i
] = (value
>> 8) * scale
;
5008 DEPTH_VALUES(GLfloat
, 1*);
5009 needClamp
= GL_TRUE
;
5011 case GL_HALF_FLOAT_ARB
:
5014 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
5015 for (i
= 0; i
< n
; i
++) {
5016 GLhalfARB value
= src
[i
];
5017 if (srcPacking
->SwapBytes
) {
5020 depthValues
[i
] = _mesa_half_to_float(value
);
5022 needClamp
= GL_TRUE
;
5026 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
5030 /* apply depth scale and bias */
5032 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
5033 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
5034 if (scale
!= 1.0 || bias
!= 0.0) {
5036 for (i
= 0; i
< n
; i
++) {
5037 depthValues
[i
] = depthValues
[i
] * scale
+ bias
;
5039 needClamp
= GL_TRUE
;
5043 /* clamp to [0, 1] */
5046 for (i
= 0; i
< n
; i
++) {
5047 depthValues
[i
] = (GLfloat
)CLAMP(depthValues
[i
], 0.0, 1.0);
5052 * Convert values to dstType
5054 if (dstType
== GL_UNSIGNED_INT
) {
5055 GLuint
*zValues
= (GLuint
*) dest
;
5057 if (depthMax
<= 0xffffff) {
5058 /* no overflow worries */
5059 for (i
= 0; i
< n
; i
++) {
5060 zValues
[i
] = (GLuint
) (depthValues
[i
] * (GLfloat
) depthMax
);
5064 /* need to use double precision to prevent overflow problems */
5065 for (i
= 0; i
< n
; i
++) {
5066 GLdouble z
= depthValues
[i
] * (GLfloat
) depthMax
;
5067 if (z
>= (GLdouble
) 0xffffffff)
5068 zValues
[i
] = 0xffffffff;
5070 zValues
[i
] = (GLuint
) z
;
5074 else if (dstType
== GL_UNSIGNED_SHORT
) {
5075 GLushort
*zValues
= (GLushort
*) dest
;
5077 ASSERT(depthMax
<= 0xffff);
5078 for (i
= 0; i
< n
; i
++) {
5079 zValues
[i
] = (GLushort
) (depthValues
[i
] * (GLfloat
) depthMax
);
5083 ASSERT(dstType
== GL_FLOAT
);
5084 /*ASSERT(depthMax == 1.0F);*/
5090 * Pack an array of depth values. The values are floats in [0,1].
5093 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
5094 GLenum dstType
, const GLfloat
*depthSpan
,
5095 const struct gl_pixelstore_attrib
*dstPacking
)
5097 GLfloat depthCopy
[MAX_WIDTH
];
5099 ASSERT(n
<= MAX_WIDTH
);
5101 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
5102 memcpy(depthCopy
, depthSpan
, n
* sizeof(GLfloat
));
5103 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
5104 depthSpan
= depthCopy
;
5108 case GL_UNSIGNED_BYTE
:
5110 GLubyte
*dst
= (GLubyte
*) dest
;
5112 for (i
= 0; i
< n
; i
++) {
5113 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
5119 GLbyte
*dst
= (GLbyte
*) dest
;
5121 for (i
= 0; i
< n
; i
++) {
5122 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
5126 case GL_UNSIGNED_SHORT
:
5128 GLushort
*dst
= (GLushort
*) dest
;
5130 for (i
= 0; i
< n
; i
++) {
5131 CLAMPED_FLOAT_TO_USHORT(dst
[i
], depthSpan
[i
]);
5133 if (dstPacking
->SwapBytes
) {
5134 _mesa_swap2( (GLushort
*) dst
, n
);
5140 GLshort
*dst
= (GLshort
*) dest
;
5142 for (i
= 0; i
< n
; i
++) {
5143 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
5145 if (dstPacking
->SwapBytes
) {
5146 _mesa_swap2( (GLushort
*) dst
, n
);
5150 case GL_UNSIGNED_INT
:
5152 GLuint
*dst
= (GLuint
*) dest
;
5154 for (i
= 0; i
< n
; i
++) {
5155 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
5157 if (dstPacking
->SwapBytes
) {
5158 _mesa_swap4( (GLuint
*) dst
, n
);
5164 GLint
*dst
= (GLint
*) dest
;
5166 for (i
= 0; i
< n
; i
++) {
5167 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
5169 if (dstPacking
->SwapBytes
) {
5170 _mesa_swap4( (GLuint
*) dst
, n
);
5176 GLfloat
*dst
= (GLfloat
*) dest
;
5178 for (i
= 0; i
< n
; i
++) {
5179 dst
[i
] = depthSpan
[i
];
5181 if (dstPacking
->SwapBytes
) {
5182 _mesa_swap4( (GLuint
*) dst
, n
);
5186 case GL_HALF_FLOAT_ARB
:
5188 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
5190 for (i
= 0; i
< n
; i
++) {
5191 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
5193 if (dstPacking
->SwapBytes
) {
5194 _mesa_swap2( (GLushort
*) dst
, n
);
5199 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
5206 * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
5209 _mesa_pack_depth_stencil_span(const GLcontext
*ctx
, GLuint n
, GLuint
*dest
,
5210 const GLfloat
*depthVals
,
5211 const GLstencil
*stencilVals
,
5212 const struct gl_pixelstore_attrib
*dstPacking
)
5214 GLfloat depthCopy
[MAX_WIDTH
];
5215 GLstencil stencilCopy
[MAX_WIDTH
];
5218 ASSERT(n
<= MAX_WIDTH
);
5220 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
5221 memcpy(depthCopy
, depthVals
, n
* sizeof(GLfloat
));
5222 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
5223 depthVals
= depthCopy
;
5226 if (ctx
->Pixel
.IndexShift
||
5227 ctx
->Pixel
.IndexOffset
||
5228 ctx
->Pixel
.MapStencilFlag
) {
5229 memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
5230 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencilCopy
);
5231 stencilVals
= stencilCopy
;
5234 for (i
= 0; i
< n
; i
++) {
5235 GLuint z
= (GLuint
) (depthVals
[i
] * 0xffffff);
5236 dest
[i
] = (z
<< 8) | (stencilVals
[i
] & 0xff);
5239 if (dstPacking
->SwapBytes
) {
5240 _mesa_swap4(dest
, n
);
5248 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
5249 * Return all image data in a contiguous block. This is used when we
5250 * compile glDrawPixels, glTexImage, etc into a display list. We
5251 * need a copy of the data in a standard format.
5254 _mesa_unpack_image( GLuint dimensions
,
5255 GLsizei width
, GLsizei height
, GLsizei depth
,
5256 GLenum format
, GLenum type
, const GLvoid
*pixels
,
5257 const struct gl_pixelstore_attrib
*unpack
)
5259 GLint bytesPerRow
, compsPerRow
;
5260 GLboolean flipBytes
, swap2
, swap4
;
5263 return NULL
; /* not necessarily an error */
5265 if (width
<= 0 || height
<= 0 || depth
<= 0)
5266 return NULL
; /* generate error later */
5268 if (type
== GL_BITMAP
) {
5269 bytesPerRow
= (width
+ 7) >> 3;
5270 flipBytes
= unpack
->LsbFirst
;
5271 swap2
= swap4
= GL_FALSE
;
5275 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
5276 GLint components
= _mesa_components_in_format(format
);
5279 if (_mesa_type_is_packed(type
))
5282 if (bytesPerPixel
<= 0 || components
<= 0)
5283 return NULL
; /* bad format or type. generate error later */
5284 bytesPerRow
= bytesPerPixel
* width
;
5285 bytesPerComp
= bytesPerPixel
/ components
;
5286 flipBytes
= GL_FALSE
;
5287 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
5288 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
5289 compsPerRow
= components
* width
;
5290 assert(compsPerRow
>= width
);
5295 = (GLubyte
*) malloc(bytesPerRow
* height
* depth
);
5299 return NULL
; /* generate GL_OUT_OF_MEMORY later */
5302 for (img
= 0; img
< depth
; img
++) {
5303 for (row
= 0; row
< height
; row
++) {
5304 const GLvoid
*src
= _mesa_image_address(dimensions
, unpack
, pixels
,
5305 width
, height
, format
, type
, img
, row
, 0);
5307 if ((type
== GL_BITMAP
) && (unpack
->SkipPixels
& 0x7)) {
5309 flipBytes
= GL_FALSE
;
5310 if (unpack
->LsbFirst
) {
5311 GLubyte srcMask
= 1 << (unpack
->SkipPixels
& 0x7);
5312 GLubyte dstMask
= 128;
5313 const GLubyte
*s
= src
;
5316 for (i
= 0; i
< width
; i
++) {
5320 if (srcMask
== 128) {
5325 srcMask
= srcMask
<< 1;
5333 dstMask
= dstMask
>> 1;
5338 GLubyte srcMask
= 128 >> (unpack
->SkipPixels
& 0x7);
5339 GLubyte dstMask
= 128;
5340 const GLubyte
*s
= src
;
5343 for (i
= 0; i
< width
; i
++) {
5352 srcMask
= srcMask
>> 1;
5360 dstMask
= dstMask
>> 1;
5366 memcpy(dst
, src
, bytesPerRow
);
5369 /* byte flipping/swapping */
5371 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
5374 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
5377 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
5386 #endif /* _HAVE_FULL_GL */
5391 * Convert an array of RGBA colors from one datatype to another.
5392 * NOTE: src may equal dst. In that case, we use a temporary buffer.
5395 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
5396 GLenum dstType
, GLvoid
*dst
,
5397 GLuint count
, const GLubyte mask
[])
5399 GLuint tempBuffer
[MAX_WIDTH
][4];
5400 const GLboolean useTemp
= (src
== dst
);
5402 ASSERT(srcType
!= dstType
);
5405 case GL_UNSIGNED_BYTE
:
5406 if (dstType
== GL_UNSIGNED_SHORT
) {
5407 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5408 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5410 for (i
= 0; i
< count
; i
++) {
5411 if (!mask
|| mask
[i
]) {
5412 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
5413 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
5414 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
5415 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
5419 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5422 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5423 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5425 ASSERT(dstType
== GL_FLOAT
);
5426 for (i
= 0; i
< count
; i
++) {
5427 if (!mask
|| mask
[i
]) {
5428 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
5429 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
5430 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
5431 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
5435 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5438 case GL_UNSIGNED_SHORT
:
5439 if (dstType
== GL_UNSIGNED_BYTE
) {
5440 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5441 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5443 for (i
= 0; i
< count
; i
++) {
5444 if (!mask
|| mask
[i
]) {
5445 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
5446 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
5447 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
5448 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
5452 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5455 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5456 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5458 ASSERT(dstType
== GL_FLOAT
);
5459 for (i
= 0; i
< count
; i
++) {
5460 if (!mask
|| mask
[i
]) {
5461 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
5462 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
5463 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
5464 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
5468 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5472 if (dstType
== GL_UNSIGNED_BYTE
) {
5473 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5474 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5476 for (i
= 0; i
< count
; i
++) {
5477 if (!mask
|| mask
[i
]) {
5478 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
5479 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
5480 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
5481 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
5485 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5488 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5489 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5491 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
5492 for (i
= 0; i
< count
; i
++) {
5493 if (!mask
|| mask
[i
]) {
5494 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
5495 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
5496 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
5497 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
5501 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5505 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
5513 * Perform basic clipping for glDrawPixels. The image's position and size
5514 * and the unpack SkipPixels and SkipRows are adjusted so that the image
5515 * region is entirely within the window and scissor bounds.
5516 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
5517 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
5518 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
5520 * \return GL_TRUE if image is ready for drawing or
5521 * GL_FALSE if image was completely clipped away (draw nothing)
5524 _mesa_clip_drawpixels(const GLcontext
*ctx
,
5525 GLint
*destX
, GLint
*destY
,
5526 GLsizei
*width
, GLsizei
*height
,
5527 struct gl_pixelstore_attrib
*unpack
)
5529 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
5531 if (unpack
->RowLength
== 0) {
5532 unpack
->RowLength
= *width
;
5535 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
5536 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
5539 if (*destX
< buffer
->_Xmin
) {
5540 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
5541 *width
-= (buffer
->_Xmin
- *destX
);
5542 *destX
= buffer
->_Xmin
;
5544 /* right clipping */
5545 if (*destX
+ *width
> buffer
->_Xmax
)
5546 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
5551 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
5552 /* bottom clipping */
5553 if (*destY
< buffer
->_Ymin
) {
5554 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
5555 *height
-= (buffer
->_Ymin
- *destY
);
5556 *destY
= buffer
->_Ymin
;
5559 if (*destY
+ *height
> buffer
->_Ymax
)
5560 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
5562 else { /* upside down */
5564 if (*destY
> buffer
->_Ymax
) {
5565 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
5566 *height
-= (*destY
- buffer
->_Ymax
);
5567 *destY
= buffer
->_Ymax
;
5569 /* bottom clipping */
5570 if (*destY
- *height
< buffer
->_Ymin
)
5571 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
5572 /* adjust destY so it's the first row to write to */
5584 * Perform clipping for glReadPixels. The image's window position
5585 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
5586 * so that the image region is entirely within the window bounds.
5587 * Note: this is different from _mesa_clip_drawpixels() in that the
5588 * scissor box is ignored, and we use the bounds of the current readbuffer
5591 * \return GL_TRUE if image is ready for drawing or
5592 * GL_FALSE if image was completely clipped away (draw nothing)
5595 _mesa_clip_readpixels(const GLcontext
*ctx
,
5596 GLint
*srcX
, GLint
*srcY
,
5597 GLsizei
*width
, GLsizei
*height
,
5598 struct gl_pixelstore_attrib
*pack
)
5600 const GLframebuffer
*buffer
= ctx
->ReadBuffer
;
5602 if (pack
->RowLength
== 0) {
5603 pack
->RowLength
= *width
;
5608 pack
->SkipPixels
+= (0 - *srcX
);
5609 *width
-= (0 - *srcX
);
5612 /* right clipping */
5613 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
5614 *width
-= (*srcX
+ *width
- buffer
->Width
);
5619 /* bottom clipping */
5621 pack
->SkipRows
+= (0 - *srcY
);
5622 *height
-= (0 - *srcY
);
5626 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
5627 *height
-= (*srcY
+ *height
- buffer
->Height
);
5637 * Do clipping for a glCopyTexSubImage call.
5638 * The framebuffer source region might extend outside the framebuffer
5639 * bounds. Clip the source region against the framebuffer bounds and
5640 * adjust the texture/dest position and size accordingly.
5642 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
5645 _mesa_clip_copytexsubimage(const GLcontext
*ctx
,
5646 GLint
*destX
, GLint
*destY
,
5647 GLint
*srcX
, GLint
*srcY
,
5648 GLsizei
*width
, GLsizei
*height
)
5650 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
5651 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
5653 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
5654 srcX
, srcY
, width
, height
)) {
5655 *destX
= *destX
+ *srcX
- srcX0
;
5656 *destY
= *destY
+ *srcY
- srcY0
;
5668 * Clip the rectangle defined by (x, y, width, height) against the bounds
5669 * specified by [xmin, xmax) and [ymin, ymax).
5670 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
5673 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
5674 GLint xmax
, GLint ymax
,
5676 GLsizei
*width
, GLsizei
*height
)
5680 *width
-= (xmin
- *x
);
5684 /* right clipping */
5685 if (*x
+ *width
> xmax
)
5686 *width
-= (*x
+ *width
- xmax
);
5691 /* bottom (or top) clipping */
5693 *height
-= (ymin
- *y
);
5697 /* top (or bottom) clipping */
5698 if (*y
+ *height
> ymax
)
5699 *height
-= (*y
+ *height
- ymax
);
5709 * Clip dst coords against Xmax (or Ymax).
5712 clip_right_or_top(GLint
*srcX0
, GLint
*srcX1
,
5713 GLint
*dstX0
, GLint
*dstX1
,
5718 if (*dstX1
> maxValue
) {
5719 /* X1 outside right edge */
5720 ASSERT(*dstX0
< maxValue
); /* X0 should be inside right edge */
5721 t
= (GLfloat
) (maxValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
5722 /* chop off [t, 1] part */
5723 ASSERT(t
>= 0.0 && t
<= 1.0);
5725 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
5726 *srcX1
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
5728 else if (*dstX0
> maxValue
) {
5729 /* X0 outside right edge */
5730 ASSERT(*dstX1
< maxValue
); /* X1 should be inside right edge */
5731 t
= (GLfloat
) (maxValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
5732 /* chop off [t, 1] part */
5733 ASSERT(t
>= 0.0 && t
<= 1.0);
5735 bias
= (*srcX0
< *srcX1
) ? -0.5F
: 0.5F
;
5736 *srcX0
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
5742 * Clip dst coords against Xmin (or Ymin).
5745 clip_left_or_bottom(GLint
*srcX0
, GLint
*srcX1
,
5746 GLint
*dstX0
, GLint
*dstX1
,
5751 if (*dstX0
< minValue
) {
5752 /* X0 outside left edge */
5753 ASSERT(*dstX1
> minValue
); /* X1 should be inside left edge */
5754 t
= (GLfloat
) (minValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
5755 /* chop off [0, t] part */
5756 ASSERT(t
>= 0.0 && t
<= 1.0);
5758 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
; /* flipped??? */
5759 *srcX0
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
5761 else if (*dstX1
< minValue
) {
5762 /* X1 outside left edge */
5763 ASSERT(*dstX0
> minValue
); /* X0 should be inside left edge */
5764 t
= (GLfloat
) (minValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
5765 /* chop off [0, t] part */
5766 ASSERT(t
>= 0.0 && t
<= 1.0);
5768 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
5769 *srcX1
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
5775 * Do clipping of blit src/dest rectangles.
5776 * The dest rect is clipped against both the buffer bounds and scissor bounds.
5777 * The src rect is just clipped against the buffer bounds.
5779 * When either the src or dest rect is clipped, the other is also clipped
5782 * Note that X0 need not be less than X1 (same for Y) for either the source
5783 * and dest rects. That makes the clipping a little trickier.
5785 * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
5788 _mesa_clip_blit(GLcontext
*ctx
,
5789 GLint
*srcX0
, GLint
*srcY0
, GLint
*srcX1
, GLint
*srcY1
,
5790 GLint
*dstX0
, GLint
*dstY0
, GLint
*dstX1
, GLint
*dstY1
)
5792 const GLint srcXmin
= 0;
5793 const GLint srcXmax
= ctx
->ReadBuffer
->Width
;
5794 const GLint srcYmin
= 0;
5795 const GLint srcYmax
= ctx
->ReadBuffer
->Height
;
5797 /* these include scissor bounds */
5798 const GLint dstXmin
= ctx
->DrawBuffer
->_Xmin
;
5799 const GLint dstXmax
= ctx
->DrawBuffer
->_Xmax
;
5800 const GLint dstYmin
= ctx
->DrawBuffer
->_Ymin
;
5801 const GLint dstYmax
= ctx
->DrawBuffer
->_Ymax
;
5804 printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
5805 *srcX0, *srcX1, *dstX0, *dstX1);
5806 printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
5807 *srcY0, *srcY1, *dstY0, *dstY1);
5810 /* trivial rejection tests */
5811 if (*dstX0
== *dstX1
)
5812 return GL_FALSE
; /* no width */
5813 if (*dstX0
<= dstXmin
&& *dstX1
<= dstXmin
)
5814 return GL_FALSE
; /* totally out (left) of bounds */
5815 if (*dstX0
>= dstXmax
&& *dstX1
>= dstXmax
)
5816 return GL_FALSE
; /* totally out (right) of bounds */
5818 if (*dstY0
== *dstY1
)
5820 if (*dstY0
<= dstYmin
&& *dstY1
<= dstYmin
)
5822 if (*dstY0
>= dstYmax
&& *dstY1
>= dstYmax
)
5825 if (*srcX0
== *srcX1
)
5827 if (*srcX0
<= srcXmin
&& *srcX1
<= srcXmin
)
5829 if (*srcX0
>= srcXmax
&& *srcX1
>= srcXmax
)
5832 if (*srcY0
== *srcY1
)
5834 if (*srcY0
<= srcYmin
&& *srcY1
<= srcYmin
)
5836 if (*srcY0
>= srcYmax
&& *srcY1
>= srcYmax
)
5842 clip_right_or_top(srcX0
, srcX1
, dstX0
, dstX1
, dstXmax
);
5843 clip_right_or_top(srcY0
, srcY1
, dstY0
, dstY1
, dstYmax
);
5844 clip_left_or_bottom(srcX0
, srcX1
, dstX0
, dstX1
, dstXmin
);
5845 clip_left_or_bottom(srcY0
, srcY1
, dstY0
, dstY1
, dstYmin
);
5848 * src clip (just swap src/dst values from above)
5850 clip_right_or_top(dstX0
, dstX1
, srcX0
, srcX1
, srcXmax
);
5851 clip_right_or_top(dstY0
, dstY1
, srcY0
, srcY1
, srcYmax
);
5852 clip_left_or_bottom(dstX0
, dstX1
, srcX0
, srcX1
, srcXmin
);
5853 clip_left_or_bottom(dstY0
, dstY1
, srcY0
, srcY1
, srcYmin
);
5856 printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
5857 *srcX0, *srcX1, *dstX0, *dstX1);
5858 printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
5859 *srcY0, *srcY1, *dstY0, *dstY1);
5862 ASSERT(*dstX0
>= dstXmin
);
5863 ASSERT(*dstX0
<= dstXmax
);
5864 ASSERT(*dstX1
>= dstXmin
);
5865 ASSERT(*dstX1
<= dstXmax
);
5867 ASSERT(*dstY0
>= dstYmin
);
5868 ASSERT(*dstY0
<= dstYmax
);
5869 ASSERT(*dstY1
>= dstYmin
);
5870 ASSERT(*dstY1
<= dstYmax
);
5872 ASSERT(*srcX0
>= srcXmin
);
5873 ASSERT(*srcX0
<= srcXmax
);
5874 ASSERT(*srcX1
>= srcXmin
);
5875 ASSERT(*srcX1
<= srcXmax
);
5877 ASSERT(*srcY0
>= srcYmin
);
5878 ASSERT(*srcY0
<= srcYmax
);
5879 ASSERT(*srcY1
>= srcYmin
);
5880 ASSERT(*srcY1
<= srcYmax
);