1 /* $Id: image.c,v 1.10 1999/10/26 09:21:04 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 #include "GL/xf86glx.h"
46 #include "GL/xf86glx.h"
53 * Flip the 8 bits in each byte of the given array.
55 void gl_flip_bytes( GLubyte
*p
, GLuint n
)
57 register GLuint i
, a
, b
;
61 a
= ((b
& 0x01) << 7) |
75 * Flip the order of the 2 bytes in each word in the given array.
77 void gl_swap2( GLushort
*p
, GLuint n
)
82 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
89 * Flip the order of the 4 bytes in each word in the given array.
91 void gl_swap4( GLuint
*p
, GLuint n
)
93 register GLuint i
, a
, b
;
99 | ((b
<< 8) & 0xff0000)
100 | ((b
<< 24) & 0xff000000);
109 * Return the size, in bytes, of the given GL datatype.
110 * Return 0 if GL_BITMAP.
111 * Return -1 if invalid type enum.
113 GLint
gl_sizeof_type( GLenum type
)
118 case GL_UNSIGNED_BYTE
:
119 return sizeof(GLubyte
);
121 return sizeof(GLbyte
);
122 case GL_UNSIGNED_SHORT
:
123 return sizeof(GLushort
);
125 return sizeof(GLshort
);
126 case GL_UNSIGNED_INT
:
127 return sizeof(GLuint
);
129 return sizeof(GLint
);
131 return sizeof(GLfloat
);
139 * Same as gl_sizeof_packed_type() but we also accept the
140 * packed pixel format datatypes.
142 GLint
gl_sizeof_packed_type( GLenum type
)
147 case GL_UNSIGNED_BYTE
:
148 return sizeof(GLubyte
);
150 return sizeof(GLbyte
);
151 case GL_UNSIGNED_SHORT
:
152 return sizeof(GLushort
);
154 return sizeof(GLshort
);
155 case GL_UNSIGNED_INT
:
156 return sizeof(GLuint
);
158 return sizeof(GLint
);
160 return sizeof(GLfloat
);
161 case GL_UNSIGNED_BYTE_3_3_2
:
162 return sizeof(GLubyte
);
163 case GL_UNSIGNED_BYTE_2_3_3_REV
:
164 return sizeof(GLubyte
);
165 case GL_UNSIGNED_SHORT_5_6_5
:
166 return sizeof(GLshort
);
167 case GL_UNSIGNED_SHORT_5_6_5_REV
:
168 return sizeof(GLshort
);
169 case GL_UNSIGNED_SHORT_4_4_4_4
:
170 return sizeof(GLshort
);
171 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
172 return sizeof(GLshort
);
173 case GL_UNSIGNED_SHORT_5_5_5_1
:
174 return sizeof(GLshort
);
175 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
176 return sizeof(GLshort
);
177 case GL_UNSIGNED_INT_8_8_8_8
:
178 return sizeof(GLuint
);
179 case GL_UNSIGNED_INT_8_8_8_8_REV
:
180 return sizeof(GLuint
);
181 case GL_UNSIGNED_INT_10_10_10_2
:
182 return sizeof(GLuint
);
183 case GL_UNSIGNED_INT_2_10_10_10_REV
:
184 return sizeof(GLuint
);
193 * Return the number of components in a GL enum pixel type.
194 * Return -1 if bad format.
196 GLint
gl_components_in_format( GLenum format
)
200 case GL_COLOR_INDEX1_EXT
:
201 case GL_COLOR_INDEX2_EXT
:
202 case GL_COLOR_INDEX4_EXT
:
203 case GL_COLOR_INDEX8_EXT
:
204 case GL_COLOR_INDEX12_EXT
:
205 case GL_COLOR_INDEX16_EXT
:
206 case GL_STENCIL_INDEX
:
207 case GL_DEPTH_COMPONENT
:
214 case GL_LUMINANCE_ALPHA
:
233 * Return bytes per pixel for given format and type
234 * Return -1 if bad format or type.
236 GLint
gl_bytes_per_pixel( GLenum format
, GLenum type
)
238 GLint comps
= gl_components_in_format( format
);
244 return 0; /* special case */
246 case GL_UNSIGNED_BYTE
:
247 return comps
* sizeof(GLubyte
);
249 case GL_UNSIGNED_SHORT
:
250 return comps
* sizeof(GLshort
);
252 case GL_UNSIGNED_INT
:
253 return comps
* sizeof(GLint
);
255 return comps
* sizeof(GLfloat
);
256 case GL_UNSIGNED_BYTE_3_3_2
:
257 case GL_UNSIGNED_BYTE_2_3_3_REV
:
258 if (format
== GL_RGB
|| format
== GL_BGR
)
259 return sizeof(GLubyte
);
261 return -1; /* error */
262 case GL_UNSIGNED_SHORT_5_6_5
:
263 case GL_UNSIGNED_SHORT_5_6_5_REV
:
264 if (format
== GL_RGB
|| format
== GL_BGR
)
265 return sizeof(GLshort
);
267 return -1; /* error */
268 case GL_UNSIGNED_SHORT_4_4_4_4
:
269 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
270 case GL_UNSIGNED_SHORT_5_5_5_1
:
271 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
272 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
273 return sizeof(GLushort
);
276 case GL_UNSIGNED_INT_8_8_8_8
:
277 case GL_UNSIGNED_INT_8_8_8_8_REV
:
278 case GL_UNSIGNED_INT_10_10_10_2
:
279 case GL_UNSIGNED_INT_2_10_10_10_REV
:
280 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
281 return sizeof(GLuint
);
291 * Test if the given pixel format and type are legal.
292 * Return GL_TRUE for legal, GL_FALSE for illegal.
294 GLboolean
gl_is_legal_format_and_type( GLenum format
, GLenum type
)
298 case GL_STENCIL_INDEX
:
302 case GL_UNSIGNED_BYTE
:
304 case GL_UNSIGNED_SHORT
:
306 case GL_UNSIGNED_INT
:
317 case GL_LUMINANCE_ALPHA
:
318 case GL_DEPTH_COMPONENT
:
322 case GL_UNSIGNED_BYTE
:
324 case GL_UNSIGNED_SHORT
:
326 case GL_UNSIGNED_INT
:
335 case GL_UNSIGNED_BYTE
:
337 case GL_UNSIGNED_SHORT
:
339 case GL_UNSIGNED_INT
:
341 case GL_UNSIGNED_BYTE_3_3_2
:
342 case GL_UNSIGNED_BYTE_2_3_3_REV
:
343 case GL_UNSIGNED_SHORT_5_6_5
:
344 case GL_UNSIGNED_SHORT_5_6_5_REV
:
354 case GL_UNSIGNED_BYTE
:
356 case GL_UNSIGNED_SHORT
:
358 case GL_UNSIGNED_INT
:
360 case GL_UNSIGNED_SHORT_4_4_4_4
:
361 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
362 case GL_UNSIGNED_SHORT_5_5_5_1
:
363 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
364 case GL_UNSIGNED_INT_8_8_8_8
:
365 case GL_UNSIGNED_INT_8_8_8_8_REV
:
366 case GL_UNSIGNED_INT_10_10_10_2
:
367 case GL_UNSIGNED_INT_2_10_10_10_REV
:
381 * Return the address of a pixel in an image (actually a volume).
382 * Pixel unpacking/packing parameters are observed according to 'packing'.
383 * Input: image - start of image data
384 * width, height - size of image
385 * format - image format
386 * type - pixel component type
387 * packing - the pixelstore attributes
388 * img - which image in the volume (0 for 1D or 2D images)
389 * row, column - location of pixel in the image
390 * Return: address of pixel at (image,row,column) in image or NULL if error.
392 GLvoid
*gl_pixel_addr_in_image( const struct gl_pixelstore_attrib
*packing
,
393 const GLvoid
*image
, GLsizei width
,
394 GLsizei height
, GLenum format
, GLenum type
,
395 GLint img
, GLint row
, GLint column
)
397 GLint alignment
; /* 1, 2 or 4 */
398 GLint pixels_per_row
;
399 GLint rows_per_image
;
402 GLint skipimages
; /* for 3-D volume images */
405 alignment
= packing
->Alignment
;
406 if (packing
->RowLength
> 0) {
407 pixels_per_row
= packing
->RowLength
;
410 pixels_per_row
= width
;
412 if (packing
->ImageHeight
> 0) {
413 rows_per_image
= packing
->ImageHeight
;
416 rows_per_image
= height
;
418 skiprows
= packing
->SkipRows
;
419 skippixels
= packing
->SkipPixels
;
420 skipimages
= packing
->SkipImages
;
422 if (type
==GL_BITMAP
) {
424 GLint comp_per_pixel
; /* components per pixel */
425 GLint bytes_per_comp
; /* bytes per component */
427 GLint bytes_per_image
;
429 /* Compute bytes per component */
430 bytes_per_comp
= gl_sizeof_packed_type( type
);
431 if (bytes_per_comp
<0) {
435 /* Compute number of components per pixel */
436 comp_per_pixel
= gl_components_in_format( format
);
437 if (comp_per_pixel
<0 && type
!= GL_BITMAP
) {
441 bytes_per_row
= alignment
442 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
444 bytes_per_image
= bytes_per_row
* rows_per_image
;
446 pixel_addr
= (GLubyte
*) image
447 + (skipimages
+ img
) * bytes_per_image
448 + (skiprows
+ row
) * bytes_per_row
449 + (skippixels
+ column
) / 8;
452 /* Non-BITMAP data */
453 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
455 bytes_per_pixel
= gl_bytes_per_pixel( format
, type
);
457 /* The pixel type and format should have been error checked earlier */
458 assert(bytes_per_pixel
> 0);
460 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
461 remainder
= bytes_per_row
% alignment
;
463 bytes_per_row
+= (alignment
- remainder
);
465 ASSERT(bytes_per_row
% alignment
== 0);
467 bytes_per_image
= bytes_per_row
* rows_per_image
;
469 /* compute final pixel address */
470 pixel_addr
= (GLubyte
*) image
471 + (skipimages
+ img
) * bytes_per_image
472 + (skiprows
+ row
) * bytes_per_row
473 + (skippixels
+ column
) * bytes_per_pixel
;
476 return (GLvoid
*) pixel_addr
;
482 * Allocate a new gl_image. All fields are initialized to zero.
484 static struct gl_image
*alloc_image( void )
486 return CALLOC_STRUCT(gl_image
);
492 * Allocate a new gl_image with the error flag set.
494 static struct gl_image
*alloc_error_image( GLint width
, GLint height
,
495 GLint depth
, GLenum format
,
498 struct gl_image
*image
= alloc_image();
500 image
->Width
= width
;
501 image
->Height
= height
;
502 image
->Depth
= depth
;
503 image
->Format
= format
;
505 image
->ErrorFlag
= GL_TRUE
;
515 void gl_free_image( struct gl_image
*image
)
526 * Do error checking on an image. If there's an error, register it and
527 * return GL_TRUE, else return GL_FALSE.
529 GLboolean
gl_image_error_test( GLcontext
*ctx
, const struct gl_image
*image
,
533 gl_error( ctx
, GL_OUT_OF_MEMORY
, msg
);
536 if (image
->Width
<= 0 || image
->Height
<= 0 || image
->Depth
<= 0) {
537 gl_error( ctx
, GL_INVALID_VALUE
, msg
);
540 else if (!gl_is_legal_format_and_type(image
->Format
, image
->Type
)) {
551 * Unpack a depth-buffer image storing values as GLshort, GLuint, or GLfloats.
552 * Input: type - datatype of src depth image
553 * Return pointer to a new gl_image structure.
555 * Notes: if the source image type is GLushort then the gl_image will
556 * also store GLushorts. If the src image type is GLuint then the gl_image
557 * will also store GLuints. For all other src image types the gl_image
558 * will store GLfloats. The integer cases can later be optimized.
560 static struct gl_image
*
561 unpack_depth_image( GLcontext
*ctx
, GLenum type
, GLint width
, GLint height
,
562 const GLvoid
*pixels
,
563 const struct gl_pixelstore_attrib
*packing
)
566 struct gl_image
*image
;
573 errorType
= type
!= GL_BYTE
&&
574 type
!= GL_UNSIGNED_BYTE
&&
576 type
!= GL_UNSIGNED_SHORT
&&
578 type
!= GL_UNSIGNED_INT
&&
581 image
= alloc_image();
583 image
->Width
= width
;
584 image
->Height
= height
;
586 image
->Components
= 1;
587 image
->Format
= GL_DEPTH_COMPONENT
;
592 if (type
==GL_UNSIGNED_SHORT
) {
593 image
->Type
= GL_UNSIGNED_SHORT
;
594 image
->Data
= MALLOC( width
* height
* sizeof(GLushort
));
596 else if (type
==GL_UNSIGNED_INT
) {
597 image
->Type
= GL_UNSIGNED_INT
;
598 image
->Data
= MALLOC( width
* height
* sizeof(GLuint
));
601 image
->Type
= GL_FLOAT
;
602 image
->Data
= MALLOC( width
* height
* sizeof(GLfloat
));
615 fDst
= (GLfloat
*) image
->Data
;
616 sDst
= (GLushort
*) image
->Data
;
617 iDst
= (GLuint
*) image
->Data
;
619 for (i
=0;i
<height
;i
++) {
620 GLvoid
*src
= gl_pixel_addr_in_image( packing
, pixels
,
622 GL_DEPTH_COMPONENT
, type
,
630 assert(image
->Type
== GL_FLOAT
);
631 for (j
=0; j
<width
; j
++) {
632 *fDst
++ = BYTE_TO_FLOAT(((GLbyte
*)src
)[j
]);
635 case GL_UNSIGNED_BYTE
:
636 assert(image
->Type
== GL_FLOAT
);
637 for (j
=0; j
<width
; j
++) {
638 *fDst
++ = UBYTE_TO_FLOAT(((GLubyte
*)src
)[j
]);
641 case GL_UNSIGNED_SHORT
:
642 assert(image
->Type
== GL_UNSIGNED_SHORT
);
643 MEMCPY( sDst
, src
, width
* sizeof(GLushort
) );
644 if (packing
->SwapBytes
) {
645 gl_swap2( sDst
, width
);
650 assert(image
->Type
== GL_FLOAT
);
651 if (packing
->SwapBytes
) {
652 for (j
=0;j
<width
;j
++) {
653 GLshort value
= ((GLshort
*)src
)[j
];
654 value
= ((value
>> 8) & 0xff) | ((value
&0xff) << 8);
655 *fDst
++ = SHORT_TO_FLOAT(value
);
659 for (j
=0;j
<width
;j
++) {
660 *fDst
++ = SHORT_TO_FLOAT(((GLshort
*)src
)[j
]);
665 assert(image
->Type
== GL_FLOAT
);
666 if (packing
->SwapBytes
) {
667 for (j
=0;j
<width
;j
++) {
668 GLint value
= ((GLint
*)src
)[j
];
669 value
= ((value
>> 24) & 0x000000ff) |
670 ((value
>> 8) & 0x0000ff00) |
671 ((value
<< 8) & 0x00ff0000) |
672 ((value
<< 24) & 0xff000000);
673 *fDst
++ = INT_TO_FLOAT(value
);
677 for (j
=0;j
<width
;j
++) {
678 *fDst
++ = INT_TO_FLOAT(((GLint
*)src
)[j
]);
683 case GL_UNSIGNED_INT
:
684 assert(image
->Type
== GL_UNSIGNED_INT
);
685 MEMCPY( iDst
, src
, width
* sizeof(GLuint
) );
686 if (packing
->SwapBytes
) {
687 gl_swap4( iDst
, width
);
692 assert(image
->Type
== GL_FLOAT
);
693 MEMCPY( fDst
, src
, width
* sizeof(GLfloat
) );
694 if (packing
->SwapBytes
) {
695 gl_swap4( (GLuint
*) fDst
, width
);
700 gl_problem(ctx
, "unpack_depth_image type" );
711 * Unpack a stencil image. Store as GLubytes in a gl_image structure.
712 * Return: pointer to new gl_image structure.
714 static struct gl_image
*
715 unpack_stencil_image( GLcontext
*ctx
, GLenum type
, GLint width
, GLint height
,
716 const GLvoid
*pixels
,
717 const struct gl_pixelstore_attrib
*packing
)
719 struct gl_image
*image
;
724 assert(sizeof(GLstencil
) == sizeof(GLubyte
));
726 errorType
= type
!= GL_BYTE
&&
727 type
!= GL_UNSIGNED_BYTE
&&
729 type
!= GL_UNSIGNED_SHORT
&&
731 type
!= GL_UNSIGNED_INT
&&
735 image
= alloc_image();
737 image
->Width
= width
;
738 image
->Height
= height
;
740 image
->Components
= 1;
741 image
->Format
= GL_STENCIL_INDEX
;
747 image
->Type
= GL_UNSIGNED_BYTE
;
748 image
->Data
= MALLOC( width
* height
* sizeof(GLubyte
));
759 return image
; /* error will be generated later */
761 dst
= (GLubyte
*) image
->Data
;
763 for (i
=0;i
<height
;i
++) {
764 GLvoid
*src
= gl_pixel_addr_in_image( packing
, pixels
,
766 GL_STENCIL_INDEX
, type
,
773 case GL_UNSIGNED_BYTE
:
775 MEMCPY( dst
, src
, width
* sizeof(GLubyte
) );
776 dst
+= width
* sizeof(GLubyte
);
778 case GL_UNSIGNED_SHORT
:
780 if (packing
->SwapBytes
) {
781 /* grab upper byte */
782 for (j
=0; j
< width
; j
++) {
783 *dst
++ = (((GLushort
*)src
)[j
] & 0xff00) >> 8;
787 for (j
=0; j
< width
; j
++) {
788 *dst
++ = (((GLushort
*)src
)[j
]) & 0xff;
793 if (packing
->SwapBytes
) {
794 /* grab upper byte */
795 for (j
=0; j
< width
; j
++) {
796 *dst
++ = (((GLuint
*)src
)[j
] & 0xff000000) >> 8;
800 for (j
=0; j
< width
; j
++) {
801 *dst
++ = (((GLuint
*)src
)[j
]) & 0xff;
805 case GL_UNSIGNED_INT
:
806 if (packing
->SwapBytes
) {
807 /* grab upper byte */
808 for (j
=0; j
< width
; j
++) {
809 *dst
++ = (((GLuint
*)src
)[j
] & 0xff000000) >> 8;
813 for (j
=0; j
< width
; j
++) {
814 *dst
++ = (((GLuint
*)src
)[j
]) & 0xff;
819 if (packing
->SwapBytes
) {
820 for (j
=0; j
< width
; j
++) {
822 GLint value
= ((GLuint
*)src
)[j
];
823 value
= ((value
& 0xff000000) >> 24)
824 | ((value
& 0x00ff0000) >> 8)
825 | ((value
& 0x0000ff00) << 8)
826 | ((value
& 0x000000ff) << 24);
827 fvalue
= *((GLfloat
*) &value
);
828 *dst
++ = ((GLint
) fvalue
) & 0xff;
832 for (j
=0; j
< width
; j
++) {
833 GLfloat fvalue
= ((GLfloat
*)src
)[j
];
834 *dst
++ = ((GLint
) fvalue
) & 0xff;
839 gl_problem(ctx
, "unpack_stencil_image type" );
850 * Unpack a bitmap, return a new gl_image struct.
852 static struct gl_image
*
853 unpack_bitmap( GLenum format
, GLint width
, GLint height
,
854 const GLvoid
*pixels
,
855 const struct gl_pixelstore_attrib
*packing
)
857 struct gl_image
*image
;
858 GLint bytes
, i
, width_in_bytes
;
859 GLubyte
*buffer
, *dst
;
861 assert(format
== GL_COLOR_INDEX
|| format
== GL_STENCIL_INDEX
);
863 /* Alloc dest storage */
864 bytes
= ((width
+7)/8 * height
);
865 if (bytes
>0 && pixels
!=NULL
) {
866 buffer
= (GLubyte
*) MALLOC( bytes
);
870 /* Copy/unpack pixel data to buffer */
871 width_in_bytes
= CEILING( width
, 8 );
873 for (i
=0; i
<height
; i
++) {
874 GLvoid
*src
= gl_pixel_addr_in_image( packing
, pixels
,
876 GL_COLOR_INDEX
, GL_BITMAP
,
882 MEMCPY( dst
, src
, width_in_bytes
);
883 dst
+= width_in_bytes
;
886 if (packing
->LsbFirst
) {
887 gl_flip_bytes( buffer
, bytes
);
891 /* a 'null' bitmap */
895 image
= alloc_image();
897 image
->Width
= width
;
898 image
->Height
= height
;
900 image
->Components
= 0;
901 image
->Format
= format
;
902 image
->Type
= GL_BITMAP
;
903 image
->Data
= buffer
;
917 * Unpack a 32x32 pixel polygon stipple from user memory using the
918 * current pixel unpack settings.
920 void gl_unpack_polygon_stipple( const GLcontext
*ctx
,
921 const GLubyte
*pattern
, GLuint dest
[32] )
924 for (i
= 0; i
< 32; i
++) {
925 GLubyte
*src
= (GLubyte
*) gl_pixel_addr_in_image( &ctx
->Unpack
, pattern
,
926 32, 32, GL_COLOR_INDEX
, GL_BITMAP
, 0, i
, 0 );
927 dest
[i
] = (src
[0] << 24)
933 /* Bit flipping within each byte */
934 if (ctx
->Unpack
.LsbFirst
) {
935 gl_flip_bytes( (GLubyte
*) dest
, 32 * 4 );
942 * Pack polygon stipple into user memory given current pixel packing
945 void gl_pack_polygon_stipple( const GLcontext
*ctx
,
946 const GLuint pattern
[32],
950 for (i
= 0; i
< 32; i
++) {
951 GLubyte
*dst
= (GLubyte
*) gl_pixel_addr_in_image( &ctx
->Pack
, dest
,
952 32, 32, GL_COLOR_INDEX
, GL_BITMAP
, 0, i
, 0 );
953 dst
[0] = (pattern
[i
] >> 24) & 0xff;
954 dst
[1] = (pattern
[i
] >> 16) & 0xff;
955 dst
[2] = (pattern
[i
] >> 8) & 0xff;
956 dst
[3] = (pattern
[i
] ) & 0xff;
958 /* Bit flipping within each byte */
959 if (ctx
->Pack
.LsbFirst
) {
960 gl_flip_bytes( (GLubyte
*) dst
, 4 );
968 * Unpack an RGBA or CI image and store it as unsigned bytes
970 static struct gl_image
*
971 unpack_ubyte_image( GLint width
, GLint height
,
972 GLint depth
, GLenum format
, const GLvoid
*pixels
,
973 const struct gl_pixelstore_attrib
*packing
)
975 struct gl_image
*image
;
976 GLint width_in_bytes
;
978 GLubyte
*buffer
, *dst
;
981 components
= gl_components_in_format( format
);
983 width_in_bytes
= width
* components
* sizeof(GLubyte
);
984 buffer
= (GLubyte
*) MALLOC( height
* width_in_bytes
* depth
);
989 /* Copy/unpack pixel data to buffer */
991 for (d
=0; d
<depth
; d
++ ) {
992 for (i
=0;i
<height
;i
++) {
993 GLubyte
*src
= (GLubyte
*) gl_pixel_addr_in_image( packing
,
994 pixels
, width
, height
, format
, GL_UNSIGNED_BYTE
,
1000 MEMCPY( dst
, src
, width_in_bytes
);
1001 dst
+= width_in_bytes
;
1005 if (format
== GL_BGR
) {
1006 /* swap order of every ubyte triplet from BGR to RGB */
1007 for (i
=0; i
<width
*height
; i
++) {
1008 GLubyte b
= buffer
[i
*3+0];
1009 GLubyte r
= buffer
[i
*3+2];
1014 else if (format
== GL_BGRA
) {
1015 /* swap order of every ubyte quadruplet from BGRA to RGBA */
1016 for (i
=0; i
<width
*height
; i
++) {
1017 GLubyte b
= buffer
[i
*4+0];
1018 GLubyte r
= buffer
[i
*4+2];
1023 else if (format
== GL_ABGR_EXT
) {
1024 /* swap order of every ubyte quadruplet from ABGR to RGBA */
1025 for (i
=0; i
<width
*height
; i
++) {
1026 GLubyte a
= buffer
[i
*4+0];
1027 GLubyte b
= buffer
[i
*4+1];
1028 GLubyte g
= buffer
[i
*4+2];
1029 GLubyte r
= buffer
[i
*4+3];
1038 image
= alloc_image();
1040 image
->Width
= width
;
1041 image
->Height
= height
;
1042 image
->Depth
= depth
;
1043 image
->Components
= components
;
1044 if (format
== GL_BGR
)
1045 image
->Format
= GL_RGB
;
1046 else if (format
== GL_BGRA
)
1047 image
->Format
= GL_RGBA
;
1048 else if (format
== GL_ABGR_EXT
)
1049 image
->Format
= GL_RGBA
;
1051 image
->Format
= format
;
1052 image
->Type
= GL_UNSIGNED_BYTE
;
1053 image
->Data
= buffer
;
1054 image
->RefCount
= 0;
1066 * Unpack a color image storing image as GLfloats
1068 static struct gl_image
*
1069 unpack_float_image( GLcontext
*ctx
, GLint width
, GLint height
, GLint depth
,
1070 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1071 const struct gl_pixelstore_attrib
*packing
)
1073 struct gl_image
*image
;
1075 GLint elems_per_row
;
1078 GLboolean normalize
;
1080 assert(type
!= GL_BITMAP
);
1082 components
= gl_components_in_format( format
);
1083 assert(components
> 0); /* should have been caught earlier */
1085 if (!gl_is_legal_format_and_type( format
, type
)) {
1086 /* bad pixel type for format, make dummy image */
1087 image
= alloc_image();
1089 image
->Width
= width
;
1090 image
->Height
= height
;
1091 image
->Depth
= depth
;
1092 image
->Components
= components
;
1093 image
->Format
= format
;
1096 image
->RefCount
= 0;
1101 elems_per_row
= width
* components
;
1103 image
= alloc_image();
1105 image
->Width
= width
;
1106 image
->Height
= height
;
1107 image
->Depth
= depth
;
1108 image
->Components
= components
;
1109 if (format
== GL_BGR
)
1110 image
->Format
= GL_RGB
;
1111 else if (format
== GL_BGRA
)
1112 image
->Format
= GL_RGBA
;
1113 else if (format
== GL_ABGR_EXT
)
1114 image
->Format
= GL_RGBA
;
1116 image
->Format
= format
;
1117 image
->Type
= GL_FLOAT
;
1118 image
->Data
= MALLOC( elems_per_row
* height
* depth
* sizeof(GLfloat
));
1119 image
->RefCount
= 0;
1127 normalize
= (format
!= GL_COLOR_INDEX
) && (format
!= GL_STENCIL_INDEX
);
1129 dst
= (GLfloat
*) image
->Data
;
1131 for (d
=0; d
<depth
; d
++) {
1132 for (i
=0;i
<height
;i
++) {
1133 GLvoid
*src
= gl_pixel_addr_in_image( packing
, pixels
,
1142 case GL_UNSIGNED_BYTE
:
1144 GLubyte
*ubsrc
= (GLubyte
*) src
;
1146 for (j
=0;j
<elems_per_row
;j
++) {
1147 *dst
++ = UBYTE_TO_FLOAT(ubsrc
[j
]);
1151 for (j
=0;j
<elems_per_row
;j
++) {
1152 *dst
++ = (GLfloat
) ubsrc
[j
];
1159 for (j
=0;j
<elems_per_row
;j
++) {
1160 *dst
++ = BYTE_TO_FLOAT(((GLbyte
*)src
)[j
]);
1164 for (j
=0;j
<elems_per_row
;j
++) {
1165 *dst
++ = (GLfloat
) ((GLbyte
*)src
)[j
];
1169 case GL_UNSIGNED_SHORT
:
1170 if (packing
->SwapBytes
) {
1171 for (j
=0;j
<elems_per_row
;j
++) {
1172 GLushort value
= ((GLushort
*)src
)[j
];
1173 value
= ((value
>> 8) & 0xff) | ((value
&0xff) << 8);
1175 *dst
++ = USHORT_TO_FLOAT(value
);
1178 *dst
++ = (GLfloat
) value
;
1184 for (j
=0;j
<elems_per_row
;j
++) {
1185 *dst
++ = USHORT_TO_FLOAT(((GLushort
*)src
)[j
]);
1189 for (j
=0;j
<elems_per_row
;j
++) {
1190 *dst
++ = (GLfloat
) ((GLushort
*)src
)[j
];
1196 if (packing
->SwapBytes
) {
1197 for (j
=0;j
<elems_per_row
;j
++) {
1198 GLshort value
= ((GLshort
*)src
)[j
];
1199 value
= ((value
>> 8) & 0xff) | ((value
&0xff) << 8);
1201 *dst
++ = SHORT_TO_FLOAT(value
);
1204 *dst
++ = (GLfloat
) value
;
1210 for (j
=0;j
<elems_per_row
;j
++) {
1211 *dst
++ = SHORT_TO_FLOAT(((GLshort
*)src
)[j
]);
1215 for (j
=0;j
<elems_per_row
;j
++) {
1216 *dst
++ = (GLfloat
) ((GLshort
*)src
)[j
];
1221 case GL_UNSIGNED_INT
:
1222 if (packing
->SwapBytes
) {
1224 for (j
=0;j
<elems_per_row
;j
++) {
1225 value
= ((GLuint
*)src
)[j
];
1226 value
= ((value
& 0xff000000) >> 24)
1227 | ((value
& 0x00ff0000) >> 8)
1228 | ((value
& 0x0000ff00) << 8)
1229 | ((value
& 0x000000ff) << 24);
1231 *dst
++ = UINT_TO_FLOAT(value
);
1234 *dst
++ = (GLfloat
) value
;
1240 for (j
=0;j
<elems_per_row
;j
++) {
1241 *dst
++ = UINT_TO_FLOAT(((GLuint
*)src
)[j
]);
1245 for (j
=0;j
<elems_per_row
;j
++) {
1246 *dst
++ = (GLfloat
) ((GLuint
*)src
)[j
];
1252 if (packing
->SwapBytes
) {
1254 for (j
=0;j
<elems_per_row
;j
++) {
1255 value
= ((GLint
*)src
)[j
];
1256 value
= ((value
& 0xff000000) >> 24)
1257 | ((value
& 0x00ff0000) >> 8)
1258 | ((value
& 0x0000ff00) << 8)
1259 | ((value
& 0x000000ff) << 24);
1261 *dst
++ = INT_TO_FLOAT(value
);
1264 *dst
++ = (GLfloat
) value
;
1270 for (j
=0;j
<elems_per_row
;j
++) {
1271 *dst
++ = INT_TO_FLOAT(((GLint
*)src
)[j
]);
1275 for (j
=0;j
<elems_per_row
;j
++) {
1276 *dst
++ = (GLfloat
) ((GLint
*)src
)[j
];
1282 if (packing
->SwapBytes
) {
1284 for (j
=0;j
<elems_per_row
;j
++) {
1285 value
= ((GLuint
*)src
)[j
];
1286 value
= ((value
& 0xff000000) >> 24)
1287 | ((value
& 0x00ff0000) >> 8)
1288 | ((value
& 0x0000ff00) << 8)
1289 | ((value
& 0x000000ff) << 24);
1290 *dst
++ = *((GLfloat
*) &value
);
1294 MEMCPY( dst
, src
, elems_per_row
*sizeof(GLfloat
) );
1295 dst
+= elems_per_row
;
1298 case GL_UNSIGNED_BYTE_3_3_2
:
1300 GLubyte
*ubsrc
= (GLubyte
*) src
;
1301 for (j
=0;j
<width
;j
++) {
1302 GLubyte p
= ubsrc
[j
];
1303 *dst
++ = ((p
>> 5) ) * (1.0F
/ 7.0F
); /* red */
1304 *dst
++ = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
); /* green */
1305 *dst
++ = ((p
) & 0x3) * (1.0F
/ 3.0F
); /* blue */
1309 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1311 GLubyte
*ubsrc
= (GLubyte
*) src
;
1312 for (j
=0;j
<width
;j
++) {
1313 GLubyte p
= ubsrc
[j
];
1314 *dst
++ = ((p
) & 0x7) * (1.0F
/ 7.0F
); /* red */
1315 *dst
++ = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
); /* green */
1316 *dst
++ = ((p
>> 6) ) * (1.0F
/ 3.0F
); /* blue */
1320 case GL_UNSIGNED_SHORT_5_6_5
:
1322 GLushort
*ussrc
= (GLushort
*) src
;
1323 for (j
=0;j
<width
;j
++) {
1324 GLushort p
= ussrc
[j
];
1325 *dst
++ = ((p
>> 11) ) * (1.0F
/ 31.0F
); /* red */
1326 *dst
++ = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
); /* green */
1327 *dst
++ = ((p
) & 0x1f) * (1.0F
/ 31.0F
); /* blue */
1331 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1333 GLushort
*ussrc
= (GLushort
*) src
;
1334 for (j
=0;j
<width
;j
++) {
1335 GLushort p
= ussrc
[j
];
1336 *dst
++ = ((p
) & 0x1f) * (1.0F
/ 31.0F
); /* red */
1337 *dst
++ = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
); /* green */
1338 *dst
++ = ((p
>> 11) ) * (1.0F
/ 31.0F
); /* blue */
1342 case GL_UNSIGNED_SHORT_4_4_4_4
:
1344 GLushort
*ussrc
= (GLushort
*) src
;
1345 for (j
=0;j
<width
;j
++) {
1346 GLushort p
= ussrc
[j
];
1347 *dst
++ = ((p
>> 12) ) * (1.0F
/ 15.0F
); /* red */
1348 *dst
++ = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
); /* green */
1349 *dst
++ = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
); /* blue */
1350 *dst
++ = ((p
) & 0xf) * (1.0F
/ 15.0F
); /* alpha */
1354 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1356 GLushort
*ussrc
= (GLushort
*) src
;
1357 for (j
=0;j
<width
;j
++) {
1358 GLushort p
= ussrc
[j
];
1359 *dst
++ = ((p
) & 0xf) * (1.0F
/ 15.0F
); /* red */
1360 *dst
++ = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
); /* green */
1361 *dst
++ = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
); /* blue */
1362 *dst
++ = ((p
>> 12) ) * (1.0F
/ 15.0F
); /* alpha */
1366 case GL_UNSIGNED_SHORT_5_5_5_1
:
1368 GLushort
*ussrc
= (GLushort
*) src
;
1369 for (j
=0;j
<width
;j
++) {
1370 GLushort p
= ussrc
[j
];
1371 *dst
++ = ((p
>> 11) ) * (1.0F
/ 31.0F
); /* red */
1372 *dst
++ = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
); /* green */
1373 *dst
++ = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
); /* blue */
1374 *dst
++ = ((p
) & 0x1) * (1.0F
/ 1.0F
); /* alpha */
1378 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1380 GLushort
*ussrc
= (GLushort
*) src
;
1381 for (j
=0;j
<width
;j
++) {
1382 GLushort p
= ussrc
[j
];
1383 *dst
++ = ((p
) & 0x1f) * (1.0F
/ 31.0F
); /* red */
1384 *dst
++ = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
); /* green */
1385 *dst
++ = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
); /* blue */
1386 *dst
++ = ((p
>> 15) ) * (1.0F
/ 1.0F
); /* alpha */
1390 case GL_UNSIGNED_INT_8_8_8_8
:
1392 GLuint
*uisrc
= (GLuint
*) src
;
1393 for (j
=0;j
<width
;j
++) {
1394 GLuint p
= uisrc
[j
];
1395 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
1396 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
1397 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
1398 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
1402 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1404 GLuint
*uisrc
= (GLuint
*) src
;
1405 for (j
=0;j
<width
;j
++) {
1406 GLuint p
= uisrc
[j
];
1407 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
1408 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
1409 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
1410 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
1414 case GL_UNSIGNED_INT_10_10_10_2
:
1416 GLuint
*uisrc
= (GLuint
*) src
;
1417 for (j
=0;j
<width
;j
++) {
1418 GLuint p
= uisrc
[j
];
1419 *dst
++ = ((p
>> 22) ) * (1.0F
/ 1023.0F
); /* r */
1420 *dst
++ = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
); /* g */
1421 *dst
++ = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
); /* b */
1422 *dst
++ = ((p
) & 0x3 ) * (1.0F
/ 3.0F
); /* a */
1426 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1428 GLuint
*uisrc
= (GLuint
*) src
;
1429 for (j
=0;j
<width
;j
++) {
1430 GLuint p
= uisrc
[j
];
1431 *dst
++ = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
); /* r*/
1432 *dst
++ = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
); /* g */
1433 *dst
++ = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
); /* b */
1434 *dst
++ = ((p
>> 30) ) * (1.0F
/ 3.0F
); /* a */
1439 gl_problem(ctx
, "unpack_float_image type" );
1445 if (format
== GL_BGR
) {
1446 /* swap order of every float triplet from BGR to RGBA */
1447 GLfloat
*buffer
= (GLfloat
*) image
->Data
;
1448 for (i
=0; i
<width
*height
*depth
; i
++) {
1449 GLfloat b
= buffer
[i
*3+0];
1450 GLfloat r
= buffer
[i
*3+2];
1455 else if (format
== GL_BGRA
) {
1456 /* swap order of every float quadruplet from BGRA to RGBA */
1457 GLfloat
*buffer
= (GLfloat
*) image
->Data
;
1458 for (i
=0; i
<width
*height
*depth
; i
++) {
1459 GLfloat b
= buffer
[i
*4+0];
1460 GLfloat r
= buffer
[i
*4+2];
1465 else if (format
== GL_ABGR_EXT
) {
1466 /* swap order of every float quadruplet from ABGR to RGBA */
1467 GLfloat
*buffer
= (GLfloat
*) image
->Data
;
1468 for (i
=0; i
<width
*height
*depth
; i
++) {
1469 GLfloat a
= buffer
[i
*4+0];
1470 GLfloat b
= buffer
[i
*4+1];
1471 GLfloat g
= buffer
[i
*4+2];
1472 GLfloat r
= buffer
[i
*4+3];
1486 * Unpack a bitmap image, using current glPixelStore parameters,
1487 * making a new gl_image.
1489 struct gl_image
*gl_unpack_bitmap( GLcontext
*ctx
,
1490 GLsizei width
, GLsizei height
,
1491 const GLubyte
*bitmap
,
1492 const struct gl_pixelstore_attrib
*packing
)
1494 return gl_unpack_image( ctx
, width
, height
,
1495 GL_COLOR_INDEX
, GL_BITMAP
, bitmap
, packing
);
1501 * Unpack a 2-D image from user's buffer. Return pointer to new
1504 * Input: width, height - size in pixels
1505 * format - format of incoming pixel data
1506 * type - datatype of incoming pixel data
1507 * pixels - pointer to unpacked image in user buffer
1509 struct gl_image
*gl_unpack_image( GLcontext
*ctx
,
1510 GLint width
, GLint height
,
1511 GLenum format
, GLenum type
,
1512 const GLvoid
*pixels
,
1513 const struct gl_pixelstore_attrib
*packing
)
1515 return gl_unpack_image3D( ctx
, width
, height
, 1,
1516 format
, type
, pixels
, packing
);
1522 * Unpack a 1, 2 or 3-D image from user-supplied address, returning a
1523 * pointer to a new gl_image struct.
1524 * This function is always called by a higher-level unpack function such
1525 * as gl_unpack_texsubimage() or gl_unpack_bitmap().
1527 * Input: width, height, depth - size in pixels
1528 * format - format of incoming pixel data
1529 * type - datatype of incoming pixel data
1530 * pixels - pointer to unpacked image.
1532 struct gl_image
*gl_unpack_image3D( GLcontext
*ctx
,
1533 GLint width
, GLint height
, GLint depth
,
1534 GLenum format
, GLenum type
,
1535 const GLvoid
*pixels
,
1536 const struct gl_pixelstore_attrib
*packing
)
1538 if (width
<= 0 || height
<= 0 || depth
<= 0) {
1539 return alloc_error_image(width
, height
, depth
, format
, type
);
1542 if (type
==GL_BITMAP
) {
1543 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1544 return alloc_error_image(width
, height
, depth
, format
, type
);
1547 return unpack_bitmap( format
, width
, height
, pixels
, packing
);
1550 else if (format
==GL_DEPTH_COMPONENT
) {
1551 /* TODO: pack as GLdepth values (GLushort or GLuint) */
1552 return unpack_depth_image( ctx
, type
, width
, height
, pixels
, packing
);
1554 else if (format
==GL_STENCIL_INDEX
) {
1555 /* TODO: pack as GLstencil (GLubyte or GLushort) */
1556 return unpack_stencil_image( ctx
, type
, width
, height
, pixels
, packing
);
1558 else if (type
==GL_UNSIGNED_BYTE
) {
1559 /* upack, convert to GLubytes */
1560 return unpack_ubyte_image( width
, height
, depth
, format
, pixels
, packing
);
1563 /* upack, convert to floats */
1564 return unpack_float_image( ctx
, width
, height
, depth
,
1565 format
, type
, pixels
, packing
);
1568 /* never get here */
1574 * Apply pixel-transfer operations (scale, bias, mapping) to a single row
1575 * of a gl_image. Put resulting color components into result array.
1577 void gl_scale_bias_map_image_data( const GLcontext
*ctx
,
1578 const struct gl_image
*image
,
1579 GLint row
, GLubyte result
[] )
1588 start
= row
* image
->Width
* image
->Components
;
1590 for (i
=0; i
< image
->Width
; i
++) {
1591 GLint pos
= start
+i
;
1592 GLfloat red
, green
, blue
, alpha
;
1593 if (image
->Type
== GL_UNSIGNED_BYTE
) {
1594 const GLubyte
*data
= (GLubyte
*) image
->Data
;
1595 switch (image
->Format
) {
1597 red
= data
[pos
] * (1.0F
/255.0F
);
1603 red
= data
[pos
*3+0] * (1.0F
/255.0F
);
1604 green
= data
[pos
*3+1] * (1.0F
/255.0F
);
1605 blue
= data
[pos
*3+2] * (1.0F
/255.0F
);
1609 gl_problem(ctx
, "bad image format in gl_scale...image_data");
1613 else if (image
->Type
== GL_FLOAT
) {
1614 const GLubyte
*data
= (GLubyte
*) image
->Data
;
1615 switch (image
->Format
) {
1623 red
= data
[pos
*3+0];
1624 green
= data
[pos
*3+1];
1625 blue
= data
[pos
*3+2];
1629 gl_problem(ctx
, "bad image format in gl_scale...image_data");
1634 gl_problem(ctx
, "Bad image type in gl_scale_...image_data");
1638 assert(red
>= 0.0 && red
<= 1.0);
1639 assert(green
>= 0.0 && green
<= 1.0);
1640 assert(blue
>= 0.0 && blue
<= 1.0);
1641 assert(alpha
>= 0.0 && alpha
<= 1.0);
1644 if (scale or bias) {
1653 result
[i
*4+0] = (GLubyte
) (red
* 255.0);
1654 result
[i
*4+1] = (GLubyte
) (green
* 255.0);
1655 result
[i
*4+2] = (GLubyte
) (blue
* 255.0);
1656 result
[i
*4+3] = (GLubyte
) (alpha
* 255.0);
1663 * Pack the given RGBA span into client memory at 'dest' address
1664 * in the given pixel format and type.
1665 * Optionally apply the enabled pixel transfer ops.
1666 * Pack into memory using the given packing params struct.
1667 * This is used by glReadPixels and glGetTexImage?D()
1668 * Input: ctx - the context
1669 * n - number of pixels in the span
1671 * format - dest packing format
1672 * type - dest packing datatype
1673 * destination - destination packing address
1674 * packing - pixel packing parameters
1675 * applyTransferOps - apply scale/bias/lookup-table ops?
1677 void gl_pack_rgba_span( const GLcontext
*ctx
,
1678 GLuint n
, CONST GLubyte rgba
[][4],
1679 GLenum format
, GLenum type
, GLvoid
*destination
,
1680 const struct gl_pixelstore_attrib
*packing
,
1681 GLboolean applyTransferOps
)
1683 /* Test for optimized case first */
1684 if (!ctx
->Pixel
.ScaleOrBiasRGBA
&& !ctx
->Pixel
.MapColorFlag
&&
1685 format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
1686 /* common simple case */
1687 MEMCPY( destination
, rgba
, n
* 4 * sizeof(GLubyte
) );
1689 else if (!ctx
->Pixel
.ScaleOrBiasRGBA
&& !ctx
->Pixel
.MapColorFlag
&&
1690 format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
1691 /* common simple case */
1693 GLubyte
*dest
= (GLubyte
*) destination
;
1694 for (i
= 0; i
< n
; i
++) {
1695 dest
[0] = rgba
[i
][RCOMP
];
1696 dest
[1] = rgba
[i
][GCOMP
];
1697 dest
[2] = rgba
[i
][BCOMP
];
1702 GLfloat red
[MAX_WIDTH
], green
[MAX_WIDTH
], blue
[MAX_WIDTH
];
1703 GLfloat alpha
[MAX_WIDTH
], luminance
[MAX_WIDTH
];
1704 const GLfloat rscale
= 1.0F
/ 255.0F
;
1705 const GLfloat gscale
= 1.0F
/ 255.0F
;
1706 const GLfloat bscale
= 1.0F
/ 255.0F
;
1707 const GLfloat ascale
= 1.0F
/ 255.0F
;
1708 const GLint comps
= gl_components_in_format(format
);
1711 assert(n
<= MAX_WIDTH
);
1713 /* convert color components to floating point */
1715 red
[i
] = rgba
[i
][RCOMP
] * rscale
;
1716 green
[i
] = rgba
[i
][GCOMP
] * gscale
;
1717 blue
[i
] = rgba
[i
][BCOMP
] * bscale
;
1718 alpha
[i
] = rgba
[i
][ACOMP
] * ascale
;
1722 * Apply scale, bias and lookup-tables if enabled.
1724 if (applyTransferOps
) {
1725 if (ctx
->Pixel
.ScaleOrBiasRGBA
) {
1726 gl_scale_and_bias_color( ctx
, n
, red
, green
, blue
, alpha
);
1728 if (ctx
->Pixel
.MapColorFlag
) {
1729 gl_map_color( ctx
, n
, red
, green
, blue
, alpha
);
1733 if (format
==GL_LUMINANCE
|| format
==GL_LUMINANCE_ALPHA
) {
1735 GLfloat sum
= red
[i
] + green
[i
] + blue
[i
];
1736 luminance
[i
] = CLAMP( sum
, 0.0F
, 1.0F
);
1741 * Pack/store the pixels. Ugh! Lots of cases!!!
1744 case GL_UNSIGNED_BYTE
:
1746 GLubyte
*dst
= (GLubyte
*) destination
;
1750 dst
[i
] = FLOAT_TO_UBYTE(red
[i
]);
1754 dst
[i
] = FLOAT_TO_UBYTE(green
[i
]);
1758 dst
[i
] = FLOAT_TO_UBYTE(blue
[i
]);
1762 dst
[i
] = FLOAT_TO_UBYTE(alpha
[i
]);
1766 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1768 case GL_LUMINANCE_ALPHA
:
1770 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1771 dst
[i
*2+1] = FLOAT_TO_UBYTE(alpha
[i
]);
1776 dst
[i
*3+0] = FLOAT_TO_UBYTE(red
[i
]);
1777 dst
[i
*3+1] = FLOAT_TO_UBYTE(green
[i
]);
1778 dst
[i
*3+2] = FLOAT_TO_UBYTE(blue
[i
]);
1783 dst
[i
*4+0] = FLOAT_TO_UBYTE(red
[i
]);
1784 dst
[i
*4+1] = FLOAT_TO_UBYTE(green
[i
]);
1785 dst
[i
*4+2] = FLOAT_TO_UBYTE(blue
[i
]);
1786 dst
[i
*4+3] = FLOAT_TO_UBYTE(alpha
[i
]);
1791 dst
[i
*3+0] = FLOAT_TO_UBYTE(blue
[i
]);
1792 dst
[i
*3+1] = FLOAT_TO_UBYTE(green
[i
]);
1793 dst
[i
*3+2] = FLOAT_TO_UBYTE(red
[i
]);
1798 dst
[i
*4+0] = FLOAT_TO_UBYTE(blue
[i
]);
1799 dst
[i
*4+1] = FLOAT_TO_UBYTE(green
[i
]);
1800 dst
[i
*4+2] = FLOAT_TO_UBYTE(red
[i
]);
1801 dst
[i
*4+3] = FLOAT_TO_UBYTE(alpha
[i
]);
1806 dst
[i
*4+0] = FLOAT_TO_UBYTE(alpha
[i
]);
1807 dst
[i
*4+1] = FLOAT_TO_UBYTE(blue
[i
]);
1808 dst
[i
*4+2] = FLOAT_TO_UBYTE(green
[i
]);
1809 dst
[i
*4+3] = FLOAT_TO_UBYTE(red
[i
]);
1813 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
1819 GLbyte
*dst
= (GLbyte
*) destination
;
1823 dst
[i
] = FLOAT_TO_BYTE(red
[i
]);
1827 dst
[i
] = FLOAT_TO_BYTE(green
[i
]);
1831 dst
[i
] = FLOAT_TO_BYTE(blue
[i
]);
1835 dst
[i
] = FLOAT_TO_BYTE(alpha
[i
]);
1839 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1841 case GL_LUMINANCE_ALPHA
:
1843 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1844 dst
[i
*2+1] = FLOAT_TO_BYTE(alpha
[i
]);
1849 dst
[i
*3+0] = FLOAT_TO_BYTE(red
[i
]);
1850 dst
[i
*3+1] = FLOAT_TO_BYTE(green
[i
]);
1851 dst
[i
*3+2] = FLOAT_TO_BYTE(blue
[i
]);
1856 dst
[i
*4+0] = FLOAT_TO_BYTE(red
[i
]);
1857 dst
[i
*4+1] = FLOAT_TO_BYTE(green
[i
]);
1858 dst
[i
*4+2] = FLOAT_TO_BYTE(blue
[i
]);
1859 dst
[i
*4+3] = FLOAT_TO_BYTE(alpha
[i
]);
1864 dst
[i
*3+0] = FLOAT_TO_BYTE(blue
[i
]);
1865 dst
[i
*3+1] = FLOAT_TO_BYTE(green
[i
]);
1866 dst
[i
*3+2] = FLOAT_TO_BYTE(red
[i
]);
1871 dst
[i
*4+0] = FLOAT_TO_BYTE(blue
[i
]);
1872 dst
[i
*4+1] = FLOAT_TO_BYTE(green
[i
]);
1873 dst
[i
*4+2] = FLOAT_TO_BYTE(red
[i
]);
1874 dst
[i
*4+3] = FLOAT_TO_BYTE(alpha
[i
]);
1878 dst
[i
*4+0] = FLOAT_TO_BYTE(alpha
[i
]);
1879 dst
[i
*4+1] = FLOAT_TO_BYTE(blue
[i
]);
1880 dst
[i
*4+2] = FLOAT_TO_BYTE(green
[i
]);
1881 dst
[i
*4+3] = FLOAT_TO_BYTE(red
[i
]);
1885 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
1889 case GL_UNSIGNED_SHORT
:
1891 GLushort
*dst
= (GLushort
*) destination
;
1895 dst
[i
] = FLOAT_TO_USHORT(red
[i
]);
1899 dst
[i
] = FLOAT_TO_USHORT(green
[i
]);
1903 dst
[i
] = FLOAT_TO_USHORT(blue
[i
]);
1907 dst
[i
] = FLOAT_TO_USHORT(alpha
[i
]);
1911 dst
[i
] = FLOAT_TO_USHORT(luminance
[i
]);
1913 case GL_LUMINANCE_ALPHA
:
1915 dst
[i
*2+0] = FLOAT_TO_USHORT(luminance
[i
]);
1916 dst
[i
*2+1] = FLOAT_TO_USHORT(alpha
[i
]);
1921 dst
[i
*3+0] = FLOAT_TO_USHORT(red
[i
]);
1922 dst
[i
*3+1] = FLOAT_TO_USHORT(green
[i
]);
1923 dst
[i
*3+2] = FLOAT_TO_USHORT(blue
[i
]);
1928 dst
[i
*4+0] = FLOAT_TO_USHORT(red
[i
]);
1929 dst
[i
*4+1] = FLOAT_TO_USHORT(green
[i
]);
1930 dst
[i
*4+2] = FLOAT_TO_USHORT(blue
[i
]);
1931 dst
[i
*4+3] = FLOAT_TO_USHORT(alpha
[i
]);
1936 dst
[i
*3+0] = FLOAT_TO_USHORT(blue
[i
]);
1937 dst
[i
*3+1] = FLOAT_TO_USHORT(green
[i
]);
1938 dst
[i
*3+2] = FLOAT_TO_USHORT(red
[i
]);
1943 dst
[i
*4+0] = FLOAT_TO_USHORT(blue
[i
]);
1944 dst
[i
*4+1] = FLOAT_TO_USHORT(green
[i
]);
1945 dst
[i
*4+2] = FLOAT_TO_USHORT(red
[i
]);
1946 dst
[i
*4+3] = FLOAT_TO_USHORT(alpha
[i
]);
1951 dst
[i
*4+0] = FLOAT_TO_USHORT(alpha
[i
]);
1952 dst
[i
*4+1] = FLOAT_TO_USHORT(blue
[i
]);
1953 dst
[i
*4+2] = FLOAT_TO_USHORT(green
[i
]);
1954 dst
[i
*4+3] = FLOAT_TO_USHORT(red
[i
]);
1958 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
1960 if (packing
->SwapBytes
) {
1961 gl_swap2( (GLushort
*) dst
, n
* comps
);
1967 GLshort
*dst
= (GLshort
*) destination
;
1971 dst
[i
] = FLOAT_TO_SHORT(red
[i
]);
1975 dst
[i
] = FLOAT_TO_SHORT(green
[i
]);
1979 dst
[i
] = FLOAT_TO_SHORT(blue
[i
]);
1983 dst
[i
] = FLOAT_TO_SHORT(alpha
[i
]);
1987 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
1989 case GL_LUMINANCE_ALPHA
:
1991 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
1992 dst
[i
*2+1] = FLOAT_TO_SHORT(alpha
[i
]);
1997 dst
[i
*3+0] = FLOAT_TO_SHORT(red
[i
]);
1998 dst
[i
*3+1] = FLOAT_TO_SHORT(green
[i
]);
1999 dst
[i
*3+2] = FLOAT_TO_SHORT(blue
[i
]);
2004 dst
[i
*4+0] = FLOAT_TO_SHORT(red
[i
]);
2005 dst
[i
*4+1] = FLOAT_TO_SHORT(green
[i
]);
2006 dst
[i
*4+2] = FLOAT_TO_SHORT(blue
[i
]);
2007 dst
[i
*4+3] = FLOAT_TO_SHORT(alpha
[i
]);
2012 dst
[i
*3+0] = FLOAT_TO_SHORT(blue
[i
]);
2013 dst
[i
*3+1] = FLOAT_TO_SHORT(green
[i
]);
2014 dst
[i
*3+2] = FLOAT_TO_SHORT(red
[i
]);
2019 dst
[i
*4+0] = FLOAT_TO_SHORT(blue
[i
]);
2020 dst
[i
*4+1] = FLOAT_TO_SHORT(green
[i
]);
2021 dst
[i
*4+2] = FLOAT_TO_SHORT(red
[i
]);
2022 dst
[i
*4+3] = FLOAT_TO_SHORT(alpha
[i
]);
2026 dst
[i
*4+0] = FLOAT_TO_SHORT(alpha
[i
]);
2027 dst
[i
*4+1] = FLOAT_TO_SHORT(blue
[i
]);
2028 dst
[i
*4+2] = FLOAT_TO_SHORT(green
[i
]);
2029 dst
[i
*4+3] = FLOAT_TO_SHORT(red
[i
]);
2033 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
2035 if (packing
->SwapBytes
) {
2036 gl_swap2( (GLushort
*) dst
, n
* comps
);
2040 case GL_UNSIGNED_INT
:
2042 GLuint
*dst
= (GLuint
*) destination
;
2046 dst
[i
] = FLOAT_TO_UINT(red
[i
]);
2050 dst
[i
] = FLOAT_TO_UINT(green
[i
]);
2054 dst
[i
] = FLOAT_TO_UINT(blue
[i
]);
2058 dst
[i
] = FLOAT_TO_UINT(alpha
[i
]);
2062 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
2064 case GL_LUMINANCE_ALPHA
:
2066 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
2067 dst
[i
*2+1] = FLOAT_TO_UINT(alpha
[i
]);
2072 dst
[i
*3+0] = FLOAT_TO_UINT(red
[i
]);
2073 dst
[i
*3+1] = FLOAT_TO_UINT(green
[i
]);
2074 dst
[i
*3+2] = FLOAT_TO_UINT(blue
[i
]);
2079 dst
[i
*4+0] = FLOAT_TO_UINT(red
[i
]);
2080 dst
[i
*4+1] = FLOAT_TO_UINT(green
[i
]);
2081 dst
[i
*4+2] = FLOAT_TO_UINT(blue
[i
]);
2082 dst
[i
*4+3] = FLOAT_TO_UINT(alpha
[i
]);
2087 dst
[i
*3+0] = FLOAT_TO_UINT(blue
[i
]);
2088 dst
[i
*3+1] = FLOAT_TO_UINT(green
[i
]);
2089 dst
[i
*3+2] = FLOAT_TO_UINT(red
[i
]);
2094 dst
[i
*4+0] = FLOAT_TO_UINT(blue
[i
]);
2095 dst
[i
*4+1] = FLOAT_TO_UINT(green
[i
]);
2096 dst
[i
*4+2] = FLOAT_TO_UINT(red
[i
]);
2097 dst
[i
*4+3] = FLOAT_TO_UINT(alpha
[i
]);
2102 dst
[i
*4+0] = FLOAT_TO_UINT(alpha
[i
]);
2103 dst
[i
*4+1] = FLOAT_TO_UINT(blue
[i
]);
2104 dst
[i
*4+2] = FLOAT_TO_UINT(green
[i
]);
2105 dst
[i
*4+3] = FLOAT_TO_UINT(red
[i
]);
2109 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
2111 if (packing
->SwapBytes
) {
2112 gl_swap4( (GLuint
*) dst
, n
* comps
);
2118 GLint
*dst
= (GLint
*) destination
;
2122 dst
[i
] = FLOAT_TO_INT(red
[i
]);
2126 dst
[i
] = FLOAT_TO_INT(green
[i
]);
2130 dst
[i
] = FLOAT_TO_INT(blue
[i
]);
2134 dst
[i
] = FLOAT_TO_INT(alpha
[i
]);
2138 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
2140 case GL_LUMINANCE_ALPHA
:
2142 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
2143 dst
[i
*2+1] = FLOAT_TO_INT(alpha
[i
]);
2148 dst
[i
*3+0] = FLOAT_TO_INT(red
[i
]);
2149 dst
[i
*3+1] = FLOAT_TO_INT(green
[i
]);
2150 dst
[i
*3+2] = FLOAT_TO_INT(blue
[i
]);
2155 dst
[i
*4+0] = FLOAT_TO_INT(red
[i
]);
2156 dst
[i
*4+1] = FLOAT_TO_INT(green
[i
]);
2157 dst
[i
*4+2] = FLOAT_TO_INT(blue
[i
]);
2158 dst
[i
*4+3] = FLOAT_TO_INT(alpha
[i
]);
2163 dst
[i
*3+0] = FLOAT_TO_INT(blue
[i
]);
2164 dst
[i
*3+1] = FLOAT_TO_INT(green
[i
]);
2165 dst
[i
*3+2] = FLOAT_TO_INT(red
[i
]);
2170 dst
[i
*4+0] = FLOAT_TO_INT(blue
[i
]);
2171 dst
[i
*4+1] = FLOAT_TO_INT(green
[i
]);
2172 dst
[i
*4+2] = FLOAT_TO_INT(red
[i
]);
2173 dst
[i
*4+3] = FLOAT_TO_INT(alpha
[i
]);
2178 dst
[i
*4+0] = FLOAT_TO_INT(alpha
[i
]);
2179 dst
[i
*4+1] = FLOAT_TO_INT(blue
[i
]);
2180 dst
[i
*4+2] = FLOAT_TO_INT(green
[i
]);
2181 dst
[i
*4+3] = FLOAT_TO_INT(red
[i
]);
2185 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
2187 if (packing
->SwapBytes
) {
2188 gl_swap4( (GLuint
*) dst
, n
* comps
);
2194 GLfloat
*dst
= (GLfloat
*) destination
;
2214 dst
[i
] = luminance
[i
];
2216 case GL_LUMINANCE_ALPHA
:
2218 dst
[i
*2+0] = luminance
[i
];
2219 dst
[i
*2+1] = alpha
[i
];
2224 dst
[i
*3+0] = red
[i
];
2225 dst
[i
*3+1] = green
[i
];
2226 dst
[i
*3+2] = blue
[i
];
2231 dst
[i
*4+0] = red
[i
];
2232 dst
[i
*4+1] = green
[i
];
2233 dst
[i
*4+2] = blue
[i
];
2234 dst
[i
*4+3] = alpha
[i
];
2239 dst
[i
*3+0] = blue
[i
];
2240 dst
[i
*3+1] = green
[i
];
2241 dst
[i
*3+2] = red
[i
];
2246 dst
[i
*4+0] = blue
[i
];
2247 dst
[i
*4+1] = green
[i
];
2248 dst
[i
*4+2] = red
[i
];
2249 dst
[i
*4+3] = alpha
[i
];
2254 dst
[i
*4+0] = alpha
[i
];
2255 dst
[i
*4+1] = blue
[i
];
2256 dst
[i
*4+2] = green
[i
];
2257 dst
[i
*4+3] = red
[i
];
2261 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
2263 if (packing
->SwapBytes
) {
2264 gl_swap4( (GLuint
*) dst
, n
* comps
);
2268 case GL_UNSIGNED_BYTE_3_3_2
:
2269 if (format
== GL_RGB
) {
2270 GLubyte
*dst
= (GLubyte
*) destination
;
2272 dst
[i
] = (((GLint
) (red
[i
] * 7.0F
)) << 5)
2273 | (((GLint
) (green
[i
] * 7.0F
)) << 2)
2274 | (((GLint
) (blue
[i
] * 3.0F
)) );
2278 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2279 if (format
== GL_RGB
) {
2280 GLubyte
*dst
= (GLubyte
*) destination
;
2282 dst
[i
] = (((GLint
) (red
[i
] * 7.0F
)) )
2283 | (((GLint
) (green
[i
] * 7.0F
)) << 3)
2284 | (((GLint
) (blue
[i
] * 3.0F
)) << 5);
2288 case GL_UNSIGNED_SHORT_5_6_5
:
2289 if (format
== GL_RGB
) {
2290 GLushort
*dst
= (GLushort
*) destination
;
2292 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) << 11)
2293 | (((GLint
) (green
[i
] * 63.0F
)) << 5)
2294 | (((GLint
) (blue
[i
] * 31.0F
)) );
2298 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2299 if (format
== GL_RGB
) {
2300 GLushort
*dst
= (GLushort
*) destination
;
2302 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) )
2303 | (((GLint
) (green
[i
] * 63.0F
)) << 5)
2304 | (((GLint
) (blue
[i
] * 31.0F
)) << 11);
2308 case GL_UNSIGNED_SHORT_4_4_4_4
:
2309 if (format
== GL_RGB
) {
2310 GLushort
*dst
= (GLushort
*) destination
;
2312 dst
[i
] = (((GLint
) (red
[i
] * 15.0F
)) << 12)
2313 | (((GLint
) (green
[i
] * 15.0F
)) << 8)
2314 | (((GLint
) (blue
[i
] * 15.0F
)) << 4)
2315 | (((GLint
) (alpha
[i
] * 15.0F
)) );
2319 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2320 if (format
== GL_RGB
) {
2321 GLushort
*dst
= (GLushort
*) destination
;
2323 dst
[i
] = (((GLint
) (red
[i
] * 15.0F
)) )
2324 | (((GLint
) (green
[i
] * 15.0F
)) << 4)
2325 | (((GLint
) (blue
[i
] * 15.0F
)) << 8)
2326 | (((GLint
) (alpha
[i
] * 15.0F
)) << 12);
2330 case GL_UNSIGNED_SHORT_5_5_5_1
:
2331 if (format
== GL_RGB
) {
2332 GLushort
*dst
= (GLushort
*) destination
;
2334 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) << 11)
2335 | (((GLint
) (green
[i
] * 31.0F
)) << 6)
2336 | (((GLint
) (blue
[i
] * 31.0F
)) << 1)
2337 | (((GLint
) (alpha
[i
] * 1.0F
)) );
2341 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2342 if (format
== GL_RGB
) {
2343 GLushort
*dst
= (GLushort
*) destination
;
2345 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) )
2346 | (((GLint
) (green
[i
] * 31.0F
)) << 5)
2347 | (((GLint
) (blue
[i
] * 31.0F
)) << 10)
2348 | (((GLint
) (alpha
[i
] * 1.0F
)) << 15);
2352 case GL_UNSIGNED_INT_8_8_8_8
:
2353 if (format
== GL_RGBA
) {
2354 GLuint
*dst
= (GLuint
*) destination
;
2356 dst
[i
] = (((GLuint
) (red
[i
] * 255.0F
)) << 24)
2357 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
2358 | (((GLuint
) (blue
[i
] * 255.0F
)) << 8)
2359 | (((GLuint
) (alpha
[i
] * 255.0F
)) );
2362 else if (format
== GL_BGRA
) {
2363 GLuint
*dst
= (GLuint
*) destination
;
2365 dst
[i
] = (((GLuint
) (blue
[i
] * 255.0F
)) << 24)
2366 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
2367 | (((GLuint
) (red
[i
] * 255.0F
)) << 8)
2368 | (((GLuint
) (alpha
[i
] * 255.0F
)) );
2371 else if (format
== GL_ABGR_EXT
) {
2372 GLuint
*dst
= (GLuint
*) destination
;
2374 dst
[i
] = (((GLuint
) (alpha
[i
] * 255.0F
)) << 24)
2375 | (((GLuint
) (blue
[i
] * 255.0F
)) << 16)
2376 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
2377 | (((GLuint
) (red
[i
] * 255.0F
)) );
2381 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2382 if (format
== GL_RGBA
) {
2383 GLuint
*dst
= (GLuint
*) destination
;
2385 dst
[i
] = (((GLuint
) (red
[i
] * 255.0F
)) )
2386 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
2387 | (((GLuint
) (blue
[i
] * 255.0F
)) << 16)
2388 | (((GLuint
) (alpha
[i
] * 255.0F
)) << 24);
2391 else if (format
== GL_BGRA
) {
2392 GLuint
*dst
= (GLuint
*) destination
;
2394 dst
[i
] = (((GLuint
) (blue
[i
] * 255.0F
)) )
2395 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
2396 | (((GLuint
) (red
[i
] * 255.0F
)) << 16)
2397 | (((GLuint
) (alpha
[i
] * 255.0F
)) << 24);
2400 else if (format
== GL_ABGR_EXT
) {
2401 GLuint
*dst
= (GLuint
*) destination
;
2403 dst
[i
] = (((GLuint
) (alpha
[i
] * 255.0F
)) )
2404 | (((GLuint
) (blue
[i
] * 255.0F
)) << 8)
2405 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
2406 | (((GLuint
) (red
[i
] * 255.0F
)) << 24);
2410 case GL_UNSIGNED_INT_10_10_10_2
:
2411 if (format
== GL_RGBA
) {
2412 GLuint
*dst
= (GLuint
*) destination
;
2414 dst
[i
] = (((GLuint
) (red
[i
] * 1023.0F
)) << 22)
2415 | (((GLuint
) (green
[i
] * 1023.0F
)) << 12)
2416 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 2)
2417 | (((GLuint
) (alpha
[i
] * 3.0F
)) );
2420 else if (format
== GL_BGRA
) {
2421 GLuint
*dst
= (GLuint
*) destination
;
2423 dst
[i
] = (((GLuint
) (blue
[i
] * 1023.0F
)) << 22)
2424 | (((GLuint
) (green
[i
] * 1023.0F
)) << 12)
2425 | (((GLuint
) (red
[i
] * 1023.0F
)) << 2)
2426 | (((GLuint
) (alpha
[i
] * 3.0F
)) );
2429 else if (format
== GL_ABGR_EXT
) {
2430 GLuint
*dst
= (GLuint
*) destination
;
2432 dst
[i
] = (((GLuint
) (alpha
[i
] * 1023.0F
)) << 22)
2433 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 12)
2434 | (((GLuint
) (green
[i
] * 1023.0F
)) << 2)
2435 | (((GLuint
) (red
[i
] * 3.0F
)) );
2439 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2440 if (format
== GL_RGBA
) {
2441 GLuint
*dst
= (GLuint
*) destination
;
2443 dst
[i
] = (((GLuint
) (red
[i
] * 1023.0F
)) )
2444 | (((GLuint
) (green
[i
] * 1023.0F
)) << 10)
2445 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 20)
2446 | (((GLuint
) (alpha
[i
] * 3.0F
)) << 30);
2449 else if (format
== GL_BGRA
) {
2450 GLuint
*dst
= (GLuint
*) destination
;
2452 dst
[i
] = (((GLuint
) (blue
[i
] * 1023.0F
)) )
2453 | (((GLuint
) (green
[i
] * 1023.0F
)) << 10)
2454 | (((GLuint
) (red
[i
] * 1023.0F
)) << 20)
2455 | (((GLuint
) (alpha
[i
] * 3.0F
)) << 30);
2458 else if (format
== GL_ABGR_EXT
) {
2459 GLuint
*dst
= (GLuint
*) destination
;
2461 dst
[i
] = (((GLuint
) (alpha
[i
] * 1023.0F
)) )
2462 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 10)
2463 | (((GLuint
) (green
[i
] * 1023.0F
)) << 20)
2464 | (((GLuint
) (red
[i
] * 3.0F
)) << 30);
2469 gl_problem( ctx
, "bad type in gl_pack_rgba_span" );