1 /* $Id: image.c,v 1.6 1999/10/13 18:42:50 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
);
548 * Unpack a depth-buffer image storing values as GLshort, GLuint, or GLfloats.
549 * Input: type - datatype of src depth image
550 * Return pointer to a new gl_image structure.
552 * Notes: if the source image type is GLushort then the gl_image will
553 * also store GLushorts. If the src image type is GLuint then the gl_image
554 * will also store GLuints. For all other src image types the gl_image
555 * will store GLfloats. The integer cases can later be optimized.
557 static struct gl_image
*
558 unpack_depth_image( GLcontext
*ctx
, GLenum type
, GLint width
, GLint height
,
559 const GLvoid
*pixels
,
560 const struct gl_pixelstore_attrib
*packing
)
563 struct gl_image
*image
;
569 image
= alloc_image();
571 image
->Width
= width
;
572 image
->Height
= height
;
574 image
->Components
= 1;
575 image
->Format
= GL_DEPTH_COMPONENT
;
576 if (type
==GL_UNSIGNED_SHORT
) {
577 image
->Type
= GL_UNSIGNED_SHORT
;
578 image
->Data
= MALLOC( width
* height
* sizeof(GLushort
));
580 else if (type
==GL_UNSIGNED_INT
) {
581 image
->Type
= GL_UNSIGNED_INT
;
582 image
->Data
= MALLOC( width
* height
* sizeof(GLuint
));
585 image
->Type
= GL_FLOAT
;
586 image
->Data
= MALLOC( width
* height
* sizeof(GLfloat
));
596 fDst
= (GLfloat
*) image
->Data
;
597 sDst
= (GLushort
*) image
->Data
;
598 iDst
= (GLuint
*) image
->Data
;
600 for (i
=0;i
<height
;i
++) {
601 GLvoid
*src
= gl_pixel_addr_in_image( packing
, pixels
,
603 GL_DEPTH_COMPONENT
, type
,
611 assert(image
->Type
== GL_FLOAT
);
612 for (j
=0; j
<width
; j
++) {
613 *fDst
++ = BYTE_TO_FLOAT(((GLbyte
*)src
)[j
]);
616 case GL_UNSIGNED_BYTE
:
617 assert(image
->Type
== GL_FLOAT
);
618 for (j
=0; j
<width
; j
++) {
619 *fDst
++ = UBYTE_TO_FLOAT(((GLubyte
*)src
)[j
]);
622 case GL_UNSIGNED_SHORT
:
623 assert(image
->Type
== GL_UNSIGNED_SHORT
);
624 MEMCPY( sDst
, src
, width
* sizeof(GLushort
) );
625 if (packing
->SwapBytes
) {
626 gl_swap2( sDst
, width
);
631 assert(image
->Type
== GL_FLOAT
);
632 if (packing
->SwapBytes
) {
633 for (j
=0;j
<width
;j
++) {
634 GLshort value
= ((GLshort
*)src
)[j
];
635 value
= ((value
>> 8) & 0xff) | ((value
&0xff) << 8);
636 *fDst
++ = SHORT_TO_FLOAT(value
);
640 for (j
=0;j
<width
;j
++) {
641 *fDst
++ = SHORT_TO_FLOAT(((GLshort
*)src
)[j
]);
646 assert(image
->Type
== GL_FLOAT
);
647 if (packing
->SwapBytes
) {
648 for (j
=0;j
<width
;j
++) {
649 GLint value
= ((GLint
*)src
)[j
];
650 value
= ((value
>> 24) & 0x000000ff) |
651 ((value
>> 8) & 0x0000ff00) |
652 ((value
<< 8) & 0x00ff0000) |
653 ((value
<< 24) & 0xff000000);
654 *fDst
++ = INT_TO_FLOAT(value
);
658 for (j
=0;j
<width
;j
++) {
659 *fDst
++ = INT_TO_FLOAT(((GLint
*)src
)[j
]);
664 case GL_UNSIGNED_INT
:
665 assert(image
->Type
== GL_UNSIGNED_INT
);
666 MEMCPY( iDst
, src
, width
* sizeof(GLuint
) );
667 if (packing
->SwapBytes
) {
668 gl_swap4( iDst
, width
);
673 assert(image
->Type
== GL_FLOAT
);
674 MEMCPY( fDst
, src
, width
* sizeof(GLfloat
) );
675 if (packing
->SwapBytes
) {
676 gl_swap4( (GLuint
*) fDst
, width
);
681 gl_problem(ctx
, "unpack_depth_image type" );
692 * Unpack a stencil image. Store as GLubytes in a gl_image structure.
693 * Return: pointer to new gl_image structure.
695 static struct gl_image
*
696 unpack_stencil_image( GLcontext
*ctx
, GLenum type
, GLint width
, GLint height
,
697 const GLvoid
*pixels
,
698 const struct gl_pixelstore_attrib
*packing
)
700 struct gl_image
*image
;
704 assert(sizeof(GLstencil
) == sizeof(GLubyte
));
706 image
= alloc_image();
708 image
->Width
= width
;
709 image
->Height
= height
;
711 image
->Components
= 1;
712 image
->Format
= GL_STENCIL_INDEX
;
713 image
->Type
= GL_UNSIGNED_BYTE
;
714 image
->Data
= MALLOC( width
* height
* sizeof(GLubyte
));
723 dst
= (GLubyte
*) image
->Data
;
725 for (i
=0;i
<height
;i
++) {
726 GLvoid
*src
= gl_pixel_addr_in_image( packing
, pixels
,
728 GL_STENCIL_INDEX
, type
,
735 case GL_UNSIGNED_BYTE
:
737 MEMCPY( dst
, src
, width
* sizeof(GLubyte
) );
738 dst
+= width
* sizeof(GLubyte
);
740 case GL_UNSIGNED_SHORT
:
742 if (packing
->SwapBytes
) {
743 /* grab upper byte */
744 for (j
=0; j
< width
; j
++) {
745 *dst
++ = (((GLushort
*)src
)[j
] & 0xff00) >> 8;
749 for (j
=0; j
< width
; j
++) {
750 *dst
++ = (((GLushort
*)src
)[j
]) & 0xff;
755 if (packing
->SwapBytes
) {
756 /* grab upper byte */
757 for (j
=0; j
< width
; j
++) {
758 *dst
++ = (((GLuint
*)src
)[j
] & 0xff000000) >> 8;
762 for (j
=0; j
< width
; j
++) {
763 *dst
++ = (((GLuint
*)src
)[j
]) & 0xff;
767 case GL_UNSIGNED_INT
:
768 if (packing
->SwapBytes
) {
769 /* grab upper byte */
770 for (j
=0; j
< width
; j
++) {
771 *dst
++ = (((GLuint
*)src
)[j
] & 0xff000000) >> 8;
775 for (j
=0; j
< width
; j
++) {
776 *dst
++ = (((GLuint
*)src
)[j
]) & 0xff;
781 if (packing
->SwapBytes
) {
782 for (j
=0; j
< width
; j
++) {
784 GLint value
= ((GLuint
*)src
)[j
];
785 value
= ((value
& 0xff000000) >> 24)
786 | ((value
& 0x00ff0000) >> 8)
787 | ((value
& 0x0000ff00) << 8)
788 | ((value
& 0x000000ff) << 24);
789 fvalue
= *((GLfloat
*) &value
);
790 *dst
++ = ((GLint
) fvalue
) & 0xff;
794 for (j
=0; j
< width
; j
++) {
795 GLfloat fvalue
= ((GLfloat
*)src
)[j
];
796 *dst
++ = ((GLint
) fvalue
) & 0xff;
801 gl_problem(ctx
, "unpack_stencil_image type" );
812 * Unpack a bitmap, return a new gl_image struct.
814 static struct gl_image
*
815 unpack_bitmap( GLenum format
, GLint width
, GLint height
,
816 const GLvoid
*pixels
,
817 const struct gl_pixelstore_attrib
*packing
)
819 struct gl_image
*image
;
820 GLint bytes
, i
, width_in_bytes
;
821 GLubyte
*buffer
, *dst
;
823 assert(format
== GL_COLOR_INDEX
|| format
== GL_STENCIL_INDEX
);
825 /* Alloc dest storage */
826 bytes
= ((width
+7)/8 * height
);
827 if (bytes
>0 && pixels
!=NULL
) {
828 buffer
= (GLubyte
*) MALLOC( bytes
);
832 /* Copy/unpack pixel data to buffer */
833 width_in_bytes
= CEILING( width
, 8 );
835 for (i
=0; i
<height
; i
++) {
836 GLvoid
*src
= gl_pixel_addr_in_image( packing
, pixels
,
838 GL_COLOR_INDEX
, GL_BITMAP
,
844 MEMCPY( dst
, src
, width_in_bytes
);
845 dst
+= width_in_bytes
;
848 if (packing
->LsbFirst
) {
849 gl_flip_bytes( buffer
, bytes
);
853 /* a 'null' bitmap */
857 image
= alloc_image();
859 image
->Width
= width
;
860 image
->Height
= height
;
862 image
->Components
= 0;
863 image
->Format
= format
;
864 image
->Type
= GL_BITMAP
;
865 image
->Data
= buffer
;
879 * Unpack a 32x32 pixel polygon stipple from user memory using the
880 * current pixel unpack settings.
882 void gl_unpack_polygon_stipple( const GLcontext
*ctx
,
883 const GLubyte
*pattern
, GLuint dest
[32] )
886 for (i
= 0; i
< 32; i
++) {
887 GLubyte
*src
= (GLubyte
*) gl_pixel_addr_in_image( &ctx
->Unpack
, pattern
,
888 32, 32, GL_COLOR_INDEX
, GL_BITMAP
, 0, i
, 0 );
889 dest
[i
] = (src
[0] << 24)
895 /* Bit flipping within each byte */
896 if (ctx
->Unpack
.LsbFirst
) {
897 gl_flip_bytes( (GLubyte
*) dest
, 32 * 4 );
904 * Pack polygon stipple into user memory given current pixel packing
907 void gl_pack_polygon_stipple( const GLcontext
*ctx
,
908 const GLuint pattern
[32],
912 for (i
= 0; i
< 32; i
++) {
913 GLubyte
*dst
= (GLubyte
*) gl_pixel_addr_in_image( &ctx
->Pack
, dest
,
914 32, 32, GL_COLOR_INDEX
, GL_BITMAP
, 0, i
, 0 );
915 dst
[0] = (pattern
[i
] >> 24) & 0xff;
916 dst
[1] = (pattern
[i
] >> 16) & 0xff;
917 dst
[2] = (pattern
[i
] >> 8) & 0xff;
918 dst
[3] = (pattern
[i
] ) & 0xff;
920 /* Bit flipping within each byte */
921 if (ctx
->Pack
.LsbFirst
) {
922 gl_flip_bytes( (GLubyte
*) dst
, 4 );
930 * Unpack an RGBA or CI image and store it as unsigned bytes
932 static struct gl_image
*
933 unpack_ubyte_image( GLint width
, GLint height
,
934 GLint depth
, GLenum format
, const GLvoid
*pixels
,
935 const struct gl_pixelstore_attrib
*packing
)
937 struct gl_image
*image
;
938 GLint width_in_bytes
;
940 GLubyte
*buffer
, *dst
;
943 components
= gl_components_in_format( format
);
945 width_in_bytes
= width
* components
* sizeof(GLubyte
);
946 buffer
= (GLubyte
*) MALLOC( height
* width_in_bytes
* depth
);
951 /* Copy/unpack pixel data to buffer */
953 for (d
=0; d
<depth
; d
++ ) {
954 for (i
=0;i
<height
;i
++) {
955 GLubyte
*src
= (GLubyte
*) gl_pixel_addr_in_image( packing
,
956 pixels
, width
, height
, format
, GL_UNSIGNED_BYTE
,
962 MEMCPY( dst
, src
, width_in_bytes
);
963 dst
+= width_in_bytes
;
967 if (format
== GL_BGR
) {
968 /* swap order of every ubyte triplet from BGR to RGB */
969 for (i
=0; i
<width
*height
; i
++) {
970 GLubyte b
= buffer
[i
*3+0];
971 GLubyte r
= buffer
[i
*3+2];
976 else if (format
== GL_BGRA
) {
977 /* swap order of every ubyte quadruplet from BGRA to RGBA */
978 for (i
=0; i
<width
*height
; i
++) {
979 GLubyte b
= buffer
[i
*4+0];
980 GLubyte r
= buffer
[i
*4+2];
985 else if (format
== GL_ABGR_EXT
) {
986 /* swap order of every ubyte quadruplet from ABGR to RGBA */
987 for (i
=0; i
<width
*height
; i
++) {
988 GLubyte a
= buffer
[i
*4+0];
989 GLubyte b
= buffer
[i
*4+1];
990 GLubyte g
= buffer
[i
*4+2];
991 GLubyte r
= buffer
[i
*4+3];
1000 image
= alloc_image();
1002 image
->Width
= width
;
1003 image
->Height
= height
;
1004 image
->Depth
= depth
;
1005 image
->Components
= components
;
1006 if (format
== GL_BGR
)
1007 image
->Format
= GL_RGB
;
1008 else if (format
== GL_BGRA
)
1009 image
->Format
= GL_RGBA
;
1010 else if (format
== GL_ABGR_EXT
)
1011 image
->Format
= GL_RGBA
;
1013 image
->Format
= format
;
1014 image
->Type
= GL_UNSIGNED_BYTE
;
1015 image
->Data
= buffer
;
1016 image
->RefCount
= 0;
1028 * Unpack a color image storing image as GLfloats
1030 static struct gl_image
*
1031 unpack_float_image( GLcontext
*ctx
, GLint width
, GLint height
, GLint depth
,
1032 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1033 const struct gl_pixelstore_attrib
*packing
)
1035 struct gl_image
*image
;
1037 GLint elems_per_row
;
1040 GLboolean normalize
;
1042 assert(type
!= GL_BITMAP
);
1044 components
= gl_components_in_format( format
);
1045 assert(components
> 0); /* should have been caught earlier */
1047 if (!gl_is_legal_format_and_type( format
, type
)) {
1048 /* bad pixel type for format, make dummy image */
1049 image
= alloc_image();
1051 image
->Width
= width
;
1052 image
->Height
= height
;
1053 image
->Depth
= depth
;
1054 image
->Components
= components
;
1055 image
->Format
= format
;
1058 image
->RefCount
= 0;
1063 elems_per_row
= width
* components
;
1065 image
= alloc_image();
1067 image
->Width
= width
;
1068 image
->Height
= height
;
1069 image
->Depth
= depth
;
1070 image
->Components
= components
;
1071 if (format
== GL_BGR
)
1072 image
->Format
= GL_RGB
;
1073 else if (format
== GL_BGRA
)
1074 image
->Format
= GL_RGBA
;
1075 else if (format
== GL_ABGR_EXT
)
1076 image
->Format
= GL_RGBA
;
1078 image
->Format
= format
;
1079 image
->Type
= GL_FLOAT
;
1080 image
->Data
= MALLOC( elems_per_row
* height
* depth
* sizeof(GLfloat
));
1081 image
->RefCount
= 0;
1089 normalize
= (format
!= GL_COLOR_INDEX
) && (format
!= GL_STENCIL_INDEX
);
1091 dst
= (GLfloat
*) image
->Data
;
1093 for (d
=0; d
<depth
; d
++) {
1094 for (i
=0;i
<height
;i
++) {
1095 GLvoid
*src
= gl_pixel_addr_in_image( packing
, pixels
,
1104 case GL_UNSIGNED_BYTE
:
1106 GLubyte
*ubsrc
= (GLubyte
*) src
;
1108 for (j
=0;j
<elems_per_row
;j
++) {
1109 *dst
++ = UBYTE_TO_FLOAT(ubsrc
[j
]);
1113 for (j
=0;j
<elems_per_row
;j
++) {
1114 *dst
++ = (GLfloat
) ubsrc
[j
];
1121 for (j
=0;j
<elems_per_row
;j
++) {
1122 *dst
++ = BYTE_TO_FLOAT(((GLbyte
*)src
)[j
]);
1126 for (j
=0;j
<elems_per_row
;j
++) {
1127 *dst
++ = (GLfloat
) ((GLbyte
*)src
)[j
];
1131 case GL_UNSIGNED_SHORT
:
1132 if (packing
->SwapBytes
) {
1133 for (j
=0;j
<elems_per_row
;j
++) {
1134 GLushort value
= ((GLushort
*)src
)[j
];
1135 value
= ((value
>> 8) & 0xff) | ((value
&0xff) << 8);
1137 *dst
++ = USHORT_TO_FLOAT(value
);
1140 *dst
++ = (GLfloat
) value
;
1146 for (j
=0;j
<elems_per_row
;j
++) {
1147 *dst
++ = USHORT_TO_FLOAT(((GLushort
*)src
)[j
]);
1151 for (j
=0;j
<elems_per_row
;j
++) {
1152 *dst
++ = (GLfloat
) ((GLushort
*)src
)[j
];
1158 if (packing
->SwapBytes
) {
1159 for (j
=0;j
<elems_per_row
;j
++) {
1160 GLshort value
= ((GLshort
*)src
)[j
];
1161 value
= ((value
>> 8) & 0xff) | ((value
&0xff) << 8);
1163 *dst
++ = SHORT_TO_FLOAT(value
);
1166 *dst
++ = (GLfloat
) value
;
1172 for (j
=0;j
<elems_per_row
;j
++) {
1173 *dst
++ = SHORT_TO_FLOAT(((GLshort
*)src
)[j
]);
1177 for (j
=0;j
<elems_per_row
;j
++) {
1178 *dst
++ = (GLfloat
) ((GLshort
*)src
)[j
];
1183 case GL_UNSIGNED_INT
:
1184 if (packing
->SwapBytes
) {
1186 for (j
=0;j
<elems_per_row
;j
++) {
1187 value
= ((GLuint
*)src
)[j
];
1188 value
= ((value
& 0xff000000) >> 24)
1189 | ((value
& 0x00ff0000) >> 8)
1190 | ((value
& 0x0000ff00) << 8)
1191 | ((value
& 0x000000ff) << 24);
1193 *dst
++ = UINT_TO_FLOAT(value
);
1196 *dst
++ = (GLfloat
) value
;
1202 for (j
=0;j
<elems_per_row
;j
++) {
1203 *dst
++ = UINT_TO_FLOAT(((GLuint
*)src
)[j
]);
1207 for (j
=0;j
<elems_per_row
;j
++) {
1208 *dst
++ = (GLfloat
) ((GLuint
*)src
)[j
];
1214 if (packing
->SwapBytes
) {
1216 for (j
=0;j
<elems_per_row
;j
++) {
1217 value
= ((GLint
*)src
)[j
];
1218 value
= ((value
& 0xff000000) >> 24)
1219 | ((value
& 0x00ff0000) >> 8)
1220 | ((value
& 0x0000ff00) << 8)
1221 | ((value
& 0x000000ff) << 24);
1223 *dst
++ = INT_TO_FLOAT(value
);
1226 *dst
++ = (GLfloat
) value
;
1232 for (j
=0;j
<elems_per_row
;j
++) {
1233 *dst
++ = INT_TO_FLOAT(((GLint
*)src
)[j
]);
1237 for (j
=0;j
<elems_per_row
;j
++) {
1238 *dst
++ = (GLfloat
) ((GLint
*)src
)[j
];
1244 if (packing
->SwapBytes
) {
1246 for (j
=0;j
<elems_per_row
;j
++) {
1247 value
= ((GLuint
*)src
)[j
];
1248 value
= ((value
& 0xff000000) >> 24)
1249 | ((value
& 0x00ff0000) >> 8)
1250 | ((value
& 0x0000ff00) << 8)
1251 | ((value
& 0x000000ff) << 24);
1252 *dst
++ = *((GLfloat
*) &value
);
1256 MEMCPY( dst
, src
, elems_per_row
*sizeof(GLfloat
) );
1257 dst
+= elems_per_row
;
1260 case GL_UNSIGNED_BYTE_3_3_2
:
1262 GLubyte
*ubsrc
= (GLubyte
*) src
;
1263 for (j
=0;j
<width
;j
++) {
1264 GLubyte p
= ubsrc
[j
];
1265 *dst
++ = ((p
>> 5) ) * (1.0F
/ 7.0F
); /* red */
1266 *dst
++ = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
); /* green */
1267 *dst
++ = ((p
) & 0x3) * (1.0F
/ 3.0F
); /* blue */
1271 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1273 GLubyte
*ubsrc
= (GLubyte
*) src
;
1274 for (j
=0;j
<width
;j
++) {
1275 GLubyte p
= ubsrc
[j
];
1276 *dst
++ = ((p
) & 0x7) * (1.0F
/ 7.0F
); /* red */
1277 *dst
++ = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
); /* green */
1278 *dst
++ = ((p
>> 6) ) * (1.0F
/ 3.0F
); /* blue */
1282 case GL_UNSIGNED_SHORT_5_6_5
:
1284 GLushort
*ussrc
= (GLushort
*) src
;
1285 for (j
=0;j
<width
;j
++) {
1286 GLushort p
= ussrc
[j
];
1287 *dst
++ = ((p
>> 11) ) * (1.0F
/ 31.0F
); /* red */
1288 *dst
++ = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
); /* green */
1289 *dst
++ = ((p
) & 0x1f) * (1.0F
/ 31.0F
); /* blue */
1293 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1295 GLushort
*ussrc
= (GLushort
*) src
;
1296 for (j
=0;j
<width
;j
++) {
1297 GLushort p
= ussrc
[j
];
1298 *dst
++ = ((p
) & 0x1f) * (1.0F
/ 31.0F
); /* red */
1299 *dst
++ = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
); /* green */
1300 *dst
++ = ((p
>> 11) ) * (1.0F
/ 31.0F
); /* blue */
1304 case GL_UNSIGNED_SHORT_4_4_4_4
:
1306 GLushort
*ussrc
= (GLushort
*) src
;
1307 for (j
=0;j
<width
;j
++) {
1308 GLushort p
= ussrc
[j
];
1309 *dst
++ = ((p
>> 12) ) * (1.0F
/ 15.0F
); /* red */
1310 *dst
++ = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
); /* green */
1311 *dst
++ = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
); /* blue */
1312 *dst
++ = ((p
) & 0xf) * (1.0F
/ 15.0F
); /* alpha */
1316 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1318 GLushort
*ussrc
= (GLushort
*) src
;
1319 for (j
=0;j
<width
;j
++) {
1320 GLushort p
= ussrc
[j
];
1321 *dst
++ = ((p
) & 0xf) * (1.0F
/ 15.0F
); /* red */
1322 *dst
++ = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
); /* green */
1323 *dst
++ = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
); /* blue */
1324 *dst
++ = ((p
>> 12) ) * (1.0F
/ 15.0F
); /* alpha */
1328 case GL_UNSIGNED_SHORT_5_5_5_1
:
1330 GLushort
*ussrc
= (GLushort
*) src
;
1331 for (j
=0;j
<width
;j
++) {
1332 GLushort p
= ussrc
[j
];
1333 *dst
++ = ((p
>> 11) ) * (1.0F
/ 31.0F
); /* red */
1334 *dst
++ = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
); /* green */
1335 *dst
++ = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
); /* blue */
1336 *dst
++ = ((p
) & 0x1) * (1.0F
/ 1.0F
); /* alpha */
1340 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1342 GLushort
*ussrc
= (GLushort
*) src
;
1343 for (j
=0;j
<width
;j
++) {
1344 GLushort p
= ussrc
[j
];
1345 *dst
++ = ((p
) & 0x1f) * (1.0F
/ 31.0F
); /* red */
1346 *dst
++ = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
); /* green */
1347 *dst
++ = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
); /* blue */
1348 *dst
++ = ((p
>> 15) ) * (1.0F
/ 1.0F
); /* alpha */
1352 case GL_UNSIGNED_INT_8_8_8_8
:
1354 GLuint
*uisrc
= (GLuint
*) src
;
1355 for (j
=0;j
<width
;j
++) {
1356 GLuint p
= uisrc
[j
];
1357 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
1358 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
1359 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
1360 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
1364 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1366 GLuint
*uisrc
= (GLuint
*) src
;
1367 for (j
=0;j
<width
;j
++) {
1368 GLuint p
= uisrc
[j
];
1369 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
1370 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
1371 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
1372 *dst
++ = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
1376 case GL_UNSIGNED_INT_10_10_10_2
:
1378 GLuint
*uisrc
= (GLuint
*) src
;
1379 for (j
=0;j
<width
;j
++) {
1380 GLuint p
= uisrc
[j
];
1381 *dst
++ = ((p
>> 22) ) * (1.0F
/ 1023.0F
); /* r */
1382 *dst
++ = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
); /* g */
1383 *dst
++ = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
); /* b */
1384 *dst
++ = ((p
) & 0x3 ) * (1.0F
/ 3.0F
); /* a */
1388 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1390 GLuint
*uisrc
= (GLuint
*) src
;
1391 for (j
=0;j
<width
;j
++) {
1392 GLuint p
= uisrc
[j
];
1393 *dst
++ = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
); /* r*/
1394 *dst
++ = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
); /* g */
1395 *dst
++ = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
); /* b */
1396 *dst
++ = ((p
>> 30) ) * (1.0F
/ 3.0F
); /* a */
1401 gl_problem(ctx
, "unpack_float_image type" );
1407 if (format
== GL_BGR
) {
1408 /* swap order of every float triplet from BGR to RGBA */
1409 GLfloat
*buffer
= (GLfloat
*) image
->Data
;
1410 for (i
=0; i
<width
*height
*depth
; i
++) {
1411 GLfloat b
= buffer
[i
*3+0];
1412 GLfloat r
= buffer
[i
*3+2];
1417 else if (format
== GL_BGRA
) {
1418 /* swap order of every float quadruplet from BGRA to RGBA */
1419 GLfloat
*buffer
= (GLfloat
*) image
->Data
;
1420 for (i
=0; i
<width
*height
*depth
; i
++) {
1421 GLfloat b
= buffer
[i
*4+0];
1422 GLfloat r
= buffer
[i
*4+2];
1427 else if (format
== GL_ABGR_EXT
) {
1428 /* swap order of every float quadruplet from ABGR to RGBA */
1429 GLfloat
*buffer
= (GLfloat
*) image
->Data
;
1430 for (i
=0; i
<width
*height
*depth
; i
++) {
1431 GLfloat a
= buffer
[i
*4+0];
1432 GLfloat b
= buffer
[i
*4+1];
1433 GLfloat g
= buffer
[i
*4+2];
1434 GLfloat r
= buffer
[i
*4+3];
1448 * Unpack a bitmap image, using current glPixelStore parameters,
1449 * making a new gl_image.
1451 struct gl_image
*gl_unpack_bitmap( GLcontext
*ctx
,
1452 GLsizei width
, GLsizei height
,
1453 const GLubyte
*bitmap
,
1454 const struct gl_pixelstore_attrib
*packing
)
1456 return gl_unpack_image( ctx
, width
, height
,
1457 GL_COLOR_INDEX
, GL_BITMAP
, bitmap
, packing
);
1463 * Unpack a 2-D image from user's buffer. Return pointer to new
1466 * Input: width, height - size in pixels
1467 * format - format of incoming pixel data
1468 * type - datatype of incoming pixel data
1469 * pixels - pointer to unpacked image in user buffer
1471 struct gl_image
*gl_unpack_image( GLcontext
*ctx
,
1472 GLint width
, GLint height
,
1473 GLenum format
, GLenum type
,
1474 const GLvoid
*pixels
,
1475 const struct gl_pixelstore_attrib
*packing
)
1477 return gl_unpack_image3D( ctx
, width
, height
, 1,
1478 format
, type
, pixels
, packing
);
1484 * Unpack a 1, 2 or 3-D image from user-supplied address, returning a
1485 * pointer to a new gl_image struct.
1486 * This function is always called by a higher-level unpack function such
1487 * as gl_unpack_texsubimage() or gl_unpack_bitmap().
1489 * Input: width, height, depth - size in pixels
1490 * format - format of incoming pixel data
1491 * type - datatype of incoming pixel data
1492 * pixels - pointer to unpacked image.
1494 struct gl_image
*gl_unpack_image3D( GLcontext
*ctx
,
1495 GLint width
, GLint height
, GLint depth
,
1496 GLenum format
, GLenum type
,
1497 const GLvoid
*pixels
,
1498 const struct gl_pixelstore_attrib
*packing
)
1500 if (width
<= 0 || height
<= 0 || depth
<= 0) {
1501 return alloc_error_image(width
, height
, depth
, format
, type
);
1504 if (type
==GL_BITMAP
) {
1505 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1506 return alloc_error_image(width
, height
, depth
, format
, type
);
1509 return unpack_bitmap( format
, width
, height
, pixels
, packing
);
1512 else if (format
==GL_DEPTH_COMPONENT
) {
1513 /* TODO: pack as GLdepth values (GLushort or GLuint) */
1514 return unpack_depth_image( ctx
, type
, width
, height
, pixels
, packing
);
1516 else if (format
==GL_STENCIL_INDEX
) {
1517 /* TODO: pack as GLstencil (GLubyte or GLushort) */
1518 return unpack_stencil_image( ctx
, type
, width
, height
, pixels
, packing
);
1520 else if (type
==GL_UNSIGNED_BYTE
) {
1521 /* upack, convert to GLubytes */
1522 return unpack_ubyte_image( width
, height
, depth
, format
, pixels
, packing
);
1525 /* upack, convert to floats */
1526 return unpack_float_image( ctx
, width
, height
, depth
,
1527 format
, type
, pixels
, packing
);
1530 /* never get here */
1536 * Apply pixel-transfer operations (scale, bias, mapping) to a single row
1537 * of a gl_image. Put resulting color components into result array.
1539 void gl_scale_bias_map_image_data( const GLcontext
*ctx
,
1540 const struct gl_image
*image
,
1541 GLint row
, GLubyte result
[] )
1550 start
= row
* image
->Width
* image
->Components
;
1552 for (i
=0; i
< image
->Width
; i
++) {
1553 GLint pos
= start
+i
;
1554 GLfloat red
, green
, blue
, alpha
;
1555 if (image
->Type
== GL_UNSIGNED_BYTE
) {
1556 const GLubyte
*data
= (GLubyte
*) image
->Data
;
1557 switch (image
->Format
) {
1559 red
= data
[pos
] * (1.0F
/255.0F
);
1565 red
= data
[pos
*3+0] * (1.0F
/255.0F
);
1566 green
= data
[pos
*3+1] * (1.0F
/255.0F
);
1567 blue
= data
[pos
*3+2] * (1.0F
/255.0F
);
1571 gl_problem(ctx
, "bad image format in gl_scale...image_data");
1575 else if (image
->Type
== GL_FLOAT
) {
1576 const GLubyte
*data
= (GLubyte
*) image
->Data
;
1577 switch (image
->Format
) {
1585 red
= data
[pos
*3+0];
1586 green
= data
[pos
*3+1];
1587 blue
= data
[pos
*3+2];
1591 gl_problem(ctx
, "bad image format in gl_scale...image_data");
1596 gl_problem(ctx
, "Bad image type in gl_scale_...image_data");
1600 assert(red
>= 0.0 && red
<= 1.0);
1601 assert(green
>= 0.0 && green
<= 1.0);
1602 assert(blue
>= 0.0 && blue
<= 1.0);
1603 assert(alpha
>= 0.0 && alpha
<= 1.0);
1606 if (scale or bias) {
1615 result
[i
*4+0] = (GLubyte
) (red
* 255.0);
1616 result
[i
*4+1] = (GLubyte
) (green
* 255.0);
1617 result
[i
*4+2] = (GLubyte
) (blue
* 255.0);
1618 result
[i
*4+3] = (GLubyte
) (alpha
* 255.0);
1625 * Pack the given RGBA span into client memory at 'dest' address
1626 * in the given pixel format and type.
1627 * Optionally apply the enabled pixel transfer ops.
1628 * Pack into memory using the given packing params struct.
1629 * This is used by glReadPixels and glGetTexImage?D()
1630 * Input: ctx - the context
1631 * n - number of pixels in the span
1633 * format - dest packing format
1634 * type - dest packing datatype
1635 * destination - destination packing address
1636 * packing - pixel packing parameters
1637 * applyTransferOps - apply scale/bias/lookup-table ops?
1639 void gl_pack_rgba_span( const GLcontext
*ctx
,
1640 GLuint n
, CONST GLubyte rgba
[][4],
1641 GLenum format
, GLenum type
, GLvoid
*destination
,
1642 const struct gl_pixelstore_attrib
*packing
,
1643 GLboolean applyTransferOps
)
1645 /* Test for optimized case first */
1646 if (!ctx
->Pixel
.ScaleOrBiasRGBA
&& !ctx
->Pixel
.MapColorFlag
&&
1647 format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
1649 MEMCPY( destination
, rgba
, n
* 4 * sizeof(GLubyte
) );
1652 GLfloat red
[MAX_WIDTH
], green
[MAX_WIDTH
], blue
[MAX_WIDTH
];
1653 GLfloat alpha
[MAX_WIDTH
], luminance
[MAX_WIDTH
];
1654 GLfloat rscale
= 1.0F
/ 255.0F
;
1655 GLfloat gscale
= 1.0F
/ 255.0F
;
1656 GLfloat bscale
= 1.0F
/ 255.0F
;
1657 GLfloat ascale
= 1.0F
/ 255.0F
;
1660 assert( n
< MAX_WIDTH
);
1662 /* convert color components to floating point */
1664 red
[i
] = rgba
[i
][RCOMP
] * rscale
;
1665 green
[i
] = rgba
[i
][GCOMP
] * gscale
;
1666 blue
[i
] = rgba
[i
][BCOMP
] * bscale
;
1667 alpha
[i
] = rgba
[i
][ACOMP
] * ascale
;
1671 * Apply scale, bias and lookup-tables if enabled.
1673 if (applyTransferOps
) {
1674 if (ctx
->Pixel
.ScaleOrBiasRGBA
) {
1675 gl_scale_and_bias_color( ctx
, n
, red
, green
, blue
, alpha
);
1677 if (ctx
->Pixel
.MapColorFlag
) {
1678 gl_map_color( ctx
, n
, red
, green
, blue
, alpha
);
1682 if (format
==GL_LUMINANCE
|| format
==GL_LUMINANCE_ALPHA
) {
1684 GLfloat sum
= red
[i
] + green
[i
] + blue
[i
];
1685 luminance
[i
] = CLAMP( sum
, 0.0F
, 1.0F
);
1690 * Pack/store the pixels. Ugh! Lots of cases!!!
1693 case GL_UNSIGNED_BYTE
:
1695 GLubyte
*dst
= (GLubyte
*) destination
;
1699 dst
[i
] = FLOAT_TO_UBYTE(red
[i
]);
1703 dst
[i
] = FLOAT_TO_UBYTE(green
[i
]);
1707 dst
[i
] = FLOAT_TO_UBYTE(blue
[i
]);
1711 dst
[i
] = FLOAT_TO_UBYTE(alpha
[i
]);
1715 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1717 case GL_LUMINANCE_ALPHA
:
1719 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1720 dst
[i
*2+1] = FLOAT_TO_UBYTE(alpha
[i
]);
1725 dst
[i
*3+0] = FLOAT_TO_UBYTE(red
[i
]);
1726 dst
[i
*3+1] = FLOAT_TO_UBYTE(green
[i
]);
1727 dst
[i
*3+2] = FLOAT_TO_UBYTE(blue
[i
]);
1732 dst
[i
*4+0] = FLOAT_TO_UBYTE(red
[i
]);
1733 dst
[i
*4+1] = FLOAT_TO_UBYTE(green
[i
]);
1734 dst
[i
*4+2] = FLOAT_TO_UBYTE(blue
[i
]);
1735 dst
[i
*4+3] = FLOAT_TO_UBYTE(alpha
[i
]);
1740 dst
[i
*3+0] = FLOAT_TO_UBYTE(blue
[i
]);
1741 dst
[i
*3+1] = FLOAT_TO_UBYTE(green
[i
]);
1742 dst
[i
*3+2] = FLOAT_TO_UBYTE(red
[i
]);
1747 dst
[i
*4+0] = FLOAT_TO_UBYTE(blue
[i
]);
1748 dst
[i
*4+1] = FLOAT_TO_UBYTE(green
[i
]);
1749 dst
[i
*4+2] = FLOAT_TO_UBYTE(red
[i
]);
1750 dst
[i
*4+3] = FLOAT_TO_UBYTE(alpha
[i
]);
1755 dst
[i
*4+0] = FLOAT_TO_UBYTE(alpha
[i
]);
1756 dst
[i
*4+1] = FLOAT_TO_UBYTE(blue
[i
]);
1757 dst
[i
*4+2] = FLOAT_TO_UBYTE(green
[i
]);
1758 dst
[i
*4+3] = FLOAT_TO_UBYTE(red
[i
]);
1762 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
1768 GLbyte
*dst
= (GLbyte
*) destination
;
1772 dst
[i
] = FLOAT_TO_BYTE(red
[i
]);
1776 dst
[i
] = FLOAT_TO_BYTE(green
[i
]);
1780 dst
[i
] = FLOAT_TO_BYTE(blue
[i
]);
1784 dst
[i
] = FLOAT_TO_BYTE(alpha
[i
]);
1788 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1790 case GL_LUMINANCE_ALPHA
:
1792 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1793 dst
[i
*2+1] = FLOAT_TO_BYTE(alpha
[i
]);
1798 dst
[i
*3+0] = FLOAT_TO_BYTE(red
[i
]);
1799 dst
[i
*3+1] = FLOAT_TO_BYTE(green
[i
]);
1800 dst
[i
*3+2] = FLOAT_TO_BYTE(blue
[i
]);
1805 dst
[i
*4+0] = FLOAT_TO_BYTE(red
[i
]);
1806 dst
[i
*4+1] = FLOAT_TO_BYTE(green
[i
]);
1807 dst
[i
*4+2] = FLOAT_TO_BYTE(blue
[i
]);
1808 dst
[i
*4+3] = FLOAT_TO_BYTE(alpha
[i
]);
1813 dst
[i
*3+0] = FLOAT_TO_BYTE(blue
[i
]);
1814 dst
[i
*3+1] = FLOAT_TO_BYTE(green
[i
]);
1815 dst
[i
*3+2] = FLOAT_TO_BYTE(red
[i
]);
1820 dst
[i
*4+0] = FLOAT_TO_BYTE(blue
[i
]);
1821 dst
[i
*4+1] = FLOAT_TO_BYTE(green
[i
]);
1822 dst
[i
*4+2] = FLOAT_TO_BYTE(red
[i
]);
1823 dst
[i
*4+3] = FLOAT_TO_BYTE(alpha
[i
]);
1827 dst
[i
*4+0] = FLOAT_TO_BYTE(alpha
[i
]);
1828 dst
[i
*4+1] = FLOAT_TO_BYTE(blue
[i
]);
1829 dst
[i
*4+2] = FLOAT_TO_BYTE(green
[i
]);
1830 dst
[i
*4+3] = FLOAT_TO_BYTE(red
[i
]);
1834 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
1838 case GL_UNSIGNED_SHORT
:
1840 GLushort
*dst
= (GLushort
*) destination
;
1844 dst
[i
] = FLOAT_TO_USHORT(red
[i
]);
1848 dst
[i
] = FLOAT_TO_USHORT(green
[i
]);
1852 dst
[i
] = FLOAT_TO_USHORT(blue
[i
]);
1856 dst
[i
] = FLOAT_TO_USHORT(alpha
[i
]);
1860 dst
[i
] = FLOAT_TO_USHORT(luminance
[i
]);
1862 case GL_LUMINANCE_ALPHA
:
1864 dst
[i
*2+0] = FLOAT_TO_USHORT(luminance
[i
]);
1865 dst
[i
*2+1] = FLOAT_TO_USHORT(alpha
[i
]);
1870 dst
[i
*3+0] = FLOAT_TO_USHORT(red
[i
]);
1871 dst
[i
*3+1] = FLOAT_TO_USHORT(green
[i
]);
1872 dst
[i
*3+2] = FLOAT_TO_USHORT(blue
[i
]);
1877 dst
[i
*4+0] = FLOAT_TO_USHORT(red
[i
]);
1878 dst
[i
*4+1] = FLOAT_TO_USHORT(green
[i
]);
1879 dst
[i
*4+2] = FLOAT_TO_USHORT(blue
[i
]);
1880 dst
[i
*4+3] = FLOAT_TO_USHORT(alpha
[i
]);
1885 dst
[i
*3+0] = FLOAT_TO_USHORT(blue
[i
]);
1886 dst
[i
*3+1] = FLOAT_TO_USHORT(green
[i
]);
1887 dst
[i
*3+2] = FLOAT_TO_USHORT(red
[i
]);
1892 dst
[i
*4+0] = FLOAT_TO_USHORT(blue
[i
]);
1893 dst
[i
*4+1] = FLOAT_TO_USHORT(green
[i
]);
1894 dst
[i
*4+2] = FLOAT_TO_USHORT(red
[i
]);
1895 dst
[i
*4+3] = FLOAT_TO_USHORT(alpha
[i
]);
1900 dst
[i
*4+0] = FLOAT_TO_USHORT(alpha
[i
]);
1901 dst
[i
*4+1] = FLOAT_TO_USHORT(blue
[i
]);
1902 dst
[i
*4+2] = FLOAT_TO_USHORT(green
[i
]);
1903 dst
[i
*4+3] = FLOAT_TO_USHORT(red
[i
]);
1907 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
1909 if (packing
->SwapBytes
) {
1910 gl_swap2( (GLushort
*) dst
, n
);
1916 GLshort
*dst
= (GLshort
*) destination
;
1920 dst
[i
] = FLOAT_TO_SHORT(red
[i
]);
1924 dst
[i
] = FLOAT_TO_SHORT(green
[i
]);
1928 dst
[i
] = FLOAT_TO_SHORT(blue
[i
]);
1932 dst
[i
] = FLOAT_TO_SHORT(alpha
[i
]);
1936 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
1938 case GL_LUMINANCE_ALPHA
:
1940 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
1941 dst
[i
*2+1] = FLOAT_TO_SHORT(alpha
[i
]);
1946 dst
[i
*3+0] = FLOAT_TO_SHORT(red
[i
]);
1947 dst
[i
*3+1] = FLOAT_TO_SHORT(green
[i
]);
1948 dst
[i
*3+2] = FLOAT_TO_SHORT(blue
[i
]);
1953 dst
[i
*4+0] = FLOAT_TO_SHORT(red
[i
]);
1954 dst
[i
*4+1] = FLOAT_TO_SHORT(green
[i
]);
1955 dst
[i
*4+2] = FLOAT_TO_SHORT(blue
[i
]);
1956 dst
[i
*4+3] = FLOAT_TO_SHORT(alpha
[i
]);
1961 dst
[i
*3+0] = FLOAT_TO_SHORT(blue
[i
]);
1962 dst
[i
*3+1] = FLOAT_TO_SHORT(green
[i
]);
1963 dst
[i
*3+2] = FLOAT_TO_SHORT(red
[i
]);
1968 dst
[i
*4+0] = FLOAT_TO_SHORT(blue
[i
]);
1969 dst
[i
*4+1] = FLOAT_TO_SHORT(green
[i
]);
1970 dst
[i
*4+2] = FLOAT_TO_SHORT(red
[i
]);
1971 dst
[i
*4+3] = FLOAT_TO_SHORT(alpha
[i
]);
1975 dst
[i
*4+0] = FLOAT_TO_SHORT(alpha
[i
]);
1976 dst
[i
*4+1] = FLOAT_TO_SHORT(blue
[i
]);
1977 dst
[i
*4+2] = FLOAT_TO_SHORT(green
[i
]);
1978 dst
[i
*4+3] = FLOAT_TO_SHORT(red
[i
]);
1982 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
1984 if (packing
->SwapBytes
) {
1985 gl_swap2( (GLushort
*) dst
, n
);
1989 case GL_UNSIGNED_INT
:
1991 GLuint
*dst
= (GLuint
*) destination
;
1995 dst
[i
] = FLOAT_TO_UINT(red
[i
]);
1999 dst
[i
] = FLOAT_TO_UINT(green
[i
]);
2003 dst
[i
] = FLOAT_TO_UINT(blue
[i
]);
2007 dst
[i
] = FLOAT_TO_UINT(alpha
[i
]);
2011 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
2013 case GL_LUMINANCE_ALPHA
:
2015 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
2016 dst
[i
*2+1] = FLOAT_TO_UINT(alpha
[i
]);
2021 dst
[i
*3+0] = FLOAT_TO_UINT(red
[i
]);
2022 dst
[i
*3+1] = FLOAT_TO_UINT(green
[i
]);
2023 dst
[i
*3+2] = FLOAT_TO_UINT(blue
[i
]);
2028 dst
[i
*4+0] = FLOAT_TO_UINT(red
[i
]);
2029 dst
[i
*4+1] = FLOAT_TO_UINT(green
[i
]);
2030 dst
[i
*4+2] = FLOAT_TO_UINT(blue
[i
]);
2031 dst
[i
*4+3] = FLOAT_TO_UINT(alpha
[i
]);
2036 dst
[i
*3+0] = FLOAT_TO_UINT(blue
[i
]);
2037 dst
[i
*3+1] = FLOAT_TO_UINT(green
[i
]);
2038 dst
[i
*3+2] = FLOAT_TO_UINT(red
[i
]);
2043 dst
[i
*4+0] = FLOAT_TO_UINT(blue
[i
]);
2044 dst
[i
*4+1] = FLOAT_TO_UINT(green
[i
]);
2045 dst
[i
*4+2] = FLOAT_TO_UINT(red
[i
]);
2046 dst
[i
*4+3] = FLOAT_TO_UINT(alpha
[i
]);
2051 dst
[i
*4+0] = FLOAT_TO_UINT(alpha
[i
]);
2052 dst
[i
*4+1] = FLOAT_TO_UINT(blue
[i
]);
2053 dst
[i
*4+2] = FLOAT_TO_UINT(green
[i
]);
2054 dst
[i
*4+3] = FLOAT_TO_UINT(red
[i
]);
2058 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
2060 if (packing
->SwapBytes
) {
2061 gl_swap4( (GLuint
*) dst
, n
);
2067 GLint
*dst
= (GLint
*) destination
;
2071 dst
[i
] = FLOAT_TO_INT(red
[i
]);
2075 dst
[i
] = FLOAT_TO_INT(green
[i
]);
2079 dst
[i
] = FLOAT_TO_INT(blue
[i
]);
2083 dst
[i
] = FLOAT_TO_INT(alpha
[i
]);
2087 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
2089 case GL_LUMINANCE_ALPHA
:
2091 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
2092 dst
[i
*2+1] = FLOAT_TO_INT(alpha
[i
]);
2097 dst
[i
*3+0] = FLOAT_TO_INT(red
[i
]);
2098 dst
[i
*3+1] = FLOAT_TO_INT(green
[i
]);
2099 dst
[i
*3+2] = FLOAT_TO_INT(blue
[i
]);
2104 dst
[i
*4+0] = FLOAT_TO_INT(red
[i
]);
2105 dst
[i
*4+1] = FLOAT_TO_INT(green
[i
]);
2106 dst
[i
*4+2] = FLOAT_TO_INT(blue
[i
]);
2107 dst
[i
*4+3] = FLOAT_TO_INT(alpha
[i
]);
2112 dst
[i
*3+0] = FLOAT_TO_INT(blue
[i
]);
2113 dst
[i
*3+1] = FLOAT_TO_INT(green
[i
]);
2114 dst
[i
*3+2] = FLOAT_TO_INT(red
[i
]);
2119 dst
[i
*4+0] = FLOAT_TO_INT(blue
[i
]);
2120 dst
[i
*4+1] = FLOAT_TO_INT(green
[i
]);
2121 dst
[i
*4+2] = FLOAT_TO_INT(red
[i
]);
2122 dst
[i
*4+3] = FLOAT_TO_INT(alpha
[i
]);
2127 dst
[i
*4+0] = FLOAT_TO_INT(alpha
[i
]);
2128 dst
[i
*4+1] = FLOAT_TO_INT(blue
[i
]);
2129 dst
[i
*4+2] = FLOAT_TO_INT(green
[i
]);
2130 dst
[i
*4+3] = FLOAT_TO_INT(red
[i
]);
2134 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
2136 if (packing
->SwapBytes
) {
2137 gl_swap4( (GLuint
*) dst
, n
);
2143 GLfloat
*dst
= (GLfloat
*) destination
;
2163 dst
[i
] = luminance
[i
];
2165 case GL_LUMINANCE_ALPHA
:
2167 dst
[i
*2+0] = luminance
[i
];
2168 dst
[i
*2+1] = alpha
[i
];
2173 dst
[i
*3+0] = red
[i
];
2174 dst
[i
*3+1] = green
[i
];
2175 dst
[i
*3+2] = blue
[i
];
2180 dst
[i
*4+0] = red
[i
];
2181 dst
[i
*4+1] = green
[i
];
2182 dst
[i
*4+2] = blue
[i
];
2183 dst
[i
*4+3] = alpha
[i
];
2188 dst
[i
*3+0] = blue
[i
];
2189 dst
[i
*3+1] = green
[i
];
2190 dst
[i
*3+2] = red
[i
];
2195 dst
[i
*4+0] = blue
[i
];
2196 dst
[i
*4+1] = green
[i
];
2197 dst
[i
*4+2] = red
[i
];
2198 dst
[i
*4+3] = alpha
[i
];
2203 dst
[i
*4+0] = alpha
[i
];
2204 dst
[i
*4+1] = blue
[i
];
2205 dst
[i
*4+2] = green
[i
];
2206 dst
[i
*4+3] = red
[i
];
2210 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
2212 if (packing
->SwapBytes
) {
2213 gl_swap4( (GLuint
*) dst
, n
);
2217 case GL_UNSIGNED_BYTE_3_3_2
:
2218 if (format
== GL_RGB
) {
2219 GLubyte
*dst
= (GLubyte
*) destination
;
2221 dst
[i
] = (((GLint
) (red
[i
] * 7.0F
)) << 5)
2222 | (((GLint
) (green
[i
] * 7.0F
)) << 2)
2223 | (((GLint
) (blue
[i
] * 3.0F
)) );
2227 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2228 if (format
== GL_RGB
) {
2229 GLubyte
*dst
= (GLubyte
*) destination
;
2231 dst
[i
] = (((GLint
) (red
[i
] * 7.0F
)) )
2232 | (((GLint
) (green
[i
] * 7.0F
)) << 3)
2233 | (((GLint
) (blue
[i
] * 3.0F
)) << 5);
2237 case GL_UNSIGNED_SHORT_5_6_5
:
2238 if (format
== GL_RGB
) {
2239 GLushort
*dst
= (GLushort
*) destination
;
2241 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) << 11)
2242 | (((GLint
) (green
[i
] * 63.0F
)) << 5)
2243 | (((GLint
) (blue
[i
] * 31.0F
)) );
2247 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2248 if (format
== GL_RGB
) {
2249 GLushort
*dst
= (GLushort
*) destination
;
2251 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) )
2252 | (((GLint
) (green
[i
] * 63.0F
)) << 5)
2253 | (((GLint
) (blue
[i
] * 31.0F
)) << 11);
2257 case GL_UNSIGNED_SHORT_4_4_4_4
:
2258 if (format
== GL_RGB
) {
2259 GLushort
*dst
= (GLushort
*) destination
;
2261 dst
[i
] = (((GLint
) (red
[i
] * 15.0F
)) << 12)
2262 | (((GLint
) (green
[i
] * 15.0F
)) << 8)
2263 | (((GLint
) (blue
[i
] * 15.0F
)) << 4)
2264 | (((GLint
) (alpha
[i
] * 15.0F
)) );
2268 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2269 if (format
== GL_RGB
) {
2270 GLushort
*dst
= (GLushort
*) destination
;
2272 dst
[i
] = (((GLint
) (red
[i
] * 15.0F
)) )
2273 | (((GLint
) (green
[i
] * 15.0F
)) << 4)
2274 | (((GLint
) (blue
[i
] * 15.0F
)) << 8)
2275 | (((GLint
) (alpha
[i
] * 15.0F
)) << 12);
2279 case GL_UNSIGNED_SHORT_5_5_5_1
:
2280 if (format
== GL_RGB
) {
2281 GLushort
*dst
= (GLushort
*) destination
;
2283 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) << 11)
2284 | (((GLint
) (green
[i
] * 31.0F
)) << 6)
2285 | (((GLint
) (blue
[i
] * 31.0F
)) << 1)
2286 | (((GLint
) (alpha
[i
] * 1.0F
)) );
2290 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2291 if (format
== GL_RGB
) {
2292 GLushort
*dst
= (GLushort
*) destination
;
2294 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) )
2295 | (((GLint
) (green
[i
] * 31.0F
)) << 5)
2296 | (((GLint
) (blue
[i
] * 31.0F
)) << 10)
2297 | (((GLint
) (alpha
[i
] * 1.0F
)) << 15);
2301 case GL_UNSIGNED_INT_8_8_8_8
:
2302 if (format
== GL_RGBA
) {
2303 GLuint
*dst
= (GLuint
*) destination
;
2305 dst
[i
] = (((GLuint
) (red
[i
] * 255.0F
)) << 24)
2306 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
2307 | (((GLuint
) (blue
[i
] * 255.0F
)) << 8)
2308 | (((GLuint
) (alpha
[i
] * 255.0F
)) );
2311 else if (format
== GL_BGRA
) {
2312 GLuint
*dst
= (GLuint
*) destination
;
2314 dst
[i
] = (((GLuint
) (blue
[i
] * 255.0F
)) << 24)
2315 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
2316 | (((GLuint
) (red
[i
] * 255.0F
)) << 8)
2317 | (((GLuint
) (alpha
[i
] * 255.0F
)) );
2320 else if (format
== GL_ABGR_EXT
) {
2321 GLuint
*dst
= (GLuint
*) destination
;
2323 dst
[i
] = (((GLuint
) (alpha
[i
] * 255.0F
)) << 24)
2324 | (((GLuint
) (blue
[i
] * 255.0F
)) << 16)
2325 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
2326 | (((GLuint
) (red
[i
] * 255.0F
)) );
2330 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2331 if (format
== GL_RGBA
) {
2332 GLuint
*dst
= (GLuint
*) destination
;
2334 dst
[i
] = (((GLuint
) (red
[i
] * 255.0F
)) )
2335 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
2336 | (((GLuint
) (blue
[i
] * 255.0F
)) << 16)
2337 | (((GLuint
) (alpha
[i
] * 255.0F
)) << 24);
2340 else if (format
== GL_BGRA
) {
2341 GLuint
*dst
= (GLuint
*) destination
;
2343 dst
[i
] = (((GLuint
) (blue
[i
] * 255.0F
)) )
2344 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
2345 | (((GLuint
) (red
[i
] * 255.0F
)) << 16)
2346 | (((GLuint
) (alpha
[i
] * 255.0F
)) << 24);
2349 else if (format
== GL_ABGR_EXT
) {
2350 GLuint
*dst
= (GLuint
*) destination
;
2352 dst
[i
] = (((GLuint
) (alpha
[i
] * 255.0F
)) )
2353 | (((GLuint
) (blue
[i
] * 255.0F
)) << 8)
2354 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
2355 | (((GLuint
) (red
[i
] * 255.0F
)) << 24);
2359 case GL_UNSIGNED_INT_10_10_10_2
:
2360 if (format
== GL_RGBA
) {
2361 GLuint
*dst
= (GLuint
*) destination
;
2363 dst
[i
] = (((GLuint
) (red
[i
] * 1023.0F
)) << 22)
2364 | (((GLuint
) (green
[i
] * 1023.0F
)) << 12)
2365 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 2)
2366 | (((GLuint
) (alpha
[i
] * 3.0F
)) );
2369 else if (format
== GL_BGRA
) {
2370 GLuint
*dst
= (GLuint
*) destination
;
2372 dst
[i
] = (((GLuint
) (blue
[i
] * 1023.0F
)) << 22)
2373 | (((GLuint
) (green
[i
] * 1023.0F
)) << 12)
2374 | (((GLuint
) (red
[i
] * 1023.0F
)) << 2)
2375 | (((GLuint
) (alpha
[i
] * 3.0F
)) );
2378 else if (format
== GL_ABGR_EXT
) {
2379 GLuint
*dst
= (GLuint
*) destination
;
2381 dst
[i
] = (((GLuint
) (alpha
[i
] * 1023.0F
)) << 22)
2382 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 12)
2383 | (((GLuint
) (green
[i
] * 1023.0F
)) << 2)
2384 | (((GLuint
) (red
[i
] * 3.0F
)) );
2388 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2389 if (format
== GL_RGBA
) {
2390 GLuint
*dst
= (GLuint
*) destination
;
2392 dst
[i
] = (((GLuint
) (red
[i
] * 1023.0F
)) )
2393 | (((GLuint
) (green
[i
] * 1023.0F
)) << 10)
2394 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 20)
2395 | (((GLuint
) (alpha
[i
] * 3.0F
)) << 30);
2398 else if (format
== GL_BGRA
) {
2399 GLuint
*dst
= (GLuint
*) destination
;
2401 dst
[i
] = (((GLuint
) (blue
[i
] * 1023.0F
)) )
2402 | (((GLuint
) (green
[i
] * 1023.0F
)) << 10)
2403 | (((GLuint
) (red
[i
] * 1023.0F
)) << 20)
2404 | (((GLuint
) (alpha
[i
] * 3.0F
)) << 30);
2407 else if (format
== GL_ABGR_EXT
) {
2408 GLuint
*dst
= (GLuint
*) destination
;
2410 dst
[i
] = (((GLuint
) (alpha
[i
] * 1023.0F
)) )
2411 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 10)
2412 | (((GLuint
) (green
[i
] * 1023.0F
)) << 20)
2413 | (((GLuint
) (red
[i
] * 3.0F
)) << 30);
2418 gl_problem( ctx
, "bad type in gl_pack_rgba_span" );