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
, GLbitfield 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 * Incoming colors will be clamped to [0,1] if needed.
1068 * Note: the rgba values will be modified by this function when any pixel
1069 * transfer ops are enabled.
1072 _mesa_pack_rgba_span_float(GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4],
1073 GLenum dstFormat
, GLenum dstType
,
1075 const struct gl_pixelstore_attrib
*dstPacking
,
1076 GLbitfield transferOps
)
1078 GLfloat luminance
[MAX_WIDTH
];
1079 const GLint comps
= _mesa_components_in_format(dstFormat
);
1082 if (dstType
!= GL_FLOAT
) {
1083 /* need to clamp to [0, 1] */
1084 transferOps
|= IMAGE_CLAMP_BIT
;
1088 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
1089 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
1094 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
1095 /* compute luminance values */
1096 if (ctx
->Color
.ClampReadColor
== GL_TRUE
|| dstType
!= GL_FLOAT
) {
1097 for (i
= 0; i
< n
; i
++) {
1098 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1099 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
1103 for (i
= 0; i
< n
; i
++) {
1104 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1110 * Pack/store the pixels. Ugh! Lots of cases!!!
1113 case GL_UNSIGNED_BYTE
:
1115 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1116 switch (dstFormat
) {
1119 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1123 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1127 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1131 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1135 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1137 case GL_LUMINANCE_ALPHA
:
1139 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1140 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1145 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1146 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1147 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1152 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1153 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1154 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1155 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1160 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1161 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1162 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1167 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1168 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1169 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1170 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1175 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1176 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1177 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1178 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1182 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1188 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1189 switch (dstFormat
) {
1192 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1196 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1200 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1204 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1208 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1210 case GL_LUMINANCE_ALPHA
:
1212 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1213 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1218 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1219 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1220 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1225 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1226 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1227 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1228 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1233 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1234 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1235 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1240 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1241 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1242 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1243 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1247 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1248 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1249 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1250 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1254 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1258 case GL_UNSIGNED_SHORT
:
1260 GLushort
*dst
= (GLushort
*) dstAddr
;
1261 switch (dstFormat
) {
1264 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][RCOMP
]);
1268 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][GCOMP
]);
1272 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][BCOMP
]);
1276 CLAMPED_FLOAT_TO_USHORT(dst
[i
], rgba
[i
][ACOMP
]);
1280 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
], luminance
[i
]);
1282 case GL_LUMINANCE_ALPHA
:
1284 UNCLAMPED_FLOAT_TO_USHORT(dst
[i
*2+0], luminance
[i
]);
1285 CLAMPED_FLOAT_TO_USHORT(dst
[i
*2+1], rgba
[i
][ACOMP
]);
1290 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][RCOMP
]);
1291 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1292 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][BCOMP
]);
1297 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][RCOMP
]);
1298 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1299 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][BCOMP
]);
1300 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1305 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+0], rgba
[i
][BCOMP
]);
1306 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+1], rgba
[i
][GCOMP
]);
1307 CLAMPED_FLOAT_TO_USHORT(dst
[i
*3+2], rgba
[i
][RCOMP
]);
1312 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][BCOMP
]);
1313 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][GCOMP
]);
1314 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][RCOMP
]);
1315 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][ACOMP
]);
1320 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+0], rgba
[i
][ACOMP
]);
1321 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+1], rgba
[i
][BCOMP
]);
1322 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+2], rgba
[i
][GCOMP
]);
1323 CLAMPED_FLOAT_TO_USHORT(dst
[i
*4+3], rgba
[i
][RCOMP
]);
1327 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1329 if (dstPacking
->SwapBytes
) {
1330 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1336 GLshort
*dst
= (GLshort
*) dstAddr
;
1337 switch (dstFormat
) {
1340 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1344 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1348 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1352 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1356 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
1358 case GL_LUMINANCE_ALPHA
:
1360 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
1361 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1366 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1367 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1368 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1373 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1374 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1375 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1376 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1381 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1382 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1383 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1388 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1389 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1390 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1391 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1395 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1396 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1397 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1398 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1402 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1404 if (dstPacking
->SwapBytes
) {
1405 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1409 case GL_UNSIGNED_INT
:
1411 GLuint
*dst
= (GLuint
*) dstAddr
;
1412 switch (dstFormat
) {
1415 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1419 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1423 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1427 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1431 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
1433 case GL_LUMINANCE_ALPHA
:
1435 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
1436 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1441 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1442 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1443 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1448 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1449 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1450 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1451 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1456 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1457 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1458 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1463 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1464 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1465 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1466 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1471 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1472 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1473 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1474 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1478 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1480 if (dstPacking
->SwapBytes
) {
1481 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1487 GLint
*dst
= (GLint
*) dstAddr
;
1488 switch (dstFormat
) {
1491 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1495 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1499 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1503 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1507 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1509 case GL_LUMINANCE_ALPHA
:
1511 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1512 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1517 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1518 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1519 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1524 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1525 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1526 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1527 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1532 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1533 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1534 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1539 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1540 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1541 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1542 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1547 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1548 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1549 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1550 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1554 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1556 if (dstPacking
->SwapBytes
) {
1557 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1563 GLfloat
*dst
= (GLfloat
*) dstAddr
;
1564 switch (dstFormat
) {
1567 dst
[i
] = rgba
[i
][RCOMP
];
1571 dst
[i
] = rgba
[i
][GCOMP
];
1575 dst
[i
] = rgba
[i
][BCOMP
];
1579 dst
[i
] = rgba
[i
][ACOMP
];
1583 dst
[i
] = luminance
[i
];
1585 case GL_LUMINANCE_ALPHA
:
1587 dst
[i
*2+0] = luminance
[i
];
1588 dst
[i
*2+1] = rgba
[i
][ACOMP
];
1593 dst
[i
*3+0] = rgba
[i
][RCOMP
];
1594 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1595 dst
[i
*3+2] = rgba
[i
][BCOMP
];
1600 dst
[i
*4+0] = rgba
[i
][RCOMP
];
1601 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1602 dst
[i
*4+2] = rgba
[i
][BCOMP
];
1603 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1608 dst
[i
*3+0] = rgba
[i
][BCOMP
];
1609 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1610 dst
[i
*3+2] = rgba
[i
][RCOMP
];
1615 dst
[i
*4+0] = rgba
[i
][BCOMP
];
1616 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1617 dst
[i
*4+2] = rgba
[i
][RCOMP
];
1618 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1623 dst
[i
*4+0] = rgba
[i
][ACOMP
];
1624 dst
[i
*4+1] = rgba
[i
][BCOMP
];
1625 dst
[i
*4+2] = rgba
[i
][GCOMP
];
1626 dst
[i
*4+3] = rgba
[i
][RCOMP
];
1630 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1632 if (dstPacking
->SwapBytes
) {
1633 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1637 case GL_HALF_FLOAT_ARB
:
1639 GLhalfARB
*dst
= (GLhalfARB
*) dstAddr
;
1640 switch (dstFormat
) {
1643 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1647 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1651 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1655 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1659 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
1661 case GL_LUMINANCE_ALPHA
:
1663 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
1664 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1669 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1670 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1671 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1676 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1677 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1678 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1679 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1684 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1685 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1686 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1691 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1692 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1693 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1694 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1699 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1700 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1701 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1702 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1706 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1708 if (dstPacking
->SwapBytes
) {
1709 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1713 case GL_UNSIGNED_BYTE_3_3_2
:
1714 if (dstFormat
== GL_RGB
) {
1715 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1717 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
1718 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
1719 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
1723 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1724 if (dstFormat
== GL_RGB
) {
1725 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1727 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
1728 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
1729 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 5);
1733 case GL_UNSIGNED_SHORT_5_6_5
:
1734 if (dstFormat
== GL_RGB
) {
1735 GLushort
*dst
= (GLushort
*) dstAddr
;
1737 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1738 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1739 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
1743 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1744 if (dstFormat
== GL_RGB
) {
1745 GLushort
*dst
= (GLushort
*) dstAddr
;
1747 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1748 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1749 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
1753 case GL_UNSIGNED_SHORT_4_4_4_4
:
1754 if (dstFormat
== GL_RGBA
) {
1755 GLushort
*dst
= (GLushort
*) dstAddr
;
1757 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
1758 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1759 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1760 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1763 else if (dstFormat
== GL_BGRA
) {
1764 GLushort
*dst
= (GLushort
*) dstAddr
;
1766 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 12)
1767 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1768 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 4)
1769 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1772 else if (dstFormat
== GL_ABGR_EXT
) {
1773 GLushort
*dst
= (GLushort
*) dstAddr
;
1775 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 4)
1776 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1777 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 12)
1778 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) );
1782 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1783 if (dstFormat
== GL_RGBA
) {
1784 GLushort
*dst
= (GLushort
*) dstAddr
;
1786 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
1787 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1788 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1789 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1792 else if (dstFormat
== GL_BGRA
) {
1793 GLushort
*dst
= (GLushort
*) dstAddr
;
1795 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) )
1796 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1797 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 8)
1798 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1801 else if (dstFormat
== GL_ABGR_EXT
) {
1802 GLushort
*dst
= (GLushort
*) dstAddr
;
1804 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) )
1805 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1806 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1807 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12);
1811 case GL_UNSIGNED_SHORT_5_5_5_1
:
1812 if (dstFormat
== GL_RGBA
) {
1813 GLushort
*dst
= (GLushort
*) dstAddr
;
1815 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1816 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1817 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
1818 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1821 else if (dstFormat
== GL_BGRA
) {
1822 GLushort
*dst
= (GLushort
*) dstAddr
;
1824 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11)
1825 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1826 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 1)
1827 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1830 else if (dstFormat
== GL_ABGR_EXT
) {
1831 GLushort
*dst
= (GLushort
*) dstAddr
;
1833 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) << 11)
1834 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 6)
1835 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 1)
1836 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) );
1840 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1841 if (dstFormat
== GL_RGBA
) {
1842 GLushort
*dst
= (GLushort
*) dstAddr
;
1844 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1845 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1846 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
1847 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1850 else if (dstFormat
== GL_BGRA
) {
1851 GLushort
*dst
= (GLushort
*) dstAddr
;
1853 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) )
1854 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1855 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 10)
1856 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1859 else if (dstFormat
== GL_ABGR_EXT
) {
1860 GLushort
*dst
= (GLushort
*) dstAddr
;
1862 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) )
1863 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 5)
1864 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 10)
1865 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) << 15);
1869 case GL_UNSIGNED_INT_8_8_8_8
:
1870 if (dstFormat
== GL_RGBA
) {
1871 GLuint
*dst
= (GLuint
*) dstAddr
;
1873 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
1874 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1875 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1876 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1879 else if (dstFormat
== GL_BGRA
) {
1880 GLuint
*dst
= (GLuint
*) dstAddr
;
1882 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
1883 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1884 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
1885 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1888 else if (dstFormat
== GL_ABGR_EXT
) {
1889 GLuint
*dst
= (GLuint
*) dstAddr
;
1891 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
1892 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1893 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1894 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
1898 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1899 if (dstFormat
== GL_RGBA
) {
1900 GLuint
*dst
= (GLuint
*) dstAddr
;
1902 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
1903 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1904 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1905 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1908 else if (dstFormat
== GL_BGRA
) {
1909 GLuint
*dst
= (GLuint
*) dstAddr
;
1911 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
1912 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1913 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
1914 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1917 else if (dstFormat
== GL_ABGR_EXT
) {
1918 GLuint
*dst
= (GLuint
*) dstAddr
;
1920 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
1921 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1922 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1923 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
1927 case GL_UNSIGNED_INT_10_10_10_2
:
1928 if (dstFormat
== GL_RGBA
) {
1929 GLuint
*dst
= (GLuint
*) dstAddr
;
1931 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
1932 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1933 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
1934 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1937 else if (dstFormat
== GL_BGRA
) {
1938 GLuint
*dst
= (GLuint
*) dstAddr
;
1940 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
1941 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1942 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
1943 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1946 else if (dstFormat
== GL_ABGR_EXT
) {
1947 GLuint
*dst
= (GLuint
*) dstAddr
;
1949 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
1950 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
1951 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
1952 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
1956 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1957 if (dstFormat
== GL_RGBA
) {
1958 GLuint
*dst
= (GLuint
*) dstAddr
;
1960 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
1961 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1962 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
1963 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1966 else if (dstFormat
== GL_BGRA
) {
1967 GLuint
*dst
= (GLuint
*) dstAddr
;
1969 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
1970 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1971 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
1972 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1975 else if (dstFormat
== GL_ABGR_EXT
) {
1976 GLuint
*dst
= (GLuint
*) dstAddr
;
1978 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
1979 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
1980 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
1981 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
1986 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
1991 #define SWAP2BYTE(VALUE) \
1993 GLubyte *bytes = (GLubyte *) &(VALUE); \
1994 GLubyte tmp = bytes[0]; \
1995 bytes[0] = bytes[1]; \
1999 #define SWAP4BYTE(VALUE) \
2001 GLubyte *bytes = (GLubyte *) &(VALUE); \
2002 GLubyte tmp = bytes[0]; \
2003 bytes[0] = bytes[3]; \
2006 bytes[1] = bytes[2]; \
2012 extract_uint_indexes(GLuint n
, GLuint indexes
[],
2013 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2014 const struct gl_pixelstore_attrib
*unpack
)
2016 assert(srcFormat
== GL_COLOR_INDEX
);
2018 ASSERT(srcType
== GL_BITMAP
||
2019 srcType
== GL_UNSIGNED_BYTE
||
2020 srcType
== GL_BYTE
||
2021 srcType
== GL_UNSIGNED_SHORT
||
2022 srcType
== GL_SHORT
||
2023 srcType
== GL_UNSIGNED_INT
||
2024 srcType
== GL_INT
||
2025 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
2026 srcType
== GL_HALF_FLOAT_ARB
||
2027 srcType
== GL_FLOAT
);
2032 GLubyte
*ubsrc
= (GLubyte
*) src
;
2033 if (unpack
->LsbFirst
) {
2034 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
2036 for (i
= 0; i
< n
; i
++) {
2037 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2048 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
2050 for (i
= 0; i
< n
; i
++) {
2051 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2063 case GL_UNSIGNED_BYTE
:
2066 const GLubyte
*s
= (const GLubyte
*) src
;
2067 for (i
= 0; i
< n
; i
++)
2074 const GLbyte
*s
= (const GLbyte
*) src
;
2075 for (i
= 0; i
< n
; i
++)
2079 case GL_UNSIGNED_SHORT
:
2082 const GLushort
*s
= (const GLushort
*) src
;
2083 if (unpack
->SwapBytes
) {
2084 for (i
= 0; i
< n
; i
++) {
2085 GLushort value
= s
[i
];
2091 for (i
= 0; i
< n
; i
++)
2099 const GLshort
*s
= (const GLshort
*) src
;
2100 if (unpack
->SwapBytes
) {
2101 for (i
= 0; i
< n
; i
++) {
2102 GLshort value
= s
[i
];
2108 for (i
= 0; i
< n
; i
++)
2113 case GL_UNSIGNED_INT
:
2116 const GLuint
*s
= (const GLuint
*) src
;
2117 if (unpack
->SwapBytes
) {
2118 for (i
= 0; i
< n
; i
++) {
2119 GLuint value
= s
[i
];
2125 for (i
= 0; i
< n
; i
++)
2133 const GLint
*s
= (const GLint
*) src
;
2134 if (unpack
->SwapBytes
) {
2135 for (i
= 0; i
< n
; i
++) {
2142 for (i
= 0; i
< n
; i
++)
2150 const GLfloat
*s
= (const GLfloat
*) src
;
2151 if (unpack
->SwapBytes
) {
2152 for (i
= 0; i
< n
; i
++) {
2153 GLfloat value
= s
[i
];
2155 indexes
[i
] = (GLuint
) value
;
2159 for (i
= 0; i
< n
; i
++)
2160 indexes
[i
] = (GLuint
) s
[i
];
2164 case GL_HALF_FLOAT_ARB
:
2167 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
2168 if (unpack
->SwapBytes
) {
2169 for (i
= 0; i
< n
; i
++) {
2170 GLhalfARB value
= s
[i
];
2172 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
2176 for (i
= 0; i
< n
; i
++)
2177 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
2181 case GL_UNSIGNED_INT_24_8_EXT
:
2184 const GLuint
*s
= (const GLuint
*) src
;
2185 if (unpack
->SwapBytes
) {
2186 for (i
= 0; i
< n
; i
++) {
2187 GLuint value
= s
[i
];
2189 indexes
[i
] = value
& 0xff; /* lower 8 bits */
2193 for (i
= 0; i
< n
; i
++)
2194 indexes
[i
] = s
[i
] & 0xfff; /* lower 8 bits */
2200 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2207 * This function extracts floating point RGBA values from arbitrary
2208 * image data. srcFormat and srcType are the format and type parameters
2209 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2211 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2212 * implements the "Conversion to floating point", "Conversion to RGB",
2213 * and "Final Expansion to RGBA" operations.
2215 * Args: n - number of pixels
2216 * rgba - output colors
2217 * srcFormat - format of incoming data
2218 * srcType - data type of incoming data
2219 * src - source data pointer
2220 * swapBytes - perform byteswapping of incoming data?
2223 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2224 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2225 GLboolean swapBytes
)
2227 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2229 GLint rComp
, bComp
, gComp
, aComp
;
2231 ASSERT(srcFormat
== GL_RED
||
2232 srcFormat
== GL_GREEN
||
2233 srcFormat
== GL_BLUE
||
2234 srcFormat
== GL_ALPHA
||
2235 srcFormat
== GL_LUMINANCE
||
2236 srcFormat
== GL_LUMINANCE_ALPHA
||
2237 srcFormat
== GL_INTENSITY
||
2238 srcFormat
== GL_RGB
||
2239 srcFormat
== GL_BGR
||
2240 srcFormat
== GL_RGBA
||
2241 srcFormat
== GL_BGRA
||
2242 srcFormat
== GL_ABGR_EXT
);
2244 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2245 srcType
== GL_BYTE
||
2246 srcType
== GL_UNSIGNED_SHORT
||
2247 srcType
== GL_SHORT
||
2248 srcType
== GL_UNSIGNED_INT
||
2249 srcType
== GL_INT
||
2250 srcType
== GL_HALF_FLOAT_ARB
||
2251 srcType
== GL_FLOAT
||
2252 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2253 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2254 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2255 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2256 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2257 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2258 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2259 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2260 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2261 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2262 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2263 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2265 rComp
= gComp
= bComp
= aComp
= -1;
2267 switch (srcFormat
) {
2270 greenIndex
= blueIndex
= alphaIndex
= -1;
2275 redIndex
= blueIndex
= alphaIndex
= -1;
2280 redIndex
= greenIndex
= alphaIndex
= -1;
2284 redIndex
= greenIndex
= blueIndex
= -1;
2289 redIndex
= greenIndex
= blueIndex
= 0;
2293 case GL_LUMINANCE_ALPHA
:
2294 redIndex
= greenIndex
= blueIndex
= 0;
2299 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
2358 _mesa_problem(NULL
, "bad srcFormat in extract float data");
2363 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
2364 if ((INDEX) < 0) { \
2366 for (i = 0; i < n; i++) { \
2367 rgba[i][CHANNEL] = DEFAULT; \
2370 else if (swapBytes) { \
2371 const TYPE *s = (const TYPE *) src; \
2373 for (i = 0; i < n; i++) { \
2374 TYPE value = s[INDEX]; \
2375 if (sizeof(TYPE) == 2) { \
2378 else if (sizeof(TYPE) == 4) { \
2381 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
2386 const TYPE *s = (const TYPE *) src; \
2388 for (i = 0; i < n; i++) { \
2389 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
2395 case GL_UNSIGNED_BYTE
:
2396 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2397 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2398 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2399 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2402 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2403 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2404 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2405 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
2407 case GL_UNSIGNED_SHORT
:
2408 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2409 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2410 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2411 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
2414 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2415 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2416 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2417 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
2419 case GL_UNSIGNED_INT
:
2420 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2421 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2422 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2423 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
2426 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2427 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2428 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2429 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
2432 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2433 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2434 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2435 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
2437 case GL_HALF_FLOAT_ARB
:
2438 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2439 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2440 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfARB
, _mesa_half_to_float
);
2441 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfARB
, _mesa_half_to_float
);
2443 case GL_UNSIGNED_BYTE_3_3_2
:
2445 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2447 for (i
= 0; i
< n
; i
++) {
2448 GLubyte p
= ubsrc
[i
];
2449 rgba
[i
][rComp
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
2450 rgba
[i
][gComp
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
2451 rgba
[i
][bComp
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
2452 rgba
[i
][aComp
] = 1.0F
;
2456 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2458 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2460 for (i
= 0; i
< n
; i
++) {
2461 GLubyte p
= ubsrc
[i
];
2462 rgba
[i
][rComp
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
2463 rgba
[i
][gComp
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
2464 rgba
[i
][bComp
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
2465 rgba
[i
][aComp
] = 1.0F
;
2469 case GL_UNSIGNED_SHORT_5_6_5
:
2471 const GLushort
*ussrc
= (const GLushort
*) src
;
2473 for (i
= 0; i
< n
; i
++) {
2474 GLushort p
= ussrc
[i
];
2476 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2477 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2478 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2479 rgba
[i
][aComp
] = 1.0F
;
2483 const GLushort
*ussrc
= (const GLushort
*) src
;
2485 for (i
= 0; i
< n
; i
++) {
2486 GLushort p
= ussrc
[i
];
2487 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2488 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2489 rgba
[i
][bComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2490 rgba
[i
][aComp
] = 1.0F
;
2494 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2496 const GLushort
*ussrc
= (const GLushort
*) src
;
2498 for (i
= 0; i
< n
; i
++) {
2499 GLushort p
= ussrc
[i
];
2501 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2502 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2503 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2504 rgba
[i
][aComp
] = 1.0F
;
2508 const GLushort
*ussrc
= (const GLushort
*) src
;
2510 for (i
= 0; i
< n
; i
++) {
2511 GLushort p
= ussrc
[i
];
2512 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2513 rgba
[i
][gComp
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2514 rgba
[i
][bComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2515 rgba
[i
][aComp
] = 1.0F
;
2519 case GL_UNSIGNED_SHORT_4_4_4_4
:
2521 const GLushort
*ussrc
= (const GLushort
*) src
;
2523 for (i
= 0; i
< n
; i
++) {
2524 GLushort p
= ussrc
[i
];
2526 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2527 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2528 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2529 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2533 const GLushort
*ussrc
= (const GLushort
*) src
;
2535 for (i
= 0; i
< n
; i
++) {
2536 GLushort p
= ussrc
[i
];
2537 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2538 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2539 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2540 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2544 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2546 const GLushort
*ussrc
= (const GLushort
*) src
;
2548 for (i
= 0; i
< n
; i
++) {
2549 GLushort p
= ussrc
[i
];
2551 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2552 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2553 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2554 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2558 const GLushort
*ussrc
= (const GLushort
*) src
;
2560 for (i
= 0; i
< n
; i
++) {
2561 GLushort p
= ussrc
[i
];
2562 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2563 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2564 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2565 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2569 case GL_UNSIGNED_SHORT_5_5_5_1
:
2571 const GLushort
*ussrc
= (const GLushort
*) src
;
2573 for (i
= 0; i
< n
; i
++) {
2574 GLushort p
= ussrc
[i
];
2576 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2577 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2578 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2579 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2583 const GLushort
*ussrc
= (const GLushort
*) src
;
2585 for (i
= 0; i
< n
; i
++) {
2586 GLushort p
= ussrc
[i
];
2587 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2588 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2589 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2590 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2594 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2596 const GLushort
*ussrc
= (const GLushort
*) src
;
2598 for (i
= 0; i
< n
; i
++) {
2599 GLushort p
= ussrc
[i
];
2601 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2602 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2603 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2604 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2608 const GLushort
*ussrc
= (const GLushort
*) src
;
2610 for (i
= 0; i
< n
; i
++) {
2611 GLushort p
= ussrc
[i
];
2612 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2613 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2614 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2615 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2619 case GL_UNSIGNED_INT_8_8_8_8
:
2621 const GLuint
*uisrc
= (const GLuint
*) src
;
2623 for (i
= 0; i
< n
; i
++) {
2624 GLuint p
= uisrc
[i
];
2625 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2626 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2627 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2628 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2632 const GLuint
*uisrc
= (const GLuint
*) src
;
2634 for (i
= 0; i
< n
; i
++) {
2635 GLuint p
= uisrc
[i
];
2636 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2637 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2638 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2639 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2643 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2645 const GLuint
*uisrc
= (const GLuint
*) src
;
2647 for (i
= 0; i
< n
; i
++) {
2648 GLuint p
= uisrc
[i
];
2649 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2650 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2651 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2652 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2656 const GLuint
*uisrc
= (const GLuint
*) src
;
2658 for (i
= 0; i
< n
; i
++) {
2659 GLuint p
= uisrc
[i
];
2660 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2661 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2662 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2663 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2667 case GL_UNSIGNED_INT_10_10_10_2
:
2669 const GLuint
*uisrc
= (const GLuint
*) src
;
2671 for (i
= 0; i
< n
; i
++) {
2672 GLuint p
= uisrc
[i
];
2674 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2675 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2676 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2677 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2681 const GLuint
*uisrc
= (const GLuint
*) src
;
2683 for (i
= 0; i
< n
; i
++) {
2684 GLuint p
= uisrc
[i
];
2685 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2686 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2687 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2688 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2692 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2694 const GLuint
*uisrc
= (const GLuint
*) src
;
2696 for (i
= 0; i
< n
; i
++) {
2697 GLuint p
= uisrc
[i
];
2699 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2700 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2701 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2702 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2706 const GLuint
*uisrc
= (const GLuint
*) src
;
2708 for (i
= 0; i
< n
; i
++) {
2709 GLuint p
= uisrc
[i
];
2710 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2711 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2712 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2713 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2718 _mesa_problem(NULL
, "bad srcType in extract float data");
2725 * Unpack a row of color image data from a client buffer according to
2726 * the pixel unpacking parameters.
2727 * Return GLchan values in the specified dest image format.
2728 * This is used by glDrawPixels and glTexImage?D().
2729 * \param ctx - the context
2730 * n - number of pixels in the span
2731 * dstFormat - format of destination color array
2732 * dest - the destination color array
2733 * srcFormat - source image format
2734 * srcType - source image data type
2735 * source - source image pointer
2736 * srcPacking - pixel unpacking parameters
2737 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
2739 * XXX perhaps expand this to process whole images someday.
2742 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
2743 GLuint n
, GLenum dstFormat
, GLchan dest
[],
2744 GLenum srcFormat
, GLenum srcType
,
2745 const GLvoid
*source
,
2746 const struct gl_pixelstore_attrib
*srcPacking
,
2747 GLbitfield transferOps
)
2749 ASSERT(dstFormat
== GL_ALPHA
||
2750 dstFormat
== GL_LUMINANCE
||
2751 dstFormat
== GL_LUMINANCE_ALPHA
||
2752 dstFormat
== GL_INTENSITY
||
2753 dstFormat
== GL_RGB
||
2754 dstFormat
== GL_RGBA
||
2755 dstFormat
== GL_COLOR_INDEX
);
2757 ASSERT(srcFormat
== GL_RED
||
2758 srcFormat
== GL_GREEN
||
2759 srcFormat
== GL_BLUE
||
2760 srcFormat
== GL_ALPHA
||
2761 srcFormat
== GL_LUMINANCE
||
2762 srcFormat
== GL_LUMINANCE_ALPHA
||
2763 srcFormat
== GL_INTENSITY
||
2764 srcFormat
== GL_RGB
||
2765 srcFormat
== GL_BGR
||
2766 srcFormat
== GL_RGBA
||
2767 srcFormat
== GL_BGRA
||
2768 srcFormat
== GL_ABGR_EXT
||
2769 srcFormat
== GL_COLOR_INDEX
);
2771 ASSERT(srcType
== GL_BITMAP
||
2772 srcType
== GL_UNSIGNED_BYTE
||
2773 srcType
== GL_BYTE
||
2774 srcType
== GL_UNSIGNED_SHORT
||
2775 srcType
== GL_SHORT
||
2776 srcType
== GL_UNSIGNED_INT
||
2777 srcType
== GL_INT
||
2778 srcType
== GL_HALF_FLOAT_ARB
||
2779 srcType
== GL_FLOAT
||
2780 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2781 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2782 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2783 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2784 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2785 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2786 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2787 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2788 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2789 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2790 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2791 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2793 /* Try simple cases first */
2794 if (transferOps
== 0) {
2795 if (srcType
== CHAN_TYPE
) {
2796 if (dstFormat
== GL_RGBA
) {
2797 if (srcFormat
== GL_RGBA
) {
2798 _mesa_memcpy( dest
, source
, n
* 4 * sizeof(GLchan
) );
2801 else if (srcFormat
== GL_RGB
) {
2803 const GLchan
*src
= (const GLchan
*) source
;
2805 for (i
= 0; i
< n
; i
++) {
2816 else if (dstFormat
== GL_RGB
) {
2817 if (srcFormat
== GL_RGB
) {
2818 _mesa_memcpy( dest
, source
, n
* 3 * sizeof(GLchan
) );
2821 else if (srcFormat
== GL_RGBA
) {
2823 const GLchan
*src
= (const GLchan
*) source
;
2825 for (i
= 0; i
< n
; i
++) {
2835 else if (dstFormat
== srcFormat
) {
2836 GLint comps
= _mesa_components_in_format(srcFormat
);
2838 _mesa_memcpy( dest
, source
, n
* comps
* sizeof(GLchan
) );
2843 * Common situation, loading 8bit RGBA/RGB source images
2844 * into 16/32 bit destination. (OSMesa16/32)
2846 else if (srcType
== GL_UNSIGNED_BYTE
) {
2847 if (dstFormat
== GL_RGBA
) {
2848 if (srcFormat
== GL_RGB
) {
2850 const GLubyte
*src
= (const GLubyte
*) source
;
2852 for (i
= 0; i
< n
; i
++) {
2853 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2854 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2855 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2862 else if (srcFormat
== GL_RGBA
) {
2864 const GLubyte
*src
= (const GLubyte
*) source
;
2866 for (i
= 0; i
< n
; i
++) {
2867 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2868 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2869 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2870 dst
[3] = UBYTE_TO_CHAN(src
[3]);
2877 else if (dstFormat
== GL_RGB
) {
2878 if (srcFormat
== GL_RGB
) {
2880 const GLubyte
*src
= (const GLubyte
*) source
;
2882 for (i
= 0; i
< n
; i
++) {
2883 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2884 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2885 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2891 else if (srcFormat
== GL_RGBA
) {
2893 const GLubyte
*src
= (const GLubyte
*) source
;
2895 for (i
= 0; i
< n
; i
++) {
2896 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2897 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2898 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2909 /* general solution begins here */
2911 GLint dstComponents
;
2912 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2913 GLint dstLuminanceIndex
, dstIntensityIndex
;
2914 GLfloat rgba
[MAX_WIDTH
][4];
2916 dstComponents
= _mesa_components_in_format( dstFormat
);
2917 /* source & dest image formats should have been error checked by now */
2918 assert(dstComponents
> 0);
2921 * Extract image data and convert to RGBA floats
2923 assert(n
<= MAX_WIDTH
);
2924 if (srcFormat
== GL_COLOR_INDEX
) {
2925 GLuint indexes
[MAX_WIDTH
];
2926 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2929 if (dstFormat
== GL_COLOR_INDEX
2930 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
2931 _mesa_map_ci(ctx
, n
, indexes
);
2933 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
2934 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2937 if (dstFormat
== GL_COLOR_INDEX
) {
2938 /* convert to GLchan and return */
2940 for (i
= 0; i
< n
; i
++) {
2941 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
2946 /* Convert indexes to RGBA */
2947 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
2950 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
2951 * with color indexes.
2953 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
2956 /* non-color index data */
2957 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2958 srcPacking
->SwapBytes
);
2961 /* Need to clamp if returning GLubytes or GLushorts */
2962 #if CHAN_TYPE != GL_FLOAT
2963 transferOps
|= IMAGE_CLAMP_BIT
;
2967 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
2970 /* Now determine which color channels we need to produce.
2971 * And determine the dest index (offset) within each color tuple.
2973 switch (dstFormat
) {
2976 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2977 dstLuminanceIndex
= dstIntensityIndex
= -1;
2980 dstLuminanceIndex
= 0;
2981 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2982 dstIntensityIndex
= -1;
2984 case GL_LUMINANCE_ALPHA
:
2985 dstLuminanceIndex
= 0;
2987 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2988 dstIntensityIndex
= -1;
2991 dstIntensityIndex
= 0;
2992 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2993 dstLuminanceIndex
= -1;
2999 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3006 dstLuminanceIndex
= dstIntensityIndex
= -1;
3009 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
3014 /* Now return the GLchan data in the requested dstFormat */
3016 if (dstRedIndex
>= 0) {
3019 for (i
= 0; i
< n
; i
++) {
3020 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
3021 dst
+= dstComponents
;
3025 if (dstGreenIndex
>= 0) {
3028 for (i
= 0; i
< n
; i
++) {
3029 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
3030 dst
+= dstComponents
;
3034 if (dstBlueIndex
>= 0) {
3037 for (i
= 0; i
< n
; i
++) {
3038 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
3039 dst
+= dstComponents
;
3043 if (dstAlphaIndex
>= 0) {
3046 for (i
= 0; i
< n
; i
++) {
3047 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
3048 dst
+= dstComponents
;
3052 if (dstIntensityIndex
>= 0) {
3055 assert(dstIntensityIndex
== 0);
3056 assert(dstComponents
== 1);
3057 for (i
= 0; i
< n
; i
++) {
3058 /* Intensity comes from red channel */
3059 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
3063 if (dstLuminanceIndex
>= 0) {
3066 assert(dstLuminanceIndex
== 0);
3067 for (i
= 0; i
< n
; i
++) {
3068 /* Luminance comes from red channel */
3069 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
3070 dst
+= dstComponents
;
3078 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
3079 * instead of GLchan.
3082 _mesa_unpack_color_span_float( GLcontext
*ctx
,
3083 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
3084 GLenum srcFormat
, GLenum srcType
,
3085 const GLvoid
*source
,
3086 const struct gl_pixelstore_attrib
*srcPacking
,
3087 GLbitfield transferOps
)
3089 ASSERT(dstFormat
== GL_ALPHA
||
3090 dstFormat
== GL_LUMINANCE
||
3091 dstFormat
== GL_LUMINANCE_ALPHA
||
3092 dstFormat
== GL_INTENSITY
||
3093 dstFormat
== GL_RGB
||
3094 dstFormat
== GL_RGBA
||
3095 dstFormat
== GL_COLOR_INDEX
);
3097 ASSERT(srcFormat
== GL_RED
||
3098 srcFormat
== GL_GREEN
||
3099 srcFormat
== GL_BLUE
||
3100 srcFormat
== GL_ALPHA
||
3101 srcFormat
== GL_LUMINANCE
||
3102 srcFormat
== GL_LUMINANCE_ALPHA
||
3103 srcFormat
== GL_INTENSITY
||
3104 srcFormat
== GL_RGB
||
3105 srcFormat
== GL_BGR
||
3106 srcFormat
== GL_RGBA
||
3107 srcFormat
== GL_BGRA
||
3108 srcFormat
== GL_ABGR_EXT
||
3109 srcFormat
== GL_COLOR_INDEX
);
3111 ASSERT(srcType
== GL_BITMAP
||
3112 srcType
== GL_UNSIGNED_BYTE
||
3113 srcType
== GL_BYTE
||
3114 srcType
== GL_UNSIGNED_SHORT
||
3115 srcType
== GL_SHORT
||
3116 srcType
== GL_UNSIGNED_INT
||
3117 srcType
== GL_INT
||
3118 srcType
== GL_HALF_FLOAT_ARB
||
3119 srcType
== GL_FLOAT
||
3120 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3121 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3122 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3123 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3124 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3125 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3126 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3127 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3128 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3129 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3130 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3131 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3133 /* general solution, no special cases, yet */
3135 GLint dstComponents
;
3136 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3137 GLint dstLuminanceIndex
, dstIntensityIndex
;
3138 GLfloat rgba
[MAX_WIDTH
][4];
3140 dstComponents
= _mesa_components_in_format( dstFormat
);
3141 /* source & dest image formats should have been error checked by now */
3142 assert(dstComponents
> 0);
3145 * Extract image data and convert to RGBA floats
3147 assert(n
<= MAX_WIDTH
);
3148 if (srcFormat
== GL_COLOR_INDEX
) {
3149 GLuint indexes
[MAX_WIDTH
];
3150 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3153 if (dstFormat
== GL_COLOR_INDEX
3154 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
3155 _mesa_map_ci(ctx
, n
, indexes
);
3157 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3158 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3161 if (dstFormat
== GL_COLOR_INDEX
) {
3162 /* convert to GLchan and return */
3164 for (i
= 0; i
< n
; i
++) {
3165 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3170 /* Convert indexes to RGBA */
3171 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3174 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3175 * with color indexes.
3177 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3180 /* non-color index data */
3181 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3182 srcPacking
->SwapBytes
);
3186 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3189 /* Now determine which color channels we need to produce.
3190 * And determine the dest index (offset) within each color tuple.
3192 switch (dstFormat
) {
3195 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3196 dstLuminanceIndex
= dstIntensityIndex
= -1;
3199 dstLuminanceIndex
= 0;
3200 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3201 dstIntensityIndex
= -1;
3203 case GL_LUMINANCE_ALPHA
:
3204 dstLuminanceIndex
= 0;
3206 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3207 dstIntensityIndex
= -1;
3210 dstIntensityIndex
= 0;
3211 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3212 dstLuminanceIndex
= -1;
3218 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3225 dstLuminanceIndex
= dstIntensityIndex
= -1;
3228 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
3232 /* Now pack results in the requested dstFormat */
3233 if (dstRedIndex
>= 0) {
3234 GLfloat
*dst
= dest
;
3236 for (i
= 0; i
< n
; i
++) {
3237 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3238 dst
+= dstComponents
;
3242 if (dstGreenIndex
>= 0) {
3243 GLfloat
*dst
= dest
;
3245 for (i
= 0; i
< n
; i
++) {
3246 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3247 dst
+= dstComponents
;
3251 if (dstBlueIndex
>= 0) {
3252 GLfloat
*dst
= dest
;
3254 for (i
= 0; i
< n
; i
++) {
3255 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3256 dst
+= dstComponents
;
3260 if (dstAlphaIndex
>= 0) {
3261 GLfloat
*dst
= dest
;
3263 for (i
= 0; i
< n
; i
++) {
3264 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3265 dst
+= dstComponents
;
3269 if (dstIntensityIndex
>= 0) {
3270 GLfloat
*dst
= dest
;
3272 assert(dstIntensityIndex
== 0);
3273 assert(dstComponents
== 1);
3274 for (i
= 0; i
< n
; i
++) {
3275 /* Intensity comes from red channel */
3276 dst
[i
] = rgba
[i
][RCOMP
];
3280 if (dstLuminanceIndex
>= 0) {
3281 GLfloat
*dst
= dest
;
3283 assert(dstLuminanceIndex
== 0);
3284 for (i
= 0; i
< n
; i
++) {
3285 /* Luminance comes from red channel */
3286 dst
[0] = rgba
[i
][RCOMP
];
3287 dst
+= dstComponents
;
3295 * Unpack a row of color index data from a client buffer according to
3296 * the pixel unpacking parameters.
3297 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
3299 * Args: ctx - the context
3300 * n - number of pixels
3301 * dstType - destination data type
3302 * dest - destination array
3303 * srcType - source pixel type
3304 * source - source data pointer
3305 * srcPacking - pixel unpacking parameters
3306 * transferOps - the pixel transfer operations to apply
3309 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
3310 GLenum dstType
, GLvoid
*dest
,
3311 GLenum srcType
, const GLvoid
*source
,
3312 const struct gl_pixelstore_attrib
*srcPacking
,
3313 GLbitfield transferOps
)
3315 ASSERT(srcType
== GL_BITMAP
||
3316 srcType
== GL_UNSIGNED_BYTE
||
3317 srcType
== GL_BYTE
||
3318 srcType
== GL_UNSIGNED_SHORT
||
3319 srcType
== GL_SHORT
||
3320 srcType
== GL_UNSIGNED_INT
||
3321 srcType
== GL_INT
||
3322 srcType
== GL_HALF_FLOAT_ARB
||
3323 srcType
== GL_FLOAT
);
3325 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3326 dstType
== GL_UNSIGNED_SHORT
||
3327 dstType
== GL_UNSIGNED_INT
);
3330 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3333 * Try simple cases first
3335 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
3336 && dstType
== GL_UNSIGNED_BYTE
) {
3337 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
3339 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
3340 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
3341 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
3347 GLuint indexes
[MAX_WIDTH
];
3348 assert(n
<= MAX_WIDTH
);
3350 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3353 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3354 /* shift and offset indexes */
3355 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3357 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3358 /* Apply lookup table */
3359 _mesa_map_ci(ctx
, n
, indexes
);
3362 /* convert to dest type */
3364 case GL_UNSIGNED_BYTE
:
3366 GLubyte
*dst
= (GLubyte
*) dest
;
3368 for (i
= 0; i
< n
; i
++) {
3369 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3373 case GL_UNSIGNED_SHORT
:
3375 GLuint
*dst
= (GLuint
*) dest
;
3377 for (i
= 0; i
< n
; i
++) {
3378 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3382 case GL_UNSIGNED_INT
:
3383 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
3386 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
3393 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
3394 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
3395 const struct gl_pixelstore_attrib
*dstPacking
,
3396 GLbitfield transferOps
)
3398 GLuint indexes
[MAX_WIDTH
];
3400 ASSERT(n
<= MAX_WIDTH
);
3402 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3404 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
3405 /* make a copy of input */
3406 _mesa_memcpy(indexes
, source
, n
* sizeof(GLuint
));
3407 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3408 _mesa_shift_and_offset_ci( ctx
, n
, indexes
);
3410 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3411 _mesa_map_ci(ctx
, n
, indexes
);
3417 case GL_UNSIGNED_BYTE
:
3419 GLubyte
*dst
= (GLubyte
*) dest
;
3421 for (i
= 0; i
< n
; i
++) {
3422 *dst
++ = (GLubyte
) source
[i
];
3428 GLbyte
*dst
= (GLbyte
*) dest
;
3430 for (i
= 0; i
< n
; i
++) {
3431 dst
[i
] = (GLbyte
) source
[i
];
3435 case GL_UNSIGNED_SHORT
:
3437 GLushort
*dst
= (GLushort
*) dest
;
3439 for (i
= 0; i
< n
; i
++) {
3440 dst
[i
] = (GLushort
) source
[i
];
3442 if (dstPacking
->SwapBytes
) {
3443 _mesa_swap2( (GLushort
*) dst
, n
);
3449 GLshort
*dst
= (GLshort
*) dest
;
3451 for (i
= 0; i
< n
; i
++) {
3452 dst
[i
] = (GLshort
) source
[i
];
3454 if (dstPacking
->SwapBytes
) {
3455 _mesa_swap2( (GLushort
*) dst
, n
);
3459 case GL_UNSIGNED_INT
:
3461 GLuint
*dst
= (GLuint
*) dest
;
3463 for (i
= 0; i
< n
; i
++) {
3464 dst
[i
] = (GLuint
) source
[i
];
3466 if (dstPacking
->SwapBytes
) {
3467 _mesa_swap4( (GLuint
*) dst
, n
);
3473 GLint
*dst
= (GLint
*) dest
;
3475 for (i
= 0; i
< n
; i
++) {
3476 dst
[i
] = (GLint
) source
[i
];
3478 if (dstPacking
->SwapBytes
) {
3479 _mesa_swap4( (GLuint
*) dst
, n
);
3485 GLfloat
*dst
= (GLfloat
*) dest
;
3487 for (i
= 0; i
< n
; i
++) {
3488 dst
[i
] = (GLfloat
) source
[i
];
3490 if (dstPacking
->SwapBytes
) {
3491 _mesa_swap4( (GLuint
*) dst
, n
);
3495 case GL_HALF_FLOAT_ARB
:
3497 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
3499 for (i
= 0; i
< n
; i
++) {
3500 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
3502 if (dstPacking
->SwapBytes
) {
3503 _mesa_swap2( (GLushort
*) dst
, n
);
3508 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3514 * Unpack a row of stencil data from a client buffer according to
3515 * the pixel unpacking parameters.
3516 * This is (or will be) used by glDrawPixels
3518 * Args: ctx - the context
3519 * n - number of pixels
3520 * dstType - destination data type
3521 * dest - destination array
3522 * srcType - source pixel type
3523 * source - source data pointer
3524 * srcPacking - pixel unpacking parameters
3525 * transferOps - apply offset/bias/lookup ops?
3528 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3529 GLenum dstType
, GLvoid
*dest
,
3530 GLenum srcType
, const GLvoid
*source
,
3531 const struct gl_pixelstore_attrib
*srcPacking
,
3532 GLbitfield transferOps
)
3534 ASSERT(srcType
== GL_BITMAP
||
3535 srcType
== GL_UNSIGNED_BYTE
||
3536 srcType
== GL_BYTE
||
3537 srcType
== GL_UNSIGNED_SHORT
||
3538 srcType
== GL_SHORT
||
3539 srcType
== GL_UNSIGNED_INT
||
3540 srcType
== GL_INT
||
3541 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
3542 srcType
== GL_HALF_FLOAT_ARB
||
3543 srcType
== GL_FLOAT
);
3545 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3546 dstType
== GL_UNSIGNED_SHORT
||
3547 dstType
== GL_UNSIGNED_INT
);
3549 /* only shift and offset apply to stencil */
3550 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
3553 * Try simple cases first
3555 if (transferOps
== 0 &&
3556 srcType
== GL_UNSIGNED_BYTE
&&
3557 dstType
== GL_UNSIGNED_BYTE
) {
3558 _mesa_memcpy(dest
, source
, n
* sizeof(GLubyte
));
3560 else if (transferOps
== 0 &&
3561 srcType
== GL_UNSIGNED_INT
&&
3562 dstType
== GL_UNSIGNED_INT
&&
3563 !srcPacking
->SwapBytes
) {
3564 _mesa_memcpy(dest
, source
, n
* sizeof(GLuint
));
3570 GLuint indexes
[MAX_WIDTH
];
3571 assert(n
<= MAX_WIDTH
);
3573 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3577 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3578 /* shift and offset indexes */
3579 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3582 if (ctx
->Pixel
.MapStencilFlag
) {
3583 /* Apply stencil lookup table */
3584 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
3587 indexes
[i
] = ctx
->Pixel
.MapStoS
[ indexes
[i
] & mask
];
3592 /* convert to dest type */
3594 case GL_UNSIGNED_BYTE
:
3596 GLubyte
*dst
= (GLubyte
*) dest
;
3598 for (i
= 0; i
< n
; i
++) {
3599 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3603 case GL_UNSIGNED_SHORT
:
3605 GLuint
*dst
= (GLuint
*) dest
;
3607 for (i
= 0; i
< n
; i
++) {
3608 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3612 case GL_UNSIGNED_INT
:
3613 _mesa_memcpy(dest
, indexes
, n
* sizeof(GLuint
));
3616 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
3623 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3624 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
3625 const struct gl_pixelstore_attrib
*dstPacking
)
3627 GLstencil stencil
[MAX_WIDTH
];
3629 ASSERT(n
<= MAX_WIDTH
);
3631 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
3632 ctx
->Pixel
.MapStencilFlag
) {
3633 /* make a copy of input */
3634 _mesa_memcpy(stencil
, source
, n
* sizeof(GLstencil
));
3635 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
3636 _mesa_shift_and_offset_stencil( ctx
, n
, stencil
);
3638 if (ctx
->Pixel
.MapStencilFlag
) {
3639 _mesa_map_stencil( ctx
, n
, stencil
);
3645 case GL_UNSIGNED_BYTE
:
3646 if (sizeof(GLstencil
) == 8) {
3647 _mesa_memcpy( dest
, source
, n
);
3650 GLubyte
*dst
= (GLubyte
*) dest
;
3653 dst
[i
] = (GLubyte
) source
[i
];
3658 if (sizeof(GLstencil
) == 8) {
3659 _mesa_memcpy( dest
, source
, n
);
3662 GLbyte
*dst
= (GLbyte
*) dest
;
3665 dst
[i
] = (GLbyte
) source
[i
];
3669 case GL_UNSIGNED_SHORT
:
3671 GLushort
*dst
= (GLushort
*) dest
;
3674 dst
[i
] = (GLushort
) source
[i
];
3676 if (dstPacking
->SwapBytes
) {
3677 _mesa_swap2( (GLushort
*) dst
, n
);
3683 GLshort
*dst
= (GLshort
*) dest
;
3686 dst
[i
] = (GLshort
) source
[i
];
3688 if (dstPacking
->SwapBytes
) {
3689 _mesa_swap2( (GLushort
*) dst
, n
);
3693 case GL_UNSIGNED_INT
:
3695 GLuint
*dst
= (GLuint
*) dest
;
3698 dst
[i
] = (GLuint
) source
[i
];
3700 if (dstPacking
->SwapBytes
) {
3701 _mesa_swap4( (GLuint
*) dst
, n
);
3707 GLint
*dst
= (GLint
*) dest
;
3710 *dst
++ = (GLint
) source
[i
];
3712 if (dstPacking
->SwapBytes
) {
3713 _mesa_swap4( (GLuint
*) dst
, n
);
3719 GLfloat
*dst
= (GLfloat
*) dest
;
3722 dst
[i
] = (GLfloat
) source
[i
];
3724 if (dstPacking
->SwapBytes
) {
3725 _mesa_swap4( (GLuint
*) dst
, n
);
3729 case GL_HALF_FLOAT_ARB
:
3731 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
3734 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
3736 if (dstPacking
->SwapBytes
) {
3737 _mesa_swap2( (GLushort
*) dst
, n
);
3742 if (dstPacking
->LsbFirst
) {
3743 GLubyte
*dst
= (GLubyte
*) dest
;
3746 for (i
= 0; i
< n
; i
++) {
3749 *dst
|= ((source
[i
] != 0) << shift
);
3758 GLubyte
*dst
= (GLubyte
*) dest
;
3761 for (i
= 0; i
< n
; i
++) {
3764 *dst
|= ((source
[i
] != 0) << shift
);
3774 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3780 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
,
3781 GLenum dstType
, GLvoid
*dest
, GLfloat depthScale
,
3782 GLenum srcType
, const GLvoid
*source
,
3783 const struct gl_pixelstore_attrib
*srcPacking
)
3785 GLfloat depthTemp
[MAX_WIDTH
], *depthValues
;
3787 if (dstType
== GL_FLOAT
) {
3788 depthValues
= (GLfloat
*) dest
;
3791 depthValues
= depthTemp
;
3794 /* XXX we need to obey srcPacking->SwapBytes here!!! */
3801 const GLubyte
*src
= (const GLubyte
*) source
;
3802 for (i
= 0; i
< n
; i
++) {
3803 depthValues
[i
] = BYTE_TO_FLOAT(src
[i
]);
3807 case GL_UNSIGNED_BYTE
:
3810 const GLubyte
*src
= (const GLubyte
*) source
;
3811 for (i
= 0; i
< n
; i
++) {
3812 depthValues
[i
] = UBYTE_TO_FLOAT(src
[i
]);
3819 const GLshort
*src
= (const GLshort
*) source
;
3820 for (i
= 0; i
< n
; i
++) {
3821 depthValues
[i
] = SHORT_TO_FLOAT(src
[i
]);
3825 case GL_UNSIGNED_SHORT
:
3828 const GLushort
*src
= (const GLushort
*) source
;
3829 for (i
= 0; i
< n
; i
++) {
3830 depthValues
[i
] = USHORT_TO_FLOAT(src
[i
]);
3837 const GLint
*src
= (const GLint
*) source
;
3838 for (i
= 0; i
< n
; i
++) {
3839 depthValues
[i
] = INT_TO_FLOAT(src
[i
]);
3843 case GL_UNSIGNED_INT
:
3846 const GLuint
*src
= (const GLuint
*) source
;
3847 for (i
= 0; i
< n
; i
++) {
3848 depthValues
[i
] = UINT_TO_FLOAT(src
[i
]);
3852 case GL_UNSIGNED_INT_24_8_EXT
: /* GL_EXT_packed_depth_stencil */
3853 if (dstType
== GL_UNSIGNED_INT
&&
3854 depthScale
== (GLfloat
) 0xffffff &&
3855 ctx
->Pixel
.DepthScale
== 1.0 &&
3856 ctx
->Pixel
.DepthBias
== 0.0) {
3857 const GLuint
*src
= (const GLuint
*) source
;
3858 GLuint
*zValues
= (GLuint
*) dest
;
3860 for (i
= 0; i
< n
; i
++) {
3861 zValues
[i
] = src
[i
] & 0xffffff00;
3866 const GLuint
*src
= (const GLuint
*) source
;
3867 const GLfloat scale
= 1.0f
/ 0xffffff;
3869 for (i
= 0; i
< n
; i
++) {
3870 depthValues
[i
] = (src
[i
] >> 8) * scale
;
3875 _mesa_memcpy(depthValues
, source
, n
* sizeof(GLfloat
));
3877 case GL_HALF_FLOAT_ARB
:
3880 const GLhalfARB
*src
= (const GLhalfARB
*) source
;
3881 for (i
= 0; i
< n
; i
++) {
3882 depthValues
[i
] = _mesa_half_to_float(src
[i
]);
3887 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
3892 /* apply depth scale and bias and clamp to [0,1] */
3893 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
3894 _mesa_scale_and_bias_depth(ctx
, n
, depthValues
);
3897 if (dstType
== GL_UNSIGNED_INT
) {
3898 GLuint
*zValues
= (GLuint
*) dest
;
3900 if (depthScale
<= (GLfloat
) 0xffffff) {
3901 /* no overflow worries */
3902 for (i
= 0; i
< n
; i
++) {
3903 zValues
[i
] = (GLuint
) (depthValues
[i
] * depthScale
);
3907 /* need to use double precision to prevent overflow problems */
3908 for (i
= 0; i
< n
; i
++) {
3909 GLdouble z
= depthValues
[i
] * depthScale
;
3910 if (z
>= (GLdouble
) 0xffffffff)
3911 zValues
[i
] = 0xffffffff;
3913 zValues
[i
] = (GLuint
) z
;
3917 else if (dstType
== GL_UNSIGNED_SHORT
) {
3918 GLushort
*zValues
= (GLushort
*) dest
;
3920 ASSERT(depthScale
<= 65535.0);
3921 for (i
= 0; i
< n
; i
++) {
3922 zValues
[i
] = (GLushort
) (depthValues
[i
] * depthScale
);
3926 ASSERT(dstType
== GL_FLOAT
);
3927 ASSERT(depthScale
== 1.0F
);
3933 * Pack an array of depth values. The values are floats in [0,1].
3936 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
3937 GLenum dstType
, const GLfloat
*depthSpan
,
3938 const struct gl_pixelstore_attrib
*dstPacking
)
3940 GLfloat depthCopy
[MAX_WIDTH
];
3942 ASSERT(n
<= MAX_WIDTH
);
3944 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
3945 _mesa_memcpy(depthCopy
, depthSpan
, n
* sizeof(GLfloat
));
3946 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
3947 depthSpan
= depthCopy
;
3951 case GL_UNSIGNED_BYTE
:
3953 GLubyte
*dst
= (GLubyte
*) dest
;
3955 for (i
= 0; i
< n
; i
++) {
3956 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
3962 GLbyte
*dst
= (GLbyte
*) dest
;
3964 for (i
= 0; i
< n
; i
++) {
3965 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
3969 case GL_UNSIGNED_SHORT
:
3971 GLushort
*dst
= (GLushort
*) dest
;
3973 for (i
= 0; i
< n
; i
++) {
3974 CLAMPED_FLOAT_TO_USHORT(dst
[i
], depthSpan
[i
]);
3976 if (dstPacking
->SwapBytes
) {
3977 _mesa_swap2( (GLushort
*) dst
, n
);
3983 GLshort
*dst
= (GLshort
*) dest
;
3985 for (i
= 0; i
< n
; i
++) {
3986 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
3988 if (dstPacking
->SwapBytes
) {
3989 _mesa_swap2( (GLushort
*) dst
, n
);
3993 case GL_UNSIGNED_INT
:
3995 GLuint
*dst
= (GLuint
*) dest
;
3997 for (i
= 0; i
< n
; i
++) {
3998 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
4000 if (dstPacking
->SwapBytes
) {
4001 _mesa_swap4( (GLuint
*) dst
, n
);
4007 GLint
*dst
= (GLint
*) dest
;
4009 for (i
= 0; i
< n
; i
++) {
4010 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
4012 if (dstPacking
->SwapBytes
) {
4013 _mesa_swap4( (GLuint
*) dst
, n
);
4019 GLfloat
*dst
= (GLfloat
*) dest
;
4021 for (i
= 0; i
< n
; i
++) {
4022 dst
[i
] = depthSpan
[i
];
4024 if (dstPacking
->SwapBytes
) {
4025 _mesa_swap4( (GLuint
*) dst
, n
);
4029 case GL_HALF_FLOAT_ARB
:
4031 GLhalfARB
*dst
= (GLhalfARB
*) dest
;
4033 for (i
= 0; i
< n
; i
++) {
4034 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
4036 if (dstPacking
->SwapBytes
) {
4037 _mesa_swap2( (GLushort
*) dst
, n
);
4042 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
4049 * Pack depth and stencil values as GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8.
4052 _mesa_pack_depth_stencil_span(const GLcontext
*ctx
, GLuint n
, GLuint
*dest
,
4053 const GLfloat
*depthVals
,
4054 const GLstencil
*stencilVals
,
4055 const struct gl_pixelstore_attrib
*dstPacking
)
4057 GLfloat depthCopy
[MAX_WIDTH
];
4058 GLstencil stencilCopy
[MAX_WIDTH
];
4061 ASSERT(n
<= MAX_WIDTH
);
4063 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
4064 _mesa_memcpy(depthCopy
, depthVals
, n
* sizeof(GLfloat
));
4065 _mesa_scale_and_bias_depth(ctx
, n
, depthCopy
);
4066 depthVals
= depthCopy
;
4069 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
4070 _mesa_memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
4071 _mesa_shift_and_offset_stencil(ctx
, n
, stencilCopy
);
4072 stencilVals
= stencilCopy
;
4074 if (ctx
->Pixel
.MapStencilFlag
) {
4075 if (stencilVals
!= stencilCopy
)
4076 _mesa_memcpy(stencilCopy
, stencilVals
, n
* sizeof(GLstencil
));
4077 _mesa_map_stencil(ctx
, n
, stencilCopy
);
4078 stencilVals
= stencilCopy
;
4081 for (i
= 0; i
< n
; i
++) {
4082 GLuint z
= (GLuint
) (depthVals
[i
] * 0xffffff);
4083 dest
[i
] = (z
<< 8) | (stencilVals
[i
] & 0xff);
4086 if (dstPacking
->SwapBytes
) {
4087 _mesa_swap4(dest
, n
);
4095 * Unpack image data. Apply byte swapping, byte flipping (bitmap).
4096 * Return all image data in a contiguous block. This is used when we
4097 * compile glDrawPixels, glTexImage, etc into a display list. We
4098 * need a copy of the data in a standard format.
4101 _mesa_unpack_image( GLuint dimensions
,
4102 GLsizei width
, GLsizei height
, GLsizei depth
,
4103 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4104 const struct gl_pixelstore_attrib
*unpack
)
4106 GLint bytesPerRow
, compsPerRow
;
4107 GLboolean flipBytes
, swap2
, swap4
;
4110 return NULL
; /* not necessarily an error */
4112 if (width
<= 0 || height
<= 0 || depth
<= 0)
4113 return NULL
; /* generate error later */
4115 if (format
== GL_BITMAP
) {
4116 bytesPerRow
= (width
+ 7) >> 3;
4117 flipBytes
= !unpack
->LsbFirst
;
4118 swap2
= swap4
= GL_FALSE
;
4122 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
4123 const GLint components
= _mesa_components_in_format(format
);
4125 if (bytesPerPixel
<= 0 || components
<= 0)
4126 return NULL
; /* bad format or type. generate error later */
4127 bytesPerRow
= bytesPerPixel
* width
;
4128 bytesPerComp
= bytesPerPixel
/ components
;
4129 flipBytes
= GL_FALSE
;
4130 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
4131 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
4132 compsPerRow
= components
* width
;
4133 assert(compsPerRow
>= width
);
4138 = (GLubyte
*) _mesa_malloc(bytesPerRow
* height
* depth
);
4142 return NULL
; /* generate GL_OUT_OF_MEMORY later */
4145 for (img
= 0; img
< depth
; img
++) {
4146 for (row
= 0; row
< height
; row
++) {
4147 const GLvoid
*src
= _mesa_image_address(dimensions
, unpack
, pixels
,
4148 width
, height
, format
, type
, img
, row
, 0);
4149 _mesa_memcpy(dst
, src
, bytesPerRow
);
4150 /* byte flipping/swapping */
4152 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
4155 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
4158 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
4167 #endif /* _HAVE_FULL_GL */
4172 * Convert an array of RGBA colors from one datatype to another.
4173 * NOTE: src may equal dst. In that case, we use a temporary buffer.
4176 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
4177 GLenum dstType
, GLvoid
*dst
,
4178 GLuint count
, const GLubyte mask
[])
4180 GLuint tempBuffer
[MAX_WIDTH
][4];
4181 const GLboolean useTemp
= (src
== dst
);
4183 ASSERT(srcType
!= dstType
);
4186 case GL_UNSIGNED_BYTE
:
4187 if (dstType
== GL_UNSIGNED_SHORT
) {
4188 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
4189 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
4191 for (i
= 0; i
< count
; i
++) {
4192 if (!mask
|| mask
[i
]) {
4193 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
4194 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
4195 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
4196 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
4200 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
4203 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
4204 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
4206 ASSERT(dstType
== GL_FLOAT
);
4207 for (i
= 0; i
< count
; i
++) {
4208 if (!mask
|| mask
[i
]) {
4209 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
4210 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
4211 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
4212 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
4216 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
4219 case GL_UNSIGNED_SHORT
:
4220 if (dstType
== GL_UNSIGNED_BYTE
) {
4221 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
4222 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
4224 for (i
= 0; i
< count
; i
++) {
4225 if (!mask
|| mask
[i
]) {
4226 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
4227 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
4228 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
4229 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
4233 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
4236 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
4237 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
4239 ASSERT(dstType
== GL_FLOAT
);
4240 for (i
= 0; i
< count
; i
++) {
4241 if (!mask
|| mask
[i
]) {
4242 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
4243 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
4244 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
4245 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
4249 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
4253 if (dstType
== GL_UNSIGNED_BYTE
) {
4254 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
4255 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
4257 for (i
= 0; i
< count
; i
++) {
4258 if (!mask
|| mask
[i
]) {
4259 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
4260 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
4261 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
4262 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
4266 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
4269 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
4270 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
4272 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
4273 for (i
= 0; i
< count
; i
++) {
4274 if (!mask
|| mask
[i
]) {
4275 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
4276 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
4277 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
4278 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
4282 _mesa_memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
4286 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
4294 * Perform basic clipping for glDrawPixels. The image's position and size
4295 * and the unpack SkipPixels and SkipRows are adjusted so that the image
4296 * region is entirely within the window and scissor bounds.
4297 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
4298 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
4299 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
4301 * \return GL_TRUE if image is ready for drawing or
4302 * GL_FALSE if image was completely clipped away (draw nothing)
4305 _mesa_clip_drawpixels(const GLcontext
*ctx
,
4306 GLint
*destX
, GLint
*destY
,
4307 GLsizei
*width
, GLsizei
*height
,
4308 struct gl_pixelstore_attrib
*unpack
)
4310 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
4312 if (unpack
->RowLength
== 0) {
4313 unpack
->RowLength
= *width
;
4316 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
4317 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
4320 if (*destX
< buffer
->_Xmin
) {
4321 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
4322 *width
-= (buffer
->_Xmin
- *destX
);
4323 *destX
= buffer
->_Xmin
;
4325 /* right clipping */
4326 if (*destX
+ *width
> buffer
->_Xmax
)
4327 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
4332 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
4333 /* bottom clipping */
4334 if (*destY
< buffer
->_Ymin
) {
4335 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
4336 *height
-= (buffer
->_Ymin
- *destY
);
4337 *destY
= buffer
->_Ymin
;
4340 if (*destY
+ *height
> buffer
->_Ymax
)
4341 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
4343 else { /* upside down */
4345 if (*destY
> buffer
->_Ymax
) {
4346 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
4347 *height
-= (*destY
- buffer
->_Ymax
);
4348 *destY
= buffer
->_Ymax
;
4350 /* bottom clipping */
4351 if (*destY
- *height
< buffer
->_Ymin
)
4352 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
4353 /* adjust destY so it's the first row to write to */
4365 * Perform clipping for glReadPixels. The image's window position
4366 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
4367 * so that the image region is entirely within the window bounds.
4368 * Note: this is different from _mesa_clip_drawpixels() in that the
4369 * scissor box is ignored, and we use the bounds of the current readbuffer
4372 * \return GL_TRUE if image is ready for drawing or
4373 * GL_FALSE if image was completely clipped away (draw nothing)
4376 _mesa_clip_readpixels(const GLcontext
*ctx
,
4377 GLint
*srcX
, GLint
*srcY
,
4378 GLsizei
*width
, GLsizei
*height
,
4379 struct gl_pixelstore_attrib
*pack
)
4381 const GLframebuffer
*buffer
= ctx
->ReadBuffer
;
4383 if (pack
->RowLength
== 0) {
4384 pack
->RowLength
= *width
;
4389 pack
->SkipPixels
+= (0 - *srcX
);
4390 *width
-= (0 - *srcX
);
4393 /* right clipping */
4394 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
4395 *width
-= (*srcX
+ *width
- buffer
->Width
);
4400 /* bottom clipping */
4402 pack
->SkipRows
+= (0 - *srcY
);
4403 *height
-= (0 - *srcY
);
4407 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
4408 *height
-= (*srcY
+ *height
- buffer
->Height
);
4418 * Clip the rectangle defined by (x, y, width, height) against the bounds
4419 * specified by [xmin, xmax) and [ymin, ymax).
4420 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
4423 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
4424 GLint xmax
, GLint ymax
,
4426 GLsizei
*width
, GLsizei
*height
)
4430 *width
-= (xmin
- *x
);
4434 /* right clipping */
4435 if (*x
+ *width
> xmax
)
4436 *width
-= (*x
+ *width
- xmax
- 1);
4441 /* bottom (or top) clipping */
4443 *height
-= (ymin
- *y
);
4447 /* top (or bottom) clipping */
4448 if (*y
+ *height
> ymax
)
4449 *height
-= (*y
+ *height
- ymax
- 1);