1 /* $Id: image.c,v 1.69 2002/10/24 23:57:21 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 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.
32 #include "histogram.h"
40 * These are the image packing parameters for Mesa's internal images.
41 * That is, _mesa_unpack_image() returns image data in this format.
42 * When we execute image commands (glDrawPixels, glTexImage, etc)
43 * from within display lists we have to be sure to set the current
44 * unpacking params to these values!
46 const struct gl_pixelstore_attrib _mesa_native_packing
= {
53 GL_FALSE
, /* SwapBytes */
54 GL_FALSE
, /* LsbFirst */
55 GL_FALSE
, /* ClientStorage */
62 * Flip the 8 bits in each byte of the given array.
64 * XXX try this trick to flip bytes someday:
65 * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555);
66 * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333);
67 * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f);
70 flip_bytes( GLubyte
*p
, GLuint n
)
72 register GLuint i
, a
, b
;
75 b
= (GLuint
) p
[i
]; /* words are often faster than bytes */
76 a
= ((b
& 0x01) << 7) |
90 * Flip the order of the 2 bytes in each word in the given array.
93 _mesa_swap2( GLushort
*p
, GLuint n
)
98 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
105 * Flip the order of the 4 bytes in each word in the given array.
108 _mesa_swap4( GLuint
*p
, GLuint n
)
110 register GLuint i
, a
, b
;
115 | ((b
>> 8) & 0xff00)
116 | ((b
<< 8) & 0xff0000)
117 | ((b
<< 24) & 0xff000000);
126 * Return the size, in bytes, of the given GL datatype.
127 * Return 0 if GL_BITMAP.
128 * Return -1 if invalid type enum.
130 GLint
_mesa_sizeof_type( GLenum type
)
135 case GL_UNSIGNED_BYTE
:
136 return sizeof(GLubyte
);
138 return sizeof(GLbyte
);
139 case GL_UNSIGNED_SHORT
:
140 return sizeof(GLushort
);
142 return sizeof(GLshort
);
143 case GL_UNSIGNED_INT
:
144 return sizeof(GLuint
);
146 return sizeof(GLint
);
148 return sizeof(GLfloat
);
156 * Same as _mesa_sizeof_packed_type() but we also accept the
157 * packed pixel format datatypes.
159 GLint
_mesa_sizeof_packed_type( GLenum type
)
164 case GL_UNSIGNED_BYTE
:
165 return sizeof(GLubyte
);
167 return sizeof(GLbyte
);
168 case GL_UNSIGNED_SHORT
:
169 return sizeof(GLushort
);
171 return sizeof(GLshort
);
172 case GL_UNSIGNED_INT
:
173 return sizeof(GLuint
);
175 return sizeof(GLint
);
177 return sizeof(GLfloat
);
178 case GL_UNSIGNED_BYTE_3_3_2
:
179 return sizeof(GLubyte
);
180 case GL_UNSIGNED_BYTE_2_3_3_REV
:
181 return sizeof(GLubyte
);
182 case GL_UNSIGNED_SHORT_5_6_5
:
183 return sizeof(GLushort
);
184 case GL_UNSIGNED_SHORT_5_6_5_REV
:
185 return sizeof(GLushort
);
186 case GL_UNSIGNED_SHORT_4_4_4_4
:
187 return sizeof(GLushort
);
188 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
189 return sizeof(GLushort
);
190 case GL_UNSIGNED_SHORT_5_5_5_1
:
191 return sizeof(GLushort
);
192 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
193 return sizeof(GLushort
);
194 case GL_UNSIGNED_INT_8_8_8_8
:
195 return sizeof(GLuint
);
196 case GL_UNSIGNED_INT_8_8_8_8_REV
:
197 return sizeof(GLuint
);
198 case GL_UNSIGNED_INT_10_10_10_2
:
199 return sizeof(GLuint
);
200 case GL_UNSIGNED_INT_2_10_10_10_REV
:
201 return sizeof(GLuint
);
202 case GL_UNSIGNED_SHORT_8_8_MESA
:
203 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
204 return sizeof(GLushort
);
213 * Return the number of components in a GL enum pixel type.
214 * Return -1 if bad format.
216 GLint
_mesa_components_in_format( GLenum format
)
220 case GL_COLOR_INDEX1_EXT
:
221 case GL_COLOR_INDEX2_EXT
:
222 case GL_COLOR_INDEX4_EXT
:
223 case GL_COLOR_INDEX8_EXT
:
224 case GL_COLOR_INDEX12_EXT
:
225 case GL_COLOR_INDEX16_EXT
:
226 case GL_STENCIL_INDEX
:
227 case GL_DEPTH_COMPONENT
:
235 case GL_LUMINANCE_ALPHA
:
256 * Return bytes per pixel for given format and type
257 * Return -1 if bad format or type.
259 GLint
_mesa_bytes_per_pixel( GLenum format
, GLenum type
)
261 GLint comps
= _mesa_components_in_format( format
);
267 return 0; /* special case */
269 case GL_UNSIGNED_BYTE
:
270 return comps
* sizeof(GLubyte
);
272 case GL_UNSIGNED_SHORT
:
273 return comps
* sizeof(GLshort
);
275 case GL_UNSIGNED_INT
:
276 return comps
* sizeof(GLint
);
278 return comps
* sizeof(GLfloat
);
279 case GL_UNSIGNED_BYTE_3_3_2
:
280 case GL_UNSIGNED_BYTE_2_3_3_REV
:
281 if (format
== GL_RGB
|| format
== GL_BGR
)
282 return sizeof(GLubyte
);
284 return -1; /* error */
285 case GL_UNSIGNED_SHORT_5_6_5
:
286 case GL_UNSIGNED_SHORT_5_6_5_REV
:
287 if (format
== GL_RGB
|| format
== GL_BGR
)
288 return sizeof(GLushort
);
290 return -1; /* error */
291 case GL_UNSIGNED_SHORT_4_4_4_4
:
292 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
293 case GL_UNSIGNED_SHORT_5_5_5_1
:
294 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
295 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
296 return sizeof(GLushort
);
299 case GL_UNSIGNED_INT_8_8_8_8
:
300 case GL_UNSIGNED_INT_8_8_8_8_REV
:
301 case GL_UNSIGNED_INT_10_10_10_2
:
302 case GL_UNSIGNED_INT_2_10_10_10_REV
:
303 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
304 return sizeof(GLuint
);
307 case GL_UNSIGNED_SHORT_8_8_MESA
:
308 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
309 if (format
== GL_YCBCR_MESA
)
310 return sizeof(GLushort
);
320 * Test if the given pixel format and type are legal.
321 * Return GL_TRUE for legal, GL_FALSE for illegal.
324 _mesa_is_legal_format_and_type( GLenum format
, GLenum type
)
328 case GL_STENCIL_INDEX
:
332 case GL_UNSIGNED_BYTE
:
334 case GL_UNSIGNED_SHORT
:
336 case GL_UNSIGNED_INT
:
348 case GL_LUMINANCE_ALPHA
:
349 case GL_DEPTH_COMPONENT
:
352 case GL_UNSIGNED_BYTE
:
354 case GL_UNSIGNED_SHORT
:
356 case GL_UNSIGNED_INT
:
366 case GL_UNSIGNED_BYTE
:
368 case GL_UNSIGNED_SHORT
:
370 case GL_UNSIGNED_INT
:
372 case GL_UNSIGNED_BYTE_3_3_2
:
373 case GL_UNSIGNED_BYTE_2_3_3_REV
:
374 case GL_UNSIGNED_SHORT_5_6_5
:
375 case GL_UNSIGNED_SHORT_5_6_5_REV
:
385 case GL_UNSIGNED_BYTE
:
387 case GL_UNSIGNED_SHORT
:
389 case GL_UNSIGNED_INT
:
391 case GL_UNSIGNED_SHORT_4_4_4_4
:
392 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
393 case GL_UNSIGNED_SHORT_5_5_5_1
:
394 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
395 case GL_UNSIGNED_INT_8_8_8_8
:
396 case GL_UNSIGNED_INT_8_8_8_8_REV
:
397 case GL_UNSIGNED_INT_10_10_10_2
:
398 case GL_UNSIGNED_INT_2_10_10_10_REV
:
404 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
405 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
418 * Return the address of a pixel in an image (actually a volume).
419 * Pixel unpacking/packing parameters are observed according to 'packing'.
420 * Input: image - start of image data
421 * width, height - size of image
422 * format - image format
423 * type - pixel component type
424 * packing - the pixelstore attributes
425 * img - which image in the volume (0 for 1D or 2D images)
426 * row, column - location of pixel in the image
427 * Return: address of pixel at (image,row,column) in image or NULL if error.
430 _mesa_image_address( const struct gl_pixelstore_attrib
*packing
,
431 const GLvoid
*image
, GLsizei width
,
432 GLsizei height
, GLenum format
, GLenum type
,
433 GLint img
, GLint row
, GLint column
)
435 GLint alignment
; /* 1, 2 or 4 */
436 GLint pixels_per_row
;
437 GLint rows_per_image
;
440 GLint skipimages
; /* for 3-D volume images */
443 alignment
= packing
->Alignment
;
444 if (packing
->RowLength
> 0) {
445 pixels_per_row
= packing
->RowLength
;
448 pixels_per_row
= width
;
450 if (packing
->ImageHeight
> 0) {
451 rows_per_image
= packing
->ImageHeight
;
454 rows_per_image
= height
;
456 skiprows
= packing
->SkipRows
;
457 skippixels
= packing
->SkipPixels
;
458 skipimages
= packing
->SkipImages
;
460 if (type
==GL_BITMAP
) {
462 GLint comp_per_pixel
; /* components per pixel */
463 GLint bytes_per_comp
; /* bytes per component */
465 GLint bytes_per_image
;
467 /* Compute bytes per component */
468 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
469 if (bytes_per_comp
<0) {
473 /* Compute number of components per pixel */
474 comp_per_pixel
= _mesa_components_in_format( format
);
475 if (comp_per_pixel
<0 && type
!= GL_BITMAP
) {
479 bytes_per_row
= alignment
480 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
482 bytes_per_image
= bytes_per_row
* rows_per_image
;
484 pixel_addr
= (GLubyte
*) image
485 + (skipimages
+ img
) * bytes_per_image
486 + (skiprows
+ row
) * bytes_per_row
487 + (skippixels
+ column
) / 8;
490 /* Non-BITMAP data */
491 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
494 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
496 /* The pixel type and format should have been error checked earlier */
497 assert(bytes_per_pixel
> 0);
499 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
500 remainder
= bytes_per_row
% alignment
;
502 bytes_per_row
+= (alignment
- remainder
);
504 ASSERT(bytes_per_row
% alignment
== 0);
506 bytes_per_image
= bytes_per_row
* rows_per_image
;
508 if (packing
->Invert
) {
509 /* set pixel_addr to the last row */
510 topOfImage
= bytes_per_row
* (height
- 1);
511 bytes_per_row
= -bytes_per_row
;
517 /* compute final pixel address */
518 pixel_addr
= (GLubyte
*) image
519 + (skipimages
+ img
) * bytes_per_image
521 + (skiprows
+ row
) * bytes_per_row
522 + (skippixels
+ column
) * bytes_per_pixel
;
525 return (GLvoid
*) pixel_addr
;
531 * Compute the stride between image rows (in bytes) for the given
532 * pixel packing parameters and image width, format and type.
535 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
536 GLint width
, GLenum format
, GLenum type
)
539 if (type
== GL_BITMAP
) {
542 if (packing
->RowLength
== 0) {
543 bytes
= (width
+ 7) / 8;
546 bytes
= (packing
->RowLength
+ 7) / 8;
548 if (packing
->Invert
) {
549 /* negate the bytes per row (negative row stride) */
555 /* Non-BITMAP data */
556 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
557 GLint bytesPerRow
, remainder
;
558 if (bytesPerPixel
<= 0)
559 return -1; /* error */
560 if (packing
->RowLength
== 0) {
561 bytesPerRow
= bytesPerPixel
* width
;
564 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
566 remainder
= bytesPerRow
% packing
->Alignment
;
568 bytesPerRow
+= (packing
->Alignment
- remainder
);
570 bytesPerRow
= -bytesPerRow
;
578 * Compute the stride between images in a 3D texture (in bytes) for the given
579 * pixel packing parameters and image width, format and type.
582 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
583 GLint width
, GLint height
,
584 GLenum format
, GLenum type
)
587 ASSERT(type
!= GL_BITMAP
);
590 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
591 GLint bytesPerRow
, bytesPerImage
, remainder
;
593 if (bytesPerPixel
<= 0)
594 return -1; /* error */
595 if (packing
->RowLength
== 0) {
596 bytesPerRow
= bytesPerPixel
* width
;
599 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
601 remainder
= bytesPerRow
% packing
->Alignment
;
603 bytesPerRow
+= (packing
->Alignment
- remainder
);
605 if (packing
->ImageHeight
== 0)
606 bytesPerImage
= bytesPerRow
* height
;
608 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
610 return bytesPerImage
;
618 * Unpack a 32x32 pixel polygon stipple from user memory using the
619 * current pixel unpack settings.
622 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
623 const struct gl_pixelstore_attrib
*unpacking
)
625 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap( 32, 32, pattern
, unpacking
);
627 /* Convert pattern from GLubytes to GLuints and handle big/little
632 for (i
= 0; i
< 32; i
++) {
633 dest
[i
] = (p
[0] << 24)
646 * Pack polygon stipple into user memory given current pixel packing
650 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
651 const struct gl_pixelstore_attrib
*packing
)
653 /* Convert pattern from GLuints to GLubytes to handle big/little
654 * endian differences.
658 for (i
= 0; i
< 32; i
++) {
659 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
660 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
661 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
662 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
665 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
670 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
671 * order with row alignment = 1 byte.
674 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
675 const struct gl_pixelstore_attrib
*packing
)
677 GLint bytes
, row
, width_in_bytes
;
678 GLubyte
*buffer
, *dst
;
683 /* Alloc dest storage */
684 bytes
= ((width
+ 7) / 8 * height
);
685 buffer
= (GLubyte
*) MALLOC( bytes
);
690 width_in_bytes
= CEILING( width
, 8 );
692 for (row
= 0; row
< height
; row
++) {
693 const GLubyte
*src
= (const GLubyte
*)
694 _mesa_image_address(packing
, pixels
, width
, height
,
695 GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0);
701 if (packing
->SkipPixels
== 0) {
702 MEMCPY( dst
, src
, width_in_bytes
);
703 if (packing
->LsbFirst
) {
704 flip_bytes( dst
, width_in_bytes
);
708 /* handling SkipPixels is a bit tricky (no pun intended!) */
710 if (packing
->LsbFirst
) {
711 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
712 GLubyte dstMask
= 128;
713 const GLubyte
*s
= src
;
716 for (i
= 0; i
< width
; i
++) {
720 if (srcMask
== 128) {
725 srcMask
= srcMask
<< 1;
733 dstMask
= dstMask
>> 1;
738 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
739 GLubyte dstMask
= 128;
740 const GLubyte
*s
= src
;
743 for (i
= 0; i
< width
; i
++) {
752 srcMask
= srcMask
>> 1;
760 dstMask
= dstMask
>> 1;
765 dst
+= width_in_bytes
;
776 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
777 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
779 GLint row
, width_in_bytes
;
785 width_in_bytes
= CEILING( width
, 8 );
787 for (row
= 0; row
< height
; row
++) {
788 GLubyte
*dst
= (GLubyte
*) _mesa_image_address( packing
, dest
,
789 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
793 if (packing
->SkipPixels
== 0) {
794 MEMCPY( dst
, src
, width_in_bytes
);
795 if (packing
->LsbFirst
) {
796 flip_bytes( dst
, width_in_bytes
);
800 /* handling SkipPixels is a bit tricky (no pun intended!) */
802 if (packing
->LsbFirst
) {
803 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
804 GLubyte dstMask
= 128;
805 const GLubyte
*s
= src
;
808 for (i
= 0; i
< width
; i
++) {
812 if (srcMask
== 128) {
817 srcMask
= srcMask
<< 1;
825 dstMask
= dstMask
>> 1;
830 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
831 GLubyte dstMask
= 128;
832 const GLubyte
*s
= src
;
835 for (i
= 0; i
< width
; i
++) {
844 srcMask
= srcMask
>> 1;
852 dstMask
= dstMask
>> 1;
857 src
+= width_in_bytes
;
864 * Used to pack an array [][4] of RGBA GLchan colors as specified
865 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
866 * glGetConvolutionFilter(), etc.
869 _mesa_pack_float_rgba_span( GLcontext
*ctx
,
870 GLuint n
, CONST GLfloat rgbaIn
[][4],
871 GLenum dstFormat
, GLenum dstType
,
873 const struct gl_pixelstore_attrib
*dstPacking
,
876 const GLint comps
= _mesa_components_in_format(dstFormat
);
877 GLfloat luminance
[MAX_WIDTH
];
882 /* make copy of incoming data */
883 DEFMARRAY(GLfloat
, rgbaCopy
, MAX_WIDTH
, 4); /* mac 32k limitation */
884 CHECKARRAY(rgbaCopy
, return); /* mac 32k limitation */
886 for (i
= 0; i
< n
; i
++) {
887 rgbaCopy
[i
][0] = rgbaIn
[i
][0];
888 rgbaCopy
[i
][1] = rgbaIn
[i
][1];
889 rgbaCopy
[i
][2] = rgbaIn
[i
][2];
890 rgbaCopy
[i
][3] = rgbaIn
[i
][3];
893 rgba
= (GLfloat (*)[4]) rgbaCopy
;
896 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
897 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
,
898 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
899 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
900 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
901 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
903 /* color map lookup */
904 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
905 _mesa_map_rgba( ctx
, n
, rgba
);
907 /* GL_COLOR_TABLE lookup */
908 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
909 _mesa_lookup_rgba(&ctx
->ColorTable
, n
, rgba
);
912 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
913 /* this has to be done in the calling code */
915 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
916 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
917 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
,
918 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
919 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
920 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
921 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
922 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
923 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
924 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
925 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
927 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
928 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
929 _mesa_lookup_rgba(&ctx
->PostConvolutionColorTable
, n
, rgba
);
931 /* color matrix transform */
932 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
933 _mesa_transform_rgba(ctx
, n
, rgba
);
935 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
936 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
937 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
939 /* update histogram count */
940 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
941 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
944 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
945 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
946 if (ctx
->MinMax
.Sink
) {
947 UNDEFARRAY(rgbaCopy
); /* mac 32k limitation */
951 UNDEFARRAY(rgbaCopy
); /* mac 32k limitation */
954 /* use incoming data, not a copy */
955 rgba
= (GLfloat (*)[4]) rgbaIn
;
958 /* XXX clamp rgba to [0,1]? */
961 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
962 for (i
= 0; i
< n
; i
++) {
963 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
964 #if CHAN_TYPE == GL_FLOAT
967 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
973 * Pack/store the pixels. Ugh! Lots of cases!!!
976 case GL_UNSIGNED_BYTE
:
978 GLubyte
*dst
= (GLubyte
*) dstAddr
;
982 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
986 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
990 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
994 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
998 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1000 case GL_LUMINANCE_ALPHA
:
1002 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1003 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1008 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1009 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1010 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1015 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1016 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1017 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1018 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1023 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1024 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1025 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1030 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1031 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1032 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1033 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1038 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1039 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1040 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1041 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1045 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1051 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1052 switch (dstFormat
) {
1055 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1059 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1063 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1067 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1071 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1073 case GL_LUMINANCE_ALPHA
:
1075 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1076 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1081 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1082 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1083 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1088 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1089 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1090 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1091 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1096 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1097 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1098 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1103 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1104 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1105 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1106 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1110 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1111 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1112 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1113 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1117 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1121 case GL_UNSIGNED_SHORT
:
1123 GLushort
*dst
= (GLushort
*) dstAddr
;
1124 switch (dstFormat
) {
1127 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1131 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1135 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1139 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1143 dst
[i
] = FLOAT_TO_USHORT(luminance
[i
]);
1145 case GL_LUMINANCE_ALPHA
:
1147 dst
[i
*2+0] = FLOAT_TO_USHORT(luminance
[i
]);
1148 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1153 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1154 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1155 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1160 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1161 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1162 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1163 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1168 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1169 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1170 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1175 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1176 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1177 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1178 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1183 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1184 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1185 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1186 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1190 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1192 if (dstPacking
->SwapBytes
) {
1193 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1199 GLshort
*dst
= (GLshort
*) dstAddr
;
1200 switch (dstFormat
) {
1203 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1207 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1211 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1215 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1219 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
1221 case GL_LUMINANCE_ALPHA
:
1223 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
1224 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1229 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1230 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1231 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1236 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1237 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1238 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1239 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1244 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1245 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1246 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1251 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1252 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1253 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1254 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1258 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1259 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1260 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1261 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1265 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1267 if (dstPacking
->SwapBytes
) {
1268 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1272 case GL_UNSIGNED_INT
:
1274 GLuint
*dst
= (GLuint
*) dstAddr
;
1275 switch (dstFormat
) {
1278 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1282 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1286 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1290 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1294 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
1296 case GL_LUMINANCE_ALPHA
:
1298 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
1299 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1304 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1305 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1306 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1311 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1312 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1313 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1314 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1319 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1320 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1321 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1326 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1327 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1328 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1329 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1334 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1335 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1336 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1337 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1341 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1343 if (dstPacking
->SwapBytes
) {
1344 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1350 GLint
*dst
= (GLint
*) dstAddr
;
1351 switch (dstFormat
) {
1354 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1358 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1362 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1366 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1370 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1372 case GL_LUMINANCE_ALPHA
:
1374 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1375 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1380 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1381 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1382 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1387 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1388 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1389 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1390 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1395 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1396 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1397 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1402 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1403 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1404 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1405 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1410 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1411 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1412 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1413 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1417 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1419 if (dstPacking
->SwapBytes
) {
1420 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1426 GLfloat
*dst
= (GLfloat
*) dstAddr
;
1427 switch (dstFormat
) {
1430 dst
[i
] = rgba
[i
][RCOMP
];
1434 dst
[i
] = rgba
[i
][GCOMP
];
1438 dst
[i
] = rgba
[i
][BCOMP
];
1442 dst
[i
] = rgba
[i
][ACOMP
];
1446 dst
[i
] = luminance
[i
];
1448 case GL_LUMINANCE_ALPHA
:
1450 dst
[i
*2+0] = luminance
[i
];
1451 dst
[i
*2+1] = rgba
[i
][ACOMP
];
1456 dst
[i
*3+0] = rgba
[i
][RCOMP
];
1457 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1458 dst
[i
*3+2] = rgba
[i
][BCOMP
];
1463 dst
[i
*4+0] = rgba
[i
][RCOMP
];
1464 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1465 dst
[i
*4+2] = rgba
[i
][BCOMP
];
1466 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1471 dst
[i
*3+0] = rgba
[i
][BCOMP
];
1472 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1473 dst
[i
*3+2] = rgba
[i
][RCOMP
];
1478 dst
[i
*4+0] = rgba
[i
][BCOMP
];
1479 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1480 dst
[i
*4+2] = rgba
[i
][RCOMP
];
1481 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1486 dst
[i
*4+0] = rgba
[i
][ACOMP
];
1487 dst
[i
*4+1] = rgba
[i
][BCOMP
];
1488 dst
[i
*4+2] = rgba
[i
][GCOMP
];
1489 dst
[i
*4+3] = rgba
[i
][RCOMP
];
1493 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1495 if (dstPacking
->SwapBytes
) {
1496 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1500 case GL_UNSIGNED_BYTE_3_3_2
:
1501 if (dstFormat
== GL_RGB
) {
1502 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1504 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
1505 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
1506 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
1510 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1511 if (dstFormat
== GL_RGB
) {
1512 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1514 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
1515 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
1516 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 5);
1520 case GL_UNSIGNED_SHORT_5_6_5
:
1521 if (dstFormat
== GL_RGB
) {
1522 GLushort
*dst
= (GLushort
*) dstAddr
;
1524 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1525 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1526 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
1530 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1531 if (dstFormat
== GL_RGB
) {
1532 GLushort
*dst
= (GLushort
*) dstAddr
;
1534 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1535 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1536 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
1540 case GL_UNSIGNED_SHORT_4_4_4_4
:
1541 if (dstFormat
== GL_RGBA
) {
1542 GLushort
*dst
= (GLushort
*) dstAddr
;
1544 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
1545 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1546 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1547 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1550 else if (dstFormat
== GL_BGRA
) {
1551 GLushort
*dst
= (GLushort
*) dstAddr
;
1553 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 12)
1554 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1555 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 4)
1556 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1559 else if (dstFormat
== GL_ABGR_EXT
) {
1560 GLushort
*dst
= (GLushort
*) dstAddr
;
1562 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 4)
1563 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1564 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 12)
1565 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) );
1569 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1570 if (dstFormat
== GL_RGBA
) {
1571 GLushort
*dst
= (GLushort
*) dstAddr
;
1573 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
1574 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1575 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1576 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1579 else if (dstFormat
== GL_BGRA
) {
1580 GLushort
*dst
= (GLushort
*) dstAddr
;
1582 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) )
1583 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1584 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 8)
1585 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1588 else if (dstFormat
== GL_ABGR_EXT
) {
1589 GLushort
*dst
= (GLushort
*) dstAddr
;
1591 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) )
1592 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1593 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1594 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12);
1598 case GL_UNSIGNED_SHORT_5_5_5_1
:
1599 if (dstFormat
== GL_RGBA
) {
1600 GLushort
*dst
= (GLushort
*) dstAddr
;
1602 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1603 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1604 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
1605 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1608 else if (dstFormat
== GL_BGRA
) {
1609 GLushort
*dst
= (GLushort
*) dstAddr
;
1611 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11)
1612 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1613 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 1)
1614 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1617 else if (dstFormat
== GL_ABGR_EXT
) {
1618 GLushort
*dst
= (GLushort
*) dstAddr
;
1620 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) << 11)
1621 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 6)
1622 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 1)
1623 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) );
1627 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1628 if (dstFormat
== GL_RGBA
) {
1629 GLushort
*dst
= (GLushort
*) dstAddr
;
1631 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1632 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1633 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
1634 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1637 else if (dstFormat
== GL_BGRA
) {
1638 GLushort
*dst
= (GLushort
*) dstAddr
;
1640 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) )
1641 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1642 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 10)
1643 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1646 else if (dstFormat
== GL_ABGR_EXT
) {
1647 GLushort
*dst
= (GLushort
*) dstAddr
;
1649 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) )
1650 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 5)
1651 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 10)
1652 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) << 15);
1656 case GL_UNSIGNED_INT_8_8_8_8
:
1657 if (dstFormat
== GL_RGBA
) {
1658 GLuint
*dst
= (GLuint
*) dstAddr
;
1660 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
1661 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1662 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1663 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1666 else if (dstFormat
== GL_BGRA
) {
1667 GLuint
*dst
= (GLuint
*) dstAddr
;
1669 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
1670 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1671 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
1672 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1675 else if (dstFormat
== GL_ABGR_EXT
) {
1676 GLuint
*dst
= (GLuint
*) dstAddr
;
1678 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
1679 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1680 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1681 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
1685 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1686 if (dstFormat
== GL_RGBA
) {
1687 GLuint
*dst
= (GLuint
*) dstAddr
;
1689 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
1690 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1691 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1692 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1695 else if (dstFormat
== GL_BGRA
) {
1696 GLuint
*dst
= (GLuint
*) dstAddr
;
1698 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
1699 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1700 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
1701 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1704 else if (dstFormat
== GL_ABGR_EXT
) {
1705 GLuint
*dst
= (GLuint
*) dstAddr
;
1707 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
1708 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1709 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1710 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
1714 case GL_UNSIGNED_INT_10_10_10_2
:
1715 if (dstFormat
== GL_RGBA
) {
1716 GLuint
*dst
= (GLuint
*) dstAddr
;
1718 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
1719 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1720 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
1721 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1724 else if (dstFormat
== GL_BGRA
) {
1725 GLuint
*dst
= (GLuint
*) dstAddr
;
1727 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
1728 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1729 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
1730 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1733 else if (dstFormat
== GL_ABGR_EXT
) {
1734 GLuint
*dst
= (GLuint
*) dstAddr
;
1736 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
1737 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
1738 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
1739 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
1743 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1744 if (dstFormat
== GL_RGBA
) {
1745 GLuint
*dst
= (GLuint
*) dstAddr
;
1747 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
1748 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1749 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
1750 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1753 else if (dstFormat
== GL_BGRA
) {
1754 GLuint
*dst
= (GLuint
*) dstAddr
;
1756 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
1757 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1758 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
1759 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1762 else if (dstFormat
== GL_ABGR_EXT
) {
1763 GLuint
*dst
= (GLuint
*) dstAddr
;
1765 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
1766 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
1767 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
1768 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
1773 _mesa_problem(ctx
, "bad type in _mesa_pack_float_rgba_span");
1780 * Pack the given RGBA span into client memory at 'dest' address
1781 * in the given pixel format and type.
1782 * Optionally apply the enabled pixel transfer ops.
1783 * Pack into memory using the given packing params struct.
1784 * This is used by glReadPixels and glGetTexImage?D()
1785 * Input: ctx - the context
1786 * n - number of pixels in the span
1788 * format - dest packing format
1789 * type - dest packing datatype
1790 * destination - destination packing address
1791 * packing - pixel packing parameters
1792 * transferOps - bitmask of IMAGE_*_BIT operations to apply
1795 _mesa_pack_rgba_span( GLcontext
*ctx
,
1796 GLuint n
, CONST GLchan srcRgba
[][4],
1797 GLenum dstFormat
, GLenum dstType
,
1799 const struct gl_pixelstore_attrib
*dstPacking
,
1802 ASSERT((ctx
->NewState
& _NEW_PIXEL
) == 0 || transferOps
== 0);
1804 /* Test for optimized case first */
1805 if (transferOps
== 0 && dstFormat
== GL_RGBA
&& dstType
== CHAN_TYPE
) {
1806 /* common simple case */
1807 MEMCPY(dstAddr
, srcRgba
, n
* 4 * sizeof(GLchan
));
1809 else if (transferOps
== 0 && dstFormat
== GL_RGB
&& dstType
== CHAN_TYPE
) {
1810 /* common simple case */
1812 GLchan
*dest
= (GLchan
*) dstAddr
;
1813 for (i
= 0; i
< n
; i
++) {
1814 dest
[0] = srcRgba
[i
][RCOMP
];
1815 dest
[1] = srcRgba
[i
][GCOMP
];
1816 dest
[2] = srcRgba
[i
][BCOMP
];
1820 else if (transferOps
== 0 && dstFormat
== GL_RGBA
&& dstType
== GL_UNSIGNED_BYTE
) {
1821 /* common simple case */
1823 GLubyte
*dest
= (GLubyte
*) dstAddr
;
1824 for (i
= 0; i
< n
; i
++) {
1825 dest
[0] = CHAN_TO_UBYTE(srcRgba
[i
][RCOMP
]);
1826 dest
[1] = CHAN_TO_UBYTE(srcRgba
[i
][GCOMP
]);
1827 dest
[2] = CHAN_TO_UBYTE(srcRgba
[i
][BCOMP
]);
1828 dest
[3] = CHAN_TO_UBYTE(srcRgba
[i
][ACOMP
]);
1833 /* general solution */
1835 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
1836 CHECKARRAY(rgba
, return); /* mac 32k limitation */
1838 assert(n
<= MAX_WIDTH
);
1839 /* convert color components to floating point */
1841 rgba
[i
][RCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][RCOMP
]);
1842 rgba
[i
][GCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][GCOMP
]);
1843 rgba
[i
][BCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][BCOMP
]);
1844 rgba
[i
][ACOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][ACOMP
]);
1846 _mesa_pack_float_rgba_span(ctx
, n
, (const GLfloat (*)[4]) rgba
,
1847 dstFormat
, dstType
, dstAddr
,
1848 dstPacking
, transferOps
);
1849 UNDEFARRAY(rgba
); /* mac 32k limitation */
1854 #define SWAP2BYTE(VALUE) \
1856 GLubyte *bytes = (GLubyte *) &(VALUE); \
1857 GLubyte tmp = bytes[0]; \
1858 bytes[0] = bytes[1]; \
1862 #define SWAP4BYTE(VALUE) \
1864 GLubyte *bytes = (GLubyte *) &(VALUE); \
1865 GLubyte tmp = bytes[0]; \
1866 bytes[0] = bytes[3]; \
1869 bytes[1] = bytes[2]; \
1875 extract_uint_indexes(GLuint n
, GLuint indexes
[],
1876 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
1877 const struct gl_pixelstore_attrib
*unpack
)
1879 assert(srcFormat
== GL_COLOR_INDEX
);
1881 ASSERT(srcType
== GL_BITMAP
||
1882 srcType
== GL_UNSIGNED_BYTE
||
1883 srcType
== GL_BYTE
||
1884 srcType
== GL_UNSIGNED_SHORT
||
1885 srcType
== GL_SHORT
||
1886 srcType
== GL_UNSIGNED_INT
||
1887 srcType
== GL_INT
||
1888 srcType
== GL_FLOAT
);
1893 GLubyte
*ubsrc
= (GLubyte
*) src
;
1894 if (unpack
->LsbFirst
) {
1895 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
1897 for (i
= 0; i
< n
; i
++) {
1898 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
1909 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
1911 for (i
= 0; i
< n
; i
++) {
1912 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
1924 case GL_UNSIGNED_BYTE
:
1927 const GLubyte
*s
= (const GLubyte
*) src
;
1928 for (i
= 0; i
< n
; i
++)
1935 const GLbyte
*s
= (const GLbyte
*) src
;
1936 for (i
= 0; i
< n
; i
++)
1940 case GL_UNSIGNED_SHORT
:
1943 const GLushort
*s
= (const GLushort
*) src
;
1944 if (unpack
->SwapBytes
) {
1945 for (i
= 0; i
< n
; i
++) {
1946 GLushort value
= s
[i
];
1952 for (i
= 0; i
< n
; i
++)
1960 const GLshort
*s
= (const GLshort
*) src
;
1961 if (unpack
->SwapBytes
) {
1962 for (i
= 0; i
< n
; i
++) {
1963 GLshort value
= s
[i
];
1969 for (i
= 0; i
< n
; i
++)
1974 case GL_UNSIGNED_INT
:
1977 const GLuint
*s
= (const GLuint
*) src
;
1978 if (unpack
->SwapBytes
) {
1979 for (i
= 0; i
< n
; i
++) {
1980 GLuint value
= s
[i
];
1986 for (i
= 0; i
< n
; i
++)
1994 const GLint
*s
= (const GLint
*) src
;
1995 if (unpack
->SwapBytes
) {
1996 for (i
= 0; i
< n
; i
++) {
2003 for (i
= 0; i
< n
; i
++)
2011 const GLfloat
*s
= (const GLfloat
*) src
;
2012 if (unpack
->SwapBytes
) {
2013 for (i
= 0; i
< n
; i
++) {
2014 GLfloat value
= s
[i
];
2016 indexes
[i
] = (GLuint
) value
;
2020 for (i
= 0; i
< n
; i
++)
2021 indexes
[i
] = (GLuint
) s
[i
];
2026 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2034 * This function extracts floating point RGBA values from arbitrary
2035 * image data. srcFormat and srcType are the format and type parameters
2036 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2038 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2039 * implements the "Conversion to floating point", "Conversion to RGB",
2040 * and "Final Expansion to RGBA" operations.
2042 * Args: n - number of pixels
2043 * rgba - output colors
2044 * srcFormat - format of incoming data
2045 * srcType - datatype of incoming data
2046 * src - source data pointer
2047 * swapBytes - perform byteswapping of incoming data?
2050 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2051 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2052 GLboolean swapBytes
)
2054 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2056 GLint rComp
, bComp
, gComp
, aComp
;
2058 ASSERT(srcFormat
== GL_RED
||
2059 srcFormat
== GL_GREEN
||
2060 srcFormat
== GL_BLUE
||
2061 srcFormat
== GL_ALPHA
||
2062 srcFormat
== GL_LUMINANCE
||
2063 srcFormat
== GL_LUMINANCE_ALPHA
||
2064 srcFormat
== GL_INTENSITY
||
2065 srcFormat
== GL_RGB
||
2066 srcFormat
== GL_BGR
||
2067 srcFormat
== GL_RGBA
||
2068 srcFormat
== GL_BGRA
||
2069 srcFormat
== GL_ABGR_EXT
);
2071 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2072 srcType
== GL_BYTE
||
2073 srcType
== GL_UNSIGNED_SHORT
||
2074 srcType
== GL_SHORT
||
2075 srcType
== GL_UNSIGNED_INT
||
2076 srcType
== GL_INT
||
2077 srcType
== GL_FLOAT
||
2078 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2079 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2080 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2081 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2082 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2083 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2084 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2085 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2086 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2087 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2088 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2089 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2091 rComp
= gComp
= bComp
= aComp
= -1;
2093 switch (srcFormat
) {
2096 greenIndex
= blueIndex
= alphaIndex
= -1;
2101 redIndex
= blueIndex
= alphaIndex
= -1;
2106 redIndex
= greenIndex
= alphaIndex
= -1;
2110 redIndex
= greenIndex
= blueIndex
= -1;
2115 redIndex
= greenIndex
= blueIndex
= 0;
2119 case GL_LUMINANCE_ALPHA
:
2120 redIndex
= greenIndex
= blueIndex
= 0;
2125 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
2176 _mesa_problem(NULL
, "bad srcFormat in extract float data");
2181 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
2182 if ((INDEX) < 0) { \
2184 for (i = 0; i < n; i++) { \
2185 rgba[i][CHANNEL] = DEFAULT; \
2188 else if (swapBytes) { \
2189 const TYPE *s = (const TYPE *) src; \
2191 for (i = 0; i < n; i++) { \
2192 TYPE value = s[INDEX]; \
2193 if (sizeof(TYPE) == 2) { \
2196 else if (sizeof(TYPE) == 4) { \
2199 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
2204 const TYPE *s = (const TYPE *) src; \
2206 for (i = 0; i < n; i++) { \
2207 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
2213 case GL_UNSIGNED_BYTE
:
2214 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2215 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2216 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2217 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2220 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2221 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2222 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2223 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
2225 case GL_UNSIGNED_SHORT
:
2226 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2227 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2228 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2229 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
2232 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2233 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2234 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2235 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
2237 case GL_UNSIGNED_INT
:
2238 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2239 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2240 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2241 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
2244 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2245 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2246 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2247 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
2250 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2251 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2252 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2253 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
2255 case GL_UNSIGNED_BYTE_3_3_2
:
2257 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2259 for (i
= 0; i
< n
; i
++) {
2260 GLubyte p
= ubsrc
[i
];
2261 rgba
[i
][RCOMP
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
2262 rgba
[i
][GCOMP
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
2263 rgba
[i
][BCOMP
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
2264 rgba
[i
][ACOMP
] = 1.0F
;
2268 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2270 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2272 for (i
= 0; i
< n
; i
++) {
2273 GLubyte p
= ubsrc
[i
];
2274 rgba
[i
][RCOMP
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
2275 rgba
[i
][GCOMP
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
2276 rgba
[i
][BCOMP
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
2277 rgba
[i
][ACOMP
] = 1.0F
;
2281 case GL_UNSIGNED_SHORT_5_6_5
:
2283 const GLushort
*ussrc
= (const GLushort
*) src
;
2285 for (i
= 0; i
< n
; i
++) {
2286 GLushort p
= ussrc
[i
];
2288 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2289 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2290 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2291 rgba
[i
][ACOMP
] = 1.0F
;
2295 const GLushort
*ussrc
= (const GLushort
*) src
;
2297 for (i
= 0; i
< n
; i
++) {
2298 GLushort p
= ussrc
[i
];
2299 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2300 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2301 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2302 rgba
[i
][ACOMP
] = 1.0F
;
2306 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2308 const GLushort
*ussrc
= (const GLushort
*) src
;
2310 for (i
= 0; i
< n
; i
++) {
2311 GLushort p
= ussrc
[i
];
2313 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2314 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2315 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2316 rgba
[i
][ACOMP
] = 1.0F
;
2320 const GLushort
*ussrc
= (const GLushort
*) src
;
2322 for (i
= 0; i
< n
; i
++) {
2323 GLushort p
= ussrc
[i
];
2324 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2325 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2326 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2327 rgba
[i
][ACOMP
] = 1.0F
;
2331 case GL_UNSIGNED_SHORT_4_4_4_4
:
2333 const GLushort
*ussrc
= (const GLushort
*) src
;
2335 for (i
= 0; i
< n
; i
++) {
2336 GLushort p
= ussrc
[i
];
2338 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2339 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2340 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2341 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2345 const GLushort
*ussrc
= (const GLushort
*) src
;
2347 for (i
= 0; i
< n
; i
++) {
2348 GLushort p
= ussrc
[i
];
2349 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2350 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2351 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2352 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2356 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2358 const GLushort
*ussrc
= (const GLushort
*) src
;
2360 for (i
= 0; i
< n
; i
++) {
2361 GLushort p
= ussrc
[i
];
2363 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2364 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2365 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2366 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2370 const GLushort
*ussrc
= (const GLushort
*) src
;
2372 for (i
= 0; i
< n
; i
++) {
2373 GLushort p
= ussrc
[i
];
2374 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2375 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2376 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2377 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2381 case GL_UNSIGNED_SHORT_5_5_5_1
:
2383 const GLushort
*ussrc
= (const GLushort
*) src
;
2385 for (i
= 0; i
< n
; i
++) {
2386 GLushort p
= ussrc
[i
];
2388 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2389 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2390 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2391 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2395 const GLushort
*ussrc
= (const GLushort
*) src
;
2397 for (i
= 0; i
< n
; i
++) {
2398 GLushort p
= ussrc
[i
];
2399 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2400 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2401 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2402 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2406 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2408 const GLushort
*ussrc
= (const GLushort
*) src
;
2410 for (i
= 0; i
< n
; i
++) {
2411 GLushort p
= ussrc
[i
];
2413 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2414 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2415 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2416 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2420 const GLushort
*ussrc
= (const GLushort
*) src
;
2422 for (i
= 0; i
< n
; i
++) {
2423 GLushort p
= ussrc
[i
];
2424 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2425 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2426 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2427 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2431 case GL_UNSIGNED_INT_8_8_8_8
:
2433 const GLuint
*uisrc
= (const GLuint
*) src
;
2435 for (i
= 0; i
< n
; i
++) {
2436 GLuint p
= uisrc
[i
];
2437 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2438 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2439 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2440 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2444 const GLuint
*uisrc
= (const GLuint
*) src
;
2446 for (i
= 0; i
< n
; i
++) {
2447 GLuint p
= uisrc
[i
];
2448 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2449 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2450 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2451 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2455 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2457 const GLuint
*uisrc
= (const GLuint
*) src
;
2459 for (i
= 0; i
< n
; i
++) {
2460 GLuint p
= uisrc
[i
];
2461 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2462 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2463 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2464 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2468 const GLuint
*uisrc
= (const GLuint
*) src
;
2470 for (i
= 0; i
< n
; i
++) {
2471 GLuint p
= uisrc
[i
];
2472 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2473 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2474 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2475 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2479 case GL_UNSIGNED_INT_10_10_10_2
:
2481 const GLuint
*uisrc
= (const GLuint
*) src
;
2483 for (i
= 0; i
< n
; i
++) {
2484 GLuint p
= uisrc
[i
];
2486 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2487 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2488 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2489 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2493 const GLuint
*uisrc
= (const GLuint
*) src
;
2495 for (i
= 0; i
< n
; i
++) {
2496 GLuint p
= uisrc
[i
];
2497 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2498 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2499 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2500 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2504 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2506 const GLuint
*uisrc
= (const GLuint
*) src
;
2508 for (i
= 0; i
< n
; i
++) {
2509 GLuint p
= uisrc
[i
];
2511 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2512 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2513 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2514 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2518 const GLuint
*uisrc
= (const GLuint
*) src
;
2520 for (i
= 0; i
< n
; i
++) {
2521 GLuint p
= uisrc
[i
];
2522 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2523 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2524 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2525 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2530 _mesa_problem(NULL
, "bad srcType in extract float data");
2538 * Unpack a row of color image data from a client buffer according to
2539 * the pixel unpacking parameters.
2540 * Return GLubyte values in the specified dest image format.
2541 * This is (or will be) used by glDrawPixels and glTexImage?D().
2542 * Input: ctx - the context
2543 * n - number of pixels in the span
2544 * dstFormat - format of destination color array
2545 * dest - the destination color array
2546 * srcFormat - source image format
2547 * srcType - source image datatype
2548 * source - source image pointer
2549 * srcPacking - pixel unpacking parameters
2550 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
2552 * XXX perhaps expand this to process whole images someday.
2555 _mesa_unpack_chan_color_span( GLcontext
*ctx
,
2556 GLuint n
, GLenum dstFormat
, GLchan dest
[],
2557 GLenum srcFormat
, GLenum srcType
,
2558 const GLvoid
*source
,
2559 const struct gl_pixelstore_attrib
*srcPacking
,
2560 GLuint transferOps
)
2562 ASSERT(dstFormat
== GL_ALPHA
||
2563 dstFormat
== GL_LUMINANCE
||
2564 dstFormat
== GL_LUMINANCE_ALPHA
||
2565 dstFormat
== GL_INTENSITY
||
2566 dstFormat
== GL_RGB
||
2567 dstFormat
== GL_RGBA
||
2568 dstFormat
== GL_COLOR_INDEX
);
2570 ASSERT(srcFormat
== GL_RED
||
2571 srcFormat
== GL_GREEN
||
2572 srcFormat
== GL_BLUE
||
2573 srcFormat
== GL_ALPHA
||
2574 srcFormat
== GL_LUMINANCE
||
2575 srcFormat
== GL_LUMINANCE_ALPHA
||
2576 srcFormat
== GL_INTENSITY
||
2577 srcFormat
== GL_RGB
||
2578 srcFormat
== GL_BGR
||
2579 srcFormat
== GL_RGBA
||
2580 srcFormat
== GL_BGRA
||
2581 srcFormat
== GL_ABGR_EXT
||
2582 srcFormat
== GL_COLOR_INDEX
);
2584 ASSERT(srcType
== GL_BITMAP
||
2585 srcType
== GL_UNSIGNED_BYTE
||
2586 srcType
== GL_BYTE
||
2587 srcType
== GL_UNSIGNED_SHORT
||
2588 srcType
== GL_SHORT
||
2589 srcType
== GL_UNSIGNED_INT
||
2590 srcType
== GL_INT
||
2591 srcType
== GL_FLOAT
||
2592 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2593 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2594 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2595 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2596 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2597 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2598 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2599 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2600 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2601 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2602 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2603 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2605 /* Try simple cases first */
2606 if (transferOps
== 0 ){
2607 if (srcType
== CHAN_TYPE
) {
2608 if (dstFormat
== GL_RGBA
) {
2609 if (srcFormat
== GL_RGBA
) {
2610 MEMCPY( dest
, source
, n
* 4 * sizeof(GLchan
) );
2613 else if (srcFormat
== GL_RGB
) {
2615 const GLchan
*src
= (const GLchan
*) source
;
2617 for (i
= 0; i
< n
; i
++) {
2628 else if (dstFormat
== GL_RGB
) {
2629 if (srcFormat
== GL_RGB
) {
2630 MEMCPY( dest
, source
, n
* 3 * sizeof(GLchan
) );
2633 else if (srcFormat
== GL_RGBA
) {
2635 const GLchan
*src
= (const GLchan
*) source
;
2637 for (i
= 0; i
< n
; i
++) {
2647 else if (dstFormat
== srcFormat
) {
2648 GLint comps
= _mesa_components_in_format(srcFormat
);
2650 MEMCPY( dest
, source
, n
* comps
* sizeof(GLchan
) );
2655 * Common situation, loading 8bit RGBA/RGB source images
2656 * into 16/32 bit destination. (OSMesa16/32)
2658 else if (srcType
== GL_UNSIGNED_BYTE
) {
2659 if (dstFormat
== GL_RGBA
) {
2660 if (srcFormat
== GL_RGB
) {
2662 const GLubyte
*src
= (const GLubyte
*) source
;
2664 for (i
= 0; i
< n
; i
++) {
2665 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2666 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2667 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2674 else if (srcFormat
== GL_RGBA
) {
2676 const GLubyte
*src
= (const GLubyte
*) source
;
2678 for (i
= 0; i
< n
; i
++) {
2679 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2680 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2681 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2682 dst
[3] = UBYTE_TO_CHAN(src
[3]);
2689 else if (dstFormat
== GL_RGB
) {
2690 if (srcFormat
== GL_RGB
) {
2692 const GLubyte
*src
= (const GLubyte
*) source
;
2694 for (i
= 0; i
< n
; i
++) {
2695 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2696 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2697 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2703 else if (srcFormat
== GL_RGBA
) {
2705 const GLubyte
*src
= (const GLubyte
*) source
;
2707 for (i
= 0; i
< n
; i
++) {
2708 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2709 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2710 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2721 /* general solution begins here */
2723 GLint dstComponents
;
2724 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2725 GLint dstLuminanceIndex
, dstIntensityIndex
;
2726 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
2727 CHECKARRAY(rgba
, return); /* mac 32k limitation */
2729 dstComponents
= _mesa_components_in_format( dstFormat
);
2730 /* source & dest image formats should have been error checked by now */
2731 assert(dstComponents
> 0);
2734 * Extract image data and convert to RGBA floats
2736 assert(n
<= MAX_WIDTH
);
2737 if (srcFormat
== GL_COLOR_INDEX
) {
2738 GLuint indexes
[MAX_WIDTH
];
2739 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2742 if (dstFormat
== GL_COLOR_INDEX
2743 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
2744 _mesa_map_ci(ctx
, n
, indexes
);
2746 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
2747 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2750 if (dstFormat
== GL_COLOR_INDEX
) {
2751 /* convert to GLchan and return */
2753 for (i
= 0; i
< n
; i
++) {
2754 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
2756 UNDEFARRAY(rgba
); /* mac 32k limitation */
2760 /* Convert indexes to RGBA */
2761 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
2765 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2766 srcPacking
->SwapBytes
);
2768 /* scale and bias colors */
2769 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
2770 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
,
2771 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
2772 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
2773 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
2774 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
2776 /* color map lookup */
2777 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
2778 _mesa_map_rgba(ctx
, n
, rgba
);
2783 /* GL_COLOR_TABLE lookup */
2784 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
2785 _mesa_lookup_rgba(&ctx
->ColorTable
, n
, rgba
);
2788 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
2789 /* this has to be done in the calling code */
2791 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
2792 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
2793 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
,
2794 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
2795 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
2796 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
2797 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
2798 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
2799 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
2800 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
2801 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
2803 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
2804 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
2805 _mesa_lookup_rgba(&ctx
->PostConvolutionColorTable
, n
, rgba
);
2807 /* color matrix transform */
2808 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
2809 _mesa_transform_rgba(ctx
, n
, rgba
);
2811 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
2812 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
2813 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
2815 /* update histogram count */
2816 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
2817 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
2820 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
2821 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
2825 /* clamp to [0,1] */
2826 #if CHAN_TYPE != GL_FLOAT
2829 for (i
= 0; i
< n
; i
++) {
2830 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
2831 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
2832 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
2833 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
2838 /* Now determine which color channels we need to produce.
2839 * And determine the dest index (offset) within each color tuple.
2841 switch (dstFormat
) {
2844 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2845 dstLuminanceIndex
= dstIntensityIndex
= -1;
2848 dstLuminanceIndex
= 0;
2849 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2850 dstIntensityIndex
= -1;
2852 case GL_LUMINANCE_ALPHA
:
2853 dstLuminanceIndex
= 0;
2855 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2856 dstIntensityIndex
= -1;
2859 dstIntensityIndex
= 0;
2860 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2861 dstLuminanceIndex
= -1;
2867 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
2874 dstLuminanceIndex
= dstIntensityIndex
= -1;
2877 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
2878 UNDEFARRAY(rgba
); /* mac 32k limitation */
2883 /* Now return the GLchan data in the requested dstFormat */
2885 if (dstRedIndex
>= 0) {
2888 for (i
= 0; i
< n
; i
++) {
2889 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
2890 dst
+= dstComponents
;
2894 if (dstGreenIndex
>= 0) {
2897 for (i
= 0; i
< n
; i
++) {
2898 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
2899 dst
+= dstComponents
;
2903 if (dstBlueIndex
>= 0) {
2906 for (i
= 0; i
< n
; i
++) {
2907 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
2908 dst
+= dstComponents
;
2912 if (dstAlphaIndex
>= 0) {
2915 for (i
= 0; i
< n
; i
++) {
2916 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
2917 dst
+= dstComponents
;
2921 if (dstIntensityIndex
>= 0) {
2924 assert(dstIntensityIndex
== 0);
2925 assert(dstComponents
== 1);
2926 for (i
= 0; i
< n
; i
++) {
2927 /* Intensity comes from red channel */
2928 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
2932 if (dstLuminanceIndex
>= 0) {
2935 assert(dstLuminanceIndex
== 0);
2936 for (i
= 0; i
< n
; i
++) {
2937 /* Luminance comes from red channel */
2938 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
2939 dst
+= dstComponents
;
2942 UNDEFARRAY(rgba
); /* mac 32k limitation */
2948 _mesa_unpack_float_color_span( GLcontext
*ctx
,
2949 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
2950 GLenum srcFormat
, GLenum srcType
,
2951 const GLvoid
*source
,
2952 const struct gl_pixelstore_attrib
*srcPacking
,
2953 GLuint transferOps
, GLboolean clamp
)
2955 ASSERT(dstFormat
== GL_ALPHA
||
2956 dstFormat
== GL_LUMINANCE
||
2957 dstFormat
== GL_LUMINANCE_ALPHA
||
2958 dstFormat
== GL_INTENSITY
||
2959 dstFormat
== GL_RGB
||
2960 dstFormat
== GL_RGBA
||
2961 dstFormat
== GL_COLOR_INDEX
);
2963 ASSERT(srcFormat
== GL_RED
||
2964 srcFormat
== GL_GREEN
||
2965 srcFormat
== GL_BLUE
||
2966 srcFormat
== GL_ALPHA
||
2967 srcFormat
== GL_LUMINANCE
||
2968 srcFormat
== GL_LUMINANCE_ALPHA
||
2969 srcFormat
== GL_INTENSITY
||
2970 srcFormat
== GL_RGB
||
2971 srcFormat
== GL_BGR
||
2972 srcFormat
== GL_RGBA
||
2973 srcFormat
== GL_BGRA
||
2974 srcFormat
== GL_ABGR_EXT
||
2975 srcFormat
== GL_COLOR_INDEX
);
2977 ASSERT(srcType
== GL_BITMAP
||
2978 srcType
== GL_UNSIGNED_BYTE
||
2979 srcType
== GL_BYTE
||
2980 srcType
== GL_UNSIGNED_SHORT
||
2981 srcType
== GL_SHORT
||
2982 srcType
== GL_UNSIGNED_INT
||
2983 srcType
== GL_INT
||
2984 srcType
== GL_FLOAT
||
2985 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2986 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2987 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2988 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2989 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2990 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2991 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2992 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2993 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2994 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2995 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2996 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2998 /* general solution, no special cases, yet */
3000 GLint dstComponents
;
3001 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3002 GLint dstLuminanceIndex
, dstIntensityIndex
;
3003 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
3004 CHECKARRAY(rgba
, return); /* mac 32k limitation */
3006 dstComponents
= _mesa_components_in_format( dstFormat
);
3007 /* source & dest image formats should have been error checked by now */
3008 assert(dstComponents
> 0);
3011 * Extract image data and convert to RGBA floats
3013 assert(n
<= MAX_WIDTH
);
3014 if (srcFormat
== GL_COLOR_INDEX
) {
3015 GLuint indexes
[MAX_WIDTH
];
3016 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3019 if (dstFormat
== GL_COLOR_INDEX
3020 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
3021 _mesa_map_ci(ctx
, n
, indexes
);
3023 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3024 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3027 if (dstFormat
== GL_COLOR_INDEX
) {
3028 /* convert to GLchan and return */
3030 for (i
= 0; i
< n
; i
++) {
3031 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3033 UNDEFARRAY(rgba
); /* mac 32k limitation */
3037 /* Convert indexes to RGBA */
3038 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3042 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3043 srcPacking
->SwapBytes
);
3045 /* scale and bias colors */
3046 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
3047 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
,
3048 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
3049 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
3050 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
3051 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
3053 /* color map lookup */
3054 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3055 _mesa_map_rgba(ctx
, n
, rgba
);
3060 /* GL_COLOR_TABLE lookup */
3061 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
3062 _mesa_lookup_rgba(&ctx
->ColorTable
, n
, rgba
);
3065 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
3068 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
3069 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
3070 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
,
3071 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
3072 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
3073 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
3074 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
3075 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
3076 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
3077 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
3078 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
3080 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
3081 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
3082 _mesa_lookup_rgba(&ctx
->PostConvolutionColorTable
, n
, rgba
);
3084 /* color matrix transform */
3085 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
3086 _mesa_transform_rgba(ctx
, n
, rgba
);
3088 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
3089 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
3090 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
3092 /* update histogram count */
3093 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
3094 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
3097 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
3098 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
3102 /* clamp to [0,1] */
3103 #if CHAN_TYPE != GL_FLOAT
3106 for (i
= 0; i
< n
; i
++) {
3107 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
3108 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
3109 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
3110 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
3115 /* Now determine which color channels we need to produce.
3116 * And determine the dest index (offset) within each color tuple.
3118 switch (dstFormat
) {
3121 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3122 dstLuminanceIndex
= dstIntensityIndex
= -1;
3125 dstLuminanceIndex
= 0;
3126 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3127 dstIntensityIndex
= -1;
3129 case GL_LUMINANCE_ALPHA
:
3130 dstLuminanceIndex
= 0;
3132 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3133 dstIntensityIndex
= -1;
3136 dstIntensityIndex
= 0;
3137 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3138 dstLuminanceIndex
= -1;
3144 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3151 dstLuminanceIndex
= dstIntensityIndex
= -1;
3154 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_float_color_span()");
3155 UNDEFARRAY(rgba
); /* mac 32k limitation */
3159 /* Now pack results in the requested dstFormat */
3160 if (dstRedIndex
>= 0) {
3161 GLfloat
*dst
= dest
;
3163 for (i
= 0; i
< n
; i
++) {
3164 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3165 dst
+= dstComponents
;
3169 if (dstGreenIndex
>= 0) {
3170 GLfloat
*dst
= dest
;
3172 for (i
= 0; i
< n
; i
++) {
3173 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3174 dst
+= dstComponents
;
3178 if (dstBlueIndex
>= 0) {
3179 GLfloat
*dst
= dest
;
3181 for (i
= 0; i
< n
; i
++) {
3182 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3183 dst
+= dstComponents
;
3187 if (dstAlphaIndex
>= 0) {
3188 GLfloat
*dst
= dest
;
3190 for (i
= 0; i
< n
; i
++) {
3191 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3192 dst
+= dstComponents
;
3196 if (dstIntensityIndex
>= 0) {
3197 GLfloat
*dst
= dest
;
3199 assert(dstIntensityIndex
== 0);
3200 assert(dstComponents
== 1);
3201 for (i
= 0; i
< n
; i
++) {
3202 /* Intensity comes from red channel */
3203 dst
[i
] = rgba
[i
][RCOMP
];
3207 if (dstLuminanceIndex
>= 0) {
3208 GLfloat
*dst
= dest
;
3210 assert(dstLuminanceIndex
== 0);
3211 for (i
= 0; i
< n
; i
++) {
3212 /* Luminance comes from red channel */
3213 dst
[0] = rgba
[i
][RCOMP
];
3214 dst
+= dstComponents
;
3217 UNDEFARRAY(rgba
); /* mac 32k limitation */
3225 * Unpack a row of color index data from a client buffer according to
3226 * the pixel unpacking parameters.
3227 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
3229 * Args: ctx - the context
3230 * n - number of pixels
3231 * dstType - destination datatype
3232 * dest - destination array
3233 * srcType - source pixel type
3234 * source - source data pointer
3235 * srcPacking - pixel unpacking parameters
3236 * transferOps - the pixel transfer operations to apply
3239 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
3240 GLenum dstType
, GLvoid
*dest
,
3241 GLenum srcType
, const GLvoid
*source
,
3242 const struct gl_pixelstore_attrib
*srcPacking
,
3243 GLuint transferOps
)
3245 ASSERT(srcType
== GL_BITMAP
||
3246 srcType
== GL_UNSIGNED_BYTE
||
3247 srcType
== GL_BYTE
||
3248 srcType
== GL_UNSIGNED_SHORT
||
3249 srcType
== GL_SHORT
||
3250 srcType
== GL_UNSIGNED_INT
||
3251 srcType
== GL_INT
||
3252 srcType
== GL_FLOAT
);
3254 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3255 dstType
== GL_UNSIGNED_SHORT
||
3256 dstType
== GL_UNSIGNED_INT
);
3259 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3262 * Try simple cases first
3264 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
3265 && dstType
== GL_UNSIGNED_BYTE
) {
3266 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
3268 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
3269 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
3270 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
3276 GLuint indexes
[MAX_WIDTH
];
3277 assert(n
<= MAX_WIDTH
);
3279 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3282 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3283 /* shift and offset indexes */
3284 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3286 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3287 /* Apply lookup table */
3288 _mesa_map_ci(ctx
, n
, indexes
);
3291 /* convert to dest type */
3293 case GL_UNSIGNED_BYTE
:
3295 GLubyte
*dst
= (GLubyte
*) dest
;
3297 for (i
= 0; i
< n
; i
++) {
3298 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3302 case GL_UNSIGNED_SHORT
:
3304 GLuint
*dst
= (GLuint
*) dest
;
3306 for (i
= 0; i
< n
; i
++) {
3307 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3311 case GL_UNSIGNED_INT
:
3312 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
3315 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
3322 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
3323 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
3324 const struct gl_pixelstore_attrib
*dstPacking
,
3325 GLuint transferOps
)
3327 GLuint indexes
[MAX_WIDTH
];
3329 ASSERT(n
<= MAX_WIDTH
);
3331 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3333 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
3334 /* make a copy of input */
3335 MEMCPY(indexes
, source
, n
* sizeof(GLuint
));
3336 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3337 _mesa_shift_and_offset_ci( ctx
, n
, indexes
);
3339 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3340 _mesa_map_ci(ctx
, n
, indexes
);
3346 case GL_UNSIGNED_BYTE
:
3348 GLubyte
*dst
= (GLubyte
*) dest
;
3350 for (i
= 0; i
< n
; i
++) {
3351 *dst
++ = (GLubyte
) source
[i
];
3357 GLbyte
*dst
= (GLbyte
*) dest
;
3359 for (i
= 0; i
< n
; i
++) {
3360 dst
[i
] = (GLbyte
) source
[i
];
3364 case GL_UNSIGNED_SHORT
:
3366 GLushort
*dst
= (GLushort
*) dest
;
3368 for (i
= 0; i
< n
; i
++) {
3369 dst
[i
] = (GLushort
) source
[i
];
3371 if (dstPacking
->SwapBytes
) {
3372 _mesa_swap2( (GLushort
*) dst
, n
);
3378 GLshort
*dst
= (GLshort
*) dest
;
3380 for (i
= 0; i
< n
; i
++) {
3381 dst
[i
] = (GLshort
) source
[i
];
3383 if (dstPacking
->SwapBytes
) {
3384 _mesa_swap2( (GLushort
*) dst
, n
);
3388 case GL_UNSIGNED_INT
:
3390 GLuint
*dst
= (GLuint
*) dest
;
3392 for (i
= 0; i
< n
; i
++) {
3393 dst
[i
] = (GLuint
) source
[i
];
3395 if (dstPacking
->SwapBytes
) {
3396 _mesa_swap4( (GLuint
*) dst
, n
);
3402 GLint
*dst
= (GLint
*) dest
;
3404 for (i
= 0; i
< n
; i
++) {
3405 dst
[i
] = (GLint
) source
[i
];
3407 if (dstPacking
->SwapBytes
) {
3408 _mesa_swap4( (GLuint
*) dst
, n
);
3414 GLfloat
*dst
= (GLfloat
*) dest
;
3416 for (i
= 0; i
< n
; i
++) {
3417 dst
[i
] = (GLfloat
) source
[i
];
3419 if (dstPacking
->SwapBytes
) {
3420 _mesa_swap4( (GLuint
*) dst
, n
);
3425 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3432 * Unpack a row of stencil data from a client buffer according to
3433 * the pixel unpacking parameters.
3434 * This is (or will be) used by glDrawPixels
3436 * Args: ctx - the context
3437 * n - number of pixels
3438 * dstType - destination datatype
3439 * dest - destination array
3440 * srcType - source pixel type
3441 * source - source data pointer
3442 * srcPacking - pixel unpacking parameters
3443 * transferOps - apply offset/bias/lookup ops?
3446 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3447 GLenum dstType
, GLvoid
*dest
,
3448 GLenum srcType
, const GLvoid
*source
,
3449 const struct gl_pixelstore_attrib
*srcPacking
,
3450 GLuint transferOps
)
3452 ASSERT(srcType
== GL_BITMAP
||
3453 srcType
== GL_UNSIGNED_BYTE
||
3454 srcType
== GL_BYTE
||
3455 srcType
== GL_UNSIGNED_SHORT
||
3456 srcType
== GL_SHORT
||
3457 srcType
== GL_UNSIGNED_INT
||
3458 srcType
== GL_INT
||
3459 srcType
== GL_FLOAT
);
3461 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3462 dstType
== GL_UNSIGNED_SHORT
||
3463 dstType
== GL_UNSIGNED_INT
);
3465 /* only shift and offset apply to stencil */
3466 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
3469 * Try simple cases first
3471 if (transferOps
== 0 &&
3472 srcType
== GL_UNSIGNED_BYTE
&&
3473 dstType
== GL_UNSIGNED_BYTE
) {
3474 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
3476 else if (transferOps
== 0 &&
3477 srcType
== GL_UNSIGNED_INT
&&
3478 dstType
== GL_UNSIGNED_INT
&&
3479 !srcPacking
->SwapBytes
) {
3480 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
3486 GLuint indexes
[MAX_WIDTH
];
3487 assert(n
<= MAX_WIDTH
);
3489 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3493 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3494 /* shift and offset indexes */
3495 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3498 if (ctx
->Pixel
.MapStencilFlag
) {
3499 /* Apply stencil lookup table */
3500 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
3503 indexes
[i
] = ctx
->Pixel
.MapStoS
[ indexes
[i
] & mask
];
3508 /* convert to dest type */
3510 case GL_UNSIGNED_BYTE
:
3512 GLubyte
*dst
= (GLubyte
*) dest
;
3514 for (i
= 0; i
< n
; i
++) {
3515 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3519 case GL_UNSIGNED_SHORT
:
3521 GLuint
*dst
= (GLuint
*) dest
;
3523 for (i
= 0; i
< n
; i
++) {
3524 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3528 case GL_UNSIGNED_INT
:
3529 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
3532 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
3539 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3540 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
3541 const struct gl_pixelstore_attrib
*dstPacking
)
3543 GLstencil stencil
[MAX_WIDTH
];
3545 ASSERT(n
<= MAX_WIDTH
);
3547 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
3548 ctx
->Pixel
.MapStencilFlag
) {
3549 /* make a copy of input */
3550 MEMCPY(stencil
, source
, n
* sizeof(GLstencil
));
3551 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
3552 _mesa_shift_and_offset_stencil( ctx
, n
, stencil
);
3554 if (ctx
->Pixel
.MapStencilFlag
) {
3555 _mesa_map_stencil( ctx
, n
, stencil
);
3561 case GL_UNSIGNED_BYTE
:
3562 if (sizeof(GLstencil
) == 8) {
3563 MEMCPY( dest
, source
, n
);
3566 GLubyte
*dst
= (GLubyte
*) dest
;
3569 dst
[i
] = (GLubyte
) source
[i
];
3574 if (sizeof(GLstencil
) == 8) {
3575 MEMCPY( dest
, source
, n
);
3578 GLbyte
*dst
= (GLbyte
*) dest
;
3581 dst
[i
] = (GLbyte
) source
[i
];
3585 case GL_UNSIGNED_SHORT
:
3587 GLushort
*dst
= (GLushort
*) dest
;
3590 dst
[i
] = (GLushort
) source
[i
];
3592 if (dstPacking
->SwapBytes
) {
3593 _mesa_swap2( (GLushort
*) dst
, n
);
3599 GLshort
*dst
= (GLshort
*) dest
;
3602 dst
[i
] = (GLshort
) source
[i
];
3604 if (dstPacking
->SwapBytes
) {
3605 _mesa_swap2( (GLushort
*) dst
, n
);
3609 case GL_UNSIGNED_INT
:
3611 GLuint
*dst
= (GLuint
*) dest
;
3614 dst
[i
] = (GLuint
) source
[i
];
3616 if (dstPacking
->SwapBytes
) {
3617 _mesa_swap4( (GLuint
*) dst
, n
);
3623 GLint
*dst
= (GLint
*) dest
;
3626 *dst
++ = (GLint
) source
[i
];
3628 if (dstPacking
->SwapBytes
) {
3629 _mesa_swap4( (GLuint
*) dst
, n
);
3635 GLfloat
*dst
= (GLfloat
*) dest
;
3638 dst
[i
] = (GLfloat
) source
[i
];
3640 if (dstPacking
->SwapBytes
) {
3641 _mesa_swap4( (GLuint
*) dst
, n
);
3646 if (dstPacking
->LsbFirst
) {
3647 GLubyte
*dst
= (GLubyte
*) dest
;
3650 for (i
= 0; i
< n
; i
++) {
3653 *dst
|= ((source
[i
] != 0) << shift
);
3662 GLubyte
*dst
= (GLubyte
*) dest
;
3665 for (i
= 0; i
< n
; i
++) {
3668 *dst
|= ((source
[i
] != 0) << shift
);
3678 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3685 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
, GLfloat
*dest
,
3686 GLenum srcType
, const GLvoid
*source
,
3687 const struct gl_pixelstore_attrib
*srcPacking
)
3693 const GLubyte
*src
= (const GLubyte
*) source
;
3694 for (i
= 0; i
< n
; i
++) {
3695 dest
[i
] = BYTE_TO_FLOAT(src
[i
]);
3699 case GL_UNSIGNED_BYTE
:
3702 const GLubyte
*src
= (const GLubyte
*) source
;
3703 for (i
= 0; i
< n
; i
++) {
3704 dest
[i
] = UBYTE_TO_FLOAT(src
[i
]);
3711 const GLshort
*src
= (const GLshort
*) source
;
3712 for (i
= 0; i
< n
; i
++) {
3713 dest
[i
] = SHORT_TO_FLOAT(src
[i
]);
3717 case GL_UNSIGNED_SHORT
:
3720 const GLushort
*src
= (const GLushort
*) source
;
3721 for (i
= 0; i
< n
; i
++) {
3722 dest
[i
] = USHORT_TO_FLOAT(src
[i
]);
3729 const GLint
*src
= (const GLint
*) source
;
3730 for (i
= 0; i
< n
; i
++) {
3731 dest
[i
] = INT_TO_FLOAT(src
[i
]);
3735 case GL_UNSIGNED_INT
:
3738 const GLuint
*src
= (const GLuint
*) source
;
3739 for (i
= 0; i
< n
; i
++) {
3740 dest
[i
] = UINT_TO_FLOAT(src
[i
]);
3745 MEMCPY(dest
, source
, n
* sizeof(GLfloat
));
3748 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
3753 /* apply depth scale and bias and clamp to [0,1] */
3754 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
3756 for (i
= 0; i
< n
; i
++) {
3757 GLfloat d
= dest
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
3758 dest
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
3766 * Pack an array of depth values. The values are floats in [0,1].
3769 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
3770 GLenum dstType
, const GLfloat
*depthSpan
,
3771 const struct gl_pixelstore_attrib
*dstPacking
)
3773 GLfloat depthCopy
[MAX_WIDTH
];
3774 const GLboolean bias_or_scale
= ctx
->Pixel
.DepthBias
!= 0.0 ||
3775 ctx
->Pixel
.DepthScale
!= 1.0;
3777 ASSERT(n
<= MAX_WIDTH
);
3779 if (bias_or_scale
) {
3781 for (i
= 0; i
< n
; i
++) {
3783 d
= depthSpan
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
3784 depthCopy
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
3786 depthSpan
= depthCopy
;
3790 case GL_UNSIGNED_BYTE
:
3792 GLubyte
*dst
= (GLubyte
*) dest
;
3794 for (i
= 0; i
< n
; i
++) {
3795 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
3801 GLbyte
*dst
= (GLbyte
*) dest
;
3803 for (i
= 0; i
< n
; i
++) {
3804 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
3808 case GL_UNSIGNED_SHORT
:
3810 GLushort
*dst
= (GLushort
*) dest
;
3812 for (i
= 0; i
< n
; i
++) {
3813 dst
[i
] = FLOAT_TO_USHORT( depthSpan
[i
] );
3815 if (dstPacking
->SwapBytes
) {
3816 _mesa_swap2( (GLushort
*) dst
, n
);
3822 GLshort
*dst
= (GLshort
*) dest
;
3824 for (i
= 0; i
< n
; i
++) {
3825 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
3827 if (dstPacking
->SwapBytes
) {
3828 _mesa_swap2( (GLushort
*) dst
, n
);
3832 case GL_UNSIGNED_INT
:
3834 GLuint
*dst
= (GLuint
*) dest
;
3836 for (i
= 0; i
< n
; i
++) {
3837 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
3839 if (dstPacking
->SwapBytes
) {
3840 _mesa_swap4( (GLuint
*) dst
, n
);
3846 GLint
*dst
= (GLint
*) dest
;
3848 for (i
= 0; i
< n
; i
++) {
3849 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
3851 if (dstPacking
->SwapBytes
) {
3852 _mesa_swap4( (GLuint
*) dst
, n
);
3858 GLfloat
*dst
= (GLfloat
*) dest
;
3860 for (i
= 0; i
< n
; i
++) {
3861 dst
[i
] = depthSpan
[i
];
3863 if (dstPacking
->SwapBytes
) {
3864 _mesa_swap4( (GLuint
*) dst
, n
);
3869 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
3877 * Unpack image data. Apply byteswapping, byte flipping (bitmap).
3878 * Return all image data in a contiguous block.
3881 _mesa_unpack_image( GLsizei width
, GLsizei height
, GLsizei depth
,
3882 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3883 const struct gl_pixelstore_attrib
*unpack
)
3885 GLint bytesPerRow
, compsPerRow
;
3886 GLboolean flipBytes
, swap2
, swap4
;
3889 return NULL
; /* not necessarily an error */
3891 if (width
<= 0 || height
<= 0 || depth
<= 0)
3892 return NULL
; /* generate error later */
3894 if (format
== GL_BITMAP
) {
3895 bytesPerRow
= (width
+ 7) >> 3;
3896 flipBytes
= !unpack
->LsbFirst
;
3897 swap2
= swap4
= GL_FALSE
;
3901 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
3902 const GLint components
= _mesa_components_in_format(format
);
3904 if (bytesPerPixel
<= 0 || components
<= 0)
3905 return NULL
; /* bad format or type. generate error later */
3906 bytesPerRow
= bytesPerPixel
* width
;
3907 bytesPerComp
= bytesPerPixel
/ components
;
3908 flipBytes
= GL_FALSE
;
3909 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
3910 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
3911 compsPerRow
= components
* width
;
3912 assert(compsPerRow
>= width
);
3916 GLubyte
*destBuffer
= (GLubyte
*) MALLOC(bytesPerRow
* height
* depth
);
3920 return NULL
; /* generate GL_OUT_OF_MEMORY later */
3923 for (img
= 0; img
< depth
; img
++) {
3924 for (row
= 0; row
< height
; row
++) {
3925 const GLvoid
*src
= _mesa_image_address(unpack
, pixels
,
3926 width
, height
, format
, type
, img
, row
, 0);
3927 MEMCPY(dst
, src
, bytesPerRow
);
3928 /* byte flipping/swapping */
3930 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
3933 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
3936 _mesa_swap4((GLuint
*) dst
, compsPerRow
);