2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 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.
33 #include "bufferobj.h"
38 #include "histogram.h"
44 /** Compute ceiling of integer quotient of A divided by B. */
45 #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
49 * Flip the 8 bits in each byte of the given array.
52 * \param n number of bytes.
54 * \todo try this trick to flip bytes someday:
56 * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555);
57 * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333);
58 * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f);
62 flip_bytes( GLubyte
*p
, GLuint n
)
64 register GLuint i
, a
, b
;
67 b
= (GLuint
) p
[i
]; /* words are often faster than bytes */
68 a
= ((b
& 0x01) << 7) |
82 * Flip the order of the 2 bytes in each word in the given array.
85 * \param n number of words.
88 _mesa_swap2( GLushort
*p
, GLuint n
)
93 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
100 * Flip the order of the 4 bytes in each word in the given array.
103 _mesa_swap4( GLuint
*p
, GLuint n
)
105 register GLuint i
, a
, b
;
110 | ((b
>> 8) & 0xff00)
111 | ((b
<< 8) & 0xff0000)
112 | ((b
<< 24) & 0xff000000);
119 * Get the size of a GL data type.
121 * \param type GL data type.
123 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
124 * if an invalid type enum.
126 GLint
_mesa_sizeof_type( GLenum type
)
131 case GL_UNSIGNED_BYTE
:
132 return sizeof(GLubyte
);
134 return sizeof(GLbyte
);
135 case GL_UNSIGNED_SHORT
:
136 return sizeof(GLushort
);
138 return sizeof(GLshort
);
139 case GL_UNSIGNED_INT
:
140 return sizeof(GLuint
);
142 return sizeof(GLint
);
144 return sizeof(GLfloat
);
145 case GL_HALF_FLOAT_ARB
:
146 return sizeof(GLhalfARB
);
154 * Same as _mesa_sizeof_type() but also accepting the packed pixel
157 GLint
_mesa_sizeof_packed_type( GLenum type
)
162 case GL_UNSIGNED_BYTE
:
163 return sizeof(GLubyte
);
165 return sizeof(GLbyte
);
166 case GL_UNSIGNED_SHORT
:
167 return sizeof(GLushort
);
169 return sizeof(GLshort
);
170 case GL_UNSIGNED_INT
:
171 return sizeof(GLuint
);
173 return sizeof(GLint
);
174 case GL_HALF_FLOAT_ARB
:
175 return sizeof(GLhalfARB
);
177 return sizeof(GLfloat
);
178 case GL_UNSIGNED_BYTE_3_3_2
:
179 return sizeof(GLubyte
);
180 case GL_UNSIGNED_BYTE_2_3_3_REV
:
181 return sizeof(GLubyte
);
182 case GL_UNSIGNED_SHORT_5_6_5
:
183 return sizeof(GLushort
);
184 case GL_UNSIGNED_SHORT_5_6_5_REV
:
185 return sizeof(GLushort
);
186 case GL_UNSIGNED_SHORT_4_4_4_4
:
187 return sizeof(GLushort
);
188 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
189 return sizeof(GLushort
);
190 case GL_UNSIGNED_SHORT_5_5_5_1
:
191 return sizeof(GLushort
);
192 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
193 return sizeof(GLushort
);
194 case GL_UNSIGNED_INT_8_8_8_8
:
195 return sizeof(GLuint
);
196 case GL_UNSIGNED_INT_8_8_8_8_REV
:
197 return sizeof(GLuint
);
198 case GL_UNSIGNED_INT_10_10_10_2
:
199 return sizeof(GLuint
);
200 case GL_UNSIGNED_INT_2_10_10_10_REV
:
201 return sizeof(GLuint
);
202 case GL_UNSIGNED_SHORT_8_8_MESA
:
203 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
204 return sizeof(GLushort
);
212 * Get the number of components in a pixel format.
214 * \param format pixel format.
216 * \return the number of components in the given format, or -1 if a bad format.
218 GLint
_mesa_components_in_format( GLenum format
)
222 case GL_COLOR_INDEX1_EXT
:
223 case GL_COLOR_INDEX2_EXT
:
224 case GL_COLOR_INDEX4_EXT
:
225 case GL_COLOR_INDEX8_EXT
:
226 case GL_COLOR_INDEX12_EXT
:
227 case GL_COLOR_INDEX16_EXT
:
228 case GL_STENCIL_INDEX
:
229 case GL_DEPTH_COMPONENT
:
237 case GL_LUMINANCE_ALPHA
:
258 * Get the bytes per pixel of pixel format type pair.
260 * \param format pixel format.
261 * \param type pixel type.
263 * \return bytes per pixel, or -1 if a bad format or type was given.
265 GLint
_mesa_bytes_per_pixel( GLenum format
, GLenum type
)
267 GLint comps
= _mesa_components_in_format( format
);
273 return 0; /* special case */
275 case GL_UNSIGNED_BYTE
:
276 return comps
* sizeof(GLubyte
);
278 case GL_UNSIGNED_SHORT
:
279 return comps
* sizeof(GLshort
);
281 case GL_UNSIGNED_INT
:
282 return comps
* sizeof(GLint
);
284 return comps
* sizeof(GLfloat
);
285 case GL_HALF_FLOAT_ARB
:
286 return comps
* sizeof(GLhalfARB
);
287 case GL_UNSIGNED_BYTE_3_3_2
:
288 case GL_UNSIGNED_BYTE_2_3_3_REV
:
289 if (format
== GL_RGB
|| format
== GL_BGR
)
290 return sizeof(GLubyte
);
292 return -1; /* error */
293 case GL_UNSIGNED_SHORT_5_6_5
:
294 case GL_UNSIGNED_SHORT_5_6_5_REV
:
295 if (format
== GL_RGB
|| format
== GL_BGR
)
296 return sizeof(GLushort
);
298 return -1; /* error */
299 case GL_UNSIGNED_SHORT_4_4_4_4
:
300 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
301 case GL_UNSIGNED_SHORT_5_5_5_1
:
302 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
303 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
304 return sizeof(GLushort
);
307 case GL_UNSIGNED_INT_8_8_8_8
:
308 case GL_UNSIGNED_INT_8_8_8_8_REV
:
309 case GL_UNSIGNED_INT_10_10_10_2
:
310 case GL_UNSIGNED_INT_2_10_10_10_REV
:
311 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
312 return sizeof(GLuint
);
315 case GL_UNSIGNED_SHORT_8_8_MESA
:
316 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
317 if (format
== GL_YCBCR_MESA
)
318 return sizeof(GLushort
);
328 * Test for a legal pixel format and type.
330 * \param format pixel format.
331 * \param type pixel type.
333 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
337 _mesa_is_legal_format_and_type( GLcontext
*ctx
, GLenum format
, GLenum type
)
341 case GL_STENCIL_INDEX
:
345 case GL_UNSIGNED_BYTE
:
347 case GL_UNSIGNED_SHORT
:
349 case GL_UNSIGNED_INT
:
352 case GL_HALF_FLOAT_ARB
:
353 return ctx
->Extensions
.ARB_half_float_pixel
;
361 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
365 case GL_LUMINANCE_ALPHA
:
366 case GL_DEPTH_COMPONENT
:
369 case GL_UNSIGNED_BYTE
:
371 case GL_UNSIGNED_SHORT
:
373 case GL_UNSIGNED_INT
:
376 case GL_HALF_FLOAT_ARB
:
377 return ctx
->Extensions
.ARB_half_float_pixel
;
384 case GL_UNSIGNED_BYTE
:
386 case GL_UNSIGNED_SHORT
:
388 case GL_UNSIGNED_INT
:
390 case GL_UNSIGNED_BYTE_3_3_2
:
391 case GL_UNSIGNED_BYTE_2_3_3_REV
:
392 case GL_UNSIGNED_SHORT_5_6_5
:
393 case GL_UNSIGNED_SHORT_5_6_5_REV
:
395 case GL_HALF_FLOAT_ARB
:
396 return ctx
->Extensions
.ARB_half_float_pixel
;
403 case GL_UNSIGNED_BYTE
:
405 case GL_UNSIGNED_SHORT
:
407 case GL_UNSIGNED_INT
:
410 case GL_HALF_FLOAT_ARB
:
411 return ctx
->Extensions
.ARB_half_float_pixel
;
420 case GL_UNSIGNED_BYTE
:
422 case GL_UNSIGNED_SHORT
:
424 case GL_UNSIGNED_INT
:
426 case GL_UNSIGNED_SHORT_4_4_4_4
:
427 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
428 case GL_UNSIGNED_SHORT_5_5_5_1
:
429 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
430 case GL_UNSIGNED_INT_8_8_8_8
:
431 case GL_UNSIGNED_INT_8_8_8_8_REV
:
432 case GL_UNSIGNED_INT_10_10_10_2
:
433 case GL_UNSIGNED_INT_2_10_10_10_REV
:
435 case GL_HALF_FLOAT_ARB
:
436 return ctx
->Extensions
.ARB_half_float_pixel
;
441 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
442 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
454 * Return the address of a specific pixel in an image (1D, 2D or 3D).
456 * Pixel unpacking/packing parameters are observed according to \p packing.
458 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
459 * \param image starting address of image data
460 * \param width the image width
461 * \param height theimage height
462 * \param format the pixel format
463 * \param type the pixel data type
464 * \param packing the pixelstore attributes
465 * \param img which image in the volume (0 for 1D or 2D images)
466 * \param row row of pixel in the image (0 for 1D images)
467 * \param column column of pixel in the image
469 * \return address of pixel on success, or NULL on error.
471 * \sa gl_pixelstore_attrib.
474 _mesa_image_address( GLuint dimensions
,
475 const struct gl_pixelstore_attrib
*packing
,
477 GLsizei width
, GLsizei height
,
478 GLenum format
, GLenum type
,
479 GLint img
, GLint row
, GLint column
)
481 GLint alignment
; /* 1, 2 or 4 */
482 GLint pixels_per_row
;
483 GLint rows_per_image
;
486 GLint skipimages
; /* for 3-D volume images */
489 ASSERT(dimensions
>= 1 && dimensions
<= 3);
491 alignment
= packing
->Alignment
;
492 if (packing
->RowLength
> 0) {
493 pixels_per_row
= packing
->RowLength
;
496 pixels_per_row
= width
;
498 if (packing
->ImageHeight
> 0) {
499 rows_per_image
= packing
->ImageHeight
;
502 rows_per_image
= height
;
505 skippixels
= packing
->SkipPixels
;
506 /* Note: SKIP_ROWS _is_ used for 1D images */
507 skiprows
= packing
->SkipRows
;
508 /* Note: SKIP_IMAGES is only used for 3D images */
509 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
511 if (type
== GL_BITMAP
) {
513 GLint comp_per_pixel
; /* components per pixel */
514 GLint bytes_per_comp
; /* bytes per component */
516 GLint bytes_per_image
;
518 /* Compute bytes per component */
519 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
520 if (bytes_per_comp
< 0) {
524 /* Compute number of components per pixel */
525 comp_per_pixel
= _mesa_components_in_format( format
);
526 if (comp_per_pixel
< 0) {
530 bytes_per_row
= alignment
531 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
533 bytes_per_image
= bytes_per_row
* rows_per_image
;
535 pixel_addr
= (GLubyte
*) image
536 + (skipimages
+ img
) * bytes_per_image
537 + (skiprows
+ row
) * bytes_per_row
538 + (skippixels
+ column
) / 8;
541 /* Non-BITMAP data */
542 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
545 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
547 /* The pixel type and format should have been error checked earlier */
548 assert(bytes_per_pixel
> 0);
550 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
551 remainder
= bytes_per_row
% alignment
;
553 bytes_per_row
+= (alignment
- remainder
);
555 ASSERT(bytes_per_row
% alignment
== 0);
557 bytes_per_image
= bytes_per_row
* rows_per_image
;
559 if (packing
->Invert
) {
560 /* set pixel_addr to the last row */
561 topOfImage
= bytes_per_row
* (height
- 1);
562 bytes_per_row
= -bytes_per_row
;
568 /* compute final pixel address */
569 pixel_addr
= (GLubyte
*) image
570 + (skipimages
+ img
) * bytes_per_image
572 + (skiprows
+ row
) * bytes_per_row
573 + (skippixels
+ column
) * bytes_per_pixel
;
576 return (GLvoid
*) pixel_addr
;
581 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
584 GLenum format
, GLenum type
,
587 return _mesa_image_address(1, packing
, image
, width
, 1,
588 format
, type
, 0, 0, column
);
593 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
595 GLsizei width
, GLsizei height
,
596 GLenum format
, GLenum type
,
597 GLint row
, GLint column
)
599 return _mesa_image_address(2, packing
, image
, width
, height
,
600 format
, type
, 0, row
, column
);
605 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
607 GLsizei width
, GLsizei height
,
608 GLenum format
, GLenum type
,
609 GLint img
, GLint row
, GLint column
)
611 return _mesa_image_address(3, packing
, image
, width
, height
,
612 format
, type
, img
, row
, column
);
618 * Compute the stride between image rows.
620 * \param packing the pixelstore attributes
621 * \param width image width.
622 * \param format pixel format.
623 * \param type pixel data type.
625 * \return the stride in bytes for the given parameters.
627 * Computes the number of bytes per pixel and row and compensates for alignment.
629 * \sa gl_pixelstore_attrib.
632 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
633 GLint width
, GLenum format
, GLenum type
)
636 if (type
== GL_BITMAP
) {
639 if (packing
->RowLength
== 0) {
640 bytes
= (width
+ 7) / 8;
643 bytes
= (packing
->RowLength
+ 7) / 8;
645 if (packing
->Invert
) {
646 /* negate the bytes per row (negative row stride) */
652 /* Non-BITMAP data */
653 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
654 GLint bytesPerRow
, remainder
;
655 if (bytesPerPixel
<= 0)
656 return -1; /* error */
657 if (packing
->RowLength
== 0) {
658 bytesPerRow
= bytesPerPixel
* width
;
661 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
663 remainder
= bytesPerRow
% packing
->Alignment
;
665 bytesPerRow
+= (packing
->Alignment
- remainder
);
667 bytesPerRow
= -bytesPerRow
;
676 * Compute the stride between images in a 3D texture (in bytes) for the given
677 * pixel packing parameters and image width, format and type.
680 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
681 GLint width
, GLint height
,
682 GLenum format
, GLenum type
)
685 ASSERT(type
!= GL_BITMAP
);
688 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
689 GLint bytesPerRow
, bytesPerImage
, remainder
;
691 if (bytesPerPixel
<= 0)
692 return -1; /* error */
693 if (packing
->RowLength
== 0) {
694 bytesPerRow
= bytesPerPixel
* width
;
697 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
699 remainder
= bytesPerRow
% packing
->Alignment
;
701 bytesPerRow
+= (packing
->Alignment
- remainder
);
703 if (packing
->ImageHeight
== 0)
704 bytesPerImage
= bytesPerRow
* height
;
706 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
708 return bytesPerImage
;
714 * Unpack a 32x32 pixel polygon stipple from user memory using the
715 * current pixel unpack settings.
718 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
719 const struct gl_pixelstore_attrib
*unpacking
)
721 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap( 32, 32, pattern
, unpacking
);
723 /* Convert pattern from GLubytes to GLuints and handle big/little
728 for (i
= 0; i
< 32; i
++) {
729 dest
[i
] = (p
[0] << 24)
741 * Pack polygon stipple into user memory given current pixel packing
745 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
746 const struct gl_pixelstore_attrib
*packing
)
748 /* Convert pattern from GLuints to GLubytes to handle big/little
749 * endian differences.
753 for (i
= 0; i
< 32; i
++) {
754 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
755 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
756 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
757 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
760 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
765 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
766 * order with row alignment = 1 byte.
769 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
770 const struct gl_pixelstore_attrib
*packing
)
772 GLint bytes
, row
, width_in_bytes
;
773 GLubyte
*buffer
, *dst
;
778 /* Alloc dest storage */
779 bytes
= ((width
+ 7) / 8 * height
);
780 buffer
= (GLubyte
*) MALLOC( bytes
);
785 width_in_bytes
= CEILING( width
, 8 );
787 for (row
= 0; row
< height
; row
++) {
788 const GLubyte
*src
= (const GLubyte
*)
789 _mesa_image_address2d(packing
, pixels
, width
, height
,
790 GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
796 if (packing
->SkipPixels
== 0) {
797 MEMCPY( dst
, src
, width_in_bytes
);
798 if (packing
->LsbFirst
) {
799 flip_bytes( dst
, width_in_bytes
);
803 /* handling SkipPixels is a bit tricky (no pun intended!) */
805 if (packing
->LsbFirst
) {
806 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
807 GLubyte dstMask
= 128;
808 const GLubyte
*s
= src
;
811 for (i
= 0; i
< width
; i
++) {
815 if (srcMask
== 128) {
820 srcMask
= srcMask
<< 1;
828 dstMask
= dstMask
>> 1;
833 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
834 GLubyte dstMask
= 128;
835 const GLubyte
*s
= src
;
838 for (i
= 0; i
< width
; i
++) {
847 srcMask
= srcMask
>> 1;
855 dstMask
= dstMask
>> 1;
860 dst
+= width_in_bytes
;
871 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
872 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
874 GLint row
, width_in_bytes
;
880 width_in_bytes
= CEILING( width
, 8 );
882 for (row
= 0; row
< height
; row
++) {
883 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dest
,
884 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
888 if (packing
->SkipPixels
== 0) {
889 MEMCPY( dst
, src
, width_in_bytes
);
890 if (packing
->LsbFirst
) {
891 flip_bytes( dst
, width_in_bytes
);
895 /* handling SkipPixels is a bit tricky (no pun intended!) */
897 if (packing
->LsbFirst
) {
898 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
899 GLubyte dstMask
= 128;
900 const GLubyte
*s
= src
;
903 for (i
= 0; i
< width
; i
++) {
907 if (srcMask
== 128) {
912 srcMask
= srcMask
<< 1;
920 dstMask
= dstMask
>> 1;
925 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
926 GLubyte dstMask
= 128;
927 const GLubyte
*s
= src
;
930 for (i
= 0; i
< width
; i
++) {
939 srcMask
= srcMask
>> 1;
947 dstMask
= dstMask
>> 1;
952 src
+= width_in_bytes
;
958 * Apply various pixel transfer operations to an array of RGBA pixels
959 * as indicated by the transferOps bitmask
962 _mesa_apply_rgba_transfer_ops(GLcontext
*ctx
, GLuint transferOps
,
963 GLuint n
, GLfloat rgba
[][4])
966 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
967 _mesa_scale_and_bias_rgba(n
, rgba
,
968 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
969 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
970 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
971 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
973 /* color map lookup */
974 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
975 _mesa_map_rgba( ctx
, n
, rgba
);
977 /* GL_COLOR_TABLE lookup */
978 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
979 _mesa_lookup_rgba_float(&ctx
->ColorTable
, n
, rgba
);
982 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
983 /* this has to be done in the calling code */
984 _mesa_problem(ctx
, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");
986 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
987 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
988 _mesa_scale_and_bias_rgba(n
, rgba
,
989 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
990 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
991 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
992 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
993 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
994 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
995 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
996 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
998 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
999 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
1000 _mesa_lookup_rgba_float(&ctx
->PostConvolutionColorTable
, n
, rgba
);
1002 /* color matrix transform */
1003 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
1004 _mesa_transform_rgba(ctx
, n
, rgba
);
1006 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
1007 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
1008 _mesa_lookup_rgba_float(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
1010 /* update histogram count */
1011 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
1012 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1014 /* update min/max values */
1015 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
1016 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1018 /* clamping to [0,1] */
1019 if (transferOps
& IMAGE_CLAMP_BIT
) {
1021 for (i
= 0; i
< n
; i
++) {
1022 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1023 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1024 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1025 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1033 * Used to pack an array [][4] of RGBA float colors as specified
1034 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
1035 * glGetConvolutionFilter(), etc.
1038 _mesa_pack_rgba_span_float( GLcontext
*ctx
,
1039 GLuint n
, CONST GLfloat rgbaIn
[][4],
1040 GLenum dstFormat
, GLenum dstType
,
1042 const struct gl_pixelstore_attrib
*dstPacking
,
1043 GLuint transferOps
)
1045 const GLint comps
= _mesa_components_in_format(dstFormat
);
1046 GLfloat luminance
[MAX_WIDTH
];
1047 const GLfloat (*rgba
)[4];
1051 /* make copy of incoming data */
1052 DEFMARRAY(GLfloat
, rgbaCopy
, MAX_WIDTH
, 4); /* mac 32k limitation */
1053 CHECKARRAY(rgbaCopy
, return); /* mac 32k limitation */
1055 _mesa_memcpy(rgbaCopy
, rgbaIn
, n
* 4 * sizeof(GLfloat
));
1056 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgbaCopy
);
1057 rgba
= (const GLfloat (*)[4]) rgbaCopy
;
1059 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
1060 UNDEFARRAY(rgbaCopy
); /* mac 32k limitation */
1063 UNDEFARRAY(rgbaCopy
); /* mac 32k limitation */
1066 /* use incoming data, not a copy */
1067 rgba
= (const GLfloat (*)[4]) rgbaIn
;
1070 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
1071 /* compute luminance values */
1072 if (ctx
->ClampFragmentColors
) {
1073 for (i
= 0; i
< n
; i
++) {
1074 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1075 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
1079 for (i
= 0; i
< n
; i
++) {
1080 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1086 * Pack/store the pixels. Ugh! Lots of cases!!!
1089 case GL_UNSIGNED_BYTE
:
1091 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1092 switch (dstFormat
) {
1095 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1099 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1103 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1107 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1111 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1113 case GL_LUMINANCE_ALPHA
:
1115 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1116 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1121 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1122 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1123 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1128 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1129 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1130 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1131 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1136 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1137 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1138 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1143 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1144 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1145 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1146 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1151 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1152 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1153 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1154 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1158 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1164 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1165 switch (dstFormat
) {
1168 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1172 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1176 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1180 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1184 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1186 case GL_LUMINANCE_ALPHA
:
1188 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1189 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1194 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1195 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1196 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1201 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1202 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1203 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1204 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1209 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1210 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1211 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1216 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1217 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1218 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1219 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1223 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1224 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1225 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1226 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1230 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1234 case GL_UNSIGNED_SHORT
:
1236 GLushort
*dst
= (GLushort
*) dstAddr
;
1237 switch (dstFormat
) {
1240 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1244 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1248 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1252 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1256 dst
[i
] = FLOAT_TO_USHORT(luminance
[i
]);
1258 case GL_LUMINANCE_ALPHA
:
1260 dst
[i
*2+0] = FLOAT_TO_USHORT(luminance
[i
]);
1261 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1266 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1267 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1268 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1273 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1274 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1275 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1276 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1281 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1282 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1283 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1288 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1289 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1290 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1291 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1296 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1297 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1298 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1299 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1303 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1305 if (dstPacking
->SwapBytes
) {
1306 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1312 GLshort
*dst
= (GLshort
*) dstAddr
;
1313 switch (dstFormat
) {
1316 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1320 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1324 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1328 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1332 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
1334 case GL_LUMINANCE_ALPHA
:
1336 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
1337 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1342 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1343 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1344 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1349 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1350 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1351 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1352 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1357 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1358 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1359 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1364 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1365 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1366 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1367 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1371 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1372 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1373 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1374 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1378 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1380 if (dstPacking
->SwapBytes
) {
1381 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1385 case GL_UNSIGNED_INT
:
1387 GLuint
*dst
= (GLuint
*) dstAddr
;
1388 switch (dstFormat
) {
1391 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1395 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1399 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1403 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1407 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
1409 case GL_LUMINANCE_ALPHA
:
1411 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
1412 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1417 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1418 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1419 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1424 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1425 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1426 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1427 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1432 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1433 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1434 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1439 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1440 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1441 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1442 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1447 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1448 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1449 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1450 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1454 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1456 if (dstPacking
->SwapBytes
) {
1457 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1463 GLint
*dst
= (GLint
*) dstAddr
;
1464 switch (dstFormat
) {
1467 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1471 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1475 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1479 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1483 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1485 case GL_LUMINANCE_ALPHA
:
1487 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1488 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1493 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1494 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1495 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1500 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1501 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1502 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1503 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1508 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1509 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1510 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1515 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1516 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1517 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1518 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1523 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1524 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1525 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1526 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1530 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1532 if (dstPacking
->SwapBytes
) {
1533 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1539 GLfloat
*dst
= (GLfloat
*) dstAddr
;
1540 switch (dstFormat
) {
1543 dst
[i
] = rgba
[i
][RCOMP
];
1547 dst
[i
] = rgba
[i
][GCOMP
];
1551 dst
[i
] = rgba
[i
][BCOMP
];
1555 dst
[i
] = rgba
[i
][ACOMP
];
1559 dst
[i
] = luminance
[i
];
1561 case GL_LUMINANCE_ALPHA
:
1563 dst
[i
*2+0] = luminance
[i
];
1564 dst
[i
*2+1] = rgba
[i
][ACOMP
];
1569 dst
[i
*3+0] = rgba
[i
][RCOMP
];
1570 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1571 dst
[i
*3+2] = rgba
[i
][BCOMP
];
1576 dst
[i
*4+0] = rgba
[i
][RCOMP
];
1577 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1578 dst
[i
*4+2] = rgba
[i
][BCOMP
];
1579 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1584 dst
[i
*3+0] = rgba
[i
][BCOMP
];
1585 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1586 dst
[i
*3+2] = rgba
[i
][RCOMP
];
1591 dst
[i
*4+0] = rgba
[i
][BCOMP
];
1592 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1593 dst
[i
*4+2] = rgba
[i
][RCOMP
];
1594 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1599 dst
[i
*4+0] = rgba
[i
][ACOMP
];
1600 dst
[i
*4+1] = rgba
[i
][BCOMP
];
1601 dst
[i
*4+2] = rgba
[i
][GCOMP
];
1602 dst
[i
*4+3] = rgba
[i
][RCOMP
];
1606 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1608 if (dstPacking
->SwapBytes
) {
1609 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1613 case GL_HALF_FLOAT_ARB
:
1615 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
1616 switch (dstFormat
) {
1619 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1623 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1627 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1631 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1635 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
1637 case GL_LUMINANCE_ALPHA
:
1639 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
1640 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1645 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1646 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1647 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1652 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1653 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1654 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1655 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1660 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1661 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1662 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1667 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1668 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1669 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1670 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1675 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1676 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1677 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1678 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1682 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1684 if (dstPacking
->SwapBytes
) {
1685 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1689 case GL_UNSIGNED_BYTE_3_3_2
:
1690 if (dstFormat
== GL_RGB
) {
1691 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1693 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
1694 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
1695 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
1699 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1700 if (dstFormat
== GL_RGB
) {
1701 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1703 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
1704 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
1705 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 5);
1709 case GL_UNSIGNED_SHORT_5_6_5
:
1710 if (dstFormat
== GL_RGB
) {
1711 GLushort
*dst
= (GLushort
*) dstAddr
;
1713 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1714 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1715 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
1719 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1720 if (dstFormat
== GL_RGB
) {
1721 GLushort
*dst
= (GLushort
*) dstAddr
;
1723 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1724 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1725 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
1729 case GL_UNSIGNED_SHORT_4_4_4_4
:
1730 if (dstFormat
== GL_RGBA
) {
1731 GLushort
*dst
= (GLushort
*) dstAddr
;
1733 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
1734 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1735 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1736 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1739 else if (dstFormat
== GL_BGRA
) {
1740 GLushort
*dst
= (GLushort
*) dstAddr
;
1742 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 12)
1743 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1744 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 4)
1745 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1748 else if (dstFormat
== GL_ABGR_EXT
) {
1749 GLushort
*dst
= (GLushort
*) dstAddr
;
1751 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 4)
1752 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1753 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 12)
1754 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) );
1758 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1759 if (dstFormat
== GL_RGBA
) {
1760 GLushort
*dst
= (GLushort
*) dstAddr
;
1762 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
1763 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1764 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1765 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1768 else if (dstFormat
== GL_BGRA
) {
1769 GLushort
*dst
= (GLushort
*) dstAddr
;
1771 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) )
1772 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1773 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 8)
1774 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1777 else if (dstFormat
== GL_ABGR_EXT
) {
1778 GLushort
*dst
= (GLushort
*) dstAddr
;
1780 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) )
1781 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1782 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1783 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12);
1787 case GL_UNSIGNED_SHORT_5_5_5_1
:
1788 if (dstFormat
== GL_RGBA
) {
1789 GLushort
*dst
= (GLushort
*) dstAddr
;
1791 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1792 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1793 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
1794 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1797 else if (dstFormat
== GL_BGRA
) {
1798 GLushort
*dst
= (GLushort
*) dstAddr
;
1800 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11)
1801 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1802 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 1)
1803 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1806 else if (dstFormat
== GL_ABGR_EXT
) {
1807 GLushort
*dst
= (GLushort
*) dstAddr
;
1809 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) << 11)
1810 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 6)
1811 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 1)
1812 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) );
1816 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1817 if (dstFormat
== GL_RGBA
) {
1818 GLushort
*dst
= (GLushort
*) dstAddr
;
1820 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1821 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1822 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
1823 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1826 else if (dstFormat
== GL_BGRA
) {
1827 GLushort
*dst
= (GLushort
*) dstAddr
;
1829 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) )
1830 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1831 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 10)
1832 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1835 else if (dstFormat
== GL_ABGR_EXT
) {
1836 GLushort
*dst
= (GLushort
*) dstAddr
;
1838 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) )
1839 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 5)
1840 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 10)
1841 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) << 15);
1845 case GL_UNSIGNED_INT_8_8_8_8
:
1846 if (dstFormat
== GL_RGBA
) {
1847 GLuint
*dst
= (GLuint
*) dstAddr
;
1849 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
1850 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1851 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1852 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1855 else if (dstFormat
== GL_BGRA
) {
1856 GLuint
*dst
= (GLuint
*) dstAddr
;
1858 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
1859 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1860 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
1861 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1864 else if (dstFormat
== GL_ABGR_EXT
) {
1865 GLuint
*dst
= (GLuint
*) dstAddr
;
1867 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
1868 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1869 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1870 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
1874 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1875 if (dstFormat
== GL_RGBA
) {
1876 GLuint
*dst
= (GLuint
*) dstAddr
;
1878 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
1879 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1880 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1881 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1884 else if (dstFormat
== GL_BGRA
) {
1885 GLuint
*dst
= (GLuint
*) dstAddr
;
1887 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
1888 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1889 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
1890 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1893 else if (dstFormat
== GL_ABGR_EXT
) {
1894 GLuint
*dst
= (GLuint
*) dstAddr
;
1896 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
1897 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1898 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1899 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
1903 case GL_UNSIGNED_INT_10_10_10_2
:
1904 if (dstFormat
== GL_RGBA
) {
1905 GLuint
*dst
= (GLuint
*) dstAddr
;
1907 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
1908 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1909 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
1910 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1913 else if (dstFormat
== GL_BGRA
) {
1914 GLuint
*dst
= (GLuint
*) dstAddr
;
1916 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
1917 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1918 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
1919 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1922 else if (dstFormat
== GL_ABGR_EXT
) {
1923 GLuint
*dst
= (GLuint
*) dstAddr
;
1925 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
1926 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
1927 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
1928 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
1932 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1933 if (dstFormat
== GL_RGBA
) {
1934 GLuint
*dst
= (GLuint
*) dstAddr
;
1936 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
1937 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1938 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
1939 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1942 else if (dstFormat
== GL_BGRA
) {
1943 GLuint
*dst
= (GLuint
*) dstAddr
;
1945 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
1946 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1947 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
1948 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1951 else if (dstFormat
== GL_ABGR_EXT
) {
1952 GLuint
*dst
= (GLuint
*) dstAddr
;
1954 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
1955 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
1956 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
1957 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
1962 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
1968 * Pack the given RGBA span into client memory at 'dest' address
1969 * in the given pixel format and type.
1970 * Optionally apply the enabled pixel transfer ops.
1971 * Pack into memory using the given packing params struct.
1972 * This is used by glReadPixels and glGetTexImage?D()
1973 * \param ctx - the context
1974 * n - number of pixels in the span
1976 * format - dest packing format
1977 * type - dest packing data type
1978 * destination - destination packing address
1979 * packing - pixel packing parameters
1980 * transferOps - bitmask of IMAGE_*_BIT operations to apply
1983 _mesa_pack_rgba_span_chan( GLcontext
*ctx
,
1984 GLuint n
, CONST GLchan srcRgba
[][4],
1985 GLenum dstFormat
, GLenum dstType
,
1987 const struct gl_pixelstore_attrib
*dstPacking
,
1990 ASSERT((ctx
->NewState
& _NEW_PIXEL
) == 0 || transferOps
== 0);
1992 /* Test for optimized case first */
1993 if (transferOps
== 0 && dstFormat
== GL_RGBA
&& dstType
== CHAN_TYPE
) {
1994 /* common simple case */
1995 MEMCPY(dstAddr
, srcRgba
, n
* 4 * sizeof(GLchan
));
1997 else if (transferOps
== 0 && dstFormat
== GL_RGB
&& dstType
== CHAN_TYPE
) {
1998 /* common simple case */
2000 GLchan
*dest
= (GLchan
*) dstAddr
;
2001 for (i
= 0; i
< n
; i
++) {
2002 dest
[0] = srcRgba
[i
][RCOMP
];
2003 dest
[1] = srcRgba
[i
][GCOMP
];
2004 dest
[2] = srcRgba
[i
][BCOMP
];
2008 else if (transferOps
== 0 && dstFormat
== GL_RGBA
&& dstType
== GL_UNSIGNED_BYTE
) {
2009 /* common simple case */
2011 GLubyte
*dest
= (GLubyte
*) dstAddr
;
2012 for (i
= 0; i
< n
; i
++) {
2013 dest
[0] = CHAN_TO_UBYTE(srcRgba
[i
][RCOMP
]);
2014 dest
[1] = CHAN_TO_UBYTE(srcRgba
[i
][GCOMP
]);
2015 dest
[2] = CHAN_TO_UBYTE(srcRgba
[i
][BCOMP
]);
2016 dest
[3] = CHAN_TO_UBYTE(srcRgba
[i
][ACOMP
]);
2021 /* general solution */
2023 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
2024 CHECKARRAY(rgba
, return); /* mac 32k limitation */
2026 assert(n
<= MAX_WIDTH
);
2027 /* convert color components to floating point */
2028 for (i
= 0; i
< n
; i
++) {
2029 rgba
[i
][RCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][RCOMP
]);
2030 rgba
[i
][GCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][GCOMP
]);
2031 rgba
[i
][BCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][BCOMP
]);
2032 rgba
[i
][ACOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][ACOMP
]);
2034 _mesa_pack_rgba_span_float(ctx
, n
, (const GLfloat (*)[4]) rgba
,
2035 dstFormat
, dstType
, dstAddr
,
2036 dstPacking
, transferOps
);
2037 UNDEFARRAY(rgba
); /* mac 32k limitation */
2042 #define SWAP2BYTE(VALUE) \
2044 GLubyte *bytes = (GLubyte *) &(VALUE); \
2045 GLubyte tmp = bytes[0]; \
2046 bytes[0] = bytes[1]; \
2050 #define SWAP4BYTE(VALUE) \
2052 GLubyte *bytes = (GLubyte *) &(VALUE); \
2053 GLubyte tmp = bytes[0]; \
2054 bytes[0] = bytes[3]; \
2057 bytes[1] = bytes[2]; \
2063 extract_uint_indexes(GLuint n
, GLuint indexes
[],
2064 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2065 const struct gl_pixelstore_attrib
*unpack
)
2067 assert(srcFormat
== GL_COLOR_INDEX
);
2069 ASSERT(srcType
== GL_BITMAP
||
2070 srcType
== GL_UNSIGNED_BYTE
||
2071 srcType
== GL_BYTE
||
2072 srcType
== GL_UNSIGNED_SHORT
||
2073 srcType
== GL_SHORT
||
2074 srcType
== GL_UNSIGNED_INT
||
2075 srcType
== GL_INT
||
2076 srcType
== GL_HALF_FLOAT_ARB
||
2077 srcType
== GL_FLOAT
);
2082 GLubyte
*ubsrc
= (GLubyte
*) src
;
2083 if (unpack
->LsbFirst
) {
2084 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
2086 for (i
= 0; i
< n
; i
++) {
2087 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2098 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
2100 for (i
= 0; i
< n
; i
++) {
2101 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2113 case GL_UNSIGNED_BYTE
:
2116 const GLubyte
*s
= (const GLubyte
*) src
;
2117 for (i
= 0; i
< n
; i
++)
2124 const GLbyte
*s
= (const GLbyte
*) src
;
2125 for (i
= 0; i
< n
; i
++)
2129 case GL_UNSIGNED_SHORT
:
2132 const GLushort
*s
= (const GLushort
*) src
;
2133 if (unpack
->SwapBytes
) {
2134 for (i
= 0; i
< n
; i
++) {
2135 GLushort value
= s
[i
];
2141 for (i
= 0; i
< n
; i
++)
2149 const GLshort
*s
= (const GLshort
*) src
;
2150 if (unpack
->SwapBytes
) {
2151 for (i
= 0; i
< n
; i
++) {
2152 GLshort value
= s
[i
];
2158 for (i
= 0; i
< n
; i
++)
2163 case GL_UNSIGNED_INT
:
2166 const GLuint
*s
= (const GLuint
*) src
;
2167 if (unpack
->SwapBytes
) {
2168 for (i
= 0; i
< n
; i
++) {
2169 GLuint value
= s
[i
];
2175 for (i
= 0; i
< n
; i
++)
2183 const GLint
*s
= (const GLint
*) src
;
2184 if (unpack
->SwapBytes
) {
2185 for (i
= 0; i
< n
; i
++) {
2192 for (i
= 0; i
< n
; i
++)
2200 const GLfloat
*s
= (const GLfloat
*) src
;
2201 if (unpack
->SwapBytes
) {
2202 for (i
= 0; i
< n
; i
++) {
2203 GLfloat value
= s
[i
];
2205 indexes
[i
] = (GLuint
) value
;
2209 for (i
= 0; i
< n
; i
++)
2210 indexes
[i
] = (GLuint
) s
[i
];
2214 case GL_HALF_FLOAT_ARB
:
2217 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
2218 if (unpack
->SwapBytes
) {
2219 for (i
= 0; i
< n
; i
++) {
2220 GLhalfARB value
= s
[i
];
2222 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
2226 for (i
= 0; i
< n
; i
++)
2227 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
2232 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2239 * This function extracts floating point RGBA values from arbitrary
2240 * image data. srcFormat and srcType are the format and type parameters
2241 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2243 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2244 * implements the "Conversion to floating point", "Conversion to RGB",
2245 * and "Final Expansion to RGBA" operations.
2247 * Args: n - number of pixels
2248 * rgba - output colors
2249 * srcFormat - format of incoming data
2250 * srcType - data type of incoming data
2251 * src - source data pointer
2252 * swapBytes - perform byteswapping of incoming data?
2255 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2256 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2257 GLboolean swapBytes
)
2259 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2261 GLint rComp
, bComp
, gComp
, aComp
;
2263 ASSERT(srcFormat
== GL_RED
||
2264 srcFormat
== GL_GREEN
||
2265 srcFormat
== GL_BLUE
||
2266 srcFormat
== GL_ALPHA
||
2267 srcFormat
== GL_LUMINANCE
||
2268 srcFormat
== GL_LUMINANCE_ALPHA
||
2269 srcFormat
== GL_INTENSITY
||
2270 srcFormat
== GL_RGB
||
2271 srcFormat
== GL_BGR
||
2272 srcFormat
== GL_RGBA
||
2273 srcFormat
== GL_BGRA
||
2274 srcFormat
== GL_ABGR_EXT
);
2276 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2277 srcType
== GL_BYTE
||
2278 srcType
== GL_UNSIGNED_SHORT
||
2279 srcType
== GL_SHORT
||
2280 srcType
== GL_UNSIGNED_INT
||
2281 srcType
== GL_INT
||
2282 srcType
== GL_HALF_FLOAT_ARB
||
2283 srcType
== GL_FLOAT
||
2284 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2285 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2286 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2287 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2288 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2289 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2290 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2291 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2292 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2293 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2294 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2295 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2297 rComp
= gComp
= bComp
= aComp
= -1;
2299 switch (srcFormat
) {
2302 greenIndex
= blueIndex
= alphaIndex
= -1;
2307 redIndex
= blueIndex
= alphaIndex
= -1;
2312 redIndex
= greenIndex
= alphaIndex
= -1;
2316 redIndex
= greenIndex
= blueIndex
= -1;
2321 redIndex
= greenIndex
= blueIndex
= 0;
2325 case GL_LUMINANCE_ALPHA
:
2326 redIndex
= greenIndex
= blueIndex
= 0;
2331 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
2390 _mesa_problem(NULL
, "bad srcFormat in extract float data");
2395 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
2396 if ((INDEX) < 0) { \
2398 for (i = 0; i < n; i++) { \
2399 rgba[i][CHANNEL] = DEFAULT; \
2402 else if (swapBytes) { \
2403 const TYPE *s = (const TYPE *) src; \
2405 for (i = 0; i < n; i++) { \
2406 TYPE value = s[INDEX]; \
2407 if (sizeof(TYPE) == 2) { \
2410 else if (sizeof(TYPE) == 4) { \
2413 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
2418 const TYPE *s = (const TYPE *) src; \
2420 for (i = 0; i < n; i++) { \
2421 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
2427 case GL_UNSIGNED_BYTE
:
2428 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2429 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2430 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2431 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2434 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2435 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2436 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2437 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
2439 case GL_UNSIGNED_SHORT
:
2440 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2441 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2442 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2443 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
2446 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2447 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2448 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2449 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
2451 case GL_UNSIGNED_INT
:
2452 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2453 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2454 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2455 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
2458 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2459 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2460 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2461 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
2464 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2465 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2466 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2467 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
2469 case GL_HALF_FLOAT_ARB
:
2470 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2471 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2472 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2473 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
2475 case GL_UNSIGNED_BYTE_3_3_2
:
2477 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2479 for (i
= 0; i
< n
; i
++) {
2480 GLubyte p
= ubsrc
[i
];
2481 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
2482 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
2483 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
2484 rgba
[i
][aComp
] = 1.0F
;
2488 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2490 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2492 for (i
= 0; i
< n
; i
++) {
2493 GLubyte p
= ubsrc
[i
];
2494 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
2495 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
2496 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
2497 rgba
[i
][aComp
] = 1.0F
;
2501 case GL_UNSIGNED_SHORT_5_6_5
:
2503 const GLushort
*ussrc
= (const GLushort
*) src
;
2505 for (i
= 0; i
< n
; i
++) {
2506 GLushort p
= ussrc
[i
];
2508 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2509 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2510 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2511 rgba
[i
][aComp
] = 1.0F
;
2515 const GLushort
*ussrc
= (const GLushort
*) src
;
2517 for (i
= 0; i
< n
; i
++) {
2518 GLushort p
= ussrc
[i
];
2519 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2520 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2521 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2522 rgba
[i
][aComp
] = 1.0F
;
2526 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2528 const GLushort
*ussrc
= (const GLushort
*) src
;
2530 for (i
= 0; i
< n
; i
++) {
2531 GLushort p
= ussrc
[i
];
2533 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2534 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2535 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2536 rgba
[i
][aComp
] = 1.0F
;
2540 const GLushort
*ussrc
= (const GLushort
*) src
;
2542 for (i
= 0; i
< n
; i
++) {
2543 GLushort p
= ussrc
[i
];
2544 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2545 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2546 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2547 rgba
[i
][aComp
] = 1.0F
;
2551 case GL_UNSIGNED_SHORT_4_4_4_4
:
2553 const GLushort
*ussrc
= (const GLushort
*) src
;
2555 for (i
= 0; i
< n
; i
++) {
2556 GLushort p
= ussrc
[i
];
2558 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2559 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2560 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2561 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2565 const GLushort
*ussrc
= (const GLushort
*) src
;
2567 for (i
= 0; i
< n
; i
++) {
2568 GLushort p
= ussrc
[i
];
2569 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2570 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2571 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2572 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2576 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2578 const GLushort
*ussrc
= (const GLushort
*) src
;
2580 for (i
= 0; i
< n
; i
++) {
2581 GLushort p
= ussrc
[i
];
2583 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2584 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2585 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2586 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2590 const GLushort
*ussrc
= (const GLushort
*) src
;
2592 for (i
= 0; i
< n
; i
++) {
2593 GLushort p
= ussrc
[i
];
2594 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2595 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2596 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2597 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2601 case GL_UNSIGNED_SHORT_5_5_5_1
:
2603 const GLushort
*ussrc
= (const GLushort
*) src
;
2605 for (i
= 0; i
< n
; i
++) {
2606 GLushort p
= ussrc
[i
];
2608 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2609 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2610 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2611 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2615 const GLushort
*ussrc
= (const GLushort
*) src
;
2617 for (i
= 0; i
< n
; i
++) {
2618 GLushort p
= ussrc
[i
];
2619 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2620 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2621 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2622 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2626 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2628 const GLushort
*ussrc
= (const GLushort
*) src
;
2630 for (i
= 0; i
< n
; i
++) {
2631 GLushort p
= ussrc
[i
];
2633 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2634 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2635 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2636 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2640 const GLushort
*ussrc
= (const GLushort
*) src
;
2642 for (i
= 0; i
< n
; i
++) {
2643 GLushort p
= ussrc
[i
];
2644 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2645 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2646 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2647 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2651 case GL_UNSIGNED_INT_8_8_8_8
:
2653 const GLuint
*uisrc
= (const GLuint
*) src
;
2655 for (i
= 0; i
< n
; i
++) {
2656 GLuint p
= uisrc
[i
];
2657 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2658 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2659 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2660 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2664 const GLuint
*uisrc
= (const GLuint
*) src
;
2666 for (i
= 0; i
< n
; i
++) {
2667 GLuint p
= uisrc
[i
];
2668 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2669 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2670 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2671 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2675 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2677 const GLuint
*uisrc
= (const GLuint
*) src
;
2679 for (i
= 0; i
< n
; i
++) {
2680 GLuint p
= uisrc
[i
];
2681 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2682 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2683 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2684 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2688 const GLuint
*uisrc
= (const GLuint
*) src
;
2690 for (i
= 0; i
< n
; i
++) {
2691 GLuint p
= uisrc
[i
];
2692 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2693 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2694 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2695 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2699 case GL_UNSIGNED_INT_10_10_10_2
:
2701 const GLuint
*uisrc
= (const GLuint
*) src
;
2703 for (i
= 0; i
< n
; i
++) {
2704 GLuint p
= uisrc
[i
];
2706 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2707 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2708 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2709 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2713 const GLuint
*uisrc
= (const GLuint
*) src
;
2715 for (i
= 0; i
< n
; i
++) {
2716 GLuint p
= uisrc
[i
];
2717 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2718 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2719 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2720 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2724 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2726 const GLuint
*uisrc
= (const GLuint
*) src
;
2728 for (i
= 0; i
< n
; i
++) {
2729 GLuint p
= uisrc
[i
];
2731 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2732 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2733 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2734 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2738 const GLuint
*uisrc
= (const GLuint
*) src
;
2740 for (i
= 0; i
< n
; i
++) {
2741 GLuint p
= uisrc
[i
];
2742 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2743 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2744 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2745 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2750 _mesa_problem(NULL
, "bad srcType in extract float data");
2757 * Unpack a row of color image data from a client buffer according to
2758 * the pixel unpacking parameters.
2759 * Return GLchan values in the specified dest image format.
2760 * This is used by glDrawPixels and glTexImage?D().
2761 * \param ctx - the context
2762 * n - number of pixels in the span
2763 * dstFormat - format of destination color array
2764 * dest - the destination color array
2765 * srcFormat - source image format
2766 * srcType - source image data type
2767 * source - source image pointer
2768 * srcPacking - pixel unpacking parameters
2769 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
2771 * XXX perhaps expand this to process whole images someday.
2774 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
2775 GLuint n
, GLenum dstFormat
, GLchan dest
[],
2776 GLenum srcFormat
, GLenum srcType
,
2777 const GLvoid
*source
,
2778 const struct gl_pixelstore_attrib
*srcPacking
,
2779 GLuint transferOps
)
2781 ASSERT(dstFormat
== GL_ALPHA
||
2782 dstFormat
== GL_LUMINANCE
||
2783 dstFormat
== GL_LUMINANCE_ALPHA
||
2784 dstFormat
== GL_INTENSITY
||
2785 dstFormat
== GL_RGB
||
2786 dstFormat
== GL_RGBA
||
2787 dstFormat
== GL_COLOR_INDEX
);
2789 ASSERT(srcFormat
== GL_RED
||
2790 srcFormat
== GL_GREEN
||
2791 srcFormat
== GL_BLUE
||
2792 srcFormat
== GL_ALPHA
||
2793 srcFormat
== GL_LUMINANCE
||
2794 srcFormat
== GL_LUMINANCE_ALPHA
||
2795 srcFormat
== GL_INTENSITY
||
2796 srcFormat
== GL_RGB
||
2797 srcFormat
== GL_BGR
||
2798 srcFormat
== GL_RGBA
||
2799 srcFormat
== GL_BGRA
||
2800 srcFormat
== GL_ABGR_EXT
||
2801 srcFormat
== GL_COLOR_INDEX
);
2803 ASSERT(srcType
== GL_BITMAP
||
2804 srcType
== GL_UNSIGNED_BYTE
||
2805 srcType
== GL_BYTE
||
2806 srcType
== GL_UNSIGNED_SHORT
||
2807 srcType
== GL_SHORT
||
2808 srcType
== GL_UNSIGNED_INT
||
2809 srcType
== GL_INT
||
2810 srcType
== GL_HALF_FLOAT_ARB
||
2811 srcType
== GL_FLOAT
||
2812 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2813 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2814 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2815 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2816 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2817 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2818 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2819 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2820 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2821 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2822 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2823 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2825 /* Try simple cases first */
2826 if (transferOps
== 0) {
2827 if (srcType
== CHAN_TYPE
) {
2828 if (dstFormat
== GL_RGBA
) {
2829 if (srcFormat
== GL_RGBA
) {
2830 MEMCPY( dest
, source
, n
* 4 * sizeof(GLchan
) );
2833 else if (srcFormat
== GL_RGB
) {
2835 const GLchan
*src
= (const GLchan
*) source
;
2837 for (i
= 0; i
< n
; i
++) {
2848 else if (dstFormat
== GL_RGB
) {
2849 if (srcFormat
== GL_RGB
) {
2850 MEMCPY( dest
, source
, n
* 3 * sizeof(GLchan
) );
2853 else if (srcFormat
== GL_RGBA
) {
2855 const GLchan
*src
= (const GLchan
*) source
;
2857 for (i
= 0; i
< n
; i
++) {
2867 else if (dstFormat
== srcFormat
) {
2868 GLint comps
= _mesa_components_in_format(srcFormat
);
2870 MEMCPY( dest
, source
, n
* comps
* sizeof(GLchan
) );
2875 * Common situation, loading 8bit RGBA/RGB source images
2876 * into 16/32 bit destination. (OSMesa16/32)
2878 else if (srcType
== GL_UNSIGNED_BYTE
) {
2879 if (dstFormat
== GL_RGBA
) {
2880 if (srcFormat
== GL_RGB
) {
2882 const GLubyte
*src
= (const GLubyte
*) source
;
2884 for (i
= 0; i
< n
; i
++) {
2885 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2886 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2887 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2894 else if (srcFormat
== GL_RGBA
) {
2896 const GLubyte
*src
= (const GLubyte
*) source
;
2898 for (i
= 0; i
< n
; i
++) {
2899 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2900 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2901 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2902 dst
[3] = UBYTE_TO_CHAN(src
[3]);
2909 else if (dstFormat
== GL_RGB
) {
2910 if (srcFormat
== GL_RGB
) {
2912 const GLubyte
*src
= (const GLubyte
*) source
;
2914 for (i
= 0; i
< n
; i
++) {
2915 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2916 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2917 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2923 else if (srcFormat
== GL_RGBA
) {
2925 const GLubyte
*src
= (const GLubyte
*) source
;
2927 for (i
= 0; i
< n
; i
++) {
2928 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2929 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2930 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2941 /* general solution begins here */
2943 GLint dstComponents
;
2944 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2945 GLint dstLuminanceIndex
, dstIntensityIndex
;
2946 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
2947 CHECKARRAY(rgba
, return); /* mac 32k limitation */
2949 dstComponents
= _mesa_components_in_format( dstFormat
);
2950 /* source & dest image formats should have been error checked by now */
2951 assert(dstComponents
> 0);
2954 * Extract image data and convert to RGBA floats
2956 assert(n
<= MAX_WIDTH
);
2957 if (srcFormat
== GL_COLOR_INDEX
) {
2958 GLuint indexes
[MAX_WIDTH
];
2959 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2962 if (dstFormat
== GL_COLOR_INDEX
2963 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
2964 _mesa_map_ci(ctx
, n
, indexes
);
2966 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
2967 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2970 if (dstFormat
== GL_COLOR_INDEX
) {
2971 /* convert to GLchan and return */
2973 for (i
= 0; i
< n
; i
++) {
2974 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
2976 UNDEFARRAY(rgba
); /* mac 32k limitation */
2980 /* Convert indexes to RGBA */
2981 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
2984 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
2985 * with color indexes.
2987 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
2990 /* non-color index data */
2991 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2992 srcPacking
->SwapBytes
);
2995 /* Need to clamp if returning GLubytes or GLushorts */
2996 #if CHAN_TYPE != GL_FLOAT
2997 transferOps
|= IMAGE_CLAMP_BIT
;
3001 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3004 /* Now determine which color channels we need to produce.
3005 * And determine the dest index (offset) within each color tuple.
3007 switch (dstFormat
) {
3010 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3011 dstLuminanceIndex
= dstIntensityIndex
= -1;
3014 dstLuminanceIndex
= 0;
3015 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3016 dstIntensityIndex
= -1;
3018 case GL_LUMINANCE_ALPHA
:
3019 dstLuminanceIndex
= 0;
3021 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3022 dstIntensityIndex
= -1;
3025 dstIntensityIndex
= 0;
3026 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3027 dstLuminanceIndex
= -1;
3033 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3040 dstLuminanceIndex
= dstIntensityIndex
= -1;
3043 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
3044 UNDEFARRAY(rgba
); /* mac 32k limitation */
3049 /* Now return the GLchan data in the requested dstFormat */
3051 if (dstRedIndex
>= 0) {
3054 for (i
= 0; i
< n
; i
++) {
3055 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
3056 dst
+= dstComponents
;
3060 if (dstGreenIndex
>= 0) {
3063 for (i
= 0; i
< n
; i
++) {
3064 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
3065 dst
+= dstComponents
;
3069 if (dstBlueIndex
>= 0) {
3072 for (i
= 0; i
< n
; i
++) {
3073 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
3074 dst
+= dstComponents
;
3078 if (dstAlphaIndex
>= 0) {
3081 for (i
= 0; i
< n
; i
++) {
3082 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
3083 dst
+= dstComponents
;
3087 if (dstIntensityIndex
>= 0) {
3090 assert(dstIntensityIndex
== 0);
3091 assert(dstComponents
== 1);
3092 for (i
= 0; i
< n
; i
++) {
3093 /* Intensity comes from red channel */
3094 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
3098 if (dstLuminanceIndex
>= 0) {
3101 assert(dstLuminanceIndex
== 0);
3102 for (i
= 0; i
< n
; i
++) {
3103 /* Luminance comes from red channel */
3104 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
3105 dst
+= dstComponents
;
3108 UNDEFARRAY(rgba
); /* mac 32k limitation */
3114 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
3115 * instead of GLchan.
3118 _mesa_unpack_color_span_float( GLcontext
*ctx
,
3119 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
3120 GLenum srcFormat
, GLenum srcType
,
3121 const GLvoid
*source
,
3122 const struct gl_pixelstore_attrib
*srcPacking
,
3123 GLuint transferOps
)
3125 ASSERT(dstFormat
== GL_ALPHA
||
3126 dstFormat
== GL_LUMINANCE
||
3127 dstFormat
== GL_LUMINANCE_ALPHA
||
3128 dstFormat
== GL_INTENSITY
||
3129 dstFormat
== GL_RGB
||
3130 dstFormat
== GL_RGBA
||
3131 dstFormat
== GL_COLOR_INDEX
);
3133 ASSERT(srcFormat
== GL_RED
||
3134 srcFormat
== GL_GREEN
||
3135 srcFormat
== GL_BLUE
||
3136 srcFormat
== GL_ALPHA
||
3137 srcFormat
== GL_LUMINANCE
||
3138 srcFormat
== GL_LUMINANCE_ALPHA
||
3139 srcFormat
== GL_INTENSITY
||
3140 srcFormat
== GL_RGB
||
3141 srcFormat
== GL_BGR
||
3142 srcFormat
== GL_RGBA
||
3143 srcFormat
== GL_BGRA
||
3144 srcFormat
== GL_ABGR_EXT
||
3145 srcFormat
== GL_COLOR_INDEX
);
3147 ASSERT(srcType
== GL_BITMAP
||
3148 srcType
== GL_UNSIGNED_BYTE
||
3149 srcType
== GL_BYTE
||
3150 srcType
== GL_UNSIGNED_SHORT
||
3151 srcType
== GL_SHORT
||
3152 srcType
== GL_UNSIGNED_INT
||
3153 srcType
== GL_INT
||
3154 srcType
== GL_HALF_FLOAT_ARB
||
3155 srcType
== GL_FLOAT
||
3156 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3157 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3158 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3159 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3160 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3161 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3162 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3163 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3164 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3165 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3166 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3167 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3169 /* general solution, no special cases, yet */
3171 GLint dstComponents
;
3172 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3173 GLint dstLuminanceIndex
, dstIntensityIndex
;
3174 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
3175 CHECKARRAY(rgba
, return); /* mac 32k limitation */
3177 dstComponents
= _mesa_components_in_format( dstFormat
);
3178 /* source & dest image formats should have been error checked by now */
3179 assert(dstComponents
> 0);
3182 * Extract image data and convert to RGBA floats
3184 assert(n
<= MAX_WIDTH
);
3185 if (srcFormat
== GL_COLOR_INDEX
) {
3186 GLuint indexes
[MAX_WIDTH
];
3187 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3190 if (dstFormat
== GL_COLOR_INDEX
3191 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
3192 _mesa_map_ci(ctx
, n
, indexes
);
3194 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3195 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3198 if (dstFormat
== GL_COLOR_INDEX
) {
3199 /* convert to GLchan and return */
3201 for (i
= 0; i
< n
; i
++) {
3202 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3204 UNDEFARRAY(rgba
); /* mac 32k limitation */
3208 /* Convert indexes to RGBA */
3209 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3212 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3213 * with color indexes.
3215 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3218 /* non-color index data */
3219 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3220 srcPacking
->SwapBytes
);
3224 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3227 /* Now determine which color channels we need to produce.
3228 * And determine the dest index (offset) within each color tuple.
3230 switch (dstFormat
) {
3233 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3234 dstLuminanceIndex
= dstIntensityIndex
= -1;
3237 dstLuminanceIndex
= 0;
3238 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3239 dstIntensityIndex
= -1;
3241 case GL_LUMINANCE_ALPHA
:
3242 dstLuminanceIndex
= 0;
3244 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3245 dstIntensityIndex
= -1;
3248 dstIntensityIndex
= 0;
3249 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3250 dstLuminanceIndex
= -1;
3256 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3263 dstLuminanceIndex
= dstIntensityIndex
= -1;
3266 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
3267 UNDEFARRAY(rgba
); /* mac 32k limitation */
3271 /* Now pack results in the requested dstFormat */
3272 if (dstRedIndex
>= 0) {
3273 GLfloat
*dst
= dest
;
3275 for (i
= 0; i
< n
; i
++) {
3276 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3277 dst
+= dstComponents
;
3281 if (dstGreenIndex
>= 0) {
3282 GLfloat
*dst
= dest
;
3284 for (i
= 0; i
< n
; i
++) {
3285 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3286 dst
+= dstComponents
;
3290 if (dstBlueIndex
>= 0) {
3291 GLfloat
*dst
= dest
;
3293 for (i
= 0; i
< n
; i
++) {
3294 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3295 dst
+= dstComponents
;
3299 if (dstAlphaIndex
>= 0) {
3300 GLfloat
*dst
= dest
;
3302 for (i
= 0; i
< n
; i
++) {
3303 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3304 dst
+= dstComponents
;
3308 if (dstIntensityIndex
>= 0) {
3309 GLfloat
*dst
= dest
;
3311 assert(dstIntensityIndex
== 0);
3312 assert(dstComponents
== 1);
3313 for (i
= 0; i
< n
; i
++) {
3314 /* Intensity comes from red channel */
3315 dst
[i
] = rgba
[i
][RCOMP
];
3319 if (dstLuminanceIndex
>= 0) {
3320 GLfloat
*dst
= dest
;
3322 assert(dstLuminanceIndex
== 0);
3323 for (i
= 0; i
< n
; i
++) {
3324 /* Luminance comes from red channel */
3325 dst
[0] = rgba
[i
][RCOMP
];
3326 dst
+= dstComponents
;
3329 UNDEFARRAY(rgba
); /* mac 32k limitation */
3335 * Unpack a row of color index data from a client buffer according to
3336 * the pixel unpacking parameters.
3337 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
3339 * Args: ctx - the context
3340 * n - number of pixels
3341 * dstType - destination data type
3342 * dest - destination array
3343 * srcType - source pixel type
3344 * source - source data pointer
3345 * srcPacking - pixel unpacking parameters
3346 * transferOps - the pixel transfer operations to apply
3349 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
3350 GLenum dstType
, GLvoid
*dest
,
3351 GLenum srcType
, const GLvoid
*source
,
3352 const struct gl_pixelstore_attrib
*srcPacking
,
3353 GLuint transferOps
)
3355 ASSERT(srcType
== GL_BITMAP
||
3356 srcType
== GL_UNSIGNED_BYTE
||
3357 srcType
== GL_BYTE
||
3358 srcType
== GL_UNSIGNED_SHORT
||
3359 srcType
== GL_SHORT
||
3360 srcType
== GL_UNSIGNED_INT
||
3361 srcType
== GL_INT
||
3362 srcType
== GL_HALF_FLOAT_ARB
||
3363 srcType
== GL_FLOAT
);
3365 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3366 dstType
== GL_UNSIGNED_SHORT
||
3367 dstType
== GL_UNSIGNED_INT
);
3370 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3373 * Try simple cases first
3375 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
3376 && dstType
== GL_UNSIGNED_BYTE
) {
3377 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
3379 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
3380 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
3381 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
3387 GLuint indexes
[MAX_WIDTH
];
3388 assert(n
<= MAX_WIDTH
);
3390 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3393 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3394 /* shift and offset indexes */
3395 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3397 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3398 /* Apply lookup table */
3399 _mesa_map_ci(ctx
, n
, indexes
);
3402 /* convert to dest type */
3404 case GL_UNSIGNED_BYTE
:
3406 GLubyte
*dst
= (GLubyte
*) dest
;
3408 for (i
= 0; i
< n
; i
++) {
3409 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3413 case GL_UNSIGNED_SHORT
:
3415 GLuint
*dst
= (GLuint
*) dest
;
3417 for (i
= 0; i
< n
; i
++) {
3418 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3422 case GL_UNSIGNED_INT
:
3423 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
3426 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
3433 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
3434 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
3435 const struct gl_pixelstore_attrib
*dstPacking
,
3436 GLuint transferOps
)
3438 GLuint indexes
[MAX_WIDTH
];
3440 ASSERT(n
<= MAX_WIDTH
);
3442 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3444 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
3445 /* make a copy of input */
3446 MEMCPY(indexes
, source
, n
* sizeof(GLuint
));
3447 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3448 _mesa_shift_and_offset_ci( ctx
, n
, indexes
);
3450 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3451 _mesa_map_ci(ctx
, n
, indexes
);
3457 case GL_UNSIGNED_BYTE
:
3459 GLubyte
*dst
= (GLubyte
*) dest
;
3461 for (i
= 0; i
< n
; i
++) {
3462 *dst
++ = (GLubyte
) source
[i
];
3468 GLbyte
*dst
= (GLbyte
*) dest
;
3470 for (i
= 0; i
< n
; i
++) {
3471 dst
[i
] = (GLbyte
) source
[i
];
3475 case GL_UNSIGNED_SHORT
:
3477 GLushort
*dst
= (GLushort
*) dest
;
3479 for (i
= 0; i
< n
; i
++) {
3480 dst
[i
] = (GLushort
) source
[i
];
3482 if (dstPacking
->SwapBytes
) {
3483 _mesa_swap2( (GLushort
*) dst
, n
);
3489 GLshort
*dst
= (GLshort
*) dest
;
3491 for (i
= 0; i
< n
; i
++) {
3492 dst
[i
] = (GLshort
) source
[i
];
3494 if (dstPacking
->SwapBytes
) {
3495 _mesa_swap2( (GLushort
*) dst
, n
);
3499 case GL_UNSIGNED_INT
:
3501 GLuint
*dst
= (GLuint
*) dest
;
3503 for (i
= 0; i
< n
; i
++) {
3504 dst
[i
] = (GLuint
) source
[i
];
3506 if (dstPacking
->SwapBytes
) {
3507 _mesa_swap4( (GLuint
*) dst
, n
);
3513 GLint
*dst
= (GLint
*) dest
;
3515 for (i
= 0; i
< n
; i
++) {
3516 dst
[i
] = (GLint
) source
[i
];
3518 if (dstPacking
->SwapBytes
) {
3519 _mesa_swap4( (GLuint
*) dst
, n
);
3525 GLfloat
*dst
= (GLfloat
*) dest
;
3527 for (i
= 0; i
< n
; i
++) {
3528 dst
[i
] = (GLfloat
) source
[i
];
3530 if (dstPacking
->SwapBytes
) {
3531 _mesa_swap4( (GLuint
*) dst
, n
);
3535 case GL_HALF_FLOAT_ARB
:
3537 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
3539 for (i
= 0; i
< n
; i
++) {
3540 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
3542 if (dstPacking
->SwapBytes
) {
3543 _mesa_swap2( (GLushort
*) dst
, n
);
3548 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3554 * Unpack a row of stencil data from a client buffer according to
3555 * the pixel unpacking parameters.
3556 * This is (or will be) used by glDrawPixels
3558 * Args: ctx - the context
3559 * n - number of pixels
3560 * dstType - destination data type
3561 * dest - destination array
3562 * srcType - source pixel type
3563 * source - source data pointer
3564 * srcPacking - pixel unpacking parameters
3565 * transferOps - apply offset/bias/lookup ops?
3568 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3569 GLenum dstType
, GLvoid
*dest
,
3570 GLenum srcType
, const GLvoid
*source
,
3571 const struct gl_pixelstore_attrib
*srcPacking
,
3572 GLuint transferOps
)
3574 ASSERT(srcType
== GL_BITMAP
||
3575 srcType
== GL_UNSIGNED_BYTE
||
3576 srcType
== GL_BYTE
||
3577 srcType
== GL_UNSIGNED_SHORT
||
3578 srcType
== GL_SHORT
||
3579 srcType
== GL_UNSIGNED_INT
||
3580 srcType
== GL_INT
||
3581 srcType
== GL_HALF_FLOAT_ARB
||
3582 srcType
== GL_FLOAT
);
3584 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3585 dstType
== GL_UNSIGNED_SHORT
||
3586 dstType
== GL_UNSIGNED_INT
);
3588 /* only shift and offset apply to stencil */
3589 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
3592 * Try simple cases first
3594 if (transferOps
== 0 &&
3595 srcType
== GL_UNSIGNED_BYTE
&&
3596 dstType
== GL_UNSIGNED_BYTE
) {
3597 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
3599 else if (transferOps
== 0 &&
3600 srcType
== GL_UNSIGNED_INT
&&
3601 dstType
== GL_UNSIGNED_INT
&&
3602 !srcPacking
->SwapBytes
) {
3603 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
3609 GLuint indexes
[MAX_WIDTH
];
3610 assert(n
<= MAX_WIDTH
);
3612 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3616 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3617 /* shift and offset indexes */
3618 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3621 if (ctx
->Pixel
.MapStencilFlag
) {
3622 /* Apply stencil lookup table */
3623 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
3626 indexes
[i
] = ctx
->Pixel
.MapStoS
[ indexes
[i
] & mask
];
3631 /* convert to dest type */
3633 case GL_UNSIGNED_BYTE
:
3635 GLubyte
*dst
= (GLubyte
*) dest
;
3637 for (i
= 0; i
< n
; i
++) {
3638 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3642 case GL_UNSIGNED_SHORT
:
3644 GLuint
*dst
= (GLuint
*) dest
;
3646 for (i
= 0; i
< n
; i
++) {
3647 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3651 case GL_UNSIGNED_INT
:
3652 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
3655 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
3662 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3663 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
3664 const struct gl_pixelstore_attrib
*dstPacking
)
3666 GLstencil stencil
[MAX_WIDTH
];
3668 ASSERT(n
<= MAX_WIDTH
);
3670 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
3671 ctx
->Pixel
.MapStencilFlag
) {
3672 /* make a copy of input */
3673 MEMCPY(stencil
, source
, n
* sizeof(GLstencil
));
3674 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
3675 _mesa_shift_and_offset_stencil( ctx
, n
, stencil
);
3677 if (ctx
->Pixel
.MapStencilFlag
) {
3678 _mesa_map_stencil( ctx
, n
, stencil
);
3684 case GL_UNSIGNED_BYTE
:
3685 if (sizeof(GLstencil
) == 8) {
3686 MEMCPY( dest
, source
, n
);
3689 GLubyte
*dst
= (GLubyte
*) dest
;
3692 dst
[i
] = (GLubyte
) source
[i
];
3697 if (sizeof(GLstencil
) == 8) {
3698 MEMCPY( dest
, source
, n
);
3701 GLbyte
*dst
= (GLbyte
*) dest
;
3704 dst
[i
] = (GLbyte
) source
[i
];
3708 case GL_UNSIGNED_SHORT
:
3710 GLushort
*dst
= (GLushort
*) dest
;
3713 dst
[i
] = (GLushort
) source
[i
];
3715 if (dstPacking
->SwapBytes
) {
3716 _mesa_swap2( (GLushort
*) dst
, n
);
3722 GLshort
*dst
= (GLshort
*) dest
;
3725 dst
[i
] = (GLshort
) source
[i
];
3727 if (dstPacking
->SwapBytes
) {
3728 _mesa_swap2( (GLushort
*) dst
, n
);
3732 case GL_UNSIGNED_INT
:
3734 GLuint
*dst
= (GLuint
*) dest
;
3737 dst
[i
] = (GLuint
) source
[i
];
3739 if (dstPacking
->SwapBytes
) {
3740 _mesa_swap4( (GLuint
*) dst
, n
);
3746 GLint
*dst
= (GLint
*) dest
;
3749 *dst
++ = (GLint
) source
[i
];
3751 if (dstPacking
->SwapBytes
) {
3752 _mesa_swap4( (GLuint
*) dst
, n
);
3758 GLfloat
*dst
= (GLfloat
*) dest
;
3761 dst
[i
] = (GLfloat
) source
[i
];
3763 if (dstPacking
->SwapBytes
) {
3764 _mesa_swap4( (GLuint
*) dst
, n
);
3768 case GL_HALF_FLOAT_ARB
:
3770 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
3773 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
3775 if (dstPacking
->SwapBytes
) {
3776 _mesa_swap2( (GLushort
*) dst
, n
);
3781 if (dstPacking
->LsbFirst
) {
3782 GLubyte
*dst
= (GLubyte
*) dest
;
3785 for (i
= 0; i
< n
; i
++) {
3788 *dst
|= ((source
[i
] != 0) << shift
);
3797 GLubyte
*dst
= (GLubyte
*) dest
;
3800 for (i
= 0; i
< n
; i
++) {
3803 *dst
|= ((source
[i
] != 0) << shift
);
3813 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3819 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
, GLfloat
*dest
,
3820 GLenum srcType
, const GLvoid
*source
,
3821 const struct gl_pixelstore_attrib
*srcPacking
)
3829 const GLubyte
*src
= (const GLubyte
*) source
;
3830 for (i
= 0; i
< n
; i
++) {
3831 dest
[i
] = BYTE_TO_FLOAT(src
[i
]);
3835 case GL_UNSIGNED_BYTE
:
3838 const GLubyte
*src
= (const GLubyte
*) source
;
3839 for (i
= 0; i
< n
; i
++) {
3840 dest
[i
] = UBYTE_TO_FLOAT(src
[i
]);
3847 const GLshort
*src
= (const GLshort
*) source
;
3848 for (i
= 0; i
< n
; i
++) {
3849 dest
[i
] = SHORT_TO_FLOAT(src
[i
]);
3853 case GL_UNSIGNED_SHORT
:
3856 const GLushort
*src
= (const GLushort
*) source
;
3857 for (i
= 0; i
< n
; i
++) {
3858 dest
[i
] = USHORT_TO_FLOAT(src
[i
]);
3865 const GLint
*src
= (const GLint
*) source
;
3866 for (i
= 0; i
< n
; i
++) {
3867 dest
[i
] = INT_TO_FLOAT(src
[i
]);
3871 case GL_UNSIGNED_INT
:
3874 const GLuint
*src
= (const GLuint
*) source
;
3875 for (i
= 0; i
< n
; i
++) {
3876 dest
[i
] = UINT_TO_FLOAT(src
[i
]);
3881 MEMCPY(dest
, source
, n
* sizeof(GLfloat
));
3883 case GL_HALF_FLOAT_ARB
:
3886 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
3887 for (i
= 0; i
< n
; i
++) {
3888 dest
[i
] = _mesa_half_to_float(src
[i
]);
3893 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
3898 /* apply depth scale and bias and clamp to [0,1] */
3899 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
3901 for (i
= 0; i
< n
; i
++) {
3902 GLfloat d
= dest
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
3903 dest
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
3910 * Pack an array of depth values. The values are floats in [0,1].
3913 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
3914 GLenum dstType
, const GLfloat
*depthSpan
,
3915 const struct gl_pixelstore_attrib
*dstPacking
)
3917 GLfloat depthCopy
[MAX_WIDTH
];
3918 const GLboolean bias_or_scale
= ctx
->Pixel
.DepthBias
!= 0.0 ||
3919 ctx
->Pixel
.DepthScale
!= 1.0;
3921 ASSERT(n
<= MAX_WIDTH
);
3923 if (bias_or_scale
) {
3925 for (i
= 0; i
< n
; i
++) {
3927 d
= depthSpan
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
3928 depthCopy
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
3930 depthSpan
= depthCopy
;
3934 case GL_UNSIGNED_BYTE
:
3936 GLubyte
*dst
= (GLubyte
*) dest
;
3938 for (i
= 0; i
< n
; i
++) {
3939 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
3945 GLbyte
*dst
= (GLbyte
*) dest
;
3947 for (i
= 0; i
< n
; i
++) {
3948 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
3952 case GL_UNSIGNED_SHORT
:
3954 GLushort
*dst
= (GLushort
*) dest
;
3956 for (i
= 0; i
< n
; i
++) {
3957 dst
[i
] = FLOAT_TO_USHORT( depthSpan
[i
] );
3959 if (dstPacking
->SwapBytes
) {
3960 _mesa_swap2( (GLushort
*) dst
, n
);
3966 GLshort
*dst
= (GLshort
*) dest
;
3968 for (i
= 0; i
< n
; i
++) {
3969 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
3971 if (dstPacking
->SwapBytes
) {
3972 _mesa_swap2( (GLushort
*) dst
, n
);
3976 case GL_UNSIGNED_INT
:
3978 GLuint
*dst
= (GLuint
*) dest
;
3980 for (i
= 0; i
< n
; i
++) {
3981 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
3983 if (dstPacking
->SwapBytes
) {
3984 _mesa_swap4( (GLuint
*) dst
, n
);
3990 GLint
*dst
= (GLint
*) dest
;
3992 for (i
= 0; i
< n
; i
++) {
3993 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
3995 if (dstPacking
->SwapBytes
) {
3996 _mesa_swap4( (GLuint
*) dst
, n
);
4002 GLfloat
*dst
= (GLfloat
*) dest
;
4004 for (i
= 0; i
< n
; i
++) {
4005 dst
[i
] = depthSpan
[i
];
4007 if (dstPacking
->SwapBytes
) {
4008 _mesa_swap4( (GLuint
*) dst
, n
);
4012 case GL_HALF_FLOAT_ARB
:
4014 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4016 for (i
= 0; i
< n
; i
++) {
4017 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
4019 if (dstPacking
->SwapBytes
) {
4020 _mesa_swap2( (GLushort
*) dst
, n
);
4025 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
4031 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
4032 * Return all image data in a contiguous block. This is used when we
4033 * compile glDrawPixels, glTexImage, etc into a display list. We
4034 * need a copy of the data in a standard format.
4037 _mesa_unpack_image( GLuint dimensions
,
4038 GLsizei width
, GLsizei height
, GLsizei depth
,
4039 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4040 const struct gl_pixelstore_attrib
*unpack
)
4042 GLint bytesPerRow
, compsPerRow
;
4043 GLboolean flipBytes
, swap2
, swap4
;
4046 return NULL
; /* not necessarily an error */
4048 if (width
<= 0 || height
<= 0 || depth
<= 0)
4049 return NULL
; /* generate error later */
4051 if (format
== GL_BITMAP
) {
4052 bytesPerRow
= (width
+ 7) >> 3;
4053 flipBytes
= !unpack
->LsbFirst
;
4054 swap2
= swap4
= GL_FALSE
;
4058 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
4059 const GLint components
= _mesa_components_in_format(format
);
4061 if (bytesPerPixel
<= 0 || components
<= 0)
4062 return NULL
; /* bad format or type. generate error later */
4063 bytesPerRow
= bytesPerPixel
* width
;
4064 bytesPerComp
= bytesPerPixel
/ components
;
4065 flipBytes
= GL_FALSE
;
4066 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
4067 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
4068 compsPerRow
= components
* width
;
4069 assert(compsPerRow
>= width
);
4073 GLubyte
*destBuffer
= (GLubyte
*) MALLOC(bytesPerRow
* height
* depth
);
4077 return NULL
; /* generate GL_OUT_OF_MEMORY later */
4080 for (img
= 0; img
< depth
; img
++) {
4081 for (row
= 0; row
< height
; row
++) {
4082 const GLvoid
*src
= _mesa_image_address(dimensions
, unpack
, pixels
,
4083 width
, height
, format
, type
, img
, row
, 0);
4084 MEMCPY(dst
, src
, bytesPerRow
);
4085 /* byte flipping/swapping */
4087 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
4090 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
4093 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
4106 * Perform clipping for glDrawPixels. The image's window position
4107 * and size, and the unpack skipPixels and skipRows are adjusted so
4108 * that the image region is entirely within the window and scissor bounds.
4109 * NOTE: this will only work when glPixelZoom is (1, 1).
4111 * \return GL_TRUE if image is ready for drawing or
4112 * GL_FALSE if image was completely clipped away (draw nothing)
4115 _mesa_clip_drawpixels(const GLcontext
*ctx
,
4116 GLint
*destX
, GLint
*destY
,
4117 GLsizei
*width
, GLsizei
*height
,
4118 GLint
*skipPixels
, GLint
*skipRows
)
4120 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
4122 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
&& ctx
->Pixel
.ZoomY
== 1.0F
);
4125 if (*destX
< buffer
->_Xmin
) {
4126 *skipPixels
+= (buffer
->_Xmin
- *destX
);
4127 *width
-= (buffer
->_Xmin
- *destX
);
4128 *destX
= buffer
->_Xmin
;
4130 /* right clipping */
4131 if (*destX
+ *width
> buffer
->_Xmax
)
4132 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
4137 /* bottom clipping */
4138 if (*destY
< buffer
->_Ymin
) {
4139 *skipRows
+= (buffer
->_Ymin
- *destY
);
4140 *height
-= (buffer
->_Ymin
- *destY
);
4141 *destY
= buffer
->_Ymin
;
4144 if (*destY
+ *height
> buffer
->_Ymax
)
4145 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
4155 * Perform clipping for glReadPixels. The image's window position
4156 * and size, and the pack skipPixels and skipRows are adjusted so
4157 * that the image region is entirely within the window bounds.
4158 * Note: this is different from _mesa_clip_drawpixels() in that the
4159 * scissor box is ignored, and we use the bounds of the current "read"
4162 * \return GL_TRUE if image is ready for drawing or
4163 * GL_FALSE if image was completely clipped away (draw nothing)
4166 _mesa_clip_readpixels(const GLcontext
*ctx
,
4167 GLint
*srcX
, GLint
*srcY
,
4168 GLsizei
*width
, GLsizei
*height
,
4169 GLint
*skipPixels
, GLint
*skipRows
)
4171 const GLframebuffer
*buffer
= ctx
->ReadBuffer
;
4175 *skipPixels
+= (0 - *srcX
);
4176 *width
-= (0 - *srcX
);
4179 /* right clipping */
4180 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
4181 *width
-= (*srcX
+ *width
- buffer
->Width
);
4186 /* bottom clipping */
4188 *skipRows
+= (0 - *srcY
);
4189 *height
-= (0 - *srcY
);
4193 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
4194 *height
-= (*srcY
+ *height
- buffer
->Height
);