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
:
738 * Test if the given image format is a dudv format.
741 _mesa_is_dudv_format(GLenum format
)
754 * Test if an image format is a supported compressed format.
755 * \param format the internal format token provided by the user.
756 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
759 _mesa_is_compressed_format(GLcontext
*ctx
, GLenum format
)
762 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
763 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
764 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
765 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
766 return ctx
->Extensions
.EXT_texture_compression_s3tc
;
771 return ctx
->Extensions
.S3_s3tc
;
772 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
773 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
774 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
775 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
776 return ctx
->Extensions
.EXT_texture_sRGB
777 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
778 case GL_COMPRESSED_RGB_FXT1_3DFX
:
779 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
780 return ctx
->Extensions
.TDFX_texture_compression_FXT1
;
788 * Return the address of a specific pixel in an image (1D, 2D or 3D).
790 * Pixel unpacking/packing parameters are observed according to \p packing.
792 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
793 * \param image starting address of image data
794 * \param width the image width
795 * \param height theimage height
796 * \param format the pixel format
797 * \param type the pixel data type
798 * \param packing the pixelstore attributes
799 * \param img which image in the volume (0 for 1D or 2D images)
800 * \param row row of pixel in the image (0 for 1D images)
801 * \param column column of pixel in the image
803 * \return address of pixel on success, or NULL on error.
805 * \sa gl_pixelstore_attrib.
808 _mesa_image_address( GLuint dimensions
,
809 const struct gl_pixelstore_attrib
*packing
,
811 GLsizei width
, GLsizei height
,
812 GLenum format
, GLenum type
,
813 GLint img
, GLint row
, GLint column
)
815 GLint alignment
; /* 1, 2 or 4 */
816 GLint pixels_per_row
;
817 GLint rows_per_image
;
820 GLint skipimages
; /* for 3-D volume images */
823 ASSERT(dimensions
>= 1 && dimensions
<= 3);
825 alignment
= packing
->Alignment
;
826 if (packing
->RowLength
> 0) {
827 pixels_per_row
= packing
->RowLength
;
830 pixels_per_row
= width
;
832 if (packing
->ImageHeight
> 0) {
833 rows_per_image
= packing
->ImageHeight
;
836 rows_per_image
= height
;
839 skippixels
= packing
->SkipPixels
;
840 /* Note: SKIP_ROWS _is_ used for 1D images */
841 skiprows
= packing
->SkipRows
;
842 /* Note: SKIP_IMAGES is only used for 3D images */
843 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
845 if (type
== GL_BITMAP
) {
847 GLint comp_per_pixel
; /* components per pixel */
848 GLint bytes_per_comp
; /* bytes per component */
850 GLint bytes_per_image
;
852 /* Compute bytes per component */
853 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
854 if (bytes_per_comp
< 0) {
858 /* Compute number of components per pixel */
859 comp_per_pixel
= _mesa_components_in_format( format
);
860 if (comp_per_pixel
< 0) {
864 bytes_per_row
= alignment
865 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
867 bytes_per_image
= bytes_per_row
* rows_per_image
;
869 pixel_addr
= (GLubyte
*) image
870 + (skipimages
+ img
) * bytes_per_image
871 + (skiprows
+ row
) * bytes_per_row
872 + (skippixels
+ column
) / 8;
875 /* Non-BITMAP data */
876 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
879 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
881 /* The pixel type and format should have been error checked earlier */
882 assert(bytes_per_pixel
> 0);
884 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
885 remainder
= bytes_per_row
% alignment
;
887 bytes_per_row
+= (alignment
- remainder
);
889 ASSERT(bytes_per_row
% alignment
== 0);
891 bytes_per_image
= bytes_per_row
* rows_per_image
;
893 if (packing
->Invert
) {
894 /* set pixel_addr to the last row */
895 topOfImage
= bytes_per_row
* (height
- 1);
896 bytes_per_row
= -bytes_per_row
;
902 /* compute final pixel address */
903 pixel_addr
= (GLubyte
*) image
904 + (skipimages
+ img
) * bytes_per_image
906 + (skiprows
+ row
) * bytes_per_row
907 + (skippixels
+ column
) * bytes_per_pixel
;
910 return (GLvoid
*) pixel_addr
;
915 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
918 GLenum format
, GLenum type
,
921 return _mesa_image_address(1, packing
, image
, width
, 1,
922 format
, type
, 0, 0, column
);
927 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
929 GLsizei width
, GLsizei height
,
930 GLenum format
, GLenum type
,
931 GLint row
, GLint column
)
933 return _mesa_image_address(2, packing
, image
, width
, height
,
934 format
, type
, 0, row
, column
);
939 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
941 GLsizei width
, GLsizei height
,
942 GLenum format
, GLenum type
,
943 GLint img
, GLint row
, GLint column
)
945 return _mesa_image_address(3, packing
, image
, width
, height
,
946 format
, type
, img
, row
, column
);
952 * Compute the stride (in bytes) between image rows.
954 * \param packing the pixelstore attributes
955 * \param width image width.
956 * \param format pixel format.
957 * \param type pixel data type.
959 * \return the stride in bytes for the given parameters, or -1 if error
962 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
963 GLint width
, GLenum format
, GLenum type
)
965 GLint bytesPerRow
, remainder
;
969 if (type
== GL_BITMAP
) {
970 if (packing
->RowLength
== 0) {
971 bytesPerRow
= (width
+ 7) / 8;
974 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
978 /* Non-BITMAP data */
979 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
980 if (bytesPerPixel
<= 0)
981 return -1; /* error */
982 if (packing
->RowLength
== 0) {
983 bytesPerRow
= bytesPerPixel
* width
;
986 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
990 remainder
= bytesPerRow
% packing
->Alignment
;
992 bytesPerRow
+= (packing
->Alignment
- remainder
);
995 if (packing
->Invert
) {
996 /* negate the bytes per row (negative row stride) */
997 bytesPerRow
= -bytesPerRow
;
1007 * Compute the stride between images in a 3D texture (in bytes) for the given
1008 * pixel packing parameters and image width, format and type.
1011 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
1012 GLint width
, GLint height
,
1013 GLenum format
, GLenum type
)
1015 GLint bytesPerRow
, bytesPerImage
, remainder
;
1019 if (type
== GL_BITMAP
) {
1020 if (packing
->RowLength
== 0) {
1021 bytesPerRow
= (width
+ 7) / 8;
1024 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1028 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1030 if (bytesPerPixel
<= 0)
1031 return -1; /* error */
1032 if (packing
->RowLength
== 0) {
1033 bytesPerRow
= bytesPerPixel
* width
;
1036 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1040 remainder
= bytesPerRow
% packing
->Alignment
;
1042 bytesPerRow
+= (packing
->Alignment
- remainder
);
1044 if (packing
->ImageHeight
== 0)
1045 bytesPerImage
= bytesPerRow
* height
;
1047 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
1049 return bytesPerImage
;
1054 * Unpack a 32x32 pixel polygon stipple from user memory using the
1055 * current pixel unpack settings.
1058 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
1059 const struct gl_pixelstore_attrib
*unpacking
)
1061 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap(32, 32, pattern
, unpacking
);
1063 /* Convert pattern from GLubytes to GLuints and handle big/little
1064 * endian differences
1068 for (i
= 0; i
< 32; i
++) {
1069 dest
[i
] = (p
[0] << 24)
1081 * Pack polygon stipple into user memory given current pixel packing
1085 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
1086 const struct gl_pixelstore_attrib
*packing
)
1088 /* Convert pattern from GLuints to GLubytes to handle big/little
1089 * endian differences.
1093 for (i
= 0; i
< 32; i
++) {
1094 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
1095 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
1096 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
1097 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
1100 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
1105 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
1106 * order with row alignment = 1 byte.
1109 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
1110 const struct gl_pixelstore_attrib
*packing
)
1112 GLint bytes
, row
, width_in_bytes
;
1113 GLubyte
*buffer
, *dst
;
1118 /* Alloc dest storage */
1119 bytes
= ((width
+ 7) / 8 * height
);
1120 buffer
= (GLubyte
*) malloc( bytes
);
1124 width_in_bytes
= CEILING( width
, 8 );
1126 for (row
= 0; row
< height
; row
++) {
1127 const GLubyte
*src
= (const GLubyte
*)
1128 _mesa_image_address2d(packing
, pixels
, width
, height
,
1129 GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
1135 if ((packing
->SkipPixels
& 7) == 0) {
1136 memcpy( dst
, src
, width_in_bytes
);
1137 if (packing
->LsbFirst
) {
1138 flip_bytes( dst
, width_in_bytes
);
1142 /* handling SkipPixels is a bit tricky (no pun intended!) */
1144 if (packing
->LsbFirst
) {
1145 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
1146 GLubyte dstMask
= 128;
1147 const GLubyte
*s
= src
;
1150 for (i
= 0; i
< width
; i
++) {
1154 if (srcMask
== 128) {
1159 srcMask
= srcMask
<< 1;
1167 dstMask
= dstMask
>> 1;
1172 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
1173 GLubyte dstMask
= 128;
1174 const GLubyte
*s
= src
;
1177 for (i
= 0; i
< width
; i
++) {
1186 srcMask
= srcMask
>> 1;
1194 dstMask
= dstMask
>> 1;
1199 dst
+= width_in_bytes
;
1210 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
1211 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
1213 GLint row
, width_in_bytes
;
1219 width_in_bytes
= CEILING( width
, 8 );
1221 for (row
= 0; row
< height
; row
++) {
1222 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dest
,
1223 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
1227 if ((packing
->SkipPixels
& 7) == 0) {
1228 memcpy( dst
, src
, width_in_bytes
);
1229 if (packing
->LsbFirst
) {
1230 flip_bytes( dst
, width_in_bytes
);
1234 /* handling SkipPixels is a bit tricky (no pun intended!) */
1236 if (packing
->LsbFirst
) {
1237 GLubyte srcMask
= 128;
1238 GLubyte dstMask
= 1 << (packing
->SkipPixels
& 0x7);
1239 const GLubyte
*s
= src
;
1242 for (i
= 0; i
< width
; i
++) {
1251 srcMask
= srcMask
>> 1;
1253 if (dstMask
== 128) {
1259 dstMask
= dstMask
<< 1;
1264 GLubyte srcMask
= 128;
1265 GLubyte dstMask
= 128 >> (packing
->SkipPixels
& 0x7);
1266 const GLubyte
*s
= src
;
1269 for (i
= 0; i
< width
; i
++) {
1278 srcMask
= srcMask
>> 1;
1286 dstMask
= dstMask
>> 1;
1291 src
+= width_in_bytes
;
1297 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1298 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1299 * "On" bits will set texels to \p onValue.
1300 * "Off" bits will not modify texels.
1301 * \param width src bitmap width in pixels
1302 * \param height src bitmap height in pixels
1303 * \param unpack bitmap unpacking state
1304 * \param bitmap the src bitmap data
1305 * \param destBuffer start of dest buffer
1306 * \param destStride row stride in dest buffer
1307 * \param onValue if bit is 1, set destBuffer pixel to this value
1310 _mesa_expand_bitmap(GLsizei width
, GLsizei height
,
1311 const struct gl_pixelstore_attrib
*unpack
,
1312 const GLubyte
*bitmap
,
1313 GLubyte
*destBuffer
, GLint destStride
,
1316 const GLubyte
*srcRow
= (const GLubyte
*)
1317 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
1318 GL_COLOR_INDEX
, GL_BITMAP
, 0, 0);
1319 const GLint srcStride
= _mesa_image_row_stride(unpack
, width
,
1320 GL_COLOR_INDEX
, GL_BITMAP
);
1323 #define SET_PIXEL(COL, ROW) \
1324 destBuffer[(ROW) * destStride + (COL)] = onValue;
1326 for (row
= 0; row
< height
; row
++) {
1327 const GLubyte
*src
= srcRow
;
1329 if (unpack
->LsbFirst
) {
1331 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
1332 for (col
= 0; col
< width
; col
++) {
1335 SET_PIXEL(col
, row
);
1347 /* get ready for next row */
1353 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
1354 for (col
= 0; col
< width
; col
++) {
1357 SET_PIXEL(col
, row
);
1369 /* get ready for next row */
1374 srcRow
+= srcStride
;
1381 /**********************************************************************/
1382 /***** Pixel processing functions ******/
1383 /**********************************************************************/
1386 * Apply scale and bias factors to an array of RGBA pixels.
1389 _mesa_scale_and_bias_rgba(GLuint n
, GLfloat rgba
[][4],
1390 GLfloat rScale
, GLfloat gScale
,
1391 GLfloat bScale
, GLfloat aScale
,
1392 GLfloat rBias
, GLfloat gBias
,
1393 GLfloat bBias
, GLfloat aBias
)
1395 if (rScale
!= 1.0 || rBias
!= 0.0) {
1397 for (i
= 0; i
< n
; i
++) {
1398 rgba
[i
][RCOMP
] = rgba
[i
][RCOMP
] * rScale
+ rBias
;
1401 if (gScale
!= 1.0 || gBias
!= 0.0) {
1403 for (i
= 0; i
< n
; i
++) {
1404 rgba
[i
][GCOMP
] = rgba
[i
][GCOMP
] * gScale
+ gBias
;
1407 if (bScale
!= 1.0 || bBias
!= 0.0) {
1409 for (i
= 0; i
< n
; i
++) {
1410 rgba
[i
][BCOMP
] = rgba
[i
][BCOMP
] * bScale
+ bBias
;
1413 if (aScale
!= 1.0 || aBias
!= 0.0) {
1415 for (i
= 0; i
< n
; i
++) {
1416 rgba
[i
][ACOMP
] = rgba
[i
][ACOMP
] * aScale
+ aBias
;
1423 * Apply pixel mapping to an array of floating point RGBA pixels.
1426 _mesa_map_rgba( const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4] )
1428 const GLfloat rscale
= (GLfloat
) (ctx
->PixelMaps
.RtoR
.Size
- 1);
1429 const GLfloat gscale
= (GLfloat
) (ctx
->PixelMaps
.GtoG
.Size
- 1);
1430 const GLfloat bscale
= (GLfloat
) (ctx
->PixelMaps
.BtoB
.Size
- 1);
1431 const GLfloat ascale
= (GLfloat
) (ctx
->PixelMaps
.AtoA
.Size
- 1);
1432 const GLfloat
*rMap
= ctx
->PixelMaps
.RtoR
.Map
;
1433 const GLfloat
*gMap
= ctx
->PixelMaps
.GtoG
.Map
;
1434 const GLfloat
*bMap
= ctx
->PixelMaps
.BtoB
.Map
;
1435 const GLfloat
*aMap
= ctx
->PixelMaps
.AtoA
.Map
;
1438 GLfloat r
= CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1439 GLfloat g
= CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1440 GLfloat b
= CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1441 GLfloat a
= CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1442 rgba
[i
][RCOMP
] = rMap
[IROUND(r
* rscale
)];
1443 rgba
[i
][GCOMP
] = gMap
[IROUND(g
* gscale
)];
1444 rgba
[i
][BCOMP
] = bMap
[IROUND(b
* bscale
)];
1445 rgba
[i
][ACOMP
] = aMap
[IROUND(a
* ascale
)];
1451 * Apply the color matrix and post color matrix scaling and biasing.
1454 _mesa_transform_rgba(const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4])
1456 const GLfloat rs
= ctx
->Pixel
.PostColorMatrixScale
[0];
1457 const GLfloat rb
= ctx
->Pixel
.PostColorMatrixBias
[0];
1458 const GLfloat gs
= ctx
->Pixel
.PostColorMatrixScale
[1];
1459 const GLfloat gb
= ctx
->Pixel
.PostColorMatrixBias
[1];
1460 const GLfloat bs
= ctx
->Pixel
.PostColorMatrixScale
[2];
1461 const GLfloat bb
= ctx
->Pixel
.PostColorMatrixBias
[2];
1462 const GLfloat as
= ctx
->Pixel
.PostColorMatrixScale
[3];
1463 const GLfloat ab
= ctx
->Pixel
.PostColorMatrixBias
[3];
1464 const GLfloat
*m
= ctx
->ColorMatrixStack
.Top
->m
;
1466 for (i
= 0; i
< n
; i
++) {
1467 const GLfloat r
= rgba
[i
][RCOMP
];
1468 const GLfloat g
= rgba
[i
][GCOMP
];
1469 const GLfloat b
= rgba
[i
][BCOMP
];
1470 const GLfloat a
= rgba
[i
][ACOMP
];
1471 rgba
[i
][RCOMP
] = (m
[0] * r
+ m
[4] * g
+ m
[ 8] * b
+ m
[12] * a
) * rs
+ rb
;
1472 rgba
[i
][GCOMP
] = (m
[1] * r
+ m
[5] * g
+ m
[ 9] * b
+ m
[13] * a
) * gs
+ gb
;
1473 rgba
[i
][BCOMP
] = (m
[2] * r
+ m
[6] * g
+ m
[10] * b
+ m
[14] * a
) * bs
+ bb
;
1474 rgba
[i
][ACOMP
] = (m
[3] * r
+ m
[7] * g
+ m
[11] * b
+ m
[15] * a
) * as
+ ab
;
1480 * Apply a color table lookup to an array of floating point RGBA colors.
1483 _mesa_lookup_rgba_float(const struct gl_color_table
*table
,
1484 GLuint n
, GLfloat rgba
[][4])
1486 const GLint max
= table
->Size
- 1;
1487 const GLfloat scale
= (GLfloat
) max
;
1488 const GLfloat
*lut
= table
->TableF
;
1491 if (!table
->TableF
|| table
->Size
== 0)
1494 switch (table
->_BaseFormat
) {
1496 /* replace RGBA with I */
1497 for (i
= 0; i
< n
; i
++) {
1498 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1499 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1507 /* replace RGB with L */
1508 for (i
= 0; i
< n
; i
++) {
1509 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1510 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1517 /* replace A with A */
1518 for (i
= 0; i
< n
; i
++) {
1519 GLint j
= IROUND(rgba
[i
][ACOMP
] * scale
);
1520 rgba
[i
][ACOMP
] = lut
[CLAMP(j
, 0, max
)];
1523 case GL_LUMINANCE_ALPHA
:
1524 /* replace RGBA with LLLA */
1525 for (i
= 0; i
< n
; i
++) {
1526 GLint jL
= IROUND(rgba
[i
][RCOMP
] * scale
);
1527 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1528 GLfloat luminance
, alpha
;
1529 jL
= CLAMP(jL
, 0, max
);
1530 jA
= CLAMP(jA
, 0, max
);
1531 luminance
= lut
[jL
* 2 + 0];
1532 alpha
= lut
[jA
* 2 + 1];
1535 rgba
[i
][BCOMP
] = luminance
;
1536 rgba
[i
][ACOMP
] = alpha
;;
1540 /* replace RGB with RGB */
1541 for (i
= 0; i
< n
; i
++) {
1542 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1543 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1544 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1545 jR
= CLAMP(jR
, 0, max
);
1546 jG
= CLAMP(jG
, 0, max
);
1547 jB
= CLAMP(jB
, 0, max
);
1548 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1549 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1550 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1554 /* replace RGBA with RGBA */
1555 for (i
= 0; i
< n
; i
++) {
1556 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1557 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1558 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1559 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1560 jR
= CLAMP(jR
, 0, max
);
1561 jG
= CLAMP(jG
, 0, max
);
1562 jB
= CLAMP(jB
, 0, max
);
1563 jA
= CLAMP(jA
, 0, max
);
1564 rgba
[i
][RCOMP
] = lut
[jR
* 4 + 0];
1565 rgba
[i
][GCOMP
] = lut
[jG
* 4 + 1];
1566 rgba
[i
][BCOMP
] = lut
[jB
* 4 + 2];
1567 rgba
[i
][ACOMP
] = lut
[jA
* 4 + 3];
1571 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_float");
1579 * Apply a color table lookup to an array of ubyte/RGBA colors.
1582 _mesa_lookup_rgba_ubyte(const struct gl_color_table
*table
,
1583 GLuint n
, GLubyte rgba
[][4])
1585 const GLubyte
*lut
= table
->TableUB
;
1586 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / (GLfloat
)255.0;
1589 if (!table
->TableUB
|| table
->Size
== 0)
1592 switch (table
->_BaseFormat
) {
1594 /* replace RGBA with I */
1595 if (table
->Size
== 256) {
1596 for (i
= 0; i
< n
; i
++) {
1597 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1605 for (i
= 0; i
< n
; i
++) {
1606 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1610 rgba
[i
][ACOMP
] = lut
[j
];
1615 /* replace RGB with L */
1616 if (table
->Size
== 256) {
1617 for (i
= 0; i
< n
; i
++) {
1618 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1625 for (i
= 0; i
< n
; i
++) {
1626 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1629 rgba
[i
][BCOMP
] = lut
[j
];
1634 /* replace A with A */
1635 if (table
->Size
== 256) {
1636 for (i
= 0; i
< n
; i
++) {
1637 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
]];
1641 for (i
= 0; i
< n
; i
++) {
1642 GLint j
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1643 rgba
[i
][ACOMP
] = lut
[j
];
1647 case GL_LUMINANCE_ALPHA
:
1648 /* replace RGBA with LLLA */
1649 if (table
->Size
== 256) {
1650 for (i
= 0; i
< n
; i
++) {
1651 GLubyte l
= lut
[rgba
[i
][RCOMP
] * 2 + 0];
1652 GLubyte a
= lut
[rgba
[i
][ACOMP
] * 2 + 1];;
1660 for (i
= 0; i
< n
; i
++) {
1661 GLint jL
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1662 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1663 GLubyte luminance
= lut
[jL
* 2 + 0];
1664 GLubyte alpha
= lut
[jA
* 2 + 1];
1667 rgba
[i
][BCOMP
] = luminance
;
1668 rgba
[i
][ACOMP
] = alpha
;
1673 if (table
->Size
== 256) {
1674 for (i
= 0; i
< n
; i
++) {
1675 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 3 + 0];
1676 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 3 + 1];
1677 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 3 + 2];
1681 for (i
= 0; i
< n
; i
++) {
1682 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1683 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1684 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1685 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1686 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1687 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1692 if (table
->Size
== 256) {
1693 for (i
= 0; i
< n
; i
++) {
1694 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 4 + 0];
1695 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 4 + 1];
1696 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 4 + 2];
1697 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
] * 4 + 3];
1701 for (i
= 0; i
< n
; i
++) {
1702 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1703 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1704 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1705 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1706 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][RCOMP
], lut
[jR
* 4 + 0]);
1707 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][GCOMP
], lut
[jG
* 4 + 1]);
1708 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][BCOMP
], lut
[jB
* 4 + 2]);
1709 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][ACOMP
], lut
[jA
* 4 + 3]);
1714 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_chan");
1722 * Map color indexes to float rgba values.
1725 _mesa_map_ci_to_rgba( const GLcontext
*ctx
, GLuint n
,
1726 const GLuint index
[], GLfloat rgba
[][4] )
1728 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1729 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1730 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1731 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1732 const GLfloat
*rMap
= ctx
->PixelMaps
.ItoR
.Map
;
1733 const GLfloat
*gMap
= ctx
->PixelMaps
.ItoG
.Map
;
1734 const GLfloat
*bMap
= ctx
->PixelMaps
.ItoB
.Map
;
1735 const GLfloat
*aMap
= ctx
->PixelMaps
.ItoA
.Map
;
1738 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1739 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1740 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1741 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1747 * Map ubyte color indexes to ubyte/RGBA values.
1750 _mesa_map_ci8_to_rgba8(const GLcontext
*ctx
, GLuint n
, const GLubyte index
[],
1753 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1754 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1755 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1756 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1757 const GLubyte
*rMap
= ctx
->PixelMaps
.ItoR
.Map8
;
1758 const GLubyte
*gMap
= ctx
->PixelMaps
.ItoG
.Map8
;
1759 const GLubyte
*bMap
= ctx
->PixelMaps
.ItoB
.Map8
;
1760 const GLubyte
*aMap
= ctx
->PixelMaps
.ItoA
.Map8
;
1763 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1764 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1765 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1766 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1772 _mesa_scale_and_bias_depth(const GLcontext
*ctx
, GLuint n
,
1773 GLfloat depthValues
[])
1775 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
1776 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
1778 for (i
= 0; i
< n
; i
++) {
1779 GLfloat d
= depthValues
[i
] * scale
+ bias
;
1780 depthValues
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
1786 _mesa_scale_and_bias_depth_uint(const GLcontext
*ctx
, GLuint n
,
1787 GLuint depthValues
[])
1789 const GLdouble max
= (double) 0xffffffff;
1790 const GLdouble scale
= ctx
->Pixel
.DepthScale
;
1791 const GLdouble bias
= ctx
->Pixel
.DepthBias
* max
;
1793 for (i
= 0; i
< n
; i
++) {
1794 GLdouble d
= (GLdouble
) depthValues
[i
] * scale
+ bias
;
1795 d
= CLAMP(d
, 0.0, max
);
1796 depthValues
[i
] = (GLuint
) d
;
1803 * Update the min/max values from an array of fragment colors.
1806 update_minmax(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1809 for (i
= 0; i
< n
; i
++) {
1811 if (rgba
[i
][RCOMP
] < ctx
->MinMax
.Min
[RCOMP
])
1812 ctx
->MinMax
.Min
[RCOMP
] = rgba
[i
][RCOMP
];
1813 if (rgba
[i
][GCOMP
] < ctx
->MinMax
.Min
[GCOMP
])
1814 ctx
->MinMax
.Min
[GCOMP
] = rgba
[i
][GCOMP
];
1815 if (rgba
[i
][BCOMP
] < ctx
->MinMax
.Min
[BCOMP
])
1816 ctx
->MinMax
.Min
[BCOMP
] = rgba
[i
][BCOMP
];
1817 if (rgba
[i
][ACOMP
] < ctx
->MinMax
.Min
[ACOMP
])
1818 ctx
->MinMax
.Min
[ACOMP
] = rgba
[i
][ACOMP
];
1821 if (rgba
[i
][RCOMP
] > ctx
->MinMax
.Max
[RCOMP
])
1822 ctx
->MinMax
.Max
[RCOMP
] = rgba
[i
][RCOMP
];
1823 if (rgba
[i
][GCOMP
] > ctx
->MinMax
.Max
[GCOMP
])
1824 ctx
->MinMax
.Max
[GCOMP
] = rgba
[i
][GCOMP
];
1825 if (rgba
[i
][BCOMP
] > ctx
->MinMax
.Max
[BCOMP
])
1826 ctx
->MinMax
.Max
[BCOMP
] = rgba
[i
][BCOMP
];
1827 if (rgba
[i
][ACOMP
] > ctx
->MinMax
.Max
[ACOMP
])
1828 ctx
->MinMax
.Max
[ACOMP
] = rgba
[i
][ACOMP
];
1834 * Update the histogram values from an array of fragment colors.
1837 update_histogram(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1839 const GLint max
= ctx
->Histogram
.Width
- 1;
1840 GLfloat w
= (GLfloat
) max
;
1843 if (ctx
->Histogram
.Width
== 0)
1846 for (i
= 0; i
< n
; i
++) {
1847 GLint ri
= IROUND(rgba
[i
][RCOMP
] * w
);
1848 GLint gi
= IROUND(rgba
[i
][GCOMP
] * w
);
1849 GLint bi
= IROUND(rgba
[i
][BCOMP
] * w
);
1850 GLint ai
= IROUND(rgba
[i
][ACOMP
] * w
);
1851 ri
= CLAMP(ri
, 0, max
);
1852 gi
= CLAMP(gi
, 0, max
);
1853 bi
= CLAMP(bi
, 0, max
);
1854 ai
= CLAMP(ai
, 0, max
);
1855 ctx
->Histogram
.Count
[ri
][RCOMP
]++;
1856 ctx
->Histogram
.Count
[gi
][GCOMP
]++;
1857 ctx
->Histogram
.Count
[bi
][BCOMP
]++;
1858 ctx
->Histogram
.Count
[ai
][ACOMP
]++;
1864 * Apply various pixel transfer operations to an array of RGBA pixels
1865 * as indicated by the transferOps bitmask
1868 _mesa_apply_rgba_transfer_ops(GLcontext
*ctx
, GLbitfield transferOps
,
1869 GLuint n
, GLfloat rgba
[][4])
1872 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
1873 _mesa_scale_and_bias_rgba(n
, rgba
,
1874 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
1875 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
1876 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
1877 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
1879 /* color map lookup */
1880 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1881 _mesa_map_rgba( ctx
, n
, rgba
);
1883 /* GL_COLOR_TABLE lookup */
1884 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
1885 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
], n
, rgba
);
1888 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
1889 /* this has to be done in the calling code */
1890 _mesa_problem(ctx
, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");
1892 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
1893 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
1894 _mesa_scale_and_bias_rgba(n
, rgba
,
1895 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
1896 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
1897 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
1898 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
1899 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
1900 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
1901 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
1902 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
1904 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
1905 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
1906 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
], n
, rgba
);
1908 /* color matrix transform */
1909 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
1910 _mesa_transform_rgba(ctx
, n
, rgba
);
1912 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
1913 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
1914 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
], n
, rgba
);
1916 /* update histogram count */
1917 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
1918 update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1920 /* update min/max values */
1921 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
1922 update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1924 /* clamping to [0,1] */
1925 if (transferOps
& IMAGE_CLAMP_BIT
) {
1927 for (i
= 0; i
< n
; i
++) {
1928 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1929 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1930 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1931 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1938 * Apply color index shift and offset to an array of pixels.
1941 shift_and_offset_ci( const GLcontext
*ctx
, GLuint n
, GLuint indexes
[] )
1943 GLint shift
= ctx
->Pixel
.IndexShift
;
1944 GLint offset
= ctx
->Pixel
.IndexOffset
;
1948 indexes
[i
] = (indexes
[i
] << shift
) + offset
;
1951 else if (shift
< 0) {
1954 indexes
[i
] = (indexes
[i
] >> shift
) + offset
;
1959 indexes
[i
] = indexes
[i
] + offset
;
1967 * Apply color index shift, offset and table lookup to an array
1971 _mesa_apply_ci_transfer_ops(const GLcontext
*ctx
, GLbitfield transferOps
,
1972 GLuint n
, GLuint indexes
[])
1974 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
1975 shift_and_offset_ci(ctx
, n
, indexes
);
1977 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1978 const GLuint mask
= ctx
->PixelMaps
.ItoI
.Size
- 1;
1980 for (i
= 0; i
< n
; i
++) {
1981 const GLuint j
= indexes
[i
] & mask
;
1982 indexes
[i
] = IROUND(ctx
->PixelMaps
.ItoI
.Map
[j
]);
1989 * Apply stencil index shift, offset and table lookup to an array
1990 * of stencil values.
1993 _mesa_apply_stencil_transfer_ops(const GLcontext
*ctx
, GLuint n
,
1994 GLstencil stencil
[])
1996 if (ctx
->Pixel
.IndexShift
!= 0 || ctx
->Pixel
.IndexOffset
!= 0) {
1997 const GLint offset
= ctx
->Pixel
.IndexOffset
;
1998 GLint shift
= ctx
->Pixel
.IndexShift
;
2001 for (i
= 0; i
< n
; i
++) {
2002 stencil
[i
] = (stencil
[i
] << shift
) + offset
;
2005 else if (shift
< 0) {
2007 for (i
= 0; i
< n
; i
++) {
2008 stencil
[i
] = (stencil
[i
] >> shift
) + offset
;
2012 for (i
= 0; i
< n
; i
++) {
2013 stencil
[i
] = stencil
[i
] + offset
;
2017 if (ctx
->Pixel
.MapStencilFlag
) {
2018 GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
2020 for (i
= 0; i
< n
; i
++) {
2021 stencil
[i
] = (GLstencil
)ctx
->PixelMaps
.StoS
.Map
[ stencil
[i
] & mask
];
2028 * Used to pack an array [][4] of RGBA float colors as specified
2029 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
2030 * glGetConvolutionFilter(), etc.
2031 * Note: the rgba values will be modified by this function when any pixel
2032 * transfer ops are enabled.
2035 _mesa_pack_rgba_span_float(GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4],
2036 GLenum dstFormat
, GLenum dstType
,
2038 const struct gl_pixelstore_attrib
*dstPacking
,
2039 GLbitfield transferOps
)
2041 GLfloat luminance
[MAX_WIDTH
];
2042 const GLint comps
= _mesa_components_in_format(dstFormat
);
2046 * This test should probably go away. Have the caller set/clear the
2047 * IMAGE_CLAMP_BIT as needed.
2049 if (dstType
!= GL_FLOAT
|| ctx
->Color
.ClampReadColor
== GL_TRUE
) {
2050 /* need to clamp to [0, 1] */
2051 transferOps
|= IMAGE_CLAMP_BIT
;
2055 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
2056 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
2061 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
2062 /* compute luminance values */
2063 if (transferOps
& IMAGE_CLAMP_BIT
) {
2064 for (i
= 0; i
< n
; i
++) {
2065 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
2066 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
2070 for (i
= 0; i
< n
; i
++) {
2071 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
2077 * Pack/store the pixels. Ugh! Lots of cases!!!
2080 case GL_UNSIGNED_BYTE
:
2082 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2083 switch (dstFormat
) {
2086 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2090 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2094 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2098 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2102 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
2104 case GL_LUMINANCE_ALPHA
:
2106 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
2107 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2112 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2113 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2114 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2119 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2120 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2121 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2122 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2127 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2128 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2129 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2134 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2135 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2136 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2137 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2142 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2143 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2144 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2145 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2151 dst
[i
*2+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2152 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2156 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2162 GLbyte
*dst
= (GLbyte
*) dstAddr
;
2163 switch (dstFormat
) {
2166 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2170 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2174 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2178 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2182 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
2184 case GL_LUMINANCE_ALPHA
:
2186 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
2187 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2192 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2193 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2194 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2199 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2200 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2201 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2202 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2207 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2208 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2209 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2214 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2215 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2216 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2217 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2222 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
2223 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
2224 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2225 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2231 dst
[i
*2+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
2232 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
2236 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2240 case GL_UNSIGNED_SHORT
:
2242 GLushort
*dst
= (GLushort
*) dstAddr
;
2243 switch (dstFormat
) {
2246 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][RCOMP
]);
2250 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][GCOMP
]);
2254 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][BCOMP
]);
2258 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][ACOMP
]);
2262 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
], luminance
[i
]);
2264 case GL_LUMINANCE_ALPHA
:
2266 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
*2+0], luminance
[i
]);
2267 CLAMPED_FLOAT_TO_USHORT(dst
[i
*2+1], rgba
[i
][ACOMP
]);
2272 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][RCOMP
]);
2273 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
2274 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][BCOMP
]);
2279 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][RCOMP
]);
2280 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
2281 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][BCOMP
]);
2282 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
2287 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][BCOMP
]);
2288 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
2289 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][RCOMP
]);
2294 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][BCOMP
]);
2295 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
2296 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][RCOMP
]);
2297 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
2302 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][ACOMP
]);
2303 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][BCOMP
]);
2304 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][GCOMP
]);
2305 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][RCOMP
]);
2311 dst
[i
*2+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
2312 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
2316 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2322 GLshort
*dst
= (GLshort
*) dstAddr
;
2323 switch (dstFormat
) {
2326 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2330 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2334 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2338 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2342 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
2344 case GL_LUMINANCE_ALPHA
:
2346 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
2347 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2352 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2353 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2354 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2359 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2360 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2361 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2362 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2367 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2368 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2369 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2374 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2375 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2376 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2377 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2382 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
2383 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
2384 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2385 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2391 dst
[i
*2+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
2392 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
2396 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2400 case GL_UNSIGNED_INT
:
2402 GLuint
*dst
= (GLuint
*) dstAddr
;
2403 switch (dstFormat
) {
2406 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2410 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2414 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2418 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2422 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
2424 case GL_LUMINANCE_ALPHA
:
2426 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
2427 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2432 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2433 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2434 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2439 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2440 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2441 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2442 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2447 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2448 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2449 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2454 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2455 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2456 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2457 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2462 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2463 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2464 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2465 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2471 dst
[i
*2+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2472 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2476 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2482 GLint
*dst
= (GLint
*) dstAddr
;
2483 switch (dstFormat
) {
2486 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2490 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2494 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2498 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2502 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
2504 case GL_LUMINANCE_ALPHA
:
2506 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
2507 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2512 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2513 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2514 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2519 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2520 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2521 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2522 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2527 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2528 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2529 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2534 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2535 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2536 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2537 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2542 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2543 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2544 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2545 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2551 dst
[i
*2+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2552 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2556 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2562 GLfloat
*dst
= (GLfloat
*) dstAddr
;
2563 switch (dstFormat
) {
2566 dst
[i
] = rgba
[i
][RCOMP
];
2570 dst
[i
] = rgba
[i
][GCOMP
];
2574 dst
[i
] = rgba
[i
][BCOMP
];
2578 dst
[i
] = rgba
[i
][ACOMP
];
2582 dst
[i
] = luminance
[i
];
2584 case GL_LUMINANCE_ALPHA
:
2586 dst
[i
*2+0] = luminance
[i
];
2587 dst
[i
*2+1] = rgba
[i
][ACOMP
];
2592 dst
[i
*3+0] = rgba
[i
][RCOMP
];
2593 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2594 dst
[i
*3+2] = rgba
[i
][BCOMP
];
2599 dst
[i
*4+0] = rgba
[i
][RCOMP
];
2600 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2601 dst
[i
*4+2] = rgba
[i
][BCOMP
];
2602 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2607 dst
[i
*3+0] = rgba
[i
][BCOMP
];
2608 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2609 dst
[i
*3+2] = rgba
[i
][RCOMP
];
2614 dst
[i
*4+0] = rgba
[i
][BCOMP
];
2615 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2616 dst
[i
*4+2] = rgba
[i
][RCOMP
];
2617 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2622 dst
[i
*4+0] = rgba
[i
][ACOMP
];
2623 dst
[i
*4+1] = rgba
[i
][BCOMP
];
2624 dst
[i
*4+2] = rgba
[i
][GCOMP
];
2625 dst
[i
*4+3] = rgba
[i
][RCOMP
];
2631 dst
[i
*2+0] = rgba
[i
][RCOMP
];
2632 dst
[i
*2+1] = rgba
[i
][GCOMP
];
2636 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2640 case GL_HALF_FLOAT_ARB
:
2642 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
2643 switch (dstFormat
) {
2646 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2650 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2654 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2658 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2662 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
2664 case GL_LUMINANCE_ALPHA
:
2666 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
2667 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2672 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2673 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2674 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2679 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2680 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2681 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2682 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2687 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2688 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2689 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2694 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2695 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2696 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2697 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2702 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2703 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2704 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2705 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2711 dst
[i
*2+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2712 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2716 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2720 case GL_UNSIGNED_BYTE_3_3_2
:
2721 if (dstFormat
== GL_RGB
) {
2722 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2724 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 7.0F
) << 5)
2725 | (IROUND(rgba
[i
][GCOMP
] * 7.0F
) << 2)
2726 | (IROUND(rgba
[i
][BCOMP
] * 3.0F
) );
2730 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2731 if (dstFormat
== GL_RGB
) {
2732 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2734 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 7.0F
) )
2735 | (IROUND(rgba
[i
][GCOMP
] * 7.0F
) << 3)
2736 | (IROUND(rgba
[i
][BCOMP
] * 3.0F
) << 6);
2740 case GL_UNSIGNED_SHORT_5_6_5
:
2741 if (dstFormat
== GL_RGB
) {
2742 GLushort
*dst
= (GLushort
*) dstAddr
;
2744 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 11)
2745 | (IROUND(rgba
[i
][GCOMP
] * 63.0F
) << 5)
2746 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) );
2750 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2751 if (dstFormat
== GL_RGB
) {
2752 GLushort
*dst
= (GLushort
*) dstAddr
;
2754 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) )
2755 | (IROUND(rgba
[i
][GCOMP
] * 63.0F
) << 5)
2756 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 11);
2760 case GL_UNSIGNED_SHORT_4_4_4_4
:
2761 if (dstFormat
== GL_RGBA
) {
2762 GLushort
*dst
= (GLushort
*) dstAddr
;
2764 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 12)
2765 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2766 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 4)
2767 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) );
2770 else if (dstFormat
== GL_BGRA
) {
2771 GLushort
*dst
= (GLushort
*) dstAddr
;
2773 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 12)
2774 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2775 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 4)
2776 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) );
2779 else if (dstFormat
== GL_ABGR_EXT
) {
2780 GLushort
*dst
= (GLushort
*) dstAddr
;
2782 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12)
2783 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 8)
2784 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2785 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) );
2789 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2790 if (dstFormat
== GL_RGBA
) {
2791 GLushort
*dst
= (GLushort
*) dstAddr
;
2793 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 15.0F
) )
2794 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2795 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 8)
2796 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12);
2799 else if (dstFormat
== GL_BGRA
) {
2800 GLushort
*dst
= (GLushort
*) dstAddr
;
2802 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 15.0F
) )
2803 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 4)
2804 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 8)
2805 | (IROUND(rgba
[i
][ACOMP
] * 15.0F
) << 12);
2808 else if (dstFormat
== GL_ABGR_EXT
) {
2809 GLushort
*dst
= (GLushort
*) dstAddr
;
2811 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 15.0F
) )
2812 | (IROUND(rgba
[i
][BCOMP
] * 15.0F
) << 4)
2813 | (IROUND(rgba
[i
][GCOMP
] * 15.0F
) << 8)
2814 | (IROUND(rgba
[i
][RCOMP
] * 15.0F
) << 12);
2818 case GL_UNSIGNED_SHORT_5_5_5_1
:
2819 if (dstFormat
== GL_RGBA
) {
2820 GLushort
*dst
= (GLushort
*) dstAddr
;
2822 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 11)
2823 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 6)
2824 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 1)
2825 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) );
2828 else if (dstFormat
== GL_BGRA
) {
2829 GLushort
*dst
= (GLushort
*) dstAddr
;
2831 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 11)
2832 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 6)
2833 | (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 1)
2834 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) );
2837 else if (dstFormat
== GL_ABGR_EXT
) {
2838 GLushort
*dst
= (GLushort
*) dstAddr
;
2840 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 31.0F
) << 11)
2841 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 6)
2842 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 1)
2843 | (IROUND(rgba
[i
][RCOMP
] * 1.0F
) );
2847 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2848 if (dstFormat
== GL_RGBA
) {
2849 GLushort
*dst
= (GLushort
*) dstAddr
;
2851 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 31.0F
) )
2852 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 5)
2853 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 10)
2854 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) << 15);
2857 else if (dstFormat
== GL_BGRA
) {
2858 GLushort
*dst
= (GLushort
*) dstAddr
;
2860 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 31.0F
) )
2861 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 5)
2862 | (IROUND(rgba
[i
][RCOMP
] * 31.0F
) << 10)
2863 | (IROUND(rgba
[i
][ACOMP
] * 1.0F
) << 15);
2866 else if (dstFormat
== GL_ABGR_EXT
) {
2867 GLushort
*dst
= (GLushort
*) dstAddr
;
2869 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 31.0F
) )
2870 | (IROUND(rgba
[i
][BCOMP
] * 31.0F
) << 5)
2871 | (IROUND(rgba
[i
][GCOMP
] * 31.0F
) << 10)
2872 | (IROUND(rgba
[i
][RCOMP
] * 1.0F
) << 15);
2876 case GL_UNSIGNED_INT_8_8_8_8
:
2877 if (dstFormat
== GL_RGBA
) {
2878 GLuint
*dst
= (GLuint
*) dstAddr
;
2880 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 255.F
) << 24)
2881 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 16)
2882 | (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 8)
2883 | (IROUND(rgba
[i
][ACOMP
] * 255.F
) );
2886 else if (dstFormat
== GL_BGRA
) {
2887 GLuint
*dst
= (GLuint
*) dstAddr
;
2889 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 24)
2890 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 16)
2891 | (IROUND(rgba
[i
][RCOMP
] * 255.F
) << 8)
2892 | (IROUND(rgba
[i
][ACOMP
] * 255.F
) );
2895 else if (dstFormat
== GL_ABGR_EXT
) {
2896 GLuint
*dst
= (GLuint
*) dstAddr
;
2898 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 255.F
) << 24)
2899 | (IROUND(rgba
[i
][BCOMP
] * 255.F
) << 16)
2900 | (IROUND(rgba
[i
][GCOMP
] * 255.F
) << 8)
2901 | (IROUND(rgba
[i
][RCOMP
] * 255.F
) );
2905 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2906 if (dstFormat
== GL_RGBA
) {
2907 GLuint
*dst
= (GLuint
*) dstAddr
;
2909 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 255.0F
) )
2910 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 8)
2911 | (IROUND(rgba
[i
][BCOMP
] * 255.0F
) << 16)
2912 | (IROUND(rgba
[i
][ACOMP
] * 255.0F
) << 24);
2915 else if (dstFormat
== GL_BGRA
) {
2916 GLuint
*dst
= (GLuint
*) dstAddr
;
2918 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 255.0F
) )
2919 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 8)
2920 | (IROUND(rgba
[i
][RCOMP
] * 255.0F
) << 16)
2921 | (IROUND(rgba
[i
][ACOMP
] * 255.0F
) << 24);
2924 else if (dstFormat
== GL_ABGR_EXT
) {
2925 GLuint
*dst
= (GLuint
*) dstAddr
;
2927 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 255.0F
) )
2928 | (IROUND(rgba
[i
][BCOMP
] * 255.0F
) << 8)
2929 | (IROUND(rgba
[i
][GCOMP
] * 255.0F
) << 16)
2930 | (IROUND(rgba
[i
][RCOMP
] * 255.0F
) << 24);
2934 case GL_UNSIGNED_INT_10_10_10_2
:
2935 if (dstFormat
== GL_RGBA
) {
2936 GLuint
*dst
= (GLuint
*) dstAddr
;
2938 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 22)
2939 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 12)
2940 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 2)
2941 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) );
2944 else if (dstFormat
== GL_BGRA
) {
2945 GLuint
*dst
= (GLuint
*) dstAddr
;
2947 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 22)
2948 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 12)
2949 | (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 2)
2950 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) );
2953 else if (dstFormat
== GL_ABGR_EXT
) {
2954 GLuint
*dst
= (GLuint
*) dstAddr
;
2956 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 1023.0F
) << 22)
2957 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 12)
2958 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 2)
2959 | (IROUND(rgba
[i
][RCOMP
] * 3.0F
) );
2963 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2964 if (dstFormat
== GL_RGBA
) {
2965 GLuint
*dst
= (GLuint
*) dstAddr
;
2967 dst
[i
] = (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) )
2968 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 10)
2969 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 20)
2970 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) << 30);
2973 else if (dstFormat
== GL_BGRA
) {
2974 GLuint
*dst
= (GLuint
*) dstAddr
;
2976 dst
[i
] = (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) )
2977 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 10)
2978 | (IROUND(rgba
[i
][RCOMP
] * 1023.0F
) << 20)
2979 | (IROUND(rgba
[i
][ACOMP
] * 3.0F
) << 30);
2982 else if (dstFormat
== GL_ABGR_EXT
) {
2983 GLuint
*dst
= (GLuint
*) dstAddr
;
2985 dst
[i
] = (IROUND(rgba
[i
][ACOMP
] * 1023.0F
) )
2986 | (IROUND(rgba
[i
][BCOMP
] * 1023.0F
) << 10)
2987 | (IROUND(rgba
[i
][GCOMP
] * 1023.0F
) << 20)
2988 | (IROUND(rgba
[i
][RCOMP
] * 3.0F
) << 30);
2993 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
2997 if (dstPacking
->SwapBytes
) {
2998 GLint swapSize
= _mesa_sizeof_packed_type(dstType
);
2999 if (swapSize
== 2) {
3000 if (dstPacking
->SwapBytes
) {
3001 _mesa_swap2((GLushort
*) dstAddr
, n
* comps
);
3004 else if (swapSize
== 4) {
3005 if (dstPacking
->SwapBytes
) {
3006 _mesa_swap4((GLuint
*) dstAddr
, n
* comps
);
3013 #define SWAP2BYTE(VALUE) \
3015 GLubyte *bytes = (GLubyte *) &(VALUE); \
3016 GLubyte tmp = bytes[0]; \
3017 bytes[0] = bytes[1]; \
3021 #define SWAP4BYTE(VALUE) \
3023 GLubyte *bytes = (GLubyte *) &(VALUE); \
3024 GLubyte tmp = bytes[0]; \
3025 bytes[0] = bytes[3]; \
3028 bytes[1] = bytes[2]; \
3034 extract_uint_indexes(GLuint n
, GLuint indexes
[],
3035 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
3036 const struct gl_pixelstore_attrib
*unpack
)
3038 ASSERT(srcFormat
== GL_COLOR_INDEX
|| srcFormat
== GL_STENCIL_INDEX
);
3040 ASSERT(srcType
== GL_BITMAP
||
3041 srcType
== GL_UNSIGNED_BYTE
||
3042 srcType
== GL_BYTE
||
3043 srcType
== GL_UNSIGNED_SHORT
||
3044 srcType
== GL_SHORT
||
3045 srcType
== GL_UNSIGNED_INT
||
3046 srcType
== GL_INT
||
3047 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
3048 srcType
== GL_HALF_FLOAT_ARB
||
3049 srcType
== GL_FLOAT
);
3054 GLubyte
*ubsrc
= (GLubyte
*) src
;
3055 if (unpack
->LsbFirst
) {
3056 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
3058 for (i
= 0; i
< n
; i
++) {
3059 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
3070 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
3072 for (i
= 0; i
< n
; i
++) {
3073 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
3085 case GL_UNSIGNED_BYTE
:
3088 const GLubyte
*s
= (const GLubyte
*) src
;
3089 for (i
= 0; i
< n
; i
++)
3096 const GLbyte
*s
= (const GLbyte
*) src
;
3097 for (i
= 0; i
< n
; i
++)
3101 case GL_UNSIGNED_SHORT
:
3104 const GLushort
*s
= (const GLushort
*) src
;
3105 if (unpack
->SwapBytes
) {
3106 for (i
= 0; i
< n
; i
++) {
3107 GLushort value
= s
[i
];
3113 for (i
= 0; i
< n
; i
++)
3121 const GLshort
*s
= (const GLshort
*) src
;
3122 if (unpack
->SwapBytes
) {
3123 for (i
= 0; i
< n
; i
++) {
3124 GLshort value
= s
[i
];
3130 for (i
= 0; i
< n
; i
++)
3135 case GL_UNSIGNED_INT
:
3138 const GLuint
*s
= (const GLuint
*) src
;
3139 if (unpack
->SwapBytes
) {
3140 for (i
= 0; i
< n
; i
++) {
3141 GLuint value
= s
[i
];
3147 for (i
= 0; i
< n
; i
++)
3155 const GLint
*s
= (const GLint
*) src
;
3156 if (unpack
->SwapBytes
) {
3157 for (i
= 0; i
< n
; i
++) {
3164 for (i
= 0; i
< n
; i
++)
3172 const GLfloat
*s
= (const GLfloat
*) src
;
3173 if (unpack
->SwapBytes
) {
3174 for (i
= 0; i
< n
; i
++) {
3175 GLfloat value
= s
[i
];
3177 indexes
[i
] = (GLuint
) value
;
3181 for (i
= 0; i
< n
; i
++)
3182 indexes
[i
] = (GLuint
) s
[i
];
3186 case GL_HALF_FLOAT_ARB
:
3189 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
3190 if (unpack
->SwapBytes
) {
3191 for (i
= 0; i
< n
; i
++) {
3192 GLhalfARB value
= s
[i
];
3194 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
3198 for (i
= 0; i
< n
; i
++)
3199 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
3203 case GL_UNSIGNED_INT_24_8_EXT
:
3206 const GLuint
*s
= (const GLuint
*) src
;
3207 if (unpack
->SwapBytes
) {
3208 for (i
= 0; i
< n
; i
++) {
3209 GLuint value
= s
[i
];
3211 indexes
[i
] = value
& 0xff; /* lower 8 bits */
3215 for (i
= 0; i
< n
; i
++)
3216 indexes
[i
] = s
[i
] & 0xff; /* lower 8 bits */
3222 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
3229 * This function extracts floating point RGBA values from arbitrary
3230 * image data. srcFormat and srcType are the format and type parameters
3231 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
3233 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
3234 * implements the "Conversion to floating point", "Conversion to RGB",
3235 * and "Final Expansion to RGBA" operations.
3237 * Args: n - number of pixels
3238 * rgba - output colors
3239 * srcFormat - format of incoming data
3240 * srcType - data type of incoming data
3241 * src - source data pointer
3242 * swapBytes - perform byteswapping of incoming data?
3245 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
3246 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
3247 GLboolean swapBytes
)
3249 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
3251 GLint rComp
, bComp
, gComp
, aComp
;
3253 ASSERT(srcFormat
== GL_RED
||
3254 srcFormat
== GL_GREEN
||
3255 srcFormat
== GL_BLUE
||
3256 srcFormat
== GL_ALPHA
||
3257 srcFormat
== GL_LUMINANCE
||
3258 srcFormat
== GL_LUMINANCE_ALPHA
||
3259 srcFormat
== GL_INTENSITY
||
3260 srcFormat
== GL_RGB
||
3261 srcFormat
== GL_BGR
||
3262 srcFormat
== GL_RGBA
||
3263 srcFormat
== GL_BGRA
||
3264 srcFormat
== GL_ABGR_EXT
||
3265 srcFormat
== GL_DU8DV8_ATI
||
3266 srcFormat
== GL_DUDV_ATI
);
3268 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
3269 srcType
== GL_BYTE
||
3270 srcType
== GL_UNSIGNED_SHORT
||
3271 srcType
== GL_SHORT
||
3272 srcType
== GL_UNSIGNED_INT
||
3273 srcType
== GL_INT
||
3274 srcType
== GL_HALF_FLOAT_ARB
||
3275 srcType
== GL_FLOAT
||
3276 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3277 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3278 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3279 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3280 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3281 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3282 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3283 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3284 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3285 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3286 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3287 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3289 rComp
= gComp
= bComp
= aComp
= -1;
3291 switch (srcFormat
) {
3294 greenIndex
= blueIndex
= alphaIndex
= -1;
3299 redIndex
= blueIndex
= alphaIndex
= -1;
3304 redIndex
= greenIndex
= alphaIndex
= -1;
3308 redIndex
= greenIndex
= blueIndex
= -1;
3313 redIndex
= greenIndex
= blueIndex
= 0;
3317 case GL_LUMINANCE_ALPHA
:
3318 redIndex
= greenIndex
= blueIndex
= 0;
3323 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
3390 _mesa_problem(NULL
, "bad srcFormat %s in extract float data",
3391 _mesa_lookup_enum_by_nr(srcFormat
));
3396 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
3397 if ((INDEX) < 0) { \
3399 for (i = 0; i < n; i++) { \
3400 rgba[i][CHANNEL] = DEFAULT; \
3403 else if (swapBytes) { \
3404 const TYPE *s = (const TYPE *) src; \
3406 for (i = 0; i < n; i++) { \
3407 TYPE value = s[INDEX]; \
3408 if (sizeof(TYPE) == 2) { \
3411 else if (sizeof(TYPE) == 4) { \
3414 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
3419 const TYPE *s = (const TYPE *) src; \
3421 for (i = 0; i < n; i++) { \
3422 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
3428 case GL_UNSIGNED_BYTE
:
3429 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3430 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3431 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3432 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
3435 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3436 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3437 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3438 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
3440 case GL_UNSIGNED_SHORT
:
3441 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3442 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3443 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3444 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
3447 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3448 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3449 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3450 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
3452 case GL_UNSIGNED_INT
:
3453 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3454 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3455 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3456 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
3459 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3460 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3461 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3462 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
3465 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3466 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3467 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3468 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
3470 case GL_HALF_FLOAT_ARB
:
3471 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3472 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3473 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3474 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
3476 case GL_UNSIGNED_BYTE_3_3_2
:
3478 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3480 for (i
= 0; i
< n
; i
++) {
3481 GLubyte p
= ubsrc
[i
];
3482 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
3483 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
3484 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
3485 rgba
[i
][aComp
] = 1.0F
;
3489 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3491 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3493 for (i
= 0; i
< n
; i
++) {
3494 GLubyte p
= ubsrc
[i
];
3495 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
3496 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
3497 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
3498 rgba
[i
][aComp
] = 1.0F
;
3502 case GL_UNSIGNED_SHORT_5_6_5
:
3504 const GLushort
*ussrc
= (const GLushort
*) src
;
3506 for (i
= 0; i
< n
; i
++) {
3507 GLushort p
= ussrc
[i
];
3509 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3510 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3511 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3512 rgba
[i
][aComp
] = 1.0F
;
3516 const GLushort
*ussrc
= (const GLushort
*) src
;
3518 for (i
= 0; i
< n
; i
++) {
3519 GLushort p
= ussrc
[i
];
3520 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3521 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3522 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3523 rgba
[i
][aComp
] = 1.0F
;
3527 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3529 const GLushort
*ussrc
= (const GLushort
*) src
;
3531 for (i
= 0; i
< n
; i
++) {
3532 GLushort p
= ussrc
[i
];
3534 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3535 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3536 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3537 rgba
[i
][aComp
] = 1.0F
;
3541 const GLushort
*ussrc
= (const GLushort
*) src
;
3543 for (i
= 0; i
< n
; i
++) {
3544 GLushort p
= ussrc
[i
];
3545 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3546 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3547 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3548 rgba
[i
][aComp
] = 1.0F
;
3552 case GL_UNSIGNED_SHORT_4_4_4_4
:
3554 const GLushort
*ussrc
= (const GLushort
*) src
;
3556 for (i
= 0; i
< n
; i
++) {
3557 GLushort p
= ussrc
[i
];
3559 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3560 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3561 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3562 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3566 const GLushort
*ussrc
= (const GLushort
*) src
;
3568 for (i
= 0; i
< n
; i
++) {
3569 GLushort p
= ussrc
[i
];
3570 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3571 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3572 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3573 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3577 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3579 const GLushort
*ussrc
= (const GLushort
*) src
;
3581 for (i
= 0; i
< n
; i
++) {
3582 GLushort p
= ussrc
[i
];
3584 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3585 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3586 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3587 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3591 const GLushort
*ussrc
= (const GLushort
*) src
;
3593 for (i
= 0; i
< n
; i
++) {
3594 GLushort p
= ussrc
[i
];
3595 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3596 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3597 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3598 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3602 case GL_UNSIGNED_SHORT_5_5_5_1
:
3604 const GLushort
*ussrc
= (const GLushort
*) src
;
3606 for (i
= 0; i
< n
; i
++) {
3607 GLushort p
= ussrc
[i
];
3609 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3610 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3611 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3612 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3616 const GLushort
*ussrc
= (const GLushort
*) src
;
3618 for (i
= 0; i
< n
; i
++) {
3619 GLushort p
= ussrc
[i
];
3620 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3621 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3622 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3623 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3627 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3629 const GLushort
*ussrc
= (const GLushort
*) src
;
3631 for (i
= 0; i
< n
; i
++) {
3632 GLushort p
= ussrc
[i
];
3634 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3635 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3636 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3637 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3641 const GLushort
*ussrc
= (const GLushort
*) src
;
3643 for (i
= 0; i
< n
; i
++) {
3644 GLushort p
= ussrc
[i
];
3645 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3646 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3647 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3648 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3652 case GL_UNSIGNED_INT_8_8_8_8
:
3654 const GLuint
*uisrc
= (const GLuint
*) src
;
3656 for (i
= 0; i
< n
; i
++) {
3657 GLuint p
= uisrc
[i
];
3658 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3659 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3660 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3661 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3665 const GLuint
*uisrc
= (const GLuint
*) src
;
3667 for (i
= 0; i
< n
; i
++) {
3668 GLuint p
= uisrc
[i
];
3669 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3670 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3671 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3672 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3676 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3678 const GLuint
*uisrc
= (const GLuint
*) src
;
3680 for (i
= 0; i
< n
; i
++) {
3681 GLuint p
= uisrc
[i
];
3682 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3683 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3684 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3685 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3689 const GLuint
*uisrc
= (const GLuint
*) src
;
3691 for (i
= 0; i
< n
; i
++) {
3692 GLuint p
= uisrc
[i
];
3693 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3694 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3695 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3696 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3700 case GL_UNSIGNED_INT_10_10_10_2
:
3702 const GLuint
*uisrc
= (const GLuint
*) src
;
3704 for (i
= 0; i
< n
; i
++) {
3705 GLuint p
= uisrc
[i
];
3707 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3708 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3709 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3710 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3714 const GLuint
*uisrc
= (const GLuint
*) src
;
3716 for (i
= 0; i
< n
; i
++) {
3717 GLuint p
= uisrc
[i
];
3718 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3719 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3720 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3721 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3725 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3727 const GLuint
*uisrc
= (const GLuint
*) src
;
3729 for (i
= 0; i
< n
; i
++) {
3730 GLuint p
= uisrc
[i
];
3732 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3733 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3734 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3735 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3739 const GLuint
*uisrc
= (const GLuint
*) src
;
3741 for (i
= 0; i
< n
; i
++) {
3742 GLuint p
= uisrc
[i
];
3743 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3744 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3745 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3746 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3751 _mesa_problem(NULL
, "bad srcType in extract float data");
3758 * Unpack a row of color image data from a client buffer according to
3759 * the pixel unpacking parameters.
3760 * Return GLchan values in the specified dest image format.
3761 * This is used by glDrawPixels and glTexImage?D().
3762 * \param ctx - the context
3763 * n - number of pixels in the span
3764 * dstFormat - format of destination color array
3765 * dest - the destination color array
3766 * srcFormat - source image format
3767 * srcType - source image data type
3768 * source - source image pointer
3769 * srcPacking - pixel unpacking parameters
3770 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
3772 * XXX perhaps expand this to process whole images someday.
3775 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
3776 GLuint n
, GLenum dstFormat
, GLchan dest
[],
3777 GLenum srcFormat
, GLenum srcType
,
3778 const GLvoid
*source
,
3779 const struct gl_pixelstore_attrib
*srcPacking
,
3780 GLbitfield transferOps
)
3782 ASSERT(dstFormat
== GL_ALPHA
||
3783 dstFormat
== GL_LUMINANCE
||
3784 dstFormat
== GL_LUMINANCE_ALPHA
||
3785 dstFormat
== GL_INTENSITY
||
3786 dstFormat
== GL_RGB
||
3787 dstFormat
== GL_RGBA
||
3788 dstFormat
== GL_COLOR_INDEX
);
3790 ASSERT(srcFormat
== GL_RED
||
3791 srcFormat
== GL_GREEN
||
3792 srcFormat
== GL_BLUE
||
3793 srcFormat
== GL_ALPHA
||
3794 srcFormat
== GL_LUMINANCE
||
3795 srcFormat
== GL_LUMINANCE_ALPHA
||
3796 srcFormat
== GL_INTENSITY
||
3797 srcFormat
== GL_RGB
||
3798 srcFormat
== GL_BGR
||
3799 srcFormat
== GL_RGBA
||
3800 srcFormat
== GL_BGRA
||
3801 srcFormat
== GL_ABGR_EXT
||
3802 srcFormat
== GL_COLOR_INDEX
);
3804 ASSERT(srcType
== GL_BITMAP
||
3805 srcType
== GL_UNSIGNED_BYTE
||
3806 srcType
== GL_BYTE
||
3807 srcType
== GL_UNSIGNED_SHORT
||
3808 srcType
== GL_SHORT
||
3809 srcType
== GL_UNSIGNED_INT
||
3810 srcType
== GL_INT
||
3811 srcType
== GL_HALF_FLOAT_ARB
||
3812 srcType
== GL_FLOAT
||
3813 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3814 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3815 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3816 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3817 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3818 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3819 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3820 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3821 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3822 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3823 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3824 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3826 /* Try simple cases first */
3827 if (transferOps
== 0) {
3828 if (srcType
== CHAN_TYPE
) {
3829 if (dstFormat
== GL_RGBA
) {
3830 if (srcFormat
== GL_RGBA
) {
3831 memcpy( dest
, source
, n
* 4 * sizeof(GLchan
) );
3834 else if (srcFormat
== GL_RGB
) {
3836 const GLchan
*src
= (const GLchan
*) source
;
3838 for (i
= 0; i
< n
; i
++) {
3849 else if (dstFormat
== GL_RGB
) {
3850 if (srcFormat
== GL_RGB
) {
3851 memcpy( dest
, source
, n
* 3 * sizeof(GLchan
) );
3854 else if (srcFormat
== GL_RGBA
) {
3856 const GLchan
*src
= (const GLchan
*) source
;
3858 for (i
= 0; i
< n
; i
++) {
3868 else if (dstFormat
== srcFormat
) {
3869 GLint comps
= _mesa_components_in_format(srcFormat
);
3871 memcpy( dest
, source
, n
* comps
* sizeof(GLchan
) );
3876 * Common situation, loading 8bit RGBA/RGB source images
3877 * into 16/32 bit destination. (OSMesa16/32)
3879 else if (srcType
== GL_UNSIGNED_BYTE
) {
3880 if (dstFormat
== GL_RGBA
) {
3881 if (srcFormat
== GL_RGB
) {
3883 const GLubyte
*src
= (const GLubyte
*) source
;
3885 for (i
= 0; i
< n
; i
++) {
3886 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3887 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3888 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3895 else if (srcFormat
== GL_RGBA
) {
3897 const GLubyte
*src
= (const GLubyte
*) source
;
3899 for (i
= 0; i
< n
; i
++) {
3900 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3901 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3902 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3903 dst
[3] = UBYTE_TO_CHAN(src
[3]);
3910 else if (dstFormat
== GL_RGB
) {
3911 if (srcFormat
== GL_RGB
) {
3913 const GLubyte
*src
= (const GLubyte
*) source
;
3915 for (i
= 0; i
< n
; i
++) {
3916 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3917 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3918 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3924 else if (srcFormat
== GL_RGBA
) {
3926 const GLubyte
*src
= (const GLubyte
*) source
;
3928 for (i
= 0; i
< n
; i
++) {
3929 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3930 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3931 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3942 /* general solution begins here */
3944 GLint dstComponents
;
3945 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3946 GLint dstLuminanceIndex
, dstIntensityIndex
;
3947 GLfloat rgba
[MAX_WIDTH
][4];
3949 dstComponents
= _mesa_components_in_format( dstFormat
);
3950 /* source & dest image formats should have been error checked by now */
3951 assert(dstComponents
> 0);
3954 * Extract image data and convert to RGBA floats
3956 assert(n
<= MAX_WIDTH
);
3957 if (srcFormat
== GL_COLOR_INDEX
) {
3958 GLuint indexes
[MAX_WIDTH
];
3959 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3962 if (dstFormat
== GL_COLOR_INDEX
) {
3964 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3965 /* convert to GLchan and return */
3966 for (i
= 0; i
< n
; i
++) {
3967 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3972 /* Convert indexes to RGBA */
3973 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3974 shift_and_offset_ci(ctx
, n
, indexes
);
3976 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3979 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3980 * with color indexes.
3982 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3985 /* non-color index data */
3986 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3987 srcPacking
->SwapBytes
);
3990 /* Need to clamp if returning GLubytes or GLushorts */
3991 #if CHAN_TYPE != GL_FLOAT
3992 transferOps
|= IMAGE_CLAMP_BIT
;
3996 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3999 /* Now determine which color channels we need to produce.
4000 * And determine the dest index (offset) within each color tuple.
4002 switch (dstFormat
) {
4005 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
4006 dstLuminanceIndex
= dstIntensityIndex
= -1;
4009 dstLuminanceIndex
= 0;
4010 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
4011 dstIntensityIndex
= -1;
4013 case GL_LUMINANCE_ALPHA
:
4014 dstLuminanceIndex
= 0;
4016 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
4017 dstIntensityIndex
= -1;
4020 dstIntensityIndex
= 0;
4021 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
4022 dstLuminanceIndex
= -1;
4028 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
4035 dstLuminanceIndex
= dstIntensityIndex
= -1;
4038 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
4043 /* Now return the GLchan data in the requested dstFormat */
4045 if (dstRedIndex
>= 0) {
4048 for (i
= 0; i
< n
; i
++) {
4049 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
4050 dst
+= dstComponents
;
4054 if (dstGreenIndex
>= 0) {
4057 for (i
= 0; i
< n
; i
++) {
4058 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
4059 dst
+= dstComponents
;
4063 if (dstBlueIndex
>= 0) {
4066 for (i
= 0; i
< n
; i
++) {
4067 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
4068 dst
+= dstComponents
;
4072 if (dstAlphaIndex
>= 0) {
4075 for (i
= 0; i
< n
; i
++) {
4076 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
4077 dst
+= dstComponents
;
4081 if (dstIntensityIndex
>= 0) {
4084 assert(dstIntensityIndex
== 0);
4085 assert(dstComponents
== 1);
4086 for (i
= 0; i
< n
; i
++) {
4087 /* Intensity comes from red channel */
4088 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
4092 if (dstLuminanceIndex
>= 0) {
4095 assert(dstLuminanceIndex
== 0);
4096 for (i
= 0; i
< n
; i
++) {
4097 /* Luminance comes from red channel */
4098 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
4099 dst
+= dstComponents
;
4107 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
4108 * instead of GLchan.
4111 _mesa_unpack_color_span_float( GLcontext
*ctx
,
4112 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
4113 GLenum srcFormat
, GLenum srcType
,
4114 const GLvoid
*source
,
4115 const struct gl_pixelstore_attrib
*srcPacking
,
4116 GLbitfield transferOps
)
4118 ASSERT(dstFormat
== GL_ALPHA
||
4119 dstFormat
== GL_LUMINANCE
||
4120 dstFormat
== GL_LUMINANCE_ALPHA
||
4121 dstFormat
== GL_INTENSITY
||
4122 dstFormat
== GL_RGB
||
4123 dstFormat
== GL_RGBA
||
4124 dstFormat
== GL_COLOR_INDEX
);
4126 ASSERT(srcFormat
== GL_RED
||
4127 srcFormat
== GL_GREEN
||
4128 srcFormat
== GL_BLUE
||
4129 srcFormat
== GL_ALPHA
||
4130 srcFormat
== GL_LUMINANCE
||
4131 srcFormat
== GL_LUMINANCE_ALPHA
||
4132 srcFormat
== GL_INTENSITY
||
4133 srcFormat
== GL_RGB
||
4134 srcFormat
== GL_BGR
||
4135 srcFormat
== GL_RGBA
||
4136 srcFormat
== GL_BGRA
||
4137 srcFormat
== GL_ABGR_EXT
||
4138 srcFormat
== GL_COLOR_INDEX
);
4140 ASSERT(srcType
== GL_BITMAP
||
4141 srcType
== GL_UNSIGNED_BYTE
||
4142 srcType
== GL_BYTE
||
4143 srcType
== GL_UNSIGNED_SHORT
||
4144 srcType
== GL_SHORT
||
4145 srcType
== GL_UNSIGNED_INT
||
4146 srcType
== GL_INT
||
4147 srcType
== GL_HALF_FLOAT_ARB
||
4148 srcType
== GL_FLOAT
||
4149 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
4150 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
4151 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
4152 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
4153 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
4154 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
4155 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
4156 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
4157 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
4158 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
4159 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
4160 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
4162 /* general solution, no special cases, yet */
4164 GLint dstComponents
;
4165 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
4166 GLint dstLuminanceIndex
, dstIntensityIndex
;
4167 GLfloat rgba
[MAX_WIDTH
][4];
4169 dstComponents
= _mesa_components_in_format( dstFormat
);
4170 /* source & dest image formats should have been error checked by now */
4171 assert(dstComponents
> 0);
4174 * Extract image data and convert to RGBA floats
4176 assert(n
<= MAX_WIDTH
);
4177 if (srcFormat
== GL_COLOR_INDEX
) {
4178 GLuint indexes
[MAX_WIDTH
];
4179 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
4182 if (dstFormat
== GL_COLOR_INDEX
) {
4184 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4185 /* convert to GLchan and return */
4186 for (i
= 0; i
< n
; i
++) {
4187 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
4192 /* Convert indexes to RGBA */
4193 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
4194 shift_and_offset_ci(ctx
, n
, indexes
);
4196 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
4199 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
4200 * with color indexes.
4202 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
4205 /* non-color index data */
4206 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
4207 srcPacking
->SwapBytes
);
4211 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
4214 /* Now determine which color channels we need to produce.
4215 * And determine the dest index (offset) within each color tuple.
4217 switch (dstFormat
) {
4220 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
4221 dstLuminanceIndex
= dstIntensityIndex
= -1;
4224 dstLuminanceIndex
= 0;
4225 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
4226 dstIntensityIndex
= -1;
4228 case GL_LUMINANCE_ALPHA
:
4229 dstLuminanceIndex
= 0;
4231 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
4232 dstIntensityIndex
= -1;
4235 dstIntensityIndex
= 0;
4236 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
4237 dstLuminanceIndex
= -1;
4243 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
4250 dstLuminanceIndex
= dstIntensityIndex
= -1;
4253 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
4257 /* Now pack results in the requested dstFormat */
4258 if (dstRedIndex
>= 0) {
4259 GLfloat
*dst
= dest
;
4261 for (i
= 0; i
< n
; i
++) {
4262 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
4263 dst
+= dstComponents
;
4267 if (dstGreenIndex
>= 0) {
4268 GLfloat
*dst
= dest
;
4270 for (i
= 0; i
< n
; i
++) {
4271 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
4272 dst
+= dstComponents
;
4276 if (dstBlueIndex
>= 0) {
4277 GLfloat
*dst
= dest
;
4279 for (i
= 0; i
< n
; i
++) {
4280 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
4281 dst
+= dstComponents
;
4285 if (dstAlphaIndex
>= 0) {
4286 GLfloat
*dst
= dest
;
4288 for (i
= 0; i
< n
; i
++) {
4289 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
4290 dst
+= dstComponents
;
4294 if (dstIntensityIndex
>= 0) {
4295 GLfloat
*dst
= dest
;
4297 assert(dstIntensityIndex
== 0);
4298 assert(dstComponents
== 1);
4299 for (i
= 0; i
< n
; i
++) {
4300 /* Intensity comes from red channel */
4301 dst
[i
] = rgba
[i
][RCOMP
];
4305 if (dstLuminanceIndex
>= 0) {
4306 GLfloat
*dst
= dest
;
4308 assert(dstLuminanceIndex
== 0);
4309 for (i
= 0; i
< n
; i
++) {
4310 /* Luminance comes from red channel */
4311 dst
[0] = rgba
[i
][RCOMP
];
4312 dst
+= dstComponents
;
4319 * Similar to _mesa_unpack_color_span_float(), but for dudv data instead of rgba,
4320 * directly return GLbyte data, no transfer ops apply.
4323 _mesa_unpack_dudv_span_byte( GLcontext
*ctx
,
4324 GLuint n
, GLenum dstFormat
, GLbyte dest
[],
4325 GLenum srcFormat
, GLenum srcType
,
4326 const GLvoid
*source
,
4327 const struct gl_pixelstore_attrib
*srcPacking
,
4328 GLbitfield transferOps
)
4330 ASSERT(dstFormat
== GL_DUDV_ATI
);
4331 ASSERT(srcFormat
== GL_DUDV_ATI
);
4333 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
4334 srcType
== GL_BYTE
||
4335 srcType
== GL_UNSIGNED_SHORT
||
4336 srcType
== GL_SHORT
||
4337 srcType
== GL_UNSIGNED_INT
||
4338 srcType
== GL_INT
||
4339 srcType
== GL_HALF_FLOAT_ARB
||
4340 srcType
== GL_FLOAT
);
4342 /* general solution */
4344 GLint dstComponents
;
4345 GLfloat rgba
[MAX_WIDTH
][4];
4349 dstComponents
= _mesa_components_in_format( dstFormat
);
4350 /* source & dest image formats should have been error checked by now */
4351 assert(dstComponents
> 0);
4354 * Extract image data and convert to RGBA floats
4356 assert(n
<= MAX_WIDTH
);
4357 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
4358 srcPacking
->SwapBytes
);
4361 /* Now determine which color channels we need to produce.
4362 * And determine the dest index (offset) within each color tuple.
4365 /* Now pack results in the requested dstFormat */
4366 for (i
= 0; i
< n
; i
++) {
4367 /* not sure - need clamp[-1,1] here? */
4368 dst
[0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
4369 dst
[1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
4370 dst
+= dstComponents
;
4376 * Unpack a row of color index data from a client buffer according to
4377 * the pixel unpacking parameters.
4378 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
4380 * Args: ctx - the context
4381 * n - number of pixels
4382 * dstType - destination data type
4383 * dest - destination array
4384 * srcType - source pixel type
4385 * source - source data pointer
4386 * srcPacking - pixel unpacking parameters
4387 * transferOps - the pixel transfer operations to apply
4390 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
4391 GLenum dstType
, GLvoid
*dest
,
4392 GLenum srcType
, const GLvoid
*source
,
4393 const struct gl_pixelstore_attrib
*srcPacking
,
4394 GLbitfield transferOps
)
4396 ASSERT(srcType
== GL_BITMAP
||
4397 srcType
== GL_UNSIGNED_BYTE
||
4398 srcType
== GL_BYTE
||
4399 srcType
== GL_UNSIGNED_SHORT
||
4400 srcType
== GL_SHORT
||
4401 srcType
== GL_UNSIGNED_INT
||
4402 srcType
== GL_INT
||
4403 srcType
== GL_HALF_FLOAT_ARB
||
4404 srcType
== GL_FLOAT
);
4406 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4407 dstType
== GL_UNSIGNED_SHORT
||
4408 dstType
== GL_UNSIGNED_INT
);
4411 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4414 * Try simple cases first
4416 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
4417 && dstType
== GL_UNSIGNED_BYTE
) {
4418 memcpy(dest
, source
, n
* sizeof(GLubyte
));
4420 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
4421 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
4422 memcpy(dest
, source
, n
* sizeof(GLuint
));
4428 GLuint indexes
[MAX_WIDTH
];
4429 assert(n
<= MAX_WIDTH
);
4431 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
4435 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4437 /* convert to dest type */
4439 case GL_UNSIGNED_BYTE
:
4441 GLubyte
*dst
= (GLubyte
*) dest
;
4443 for (i
= 0; i
< n
; i
++) {
4444 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4448 case GL_UNSIGNED_SHORT
:
4450 GLuint
*dst
= (GLuint
*) dest
;
4452 for (i
= 0; i
< n
; i
++) {
4453 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4457 case GL_UNSIGNED_INT
:
4458 memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4461 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
4468 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
4469 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
4470 const struct gl_pixelstore_attrib
*dstPacking
,
4471 GLbitfield transferOps
)
4473 GLuint indexes
[MAX_WIDTH
];
4475 ASSERT(n
<= MAX_WIDTH
);
4477 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
4479 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
4480 /* make a copy of input */
4481 memcpy(indexes
, source
, n
* sizeof(GLuint
));
4482 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
4487 case GL_UNSIGNED_BYTE
:
4489 GLubyte
*dst
= (GLubyte
*) dest
;
4491 for (i
= 0; i
< n
; i
++) {
4492 *dst
++ = (GLubyte
) source
[i
];
4498 GLbyte
*dst
= (GLbyte
*) dest
;
4500 for (i
= 0; i
< n
; i
++) {
4501 dst
[i
] = (GLbyte
) source
[i
];
4505 case GL_UNSIGNED_SHORT
:
4507 GLushort
*dst
= (GLushort
*) dest
;
4509 for (i
= 0; i
< n
; i
++) {
4510 dst
[i
] = (GLushort
) source
[i
];
4512 if (dstPacking
->SwapBytes
) {
4513 _mesa_swap2( (GLushort
*) dst
, n
);
4519 GLshort
*dst
= (GLshort
*) dest
;
4521 for (i
= 0; i
< n
; i
++) {
4522 dst
[i
] = (GLshort
) source
[i
];
4524 if (dstPacking
->SwapBytes
) {
4525 _mesa_swap2( (GLushort
*) dst
, n
);
4529 case GL_UNSIGNED_INT
:
4531 GLuint
*dst
= (GLuint
*) dest
;
4533 for (i
= 0; i
< n
; i
++) {
4534 dst
[i
] = (GLuint
) source
[i
];
4536 if (dstPacking
->SwapBytes
) {
4537 _mesa_swap4( (GLuint
*) dst
, n
);
4543 GLint
*dst
= (GLint
*) dest
;
4545 for (i
= 0; i
< n
; i
++) {
4546 dst
[i
] = (GLint
) source
[i
];
4548 if (dstPacking
->SwapBytes
) {
4549 _mesa_swap4( (GLuint
*) dst
, n
);
4555 GLfloat
*dst
= (GLfloat
*) dest
;
4557 for (i
= 0; i
< n
; i
++) {
4558 dst
[i
] = (GLfloat
) source
[i
];
4560 if (dstPacking
->SwapBytes
) {
4561 _mesa_swap4( (GLuint
*) dst
, n
);
4565 case GL_HALF_FLOAT_ARB
:
4567 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4569 for (i
= 0; i
< n
; i
++) {
4570 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
4572 if (dstPacking
->SwapBytes
) {
4573 _mesa_swap2( (GLushort
*) dst
, n
);
4578 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4584 * Unpack a row of stencil data from a client buffer according to
4585 * the pixel unpacking parameters.
4586 * This is (or will be) used by glDrawPixels
4588 * Args: ctx - the context
4589 * n - number of pixels
4590 * dstType - destination data type
4591 * dest - destination array
4592 * srcType - source pixel type
4593 * source - source data pointer
4594 * srcPacking - pixel unpacking parameters
4595 * transferOps - apply offset/bias/lookup ops?
4598 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4599 GLenum dstType
, GLvoid
*dest
,
4600 GLenum srcType
, const GLvoid
*source
,
4601 const struct gl_pixelstore_attrib
*srcPacking
,
4602 GLbitfield transferOps
)
4604 ASSERT(srcType
== GL_BITMAP
||
4605 srcType
== GL_UNSIGNED_BYTE
||
4606 srcType
== GL_BYTE
||
4607 srcType
== GL_UNSIGNED_SHORT
||
4608 srcType
== GL_SHORT
||
4609 srcType
== GL_UNSIGNED_INT
||
4610 srcType
== GL_INT
||
4611 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
4612 srcType
== GL_HALF_FLOAT_ARB
||
4613 srcType
== GL_FLOAT
);
4615 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4616 dstType
== GL_UNSIGNED_SHORT
||
4617 dstType
== GL_UNSIGNED_INT
);
4619 /* only shift and offset apply to stencil */
4620 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
4623 * Try simple cases first
4625 if (transferOps
== 0 &&
4626 !ctx
->Pixel
.MapStencilFlag
&&
4627 srcType
== GL_UNSIGNED_BYTE
&&
4628 dstType
== GL_UNSIGNED_BYTE
) {
4629 memcpy(dest
, source
, n
* sizeof(GLubyte
));
4631 else if (transferOps
== 0 &&
4632 !ctx
->Pixel
.MapStencilFlag
&&
4633 srcType
== GL_UNSIGNED_INT
&&
4634 dstType
== GL_UNSIGNED_INT
&&
4635 !srcPacking
->SwapBytes
) {
4636 memcpy(dest
, source
, n
* sizeof(GLuint
));
4642 GLuint indexes
[MAX_WIDTH
];
4643 assert(n
<= MAX_WIDTH
);
4645 extract_uint_indexes(n
, indexes
, GL_STENCIL_INDEX
, srcType
, source
,
4648 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
4649 /* shift and offset indexes */
4650 shift_and_offset_ci(ctx
, n
, indexes
);
4653 if (ctx
->Pixel
.MapStencilFlag
) {
4654 /* Apply stencil lookup table */
4655 const GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
4657 for (i
= 0; i
< n
; i
++) {
4658 indexes
[i
] = (GLuint
)ctx
->PixelMaps
.StoS
.Map
[ indexes
[i
] & mask
];
4662 /* convert to dest type */
4664 case GL_UNSIGNED_BYTE
:
4666 GLubyte
*dst
= (GLubyte
*) dest
;
4668 for (i
= 0; i
< n
; i
++) {
4669 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4673 case GL_UNSIGNED_SHORT
:
4675 GLuint
*dst
= (GLuint
*) dest
;
4677 for (i
= 0; i
< n
; i
++) {
4678 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4682 case GL_UNSIGNED_INT
:
4683 memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4686 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
4693 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4694 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
4695 const struct gl_pixelstore_attrib
*dstPacking
)
4697 GLstencil stencil
[MAX_WIDTH
];
4699 ASSERT(n
<= MAX_WIDTH
);
4701 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
4702 ctx
->Pixel
.MapStencilFlag
) {
4703 /* make a copy of input */
4704 memcpy(stencil
, source
, n
* sizeof(GLstencil
));
4705 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencil
);
4710 case GL_UNSIGNED_BYTE
:
4711 if (sizeof(GLstencil
) == 1) {
4712 memcpy( dest
, source
, n
);
4715 GLubyte
*dst
= (GLubyte
*) dest
;
4718 dst
[i
] = (GLubyte
) source
[i
];
4724 GLbyte
*dst
= (GLbyte
*) dest
;
4727 dst
[i
] = (GLbyte
) (source
[i
] & 0x7f);
4731 case GL_UNSIGNED_SHORT
:
4733 GLushort
*dst
= (GLushort
*) dest
;
4736 dst
[i
] = (GLushort
) source
[i
];
4738 if (dstPacking
->SwapBytes
) {
4739 _mesa_swap2( (GLushort
*) dst
, n
);
4745 GLshort
*dst
= (GLshort
*) dest
;
4748 dst
[i
] = (GLshort
) source
[i
];
4750 if (dstPacking
->SwapBytes
) {
4751 _mesa_swap2( (GLushort
*) dst
, n
);
4755 case GL_UNSIGNED_INT
:
4757 GLuint
*dst
= (GLuint
*) dest
;
4760 dst
[i
] = (GLuint
) source
[i
];
4762 if (dstPacking
->SwapBytes
) {
4763 _mesa_swap4( (GLuint
*) dst
, n
);
4769 GLint
*dst
= (GLint
*) dest
;
4772 dst
[i
] = (GLint
) source
[i
];
4774 if (dstPacking
->SwapBytes
) {
4775 _mesa_swap4( (GLuint
*) dst
, n
);
4781 GLfloat
*dst
= (GLfloat
*) dest
;
4784 dst
[i
] = (GLfloat
) source
[i
];
4786 if (dstPacking
->SwapBytes
) {
4787 _mesa_swap4( (GLuint
*) dst
, n
);
4791 case GL_HALF_FLOAT_ARB
:
4793 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4796 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
4798 if (dstPacking
->SwapBytes
) {
4799 _mesa_swap2( (GLushort
*) dst
, n
);
4804 if (dstPacking
->LsbFirst
) {
4805 GLubyte
*dst
= (GLubyte
*) dest
;
4808 for (i
= 0; i
< n
; i
++) {
4811 *dst
|= ((source
[i
] != 0) << shift
);
4820 GLubyte
*dst
= (GLubyte
*) dest
;
4823 for (i
= 0; i
< n
; i
++) {
4826 *dst
|= ((source
[i
] != 0) << shift
);
4836 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4840 #define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT) \
4843 const GLTYPE *src = (const GLTYPE *)source; \
4844 for (i = 0; i < n; i++) { \
4845 GLTYPE value = src[i]; \
4846 if (srcPacking->SwapBytes) { \
4847 if (sizeof(GLTYPE) == 2) { \
4849 } else if (sizeof(GLTYPE) == 4) { \
4853 depthValues[i] = GLTYPE2FLOAT(value); \
4859 * Unpack a row of depth/z values from memory, returning GLushort, GLuint
4860 * or GLfloat values.
4861 * The glPixelTransfer (scale/bias) params will be applied.
4863 * \param dstType one of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT
4864 * \param depthMax max value for returned GLushort or GLuint values
4865 * (ignored for GLfloat).
4868 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
,
4869 GLenum dstType
, GLvoid
*dest
, GLuint depthMax
,
4870 GLenum srcType
, const GLvoid
*source
,
4871 const struct gl_pixelstore_attrib
*srcPacking
)
4873 GLfloat depthTemp
[MAX_WIDTH
], *depthValues
;
4874 GLboolean needClamp
= GL_FALSE
;
4876 /* Look for special cases first.
4877 * Not only are these faster, they're less prone to numeric conversion
4878 * problems. Otherwise, converting from an int type to a float then
4879 * back to an int type can introduce errors that will show up as
4880 * artifacts in things like depth peeling which uses glCopyTexImage.
4882 if (ctx
->Pixel
.DepthScale
== 1.0 && ctx
->Pixel
.DepthBias
== 0.0) {
4883 if (srcType
== GL_UNSIGNED_INT
&& dstType
== GL_UNSIGNED_SHORT
) {
4884 const GLuint
*src
= (const GLuint
*) source
;
4885 GLushort
*dst
= (GLushort
*) dest
;
4887 for (i
= 0; i
< n
; i
++) {
4888 dst
[i
] = src
[i
] >> 16;
4892 if (srcType
== GL_UNSIGNED_SHORT
4893 && dstType
== GL_UNSIGNED_INT
4894 && depthMax
== 0xffffffff) {
4895 const GLushort
*src
= (const GLushort
*) source
;
4896 GLuint
*dst
= (GLuint
*) dest
;
4898 for (i
= 0; i
< n
; i
++) {
4899 dst
[i
] = src
[i
] | (src
[i
] << 16);
4903 if (srcType
== GL_UNSIGNED_INT_24_8
4904 && dstType
== GL_UNSIGNED_INT
4905 && depthMax
== 0xffffff) {
4906 const GLuint
*src
= (const GLuint
*) source
;
4907 GLuint
*dst
= (GLuint
*) dest
;
4909 for (i
= 0; i
< n
; i
++) {
4910 dst
[i
] = src
[i
] >> 8;
4914 /* XXX may want to add additional cases here someday */
4917 /* general case path follows */
4919 if (dstType
== GL_FLOAT
) {
4920 depthValues
= (GLfloat
*) dest
;
4923 depthValues
= depthTemp
;
4926 /* Convert incoming values to GLfloat. Some conversions will require
4931 DEPTH_VALUES(GLbyte
, BYTE_TO_FLOAT
);
4932 needClamp
= GL_TRUE
;
4934 case GL_UNSIGNED_BYTE
:
4935 DEPTH_VALUES(GLubyte
, UBYTE_TO_FLOAT
);
4938 DEPTH_VALUES(GLshort
, SHORT_TO_FLOAT
);
4939 needClamp
= GL_TRUE
;
4941 case GL_UNSIGNED_SHORT
:
4942 DEPTH_VALUES(GLushort
, USHORT_TO_FLOAT
);
4945 DEPTH_VALUES(GLint
, INT_TO_FLOAT
);
4946 needClamp
= GL_TRUE
;
4948 case GL_UNSIGNED_INT
:
4949 DEPTH_VALUES(GLuint
, UINT_TO_FLOAT
);
4951 case GL_UNSIGNED_INT_24_8_EXT
: /* GL_EXT_packed_depth_stencil */
4952 if (dstType
== GL_UNSIGNED_INT_24_8_EXT
&&
4953 depthMax
== 0xffffff &&
4954 ctx
->Pixel
.DepthScale
== 1.0 &&
4955 ctx
->Pixel
.DepthBias
== 0.0) {
4956 const GLuint
*src
= (const GLuint
*) source
;
4957 GLuint
*zValues
= (GLuint
*) dest
;
4959 for (i
= 0; i
< n
; i
++) {
4960 GLuint value
= src
[i
];
4961 if (srcPacking
->SwapBytes
) {
4964 zValues
[i
] = value
& 0xffffff00;
4969 const GLuint
*src
= (const GLuint
*) source
;
4970 const GLfloat scale
= 1.0f
/ 0xffffff;
4972 for (i
= 0; i
< n
; i
++) {
4973 GLuint value
= src
[i
];
4974 if (srcPacking
->SwapBytes
) {
4977 depthValues
[i
] = (value
>> 8) * scale
;
4982 DEPTH_VALUES(GLfloat
, 1*);
4983 needClamp
= GL_TRUE
;
4985 case GL_HALF_FLOAT_ARB
:
4988 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
4989 for (i
= 0; i
< n
; i
++) {
4990 GLhalfARB value
= src
[i
];
4991 if (srcPacking
->SwapBytes
) {
4994 depthValues
[i
] = _mesa_half_to_float(value
);
4996 needClamp
= GL_TRUE
;
5000 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
5004 /* apply depth scale and bias */
5006 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
5007 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
5008 if (scale
!= 1.0 || bias
!= 0.0) {
5010 for (i
= 0; i
< n
; i
++) {
5011 depthValues
[i
] = depthValues
[i
] * scale
+ bias
;
5013 needClamp
= GL_TRUE
;
5017 /* clamp to [0, 1] */
5020 for (i
= 0; i
< n
; i
++) {
5021 depthValues
[i
] = (GLfloat
)CLAMP(depthValues
[i
], 0.0, 1.0);
5026 * Convert values to dstType
5028 if (dstType
== GL_UNSIGNED_INT
) {
5029 GLuint
*zValues
= (GLuint
*) dest
;
5031 if (depthMax
<= 0xffffff) {
5032 /* no overflow worries */
5033 for (i
= 0; i
< n
; i
++) {
5034 zValues
[i
] = (GLuint
) (depthValues
[i
] * (GLfloat
) depthMax
);
5038 /* need to use double precision to prevent overflow problems */
5039 for (i
= 0; i
< n
; i
++) {
5040 GLdouble z
= depthValues
[i
] * (GLfloat
) depthMax
;
5041 if (z
>= (GLdouble
) 0xffffffff)
5042 zValues
[i
] = 0xffffffff;
5044 zValues
[i
] = (GLuint
) z
;
5048 else if (dstType
== GL_UNSIGNED_SHORT
) {
5049 GLushort
*zValues
= (GLushort
*) dest
;
5051 ASSERT(depthMax
<= 0xffff);
5052 for (i
= 0; i
< n
; i
++) {
5053 zValues
[i
] = (GLushort
) (depthValues
[i
] * (GLfloat
) depthMax
);
5057 ASSERT(dstType
== GL_FLOAT
);
5058 /*ASSERT(depthMax == 1.0F);*/
5064 * Pack an array of depth values. The values are floats in [0,1].
5067 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
5068 GLenum dstType
, const GLfloat
*depthSpan
,
5069 const struct gl_pixelstore_attrib
*dstPacking
)
5071 GLfloat depthCopy
[MAX_WIDTH
];
5073 ASSERT(n
<= MAX_WIDTH
);
5075 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
5076 memcpy(depthCopy
, depthSpan
, n
* sizeof(GLfloat
));
5077 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
5078 depthSpan
= depthCopy
;
5082 case GL_UNSIGNED_BYTE
:
5084 GLubyte
*dst
= (GLubyte
*) dest
;
5086 for (i
= 0; i
< n
; i
++) {
5087 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
5093 GLbyte
*dst
= (GLbyte
*) dest
;
5095 for (i
= 0; i
< n
; i
++) {
5096 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
5100 case GL_UNSIGNED_SHORT
:
5102 GLushort
*dst
= (GLushort
*) dest
;
5104 for (i
= 0; i
< n
; i
++) {
5105 CLAMPED_FLOAT_TO_USHORT(dst
[i
], depthSpan
[i
]);
5107 if (dstPacking
->SwapBytes
) {
5108 _mesa_swap2( (GLushort
*) dst
, n
);
5114 GLshort
*dst
= (GLshort
*) dest
;
5116 for (i
= 0; i
< n
; i
++) {
5117 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
5119 if (dstPacking
->SwapBytes
) {
5120 _mesa_swap2( (GLushort
*) dst
, n
);
5124 case GL_UNSIGNED_INT
:
5126 GLuint
*dst
= (GLuint
*) dest
;
5128 for (i
= 0; i
< n
; i
++) {
5129 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
5131 if (dstPacking
->SwapBytes
) {
5132 _mesa_swap4( (GLuint
*) dst
, n
);
5138 GLint
*dst
= (GLint
*) dest
;
5140 for (i
= 0; i
< n
; i
++) {
5141 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
5143 if (dstPacking
->SwapBytes
) {
5144 _mesa_swap4( (GLuint
*) dst
, n
);
5150 GLfloat
*dst
= (GLfloat
*) dest
;
5152 for (i
= 0; i
< n
; i
++) {
5153 dst
[i
] = depthSpan
[i
];
5155 if (dstPacking
->SwapBytes
) {
5156 _mesa_swap4( (GLuint
*) dst
, n
);
5160 case GL_HALF_FLOAT_ARB
:
5162 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
5164 for (i
= 0; i
< n
; i
++) {
5165 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
5167 if (dstPacking
->SwapBytes
) {
5168 _mesa_swap2( (GLushort
*) dst
, n
);
5173 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
5180 * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
5183 _mesa_pack_depth_stencil_span(const GLcontext
*ctx
, GLuint n
, GLuint
*dest
,
5184 const GLfloat
*depthVals
,
5185 const GLstencil
*stencilVals
,
5186 const struct gl_pixelstore_attrib
*dstPacking
)
5188 GLfloat depthCopy
[MAX_WIDTH
];
5189 GLstencil stencilCopy
[MAX_WIDTH
];
5192 ASSERT(n
<= MAX_WIDTH
);
5194 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
5195 memcpy(depthCopy
, depthVals
, n
* sizeof(GLfloat
));
5196 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
5197 depthVals
= depthCopy
;
5200 if (ctx
->Pixel
.IndexShift
||
5201 ctx
->Pixel
.IndexOffset
||
5202 ctx
->Pixel
.MapStencilFlag
) {
5203 memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
5204 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencilCopy
);
5205 stencilVals
= stencilCopy
;
5208 for (i
= 0; i
< n
; i
++) {
5209 GLuint z
= (GLuint
) (depthVals
[i
] * 0xffffff);
5210 dest
[i
] = (z
<< 8) | (stencilVals
[i
] & 0xff);
5213 if (dstPacking
->SwapBytes
) {
5214 _mesa_swap4(dest
, n
);
5222 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
5223 * Return all image data in a contiguous block. This is used when we
5224 * compile glDrawPixels, glTexImage, etc into a display list. We
5225 * need a copy of the data in a standard format.
5228 _mesa_unpack_image( GLuint dimensions
,
5229 GLsizei width
, GLsizei height
, GLsizei depth
,
5230 GLenum format
, GLenum type
, const GLvoid
*pixels
,
5231 const struct gl_pixelstore_attrib
*unpack
)
5233 GLint bytesPerRow
, compsPerRow
;
5234 GLboolean flipBytes
, swap2
, swap4
;
5237 return NULL
; /* not necessarily an error */
5239 if (width
<= 0 || height
<= 0 || depth
<= 0)
5240 return NULL
; /* generate error later */
5242 if (type
== GL_BITMAP
) {
5243 bytesPerRow
= (width
+ 7) >> 3;
5244 flipBytes
= unpack
->LsbFirst
;
5245 swap2
= swap4
= GL_FALSE
;
5249 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
5250 GLint components
= _mesa_components_in_format(format
);
5253 if (_mesa_type_is_packed(type
))
5256 if (bytesPerPixel
<= 0 || components
<= 0)
5257 return NULL
; /* bad format or type. generate error later */
5258 bytesPerRow
= bytesPerPixel
* width
;
5259 bytesPerComp
= bytesPerPixel
/ components
;
5260 flipBytes
= GL_FALSE
;
5261 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
5262 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
5263 compsPerRow
= components
* width
;
5264 assert(compsPerRow
>= width
);
5269 = (GLubyte
*) malloc(bytesPerRow
* height
* depth
);
5273 return NULL
; /* generate GL_OUT_OF_MEMORY later */
5276 for (img
= 0; img
< depth
; img
++) {
5277 for (row
= 0; row
< height
; row
++) {
5278 const GLvoid
*src
= _mesa_image_address(dimensions
, unpack
, pixels
,
5279 width
, height
, format
, type
, img
, row
, 0);
5281 if ((type
== GL_BITMAP
) && (unpack
->SkipPixels
& 0x7)) {
5283 flipBytes
= GL_FALSE
;
5284 if (unpack
->LsbFirst
) {
5285 GLubyte srcMask
= 1 << (unpack
->SkipPixels
& 0x7);
5286 GLubyte dstMask
= 128;
5287 const GLubyte
*s
= src
;
5290 for (i
= 0; i
< width
; i
++) {
5294 if (srcMask
== 128) {
5299 srcMask
= srcMask
<< 1;
5307 dstMask
= dstMask
>> 1;
5312 GLubyte srcMask
= 128 >> (unpack
->SkipPixels
& 0x7);
5313 GLubyte dstMask
= 128;
5314 const GLubyte
*s
= src
;
5317 for (i
= 0; i
< width
; i
++) {
5326 srcMask
= srcMask
>> 1;
5334 dstMask
= dstMask
>> 1;
5340 memcpy(dst
, src
, bytesPerRow
);
5343 /* byte flipping/swapping */
5345 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
5348 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
5351 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
5360 #endif /* _HAVE_FULL_GL */
5365 * Convert an array of RGBA colors from one datatype to another.
5366 * NOTE: src may equal dst. In that case, we use a temporary buffer.
5369 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
5370 GLenum dstType
, GLvoid
*dst
,
5371 GLuint count
, const GLubyte mask
[])
5373 GLuint tempBuffer
[MAX_WIDTH
][4];
5374 const GLboolean useTemp
= (src
== dst
);
5376 ASSERT(srcType
!= dstType
);
5379 case GL_UNSIGNED_BYTE
:
5380 if (dstType
== GL_UNSIGNED_SHORT
) {
5381 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5382 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5384 for (i
= 0; i
< count
; i
++) {
5385 if (!mask
|| mask
[i
]) {
5386 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
5387 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
5388 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
5389 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
5393 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5396 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
5397 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5399 ASSERT(dstType
== GL_FLOAT
);
5400 for (i
= 0; i
< count
; i
++) {
5401 if (!mask
|| mask
[i
]) {
5402 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
5403 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
5404 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
5405 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
5409 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5412 case GL_UNSIGNED_SHORT
:
5413 if (dstType
== GL_UNSIGNED_BYTE
) {
5414 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5415 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5417 for (i
= 0; i
< count
; i
++) {
5418 if (!mask
|| mask
[i
]) {
5419 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
5420 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
5421 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
5422 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
5426 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5429 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
5430 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
5432 ASSERT(dstType
== GL_FLOAT
);
5433 for (i
= 0; i
< count
; i
++) {
5434 if (!mask
|| mask
[i
]) {
5435 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
5436 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
5437 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
5438 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
5442 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
5446 if (dstType
== GL_UNSIGNED_BYTE
) {
5447 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5448 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
5450 for (i
= 0; i
< count
; i
++) {
5451 if (!mask
|| mask
[i
]) {
5452 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
5453 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
5454 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
5455 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
5459 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
5462 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
5463 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
5465 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
5466 for (i
= 0; i
< count
; i
++) {
5467 if (!mask
|| mask
[i
]) {
5468 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
5469 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
5470 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
5471 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
5475 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
5479 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
5487 * Perform basic clipping for glDrawPixels. The image's position and size
5488 * and the unpack SkipPixels and SkipRows are adjusted so that the image
5489 * region is entirely within the window and scissor bounds.
5490 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
5491 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
5492 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
5494 * \return GL_TRUE if image is ready for drawing or
5495 * GL_FALSE if image was completely clipped away (draw nothing)
5498 _mesa_clip_drawpixels(const GLcontext
*ctx
,
5499 GLint
*destX
, GLint
*destY
,
5500 GLsizei
*width
, GLsizei
*height
,
5501 struct gl_pixelstore_attrib
*unpack
)
5503 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
5505 if (unpack
->RowLength
== 0) {
5506 unpack
->RowLength
= *width
;
5509 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
5510 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
5513 if (*destX
< buffer
->_Xmin
) {
5514 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
5515 *width
-= (buffer
->_Xmin
- *destX
);
5516 *destX
= buffer
->_Xmin
;
5518 /* right clipping */
5519 if (*destX
+ *width
> buffer
->_Xmax
)
5520 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
5525 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
5526 /* bottom clipping */
5527 if (*destY
< buffer
->_Ymin
) {
5528 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
5529 *height
-= (buffer
->_Ymin
- *destY
);
5530 *destY
= buffer
->_Ymin
;
5533 if (*destY
+ *height
> buffer
->_Ymax
)
5534 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
5536 else { /* upside down */
5538 if (*destY
> buffer
->_Ymax
) {
5539 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
5540 *height
-= (*destY
- buffer
->_Ymax
);
5541 *destY
= buffer
->_Ymax
;
5543 /* bottom clipping */
5544 if (*destY
- *height
< buffer
->_Ymin
)
5545 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
5546 /* adjust destY so it's the first row to write to */
5558 * Perform clipping for glReadPixels. The image's window position
5559 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
5560 * so that the image region is entirely within the window bounds.
5561 * Note: this is different from _mesa_clip_drawpixels() in that the
5562 * scissor box is ignored, and we use the bounds of the current readbuffer
5565 * \return GL_TRUE if image is ready for drawing or
5566 * GL_FALSE if image was completely clipped away (draw nothing)
5569 _mesa_clip_readpixels(const GLcontext
*ctx
,
5570 GLint
*srcX
, GLint
*srcY
,
5571 GLsizei
*width
, GLsizei
*height
,
5572 struct gl_pixelstore_attrib
*pack
)
5574 const GLframebuffer
*buffer
= ctx
->ReadBuffer
;
5576 if (pack
->RowLength
== 0) {
5577 pack
->RowLength
= *width
;
5582 pack
->SkipPixels
+= (0 - *srcX
);
5583 *width
-= (0 - *srcX
);
5586 /* right clipping */
5587 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
5588 *width
-= (*srcX
+ *width
- buffer
->Width
);
5593 /* bottom clipping */
5595 pack
->SkipRows
+= (0 - *srcY
);
5596 *height
-= (0 - *srcY
);
5600 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
5601 *height
-= (*srcY
+ *height
- buffer
->Height
);
5611 * Do clipping for a glCopyTexSubImage call.
5612 * The framebuffer source region might extend outside the framebuffer
5613 * bounds. Clip the source region against the framebuffer bounds and
5614 * adjust the texture/dest position and size accordingly.
5616 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
5619 _mesa_clip_copytexsubimage(const GLcontext
*ctx
,
5620 GLint
*destX
, GLint
*destY
,
5621 GLint
*srcX
, GLint
*srcY
,
5622 GLsizei
*width
, GLsizei
*height
)
5624 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
5625 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
5627 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
5628 srcX
, srcY
, width
, height
)) {
5629 *destX
= *destX
+ *srcX
- srcX0
;
5630 *destY
= *destY
+ *srcY
- srcY0
;
5642 * Clip the rectangle defined by (x, y, width, height) against the bounds
5643 * specified by [xmin, xmax) and [ymin, ymax).
5644 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
5647 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
5648 GLint xmax
, GLint ymax
,
5650 GLsizei
*width
, GLsizei
*height
)
5654 *width
-= (xmin
- *x
);
5658 /* right clipping */
5659 if (*x
+ *width
> xmax
)
5660 *width
-= (*x
+ *width
- xmax
);
5665 /* bottom (or top) clipping */
5667 *height
-= (ymin
- *y
);
5671 /* top (or bottom) clipping */
5672 if (*y
+ *height
> ymax
)
5673 *height
-= (*y
+ *height
- ymax
);
5683 * Clip dst coords against Xmax (or Ymax).
5686 clip_right_or_top(GLint
*srcX0
, GLint
*srcX1
,
5687 GLint
*dstX0
, GLint
*dstX1
,
5692 if (*dstX1
> maxValue
) {
5693 /* X1 outside right edge */
5694 ASSERT(*dstX0
< maxValue
); /* X0 should be inside right edge */
5695 t
= (GLfloat
) (maxValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
5696 /* chop off [t, 1] part */
5697 ASSERT(t
>= 0.0 && t
<= 1.0);
5699 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
5700 *srcX1
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
5702 else if (*dstX0
> maxValue
) {
5703 /* X0 outside right edge */
5704 ASSERT(*dstX1
< maxValue
); /* X1 should be inside right edge */
5705 t
= (GLfloat
) (maxValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
5706 /* chop off [t, 1] part */
5707 ASSERT(t
>= 0.0 && t
<= 1.0);
5709 bias
= (*srcX0
< *srcX1
) ? -0.5F
: 0.5F
;
5710 *srcX0
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
5716 * Clip dst coords against Xmin (or Ymin).
5719 clip_left_or_bottom(GLint
*srcX0
, GLint
*srcX1
,
5720 GLint
*dstX0
, GLint
*dstX1
,
5725 if (*dstX0
< minValue
) {
5726 /* X0 outside left edge */
5727 ASSERT(*dstX1
> minValue
); /* X1 should be inside left edge */
5728 t
= (GLfloat
) (minValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
5729 /* chop off [0, t] part */
5730 ASSERT(t
>= 0.0 && t
<= 1.0);
5732 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
; /* flipped??? */
5733 *srcX0
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
5735 else if (*dstX1
< minValue
) {
5736 /* X1 outside left edge */
5737 ASSERT(*dstX0
> minValue
); /* X0 should be inside left edge */
5738 t
= (GLfloat
) (minValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
5739 /* chop off [0, t] part */
5740 ASSERT(t
>= 0.0 && t
<= 1.0);
5742 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
5743 *srcX1
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
5749 * Do clipping of blit src/dest rectangles.
5750 * The dest rect is clipped against both the buffer bounds and scissor bounds.
5751 * The src rect is just clipped against the buffer bounds.
5753 * When either the src or dest rect is clipped, the other is also clipped
5756 * Note that X0 need not be less than X1 (same for Y) for either the source
5757 * and dest rects. That makes the clipping a little trickier.
5759 * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
5762 _mesa_clip_blit(GLcontext
*ctx
,
5763 GLint
*srcX0
, GLint
*srcY0
, GLint
*srcX1
, GLint
*srcY1
,
5764 GLint
*dstX0
, GLint
*dstY0
, GLint
*dstX1
, GLint
*dstY1
)
5766 const GLint srcXmin
= 0;
5767 const GLint srcXmax
= ctx
->ReadBuffer
->Width
;
5768 const GLint srcYmin
= 0;
5769 const GLint srcYmax
= ctx
->ReadBuffer
->Height
;
5771 /* these include scissor bounds */
5772 const GLint dstXmin
= ctx
->DrawBuffer
->_Xmin
;
5773 const GLint dstXmax
= ctx
->DrawBuffer
->_Xmax
;
5774 const GLint dstYmin
= ctx
->DrawBuffer
->_Ymin
;
5775 const GLint dstYmax
= ctx
->DrawBuffer
->_Ymax
;
5778 printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
5779 *srcX0, *srcX1, *dstX0, *dstX1);
5780 printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
5781 *srcY0, *srcY1, *dstY0, *dstY1);
5784 /* trivial rejection tests */
5785 if (*dstX0
== *dstX1
)
5786 return GL_FALSE
; /* no width */
5787 if (*dstX0
<= dstXmin
&& *dstX1
<= dstXmin
)
5788 return GL_FALSE
; /* totally out (left) of bounds */
5789 if (*dstX0
>= dstXmax
&& *dstX1
>= dstXmax
)
5790 return GL_FALSE
; /* totally out (right) of bounds */
5792 if (*dstY0
== *dstY1
)
5794 if (*dstY0
<= dstYmin
&& *dstY1
<= dstYmin
)
5796 if (*dstY0
>= dstYmax
&& *dstY1
>= dstYmax
)
5799 if (*srcX0
== *srcX1
)
5801 if (*srcX0
<= srcXmin
&& *srcX1
<= srcXmin
)
5803 if (*srcX0
>= srcXmax
&& *srcX1
>= srcXmax
)
5806 if (*srcY0
== *srcY1
)
5808 if (*srcY0
<= srcYmin
&& *srcY1
<= srcYmin
)
5810 if (*srcY0
>= srcYmax
&& *srcY1
>= srcYmax
)
5816 clip_right_or_top(srcX0
, srcX1
, dstX0
, dstX1
, dstXmax
);
5817 clip_right_or_top(srcY0
, srcY1
, dstY0
, dstY1
, dstYmax
);
5818 clip_left_or_bottom(srcX0
, srcX1
, dstX0
, dstX1
, dstXmin
);
5819 clip_left_or_bottom(srcY0
, srcY1
, dstY0
, dstY1
, dstYmin
);
5822 * src clip (just swap src/dst values from above)
5824 clip_right_or_top(dstX0
, dstX1
, srcX0
, srcX1
, srcXmax
);
5825 clip_right_or_top(dstY0
, dstY1
, srcY0
, srcY1
, srcYmax
);
5826 clip_left_or_bottom(dstX0
, dstX1
, srcX0
, srcX1
, srcXmin
);
5827 clip_left_or_bottom(dstY0
, dstY1
, srcY0
, srcY1
, srcYmin
);
5830 printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
5831 *srcX0, *srcX1, *dstX0, *dstX1);
5832 printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
5833 *srcY0, *srcY1, *dstY0, *dstY1);
5836 ASSERT(*dstX0
>= dstXmin
);
5837 ASSERT(*dstX0
<= dstXmax
);
5838 ASSERT(*dstX1
>= dstXmin
);
5839 ASSERT(*dstX1
<= dstXmax
);
5841 ASSERT(*dstY0
>= dstYmin
);
5842 ASSERT(*dstY0
<= dstYmax
);
5843 ASSERT(*dstY1
>= dstYmin
);
5844 ASSERT(*dstY1
<= dstYmax
);
5846 ASSERT(*srcX0
>= srcXmin
);
5847 ASSERT(*srcX0
<= srcXmax
);
5848 ASSERT(*srcX1
>= srcXmin
);
5849 ASSERT(*srcX1
<= srcXmax
);
5851 ASSERT(*srcY0
>= srcYmin
);
5852 ASSERT(*srcY0
<= srcYmax
);
5853 ASSERT(*srcY1
>= srcYmin
);
5854 ASSERT(*srcY1
<= srcYmax
);