2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
44 * we later convert the float to a packed integer value (such as for
45 * GL_RGB5_A1) because we'll wind up with a non-zero value.
47 * We redefine the macros here so zero is handled correctly.
50 #define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
53 #define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
57 /** Compute ceiling of integer quotient of A divided by B. */
58 #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
62 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
65 _mesa_type_is_packed(GLenum type
)
68 case GL_UNSIGNED_BYTE_3_3_2
:
69 case GL_UNSIGNED_BYTE_2_3_3_REV
:
70 case GL_UNSIGNED_SHORT_5_6_5
:
71 case GL_UNSIGNED_SHORT_5_6_5_REV
:
72 case GL_UNSIGNED_SHORT_4_4_4_4
:
73 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
74 case GL_UNSIGNED_SHORT_5_5_5_1
:
75 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
76 case GL_UNSIGNED_INT_8_8_8_8
:
77 case GL_UNSIGNED_INT_8_8_8_8_REV
:
78 case GL_UNSIGNED_INT_10_10_10_2
:
79 case GL_UNSIGNED_INT_2_10_10_10_REV
:
80 case GL_UNSIGNED_SHORT_8_8_MESA
:
81 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
82 case GL_UNSIGNED_INT_24_8_EXT
:
90 * Flip the 8 bits in each byte of the given array.
93 * \param n number of bytes.
95 * \todo try this trick to flip bytes someday:
97 * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555);
98 * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333);
99 * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f);
103 flip_bytes( GLubyte
*p
, GLuint n
)
106 for (i
= 0; i
< n
; i
++) {
107 b
= (GLuint
) p
[i
]; /* words are often faster than bytes */
108 a
= ((b
& 0x01) << 7) |
122 * Flip the order of the 2 bytes in each word in the given array.
125 * \param n number of words.
128 _mesa_swap2( GLushort
*p
, GLuint n
)
131 for (i
= 0; i
< n
; i
++) {
132 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
139 * Flip the order of the 4 bytes in each word in the given array.
142 _mesa_swap4( GLuint
*p
, GLuint n
)
145 for (i
= 0; i
< n
; i
++) {
148 | ((b
>> 8) & 0xff00)
149 | ((b
<< 8) & 0xff0000)
150 | ((b
<< 24) & 0xff000000);
157 * Get the size of a GL data type.
159 * \param type GL data type.
161 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
162 * if an invalid type enum.
165 _mesa_sizeof_type( GLenum type
)
170 case GL_UNSIGNED_BYTE
:
171 return sizeof(GLubyte
);
173 return sizeof(GLbyte
);
174 case GL_UNSIGNED_SHORT
:
175 return sizeof(GLushort
);
177 return sizeof(GLshort
);
178 case GL_UNSIGNED_INT
:
179 return sizeof(GLuint
);
181 return sizeof(GLint
);
183 return sizeof(GLfloat
);
184 case GL_HALF_FLOAT_ARB
:
185 return sizeof(GLhalfARB
);
193 * Same as _mesa_sizeof_type() but also accepting the packed pixel
197 _mesa_sizeof_packed_type( GLenum type
)
202 case GL_UNSIGNED_BYTE
:
203 return sizeof(GLubyte
);
205 return sizeof(GLbyte
);
206 case GL_UNSIGNED_SHORT
:
207 return sizeof(GLushort
);
209 return sizeof(GLshort
);
210 case GL_UNSIGNED_INT
:
211 return sizeof(GLuint
);
213 return sizeof(GLint
);
214 case GL_HALF_FLOAT_ARB
:
215 return sizeof(GLhalfARB
);
217 return sizeof(GLfloat
);
218 case GL_UNSIGNED_BYTE_3_3_2
:
219 return sizeof(GLubyte
);
220 case GL_UNSIGNED_BYTE_2_3_3_REV
:
221 return sizeof(GLubyte
);
222 case GL_UNSIGNED_SHORT_5_6_5
:
223 return sizeof(GLushort
);
224 case GL_UNSIGNED_SHORT_5_6_5_REV
:
225 return sizeof(GLushort
);
226 case GL_UNSIGNED_SHORT_4_4_4_4
:
227 return sizeof(GLushort
);
228 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
229 return sizeof(GLushort
);
230 case GL_UNSIGNED_SHORT_5_5_5_1
:
231 return sizeof(GLushort
);
232 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
233 return sizeof(GLushort
);
234 case GL_UNSIGNED_INT_8_8_8_8
:
235 return sizeof(GLuint
);
236 case GL_UNSIGNED_INT_8_8_8_8_REV
:
237 return sizeof(GLuint
);
238 case GL_UNSIGNED_INT_10_10_10_2
:
239 return sizeof(GLuint
);
240 case GL_UNSIGNED_INT_2_10_10_10_REV
:
241 return sizeof(GLuint
);
242 case GL_UNSIGNED_SHORT_8_8_MESA
:
243 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
244 return sizeof(GLushort
);
245 case GL_UNSIGNED_INT_24_8_EXT
:
246 return sizeof(GLuint
);
254 * Get the number of components in a pixel format.
256 * \param format pixel format.
258 * \return the number of components in the given format, or -1 if a bad format.
261 _mesa_components_in_format( GLenum format
)
265 case GL_COLOR_INDEX1_EXT
:
266 case GL_COLOR_INDEX2_EXT
:
267 case GL_COLOR_INDEX4_EXT
:
268 case GL_COLOR_INDEX8_EXT
:
269 case GL_COLOR_INDEX12_EXT
:
270 case GL_COLOR_INDEX16_EXT
:
271 case GL_STENCIL_INDEX
:
272 case GL_DEPTH_COMPONENT
:
280 case GL_LUMINANCE_ALPHA
:
294 case GL_DEPTH_STENCIL_EXT
:
303 * Get the bytes per pixel of pixel format type pair.
305 * \param format pixel format.
306 * \param type pixel type.
308 * \return bytes per pixel, or -1 if a bad format or type was given.
311 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
313 GLint comps
= _mesa_components_in_format( format
);
319 return 0; /* special case */
321 case GL_UNSIGNED_BYTE
:
322 return comps
* sizeof(GLubyte
);
324 case GL_UNSIGNED_SHORT
:
325 return comps
* sizeof(GLshort
);
327 case GL_UNSIGNED_INT
:
328 return comps
* sizeof(GLint
);
330 return comps
* sizeof(GLfloat
);
331 case GL_HALF_FLOAT_ARB
:
332 return comps
* sizeof(GLhalfARB
);
333 case GL_UNSIGNED_BYTE_3_3_2
:
334 case GL_UNSIGNED_BYTE_2_3_3_REV
:
335 if (format
== GL_RGB
|| format
== GL_BGR
)
336 return sizeof(GLubyte
);
338 return -1; /* error */
339 case GL_UNSIGNED_SHORT_5_6_5
:
340 case GL_UNSIGNED_SHORT_5_6_5_REV
:
341 if (format
== GL_RGB
|| format
== GL_BGR
)
342 return sizeof(GLushort
);
344 return -1; /* error */
345 case GL_UNSIGNED_SHORT_4_4_4_4
:
346 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
347 case GL_UNSIGNED_SHORT_5_5_5_1
:
348 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
349 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
350 return sizeof(GLushort
);
353 case GL_UNSIGNED_INT_8_8_8_8
:
354 case GL_UNSIGNED_INT_8_8_8_8_REV
:
355 case GL_UNSIGNED_INT_10_10_10_2
:
356 case GL_UNSIGNED_INT_2_10_10_10_REV
:
357 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
358 return sizeof(GLuint
);
361 case GL_UNSIGNED_SHORT_8_8_MESA
:
362 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
363 if (format
== GL_YCBCR_MESA
)
364 return sizeof(GLushort
);
367 case GL_UNSIGNED_INT_24_8_EXT
:
368 if (format
== GL_DEPTH_STENCIL_EXT
)
369 return sizeof(GLuint
);
379 * Test for a legal pixel format and type.
381 * \param format pixel format.
382 * \param type pixel type.
384 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
388 _mesa_is_legal_format_and_type( GLcontext
*ctx
, GLenum format
, GLenum type
)
392 case GL_STENCIL_INDEX
:
396 case GL_UNSIGNED_BYTE
:
398 case GL_UNSIGNED_SHORT
:
400 case GL_UNSIGNED_INT
:
403 case GL_HALF_FLOAT_ARB
:
404 return ctx
->Extensions
.ARB_half_float_pixel
;
412 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
416 case GL_LUMINANCE_ALPHA
:
417 case GL_DEPTH_COMPONENT
:
420 case GL_UNSIGNED_BYTE
:
422 case GL_UNSIGNED_SHORT
:
424 case GL_UNSIGNED_INT
:
427 case GL_HALF_FLOAT_ARB
:
428 return ctx
->Extensions
.ARB_half_float_pixel
;
435 case GL_UNSIGNED_BYTE
:
437 case GL_UNSIGNED_SHORT
:
439 case GL_UNSIGNED_INT
:
441 case GL_UNSIGNED_BYTE_3_3_2
:
442 case GL_UNSIGNED_BYTE_2_3_3_REV
:
443 case GL_UNSIGNED_SHORT_5_6_5
:
444 case GL_UNSIGNED_SHORT_5_6_5_REV
:
446 case GL_HALF_FLOAT_ARB
:
447 return ctx
->Extensions
.ARB_half_float_pixel
;
453 /* NOTE: no packed types are supported with BGR. That's
454 * intentional, according to the GL spec.
457 case GL_UNSIGNED_BYTE
:
459 case GL_UNSIGNED_SHORT
:
461 case GL_UNSIGNED_INT
:
464 case GL_HALF_FLOAT_ARB
:
465 return ctx
->Extensions
.ARB_half_float_pixel
;
474 case GL_UNSIGNED_BYTE
:
476 case GL_UNSIGNED_SHORT
:
478 case GL_UNSIGNED_INT
:
480 case GL_UNSIGNED_SHORT_4_4_4_4
:
481 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
482 case GL_UNSIGNED_SHORT_5_5_5_1
:
483 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
484 case GL_UNSIGNED_INT_8_8_8_8
:
485 case GL_UNSIGNED_INT_8_8_8_8_REV
:
486 case GL_UNSIGNED_INT_10_10_10_2
:
487 case GL_UNSIGNED_INT_2_10_10_10_REV
:
489 case GL_HALF_FLOAT_ARB
:
490 return ctx
->Extensions
.ARB_half_float_pixel
;
495 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
496 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
500 case GL_DEPTH_STENCIL_EXT
:
501 if (ctx
->Extensions
.EXT_packed_depth_stencil
502 && type
== GL_UNSIGNED_INT_24_8_EXT
)
514 * Return the address of a specific pixel in an image (1D, 2D or 3D).
516 * Pixel unpacking/packing parameters are observed according to \p packing.
518 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
519 * \param image starting address of image data
520 * \param width the image width
521 * \param height theimage height
522 * \param format the pixel format
523 * \param type the pixel data type
524 * \param packing the pixelstore attributes
525 * \param img which image in the volume (0 for 1D or 2D images)
526 * \param row row of pixel in the image (0 for 1D images)
527 * \param column column of pixel in the image
529 * \return address of pixel on success, or NULL on error.
531 * \sa gl_pixelstore_attrib.
534 _mesa_image_address( GLuint dimensions
,
535 const struct gl_pixelstore_attrib
*packing
,
537 GLsizei width
, GLsizei height
,
538 GLenum format
, GLenum type
,
539 GLint img
, GLint row
, GLint column
)
541 GLint alignment
; /* 1, 2 or 4 */
542 GLint pixels_per_row
;
543 GLint rows_per_image
;
546 GLint skipimages
; /* for 3-D volume images */
549 ASSERT(dimensions
>= 1 && dimensions
<= 3);
551 alignment
= packing
->Alignment
;
552 if (packing
->RowLength
> 0) {
553 pixels_per_row
= packing
->RowLength
;
556 pixels_per_row
= width
;
558 if (packing
->ImageHeight
> 0) {
559 rows_per_image
= packing
->ImageHeight
;
562 rows_per_image
= height
;
565 skippixels
= packing
->SkipPixels
;
566 /* Note: SKIP_ROWS _is_ used for 1D images */
567 skiprows
= packing
->SkipRows
;
568 /* Note: SKIP_IMAGES is only used for 3D images */
569 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
571 if (type
== GL_BITMAP
) {
573 GLint comp_per_pixel
; /* components per pixel */
574 GLint bytes_per_comp
; /* bytes per component */
576 GLint bytes_per_image
;
578 /* Compute bytes per component */
579 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
580 if (bytes_per_comp
< 0) {
584 /* Compute number of components per pixel */
585 comp_per_pixel
= _mesa_components_in_format( format
);
586 if (comp_per_pixel
< 0) {
590 bytes_per_row
= alignment
591 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
593 bytes_per_image
= bytes_per_row
* rows_per_image
;
595 pixel_addr
= (GLubyte
*) image
596 + (skipimages
+ img
) * bytes_per_image
597 + (skiprows
+ row
) * bytes_per_row
598 + (skippixels
+ column
) / 8;
601 /* Non-BITMAP data */
602 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
605 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
607 /* The pixel type and format should have been error checked earlier */
608 assert(bytes_per_pixel
> 0);
610 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
611 remainder
= bytes_per_row
% alignment
;
613 bytes_per_row
+= (alignment
- remainder
);
615 ASSERT(bytes_per_row
% alignment
== 0);
617 bytes_per_image
= bytes_per_row
* rows_per_image
;
619 if (packing
->Invert
) {
620 /* set pixel_addr to the last row */
621 topOfImage
= bytes_per_row
* (height
- 1);
622 bytes_per_row
= -bytes_per_row
;
628 /* compute final pixel address */
629 pixel_addr
= (GLubyte
*) image
630 + (skipimages
+ img
) * bytes_per_image
632 + (skiprows
+ row
) * bytes_per_row
633 + (skippixels
+ column
) * bytes_per_pixel
;
636 return (GLvoid
*) pixel_addr
;
641 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
644 GLenum format
, GLenum type
,
647 return _mesa_image_address(1, packing
, image
, width
, 1,
648 format
, type
, 0, 0, column
);
653 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
655 GLsizei width
, GLsizei height
,
656 GLenum format
, GLenum type
,
657 GLint row
, GLint column
)
659 return _mesa_image_address(2, packing
, image
, width
, height
,
660 format
, type
, 0, row
, column
);
665 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
667 GLsizei width
, GLsizei height
,
668 GLenum format
, GLenum type
,
669 GLint img
, GLint row
, GLint column
)
671 return _mesa_image_address(3, packing
, image
, width
, height
,
672 format
, type
, img
, row
, column
);
678 * Compute the stride (in bytes) between image rows.
680 * \param packing the pixelstore attributes
681 * \param width image width.
682 * \param format pixel format.
683 * \param type pixel data type.
685 * \return the stride in bytes for the given parameters, or -1 if error
688 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
689 GLint width
, GLenum format
, GLenum type
)
691 GLint bytesPerRow
, remainder
;
695 if (type
== GL_BITMAP
) {
696 if (packing
->RowLength
== 0) {
697 bytesPerRow
= (width
+ 7) / 8;
700 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
704 /* Non-BITMAP data */
705 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
706 if (bytesPerPixel
<= 0)
707 return -1; /* error */
708 if (packing
->RowLength
== 0) {
709 bytesPerRow
= bytesPerPixel
* width
;
712 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
716 remainder
= bytesPerRow
% packing
->Alignment
;
718 bytesPerRow
+= (packing
->Alignment
- remainder
);
721 if (packing
->Invert
) {
722 /* negate the bytes per row (negative row stride) */
723 bytesPerRow
= -bytesPerRow
;
733 * Compute the stride between images in a 3D texture (in bytes) for the given
734 * pixel packing parameters and image width, format and type.
737 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
738 GLint width
, GLint height
,
739 GLenum format
, GLenum type
)
742 ASSERT(type
!= GL_BITMAP
);
745 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
746 GLint bytesPerRow
, bytesPerImage
, remainder
;
748 if (bytesPerPixel
<= 0)
749 return -1; /* error */
750 if (packing
->RowLength
== 0) {
751 bytesPerRow
= bytesPerPixel
* width
;
754 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
756 remainder
= bytesPerRow
% packing
->Alignment
;
758 bytesPerRow
+= (packing
->Alignment
- remainder
);
760 if (packing
->ImageHeight
== 0)
761 bytesPerImage
= bytesPerRow
* height
;
763 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
765 return bytesPerImage
;
771 * Unpack a 32x32 pixel polygon stipple from user memory using the
772 * current pixel unpack settings.
775 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
776 const struct gl_pixelstore_attrib
*unpacking
)
778 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap(32, 32, pattern
, unpacking
);
780 /* Convert pattern from GLubytes to GLuints and handle big/little
785 for (i
= 0; i
< 32; i
++) {
786 dest
[i
] = (p
[0] << 24)
798 * Pack polygon stipple into user memory given current pixel packing
802 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
803 const struct gl_pixelstore_attrib
*packing
)
805 /* Convert pattern from GLuints to GLubytes to handle big/little
806 * endian differences.
810 for (i
= 0; i
< 32; i
++) {
811 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
812 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
813 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
814 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
817 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
822 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
823 * order with row alignment = 1 byte.
826 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
827 const struct gl_pixelstore_attrib
*packing
)
829 GLint bytes
, row
, width_in_bytes
;
830 GLubyte
*buffer
, *dst
;
835 /* Alloc dest storage */
836 bytes
= ((width
+ 7) / 8 * height
);
837 buffer
= (GLubyte
*) _mesa_malloc( bytes
);
841 width_in_bytes
= CEILING( width
, 8 );
843 for (row
= 0; row
< height
; row
++) {
844 const GLubyte
*src
= (const GLubyte
*)
845 _mesa_image_address2d(packing
, pixels
, width
, height
,
846 GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
852 if ((packing
->SkipPixels
& 7) == 0) {
853 _mesa_memcpy( dst
, src
, width_in_bytes
);
854 if (packing
->LsbFirst
) {
855 flip_bytes( dst
, width_in_bytes
);
859 /* handling SkipPixels is a bit tricky (no pun intended!) */
861 if (packing
->LsbFirst
) {
862 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
863 GLubyte dstMask
= 128;
864 const GLubyte
*s
= src
;
867 for (i
= 0; i
< width
; i
++) {
871 if (srcMask
== 128) {
876 srcMask
= srcMask
<< 1;
884 dstMask
= dstMask
>> 1;
889 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
890 GLubyte dstMask
= 128;
891 const GLubyte
*s
= src
;
894 for (i
= 0; i
< width
; i
++) {
903 srcMask
= srcMask
>> 1;
911 dstMask
= dstMask
>> 1;
916 dst
+= width_in_bytes
;
927 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
928 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
930 GLint row
, width_in_bytes
;
936 width_in_bytes
= CEILING( width
, 8 );
938 for (row
= 0; row
< height
; row
++) {
939 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dest
,
940 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
944 if ((packing
->SkipPixels
& 7) == 0) {
945 _mesa_memcpy( dst
, src
, width_in_bytes
);
946 if (packing
->LsbFirst
) {
947 flip_bytes( dst
, width_in_bytes
);
951 /* handling SkipPixels is a bit tricky (no pun intended!) */
953 if (packing
->LsbFirst
) {
954 GLubyte srcMask
= 128;
955 GLubyte dstMask
= 1 << (packing
->SkipPixels
& 0x7);
956 const GLubyte
*s
= src
;
959 for (i
= 0; i
< width
; i
++) {
968 srcMask
= srcMask
>> 1;
970 if (dstMask
== 128) {
976 dstMask
= dstMask
<< 1;
981 GLubyte srcMask
= 128;
982 GLubyte dstMask
= 128 >> (packing
->SkipPixels
& 0x7);
983 const GLubyte
*s
= src
;
986 for (i
= 0; i
< width
; i
++) {
995 srcMask
= srcMask
>> 1;
1003 dstMask
= dstMask
>> 1;
1008 src
+= width_in_bytes
;
1013 /**********************************************************************/
1014 /***** Pixel processing functions ******/
1015 /**********************************************************************/
1018 * Apply scale and bias factors to an array of RGBA pixels.
1021 _mesa_scale_and_bias_rgba(GLuint n
, GLfloat rgba
[][4],
1022 GLfloat rScale
, GLfloat gScale
,
1023 GLfloat bScale
, GLfloat aScale
,
1024 GLfloat rBias
, GLfloat gBias
,
1025 GLfloat bBias
, GLfloat aBias
)
1027 if (rScale
!= 1.0 || rBias
!= 0.0) {
1029 for (i
= 0; i
< n
; i
++) {
1030 rgba
[i
][RCOMP
] = rgba
[i
][RCOMP
] * rScale
+ rBias
;
1033 if (gScale
!= 1.0 || gBias
!= 0.0) {
1035 for (i
= 0; i
< n
; i
++) {
1036 rgba
[i
][GCOMP
] = rgba
[i
][GCOMP
] * gScale
+ gBias
;
1039 if (bScale
!= 1.0 || bBias
!= 0.0) {
1041 for (i
= 0; i
< n
; i
++) {
1042 rgba
[i
][BCOMP
] = rgba
[i
][BCOMP
] * bScale
+ bBias
;
1045 if (aScale
!= 1.0 || aBias
!= 0.0) {
1047 for (i
= 0; i
< n
; i
++) {
1048 rgba
[i
][ACOMP
] = rgba
[i
][ACOMP
] * aScale
+ aBias
;
1055 * Apply pixel mapping to an array of floating point RGBA pixels.
1058 _mesa_map_rgba( const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4] )
1060 const GLfloat rscale
= (GLfloat
) (ctx
->PixelMaps
.RtoR
.Size
- 1);
1061 const GLfloat gscale
= (GLfloat
) (ctx
->PixelMaps
.GtoG
.Size
- 1);
1062 const GLfloat bscale
= (GLfloat
) (ctx
->PixelMaps
.BtoB
.Size
- 1);
1063 const GLfloat ascale
= (GLfloat
) (ctx
->PixelMaps
.AtoA
.Size
- 1);
1064 const GLfloat
*rMap
= ctx
->PixelMaps
.RtoR
.Map
;
1065 const GLfloat
*gMap
= ctx
->PixelMaps
.GtoG
.Map
;
1066 const GLfloat
*bMap
= ctx
->PixelMaps
.BtoB
.Map
;
1067 const GLfloat
*aMap
= ctx
->PixelMaps
.AtoA
.Map
;
1070 GLfloat r
= CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1071 GLfloat g
= CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1072 GLfloat b
= CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1073 GLfloat a
= CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1074 rgba
[i
][RCOMP
] = rMap
[IROUND(r
* rscale
)];
1075 rgba
[i
][GCOMP
] = gMap
[IROUND(g
* gscale
)];
1076 rgba
[i
][BCOMP
] = bMap
[IROUND(b
* bscale
)];
1077 rgba
[i
][ACOMP
] = aMap
[IROUND(a
* ascale
)];
1083 * Apply the color matrix and post color matrix scaling and biasing.
1086 _mesa_transform_rgba(const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4])
1088 const GLfloat rs
= ctx
->Pixel
.PostColorMatrixScale
[0];
1089 const GLfloat rb
= ctx
->Pixel
.PostColorMatrixBias
[0];
1090 const GLfloat gs
= ctx
->Pixel
.PostColorMatrixScale
[1];
1091 const GLfloat gb
= ctx
->Pixel
.PostColorMatrixBias
[1];
1092 const GLfloat bs
= ctx
->Pixel
.PostColorMatrixScale
[2];
1093 const GLfloat bb
= ctx
->Pixel
.PostColorMatrixBias
[2];
1094 const GLfloat as
= ctx
->Pixel
.PostColorMatrixScale
[3];
1095 const GLfloat ab
= ctx
->Pixel
.PostColorMatrixBias
[3];
1096 const GLfloat
*m
= ctx
->ColorMatrixStack
.Top
->m
;
1098 for (i
= 0; i
< n
; i
++) {
1099 const GLfloat r
= rgba
[i
][RCOMP
];
1100 const GLfloat g
= rgba
[i
][GCOMP
];
1101 const GLfloat b
= rgba
[i
][BCOMP
];
1102 const GLfloat a
= rgba
[i
][ACOMP
];
1103 rgba
[i
][RCOMP
] = (m
[0] * r
+ m
[4] * g
+ m
[ 8] * b
+ m
[12] * a
) * rs
+ rb
;
1104 rgba
[i
][GCOMP
] = (m
[1] * r
+ m
[5] * g
+ m
[ 9] * b
+ m
[13] * a
) * gs
+ gb
;
1105 rgba
[i
][BCOMP
] = (m
[2] * r
+ m
[6] * g
+ m
[10] * b
+ m
[14] * a
) * bs
+ bb
;
1106 rgba
[i
][ACOMP
] = (m
[3] * r
+ m
[7] * g
+ m
[11] * b
+ m
[15] * a
) * as
+ ab
;
1112 * Apply a color table lookup to an array of floating point RGBA colors.
1115 _mesa_lookup_rgba_float(const struct gl_color_table
*table
,
1116 GLuint n
, GLfloat rgba
[][4])
1118 const GLint max
= table
->Size
- 1;
1119 const GLfloat scale
= (GLfloat
) max
;
1120 const GLfloat
*lut
= table
->TableF
;
1123 if (!table
->TableF
|| table
->Size
== 0)
1126 switch (table
->_BaseFormat
) {
1128 /* replace RGBA with I */
1129 for (i
= 0; i
< n
; i
++) {
1130 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1131 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1139 /* replace RGB with L */
1140 for (i
= 0; i
< n
; i
++) {
1141 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1142 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1149 /* replace A with A */
1150 for (i
= 0; i
< n
; i
++) {
1151 GLint j
= IROUND(rgba
[i
][ACOMP
] * scale
);
1152 rgba
[i
][ACOMP
] = lut
[CLAMP(j
, 0, max
)];
1155 case GL_LUMINANCE_ALPHA
:
1156 /* replace RGBA with LLLA */
1157 for (i
= 0; i
< n
; i
++) {
1158 GLint jL
= IROUND(rgba
[i
][RCOMP
] * scale
);
1159 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1160 GLfloat luminance
, alpha
;
1161 jL
= CLAMP(jL
, 0, max
);
1162 jA
= CLAMP(jA
, 0, max
);
1163 luminance
= lut
[jL
* 2 + 0];
1164 alpha
= lut
[jA
* 2 + 1];
1167 rgba
[i
][BCOMP
] = luminance
;
1168 rgba
[i
][ACOMP
] = alpha
;;
1172 /* replace RGB with RGB */
1173 for (i
= 0; i
< n
; i
++) {
1174 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1175 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1176 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1177 jR
= CLAMP(jR
, 0, max
);
1178 jG
= CLAMP(jG
, 0, max
);
1179 jB
= CLAMP(jB
, 0, max
);
1180 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1181 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1182 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1186 /* replace RGBA with RGBA */
1187 for (i
= 0; i
< n
; i
++) {
1188 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1189 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1190 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1191 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1192 jR
= CLAMP(jR
, 0, max
);
1193 jG
= CLAMP(jG
, 0, max
);
1194 jB
= CLAMP(jB
, 0, max
);
1195 jA
= CLAMP(jA
, 0, max
);
1196 rgba
[i
][RCOMP
] = lut
[jR
* 4 + 0];
1197 rgba
[i
][GCOMP
] = lut
[jG
* 4 + 1];
1198 rgba
[i
][BCOMP
] = lut
[jB
* 4 + 2];
1199 rgba
[i
][ACOMP
] = lut
[jA
* 4 + 3];
1203 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_float");
1211 * Apply a color table lookup to an array of ubyte/RGBA colors.
1214 _mesa_lookup_rgba_ubyte(const struct gl_color_table
*table
,
1215 GLuint n
, GLubyte rgba
[][4])
1217 const GLubyte
*lut
= table
->TableUB
;
1218 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / (GLfloat
)255.0;
1221 if (!table
->TableUB
|| table
->Size
== 0)
1224 switch (table
->_BaseFormat
) {
1226 /* replace RGBA with I */
1227 if (table
->Size
== 256) {
1228 for (i
= 0; i
< n
; i
++) {
1229 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1237 for (i
= 0; i
< n
; i
++) {
1238 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1242 rgba
[i
][ACOMP
] = lut
[j
];
1247 /* replace RGB with L */
1248 if (table
->Size
== 256) {
1249 for (i
= 0; i
< n
; i
++) {
1250 const GLubyte c
= lut
[rgba
[i
][RCOMP
]];
1257 for (i
= 0; i
< n
; i
++) {
1258 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1261 rgba
[i
][BCOMP
] = lut
[j
];
1266 /* replace A with A */
1267 if (table
->Size
== 256) {
1268 for (i
= 0; i
< n
; i
++) {
1269 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
]];
1273 for (i
= 0; i
< n
; i
++) {
1274 GLint j
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1275 rgba
[i
][ACOMP
] = lut
[j
];
1279 case GL_LUMINANCE_ALPHA
:
1280 /* replace RGBA with LLLA */
1281 if (table
->Size
== 256) {
1282 for (i
= 0; i
< n
; i
++) {
1283 GLubyte l
= lut
[rgba
[i
][RCOMP
] * 2 + 0];
1284 GLubyte a
= lut
[rgba
[i
][ACOMP
] * 2 + 1];;
1292 for (i
= 0; i
< n
; i
++) {
1293 GLint jL
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1294 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1295 GLubyte luminance
= lut
[jL
* 2 + 0];
1296 GLubyte alpha
= lut
[jA
* 2 + 1];
1299 rgba
[i
][BCOMP
] = luminance
;
1300 rgba
[i
][ACOMP
] = alpha
;
1305 if (table
->Size
== 256) {
1306 for (i
= 0; i
< n
; i
++) {
1307 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 3 + 0];
1308 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 3 + 1];
1309 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 3 + 2];
1313 for (i
= 0; i
< n
; i
++) {
1314 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1315 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1316 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1317 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1318 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1319 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1324 if (table
->Size
== 256) {
1325 for (i
= 0; i
< n
; i
++) {
1326 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 4 + 0];
1327 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 4 + 1];
1328 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 4 + 2];
1329 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
] * 4 + 3];
1333 for (i
= 0; i
< n
; i
++) {
1334 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1335 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1336 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1337 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1338 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][RCOMP
], lut
[jR
* 4 + 0]);
1339 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][GCOMP
], lut
[jG
* 4 + 1]);
1340 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][BCOMP
], lut
[jB
* 4 + 2]);
1341 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][ACOMP
], lut
[jA
* 4 + 3]);
1346 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_chan");
1354 * Map color indexes to float rgba values.
1357 _mesa_map_ci_to_rgba( const GLcontext
*ctx
, GLuint n
,
1358 const GLuint index
[], GLfloat rgba
[][4] )
1360 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1361 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1362 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1363 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1364 const GLfloat
*rMap
= ctx
->PixelMaps
.ItoR
.Map
;
1365 const GLfloat
*gMap
= ctx
->PixelMaps
.ItoG
.Map
;
1366 const GLfloat
*bMap
= ctx
->PixelMaps
.ItoB
.Map
;
1367 const GLfloat
*aMap
= ctx
->PixelMaps
.ItoA
.Map
;
1370 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1371 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1372 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1373 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1379 * Map ubyte color indexes to ubyte/RGBA values.
1382 _mesa_map_ci8_to_rgba8(const GLcontext
*ctx
, GLuint n
, const GLubyte index
[],
1385 GLuint rmask
= ctx
->PixelMaps
.ItoR
.Size
- 1;
1386 GLuint gmask
= ctx
->PixelMaps
.ItoG
.Size
- 1;
1387 GLuint bmask
= ctx
->PixelMaps
.ItoB
.Size
- 1;
1388 GLuint amask
= ctx
->PixelMaps
.ItoA
.Size
- 1;
1389 const GLubyte
*rMap
= ctx
->PixelMaps
.ItoR
.Map8
;
1390 const GLubyte
*gMap
= ctx
->PixelMaps
.ItoG
.Map8
;
1391 const GLubyte
*bMap
= ctx
->PixelMaps
.ItoB
.Map8
;
1392 const GLubyte
*aMap
= ctx
->PixelMaps
.ItoA
.Map8
;
1395 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1396 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1397 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1398 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1404 _mesa_scale_and_bias_depth(const GLcontext
*ctx
, GLuint n
,
1405 GLfloat depthValues
[])
1407 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
1408 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
1410 for (i
= 0; i
< n
; i
++) {
1411 GLfloat d
= depthValues
[i
] * scale
+ bias
;
1412 depthValues
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
1418 _mesa_scale_and_bias_depth_uint(const GLcontext
*ctx
, GLuint n
,
1419 GLuint depthValues
[])
1421 const GLdouble max
= (double) 0xffffffff;
1422 const GLdouble scale
= ctx
->Pixel
.DepthScale
;
1423 const GLdouble bias
= ctx
->Pixel
.DepthBias
* max
;
1425 for (i
= 0; i
< n
; i
++) {
1426 GLdouble d
= (GLdouble
) depthValues
[i
] * scale
+ bias
;
1427 d
= CLAMP(d
, 0.0, max
);
1428 depthValues
[i
] = (GLuint
) d
;
1435 * Update the min/max values from an array of fragment colors.
1438 update_minmax(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1441 for (i
= 0; i
< n
; i
++) {
1443 if (rgba
[i
][RCOMP
] < ctx
->MinMax
.Min
[RCOMP
])
1444 ctx
->MinMax
.Min
[RCOMP
] = rgba
[i
][RCOMP
];
1445 if (rgba
[i
][GCOMP
] < ctx
->MinMax
.Min
[GCOMP
])
1446 ctx
->MinMax
.Min
[GCOMP
] = rgba
[i
][GCOMP
];
1447 if (rgba
[i
][BCOMP
] < ctx
->MinMax
.Min
[BCOMP
])
1448 ctx
->MinMax
.Min
[BCOMP
] = rgba
[i
][BCOMP
];
1449 if (rgba
[i
][ACOMP
] < ctx
->MinMax
.Min
[ACOMP
])
1450 ctx
->MinMax
.Min
[ACOMP
] = rgba
[i
][ACOMP
];
1453 if (rgba
[i
][RCOMP
] > ctx
->MinMax
.Max
[RCOMP
])
1454 ctx
->MinMax
.Max
[RCOMP
] = rgba
[i
][RCOMP
];
1455 if (rgba
[i
][GCOMP
] > ctx
->MinMax
.Max
[GCOMP
])
1456 ctx
->MinMax
.Max
[GCOMP
] = rgba
[i
][GCOMP
];
1457 if (rgba
[i
][BCOMP
] > ctx
->MinMax
.Max
[BCOMP
])
1458 ctx
->MinMax
.Max
[BCOMP
] = rgba
[i
][BCOMP
];
1459 if (rgba
[i
][ACOMP
] > ctx
->MinMax
.Max
[ACOMP
])
1460 ctx
->MinMax
.Max
[ACOMP
] = rgba
[i
][ACOMP
];
1466 * Update the histogram values from an array of fragment colors.
1469 update_histogram(GLcontext
*ctx
, GLuint n
, const GLfloat rgba
[][4])
1471 const GLint max
= ctx
->Histogram
.Width
- 1;
1472 GLfloat w
= (GLfloat
) max
;
1475 if (ctx
->Histogram
.Width
== 0)
1478 for (i
= 0; i
< n
; i
++) {
1479 GLint ri
= IROUND(rgba
[i
][RCOMP
] * w
);
1480 GLint gi
= IROUND(rgba
[i
][GCOMP
] * w
);
1481 GLint bi
= IROUND(rgba
[i
][BCOMP
] * w
);
1482 GLint ai
= IROUND(rgba
[i
][ACOMP
] * w
);
1483 ri
= CLAMP(ri
, 0, max
);
1484 gi
= CLAMP(gi
, 0, max
);
1485 bi
= CLAMP(bi
, 0, max
);
1486 ai
= CLAMP(ai
, 0, max
);
1487 ctx
->Histogram
.Count
[ri
][RCOMP
]++;
1488 ctx
->Histogram
.Count
[gi
][GCOMP
]++;
1489 ctx
->Histogram
.Count
[bi
][BCOMP
]++;
1490 ctx
->Histogram
.Count
[ai
][ACOMP
]++;
1496 * Apply various pixel transfer operations to an array of RGBA pixels
1497 * as indicated by the transferOps bitmask
1500 _mesa_apply_rgba_transfer_ops(GLcontext
*ctx
, GLbitfield transferOps
,
1501 GLuint n
, GLfloat rgba
[][4])
1504 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
1505 _mesa_scale_and_bias_rgba(n
, rgba
,
1506 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
1507 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
1508 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
1509 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
1511 /* color map lookup */
1512 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1513 _mesa_map_rgba( ctx
, n
, rgba
);
1515 /* GL_COLOR_TABLE lookup */
1516 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
1517 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
], n
, rgba
);
1520 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
1521 /* this has to be done in the calling code */
1522 _mesa_problem(ctx
, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");
1524 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
1525 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
1526 _mesa_scale_and_bias_rgba(n
, rgba
,
1527 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
1528 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
1529 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
1530 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
1531 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
1532 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
1533 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
1534 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
1536 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
1537 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
1538 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
], n
, rgba
);
1540 /* color matrix transform */
1541 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
1542 _mesa_transform_rgba(ctx
, n
, rgba
);
1544 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
1545 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
1546 _mesa_lookup_rgba_float(&ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
], n
, rgba
);
1548 /* update histogram count */
1549 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
1550 update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1552 /* update min/max values */
1553 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
1554 update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1556 /* clamping to [0,1] */
1557 if (transferOps
& IMAGE_CLAMP_BIT
) {
1559 for (i
= 0; i
< n
; i
++) {
1560 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1561 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1562 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1563 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1570 * Apply color index shift and offset to an array of pixels.
1573 shift_and_offset_ci( const GLcontext
*ctx
, GLuint n
, GLuint indexes
[] )
1575 GLint shift
= ctx
->Pixel
.IndexShift
;
1576 GLint offset
= ctx
->Pixel
.IndexOffset
;
1580 indexes
[i
] = (indexes
[i
] << shift
) + offset
;
1583 else if (shift
< 0) {
1586 indexes
[i
] = (indexes
[i
] >> shift
) + offset
;
1591 indexes
[i
] = indexes
[i
] + offset
;
1599 * Apply color index shift, offset and table lookup to an array
1603 _mesa_apply_ci_transfer_ops(const GLcontext
*ctx
, GLbitfield transferOps
,
1604 GLuint n
, GLuint indexes
[])
1606 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
1607 shift_and_offset_ci(ctx
, n
, indexes
);
1609 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1610 const GLuint mask
= ctx
->PixelMaps
.ItoI
.Size
- 1;
1612 for (i
= 0; i
< n
; i
++) {
1613 const GLuint j
= indexes
[i
] & mask
;
1614 indexes
[i
] = IROUND(ctx
->PixelMaps
.ItoI
.Map
[j
]);
1621 * Apply stencil index shift, offset and table lookup to an array
1622 * of stencil values.
1625 _mesa_apply_stencil_transfer_ops(const GLcontext
*ctx
, GLuint n
,
1626 GLstencil stencil
[])
1628 if (ctx
->Pixel
.IndexShift
!= 0 || ctx
->Pixel
.IndexOffset
!= 0) {
1629 const GLint offset
= ctx
->Pixel
.IndexOffset
;
1630 GLint shift
= ctx
->Pixel
.IndexShift
;
1633 for (i
= 0; i
< n
; i
++) {
1634 stencil
[i
] = (stencil
[i
] << shift
) + offset
;
1637 else if (shift
< 0) {
1639 for (i
= 0; i
< n
; i
++) {
1640 stencil
[i
] = (stencil
[i
] >> shift
) + offset
;
1644 for (i
= 0; i
< n
; i
++) {
1645 stencil
[i
] = stencil
[i
] + offset
;
1649 if (ctx
->Pixel
.MapStencilFlag
) {
1650 GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
1652 for (i
= 0; i
< n
; i
++) {
1653 stencil
[i
] = ctx
->PixelMaps
.StoS
.Map
[ stencil
[i
] & mask
];
1660 * Used to pack an array [][4] of RGBA float colors as specified
1661 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
1662 * glGetConvolutionFilter(), etc.
1663 * Incoming colors will be clamped to [0,1] if needed.
1664 * Note: the rgba values will be modified by this function when any pixel
1665 * transfer ops are enabled.
1668 _mesa_pack_rgba_span_float(GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4],
1669 GLenum dstFormat
, GLenum dstType
,
1671 const struct gl_pixelstore_attrib
*dstPacking
,
1672 GLbitfield transferOps
)
1674 GLfloat luminance
[MAX_WIDTH
];
1675 const GLint comps
= _mesa_components_in_format(dstFormat
);
1678 if (dstType
!= GL_FLOAT
|| ctx
->Color
.ClampReadColor
== GL_TRUE
) {
1679 /* need to clamp to [0, 1] */
1680 transferOps
|= IMAGE_CLAMP_BIT
;
1684 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
1685 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
1690 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
1691 /* compute luminance values */
1692 if (dstType
!= GL_FLOAT
|| ctx
->Color
.ClampReadColor
== GL_TRUE
) {
1693 for (i
= 0; i
< n
; i
++) {
1694 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1695 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
1699 for (i
= 0; i
< n
; i
++) {
1700 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1706 * Pack/store the pixels. Ugh! Lots of cases!!!
1709 case GL_UNSIGNED_BYTE
:
1711 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1712 switch (dstFormat
) {
1715 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1719 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1723 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1727 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1731 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1733 case GL_LUMINANCE_ALPHA
:
1735 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1736 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1741 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1742 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1743 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1748 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1749 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1750 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1751 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1756 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1757 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1758 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1763 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1764 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1765 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1766 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1771 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1772 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1773 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1774 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1778 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1784 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1785 switch (dstFormat
) {
1788 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1792 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1796 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1800 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1804 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1806 case GL_LUMINANCE_ALPHA
:
1808 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1809 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1814 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1815 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1816 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1821 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1822 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1823 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1824 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1829 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1830 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1831 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1836 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1837 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1838 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1839 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1844 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1845 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1846 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1847 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1851 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1855 case GL_UNSIGNED_SHORT
:
1857 GLushort
*dst
= (GLushort
*) dstAddr
;
1858 switch (dstFormat
) {
1861 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][RCOMP
]);
1865 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][GCOMP
]);
1869 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][BCOMP
]);
1873 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][ACOMP
]);
1877 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
], luminance
[i
]);
1879 case GL_LUMINANCE_ALPHA
:
1881 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
*2+0], luminance
[i
]);
1882 CLAMPED_FLOAT_TO_USHORT(dst
[i
*2+1], rgba
[i
][ACOMP
]);
1887 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][RCOMP
]);
1888 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1889 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][BCOMP
]);
1894 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][RCOMP
]);
1895 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1896 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][BCOMP
]);
1897 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1902 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][BCOMP
]);
1903 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1904 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][RCOMP
]);
1909 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][BCOMP
]);
1910 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1911 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][RCOMP
]);
1912 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1917 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][ACOMP
]);
1918 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][BCOMP
]);
1919 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][GCOMP
]);
1920 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][RCOMP
]);
1924 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1930 GLshort
*dst
= (GLshort
*) dstAddr
;
1931 switch (dstFormat
) {
1934 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1938 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1942 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1946 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1950 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
1952 case GL_LUMINANCE_ALPHA
:
1954 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
1955 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1960 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1961 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1962 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1967 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1968 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1969 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1970 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1975 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1976 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1977 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1982 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1983 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1984 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1985 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1990 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1991 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1992 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1993 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1997 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2001 case GL_UNSIGNED_INT
:
2003 GLuint
*dst
= (GLuint
*) dstAddr
;
2004 switch (dstFormat
) {
2007 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2011 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2015 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2019 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2023 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
2025 case GL_LUMINANCE_ALPHA
:
2027 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
2028 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2033 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2034 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2035 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2040 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2041 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2042 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2043 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2048 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2049 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2050 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2055 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2056 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2057 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2058 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2063 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
2064 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
2065 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
2066 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
2070 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2076 GLint
*dst
= (GLint
*) dstAddr
;
2077 switch (dstFormat
) {
2080 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2084 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2088 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2092 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2096 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
2098 case GL_LUMINANCE_ALPHA
:
2100 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
2101 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2106 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2107 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2108 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2113 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2114 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2115 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2116 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2121 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2122 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2123 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2128 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2129 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2130 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2131 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2136 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
2137 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
2138 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
2139 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
2143 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2149 GLfloat
*dst
= (GLfloat
*) dstAddr
;
2150 switch (dstFormat
) {
2153 dst
[i
] = rgba
[i
][RCOMP
];
2157 dst
[i
] = rgba
[i
][GCOMP
];
2161 dst
[i
] = rgba
[i
][BCOMP
];
2165 dst
[i
] = rgba
[i
][ACOMP
];
2169 dst
[i
] = luminance
[i
];
2171 case GL_LUMINANCE_ALPHA
:
2173 dst
[i
*2+0] = luminance
[i
];
2174 dst
[i
*2+1] = rgba
[i
][ACOMP
];
2179 dst
[i
*3+0] = rgba
[i
][RCOMP
];
2180 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2181 dst
[i
*3+2] = rgba
[i
][BCOMP
];
2186 dst
[i
*4+0] = rgba
[i
][RCOMP
];
2187 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2188 dst
[i
*4+2] = rgba
[i
][BCOMP
];
2189 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2194 dst
[i
*3+0] = rgba
[i
][BCOMP
];
2195 dst
[i
*3+1] = rgba
[i
][GCOMP
];
2196 dst
[i
*3+2] = rgba
[i
][RCOMP
];
2201 dst
[i
*4+0] = rgba
[i
][BCOMP
];
2202 dst
[i
*4+1] = rgba
[i
][GCOMP
];
2203 dst
[i
*4+2] = rgba
[i
][RCOMP
];
2204 dst
[i
*4+3] = rgba
[i
][ACOMP
];
2209 dst
[i
*4+0] = rgba
[i
][ACOMP
];
2210 dst
[i
*4+1] = rgba
[i
][BCOMP
];
2211 dst
[i
*4+2] = rgba
[i
][GCOMP
];
2212 dst
[i
*4+3] = rgba
[i
][RCOMP
];
2216 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2220 case GL_HALF_FLOAT_ARB
:
2222 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
2223 switch (dstFormat
) {
2226 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2230 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2234 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2238 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2242 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
2244 case GL_LUMINANCE_ALPHA
:
2246 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
2247 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2252 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2253 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2254 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2259 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2260 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2261 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2262 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2267 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2268 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2269 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2274 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2275 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2276 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2277 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2282 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
2283 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
2284 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
2285 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
2289 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
2293 case GL_UNSIGNED_BYTE_3_3_2
:
2294 if (dstFormat
== GL_RGB
) {
2295 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2297 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
2298 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
2299 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
2303 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2304 if (dstFormat
== GL_RGB
) {
2305 GLubyte
*dst
= (GLubyte
*) dstAddr
;
2307 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
2308 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
2309 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 6);
2313 case GL_UNSIGNED_SHORT_5_6_5
:
2314 if (dstFormat
== GL_RGB
) {
2315 GLushort
*dst
= (GLushort
*) dstAddr
;
2317 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
2318 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
2319 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
2323 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2324 if (dstFormat
== GL_RGB
) {
2325 GLushort
*dst
= (GLushort
*) dstAddr
;
2327 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
2328 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
2329 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
2333 case GL_UNSIGNED_SHORT_4_4_4_4
:
2334 if (dstFormat
== GL_RGBA
) {
2335 GLushort
*dst
= (GLushort
*) dstAddr
;
2337 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
2338 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
2339 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
2340 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
2343 else if (dstFormat
== GL_BGRA
) {
2344 GLushort
*dst
= (GLushort
*) dstAddr
;
2346 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 12)
2347 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
2348 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 4)
2349 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
2352 else if (dstFormat
== GL_ABGR_EXT
) {
2353 GLushort
*dst
= (GLushort
*) dstAddr
;
2355 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12)
2356 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
2357 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
2358 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) );
2362 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2363 if (dstFormat
== GL_RGBA
) {
2364 GLushort
*dst
= (GLushort
*) dstAddr
;
2366 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
2367 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
2368 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
2369 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
2372 else if (dstFormat
== GL_BGRA
) {
2373 GLushort
*dst
= (GLushort
*) dstAddr
;
2375 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) )
2376 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
2377 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 8)
2378 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
2381 else if (dstFormat
== GL_ABGR_EXT
) {
2382 GLushort
*dst
= (GLushort
*) dstAddr
;
2384 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) )
2385 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
2386 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
2387 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12);
2391 case GL_UNSIGNED_SHORT_5_5_5_1
:
2392 if (dstFormat
== GL_RGBA
) {
2393 GLushort
*dst
= (GLushort
*) dstAddr
;
2395 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
2396 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
2397 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
2398 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
2401 else if (dstFormat
== GL_BGRA
) {
2402 GLushort
*dst
= (GLushort
*) dstAddr
;
2404 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11)
2405 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
2406 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 1)
2407 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
2410 else if (dstFormat
== GL_ABGR_EXT
) {
2411 GLushort
*dst
= (GLushort
*) dstAddr
;
2413 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) << 11)
2414 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 6)
2415 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 1)
2416 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) );
2420 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2421 if (dstFormat
== GL_RGBA
) {
2422 GLushort
*dst
= (GLushort
*) dstAddr
;
2424 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
2425 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
2426 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
2427 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
2430 else if (dstFormat
== GL_BGRA
) {
2431 GLushort
*dst
= (GLushort
*) dstAddr
;
2433 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) )
2434 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
2435 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 10)
2436 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
2439 else if (dstFormat
== GL_ABGR_EXT
) {
2440 GLushort
*dst
= (GLushort
*) dstAddr
;
2442 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) )
2443 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 5)
2444 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 10)
2445 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) << 15);
2449 case GL_UNSIGNED_INT_8_8_8_8
:
2450 if (dstFormat
== GL_RGBA
) {
2451 GLuint
*dst
= (GLuint
*) dstAddr
;
2453 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
2454 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
2455 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
2456 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
2459 else if (dstFormat
== GL_BGRA
) {
2460 GLuint
*dst
= (GLuint
*) dstAddr
;
2462 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
2463 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
2464 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
2465 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
2468 else if (dstFormat
== GL_ABGR_EXT
) {
2469 GLuint
*dst
= (GLuint
*) dstAddr
;
2471 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
2472 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
2473 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
2474 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
2478 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2479 if (dstFormat
== GL_RGBA
) {
2480 GLuint
*dst
= (GLuint
*) dstAddr
;
2482 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
2483 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
2484 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
2485 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
2488 else if (dstFormat
== GL_BGRA
) {
2489 GLuint
*dst
= (GLuint
*) dstAddr
;
2491 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
2492 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
2493 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
2494 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
2497 else if (dstFormat
== GL_ABGR_EXT
) {
2498 GLuint
*dst
= (GLuint
*) dstAddr
;
2500 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
2501 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
2502 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
2503 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
2507 case GL_UNSIGNED_INT_10_10_10_2
:
2508 if (dstFormat
== GL_RGBA
) {
2509 GLuint
*dst
= (GLuint
*) dstAddr
;
2511 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
2512 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
2513 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
2514 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
2517 else if (dstFormat
== GL_BGRA
) {
2518 GLuint
*dst
= (GLuint
*) dstAddr
;
2520 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
2521 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
2522 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
2523 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
2526 else if (dstFormat
== GL_ABGR_EXT
) {
2527 GLuint
*dst
= (GLuint
*) dstAddr
;
2529 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
2530 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
2531 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
2532 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
2536 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2537 if (dstFormat
== GL_RGBA
) {
2538 GLuint
*dst
= (GLuint
*) dstAddr
;
2540 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
2541 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
2542 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
2543 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
2546 else if (dstFormat
== GL_BGRA
) {
2547 GLuint
*dst
= (GLuint
*) dstAddr
;
2549 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
2550 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
2551 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
2552 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
2555 else if (dstFormat
== GL_ABGR_EXT
) {
2556 GLuint
*dst
= (GLuint
*) dstAddr
;
2558 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
2559 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
2560 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
2561 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
2566 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
2570 if (dstPacking
->SwapBytes
) {
2571 GLint swapSize
= _mesa_sizeof_packed_type(dstType
);
2572 if (swapSize
== 2) {
2573 if (dstPacking
->SwapBytes
) {
2574 _mesa_swap2((GLushort
*) dstAddr
, n
* comps
);
2577 else if (swapSize
== 4) {
2578 if (dstPacking
->SwapBytes
) {
2579 _mesa_swap4((GLuint
*) dstAddr
, n
* comps
);
2586 #define SWAP2BYTE(VALUE) \
2588 GLubyte *bytes = (GLubyte *) &(VALUE); \
2589 GLubyte tmp = bytes[0]; \
2590 bytes[0] = bytes[1]; \
2594 #define SWAP4BYTE(VALUE) \
2596 GLubyte *bytes = (GLubyte *) &(VALUE); \
2597 GLubyte tmp = bytes[0]; \
2598 bytes[0] = bytes[3]; \
2601 bytes[1] = bytes[2]; \
2607 extract_uint_indexes(GLuint n
, GLuint indexes
[],
2608 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2609 const struct gl_pixelstore_attrib
*unpack
)
2611 ASSERT(srcFormat
== GL_COLOR_INDEX
|| srcFormat
== GL_STENCIL_INDEX
);
2613 ASSERT(srcType
== GL_BITMAP
||
2614 srcType
== GL_UNSIGNED_BYTE
||
2615 srcType
== GL_BYTE
||
2616 srcType
== GL_UNSIGNED_SHORT
||
2617 srcType
== GL_SHORT
||
2618 srcType
== GL_UNSIGNED_INT
||
2619 srcType
== GL_INT
||
2620 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
2621 srcType
== GL_HALF_FLOAT_ARB
||
2622 srcType
== GL_FLOAT
);
2627 GLubyte
*ubsrc
= (GLubyte
*) src
;
2628 if (unpack
->LsbFirst
) {
2629 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
2631 for (i
= 0; i
< n
; i
++) {
2632 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2643 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
2645 for (i
= 0; i
< n
; i
++) {
2646 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2658 case GL_UNSIGNED_BYTE
:
2661 const GLubyte
*s
= (const GLubyte
*) src
;
2662 for (i
= 0; i
< n
; i
++)
2669 const GLbyte
*s
= (const GLbyte
*) src
;
2670 for (i
= 0; i
< n
; i
++)
2674 case GL_UNSIGNED_SHORT
:
2677 const GLushort
*s
= (const GLushort
*) src
;
2678 if (unpack
->SwapBytes
) {
2679 for (i
= 0; i
< n
; i
++) {
2680 GLushort value
= s
[i
];
2686 for (i
= 0; i
< n
; i
++)
2694 const GLshort
*s
= (const GLshort
*) src
;
2695 if (unpack
->SwapBytes
) {
2696 for (i
= 0; i
< n
; i
++) {
2697 GLshort value
= s
[i
];
2703 for (i
= 0; i
< n
; i
++)
2708 case GL_UNSIGNED_INT
:
2711 const GLuint
*s
= (const GLuint
*) src
;
2712 if (unpack
->SwapBytes
) {
2713 for (i
= 0; i
< n
; i
++) {
2714 GLuint value
= s
[i
];
2720 for (i
= 0; i
< n
; i
++)
2728 const GLint
*s
= (const GLint
*) src
;
2729 if (unpack
->SwapBytes
) {
2730 for (i
= 0; i
< n
; i
++) {
2737 for (i
= 0; i
< n
; i
++)
2745 const GLfloat
*s
= (const GLfloat
*) src
;
2746 if (unpack
->SwapBytes
) {
2747 for (i
= 0; i
< n
; i
++) {
2748 GLfloat value
= s
[i
];
2750 indexes
[i
] = (GLuint
) value
;
2754 for (i
= 0; i
< n
; i
++)
2755 indexes
[i
] = (GLuint
) s
[i
];
2759 case GL_HALF_FLOAT_ARB
:
2762 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
2763 if (unpack
->SwapBytes
) {
2764 for (i
= 0; i
< n
; i
++) {
2765 GLhalfARB value
= s
[i
];
2767 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
2771 for (i
= 0; i
< n
; i
++)
2772 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
2776 case GL_UNSIGNED_INT_24_8_EXT
:
2779 const GLuint
*s
= (const GLuint
*) src
;
2780 if (unpack
->SwapBytes
) {
2781 for (i
= 0; i
< n
; i
++) {
2782 GLuint value
= s
[i
];
2784 indexes
[i
] = value
& 0xff; /* lower 8 bits */
2788 for (i
= 0; i
< n
; i
++)
2789 indexes
[i
] = s
[i
] & 0xfff; /* lower 8 bits */
2795 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2802 * This function extracts floating point RGBA values from arbitrary
2803 * image data. srcFormat and srcType are the format and type parameters
2804 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2806 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2807 * implements the "Conversion to floating point", "Conversion to RGB",
2808 * and "Final Expansion to RGBA" operations.
2810 * Args: n - number of pixels
2811 * rgba - output colors
2812 * srcFormat - format of incoming data
2813 * srcType - data type of incoming data
2814 * src - source data pointer
2815 * swapBytes - perform byteswapping of incoming data?
2818 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2819 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2820 GLboolean swapBytes
)
2822 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2824 GLint rComp
, bComp
, gComp
, aComp
;
2826 ASSERT(srcFormat
== GL_RED
||
2827 srcFormat
== GL_GREEN
||
2828 srcFormat
== GL_BLUE
||
2829 srcFormat
== GL_ALPHA
||
2830 srcFormat
== GL_LUMINANCE
||
2831 srcFormat
== GL_LUMINANCE_ALPHA
||
2832 srcFormat
== GL_INTENSITY
||
2833 srcFormat
== GL_RGB
||
2834 srcFormat
== GL_BGR
||
2835 srcFormat
== GL_RGBA
||
2836 srcFormat
== GL_BGRA
||
2837 srcFormat
== GL_ABGR_EXT
);
2839 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2840 srcType
== GL_BYTE
||
2841 srcType
== GL_UNSIGNED_SHORT
||
2842 srcType
== GL_SHORT
||
2843 srcType
== GL_UNSIGNED_INT
||
2844 srcType
== GL_INT
||
2845 srcType
== GL_HALF_FLOAT_ARB
||
2846 srcType
== GL_FLOAT
||
2847 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2848 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2849 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2850 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2851 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2852 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2853 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2854 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2855 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2856 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2857 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2858 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2860 rComp
= gComp
= bComp
= aComp
= -1;
2862 switch (srcFormat
) {
2865 greenIndex
= blueIndex
= alphaIndex
= -1;
2870 redIndex
= blueIndex
= alphaIndex
= -1;
2875 redIndex
= greenIndex
= alphaIndex
= -1;
2879 redIndex
= greenIndex
= blueIndex
= -1;
2884 redIndex
= greenIndex
= blueIndex
= 0;
2888 case GL_LUMINANCE_ALPHA
:
2889 redIndex
= greenIndex
= blueIndex
= 0;
2894 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
2953 _mesa_problem(NULL
, "bad srcFormat in extract float data");
2958 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
2959 if ((INDEX) < 0) { \
2961 for (i = 0; i < n; i++) { \
2962 rgba[i][CHANNEL] = DEFAULT; \
2965 else if (swapBytes) { \
2966 const TYPE *s = (const TYPE *) src; \
2968 for (i = 0; i < n; i++) { \
2969 TYPE value = s[INDEX]; \
2970 if (sizeof(TYPE) == 2) { \
2973 else if (sizeof(TYPE) == 4) { \
2976 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
2981 const TYPE *s = (const TYPE *) src; \
2983 for (i = 0; i < n; i++) { \
2984 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
2990 case GL_UNSIGNED_BYTE
:
2991 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2992 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2993 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2994 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2997 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2998 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2999 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
3000 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
3002 case GL_UNSIGNED_SHORT
:
3003 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3004 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3005 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
3006 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
3009 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3010 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3011 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
3012 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
3014 case GL_UNSIGNED_INT
:
3015 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3016 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3017 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
3018 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
3021 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3022 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3023 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
3024 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
3027 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3028 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3029 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
3030 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
3032 case GL_HALF_FLOAT_ARB
:
3033 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3034 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3035 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
3036 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
3038 case GL_UNSIGNED_BYTE_3_3_2
:
3040 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3042 for (i
= 0; i
< n
; i
++) {
3043 GLubyte p
= ubsrc
[i
];
3044 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
3045 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
3046 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
3047 rgba
[i
][aComp
] = 1.0F
;
3051 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3053 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
3055 for (i
= 0; i
< n
; i
++) {
3056 GLubyte p
= ubsrc
[i
];
3057 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
3058 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
3059 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
3060 rgba
[i
][aComp
] = 1.0F
;
3064 case GL_UNSIGNED_SHORT_5_6_5
:
3066 const GLushort
*ussrc
= (const GLushort
*) src
;
3068 for (i
= 0; i
< n
; i
++) {
3069 GLushort p
= ussrc
[i
];
3071 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3072 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3073 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3074 rgba
[i
][aComp
] = 1.0F
;
3078 const GLushort
*ussrc
= (const GLushort
*) src
;
3080 for (i
= 0; i
< n
; i
++) {
3081 GLushort p
= ussrc
[i
];
3082 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3083 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3084 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3085 rgba
[i
][aComp
] = 1.0F
;
3089 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3091 const GLushort
*ussrc
= (const GLushort
*) src
;
3093 for (i
= 0; i
< n
; i
++) {
3094 GLushort p
= ussrc
[i
];
3096 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3097 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3098 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3099 rgba
[i
][aComp
] = 1.0F
;
3103 const GLushort
*ussrc
= (const GLushort
*) src
;
3105 for (i
= 0; i
< n
; i
++) {
3106 GLushort p
= ussrc
[i
];
3107 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3108 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
3109 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3110 rgba
[i
][aComp
] = 1.0F
;
3114 case GL_UNSIGNED_SHORT_4_4_4_4
:
3116 const GLushort
*ussrc
= (const GLushort
*) src
;
3118 for (i
= 0; i
< n
; i
++) {
3119 GLushort p
= ussrc
[i
];
3121 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3122 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3123 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3124 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3128 const GLushort
*ussrc
= (const GLushort
*) src
;
3130 for (i
= 0; i
< n
; i
++) {
3131 GLushort p
= ussrc
[i
];
3132 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3133 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3134 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3135 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3139 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3141 const GLushort
*ussrc
= (const GLushort
*) src
;
3143 for (i
= 0; i
< n
; i
++) {
3144 GLushort p
= ussrc
[i
];
3146 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3147 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3148 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3149 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3153 const GLushort
*ussrc
= (const GLushort
*) src
;
3155 for (i
= 0; i
< n
; i
++) {
3156 GLushort p
= ussrc
[i
];
3157 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
3158 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
3159 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
3160 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
3164 case GL_UNSIGNED_SHORT_5_5_5_1
:
3166 const GLushort
*ussrc
= (const GLushort
*) src
;
3168 for (i
= 0; i
< n
; i
++) {
3169 GLushort p
= ussrc
[i
];
3171 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3172 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3173 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3174 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3178 const GLushort
*ussrc
= (const GLushort
*) src
;
3180 for (i
= 0; i
< n
; i
++) {
3181 GLushort p
= ussrc
[i
];
3182 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
3183 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
3184 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
3185 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
3189 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3191 const GLushort
*ussrc
= (const GLushort
*) src
;
3193 for (i
= 0; i
< n
; i
++) {
3194 GLushort p
= ussrc
[i
];
3196 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3197 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3198 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3199 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3203 const GLushort
*ussrc
= (const GLushort
*) src
;
3205 for (i
= 0; i
< n
; i
++) {
3206 GLushort p
= ussrc
[i
];
3207 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
3208 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
3209 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
3210 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
3214 case GL_UNSIGNED_INT_8_8_8_8
:
3216 const GLuint
*uisrc
= (const GLuint
*) src
;
3218 for (i
= 0; i
< n
; i
++) {
3219 GLuint p
= uisrc
[i
];
3220 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3221 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3222 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3223 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3227 const GLuint
*uisrc
= (const GLuint
*) src
;
3229 for (i
= 0; i
< n
; i
++) {
3230 GLuint p
= uisrc
[i
];
3231 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3232 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3233 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3234 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3238 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3240 const GLuint
*uisrc
= (const GLuint
*) src
;
3242 for (i
= 0; i
< n
; i
++) {
3243 GLuint p
= uisrc
[i
];
3244 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3245 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3246 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3247 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3251 const GLuint
*uisrc
= (const GLuint
*) src
;
3253 for (i
= 0; i
< n
; i
++) {
3254 GLuint p
= uisrc
[i
];
3255 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
3256 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
3257 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
3258 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
3262 case GL_UNSIGNED_INT_10_10_10_2
:
3264 const GLuint
*uisrc
= (const GLuint
*) src
;
3266 for (i
= 0; i
< n
; i
++) {
3267 GLuint p
= uisrc
[i
];
3269 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3270 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3271 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3272 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3276 const GLuint
*uisrc
= (const GLuint
*) src
;
3278 for (i
= 0; i
< n
; i
++) {
3279 GLuint p
= uisrc
[i
];
3280 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
3281 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
3282 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
3283 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
3287 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3289 const GLuint
*uisrc
= (const GLuint
*) src
;
3291 for (i
= 0; i
< n
; i
++) {
3292 GLuint p
= uisrc
[i
];
3294 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3295 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3296 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3297 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3301 const GLuint
*uisrc
= (const GLuint
*) src
;
3303 for (i
= 0; i
< n
; i
++) {
3304 GLuint p
= uisrc
[i
];
3305 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
3306 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
3307 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
3308 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
3313 _mesa_problem(NULL
, "bad srcType in extract float data");
3320 * Unpack a row of color image data from a client buffer according to
3321 * the pixel unpacking parameters.
3322 * Return GLchan values in the specified dest image format.
3323 * This is used by glDrawPixels and glTexImage?D().
3324 * \param ctx - the context
3325 * n - number of pixels in the span
3326 * dstFormat - format of destination color array
3327 * dest - the destination color array
3328 * srcFormat - source image format
3329 * srcType - source image data type
3330 * source - source image pointer
3331 * srcPacking - pixel unpacking parameters
3332 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
3334 * XXX perhaps expand this to process whole images someday.
3337 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
3338 GLuint n
, GLenum dstFormat
, GLchan dest
[],
3339 GLenum srcFormat
, GLenum srcType
,
3340 const GLvoid
*source
,
3341 const struct gl_pixelstore_attrib
*srcPacking
,
3342 GLbitfield transferOps
)
3344 ASSERT(dstFormat
== GL_ALPHA
||
3345 dstFormat
== GL_LUMINANCE
||
3346 dstFormat
== GL_LUMINANCE_ALPHA
||
3347 dstFormat
== GL_INTENSITY
||
3348 dstFormat
== GL_RGB
||
3349 dstFormat
== GL_RGBA
||
3350 dstFormat
== GL_COLOR_INDEX
);
3352 ASSERT(srcFormat
== GL_RED
||
3353 srcFormat
== GL_GREEN
||
3354 srcFormat
== GL_BLUE
||
3355 srcFormat
== GL_ALPHA
||
3356 srcFormat
== GL_LUMINANCE
||
3357 srcFormat
== GL_LUMINANCE_ALPHA
||
3358 srcFormat
== GL_INTENSITY
||
3359 srcFormat
== GL_RGB
||
3360 srcFormat
== GL_BGR
||
3361 srcFormat
== GL_RGBA
||
3362 srcFormat
== GL_BGRA
||
3363 srcFormat
== GL_ABGR_EXT
||
3364 srcFormat
== GL_COLOR_INDEX
);
3366 ASSERT(srcType
== GL_BITMAP
||
3367 srcType
== GL_UNSIGNED_BYTE
||
3368 srcType
== GL_BYTE
||
3369 srcType
== GL_UNSIGNED_SHORT
||
3370 srcType
== GL_SHORT
||
3371 srcType
== GL_UNSIGNED_INT
||
3372 srcType
== GL_INT
||
3373 srcType
== GL_HALF_FLOAT_ARB
||
3374 srcType
== GL_FLOAT
||
3375 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3376 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3377 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3378 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3379 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3380 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3381 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3382 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3383 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3384 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3385 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3386 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3388 /* Try simple cases first */
3389 if (transferOps
== 0) {
3390 if (srcType
== CHAN_TYPE
) {
3391 if (dstFormat
== GL_RGBA
) {
3392 if (srcFormat
== GL_RGBA
) {
3393 _mesa_memcpy( dest
, source
, n
* 4 * sizeof(GLchan
) );
3396 else if (srcFormat
== GL_RGB
) {
3398 const GLchan
*src
= (const GLchan
*) source
;
3400 for (i
= 0; i
< n
; i
++) {
3411 else if (dstFormat
== GL_RGB
) {
3412 if (srcFormat
== GL_RGB
) {
3413 _mesa_memcpy( dest
, source
, n
* 3 * sizeof(GLchan
) );
3416 else if (srcFormat
== GL_RGBA
) {
3418 const GLchan
*src
= (const GLchan
*) source
;
3420 for (i
= 0; i
< n
; i
++) {
3430 else if (dstFormat
== srcFormat
) {
3431 GLint comps
= _mesa_components_in_format(srcFormat
);
3433 _mesa_memcpy( dest
, source
, n
* comps
* sizeof(GLchan
) );
3438 * Common situation, loading 8bit RGBA/RGB source images
3439 * into 16/32 bit destination. (OSMesa16/32)
3441 else if (srcType
== GL_UNSIGNED_BYTE
) {
3442 if (dstFormat
== GL_RGBA
) {
3443 if (srcFormat
== GL_RGB
) {
3445 const GLubyte
*src
= (const GLubyte
*) source
;
3447 for (i
= 0; i
< n
; i
++) {
3448 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3449 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3450 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3457 else if (srcFormat
== GL_RGBA
) {
3459 const GLubyte
*src
= (const GLubyte
*) source
;
3461 for (i
= 0; i
< n
; i
++) {
3462 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3463 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3464 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3465 dst
[3] = UBYTE_TO_CHAN(src
[3]);
3472 else if (dstFormat
== GL_RGB
) {
3473 if (srcFormat
== GL_RGB
) {
3475 const GLubyte
*src
= (const GLubyte
*) source
;
3477 for (i
= 0; i
< n
; i
++) {
3478 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3479 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3480 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3486 else if (srcFormat
== GL_RGBA
) {
3488 const GLubyte
*src
= (const GLubyte
*) source
;
3490 for (i
= 0; i
< n
; i
++) {
3491 dst
[0] = UBYTE_TO_CHAN(src
[0]);
3492 dst
[1] = UBYTE_TO_CHAN(src
[1]);
3493 dst
[2] = UBYTE_TO_CHAN(src
[2]);
3504 /* general solution begins here */
3506 GLint dstComponents
;
3507 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3508 GLint dstLuminanceIndex
, dstIntensityIndex
;
3509 GLfloat rgba
[MAX_WIDTH
][4];
3511 dstComponents
= _mesa_components_in_format( dstFormat
);
3512 /* source & dest image formats should have been error checked by now */
3513 assert(dstComponents
> 0);
3516 * Extract image data and convert to RGBA floats
3518 assert(n
<= MAX_WIDTH
);
3519 if (srcFormat
== GL_COLOR_INDEX
) {
3520 GLuint indexes
[MAX_WIDTH
];
3521 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3524 if (dstFormat
== GL_COLOR_INDEX
) {
3526 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3527 /* convert to GLchan and return */
3528 for (i
= 0; i
< n
; i
++) {
3529 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3534 /* Convert indexes to RGBA */
3535 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3536 shift_and_offset_ci(ctx
, n
, indexes
);
3538 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3541 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3542 * with color indexes.
3544 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3547 /* non-color index data */
3548 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3549 srcPacking
->SwapBytes
);
3552 /* Need to clamp if returning GLubytes or GLushorts */
3553 #if CHAN_TYPE != GL_FLOAT
3554 transferOps
|= IMAGE_CLAMP_BIT
;
3558 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3561 /* Now determine which color channels we need to produce.
3562 * And determine the dest index (offset) within each color tuple.
3564 switch (dstFormat
) {
3567 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3568 dstLuminanceIndex
= dstIntensityIndex
= -1;
3571 dstLuminanceIndex
= 0;
3572 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3573 dstIntensityIndex
= -1;
3575 case GL_LUMINANCE_ALPHA
:
3576 dstLuminanceIndex
= 0;
3578 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3579 dstIntensityIndex
= -1;
3582 dstIntensityIndex
= 0;
3583 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3584 dstLuminanceIndex
= -1;
3590 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3597 dstLuminanceIndex
= dstIntensityIndex
= -1;
3600 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
3605 /* Now return the GLchan data in the requested dstFormat */
3607 if (dstRedIndex
>= 0) {
3610 for (i
= 0; i
< n
; i
++) {
3611 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
3612 dst
+= dstComponents
;
3616 if (dstGreenIndex
>= 0) {
3619 for (i
= 0; i
< n
; i
++) {
3620 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
3621 dst
+= dstComponents
;
3625 if (dstBlueIndex
>= 0) {
3628 for (i
= 0; i
< n
; i
++) {
3629 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
3630 dst
+= dstComponents
;
3634 if (dstAlphaIndex
>= 0) {
3637 for (i
= 0; i
< n
; i
++) {
3638 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
3639 dst
+= dstComponents
;
3643 if (dstIntensityIndex
>= 0) {
3646 assert(dstIntensityIndex
== 0);
3647 assert(dstComponents
== 1);
3648 for (i
= 0; i
< n
; i
++) {
3649 /* Intensity comes from red channel */
3650 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
3654 if (dstLuminanceIndex
>= 0) {
3657 assert(dstLuminanceIndex
== 0);
3658 for (i
= 0; i
< n
; i
++) {
3659 /* Luminance comes from red channel */
3660 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
3661 dst
+= dstComponents
;
3669 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
3670 * instead of GLchan.
3673 _mesa_unpack_color_span_float( GLcontext
*ctx
,
3674 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
3675 GLenum srcFormat
, GLenum srcType
,
3676 const GLvoid
*source
,
3677 const struct gl_pixelstore_attrib
*srcPacking
,
3678 GLbitfield transferOps
)
3680 ASSERT(dstFormat
== GL_ALPHA
||
3681 dstFormat
== GL_LUMINANCE
||
3682 dstFormat
== GL_LUMINANCE_ALPHA
||
3683 dstFormat
== GL_INTENSITY
||
3684 dstFormat
== GL_RGB
||
3685 dstFormat
== GL_RGBA
||
3686 dstFormat
== GL_COLOR_INDEX
);
3688 ASSERT(srcFormat
== GL_RED
||
3689 srcFormat
== GL_GREEN
||
3690 srcFormat
== GL_BLUE
||
3691 srcFormat
== GL_ALPHA
||
3692 srcFormat
== GL_LUMINANCE
||
3693 srcFormat
== GL_LUMINANCE_ALPHA
||
3694 srcFormat
== GL_INTENSITY
||
3695 srcFormat
== GL_RGB
||
3696 srcFormat
== GL_BGR
||
3697 srcFormat
== GL_RGBA
||
3698 srcFormat
== GL_BGRA
||
3699 srcFormat
== GL_ABGR_EXT
||
3700 srcFormat
== GL_COLOR_INDEX
);
3702 ASSERT(srcType
== GL_BITMAP
||
3703 srcType
== GL_UNSIGNED_BYTE
||
3704 srcType
== GL_BYTE
||
3705 srcType
== GL_UNSIGNED_SHORT
||
3706 srcType
== GL_SHORT
||
3707 srcType
== GL_UNSIGNED_INT
||
3708 srcType
== GL_INT
||
3709 srcType
== GL_HALF_FLOAT_ARB
||
3710 srcType
== GL_FLOAT
||
3711 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3712 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3713 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3714 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3715 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3716 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3717 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3718 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3719 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3720 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3721 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3722 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3724 /* general solution, no special cases, yet */
3726 GLint dstComponents
;
3727 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3728 GLint dstLuminanceIndex
, dstIntensityIndex
;
3729 GLfloat rgba
[MAX_WIDTH
][4];
3731 dstComponents
= _mesa_components_in_format( dstFormat
);
3732 /* source & dest image formats should have been error checked by now */
3733 assert(dstComponents
> 0);
3736 * Extract image data and convert to RGBA floats
3738 assert(n
<= MAX_WIDTH
);
3739 if (srcFormat
== GL_COLOR_INDEX
) {
3740 GLuint indexes
[MAX_WIDTH
];
3741 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3744 if (dstFormat
== GL_COLOR_INDEX
) {
3746 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3747 /* convert to GLchan and return */
3748 for (i
= 0; i
< n
; i
++) {
3749 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3754 /* Convert indexes to RGBA */
3755 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3756 shift_and_offset_ci(ctx
, n
, indexes
);
3758 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3761 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3762 * with color indexes.
3764 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3767 /* non-color index data */
3768 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3769 srcPacking
->SwapBytes
);
3773 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3776 /* Now determine which color channels we need to produce.
3777 * And determine the dest index (offset) within each color tuple.
3779 switch (dstFormat
) {
3782 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3783 dstLuminanceIndex
= dstIntensityIndex
= -1;
3786 dstLuminanceIndex
= 0;
3787 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3788 dstIntensityIndex
= -1;
3790 case GL_LUMINANCE_ALPHA
:
3791 dstLuminanceIndex
= 0;
3793 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3794 dstIntensityIndex
= -1;
3797 dstIntensityIndex
= 0;
3798 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3799 dstLuminanceIndex
= -1;
3805 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3812 dstLuminanceIndex
= dstIntensityIndex
= -1;
3815 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
3819 /* Now pack results in the requested dstFormat */
3820 if (dstRedIndex
>= 0) {
3821 GLfloat
*dst
= dest
;
3823 for (i
= 0; i
< n
; i
++) {
3824 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3825 dst
+= dstComponents
;
3829 if (dstGreenIndex
>= 0) {
3830 GLfloat
*dst
= dest
;
3832 for (i
= 0; i
< n
; i
++) {
3833 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3834 dst
+= dstComponents
;
3838 if (dstBlueIndex
>= 0) {
3839 GLfloat
*dst
= dest
;
3841 for (i
= 0; i
< n
; i
++) {
3842 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3843 dst
+= dstComponents
;
3847 if (dstAlphaIndex
>= 0) {
3848 GLfloat
*dst
= dest
;
3850 for (i
= 0; i
< n
; i
++) {
3851 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3852 dst
+= dstComponents
;
3856 if (dstIntensityIndex
>= 0) {
3857 GLfloat
*dst
= dest
;
3859 assert(dstIntensityIndex
== 0);
3860 assert(dstComponents
== 1);
3861 for (i
= 0; i
< n
; i
++) {
3862 /* Intensity comes from red channel */
3863 dst
[i
] = rgba
[i
][RCOMP
];
3867 if (dstLuminanceIndex
>= 0) {
3868 GLfloat
*dst
= dest
;
3870 assert(dstLuminanceIndex
== 0);
3871 for (i
= 0; i
< n
; i
++) {
3872 /* Luminance comes from red channel */
3873 dst
[0] = rgba
[i
][RCOMP
];
3874 dst
+= dstComponents
;
3882 * Unpack a row of color index data from a client buffer according to
3883 * the pixel unpacking parameters.
3884 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
3886 * Args: ctx - the context
3887 * n - number of pixels
3888 * dstType - destination data type
3889 * dest - destination array
3890 * srcType - source pixel type
3891 * source - source data pointer
3892 * srcPacking - pixel unpacking parameters
3893 * transferOps - the pixel transfer operations to apply
3896 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
3897 GLenum dstType
, GLvoid
*dest
,
3898 GLenum srcType
, const GLvoid
*source
,
3899 const struct gl_pixelstore_attrib
*srcPacking
,
3900 GLbitfield transferOps
)
3902 ASSERT(srcType
== GL_BITMAP
||
3903 srcType
== GL_UNSIGNED_BYTE
||
3904 srcType
== GL_BYTE
||
3905 srcType
== GL_UNSIGNED_SHORT
||
3906 srcType
== GL_SHORT
||
3907 srcType
== GL_UNSIGNED_INT
||
3908 srcType
== GL_INT
||
3909 srcType
== GL_HALF_FLOAT_ARB
||
3910 srcType
== GL_FLOAT
);
3912 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3913 dstType
== GL_UNSIGNED_SHORT
||
3914 dstType
== GL_UNSIGNED_INT
);
3917 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3920 * Try simple cases first
3922 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
3923 && dstType
== GL_UNSIGNED_BYTE
) {
3924 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
3926 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
3927 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
3928 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
3934 GLuint indexes
[MAX_WIDTH
];
3935 assert(n
<= MAX_WIDTH
);
3937 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3941 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3943 /* convert to dest type */
3945 case GL_UNSIGNED_BYTE
:
3947 GLubyte
*dst
= (GLubyte
*) dest
;
3949 for (i
= 0; i
< n
; i
++) {
3950 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3954 case GL_UNSIGNED_SHORT
:
3956 GLuint
*dst
= (GLuint
*) dest
;
3958 for (i
= 0; i
< n
; i
++) {
3959 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3963 case GL_UNSIGNED_INT
:
3964 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
3967 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
3974 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
3975 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
3976 const struct gl_pixelstore_attrib
*dstPacking
,
3977 GLbitfield transferOps
)
3979 GLuint indexes
[MAX_WIDTH
];
3981 ASSERT(n
<= MAX_WIDTH
);
3983 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3985 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
3986 /* make a copy of input */
3987 _mesa_memcpy(indexes
, source
, n
* sizeof(GLuint
));
3988 _mesa_apply_ci_transfer_ops(ctx
, transferOps
, n
, indexes
);
3993 case GL_UNSIGNED_BYTE
:
3995 GLubyte
*dst
= (GLubyte
*) dest
;
3997 for (i
= 0; i
< n
; i
++) {
3998 *dst
++ = (GLubyte
) source
[i
];
4004 GLbyte
*dst
= (GLbyte
*) dest
;
4006 for (i
= 0; i
< n
; i
++) {
4007 dst
[i
] = (GLbyte
) source
[i
];
4011 case GL_UNSIGNED_SHORT
:
4013 GLushort
*dst
= (GLushort
*) dest
;
4015 for (i
= 0; i
< n
; i
++) {
4016 dst
[i
] = (GLushort
) source
[i
];
4018 if (dstPacking
->SwapBytes
) {
4019 _mesa_swap2( (GLushort
*) dst
, n
);
4025 GLshort
*dst
= (GLshort
*) dest
;
4027 for (i
= 0; i
< n
; i
++) {
4028 dst
[i
] = (GLshort
) source
[i
];
4030 if (dstPacking
->SwapBytes
) {
4031 _mesa_swap2( (GLushort
*) dst
, n
);
4035 case GL_UNSIGNED_INT
:
4037 GLuint
*dst
= (GLuint
*) dest
;
4039 for (i
= 0; i
< n
; i
++) {
4040 dst
[i
] = (GLuint
) source
[i
];
4042 if (dstPacking
->SwapBytes
) {
4043 _mesa_swap4( (GLuint
*) dst
, n
);
4049 GLint
*dst
= (GLint
*) dest
;
4051 for (i
= 0; i
< n
; i
++) {
4052 dst
[i
] = (GLint
) source
[i
];
4054 if (dstPacking
->SwapBytes
) {
4055 _mesa_swap4( (GLuint
*) dst
, n
);
4061 GLfloat
*dst
= (GLfloat
*) dest
;
4063 for (i
= 0; i
< n
; i
++) {
4064 dst
[i
] = (GLfloat
) source
[i
];
4066 if (dstPacking
->SwapBytes
) {
4067 _mesa_swap4( (GLuint
*) dst
, n
);
4071 case GL_HALF_FLOAT_ARB
:
4073 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4075 for (i
= 0; i
< n
; i
++) {
4076 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
4078 if (dstPacking
->SwapBytes
) {
4079 _mesa_swap2( (GLushort
*) dst
, n
);
4084 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4090 * Unpack a row of stencil data from a client buffer according to
4091 * the pixel unpacking parameters.
4092 * This is (or will be) used by glDrawPixels
4094 * Args: ctx - the context
4095 * n - number of pixels
4096 * dstType - destination data type
4097 * dest - destination array
4098 * srcType - source pixel type
4099 * source - source data pointer
4100 * srcPacking - pixel unpacking parameters
4101 * transferOps - apply offset/bias/lookup ops?
4104 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4105 GLenum dstType
, GLvoid
*dest
,
4106 GLenum srcType
, const GLvoid
*source
,
4107 const struct gl_pixelstore_attrib
*srcPacking
,
4108 GLbitfield transferOps
)
4110 ASSERT(srcType
== GL_BITMAP
||
4111 srcType
== GL_UNSIGNED_BYTE
||
4112 srcType
== GL_BYTE
||
4113 srcType
== GL_UNSIGNED_SHORT
||
4114 srcType
== GL_SHORT
||
4115 srcType
== GL_UNSIGNED_INT
||
4116 srcType
== GL_INT
||
4117 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
4118 srcType
== GL_HALF_FLOAT_ARB
||
4119 srcType
== GL_FLOAT
);
4121 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
4122 dstType
== GL_UNSIGNED_SHORT
||
4123 dstType
== GL_UNSIGNED_INT
);
4125 /* only shift and offset apply to stencil */
4126 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
4129 * Try simple cases first
4131 if (transferOps
== 0 &&
4132 !ctx
->Pixel
.MapStencilFlag
&&
4133 srcType
== GL_UNSIGNED_BYTE
&&
4134 dstType
== GL_UNSIGNED_BYTE
) {
4135 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
4137 else if (transferOps
== 0 &&
4138 !ctx
->Pixel
.MapStencilFlag
&&
4139 srcType
== GL_UNSIGNED_INT
&&
4140 dstType
== GL_UNSIGNED_INT
&&
4141 !srcPacking
->SwapBytes
) {
4142 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
4148 GLuint indexes
[MAX_WIDTH
];
4149 assert(n
<= MAX_WIDTH
);
4151 extract_uint_indexes(n
, indexes
, GL_STENCIL_INDEX
, srcType
, source
,
4154 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
4155 /* shift and offset indexes */
4156 shift_and_offset_ci(ctx
, n
, indexes
);
4159 if (ctx
->Pixel
.MapStencilFlag
) {
4160 /* Apply stencil lookup table */
4161 const GLuint mask
= ctx
->PixelMaps
.StoS
.Size
- 1;
4163 for (i
= 0; i
< n
; i
++) {
4164 indexes
[i
] = ctx
->PixelMaps
.StoS
.Map
[ indexes
[i
] & mask
];
4168 /* convert to dest type */
4170 case GL_UNSIGNED_BYTE
:
4172 GLubyte
*dst
= (GLubyte
*) dest
;
4174 for (i
= 0; i
< n
; i
++) {
4175 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
4179 case GL_UNSIGNED_SHORT
:
4181 GLuint
*dst
= (GLuint
*) dest
;
4183 for (i
= 0; i
< n
; i
++) {
4184 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
4188 case GL_UNSIGNED_INT
:
4189 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
4192 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
4199 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
4200 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
4201 const struct gl_pixelstore_attrib
*dstPacking
)
4203 GLstencil stencil
[MAX_WIDTH
];
4205 ASSERT(n
<= MAX_WIDTH
);
4207 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
4208 ctx
->Pixel
.MapStencilFlag
) {
4209 /* make a copy of input */
4210 _mesa_memcpy(stencil
, source
, n
* sizeof(GLstencil
));
4211 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencil
);
4216 case GL_UNSIGNED_BYTE
:
4217 if (sizeof(GLstencil
) == 1) {
4218 _mesa_memcpy( dest
, source
, n
);
4221 GLubyte
*dst
= (GLubyte
*) dest
;
4224 dst
[i
] = (GLubyte
) source
[i
];
4230 GLbyte
*dst
= (GLbyte
*) dest
;
4233 dst
[i
] = (GLbyte
) (source
[i
] & 0x7f);
4237 case GL_UNSIGNED_SHORT
:
4239 GLushort
*dst
= (GLushort
*) dest
;
4242 dst
[i
] = (GLushort
) source
[i
];
4244 if (dstPacking
->SwapBytes
) {
4245 _mesa_swap2( (GLushort
*) dst
, n
);
4251 GLshort
*dst
= (GLshort
*) dest
;
4254 dst
[i
] = (GLshort
) source
[i
];
4256 if (dstPacking
->SwapBytes
) {
4257 _mesa_swap2( (GLushort
*) dst
, n
);
4261 case GL_UNSIGNED_INT
:
4263 GLuint
*dst
= (GLuint
*) dest
;
4266 dst
[i
] = (GLuint
) source
[i
];
4268 if (dstPacking
->SwapBytes
) {
4269 _mesa_swap4( (GLuint
*) dst
, n
);
4275 GLint
*dst
= (GLint
*) dest
;
4278 dst
[i
] = (GLint
) source
[i
];
4280 if (dstPacking
->SwapBytes
) {
4281 _mesa_swap4( (GLuint
*) dst
, n
);
4287 GLfloat
*dst
= (GLfloat
*) dest
;
4290 dst
[i
] = (GLfloat
) source
[i
];
4292 if (dstPacking
->SwapBytes
) {
4293 _mesa_swap4( (GLuint
*) dst
, n
);
4297 case GL_HALF_FLOAT_ARB
:
4299 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4302 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
4304 if (dstPacking
->SwapBytes
) {
4305 _mesa_swap2( (GLushort
*) dst
, n
);
4310 if (dstPacking
->LsbFirst
) {
4311 GLubyte
*dst
= (GLubyte
*) dest
;
4314 for (i
= 0; i
< n
; i
++) {
4317 *dst
|= ((source
[i
] != 0) << shift
);
4326 GLubyte
*dst
= (GLubyte
*) dest
;
4329 for (i
= 0; i
< n
; i
++) {
4332 *dst
|= ((source
[i
] != 0) << shift
);
4342 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
4346 #define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT) \
4349 const GLTYPE *src = (const GLTYPE *)source; \
4350 for (i = 0; i < n; i++) { \
4351 GLTYPE value = src[i]; \
4352 if (srcPacking->SwapBytes) { \
4353 if (sizeof(GLTYPE) == 2) { \
4355 } else if (sizeof(GLTYPE) == 4) { \
4359 depthValues[i] = GLTYPE2FLOAT(value); \
4365 * Unpack a row of depth/z values from memory, returning GLushort, GLuint
4366 * or GLfloat values.
4367 * The glPixelTransfer (scale/bias) params will be applied.
4369 * \param dstType one of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT
4370 * \param depthMax max value for returned GLushort or GLuint values
4371 * (ignored for GLfloat).
4374 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
,
4375 GLenum dstType
, GLvoid
*dest
, GLuint depthMax
,
4376 GLenum srcType
, const GLvoid
*source
,
4377 const struct gl_pixelstore_attrib
*srcPacking
)
4379 GLfloat depthTemp
[MAX_WIDTH
], *depthValues
;
4380 GLboolean needClamp
= GL_FALSE
;
4382 /* Look for special cases first.
4383 * Not only are these faster, they're less prone to numeric conversion
4384 * problems. Otherwise, converting from an int type to a float then
4385 * back to an int type can introduce errors that will show up as
4386 * artifacts in things like depth peeling which uses glCopyTexImage.
4388 if (ctx
->Pixel
.DepthScale
== 1.0 && ctx
->Pixel
.DepthBias
== 0.0) {
4389 if (srcType
== GL_UNSIGNED_INT
&& dstType
== GL_UNSIGNED_SHORT
) {
4390 const GLuint
*src
= (const GLuint
*) source
;
4391 GLushort
*dst
= (GLushort
*) dest
;
4393 for (i
= 0; i
< n
; i
++) {
4394 dst
[i
] = src
[i
] >> 16;
4398 if (srcType
== GL_UNSIGNED_SHORT
4399 && dstType
== GL_UNSIGNED_INT
4400 && depthMax
== 0xffffffff) {
4401 const GLushort
*src
= (const GLushort
*) source
;
4402 GLuint
*dst
= (GLuint
*) dest
;
4404 for (i
= 0; i
< n
; i
++) {
4405 dst
[i
] = src
[i
] | (src
[i
] << 16);
4409 /* XXX may want to add additional cases here someday */
4412 /* general case path follows */
4414 if (dstType
== GL_FLOAT
) {
4415 depthValues
= (GLfloat
*) dest
;
4418 depthValues
= depthTemp
;
4421 /* Convert incoming values to GLfloat. Some conversions will require
4426 DEPTH_VALUES(GLbyte
, BYTE_TO_FLOAT
);
4427 needClamp
= GL_TRUE
;
4429 case GL_UNSIGNED_BYTE
:
4430 DEPTH_VALUES(GLubyte
, UBYTE_TO_FLOAT
);
4433 DEPTH_VALUES(GLshort
, SHORT_TO_FLOAT
);
4434 needClamp
= GL_TRUE
;
4436 case GL_UNSIGNED_SHORT
:
4437 DEPTH_VALUES(GLushort
, USHORT_TO_FLOAT
);
4440 DEPTH_VALUES(GLint
, INT_TO_FLOAT
);
4441 needClamp
= GL_TRUE
;
4443 case GL_UNSIGNED_INT
:
4444 DEPTH_VALUES(GLuint
, UINT_TO_FLOAT
);
4446 case GL_UNSIGNED_INT_24_8_EXT
: /* GL_EXT_packed_depth_stencil */
4447 if (dstType
== GL_UNSIGNED_INT_24_8_EXT
&&
4448 depthMax
== 0xffffff &&
4449 ctx
->Pixel
.DepthScale
== 1.0 &&
4450 ctx
->Pixel
.DepthBias
== 0.0) {
4451 const GLuint
*src
= (const GLuint
*) source
;
4452 GLuint
*zValues
= (GLuint
*) dest
;
4454 for (i
= 0; i
< n
; i
++) {
4455 GLuint value
= src
[i
];
4456 if (srcPacking
->SwapBytes
) {
4459 zValues
[i
] = value
& 0xffffff00;
4464 const GLuint
*src
= (const GLuint
*) source
;
4465 const GLfloat scale
= 1.0f
/ 0xffffff;
4467 for (i
= 0; i
< n
; i
++) {
4468 GLuint value
= src
[i
];
4469 if (srcPacking
->SwapBytes
) {
4472 depthValues
[i
] = (value
>> 8) * scale
;
4477 DEPTH_VALUES(GLfloat
, 1*);
4478 needClamp
= GL_TRUE
;
4480 case GL_HALF_FLOAT_ARB
:
4483 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
4484 for (i
= 0; i
< n
; i
++) {
4485 GLhalfARB value
= src
[i
];
4486 if (srcPacking
->SwapBytes
) {
4489 depthValues
[i
] = _mesa_half_to_float(value
);
4491 needClamp
= GL_TRUE
;
4495 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
4499 /* apply depth scale and bias */
4501 const GLfloat scale
= ctx
->Pixel
.DepthScale
;
4502 const GLfloat bias
= ctx
->Pixel
.DepthBias
;
4503 if (scale
!= 1.0 || bias
!= 0.0) {
4505 for (i
= 0; i
< n
; i
++) {
4506 depthValues
[i
] = depthValues
[i
] * scale
+ bias
;
4508 needClamp
= GL_TRUE
;
4512 /* clamp to [0, 1] */
4515 for (i
= 0; i
< n
; i
++) {
4516 depthValues
[i
] = CLAMP(depthValues
[i
], 0.0, 1.0);
4521 * Convert values to dstType
4523 if (dstType
== GL_UNSIGNED_INT
) {
4524 GLuint
*zValues
= (GLuint
*) dest
;
4526 if (depthMax
<= 0xffffff) {
4527 /* no overflow worries */
4528 for (i
= 0; i
< n
; i
++) {
4529 zValues
[i
] = (GLuint
) (depthValues
[i
] * (GLfloat
) depthMax
);
4533 /* need to use double precision to prevent overflow problems */
4534 for (i
= 0; i
< n
; i
++) {
4535 GLdouble z
= depthValues
[i
] * (GLfloat
) depthMax
;
4536 if (z
>= (GLdouble
) 0xffffffff)
4537 zValues
[i
] = 0xffffffff;
4539 zValues
[i
] = (GLuint
) z
;
4543 else if (dstType
== GL_UNSIGNED_SHORT
) {
4544 GLushort
*zValues
= (GLushort
*) dest
;
4546 ASSERT(depthMax
<= 0xffff);
4547 for (i
= 0; i
< n
; i
++) {
4548 zValues
[i
] = (GLushort
) (depthValues
[i
] * (GLfloat
) depthMax
);
4552 ASSERT(dstType
== GL_FLOAT
);
4553 /*ASSERT(depthMax == 1.0F);*/
4559 * Pack an array of depth values. The values are floats in [0,1].
4562 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
4563 GLenum dstType
, const GLfloat
*depthSpan
,
4564 const struct gl_pixelstore_attrib
*dstPacking
)
4566 GLfloat depthCopy
[MAX_WIDTH
];
4568 ASSERT(n
<= MAX_WIDTH
);
4570 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4571 _mesa_memcpy(depthCopy
, depthSpan
, n
* sizeof(GLfloat
));
4572 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4573 depthSpan
= depthCopy
;
4577 case GL_UNSIGNED_BYTE
:
4579 GLubyte
*dst
= (GLubyte
*) dest
;
4581 for (i
= 0; i
< n
; i
++) {
4582 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
4588 GLbyte
*dst
= (GLbyte
*) dest
;
4590 for (i
= 0; i
< n
; i
++) {
4591 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
4595 case GL_UNSIGNED_SHORT
:
4597 GLushort
*dst
= (GLushort
*) dest
;
4599 for (i
= 0; i
< n
; i
++) {
4600 CLAMPED_FLOAT_TO_USHORT(dst
[i
], depthSpan
[i
]);
4602 if (dstPacking
->SwapBytes
) {
4603 _mesa_swap2( (GLushort
*) dst
, n
);
4609 GLshort
*dst
= (GLshort
*) dest
;
4611 for (i
= 0; i
< n
; i
++) {
4612 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
4614 if (dstPacking
->SwapBytes
) {
4615 _mesa_swap2( (GLushort
*) dst
, n
);
4619 case GL_UNSIGNED_INT
:
4621 GLuint
*dst
= (GLuint
*) dest
;
4623 for (i
= 0; i
< n
; i
++) {
4624 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
4626 if (dstPacking
->SwapBytes
) {
4627 _mesa_swap4( (GLuint
*) dst
, n
);
4633 GLint
*dst
= (GLint
*) dest
;
4635 for (i
= 0; i
< n
; i
++) {
4636 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
4638 if (dstPacking
->SwapBytes
) {
4639 _mesa_swap4( (GLuint
*) dst
, n
);
4645 GLfloat
*dst
= (GLfloat
*) dest
;
4647 for (i
= 0; i
< n
; i
++) {
4648 dst
[i
] = depthSpan
[i
];
4650 if (dstPacking
->SwapBytes
) {
4651 _mesa_swap4( (GLuint
*) dst
, n
);
4655 case GL_HALF_FLOAT_ARB
:
4657 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4659 for (i
= 0; i
< n
; i
++) {
4660 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
4662 if (dstPacking
->SwapBytes
) {
4663 _mesa_swap2( (GLushort
*) dst
, n
);
4668 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
4675 * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
4678 _mesa_pack_depth_stencil_span(const GLcontext
*ctx
, GLuint n
, GLuint
*dest
,
4679 const GLfloat
*depthVals
,
4680 const GLstencil
*stencilVals
,
4681 const struct gl_pixelstore_attrib
*dstPacking
)
4683 GLfloat depthCopy
[MAX_WIDTH
];
4684 GLstencil stencilCopy
[MAX_WIDTH
];
4687 ASSERT(n
<= MAX_WIDTH
);
4689 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4690 _mesa_memcpy(depthCopy
, depthVals
, n
* sizeof(GLfloat
));
4691 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4692 depthVals
= depthCopy
;
4695 if (ctx
->Pixel
.IndexShift
||
4696 ctx
->Pixel
.IndexOffset
||
4697 ctx
->Pixel
.MapStencilFlag
) {
4698 _mesa_memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
4699 _mesa_apply_stencil_transfer_ops(ctx
, n
, stencilCopy
);
4700 stencilVals
= stencilCopy
;
4703 for (i
= 0; i
< n
; i
++) {
4704 GLuint z
= (GLuint
) (depthVals
[i
] * 0xffffff);
4705 dest
[i
] = (z
<< 8) | (stencilVals
[i
] & 0xff);
4708 if (dstPacking
->SwapBytes
) {
4709 _mesa_swap4(dest
, n
);
4717 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
4718 * Return all image data in a contiguous block. This is used when we
4719 * compile glDrawPixels, glTexImage, etc into a display list. We
4720 * need a copy of the data in a standard format.
4723 _mesa_unpack_image( GLuint dimensions
,
4724 GLsizei width
, GLsizei height
, GLsizei depth
,
4725 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4726 const struct gl_pixelstore_attrib
*unpack
)
4728 GLint bytesPerRow
, compsPerRow
;
4729 GLboolean flipBytes
, swap2
, swap4
;
4732 return NULL
; /* not necessarily an error */
4734 if (width
<= 0 || height
<= 0 || depth
<= 0)
4735 return NULL
; /* generate error later */
4737 if (type
== GL_BITMAP
) {
4738 bytesPerRow
= (width
+ 7) >> 3;
4739 flipBytes
= unpack
->LsbFirst
;
4740 swap2
= swap4
= GL_FALSE
;
4744 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
4745 GLint components
= _mesa_components_in_format(format
);
4748 if (_mesa_type_is_packed(type
))
4751 if (bytesPerPixel
<= 0 || components
<= 0)
4752 return NULL
; /* bad format or type. generate error later */
4753 bytesPerRow
= bytesPerPixel
* width
;
4754 bytesPerComp
= bytesPerPixel
/ components
;
4755 flipBytes
= GL_FALSE
;
4756 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
4757 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
4758 compsPerRow
= components
* width
;
4759 assert(compsPerRow
>= width
);
4764 = (GLubyte
*) _mesa_malloc(bytesPerRow
* height
* depth
);
4768 return NULL
; /* generate GL_OUT_OF_MEMORY later */
4771 for (img
= 0; img
< depth
; img
++) {
4772 for (row
= 0; row
< height
; row
++) {
4773 const GLvoid
*src
= _mesa_image_address(dimensions
, unpack
, pixels
,
4774 width
, height
, format
, type
, img
, row
, 0);
4776 if ((type
== GL_BITMAP
) && (unpack
->SkipPixels
& 0x7)) {
4778 flipBytes
= GL_FALSE
;
4779 if (unpack
->LsbFirst
) {
4780 GLubyte srcMask
= 1 << (unpack
->SkipPixels
& 0x7);
4781 GLubyte dstMask
= 128;
4782 const GLubyte
*s
= src
;
4785 for (i
= 0; i
< width
; i
++) {
4789 if (srcMask
== 128) {
4794 srcMask
= srcMask
<< 1;
4802 dstMask
= dstMask
>> 1;
4807 GLubyte srcMask
= 128 >> (unpack
->SkipPixels
& 0x7);
4808 GLubyte dstMask
= 128;
4809 const GLubyte
*s
= src
;
4812 for (i
= 0; i
< width
; i
++) {
4821 srcMask
= srcMask
>> 1;
4829 dstMask
= dstMask
>> 1;
4835 _mesa_memcpy(dst
, src
, bytesPerRow
);
4838 /* byte flipping/swapping */
4840 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
4843 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
4846 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
4855 #endif /* _HAVE_FULL_GL */
4860 * Convert an array of RGBA colors from one datatype to another.
4861 * NOTE: src may equal dst. In that case, we use a temporary buffer.
4864 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
4865 GLenum dstType
, GLvoid
*dst
,
4866 GLuint count
, const GLubyte mask
[])
4868 GLuint tempBuffer
[MAX_WIDTH
][4];
4869 const GLboolean useTemp
= (src
== dst
);
4871 ASSERT(srcType
!= dstType
);
4874 case GL_UNSIGNED_BYTE
:
4875 if (dstType
== GL_UNSIGNED_SHORT
) {
4876 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
4877 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
4879 for (i
= 0; i
< count
; i
++) {
4880 if (!mask
|| mask
[i
]) {
4881 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
4882 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
4883 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
4884 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
4888 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
4891 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
4892 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
4894 ASSERT(dstType
== GL_FLOAT
);
4895 for (i
= 0; i
< count
; i
++) {
4896 if (!mask
|| mask
[i
]) {
4897 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
4898 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
4899 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
4900 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
4904 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
4907 case GL_UNSIGNED_SHORT
:
4908 if (dstType
== GL_UNSIGNED_BYTE
) {
4909 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
4910 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
4912 for (i
= 0; i
< count
; i
++) {
4913 if (!mask
|| mask
[i
]) {
4914 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
4915 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
4916 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
4917 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
4921 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
4924 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
4925 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
4927 ASSERT(dstType
== GL_FLOAT
);
4928 for (i
= 0; i
< count
; i
++) {
4929 if (!mask
|| mask
[i
]) {
4930 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
4931 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
4932 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
4933 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
4937 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
4941 if (dstType
== GL_UNSIGNED_BYTE
) {
4942 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
4943 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
4945 for (i
= 0; i
< count
; i
++) {
4946 if (!mask
|| mask
[i
]) {
4947 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
4948 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
4949 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
4950 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
4954 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
4957 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
4958 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
4960 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
4961 for (i
= 0; i
< count
; i
++) {
4962 if (!mask
|| mask
[i
]) {
4963 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
4964 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
4965 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
4966 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
4970 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
4974 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
4982 * Perform basic clipping for glDrawPixels. The image's position and size
4983 * and the unpack SkipPixels and SkipRows are adjusted so that the image
4984 * region is entirely within the window and scissor bounds.
4985 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
4986 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
4987 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
4989 * \return GL_TRUE if image is ready for drawing or
4990 * GL_FALSE if image was completely clipped away (draw nothing)
4993 _mesa_clip_drawpixels(const GLcontext
*ctx
,
4994 GLint
*destX
, GLint
*destY
,
4995 GLsizei
*width
, GLsizei
*height
,
4996 struct gl_pixelstore_attrib
*unpack
)
4998 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
5000 if (unpack
->RowLength
== 0) {
5001 unpack
->RowLength
= *width
;
5004 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
5005 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
5008 if (*destX
< buffer
->_Xmin
) {
5009 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
5010 *width
-= (buffer
->_Xmin
- *destX
);
5011 *destX
= buffer
->_Xmin
;
5013 /* right clipping */
5014 if (*destX
+ *width
> buffer
->_Xmax
)
5015 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
5020 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
5021 /* bottom clipping */
5022 if (*destY
< buffer
->_Ymin
) {
5023 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
5024 *height
-= (buffer
->_Ymin
- *destY
);
5025 *destY
= buffer
->_Ymin
;
5028 if (*destY
+ *height
> buffer
->_Ymax
)
5029 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
5031 else { /* upside down */
5033 if (*destY
> buffer
->_Ymax
) {
5034 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
5035 *height
-= (*destY
- buffer
->_Ymax
);
5036 *destY
= buffer
->_Ymax
;
5038 /* bottom clipping */
5039 if (*destY
- *height
< buffer
->_Ymin
)
5040 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
5041 /* adjust destY so it's the first row to write to */
5053 * Perform clipping for glReadPixels. The image's window position
5054 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
5055 * so that the image region is entirely within the window bounds.
5056 * Note: this is different from _mesa_clip_drawpixels() in that the
5057 * scissor box is ignored, and we use the bounds of the current readbuffer
5060 * \return GL_TRUE if image is ready for drawing or
5061 * GL_FALSE if image was completely clipped away (draw nothing)
5064 _mesa_clip_readpixels(const GLcontext
*ctx
,
5065 GLint
*srcX
, GLint
*srcY
,
5066 GLsizei
*width
, GLsizei
*height
,
5067 struct gl_pixelstore_attrib
*pack
)
5069 const GLframebuffer
*buffer
= ctx
->ReadBuffer
;
5071 if (pack
->RowLength
== 0) {
5072 pack
->RowLength
= *width
;
5077 pack
->SkipPixels
+= (0 - *srcX
);
5078 *width
-= (0 - *srcX
);
5081 /* right clipping */
5082 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
5083 *width
-= (*srcX
+ *width
- buffer
->Width
);
5088 /* bottom clipping */
5090 pack
->SkipRows
+= (0 - *srcY
);
5091 *height
-= (0 - *srcY
);
5095 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
5096 *height
-= (*srcY
+ *height
- buffer
->Height
);
5106 * Clip the rectangle defined by (x, y, width, height) against the bounds
5107 * specified by [xmin, xmax) and [ymin, ymax).
5108 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
5111 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
5112 GLint xmax
, GLint ymax
,
5114 GLsizei
*width
, GLsizei
*height
)
5118 *width
-= (xmin
- *x
);
5122 /* right clipping */
5123 if (*x
+ *width
> xmax
)
5124 *width
-= (*x
+ *width
- xmax
- 1);
5129 /* bottom (or top) clipping */
5131 *height
-= (ymin
- *y
);
5135 /* top (or bottom) clipping */
5136 if (*y
+ *height
> ymax
)
5137 *height
-= (*y
+ *height
- ymax
- 1);