2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 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.
37 #include "histogram.h"
44 * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
45 * we later convert the float to a packed integer value (such as for
46 * GL_RGB5_A1) because we'll wind up with a non-zero value.
48 * We redefine the macros here so zero is handled correctly.
51 #define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
54 #define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
58 /** Compute ceiling of integer quotient of A divided by B. */
59 #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
63 * Flip the 8 bits in each byte of the given array.
66 * \param n number of bytes.
68 * \todo try this trick to flip bytes someday:
70 * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555);
71 * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333);
72 * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f);
76 flip_bytes( GLubyte
*p
, GLuint n
)
78 register GLuint i
, a
, b
;
81 b
= (GLuint
) p
[i
]; /* words are often faster than bytes */
82 a
= ((b
& 0x01) << 7) |
96 * Flip the order of the 2 bytes in each word in the given array.
99 * \param n number of words.
102 _mesa_swap2( GLushort
*p
, GLuint n
)
107 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
114 * Flip the order of the 4 bytes in each word in the given array.
117 _mesa_swap4( GLuint
*p
, GLuint n
)
119 register GLuint i
, a
, b
;
124 | ((b
>> 8) & 0xff00)
125 | ((b
<< 8) & 0xff0000)
126 | ((b
<< 24) & 0xff000000);
133 * Get the size of a GL data type.
135 * \param type GL data type.
137 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
138 * if an invalid type enum.
141 _mesa_sizeof_type( GLenum type
)
146 case GL_UNSIGNED_BYTE
:
147 return sizeof(GLubyte
);
149 return sizeof(GLbyte
);
150 case GL_UNSIGNED_SHORT
:
151 return sizeof(GLushort
);
153 return sizeof(GLshort
);
154 case GL_UNSIGNED_INT
:
155 return sizeof(GLuint
);
157 return sizeof(GLint
);
159 return sizeof(GLfloat
);
160 case GL_HALF_FLOAT_ARB
:
161 return sizeof(GLhalfARB
);
169 * Same as _mesa_sizeof_type() but also accepting the packed pixel
173 _mesa_sizeof_packed_type( GLenum type
)
178 case GL_UNSIGNED_BYTE
:
179 return sizeof(GLubyte
);
181 return sizeof(GLbyte
);
182 case GL_UNSIGNED_SHORT
:
183 return sizeof(GLushort
);
185 return sizeof(GLshort
);
186 case GL_UNSIGNED_INT
:
187 return sizeof(GLuint
);
189 return sizeof(GLint
);
190 case GL_HALF_FLOAT_ARB
:
191 return sizeof(GLhalfARB
);
193 return sizeof(GLfloat
);
194 case GL_UNSIGNED_BYTE_3_3_2
:
195 return sizeof(GLubyte
);
196 case GL_UNSIGNED_BYTE_2_3_3_REV
:
197 return sizeof(GLubyte
);
198 case GL_UNSIGNED_SHORT_5_6_5
:
199 return sizeof(GLushort
);
200 case GL_UNSIGNED_SHORT_5_6_5_REV
:
201 return sizeof(GLushort
);
202 case GL_UNSIGNED_SHORT_4_4_4_4
:
203 return sizeof(GLushort
);
204 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
205 return sizeof(GLushort
);
206 case GL_UNSIGNED_SHORT_5_5_5_1
:
207 return sizeof(GLushort
);
208 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
209 return sizeof(GLushort
);
210 case GL_UNSIGNED_INT_8_8_8_8
:
211 return sizeof(GLuint
);
212 case GL_UNSIGNED_INT_8_8_8_8_REV
:
213 return sizeof(GLuint
);
214 case GL_UNSIGNED_INT_10_10_10_2
:
215 return sizeof(GLuint
);
216 case GL_UNSIGNED_INT_2_10_10_10_REV
:
217 return sizeof(GLuint
);
218 case GL_UNSIGNED_SHORT_8_8_MESA
:
219 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
220 return sizeof(GLushort
);
221 case GL_UNSIGNED_INT_24_8_EXT
:
222 return sizeof(GLuint
);
230 * Get the number of components in a pixel format.
232 * \param format pixel format.
234 * \return the number of components in the given format, or -1 if a bad format.
237 _mesa_components_in_format( GLenum format
)
241 case GL_COLOR_INDEX1_EXT
:
242 case GL_COLOR_INDEX2_EXT
:
243 case GL_COLOR_INDEX4_EXT
:
244 case GL_COLOR_INDEX8_EXT
:
245 case GL_COLOR_INDEX12_EXT
:
246 case GL_COLOR_INDEX16_EXT
:
247 case GL_STENCIL_INDEX
:
248 case GL_DEPTH_COMPONENT
:
256 case GL_LUMINANCE_ALPHA
:
270 case GL_DEPTH_STENCIL_EXT
:
279 * Get the bytes per pixel of pixel format type pair.
281 * \param format pixel format.
282 * \param type pixel type.
284 * \return bytes per pixel, or -1 if a bad format or type was given.
287 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
289 GLint comps
= _mesa_components_in_format( format
);
295 return 0; /* special case */
297 case GL_UNSIGNED_BYTE
:
298 return comps
* sizeof(GLubyte
);
300 case GL_UNSIGNED_SHORT
:
301 return comps
* sizeof(GLshort
);
303 case GL_UNSIGNED_INT
:
304 return comps
* sizeof(GLint
);
306 return comps
* sizeof(GLfloat
);
307 case GL_HALF_FLOAT_ARB
:
308 return comps
* sizeof(GLhalfARB
);
309 case GL_UNSIGNED_BYTE_3_3_2
:
310 case GL_UNSIGNED_BYTE_2_3_3_REV
:
311 if (format
== GL_RGB
|| format
== GL_BGR
)
312 return sizeof(GLubyte
);
314 return -1; /* error */
315 case GL_UNSIGNED_SHORT_5_6_5
:
316 case GL_UNSIGNED_SHORT_5_6_5_REV
:
317 if (format
== GL_RGB
|| format
== GL_BGR
)
318 return sizeof(GLushort
);
320 return -1; /* error */
321 case GL_UNSIGNED_SHORT_4_4_4_4
:
322 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
323 case GL_UNSIGNED_SHORT_5_5_5_1
:
324 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
325 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
326 return sizeof(GLushort
);
329 case GL_UNSIGNED_INT_8_8_8_8
:
330 case GL_UNSIGNED_INT_8_8_8_8_REV
:
331 case GL_UNSIGNED_INT_10_10_10_2
:
332 case GL_UNSIGNED_INT_2_10_10_10_REV
:
333 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
334 return sizeof(GLuint
);
337 case GL_UNSIGNED_SHORT_8_8_MESA
:
338 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
339 if (format
== GL_YCBCR_MESA
)
340 return sizeof(GLushort
);
343 case GL_UNSIGNED_INT_24_8_EXT
:
344 if (format
== GL_DEPTH_STENCIL_EXT
)
345 return sizeof(GLuint
);
355 * Test for a legal pixel format and type.
357 * \param format pixel format.
358 * \param type pixel type.
360 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
364 _mesa_is_legal_format_and_type( GLcontext
*ctx
, GLenum format
, GLenum type
)
368 case GL_STENCIL_INDEX
:
372 case GL_UNSIGNED_BYTE
:
374 case GL_UNSIGNED_SHORT
:
376 case GL_UNSIGNED_INT
:
379 case GL_HALF_FLOAT_ARB
:
380 return ctx
->Extensions
.ARB_half_float_pixel
;
388 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
392 case GL_LUMINANCE_ALPHA
:
393 case GL_DEPTH_COMPONENT
:
396 case GL_UNSIGNED_BYTE
:
398 case GL_UNSIGNED_SHORT
:
400 case GL_UNSIGNED_INT
:
403 case GL_HALF_FLOAT_ARB
:
404 return ctx
->Extensions
.ARB_half_float_pixel
;
411 case GL_UNSIGNED_BYTE
:
413 case GL_UNSIGNED_SHORT
:
415 case GL_UNSIGNED_INT
:
417 case GL_UNSIGNED_BYTE_3_3_2
:
418 case GL_UNSIGNED_BYTE_2_3_3_REV
:
419 case GL_UNSIGNED_SHORT_5_6_5
:
420 case GL_UNSIGNED_SHORT_5_6_5_REV
:
422 case GL_HALF_FLOAT_ARB
:
423 return ctx
->Extensions
.ARB_half_float_pixel
;
429 /* NOTE: no packed types are supported with BGR. That's
430 * intentional, according to the GL spec.
433 case GL_UNSIGNED_BYTE
:
435 case GL_UNSIGNED_SHORT
:
437 case GL_UNSIGNED_INT
:
440 case GL_HALF_FLOAT_ARB
:
441 return ctx
->Extensions
.ARB_half_float_pixel
;
450 case GL_UNSIGNED_BYTE
:
452 case GL_UNSIGNED_SHORT
:
454 case GL_UNSIGNED_INT
:
456 case GL_UNSIGNED_SHORT_4_4_4_4
:
457 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
458 case GL_UNSIGNED_SHORT_5_5_5_1
:
459 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
460 case GL_UNSIGNED_INT_8_8_8_8
:
461 case GL_UNSIGNED_INT_8_8_8_8_REV
:
462 case GL_UNSIGNED_INT_10_10_10_2
:
463 case GL_UNSIGNED_INT_2_10_10_10_REV
:
465 case GL_HALF_FLOAT_ARB
:
466 return ctx
->Extensions
.ARB_half_float_pixel
;
471 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
472 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
476 case GL_DEPTH_STENCIL_EXT
:
477 if (ctx
->Extensions
.EXT_packed_depth_stencil
478 && type
== GL_UNSIGNED_INT_24_8_EXT
)
490 * Return the address of a specific pixel in an image (1D, 2D or 3D).
492 * Pixel unpacking/packing parameters are observed according to \p packing.
494 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
495 * \param image starting address of image data
496 * \param width the image width
497 * \param height theimage height
498 * \param format the pixel format
499 * \param type the pixel data type
500 * \param packing the pixelstore attributes
501 * \param img which image in the volume (0 for 1D or 2D images)
502 * \param row row of pixel in the image (0 for 1D images)
503 * \param column column of pixel in the image
505 * \return address of pixel on success, or NULL on error.
507 * \sa gl_pixelstore_attrib.
510 _mesa_image_address( GLuint dimensions
,
511 const struct gl_pixelstore_attrib
*packing
,
513 GLsizei width
, GLsizei height
,
514 GLenum format
, GLenum type
,
515 GLint img
, GLint row
, GLint column
)
517 GLint alignment
; /* 1, 2 or 4 */
518 GLint pixels_per_row
;
519 GLint rows_per_image
;
522 GLint skipimages
; /* for 3-D volume images */
525 ASSERT(dimensions
>= 1 && dimensions
<= 3);
527 alignment
= packing
->Alignment
;
528 if (packing
->RowLength
> 0) {
529 pixels_per_row
= packing
->RowLength
;
532 pixels_per_row
= width
;
534 if (packing
->ImageHeight
> 0) {
535 rows_per_image
= packing
->ImageHeight
;
538 rows_per_image
= height
;
541 skippixels
= packing
->SkipPixels
;
542 /* Note: SKIP_ROWS _is_ used for 1D images */
543 skiprows
= packing
->SkipRows
;
544 /* Note: SKIP_IMAGES is only used for 3D images */
545 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
547 if (type
== GL_BITMAP
) {
549 GLint comp_per_pixel
; /* components per pixel */
550 GLint bytes_per_comp
; /* bytes per component */
552 GLint bytes_per_image
;
554 /* Compute bytes per component */
555 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
556 if (bytes_per_comp
< 0) {
560 /* Compute number of components per pixel */
561 comp_per_pixel
= _mesa_components_in_format( format
);
562 if (comp_per_pixel
< 0) {
566 bytes_per_row
= alignment
567 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
569 bytes_per_image
= bytes_per_row
* rows_per_image
;
571 pixel_addr
= (GLubyte
*) image
572 + (skipimages
+ img
) * bytes_per_image
573 + (skiprows
+ row
) * bytes_per_row
574 + (skippixels
+ column
) / 8;
577 /* Non-BITMAP data */
578 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
581 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
583 /* The pixel type and format should have been error checked earlier */
584 assert(bytes_per_pixel
> 0);
586 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
587 remainder
= bytes_per_row
% alignment
;
589 bytes_per_row
+= (alignment
- remainder
);
591 ASSERT(bytes_per_row
% alignment
== 0);
593 bytes_per_image
= bytes_per_row
* rows_per_image
;
595 if (packing
->Invert
) {
596 /* set pixel_addr to the last row */
597 topOfImage
= bytes_per_row
* (height
- 1);
598 bytes_per_row
= -bytes_per_row
;
604 /* compute final pixel address */
605 pixel_addr
= (GLubyte
*) image
606 + (skipimages
+ img
) * bytes_per_image
608 + (skiprows
+ row
) * bytes_per_row
609 + (skippixels
+ column
) * bytes_per_pixel
;
612 return (GLvoid
*) pixel_addr
;
617 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
620 GLenum format
, GLenum type
,
623 return _mesa_image_address(1, packing
, image
, width
, 1,
624 format
, type
, 0, 0, column
);
629 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
631 GLsizei width
, GLsizei height
,
632 GLenum format
, GLenum type
,
633 GLint row
, GLint column
)
635 return _mesa_image_address(2, packing
, image
, width
, height
,
636 format
, type
, 0, row
, column
);
641 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
643 GLsizei width
, GLsizei height
,
644 GLenum format
, GLenum type
,
645 GLint img
, GLint row
, GLint column
)
647 return _mesa_image_address(3, packing
, image
, width
, height
,
648 format
, type
, img
, row
, column
);
654 * Compute the stride between image rows.
656 * \param packing the pixelstore attributes
657 * \param width image width.
658 * \param format pixel format.
659 * \param type pixel data type.
661 * \return the stride in bytes for the given parameters.
664 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
665 GLint width
, GLenum format
, GLenum type
)
668 if (type
== GL_BITMAP
) {
671 if (packing
->RowLength
== 0) {
672 bytes
= (width
+ 7) / 8;
675 bytes
= (packing
->RowLength
+ 7) / 8;
677 if (packing
->Invert
) {
678 /* negate the bytes per row (negative row stride) */
684 /* Non-BITMAP data */
685 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
686 GLint bytesPerRow
, remainder
;
687 if (bytesPerPixel
<= 0)
688 return -1; /* error */
689 if (packing
->RowLength
== 0) {
690 bytesPerRow
= bytesPerPixel
* width
;
693 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
695 remainder
= bytesPerRow
% packing
->Alignment
;
697 bytesPerRow
+= (packing
->Alignment
- remainder
);
699 bytesPerRow
= -bytesPerRow
;
708 * Compute the stride between images in a 3D texture (in bytes) for the given
709 * pixel packing parameters and image width, format and type.
712 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
713 GLint width
, GLint height
,
714 GLenum format
, GLenum type
)
717 ASSERT(type
!= GL_BITMAP
);
720 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
721 GLint bytesPerRow
, bytesPerImage
, remainder
;
723 if (bytesPerPixel
<= 0)
724 return -1; /* error */
725 if (packing
->RowLength
== 0) {
726 bytesPerRow
= bytesPerPixel
* width
;
729 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
731 remainder
= bytesPerRow
% packing
->Alignment
;
733 bytesPerRow
+= (packing
->Alignment
- remainder
);
735 if (packing
->ImageHeight
== 0)
736 bytesPerImage
= bytesPerRow
* height
;
738 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
740 return bytesPerImage
;
746 * Unpack a 32x32 pixel polygon stipple from user memory using the
747 * current pixel unpack settings.
750 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
751 const struct gl_pixelstore_attrib
*unpacking
)
753 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap(32, 32, pattern
, unpacking
);
755 /* Convert pattern from GLubytes to GLuints and handle big/little
760 for (i
= 0; i
< 32; i
++) {
761 dest
[i
] = (p
[0] << 24)
773 * Pack polygon stipple into user memory given current pixel packing
777 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
778 const struct gl_pixelstore_attrib
*packing
)
780 /* Convert pattern from GLuints to GLubytes to handle big/little
781 * endian differences.
785 for (i
= 0; i
< 32; i
++) {
786 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
787 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
788 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
789 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
792 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
797 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
798 * order with row alignment = 1 byte.
801 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
802 const struct gl_pixelstore_attrib
*packing
)
804 GLint bytes
, row
, width_in_bytes
;
805 GLubyte
*buffer
, *dst
;
810 /* Alloc dest storage */
811 bytes
= ((width
+ 7) / 8 * height
);
812 buffer
= (GLubyte
*) _mesa_malloc( bytes
);
816 width_in_bytes
= CEILING( width
, 8 );
818 for (row
= 0; row
< height
; row
++) {
819 const GLubyte
*src
= (const GLubyte
*)
820 _mesa_image_address2d(packing
, pixels
, width
, height
,
821 GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
827 if (packing
->SkipPixels
== 0) {
828 _mesa_memcpy( dst
, src
, width_in_bytes
);
829 if (packing
->LsbFirst
) {
830 flip_bytes( dst
, width_in_bytes
);
834 /* handling SkipPixels is a bit tricky (no pun intended!) */
836 if (packing
->LsbFirst
) {
837 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
838 GLubyte dstMask
= 128;
839 const GLubyte
*s
= src
;
842 for (i
= 0; i
< width
; i
++) {
846 if (srcMask
== 128) {
851 srcMask
= srcMask
<< 1;
859 dstMask
= dstMask
>> 1;
864 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
865 GLubyte dstMask
= 128;
866 const GLubyte
*s
= src
;
869 for (i
= 0; i
< width
; i
++) {
878 srcMask
= srcMask
>> 1;
886 dstMask
= dstMask
>> 1;
891 dst
+= width_in_bytes
;
902 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
903 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
905 GLint row
, width_in_bytes
;
911 width_in_bytes
= CEILING( width
, 8 );
913 for (row
= 0; row
< height
; row
++) {
914 GLubyte
*dst
= (GLubyte
*) _mesa_image_address2d(packing
, dest
,
915 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
919 if (packing
->SkipPixels
== 0) {
920 _mesa_memcpy( dst
, src
, width_in_bytes
);
921 if (packing
->LsbFirst
) {
922 flip_bytes( dst
, width_in_bytes
);
926 /* handling SkipPixels is a bit tricky (no pun intended!) */
928 if (packing
->LsbFirst
) {
929 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
930 GLubyte dstMask
= 128;
931 const GLubyte
*s
= src
;
934 for (i
= 0; i
< width
; i
++) {
938 if (srcMask
== 128) {
943 srcMask
= srcMask
<< 1;
951 dstMask
= dstMask
>> 1;
956 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
957 GLubyte dstMask
= 128;
958 const GLubyte
*s
= src
;
961 for (i
= 0; i
< width
; i
++) {
970 srcMask
= srcMask
>> 1;
978 dstMask
= dstMask
>> 1;
983 src
+= width_in_bytes
;
989 * Apply various pixel transfer operations to an array of RGBA pixels
990 * as indicated by the transferOps bitmask
993 _mesa_apply_rgba_transfer_ops(GLcontext
*ctx
, GLuint transferOps
,
994 GLuint n
, GLfloat rgba
[][4])
997 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
998 _mesa_scale_and_bias_rgba(n
, rgba
,
999 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
1000 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
1001 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
1002 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
1004 /* color map lookup */
1005 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
1006 _mesa_map_rgba( ctx
, n
, rgba
);
1008 /* GL_COLOR_TABLE lookup */
1009 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
1010 _mesa_lookup_rgba_float(&ctx
->ColorTable
, n
, rgba
);
1013 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
1014 /* this has to be done in the calling code */
1015 _mesa_problem(ctx
, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");
1017 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
1018 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
1019 _mesa_scale_and_bias_rgba(n
, rgba
,
1020 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
1021 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
1022 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
1023 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
1024 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
1025 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
1026 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
1027 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
1029 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
1030 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
1031 _mesa_lookup_rgba_float(&ctx
->PostConvolutionColorTable
, n
, rgba
);
1033 /* color matrix transform */
1034 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
1035 _mesa_transform_rgba(ctx
, n
, rgba
);
1037 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
1038 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
1039 _mesa_lookup_rgba_float(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
1041 /* update histogram count */
1042 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
1043 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1045 /* update min/max values */
1046 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
1047 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
1049 /* clamping to [0,1] */
1050 if (transferOps
& IMAGE_CLAMP_BIT
) {
1052 for (i
= 0; i
< n
; i
++) {
1053 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1054 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1055 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1056 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1064 * Used to pack an array [][4] of RGBA float colors as specified
1065 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
1066 * glGetConvolutionFilter(), etc.
1067 * NOTE: it's assumed the incoming float colors are all in [0,1].
1070 _mesa_pack_rgba_span_float( GLcontext
*ctx
,
1071 GLuint n
, CONST GLfloat rgbaIn
[][4],
1072 GLenum dstFormat
, GLenum dstType
,
1074 const struct gl_pixelstore_attrib
*dstPacking
,
1075 GLuint transferOps
)
1077 const GLint comps
= _mesa_components_in_format(dstFormat
);
1078 GLfloat luminance
[MAX_WIDTH
];
1079 const GLfloat (*rgba
)[4];
1083 /* make copy of incoming data */
1084 GLfloat rgbaCopy
[MAX_WIDTH
][4];
1085 _mesa_memcpy(rgbaCopy
, rgbaIn
, n
* 4 * sizeof(GLfloat
));
1086 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgbaCopy
);
1087 rgba
= (const GLfloat (*)[4]) rgbaCopy
;
1089 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
1094 /* use incoming data, not a copy */
1095 rgba
= (const GLfloat (*)[4]) rgbaIn
;
1098 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
1099 /* compute luminance values */
1100 if (ctx
->Color
.ClampReadColor
== GL_TRUE
) {
1101 for (i
= 0; i
< n
; i
++) {
1102 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1103 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
1107 for (i
= 0; i
< n
; i
++) {
1108 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1114 * Pack/store the pixels. Ugh! Lots of cases!!!
1117 case GL_UNSIGNED_BYTE
:
1119 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1120 switch (dstFormat
) {
1123 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1127 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1131 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1135 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1139 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1141 case GL_LUMINANCE_ALPHA
:
1143 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1144 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1149 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1150 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1151 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1156 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1157 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1158 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1159 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1164 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1165 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1166 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1171 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1172 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1173 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1174 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1179 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1180 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1181 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1182 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1186 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1192 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1193 switch (dstFormat
) {
1196 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1200 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1204 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1208 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1212 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1214 case GL_LUMINANCE_ALPHA
:
1216 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1217 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1222 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1223 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1224 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1229 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1230 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1231 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1232 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1237 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1238 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1239 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1244 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1245 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1246 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1247 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1251 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1252 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1253 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1254 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1258 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1262 case GL_UNSIGNED_SHORT
:
1264 GLushort
*dst
= (GLushort
*) dstAddr
;
1265 switch (dstFormat
) {
1268 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][RCOMP
]);
1272 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][GCOMP
]);
1276 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][BCOMP
]);
1280 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][ACOMP
]);
1284 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
], luminance
[i
]);
1286 case GL_LUMINANCE_ALPHA
:
1288 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
*2+0], luminance
[i
]);
1289 CLAMPED_FLOAT_TO_USHORT(dst
[i
*2+1], rgba
[i
][ACOMP
]);
1294 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][RCOMP
]);
1295 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1296 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][BCOMP
]);
1301 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][RCOMP
]);
1302 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1303 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][BCOMP
]);
1304 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1309 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][BCOMP
]);
1310 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1311 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][RCOMP
]);
1316 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][BCOMP
]);
1317 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1318 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][RCOMP
]);
1319 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1324 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][ACOMP
]);
1325 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][BCOMP
]);
1326 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][GCOMP
]);
1327 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][RCOMP
]);
1331 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1333 if (dstPacking
->SwapBytes
) {
1334 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1340 GLshort
*dst
= (GLshort
*) dstAddr
;
1341 switch (dstFormat
) {
1344 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1348 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1352 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1356 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1360 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
1362 case GL_LUMINANCE_ALPHA
:
1364 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
1365 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1370 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1371 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1372 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1377 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1378 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1379 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1380 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1385 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1386 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1387 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1392 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1393 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1394 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1395 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1399 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1400 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1401 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1402 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1406 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1408 if (dstPacking
->SwapBytes
) {
1409 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1413 case GL_UNSIGNED_INT
:
1415 GLuint
*dst
= (GLuint
*) dstAddr
;
1416 switch (dstFormat
) {
1419 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1423 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1427 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1431 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1435 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
1437 case GL_LUMINANCE_ALPHA
:
1439 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
1440 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1445 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1446 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1447 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1452 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1453 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1454 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1455 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1460 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1461 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1462 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1467 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1468 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1469 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1470 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1475 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1476 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1477 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1478 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1482 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1484 if (dstPacking
->SwapBytes
) {
1485 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1491 GLint
*dst
= (GLint
*) dstAddr
;
1492 switch (dstFormat
) {
1495 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1499 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1503 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1507 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1511 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1513 case GL_LUMINANCE_ALPHA
:
1515 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1516 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1521 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1522 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1523 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1528 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1529 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1530 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1531 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1536 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1537 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1538 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1543 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1544 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1545 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1546 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1551 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1552 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1553 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1554 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1558 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1560 if (dstPacking
->SwapBytes
) {
1561 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1567 GLfloat
*dst
= (GLfloat
*) dstAddr
;
1568 switch (dstFormat
) {
1571 dst
[i
] = rgba
[i
][RCOMP
];
1575 dst
[i
] = rgba
[i
][GCOMP
];
1579 dst
[i
] = rgba
[i
][BCOMP
];
1583 dst
[i
] = rgba
[i
][ACOMP
];
1587 dst
[i
] = luminance
[i
];
1589 case GL_LUMINANCE_ALPHA
:
1591 dst
[i
*2+0] = luminance
[i
];
1592 dst
[i
*2+1] = rgba
[i
][ACOMP
];
1597 dst
[i
*3+0] = rgba
[i
][RCOMP
];
1598 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1599 dst
[i
*3+2] = rgba
[i
][BCOMP
];
1604 dst
[i
*4+0] = rgba
[i
][RCOMP
];
1605 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1606 dst
[i
*4+2] = rgba
[i
][BCOMP
];
1607 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1612 dst
[i
*3+0] = rgba
[i
][BCOMP
];
1613 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1614 dst
[i
*3+2] = rgba
[i
][RCOMP
];
1619 dst
[i
*4+0] = rgba
[i
][BCOMP
];
1620 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1621 dst
[i
*4+2] = rgba
[i
][RCOMP
];
1622 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1627 dst
[i
*4+0] = rgba
[i
][ACOMP
];
1628 dst
[i
*4+1] = rgba
[i
][BCOMP
];
1629 dst
[i
*4+2] = rgba
[i
][GCOMP
];
1630 dst
[i
*4+3] = rgba
[i
][RCOMP
];
1634 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1636 if (dstPacking
->SwapBytes
) {
1637 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1641 case GL_HALF_FLOAT_ARB
:
1643 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
1644 switch (dstFormat
) {
1647 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1651 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1655 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1659 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1663 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
1665 case GL_LUMINANCE_ALPHA
:
1667 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
1668 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1673 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1674 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1675 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1680 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1681 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1682 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1683 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1688 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1689 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1690 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1695 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1696 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1697 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1698 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1703 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1704 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1705 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1706 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1710 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1712 if (dstPacking
->SwapBytes
) {
1713 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1717 case GL_UNSIGNED_BYTE_3_3_2
:
1718 if (dstFormat
== GL_RGB
) {
1719 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1721 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
1722 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
1723 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
1727 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1728 if (dstFormat
== GL_RGB
) {
1729 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1731 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
1732 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
1733 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 5);
1737 case GL_UNSIGNED_SHORT_5_6_5
:
1738 if (dstFormat
== GL_RGB
) {
1739 GLushort
*dst
= (GLushort
*) dstAddr
;
1741 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1742 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1743 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
1747 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1748 if (dstFormat
== GL_RGB
) {
1749 GLushort
*dst
= (GLushort
*) dstAddr
;
1751 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1752 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1753 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
1757 case GL_UNSIGNED_SHORT_4_4_4_4
:
1758 if (dstFormat
== GL_RGBA
) {
1759 GLushort
*dst
= (GLushort
*) dstAddr
;
1761 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
1762 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1763 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1764 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1767 else if (dstFormat
== GL_BGRA
) {
1768 GLushort
*dst
= (GLushort
*) dstAddr
;
1770 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 12)
1771 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1772 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 4)
1773 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1776 else if (dstFormat
== GL_ABGR_EXT
) {
1777 GLushort
*dst
= (GLushort
*) dstAddr
;
1779 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 4)
1780 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1781 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 12)
1782 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) );
1786 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1787 if (dstFormat
== GL_RGBA
) {
1788 GLushort
*dst
= (GLushort
*) dstAddr
;
1790 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
1791 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1792 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1793 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1796 else if (dstFormat
== GL_BGRA
) {
1797 GLushort
*dst
= (GLushort
*) dstAddr
;
1799 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) )
1800 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1801 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 8)
1802 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1805 else if (dstFormat
== GL_ABGR_EXT
) {
1806 GLushort
*dst
= (GLushort
*) dstAddr
;
1808 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) )
1809 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1810 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1811 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12);
1815 case GL_UNSIGNED_SHORT_5_5_5_1
:
1816 if (dstFormat
== GL_RGBA
) {
1817 GLushort
*dst
= (GLushort
*) dstAddr
;
1819 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1820 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1821 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
1822 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1825 else if (dstFormat
== GL_BGRA
) {
1826 GLushort
*dst
= (GLushort
*) dstAddr
;
1828 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11)
1829 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1830 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 1)
1831 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1834 else if (dstFormat
== GL_ABGR_EXT
) {
1835 GLushort
*dst
= (GLushort
*) dstAddr
;
1837 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) << 11)
1838 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 6)
1839 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 1)
1840 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) );
1844 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1845 if (dstFormat
== GL_RGBA
) {
1846 GLushort
*dst
= (GLushort
*) dstAddr
;
1848 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1849 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1850 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
1851 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1854 else if (dstFormat
== GL_BGRA
) {
1855 GLushort
*dst
= (GLushort
*) dstAddr
;
1857 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) )
1858 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1859 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 10)
1860 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1863 else if (dstFormat
== GL_ABGR_EXT
) {
1864 GLushort
*dst
= (GLushort
*) dstAddr
;
1866 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) )
1867 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 5)
1868 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 10)
1869 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) << 15);
1873 case GL_UNSIGNED_INT_8_8_8_8
:
1874 if (dstFormat
== GL_RGBA
) {
1875 GLuint
*dst
= (GLuint
*) dstAddr
;
1877 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
1878 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1879 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1880 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1883 else if (dstFormat
== GL_BGRA
) {
1884 GLuint
*dst
= (GLuint
*) dstAddr
;
1886 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
1887 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1888 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
1889 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1892 else if (dstFormat
== GL_ABGR_EXT
) {
1893 GLuint
*dst
= (GLuint
*) dstAddr
;
1895 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
1896 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1897 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1898 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
1902 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1903 if (dstFormat
== GL_RGBA
) {
1904 GLuint
*dst
= (GLuint
*) dstAddr
;
1906 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
1907 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1908 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1909 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1912 else if (dstFormat
== GL_BGRA
) {
1913 GLuint
*dst
= (GLuint
*) dstAddr
;
1915 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
1916 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1917 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
1918 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1921 else if (dstFormat
== GL_ABGR_EXT
) {
1922 GLuint
*dst
= (GLuint
*) dstAddr
;
1924 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
1925 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1926 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1927 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
1931 case GL_UNSIGNED_INT_10_10_10_2
:
1932 if (dstFormat
== GL_RGBA
) {
1933 GLuint
*dst
= (GLuint
*) dstAddr
;
1935 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
1936 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1937 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
1938 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1941 else if (dstFormat
== GL_BGRA
) {
1942 GLuint
*dst
= (GLuint
*) dstAddr
;
1944 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
1945 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1946 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
1947 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1950 else if (dstFormat
== GL_ABGR_EXT
) {
1951 GLuint
*dst
= (GLuint
*) dstAddr
;
1953 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
1954 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
1955 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
1956 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
1960 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1961 if (dstFormat
== GL_RGBA
) {
1962 GLuint
*dst
= (GLuint
*) dstAddr
;
1964 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
1965 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1966 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
1967 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1970 else if (dstFormat
== GL_BGRA
) {
1971 GLuint
*dst
= (GLuint
*) dstAddr
;
1973 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
1974 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1975 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
1976 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1979 else if (dstFormat
== GL_ABGR_EXT
) {
1980 GLuint
*dst
= (GLuint
*) dstAddr
;
1982 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
1983 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
1984 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
1985 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
1990 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
1996 * Pack the given RGBA span into client memory at 'dest' address
1997 * in the given pixel format and type.
1998 * Optionally apply the enabled pixel transfer ops.
1999 * Pack into memory using the given packing params struct.
2000 * This is used by glReadPixels and glGetTexImage?D()
2001 * \param ctx - the context
2002 * n - number of pixels in the span
2004 * format - dest packing format
2005 * type - dest packing data type
2006 * destination - destination packing address
2007 * packing - pixel packing parameters
2008 * transferOps - bitmask of IMAGE_*_BIT operations to apply
2011 _mesa_pack_rgba_span_chan( GLcontext
*ctx
,
2012 GLuint n
, CONST GLchan srcRgba
[][4],
2013 GLenum dstFormat
, GLenum dstType
,
2015 const struct gl_pixelstore_attrib
*dstPacking
,
2018 ASSERT((ctx
->NewState
& _NEW_PIXEL
) == 0 || transferOps
== 0);
2020 /* Test for optimized case first */
2021 if (transferOps
== 0 && dstFormat
== GL_RGBA
&& dstType
== CHAN_TYPE
) {
2022 /* common simple case */
2023 _mesa_memcpy(dstAddr
, srcRgba
, n
* 4 * sizeof(GLchan
));
2025 else if (transferOps
== 0 && dstFormat
== GL_RGB
&& dstType
== CHAN_TYPE
) {
2026 /* common simple case */
2028 GLchan
*dest
= (GLchan
*) dstAddr
;
2029 for (i
= 0; i
< n
; i
++) {
2030 dest
[0] = srcRgba
[i
][RCOMP
];
2031 dest
[1] = srcRgba
[i
][GCOMP
];
2032 dest
[2] = srcRgba
[i
][BCOMP
];
2036 else if (transferOps
== 0 && dstFormat
== GL_RGBA
&& dstType
== GL_UNSIGNED_BYTE
) {
2037 /* common simple case */
2039 GLubyte
*dest
= (GLubyte
*) dstAddr
;
2040 for (i
= 0; i
< n
; i
++) {
2041 dest
[0] = CHAN_TO_UBYTE(srcRgba
[i
][RCOMP
]);
2042 dest
[1] = CHAN_TO_UBYTE(srcRgba
[i
][GCOMP
]);
2043 dest
[2] = CHAN_TO_UBYTE(srcRgba
[i
][BCOMP
]);
2044 dest
[3] = CHAN_TO_UBYTE(srcRgba
[i
][ACOMP
]);
2049 /* general solution */
2051 GLfloat rgba
[MAX_WIDTH
][4];
2052 assert(n
<= MAX_WIDTH
);
2053 /* convert color components to floating point */
2054 for (i
= 0; i
< n
; i
++) {
2055 rgba
[i
][RCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][RCOMP
]);
2056 rgba
[i
][GCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][GCOMP
]);
2057 rgba
[i
][BCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][BCOMP
]);
2058 rgba
[i
][ACOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][ACOMP
]);
2060 _mesa_pack_rgba_span_float(ctx
, n
, (const GLfloat (*)[4]) rgba
,
2061 dstFormat
, dstType
, dstAddr
,
2062 dstPacking
, transferOps
);
2067 #define SWAP2BYTE(VALUE) \
2069 GLubyte *bytes = (GLubyte *) &(VALUE); \
2070 GLubyte tmp = bytes[0]; \
2071 bytes[0] = bytes[1]; \
2075 #define SWAP4BYTE(VALUE) \
2077 GLubyte *bytes = (GLubyte *) &(VALUE); \
2078 GLubyte tmp = bytes[0]; \
2079 bytes[0] = bytes[3]; \
2082 bytes[1] = bytes[2]; \
2088 extract_uint_indexes(GLuint n
, GLuint indexes
[],
2089 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2090 const struct gl_pixelstore_attrib
*unpack
)
2092 assert(srcFormat
== GL_COLOR_INDEX
);
2094 ASSERT(srcType
== GL_BITMAP
||
2095 srcType
== GL_UNSIGNED_BYTE
||
2096 srcType
== GL_BYTE
||
2097 srcType
== GL_UNSIGNED_SHORT
||
2098 srcType
== GL_SHORT
||
2099 srcType
== GL_UNSIGNED_INT
||
2100 srcType
== GL_INT
||
2101 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
2102 srcType
== GL_HALF_FLOAT_ARB
||
2103 srcType
== GL_FLOAT
);
2108 GLubyte
*ubsrc
= (GLubyte
*) src
;
2109 if (unpack
->LsbFirst
) {
2110 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
2112 for (i
= 0; i
< n
; i
++) {
2113 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2124 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
2126 for (i
= 0; i
< n
; i
++) {
2127 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2139 case GL_UNSIGNED_BYTE
:
2142 const GLubyte
*s
= (const GLubyte
*) src
;
2143 for (i
= 0; i
< n
; i
++)
2150 const GLbyte
*s
= (const GLbyte
*) src
;
2151 for (i
= 0; i
< n
; i
++)
2155 case GL_UNSIGNED_SHORT
:
2158 const GLushort
*s
= (const GLushort
*) src
;
2159 if (unpack
->SwapBytes
) {
2160 for (i
= 0; i
< n
; i
++) {
2161 GLushort value
= s
[i
];
2167 for (i
= 0; i
< n
; i
++)
2175 const GLshort
*s
= (const GLshort
*) src
;
2176 if (unpack
->SwapBytes
) {
2177 for (i
= 0; i
< n
; i
++) {
2178 GLshort value
= s
[i
];
2184 for (i
= 0; i
< n
; i
++)
2189 case GL_UNSIGNED_INT
:
2192 const GLuint
*s
= (const GLuint
*) src
;
2193 if (unpack
->SwapBytes
) {
2194 for (i
= 0; i
< n
; i
++) {
2195 GLuint value
= s
[i
];
2201 for (i
= 0; i
< n
; i
++)
2209 const GLint
*s
= (const GLint
*) src
;
2210 if (unpack
->SwapBytes
) {
2211 for (i
= 0; i
< n
; i
++) {
2218 for (i
= 0; i
< n
; i
++)
2226 const GLfloat
*s
= (const GLfloat
*) src
;
2227 if (unpack
->SwapBytes
) {
2228 for (i
= 0; i
< n
; i
++) {
2229 GLfloat value
= s
[i
];
2231 indexes
[i
] = (GLuint
) value
;
2235 for (i
= 0; i
< n
; i
++)
2236 indexes
[i
] = (GLuint
) s
[i
];
2240 case GL_HALF_FLOAT_ARB
:
2243 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
2244 if (unpack
->SwapBytes
) {
2245 for (i
= 0; i
< n
; i
++) {
2246 GLhalfARB value
= s
[i
];
2248 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
2252 for (i
= 0; i
< n
; i
++)
2253 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
2257 case GL_UNSIGNED_INT_24_8_EXT
:
2260 const GLuint
*s
= (const GLuint
*) src
;
2261 if (unpack
->SwapBytes
) {
2262 for (i
= 0; i
< n
; i
++) {
2263 GLuint value
= s
[i
];
2265 indexes
[i
] = value
& 0xff; /* lower 8 bits */
2269 for (i
= 0; i
< n
; i
++)
2270 indexes
[i
] = s
[i
] & 0xfff; /* lower 8 bits */
2276 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2283 * This function extracts floating point RGBA values from arbitrary
2284 * image data. srcFormat and srcType are the format and type parameters
2285 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2287 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2288 * implements the "Conversion to floating point", "Conversion to RGB",
2289 * and "Final Expansion to RGBA" operations.
2291 * Args: n - number of pixels
2292 * rgba - output colors
2293 * srcFormat - format of incoming data
2294 * srcType - data type of incoming data
2295 * src - source data pointer
2296 * swapBytes - perform byteswapping of incoming data?
2299 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2300 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2301 GLboolean swapBytes
)
2303 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2305 GLint rComp
, bComp
, gComp
, aComp
;
2307 ASSERT(srcFormat
== GL_RED
||
2308 srcFormat
== GL_GREEN
||
2309 srcFormat
== GL_BLUE
||
2310 srcFormat
== GL_ALPHA
||
2311 srcFormat
== GL_LUMINANCE
||
2312 srcFormat
== GL_LUMINANCE_ALPHA
||
2313 srcFormat
== GL_INTENSITY
||
2314 srcFormat
== GL_RGB
||
2315 srcFormat
== GL_BGR
||
2316 srcFormat
== GL_RGBA
||
2317 srcFormat
== GL_BGRA
||
2318 srcFormat
== GL_ABGR_EXT
);
2320 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2321 srcType
== GL_BYTE
||
2322 srcType
== GL_UNSIGNED_SHORT
||
2323 srcType
== GL_SHORT
||
2324 srcType
== GL_UNSIGNED_INT
||
2325 srcType
== GL_INT
||
2326 srcType
== GL_HALF_FLOAT_ARB
||
2327 srcType
== GL_FLOAT
||
2328 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2329 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2330 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2331 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2332 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2333 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2334 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2335 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2336 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2337 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2338 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2339 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2341 rComp
= gComp
= bComp
= aComp
= -1;
2343 switch (srcFormat
) {
2346 greenIndex
= blueIndex
= alphaIndex
= -1;
2351 redIndex
= blueIndex
= alphaIndex
= -1;
2356 redIndex
= greenIndex
= alphaIndex
= -1;
2360 redIndex
= greenIndex
= blueIndex
= -1;
2365 redIndex
= greenIndex
= blueIndex
= 0;
2369 case GL_LUMINANCE_ALPHA
:
2370 redIndex
= greenIndex
= blueIndex
= 0;
2375 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
2434 _mesa_problem(NULL
, "bad srcFormat in extract float data");
2439 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
2440 if ((INDEX) < 0) { \
2442 for (i = 0; i < n; i++) { \
2443 rgba[i][CHANNEL] = DEFAULT; \
2446 else if (swapBytes) { \
2447 const TYPE *s = (const TYPE *) src; \
2449 for (i = 0; i < n; i++) { \
2450 TYPE value = s[INDEX]; \
2451 if (sizeof(TYPE) == 2) { \
2454 else if (sizeof(TYPE) == 4) { \
2457 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
2462 const TYPE *s = (const TYPE *) src; \
2464 for (i = 0; i < n; i++) { \
2465 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
2471 case GL_UNSIGNED_BYTE
:
2472 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2473 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2474 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2475 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2478 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2479 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2480 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2481 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
2483 case GL_UNSIGNED_SHORT
:
2484 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2485 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2486 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2487 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
2490 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2491 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2492 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2493 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
2495 case GL_UNSIGNED_INT
:
2496 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2497 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2498 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2499 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
2502 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2503 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2504 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2505 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
2508 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2509 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2510 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2511 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
2513 case GL_HALF_FLOAT_ARB
:
2514 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2515 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2516 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2517 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
2519 case GL_UNSIGNED_BYTE_3_3_2
:
2521 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2523 for (i
= 0; i
< n
; i
++) {
2524 GLubyte p
= ubsrc
[i
];
2525 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
2526 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
2527 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
2528 rgba
[i
][aComp
] = 1.0F
;
2532 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2534 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2536 for (i
= 0; i
< n
; i
++) {
2537 GLubyte p
= ubsrc
[i
];
2538 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
2539 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
2540 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
2541 rgba
[i
][aComp
] = 1.0F
;
2545 case GL_UNSIGNED_SHORT_5_6_5
:
2547 const GLushort
*ussrc
= (const GLushort
*) src
;
2549 for (i
= 0; i
< n
; i
++) {
2550 GLushort p
= ussrc
[i
];
2552 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2553 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2554 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2555 rgba
[i
][aComp
] = 1.0F
;
2559 const GLushort
*ussrc
= (const GLushort
*) src
;
2561 for (i
= 0; i
< n
; i
++) {
2562 GLushort p
= ussrc
[i
];
2563 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2564 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2565 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2566 rgba
[i
][aComp
] = 1.0F
;
2570 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2572 const GLushort
*ussrc
= (const GLushort
*) src
;
2574 for (i
= 0; i
< n
; i
++) {
2575 GLushort p
= ussrc
[i
];
2577 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2578 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2579 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2580 rgba
[i
][aComp
] = 1.0F
;
2584 const GLushort
*ussrc
= (const GLushort
*) src
;
2586 for (i
= 0; i
< n
; i
++) {
2587 GLushort p
= ussrc
[i
];
2588 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2589 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2590 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2591 rgba
[i
][aComp
] = 1.0F
;
2595 case GL_UNSIGNED_SHORT_4_4_4_4
:
2597 const GLushort
*ussrc
= (const GLushort
*) src
;
2599 for (i
= 0; i
< n
; i
++) {
2600 GLushort p
= ussrc
[i
];
2602 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2603 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2604 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2605 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2609 const GLushort
*ussrc
= (const GLushort
*) src
;
2611 for (i
= 0; i
< n
; i
++) {
2612 GLushort p
= ussrc
[i
];
2613 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2614 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2615 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2616 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2620 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2622 const GLushort
*ussrc
= (const GLushort
*) src
;
2624 for (i
= 0; i
< n
; i
++) {
2625 GLushort p
= ussrc
[i
];
2627 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2628 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2629 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2630 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2634 const GLushort
*ussrc
= (const GLushort
*) src
;
2636 for (i
= 0; i
< n
; i
++) {
2637 GLushort p
= ussrc
[i
];
2638 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2639 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2640 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2641 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2645 case GL_UNSIGNED_SHORT_5_5_5_1
:
2647 const GLushort
*ussrc
= (const GLushort
*) src
;
2649 for (i
= 0; i
< n
; i
++) {
2650 GLushort p
= ussrc
[i
];
2652 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2653 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2654 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2655 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2659 const GLushort
*ussrc
= (const GLushort
*) src
;
2661 for (i
= 0; i
< n
; i
++) {
2662 GLushort p
= ussrc
[i
];
2663 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2664 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2665 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2666 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2670 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2672 const GLushort
*ussrc
= (const GLushort
*) src
;
2674 for (i
= 0; i
< n
; i
++) {
2675 GLushort p
= ussrc
[i
];
2677 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2678 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2679 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2680 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2684 const GLushort
*ussrc
= (const GLushort
*) src
;
2686 for (i
= 0; i
< n
; i
++) {
2687 GLushort p
= ussrc
[i
];
2688 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2689 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2690 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2691 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2695 case GL_UNSIGNED_INT_8_8_8_8
:
2697 const GLuint
*uisrc
= (const GLuint
*) src
;
2699 for (i
= 0; i
< n
; i
++) {
2700 GLuint p
= uisrc
[i
];
2701 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2702 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2703 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2704 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2708 const GLuint
*uisrc
= (const GLuint
*) src
;
2710 for (i
= 0; i
< n
; i
++) {
2711 GLuint p
= uisrc
[i
];
2712 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2713 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2714 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2715 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2719 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2721 const GLuint
*uisrc
= (const GLuint
*) src
;
2723 for (i
= 0; i
< n
; i
++) {
2724 GLuint p
= uisrc
[i
];
2725 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2726 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2727 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2728 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2732 const GLuint
*uisrc
= (const GLuint
*) src
;
2734 for (i
= 0; i
< n
; i
++) {
2735 GLuint p
= uisrc
[i
];
2736 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2737 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2738 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2739 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2743 case GL_UNSIGNED_INT_10_10_10_2
:
2745 const GLuint
*uisrc
= (const GLuint
*) src
;
2747 for (i
= 0; i
< n
; i
++) {
2748 GLuint p
= uisrc
[i
];
2750 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2751 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2752 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2753 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2757 const GLuint
*uisrc
= (const GLuint
*) src
;
2759 for (i
= 0; i
< n
; i
++) {
2760 GLuint p
= uisrc
[i
];
2761 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2762 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2763 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2764 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2768 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2770 const GLuint
*uisrc
= (const GLuint
*) src
;
2772 for (i
= 0; i
< n
; i
++) {
2773 GLuint p
= uisrc
[i
];
2775 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2776 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2777 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2778 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2782 const GLuint
*uisrc
= (const GLuint
*) src
;
2784 for (i
= 0; i
< n
; i
++) {
2785 GLuint p
= uisrc
[i
];
2786 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2787 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2788 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2789 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2794 _mesa_problem(NULL
, "bad srcType in extract float data");
2801 * Unpack a row of color image data from a client buffer according to
2802 * the pixel unpacking parameters.
2803 * Return GLchan values in the specified dest image format.
2804 * This is used by glDrawPixels and glTexImage?D().
2805 * \param ctx - the context
2806 * n - number of pixels in the span
2807 * dstFormat - format of destination color array
2808 * dest - the destination color array
2809 * srcFormat - source image format
2810 * srcType - source image data type
2811 * source - source image pointer
2812 * srcPacking - pixel unpacking parameters
2813 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
2815 * XXX perhaps expand this to process whole images someday.
2818 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
2819 GLuint n
, GLenum dstFormat
, GLchan dest
[],
2820 GLenum srcFormat
, GLenum srcType
,
2821 const GLvoid
*source
,
2822 const struct gl_pixelstore_attrib
*srcPacking
,
2823 GLuint transferOps
)
2825 ASSERT(dstFormat
== GL_ALPHA
||
2826 dstFormat
== GL_LUMINANCE
||
2827 dstFormat
== GL_LUMINANCE_ALPHA
||
2828 dstFormat
== GL_INTENSITY
||
2829 dstFormat
== GL_RGB
||
2830 dstFormat
== GL_RGBA
||
2831 dstFormat
== GL_COLOR_INDEX
);
2833 ASSERT(srcFormat
== GL_RED
||
2834 srcFormat
== GL_GREEN
||
2835 srcFormat
== GL_BLUE
||
2836 srcFormat
== GL_ALPHA
||
2837 srcFormat
== GL_LUMINANCE
||
2838 srcFormat
== GL_LUMINANCE_ALPHA
||
2839 srcFormat
== GL_INTENSITY
||
2840 srcFormat
== GL_RGB
||
2841 srcFormat
== GL_BGR
||
2842 srcFormat
== GL_RGBA
||
2843 srcFormat
== GL_BGRA
||
2844 srcFormat
== GL_ABGR_EXT
||
2845 srcFormat
== GL_COLOR_INDEX
);
2847 ASSERT(srcType
== GL_BITMAP
||
2848 srcType
== GL_UNSIGNED_BYTE
||
2849 srcType
== GL_BYTE
||
2850 srcType
== GL_UNSIGNED_SHORT
||
2851 srcType
== GL_SHORT
||
2852 srcType
== GL_UNSIGNED_INT
||
2853 srcType
== GL_INT
||
2854 srcType
== GL_HALF_FLOAT_ARB
||
2855 srcType
== GL_FLOAT
||
2856 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2857 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2858 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2859 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2860 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2861 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2862 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2863 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2864 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2865 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2866 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2867 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2869 /* Try simple cases first */
2870 if (transferOps
== 0) {
2871 if (srcType
== CHAN_TYPE
) {
2872 if (dstFormat
== GL_RGBA
) {
2873 if (srcFormat
== GL_RGBA
) {
2874 _mesa_memcpy( dest
, source
, n
* 4 * sizeof(GLchan
) );
2877 else if (srcFormat
== GL_RGB
) {
2879 const GLchan
*src
= (const GLchan
*) source
;
2881 for (i
= 0; i
< n
; i
++) {
2892 else if (dstFormat
== GL_RGB
) {
2893 if (srcFormat
== GL_RGB
) {
2894 _mesa_memcpy( dest
, source
, n
* 3 * sizeof(GLchan
) );
2897 else if (srcFormat
== GL_RGBA
) {
2899 const GLchan
*src
= (const GLchan
*) source
;
2901 for (i
= 0; i
< n
; i
++) {
2911 else if (dstFormat
== srcFormat
) {
2912 GLint comps
= _mesa_components_in_format(srcFormat
);
2914 _mesa_memcpy( dest
, source
, n
* comps
* sizeof(GLchan
) );
2919 * Common situation, loading 8bit RGBA/RGB source images
2920 * into 16/32 bit destination. (OSMesa16/32)
2922 else if (srcType
== GL_UNSIGNED_BYTE
) {
2923 if (dstFormat
== GL_RGBA
) {
2924 if (srcFormat
== GL_RGB
) {
2926 const GLubyte
*src
= (const GLubyte
*) source
;
2928 for (i
= 0; i
< n
; i
++) {
2929 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2930 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2931 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2938 else if (srcFormat
== GL_RGBA
) {
2940 const GLubyte
*src
= (const GLubyte
*) source
;
2942 for (i
= 0; i
< n
; i
++) {
2943 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2944 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2945 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2946 dst
[3] = UBYTE_TO_CHAN(src
[3]);
2953 else if (dstFormat
== GL_RGB
) {
2954 if (srcFormat
== GL_RGB
) {
2956 const GLubyte
*src
= (const GLubyte
*) source
;
2958 for (i
= 0; i
< n
; i
++) {
2959 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2960 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2961 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2967 else if (srcFormat
== GL_RGBA
) {
2969 const GLubyte
*src
= (const GLubyte
*) source
;
2971 for (i
= 0; i
< n
; i
++) {
2972 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2973 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2974 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2985 /* general solution begins here */
2987 GLint dstComponents
;
2988 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2989 GLint dstLuminanceIndex
, dstIntensityIndex
;
2990 GLfloat rgba
[MAX_WIDTH
][4];
2992 dstComponents
= _mesa_components_in_format( dstFormat
);
2993 /* source & dest image formats should have been error checked by now */
2994 assert(dstComponents
> 0);
2997 * Extract image data and convert to RGBA floats
2999 assert(n
<= MAX_WIDTH
);
3000 if (srcFormat
== GL_COLOR_INDEX
) {
3001 GLuint indexes
[MAX_WIDTH
];
3002 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3005 if (dstFormat
== GL_COLOR_INDEX
3006 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
3007 _mesa_map_ci(ctx
, n
, indexes
);
3009 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3010 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3013 if (dstFormat
== GL_COLOR_INDEX
) {
3014 /* convert to GLchan and return */
3016 for (i
= 0; i
< n
; i
++) {
3017 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3022 /* Convert indexes to RGBA */
3023 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3026 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3027 * with color indexes.
3029 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3032 /* non-color index data */
3033 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3034 srcPacking
->SwapBytes
);
3037 /* Need to clamp if returning GLubytes or GLushorts */
3038 #if CHAN_TYPE != GL_FLOAT
3039 transferOps
|= IMAGE_CLAMP_BIT
;
3043 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3046 /* Now determine which color channels we need to produce.
3047 * And determine the dest index (offset) within each color tuple.
3049 switch (dstFormat
) {
3052 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3053 dstLuminanceIndex
= dstIntensityIndex
= -1;
3056 dstLuminanceIndex
= 0;
3057 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3058 dstIntensityIndex
= -1;
3060 case GL_LUMINANCE_ALPHA
:
3061 dstLuminanceIndex
= 0;
3063 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3064 dstIntensityIndex
= -1;
3067 dstIntensityIndex
= 0;
3068 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3069 dstLuminanceIndex
= -1;
3075 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3082 dstLuminanceIndex
= dstIntensityIndex
= -1;
3085 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
3090 /* Now return the GLchan data in the requested dstFormat */
3092 if (dstRedIndex
>= 0) {
3095 for (i
= 0; i
< n
; i
++) {
3096 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
3097 dst
+= dstComponents
;
3101 if (dstGreenIndex
>= 0) {
3104 for (i
= 0; i
< n
; i
++) {
3105 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
3106 dst
+= dstComponents
;
3110 if (dstBlueIndex
>= 0) {
3113 for (i
= 0; i
< n
; i
++) {
3114 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
3115 dst
+= dstComponents
;
3119 if (dstAlphaIndex
>= 0) {
3122 for (i
= 0; i
< n
; i
++) {
3123 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
3124 dst
+= dstComponents
;
3128 if (dstIntensityIndex
>= 0) {
3131 assert(dstIntensityIndex
== 0);
3132 assert(dstComponents
== 1);
3133 for (i
= 0; i
< n
; i
++) {
3134 /* Intensity comes from red channel */
3135 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
3139 if (dstLuminanceIndex
>= 0) {
3142 assert(dstLuminanceIndex
== 0);
3143 for (i
= 0; i
< n
; i
++) {
3144 /* Luminance comes from red channel */
3145 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
3146 dst
+= dstComponents
;
3154 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
3155 * instead of GLchan.
3158 _mesa_unpack_color_span_float( GLcontext
*ctx
,
3159 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
3160 GLenum srcFormat
, GLenum srcType
,
3161 const GLvoid
*source
,
3162 const struct gl_pixelstore_attrib
*srcPacking
,
3163 GLuint transferOps
)
3165 ASSERT(dstFormat
== GL_ALPHA
||
3166 dstFormat
== GL_LUMINANCE
||
3167 dstFormat
== GL_LUMINANCE_ALPHA
||
3168 dstFormat
== GL_INTENSITY
||
3169 dstFormat
== GL_RGB
||
3170 dstFormat
== GL_RGBA
||
3171 dstFormat
== GL_COLOR_INDEX
);
3173 ASSERT(srcFormat
== GL_RED
||
3174 srcFormat
== GL_GREEN
||
3175 srcFormat
== GL_BLUE
||
3176 srcFormat
== GL_ALPHA
||
3177 srcFormat
== GL_LUMINANCE
||
3178 srcFormat
== GL_LUMINANCE_ALPHA
||
3179 srcFormat
== GL_INTENSITY
||
3180 srcFormat
== GL_RGB
||
3181 srcFormat
== GL_BGR
||
3182 srcFormat
== GL_RGBA
||
3183 srcFormat
== GL_BGRA
||
3184 srcFormat
== GL_ABGR_EXT
||
3185 srcFormat
== GL_COLOR_INDEX
);
3187 ASSERT(srcType
== GL_BITMAP
||
3188 srcType
== GL_UNSIGNED_BYTE
||
3189 srcType
== GL_BYTE
||
3190 srcType
== GL_UNSIGNED_SHORT
||
3191 srcType
== GL_SHORT
||
3192 srcType
== GL_UNSIGNED_INT
||
3193 srcType
== GL_INT
||
3194 srcType
== GL_HALF_FLOAT_ARB
||
3195 srcType
== GL_FLOAT
||
3196 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3197 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3198 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3199 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3200 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3201 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3202 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3203 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3204 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3205 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3206 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3207 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3209 /* general solution, no special cases, yet */
3211 GLint dstComponents
;
3212 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3213 GLint dstLuminanceIndex
, dstIntensityIndex
;
3214 GLfloat rgba
[MAX_WIDTH
][4];
3216 dstComponents
= _mesa_components_in_format( dstFormat
);
3217 /* source & dest image formats should have been error checked by now */
3218 assert(dstComponents
> 0);
3221 * Extract image data and convert to RGBA floats
3223 assert(n
<= MAX_WIDTH
);
3224 if (srcFormat
== GL_COLOR_INDEX
) {
3225 GLuint indexes
[MAX_WIDTH
];
3226 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3229 if (dstFormat
== GL_COLOR_INDEX
3230 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
3231 _mesa_map_ci(ctx
, n
, indexes
);
3233 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3234 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3237 if (dstFormat
== GL_COLOR_INDEX
) {
3238 /* convert to GLchan and return */
3240 for (i
= 0; i
< n
; i
++) {
3241 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3246 /* Convert indexes to RGBA */
3247 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3250 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3251 * with color indexes.
3253 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3256 /* non-color index data */
3257 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3258 srcPacking
->SwapBytes
);
3262 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3265 /* Now determine which color channels we need to produce.
3266 * And determine the dest index (offset) within each color tuple.
3268 switch (dstFormat
) {
3271 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3272 dstLuminanceIndex
= dstIntensityIndex
= -1;
3275 dstLuminanceIndex
= 0;
3276 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3277 dstIntensityIndex
= -1;
3279 case GL_LUMINANCE_ALPHA
:
3280 dstLuminanceIndex
= 0;
3282 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3283 dstIntensityIndex
= -1;
3286 dstIntensityIndex
= 0;
3287 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3288 dstLuminanceIndex
= -1;
3294 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3301 dstLuminanceIndex
= dstIntensityIndex
= -1;
3304 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
3308 /* Now pack results in the requested dstFormat */
3309 if (dstRedIndex
>= 0) {
3310 GLfloat
*dst
= dest
;
3312 for (i
= 0; i
< n
; i
++) {
3313 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3314 dst
+= dstComponents
;
3318 if (dstGreenIndex
>= 0) {
3319 GLfloat
*dst
= dest
;
3321 for (i
= 0; i
< n
; i
++) {
3322 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3323 dst
+= dstComponents
;
3327 if (dstBlueIndex
>= 0) {
3328 GLfloat
*dst
= dest
;
3330 for (i
= 0; i
< n
; i
++) {
3331 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3332 dst
+= dstComponents
;
3336 if (dstAlphaIndex
>= 0) {
3337 GLfloat
*dst
= dest
;
3339 for (i
= 0; i
< n
; i
++) {
3340 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3341 dst
+= dstComponents
;
3345 if (dstIntensityIndex
>= 0) {
3346 GLfloat
*dst
= dest
;
3348 assert(dstIntensityIndex
== 0);
3349 assert(dstComponents
== 1);
3350 for (i
= 0; i
< n
; i
++) {
3351 /* Intensity comes from red channel */
3352 dst
[i
] = rgba
[i
][RCOMP
];
3356 if (dstLuminanceIndex
>= 0) {
3357 GLfloat
*dst
= dest
;
3359 assert(dstLuminanceIndex
== 0);
3360 for (i
= 0; i
< n
; i
++) {
3361 /* Luminance comes from red channel */
3362 dst
[0] = rgba
[i
][RCOMP
];
3363 dst
+= dstComponents
;
3371 * Unpack a row of color index data from a client buffer according to
3372 * the pixel unpacking parameters.
3373 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
3375 * Args: ctx - the context
3376 * n - number of pixels
3377 * dstType - destination data type
3378 * dest - destination array
3379 * srcType - source pixel type
3380 * source - source data pointer
3381 * srcPacking - pixel unpacking parameters
3382 * transferOps - the pixel transfer operations to apply
3385 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
3386 GLenum dstType
, GLvoid
*dest
,
3387 GLenum srcType
, const GLvoid
*source
,
3388 const struct gl_pixelstore_attrib
*srcPacking
,
3389 GLuint transferOps
)
3391 ASSERT(srcType
== GL_BITMAP
||
3392 srcType
== GL_UNSIGNED_BYTE
||
3393 srcType
== GL_BYTE
||
3394 srcType
== GL_UNSIGNED_SHORT
||
3395 srcType
== GL_SHORT
||
3396 srcType
== GL_UNSIGNED_INT
||
3397 srcType
== GL_INT
||
3398 srcType
== GL_HALF_FLOAT_ARB
||
3399 srcType
== GL_FLOAT
);
3401 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3402 dstType
== GL_UNSIGNED_SHORT
||
3403 dstType
== GL_UNSIGNED_INT
);
3406 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3409 * Try simple cases first
3411 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
3412 && dstType
== GL_UNSIGNED_BYTE
) {
3413 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
3415 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
3416 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
3417 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
3423 GLuint indexes
[MAX_WIDTH
];
3424 assert(n
<= MAX_WIDTH
);
3426 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3429 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3430 /* shift and offset indexes */
3431 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3433 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3434 /* Apply lookup table */
3435 _mesa_map_ci(ctx
, n
, indexes
);
3438 /* convert to dest type */
3440 case GL_UNSIGNED_BYTE
:
3442 GLubyte
*dst
= (GLubyte
*) dest
;
3444 for (i
= 0; i
< n
; i
++) {
3445 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3449 case GL_UNSIGNED_SHORT
:
3451 GLuint
*dst
= (GLuint
*) dest
;
3453 for (i
= 0; i
< n
; i
++) {
3454 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3458 case GL_UNSIGNED_INT
:
3459 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
3462 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
3469 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
3470 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
3471 const struct gl_pixelstore_attrib
*dstPacking
,
3472 GLuint transferOps
)
3474 GLuint indexes
[MAX_WIDTH
];
3476 ASSERT(n
<= MAX_WIDTH
);
3478 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3480 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
3481 /* make a copy of input */
3482 _mesa_memcpy(indexes
, source
, n
* sizeof(GLuint
));
3483 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3484 _mesa_shift_and_offset_ci( ctx
, n
, indexes
);
3486 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3487 _mesa_map_ci(ctx
, n
, indexes
);
3493 case GL_UNSIGNED_BYTE
:
3495 GLubyte
*dst
= (GLubyte
*) dest
;
3497 for (i
= 0; i
< n
; i
++) {
3498 *dst
++ = (GLubyte
) source
[i
];
3504 GLbyte
*dst
= (GLbyte
*) dest
;
3506 for (i
= 0; i
< n
; i
++) {
3507 dst
[i
] = (GLbyte
) source
[i
];
3511 case GL_UNSIGNED_SHORT
:
3513 GLushort
*dst
= (GLushort
*) dest
;
3515 for (i
= 0; i
< n
; i
++) {
3516 dst
[i
] = (GLushort
) source
[i
];
3518 if (dstPacking
->SwapBytes
) {
3519 _mesa_swap2( (GLushort
*) dst
, n
);
3525 GLshort
*dst
= (GLshort
*) dest
;
3527 for (i
= 0; i
< n
; i
++) {
3528 dst
[i
] = (GLshort
) source
[i
];
3530 if (dstPacking
->SwapBytes
) {
3531 _mesa_swap2( (GLushort
*) dst
, n
);
3535 case GL_UNSIGNED_INT
:
3537 GLuint
*dst
= (GLuint
*) dest
;
3539 for (i
= 0; i
< n
; i
++) {
3540 dst
[i
] = (GLuint
) source
[i
];
3542 if (dstPacking
->SwapBytes
) {
3543 _mesa_swap4( (GLuint
*) dst
, n
);
3549 GLint
*dst
= (GLint
*) dest
;
3551 for (i
= 0; i
< n
; i
++) {
3552 dst
[i
] = (GLint
) source
[i
];
3554 if (dstPacking
->SwapBytes
) {
3555 _mesa_swap4( (GLuint
*) dst
, n
);
3561 GLfloat
*dst
= (GLfloat
*) dest
;
3563 for (i
= 0; i
< n
; i
++) {
3564 dst
[i
] = (GLfloat
) source
[i
];
3566 if (dstPacking
->SwapBytes
) {
3567 _mesa_swap4( (GLuint
*) dst
, n
);
3571 case GL_HALF_FLOAT_ARB
:
3573 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
3575 for (i
= 0; i
< n
; i
++) {
3576 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
3578 if (dstPacking
->SwapBytes
) {
3579 _mesa_swap2( (GLushort
*) dst
, n
);
3584 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3590 * Unpack a row of stencil data from a client buffer according to
3591 * the pixel unpacking parameters.
3592 * This is (or will be) used by glDrawPixels
3594 * Args: ctx - the context
3595 * n - number of pixels
3596 * dstType - destination data type
3597 * dest - destination array
3598 * srcType - source pixel type
3599 * source - source data pointer
3600 * srcPacking - pixel unpacking parameters
3601 * transferOps - apply offset/bias/lookup ops?
3604 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3605 GLenum dstType
, GLvoid
*dest
,
3606 GLenum srcType
, const GLvoid
*source
,
3607 const struct gl_pixelstore_attrib
*srcPacking
,
3608 GLuint transferOps
)
3610 ASSERT(srcType
== GL_BITMAP
||
3611 srcType
== GL_UNSIGNED_BYTE
||
3612 srcType
== GL_BYTE
||
3613 srcType
== GL_UNSIGNED_SHORT
||
3614 srcType
== GL_SHORT
||
3615 srcType
== GL_UNSIGNED_INT
||
3616 srcType
== GL_INT
||
3617 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
3618 srcType
== GL_HALF_FLOAT_ARB
||
3619 srcType
== GL_FLOAT
);
3621 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3622 dstType
== GL_UNSIGNED_SHORT
||
3623 dstType
== GL_UNSIGNED_INT
);
3625 /* only shift and offset apply to stencil */
3626 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
3629 * Try simple cases first
3631 if (transferOps
== 0 &&
3632 srcType
== GL_UNSIGNED_BYTE
&&
3633 dstType
== GL_UNSIGNED_BYTE
) {
3634 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
3636 else if (transferOps
== 0 &&
3637 srcType
== GL_UNSIGNED_INT
&&
3638 dstType
== GL_UNSIGNED_INT
&&
3639 !srcPacking
->SwapBytes
) {
3640 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
3646 GLuint indexes
[MAX_WIDTH
];
3647 assert(n
<= MAX_WIDTH
);
3649 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3653 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3654 /* shift and offset indexes */
3655 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3658 if (ctx
->Pixel
.MapStencilFlag
) {
3659 /* Apply stencil lookup table */
3660 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
3663 indexes
[i
] = ctx
->Pixel
.MapStoS
[ indexes
[i
] & mask
];
3668 /* convert to dest type */
3670 case GL_UNSIGNED_BYTE
:
3672 GLubyte
*dst
= (GLubyte
*) dest
;
3674 for (i
= 0; i
< n
; i
++) {
3675 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3679 case GL_UNSIGNED_SHORT
:
3681 GLuint
*dst
= (GLuint
*) dest
;
3683 for (i
= 0; i
< n
; i
++) {
3684 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3688 case GL_UNSIGNED_INT
:
3689 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
3692 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
3699 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3700 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
3701 const struct gl_pixelstore_attrib
*dstPacking
)
3703 GLstencil stencil
[MAX_WIDTH
];
3705 ASSERT(n
<= MAX_WIDTH
);
3707 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
3708 ctx
->Pixel
.MapStencilFlag
) {
3709 /* make a copy of input */
3710 _mesa_memcpy(stencil
, source
, n
* sizeof(GLstencil
));
3711 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
3712 _mesa_shift_and_offset_stencil( ctx
, n
, stencil
);
3714 if (ctx
->Pixel
.MapStencilFlag
) {
3715 _mesa_map_stencil( ctx
, n
, stencil
);
3721 case GL_UNSIGNED_BYTE
:
3722 if (sizeof(GLstencil
) == 8) {
3723 _mesa_memcpy( dest
, source
, n
);
3726 GLubyte
*dst
= (GLubyte
*) dest
;
3729 dst
[i
] = (GLubyte
) source
[i
];
3734 if (sizeof(GLstencil
) == 8) {
3735 _mesa_memcpy( dest
, source
, n
);
3738 GLbyte
*dst
= (GLbyte
*) dest
;
3741 dst
[i
] = (GLbyte
) source
[i
];
3745 case GL_UNSIGNED_SHORT
:
3747 GLushort
*dst
= (GLushort
*) dest
;
3750 dst
[i
] = (GLushort
) source
[i
];
3752 if (dstPacking
->SwapBytes
) {
3753 _mesa_swap2( (GLushort
*) dst
, n
);
3759 GLshort
*dst
= (GLshort
*) dest
;
3762 dst
[i
] = (GLshort
) source
[i
];
3764 if (dstPacking
->SwapBytes
) {
3765 _mesa_swap2( (GLushort
*) dst
, n
);
3769 case GL_UNSIGNED_INT
:
3771 GLuint
*dst
= (GLuint
*) dest
;
3774 dst
[i
] = (GLuint
) source
[i
];
3776 if (dstPacking
->SwapBytes
) {
3777 _mesa_swap4( (GLuint
*) dst
, n
);
3783 GLint
*dst
= (GLint
*) dest
;
3786 *dst
++ = (GLint
) source
[i
];
3788 if (dstPacking
->SwapBytes
) {
3789 _mesa_swap4( (GLuint
*) dst
, n
);
3795 GLfloat
*dst
= (GLfloat
*) dest
;
3798 dst
[i
] = (GLfloat
) source
[i
];
3800 if (dstPacking
->SwapBytes
) {
3801 _mesa_swap4( (GLuint
*) dst
, n
);
3805 case GL_HALF_FLOAT_ARB
:
3807 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
3810 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
3812 if (dstPacking
->SwapBytes
) {
3813 _mesa_swap2( (GLushort
*) dst
, n
);
3818 if (dstPacking
->LsbFirst
) {
3819 GLubyte
*dst
= (GLubyte
*) dest
;
3822 for (i
= 0; i
< n
; i
++) {
3825 *dst
|= ((source
[i
] != 0) << shift
);
3834 GLubyte
*dst
= (GLubyte
*) dest
;
3837 for (i
= 0; i
< n
; i
++) {
3840 *dst
|= ((source
[i
] != 0) << shift
);
3850 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3856 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
,
3857 GLenum dstType
, GLvoid
*dest
, GLfloat depthScale
,
3858 GLenum srcType
, const GLvoid
*source
,
3859 const struct gl_pixelstore_attrib
*srcPacking
)
3861 GLfloat depthTemp
[MAX_WIDTH
], *depthValues
;
3863 if (dstType
== GL_FLOAT
) {
3864 depthValues
= (GLfloat
*) dest
;
3867 depthValues
= depthTemp
;
3870 /* XXX we need to obey srcPacking->SwapBytes here!!! */
3877 const GLubyte
*src
= (const GLubyte
*) source
;
3878 for (i
= 0; i
< n
; i
++) {
3879 depthValues
[i
] = BYTE_TO_FLOAT(src
[i
]);
3883 case GL_UNSIGNED_BYTE
:
3886 const GLubyte
*src
= (const GLubyte
*) source
;
3887 for (i
= 0; i
< n
; i
++) {
3888 depthValues
[i
] = UBYTE_TO_FLOAT(src
[i
]);
3895 const GLshort
*src
= (const GLshort
*) source
;
3896 for (i
= 0; i
< n
; i
++) {
3897 depthValues
[i
] = SHORT_TO_FLOAT(src
[i
]);
3901 case GL_UNSIGNED_SHORT
:
3904 const GLushort
*src
= (const GLushort
*) source
;
3905 for (i
= 0; i
< n
; i
++) {
3906 depthValues
[i
] = USHORT_TO_FLOAT(src
[i
]);
3913 const GLint
*src
= (const GLint
*) source
;
3914 for (i
= 0; i
< n
; i
++) {
3915 depthValues
[i
] = INT_TO_FLOAT(src
[i
]);
3919 case GL_UNSIGNED_INT
:
3922 const GLuint
*src
= (const GLuint
*) source
;
3923 for (i
= 0; i
< n
; i
++) {
3924 depthValues
[i
] = UINT_TO_FLOAT(src
[i
]);
3928 case GL_UNSIGNED_INT_24_8_EXT
: /* GL_EXT_packed_depth_stencil */
3929 if (dstType
== GL_UNSIGNED_INT
&&
3930 depthScale
== (GLfloat
) 0xffffff &&
3931 ctx
->Pixel
.DepthScale
== 1.0 &&
3932 ctx
->Pixel
.DepthBias
== 0.0) {
3933 const GLuint
*src
= (const GLuint
*) source
;
3934 GLuint
*zValues
= (GLuint
*) dest
;
3936 for (i
= 0; i
< n
; i
++) {
3937 zValues
[i
] = src
[i
] & 0xffffff00;
3942 const GLuint
*src
= (const GLuint
*) source
;
3943 const GLfloat scale
= 1.0f
/ 0xffffff;
3945 for (i
= 0; i
< n
; i
++) {
3946 depthValues
[i
] = (src
[i
] >> 8) * scale
;
3951 _mesa_memcpy(depthValues
, source
, n
* sizeof(GLfloat
));
3953 case GL_HALF_FLOAT_ARB
:
3956 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
3957 for (i
= 0; i
< n
; i
++) {
3958 depthValues
[i
] = _mesa_half_to_float(src
[i
]);
3963 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
3968 /* apply depth scale and bias and clamp to [0,1] */
3969 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
3970 _mesa_scale_and_bias_depth(ctx
, n
, depthValues
);
3973 if (dstType
== GL_UNSIGNED_INT
) {
3974 GLuint
*zValues
= (GLuint
*) dest
;
3976 if (depthScale
<= (GLfloat
) 0xffffff) {
3977 /* no overflow worries */
3978 for (i
= 0; i
< n
; i
++) {
3979 zValues
[i
] = (GLuint
) (depthValues
[i
] * depthScale
);
3983 /* need to use double precision to prevent overflow problems */
3984 for (i
= 0; i
< n
; i
++) {
3985 GLdouble z
= depthValues
[i
] * depthScale
;
3986 if (z
>= (GLdouble
) 0xffffffff)
3987 zValues
[i
] = 0xffffffff;
3989 zValues
[i
] = (GLuint
) z
;
3993 else if (dstType
== GL_UNSIGNED_SHORT
) {
3994 GLushort
*zValues
= (GLushort
*) dest
;
3996 ASSERT(depthScale
<= 65535.0);
3997 for (i
= 0; i
< n
; i
++) {
3998 zValues
[i
] = (GLushort
) (depthValues
[i
] * depthScale
);
4002 ASSERT(dstType
== GL_FLOAT
);
4003 ASSERT(depthScale
== 1.0F
);
4009 * Pack an array of depth values. The values are floats in [0,1].
4012 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
4013 GLenum dstType
, const GLfloat
*depthSpan
,
4014 const struct gl_pixelstore_attrib
*dstPacking
)
4016 GLfloat depthCopy
[MAX_WIDTH
];
4018 ASSERT(n
<= MAX_WIDTH
);
4020 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4021 _mesa_memcpy(depthCopy
, depthSpan
, n
* sizeof(GLfloat
));
4022 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4023 depthSpan
= depthCopy
;
4027 case GL_UNSIGNED_BYTE
:
4029 GLubyte
*dst
= (GLubyte
*) dest
;
4031 for (i
= 0; i
< n
; i
++) {
4032 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
4038 GLbyte
*dst
= (GLbyte
*) dest
;
4040 for (i
= 0; i
< n
; i
++) {
4041 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
4045 case GL_UNSIGNED_SHORT
:
4047 GLushort
*dst
= (GLushort
*) dest
;
4049 for (i
= 0; i
< n
; i
++) {
4050 CLAMPED_FLOAT_TO_USHORT(dst
[i
], depthSpan
[i
]);
4052 if (dstPacking
->SwapBytes
) {
4053 _mesa_swap2( (GLushort
*) dst
, n
);
4059 GLshort
*dst
= (GLshort
*) dest
;
4061 for (i
= 0; i
< n
; i
++) {
4062 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
4064 if (dstPacking
->SwapBytes
) {
4065 _mesa_swap2( (GLushort
*) dst
, n
);
4069 case GL_UNSIGNED_INT
:
4071 GLuint
*dst
= (GLuint
*) dest
;
4073 for (i
= 0; i
< n
; i
++) {
4074 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
4076 if (dstPacking
->SwapBytes
) {
4077 _mesa_swap4( (GLuint
*) dst
, n
);
4083 GLint
*dst
= (GLint
*) dest
;
4085 for (i
= 0; i
< n
; i
++) {
4086 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
4088 if (dstPacking
->SwapBytes
) {
4089 _mesa_swap4( (GLuint
*) dst
, n
);
4095 GLfloat
*dst
= (GLfloat
*) dest
;
4097 for (i
= 0; i
< n
; i
++) {
4098 dst
[i
] = depthSpan
[i
];
4100 if (dstPacking
->SwapBytes
) {
4101 _mesa_swap4( (GLuint
*) dst
, n
);
4105 case GL_HALF_FLOAT_ARB
:
4107 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4109 for (i
= 0; i
< n
; i
++) {
4110 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
4112 if (dstPacking
->SwapBytes
) {
4113 _mesa_swap2( (GLushort
*) dst
, n
);
4118 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
4125 * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
4128 _mesa_pack_depth_stencil_span(const GLcontext
*ctx
, GLuint n
, GLuint
*dest
,
4129 const GLfloat
*depthVals
,
4130 const GLstencil
*stencilVals
,
4131 const struct gl_pixelstore_attrib
*dstPacking
)
4133 GLfloat depthCopy
[MAX_WIDTH
];
4134 GLstencil stencilCopy
[MAX_WIDTH
];
4137 ASSERT(n
<= MAX_WIDTH
);
4139 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4140 _mesa_memcpy(depthCopy
, depthVals
, n
* sizeof(GLfloat
));
4141 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4142 depthVals
= depthCopy
;
4145 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
4146 _mesa_memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
4147 _mesa_shift_and_offset_stencil(ctx
, n
, stencilCopy
);
4148 stencilVals
= stencilCopy
;
4150 if (ctx
->Pixel
.MapStencilFlag
) {
4151 if (stencilVals
!= stencilCopy
)
4152 _mesa_memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
4153 _mesa_map_stencil(ctx
, n
, stencilCopy
);
4154 stencilVals
= stencilCopy
;
4157 for (i
= 0; i
< n
; i
++) {
4158 GLuint z
= (GLuint
) (depthVals
[i
] * 0xffffff);
4159 dest
[i
] = (z
<< 8) | (stencilVals
[i
] & 0xff);
4162 if (dstPacking
->SwapBytes
) {
4163 _mesa_swap4(dest
, n
);
4171 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
4172 * Return all image data in a contiguous block. This is used when we
4173 * compile glDrawPixels, glTexImage, etc into a display list. We
4174 * need a copy of the data in a standard format.
4177 _mesa_unpack_image( GLuint dimensions
,
4178 GLsizei width
, GLsizei height
, GLsizei depth
,
4179 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4180 const struct gl_pixelstore_attrib
*unpack
)
4182 GLint bytesPerRow
, compsPerRow
;
4183 GLboolean flipBytes
, swap2
, swap4
;
4186 return NULL
; /* not necessarily an error */
4188 if (width
<= 0 || height
<= 0 || depth
<= 0)
4189 return NULL
; /* generate error later */
4191 if (format
== GL_BITMAP
) {
4192 bytesPerRow
= (width
+ 7) >> 3;
4193 flipBytes
= !unpack
->LsbFirst
;
4194 swap2
= swap4
= GL_FALSE
;
4198 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
4199 const GLint components
= _mesa_components_in_format(format
);
4201 if (bytesPerPixel
<= 0 || components
<= 0)
4202 return NULL
; /* bad format or type. generate error later */
4203 bytesPerRow
= bytesPerPixel
* width
;
4204 bytesPerComp
= bytesPerPixel
/ components
;
4205 flipBytes
= GL_FALSE
;
4206 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
4207 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
4208 compsPerRow
= components
* width
;
4209 assert(compsPerRow
>= width
);
4214 = (GLubyte
*) _mesa_malloc(bytesPerRow
* height
* depth
);
4218 return NULL
; /* generate GL_OUT_OF_MEMORY later */
4221 for (img
= 0; img
< depth
; img
++) {
4222 for (row
= 0; row
< height
; row
++) {
4223 const GLvoid
*src
= _mesa_image_address(dimensions
, unpack
, pixels
,
4224 width
, height
, format
, type
, img
, row
, 0);
4225 _mesa_memcpy(dst
, src
, bytesPerRow
);
4226 /* byte flipping/swapping */
4228 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
4231 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
4234 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
4243 #endif /* _HAVE_FULL_GL */
4247 * Perform clipping for glDrawPixels. The image's window position
4248 * and size, and the unpack SkipPixels and SkipRows are adjusted so
4249 * that the image region is entirely within the window and scissor bounds.
4250 * NOTE: this will only work when glPixelZoom is (1, 1).
4252 * \return GL_TRUE if image is ready for drawing or
4253 * GL_FALSE if image was completely clipped away (draw nothing)
4256 _mesa_clip_drawpixels(const GLcontext
*ctx
,
4257 GLint
*destX
, GLint
*destY
,
4258 GLsizei
*width
, GLsizei
*height
,
4259 struct gl_pixelstore_attrib
*unpack
)
4261 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
4263 if (unpack
->RowLength
== 0) {
4264 unpack
->RowLength
= *width
;
4267 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
&& ctx
->Pixel
.ZoomY
== 1.0F
);
4270 if (*destX
< buffer
->_Xmin
) {
4271 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
4272 *width
-= (buffer
->_Xmin
- *destX
);
4273 *destX
= buffer
->_Xmin
;
4275 /* right clipping */
4276 if (*destX
+ *width
> buffer
->_Xmax
)
4277 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
4282 /* bottom clipping */
4283 if (*destY
< buffer
->_Ymin
) {
4284 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
4285 *height
-= (buffer
->_Ymin
- *destY
);
4286 *destY
= buffer
->_Ymin
;
4289 if (*destY
+ *height
> buffer
->_Ymax
)
4290 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
4300 * Perform clipping for glReadPixels. The image's window position
4301 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
4302 * so that the image region is entirely within the window bounds.
4303 * Note: this is different from _mesa_clip_drawpixels() in that the
4304 * scissor box is ignored, and we use the bounds of the current readbuffer
4307 * \return GL_TRUE if image is ready for drawing or
4308 * GL_FALSE if image was completely clipped away (draw nothing)
4311 _mesa_clip_readpixels(const GLcontext
*ctx
,
4312 GLint
*srcX
, GLint
*srcY
,
4313 GLsizei
*width
, GLsizei
*height
,
4314 struct gl_pixelstore_attrib
*pack
)
4316 const GLframebuffer
*buffer
= ctx
->ReadBuffer
;
4318 if (pack
->RowLength
== 0) {
4319 pack
->RowLength
= *width
;
4324 pack
->SkipPixels
+= (0 - *srcX
);
4325 *width
-= (0 - *srcX
);
4328 /* right clipping */
4329 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
4330 *width
-= (*srcX
+ *width
- buffer
->Width
);
4335 /* bottom clipping */
4337 pack
->SkipRows
+= (0 - *srcY
);
4338 *height
-= (0 - *srcY
);
4342 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
4343 *height
-= (*srcY
+ *height
- buffer
->Height
);
4353 * Clip the rectangle defined by (x, y, width, height) against the bounds
4354 * specified by [xmin, xmax) and [ymin, ymax).
4355 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
4358 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
4359 GLint xmax
, GLint ymax
,
4361 GLsizei
*width
, GLsizei
*height
)
4365 *width
-= (xmin
- *x
);
4369 /* right clipping */
4370 if (*x
+ *width
> xmax
)
4371 *width
-= (*x
+ *width
- xmax
- 1);
4376 /* bottom (or top) clipping */
4378 *height
-= (ymin
- *y
);
4382 /* top (or bottom) clipping */
4383 if (*y
+ *height
> ymax
)
4384 *height
-= (*y
+ *height
- ymax
- 1);