7 * Mesa 3-D graphics library
10 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 #include "histogram.h"
42 /** Compute ceiling of integer quotient of A divided by B. */
43 #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
47 * Image packing parameters for Mesa's internal images.
49 * _mesa_unpack_image() returns image data in this format. When we execute
50 * image commands (glDrawPixels(), glTexImage(), etc) from within display lists
51 * we have to be sure to set the current unpacking parameters to these values!
53 const struct gl_pixelstore_attrib _mesa_native_packing
= {
60 GL_FALSE
, /* SwapBytes */
61 GL_FALSE
, /* LsbFirst */
62 GL_FALSE
, /* ClientStorage */
68 * Flip the 8 bits in each byte of the given array.
71 * \param n number of bytes.
73 * \todo try this trick to flip bytes someday:
75 * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555);
76 * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333);
77 * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f);
81 flip_bytes( GLubyte
*p
, GLuint n
)
83 register GLuint i
, a
, b
;
86 b
= (GLuint
) p
[i
]; /* words are often faster than bytes */
87 a
= ((b
& 0x01) << 7) |
101 * Flip the order of the 2 bytes in each word in the given array.
104 * \param n number of words.
107 _mesa_swap2( GLushort
*p
, GLuint n
)
112 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
119 * Flip the order of the 4 bytes in each word in the given array.
122 _mesa_swap4( GLuint
*p
, GLuint n
)
124 register GLuint i
, a
, b
;
129 | ((b
>> 8) & 0xff00)
130 | ((b
<< 8) & 0xff0000)
131 | ((b
<< 24) & 0xff000000);
138 * Get the size of a GL data type.
140 * \param type GL data type.
142 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
143 * if an invalid type enum.
145 GLint
_mesa_sizeof_type( GLenum type
)
150 case GL_UNSIGNED_BYTE
:
151 return sizeof(GLubyte
);
153 return sizeof(GLbyte
);
154 case GL_UNSIGNED_SHORT
:
155 return sizeof(GLushort
);
157 return sizeof(GLshort
);
158 case GL_UNSIGNED_INT
:
159 return sizeof(GLuint
);
161 return sizeof(GLint
);
163 return sizeof(GLfloat
);
164 case GL_HALF_FLOAT_NV
:
165 return sizeof(GLhalfNV
);
173 * Same as _mesa_sizeof_type() but also accepting the packed pixel
176 GLint
_mesa_sizeof_packed_type( GLenum type
)
181 case GL_UNSIGNED_BYTE
:
182 return sizeof(GLubyte
);
184 return sizeof(GLbyte
);
185 case GL_UNSIGNED_SHORT
:
186 return sizeof(GLushort
);
188 return sizeof(GLshort
);
189 case GL_UNSIGNED_INT
:
190 return sizeof(GLuint
);
192 return sizeof(GLint
);
193 case GL_HALF_FLOAT_NV
:
194 return sizeof(GLhalfNV
);
196 return sizeof(GLfloat
);
197 case GL_UNSIGNED_BYTE_3_3_2
:
198 return sizeof(GLubyte
);
199 case GL_UNSIGNED_BYTE_2_3_3_REV
:
200 return sizeof(GLubyte
);
201 case GL_UNSIGNED_SHORT_5_6_5
:
202 return sizeof(GLushort
);
203 case GL_UNSIGNED_SHORT_5_6_5_REV
:
204 return sizeof(GLushort
);
205 case GL_UNSIGNED_SHORT_4_4_4_4
:
206 return sizeof(GLushort
);
207 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
208 return sizeof(GLushort
);
209 case GL_UNSIGNED_SHORT_5_5_5_1
:
210 return sizeof(GLushort
);
211 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
212 return sizeof(GLushort
);
213 case GL_UNSIGNED_INT_8_8_8_8
:
214 return sizeof(GLuint
);
215 case GL_UNSIGNED_INT_8_8_8_8_REV
:
216 return sizeof(GLuint
);
217 case GL_UNSIGNED_INT_10_10_10_2
:
218 return sizeof(GLuint
);
219 case GL_UNSIGNED_INT_2_10_10_10_REV
:
220 return sizeof(GLuint
);
221 case GL_UNSIGNED_SHORT_8_8_MESA
:
222 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
223 return sizeof(GLushort
);
231 * Get the number of components in a pixel format.
233 * \param format pixel format.
235 * \return the number of components in the given format, or -1 if a bad format.
237 GLint
_mesa_components_in_format( GLenum format
)
241 case GL_COLOR_INDEX1_EXT
:
242 case GL_COLOR_INDEX2_EXT
:
243 case GL_COLOR_INDEX4_EXT
:
244 case GL_COLOR_INDEX8_EXT
:
245 case GL_COLOR_INDEX12_EXT
:
246 case GL_COLOR_INDEX16_EXT
:
247 case GL_STENCIL_INDEX
:
248 case GL_DEPTH_COMPONENT
:
256 case GL_LUMINANCE_ALPHA
:
277 * Get the bytes per pixel of pixel format type pair.
279 * \param format pixel format.
280 * \param type pixel type.
282 * \return bytes per pixel, or -1 if a bad format or type was given.
284 GLint
_mesa_bytes_per_pixel( GLenum format
, GLenum type
)
286 GLint comps
= _mesa_components_in_format( format
);
292 return 0; /* special case */
294 case GL_UNSIGNED_BYTE
:
295 return comps
* sizeof(GLubyte
);
297 case GL_UNSIGNED_SHORT
:
298 return comps
* sizeof(GLshort
);
300 case GL_UNSIGNED_INT
:
301 return comps
* sizeof(GLint
);
303 return comps
* sizeof(GLfloat
);
304 case GL_HALF_FLOAT_NV
:
305 return comps
* sizeof(GLhalfNV
);
306 case GL_UNSIGNED_BYTE_3_3_2
:
307 case GL_UNSIGNED_BYTE_2_3_3_REV
:
308 if (format
== GL_RGB
|| format
== GL_BGR
)
309 return sizeof(GLubyte
);
311 return -1; /* error */
312 case GL_UNSIGNED_SHORT_5_6_5
:
313 case GL_UNSIGNED_SHORT_5_6_5_REV
:
314 if (format
== GL_RGB
|| format
== GL_BGR
)
315 return sizeof(GLushort
);
317 return -1; /* error */
318 case GL_UNSIGNED_SHORT_4_4_4_4
:
319 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
320 case GL_UNSIGNED_SHORT_5_5_5_1
:
321 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
322 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
323 return sizeof(GLushort
);
326 case GL_UNSIGNED_INT_8_8_8_8
:
327 case GL_UNSIGNED_INT_8_8_8_8_REV
:
328 case GL_UNSIGNED_INT_10_10_10_2
:
329 case GL_UNSIGNED_INT_2_10_10_10_REV
:
330 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
331 return sizeof(GLuint
);
334 case GL_UNSIGNED_SHORT_8_8_MESA
:
335 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
336 if (format
== GL_YCBCR_MESA
)
337 return sizeof(GLushort
);
347 * Test for a legal pixel format and type.
349 * \param format pixel format.
350 * \param type pixel type.
352 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
356 _mesa_is_legal_format_and_type( GLenum format
, GLenum type
)
360 case GL_STENCIL_INDEX
:
364 case GL_UNSIGNED_BYTE
:
366 case GL_UNSIGNED_SHORT
:
368 case GL_UNSIGNED_INT
:
370 case GL_HALF_FLOAT_NV
:
381 case GL_LUMINANCE_ALPHA
:
382 case GL_DEPTH_COMPONENT
:
385 case GL_UNSIGNED_BYTE
:
387 case GL_UNSIGNED_SHORT
:
389 case GL_UNSIGNED_INT
:
391 case GL_HALF_FLOAT_NV
:
400 case GL_UNSIGNED_BYTE
:
402 case GL_UNSIGNED_SHORT
:
404 case GL_UNSIGNED_INT
:
406 case GL_HALF_FLOAT_NV
:
407 case GL_UNSIGNED_BYTE_3_3_2
:
408 case GL_UNSIGNED_BYTE_2_3_3_REV
:
409 case GL_UNSIGNED_SHORT_5_6_5
:
410 case GL_UNSIGNED_SHORT_5_6_5_REV
:
420 case GL_UNSIGNED_BYTE
:
422 case GL_UNSIGNED_SHORT
:
424 case GL_UNSIGNED_INT
:
426 case GL_HALF_FLOAT_NV
:
427 case GL_UNSIGNED_SHORT_4_4_4_4
:
428 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
429 case GL_UNSIGNED_SHORT_5_5_5_1
:
430 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
431 case GL_UNSIGNED_INT_8_8_8_8
:
432 case GL_UNSIGNED_INT_8_8_8_8_REV
:
433 case GL_UNSIGNED_INT_10_10_10_2
:
434 case GL_UNSIGNED_INT_2_10_10_10_REV
:
440 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
441 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
453 * Get the address of a pixel in an image (actually a volume).
455 * Pixel unpacking/packing parameters are observed according to \p packing.
457 * \param image start of image data.
458 * \param width image width.
459 * \param height image height.
460 * \param format pixel format.
461 * \param type pixel data type.
462 * \param packing the pixelstore attributes
463 * \param img which image in the volume (0 for 1D or 2D images)
464 * \param row of pixel in the image
465 * \param column of pixel in the image
467 * \return address of pixel on success, or NULL on error.
469 * According to the \p packing information calculates the number of pixel/bytes
470 * per row/image and refers it.
472 * \sa gl_pixelstore_attrib.
475 _mesa_image_address( const struct gl_pixelstore_attrib
*packing
,
476 const GLvoid
*image
, GLsizei width
,
477 GLsizei height
, GLenum format
, GLenum type
,
478 GLint img
, GLint row
, GLint column
)
480 GLint alignment
; /* 1, 2 or 4 */
481 GLint pixels_per_row
;
482 GLint rows_per_image
;
485 GLint skipimages
; /* for 3-D volume images */
488 alignment
= packing
->Alignment
;
489 if (packing
->RowLength
> 0) {
490 pixels_per_row
= packing
->RowLength
;
493 pixels_per_row
= width
;
495 if (packing
->ImageHeight
> 0) {
496 rows_per_image
= packing
->ImageHeight
;
499 rows_per_image
= height
;
501 skiprows
= packing
->SkipRows
;
502 skippixels
= packing
->SkipPixels
;
503 skipimages
= packing
->SkipImages
;
505 if (type
==GL_BITMAP
) {
507 GLint comp_per_pixel
; /* components per pixel */
508 GLint bytes_per_comp
; /* bytes per component */
510 GLint bytes_per_image
;
512 /* Compute bytes per component */
513 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
514 if (bytes_per_comp
<0) {
518 /* Compute number of components per pixel */
519 comp_per_pixel
= _mesa_components_in_format( format
);
520 if (comp_per_pixel
<0 && type
!= GL_BITMAP
) {
524 bytes_per_row
= alignment
525 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
527 bytes_per_image
= bytes_per_row
* rows_per_image
;
529 pixel_addr
= (GLubyte
*) image
530 + (skipimages
+ img
) * bytes_per_image
531 + (skiprows
+ row
) * bytes_per_row
532 + (skippixels
+ column
) / 8;
535 /* Non-BITMAP data */
536 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
539 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
541 /* The pixel type and format should have been error checked earlier */
542 assert(bytes_per_pixel
> 0);
544 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
545 remainder
= bytes_per_row
% alignment
;
547 bytes_per_row
+= (alignment
- remainder
);
549 ASSERT(bytes_per_row
% alignment
== 0);
551 bytes_per_image
= bytes_per_row
* rows_per_image
;
553 if (packing
->Invert
) {
554 /* set pixel_addr to the last row */
555 topOfImage
= bytes_per_row
* (height
- 1);
556 bytes_per_row
= -bytes_per_row
;
562 /* compute final pixel address */
563 pixel_addr
= (GLubyte
*) image
564 + (skipimages
+ img
) * bytes_per_image
566 + (skiprows
+ row
) * bytes_per_row
567 + (skippixels
+ column
) * bytes_per_pixel
;
570 return (GLvoid
*) pixel_addr
;
575 * Compute the stride between image rows.
577 * \param packing the pixelstore attributes
578 * \param width image width.
579 * \param format pixel format.
580 * \param type pixel data type.
582 * \return the stride in bytes for the given parameters.
584 * Computes the number of bytes per pixel and row and compensates for alignment.
586 * \sa gl_pixelstore_attrib.
589 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
590 GLint width
, GLenum format
, GLenum type
)
593 if (type
== GL_BITMAP
) {
596 if (packing
->RowLength
== 0) {
597 bytes
= (width
+ 7) / 8;
600 bytes
= (packing
->RowLength
+ 7) / 8;
602 if (packing
->Invert
) {
603 /* negate the bytes per row (negative row stride) */
609 /* Non-BITMAP data */
610 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
611 GLint bytesPerRow
, remainder
;
612 if (bytesPerPixel
<= 0)
613 return -1; /* error */
614 if (packing
->RowLength
== 0) {
615 bytesPerRow
= bytesPerPixel
* width
;
618 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
620 remainder
= bytesPerRow
% packing
->Alignment
;
622 bytesPerRow
+= (packing
->Alignment
- remainder
);
624 bytesPerRow
= -bytesPerRow
;
633 * Compute the stride between images in a 3D texture (in bytes) for the given
634 * pixel packing parameters and image width, format and type.
637 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
638 GLint width
, GLint height
,
639 GLenum format
, GLenum type
)
642 ASSERT(type
!= GL_BITMAP
);
645 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
646 GLint bytesPerRow
, bytesPerImage
, remainder
;
648 if (bytesPerPixel
<= 0)
649 return -1; /* error */
650 if (packing
->RowLength
== 0) {
651 bytesPerRow
= bytesPerPixel
* width
;
654 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
656 remainder
= bytesPerRow
% packing
->Alignment
;
658 bytesPerRow
+= (packing
->Alignment
- remainder
);
660 if (packing
->ImageHeight
== 0)
661 bytesPerImage
= bytesPerRow
* height
;
663 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
665 return bytesPerImage
;
671 * Unpack a 32x32 pixel polygon stipple from user memory using the
672 * current pixel unpack settings.
675 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
676 const struct gl_pixelstore_attrib
*unpacking
)
678 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap( 32, 32, pattern
, unpacking
);
680 /* Convert pattern from GLubytes to GLuints and handle big/little
685 for (i
= 0; i
< 32; i
++) {
686 dest
[i
] = (p
[0] << 24)
698 * Pack polygon stipple into user memory given current pixel packing
702 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
703 const struct gl_pixelstore_attrib
*packing
)
705 /* Convert pattern from GLuints to GLubytes to handle big/little
706 * endian differences.
710 for (i
= 0; i
< 32; i
++) {
711 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
712 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
713 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
714 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
717 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
722 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
723 * order with row alignment = 1 byte.
726 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
727 const struct gl_pixelstore_attrib
*packing
)
729 GLint bytes
, row
, width_in_bytes
;
730 GLubyte
*buffer
, *dst
;
735 /* Alloc dest storage */
736 bytes
= ((width
+ 7) / 8 * height
);
737 buffer
= (GLubyte
*) MALLOC( bytes
);
742 width_in_bytes
= CEILING( width
, 8 );
744 for (row
= 0; row
< height
; row
++) {
745 const GLubyte
*src
= (const GLubyte
*)
746 _mesa_image_address(packing
, pixels
, width
, height
,
747 GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0);
753 if (packing
->SkipPixels
== 0) {
754 MEMCPY( dst
, src
, width_in_bytes
);
755 if (packing
->LsbFirst
) {
756 flip_bytes( dst
, width_in_bytes
);
760 /* handling SkipPixels is a bit tricky (no pun intended!) */
762 if (packing
->LsbFirst
) {
763 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
764 GLubyte dstMask
= 128;
765 const GLubyte
*s
= src
;
768 for (i
= 0; i
< width
; i
++) {
772 if (srcMask
== 128) {
777 srcMask
= srcMask
<< 1;
785 dstMask
= dstMask
>> 1;
790 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
791 GLubyte dstMask
= 128;
792 const GLubyte
*s
= src
;
795 for (i
= 0; i
< width
; i
++) {
804 srcMask
= srcMask
>> 1;
812 dstMask
= dstMask
>> 1;
817 dst
+= width_in_bytes
;
828 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
829 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
831 GLint row
, width_in_bytes
;
837 width_in_bytes
= CEILING( width
, 8 );
839 for (row
= 0; row
< height
; row
++) {
840 GLubyte
*dst
= (GLubyte
*) _mesa_image_address( packing
, dest
,
841 width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, 0, row
, 0 );
845 if (packing
->SkipPixels
== 0) {
846 MEMCPY( dst
, src
, width_in_bytes
);
847 if (packing
->LsbFirst
) {
848 flip_bytes( dst
, width_in_bytes
);
852 /* handling SkipPixels is a bit tricky (no pun intended!) */
854 if (packing
->LsbFirst
) {
855 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
856 GLubyte dstMask
= 128;
857 const GLubyte
*s
= src
;
860 for (i
= 0; i
< width
; i
++) {
864 if (srcMask
== 128) {
869 srcMask
= srcMask
<< 1;
877 dstMask
= dstMask
>> 1;
882 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
883 GLubyte dstMask
= 128;
884 const GLubyte
*s
= src
;
887 for (i
= 0; i
< width
; i
++) {
896 srcMask
= srcMask
>> 1;
904 dstMask
= dstMask
>> 1;
909 src
+= width_in_bytes
;
915 * Apply various pixel transfer operations to an array of RGBA pixels
916 * as indicated by the transferOps bitmask
919 _mesa_apply_rgba_transfer_ops(GLcontext
*ctx
, GLuint transferOps
,
920 GLuint n
, GLfloat rgba
[][4])
923 if (transferOps
& IMAGE_SCALE_BIAS_BIT
) {
924 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
,
925 ctx
->Pixel
.RedScale
, ctx
->Pixel
.GreenScale
,
926 ctx
->Pixel
.BlueScale
, ctx
->Pixel
.AlphaScale
,
927 ctx
->Pixel
.RedBias
, ctx
->Pixel
.GreenBias
,
928 ctx
->Pixel
.BlueBias
, ctx
->Pixel
.AlphaBias
);
930 /* color map lookup */
931 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
932 _mesa_map_rgba( ctx
, n
, rgba
);
934 /* GL_COLOR_TABLE lookup */
935 if (transferOps
& IMAGE_COLOR_TABLE_BIT
) {
936 _mesa_lookup_rgba_float(&ctx
->ColorTable
, n
, rgba
);
939 if (transferOps
& IMAGE_CONVOLUTION_BIT
) {
940 /* this has to be done in the calling code */
941 _mesa_problem(ctx
, "IMAGE_CONVOLUTION_BIT set in _mesa_apply_transfer_ops");
943 /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
944 if (transferOps
& IMAGE_POST_CONVOLUTION_SCALE_BIAS
) {
945 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
,
946 ctx
->Pixel
.PostConvolutionScale
[RCOMP
],
947 ctx
->Pixel
.PostConvolutionScale
[GCOMP
],
948 ctx
->Pixel
.PostConvolutionScale
[BCOMP
],
949 ctx
->Pixel
.PostConvolutionScale
[ACOMP
],
950 ctx
->Pixel
.PostConvolutionBias
[RCOMP
],
951 ctx
->Pixel
.PostConvolutionBias
[GCOMP
],
952 ctx
->Pixel
.PostConvolutionBias
[BCOMP
],
953 ctx
->Pixel
.PostConvolutionBias
[ACOMP
]);
955 /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
956 if (transferOps
& IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
) {
957 _mesa_lookup_rgba_float(&ctx
->PostConvolutionColorTable
, n
, rgba
);
959 /* color matrix transform */
960 if (transferOps
& IMAGE_COLOR_MATRIX_BIT
) {
961 _mesa_transform_rgba(ctx
, n
, rgba
);
963 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
964 if (transferOps
& IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
) {
965 _mesa_lookup_rgba_float(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
967 /* update histogram count */
968 if (transferOps
& IMAGE_HISTOGRAM_BIT
) {
969 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
971 /* update min/max values */
972 if (transferOps
& IMAGE_MIN_MAX_BIT
) {
973 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
975 /* clamping to [0,1] */
976 if (transferOps
& IMAGE_CLAMP_BIT
) {
978 for (i
= 0; i
< n
; i
++) {
979 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
980 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
981 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
982 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
990 * Used to pack an array [][4] of RGBA GLchan colors as specified
991 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
992 * glGetConvolutionFilter(), etc.
995 _mesa_pack_rgba_span_float( GLcontext
*ctx
,
996 GLuint n
, CONST GLfloat rgbaIn
[][4],
997 GLenum dstFormat
, GLenum dstType
,
999 const struct gl_pixelstore_attrib
*dstPacking
,
1000 GLuint transferOps
)
1002 const GLint comps
= _mesa_components_in_format(dstFormat
);
1003 GLfloat luminance
[MAX_WIDTH
];
1004 const GLfloat (*rgba
)[4];
1008 /* make copy of incoming data */
1009 DEFMARRAY(GLfloat
, rgbaCopy
, MAX_WIDTH
, 4); /* mac 32k limitation */
1010 CHECKARRAY(rgbaCopy
, return); /* mac 32k limitation */
1012 _mesa_memcpy(rgbaCopy
, rgbaIn
, n
* 4 * sizeof(GLfloat
));
1013 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgbaCopy
);
1014 rgba
= (const GLfloat (*)[4]) rgbaCopy
;
1016 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
1017 UNDEFARRAY(rgbaCopy
); /* mac 32k limitation */
1020 UNDEFARRAY(rgbaCopy
); /* mac 32k limitation */
1023 /* use incoming data, not a copy */
1024 rgba
= (const GLfloat (*)[4]) rgbaIn
;
1027 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
1028 /* compute luminance values */
1029 if (ctx
->ClampFragmentColors
) {
1030 for (i
= 0; i
< n
; i
++) {
1031 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1032 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
1036 for (i
= 0; i
< n
; i
++) {
1037 luminance
[i
] = rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1043 * Pack/store the pixels. Ugh! Lots of cases!!!
1046 case GL_UNSIGNED_BYTE
:
1048 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1049 switch (dstFormat
) {
1052 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1056 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1060 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1064 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1068 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1070 case GL_LUMINANCE_ALPHA
:
1072 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1073 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1078 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1079 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1080 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1085 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1086 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1087 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1088 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1093 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1094 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1095 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1100 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1101 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1102 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1103 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1108 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1109 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1110 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1111 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1115 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1121 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1122 switch (dstFormat
) {
1125 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1129 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1133 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1137 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1141 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1143 case GL_LUMINANCE_ALPHA
:
1145 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1146 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1151 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1152 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1153 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1158 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1159 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1160 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1161 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1166 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1167 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1168 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1173 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1174 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1175 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1176 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1180 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1181 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1182 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1183 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1187 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1191 case GL_UNSIGNED_SHORT
:
1193 GLushort
*dst
= (GLushort
*) dstAddr
;
1194 switch (dstFormat
) {
1197 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1201 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1205 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1209 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1213 dst
[i
] = FLOAT_TO_USHORT(luminance
[i
]);
1215 case GL_LUMINANCE_ALPHA
:
1217 dst
[i
*2+0] = FLOAT_TO_USHORT(luminance
[i
]);
1218 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1223 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1224 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1225 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1230 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1231 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1232 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1233 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1238 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1239 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1240 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1245 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1246 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1247 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1248 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1253 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1254 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1255 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1256 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1260 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1262 if (dstPacking
->SwapBytes
) {
1263 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1269 GLshort
*dst
= (GLshort
*) dstAddr
;
1270 switch (dstFormat
) {
1273 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1277 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1281 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1285 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1289 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
1291 case GL_LUMINANCE_ALPHA
:
1293 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
1294 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1299 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1300 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1301 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1306 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1307 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1308 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1309 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1314 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1315 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1316 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1321 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1322 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1323 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1324 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1328 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1329 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1330 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1331 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1335 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1337 if (dstPacking
->SwapBytes
) {
1338 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1342 case GL_UNSIGNED_INT
:
1344 GLuint
*dst
= (GLuint
*) dstAddr
;
1345 switch (dstFormat
) {
1348 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1352 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1356 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1360 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1364 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
1366 case GL_LUMINANCE_ALPHA
:
1368 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
1369 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1374 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1375 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1376 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1381 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1382 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1383 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1384 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1389 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1390 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1391 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1396 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1397 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1398 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1399 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1404 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1405 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1406 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1407 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1411 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1413 if (dstPacking
->SwapBytes
) {
1414 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1420 GLint
*dst
= (GLint
*) dstAddr
;
1421 switch (dstFormat
) {
1424 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1428 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1432 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1436 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1440 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1442 case GL_LUMINANCE_ALPHA
:
1444 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1445 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1450 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1451 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1452 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1457 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1458 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1459 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1460 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1465 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1466 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1467 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1472 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1473 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1474 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1475 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1480 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1481 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1482 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1483 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1487 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1489 if (dstPacking
->SwapBytes
) {
1490 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1496 GLfloat
*dst
= (GLfloat
*) dstAddr
;
1497 switch (dstFormat
) {
1500 dst
[i
] = rgba
[i
][RCOMP
];
1504 dst
[i
] = rgba
[i
][GCOMP
];
1508 dst
[i
] = rgba
[i
][BCOMP
];
1512 dst
[i
] = rgba
[i
][ACOMP
];
1516 dst
[i
] = luminance
[i
];
1518 case GL_LUMINANCE_ALPHA
:
1520 dst
[i
*2+0] = luminance
[i
];
1521 dst
[i
*2+1] = rgba
[i
][ACOMP
];
1526 dst
[i
*3+0] = rgba
[i
][RCOMP
];
1527 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1528 dst
[i
*3+2] = rgba
[i
][BCOMP
];
1533 dst
[i
*4+0] = rgba
[i
][RCOMP
];
1534 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1535 dst
[i
*4+2] = rgba
[i
][BCOMP
];
1536 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1541 dst
[i
*3+0] = rgba
[i
][BCOMP
];
1542 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1543 dst
[i
*3+2] = rgba
[i
][RCOMP
];
1548 dst
[i
*4+0] = rgba
[i
][BCOMP
];
1549 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1550 dst
[i
*4+2] = rgba
[i
][RCOMP
];
1551 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1556 dst
[i
*4+0] = rgba
[i
][ACOMP
];
1557 dst
[i
*4+1] = rgba
[i
][BCOMP
];
1558 dst
[i
*4+2] = rgba
[i
][GCOMP
];
1559 dst
[i
*4+3] = rgba
[i
][RCOMP
];
1563 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1565 if (dstPacking
->SwapBytes
) {
1566 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1570 case GL_HALF_FLOAT_NV
:
1572 GLhalfNV
*dst
= (GLhalfNV
*) dstAddr
;
1573 switch (dstFormat
) {
1576 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1580 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1584 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1588 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1592 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
1594 case GL_LUMINANCE_ALPHA
:
1596 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
1597 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1602 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1603 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1604 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1609 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1610 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1611 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1612 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1617 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1618 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1619 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1624 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1625 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1626 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1627 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1632 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1633 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1634 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1635 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1639 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1641 if (dstPacking
->SwapBytes
) {
1642 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1646 case GL_UNSIGNED_BYTE_3_3_2
:
1647 if (dstFormat
== GL_RGB
) {
1648 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1650 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
1651 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
1652 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
1656 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1657 if (dstFormat
== GL_RGB
) {
1658 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1660 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
1661 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
1662 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 5);
1666 case GL_UNSIGNED_SHORT_5_6_5
:
1667 if (dstFormat
== GL_RGB
) {
1668 GLushort
*dst
= (GLushort
*) dstAddr
;
1670 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1671 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1672 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
1676 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1677 if (dstFormat
== GL_RGB
) {
1678 GLushort
*dst
= (GLushort
*) dstAddr
;
1680 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1681 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1682 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
1686 case GL_UNSIGNED_SHORT_4_4_4_4
:
1687 if (dstFormat
== GL_RGBA
) {
1688 GLushort
*dst
= (GLushort
*) dstAddr
;
1690 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
1691 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1692 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1693 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1696 else if (dstFormat
== GL_BGRA
) {
1697 GLushort
*dst
= (GLushort
*) dstAddr
;
1699 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 12)
1700 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1701 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 4)
1702 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1705 else if (dstFormat
== GL_ABGR_EXT
) {
1706 GLushort
*dst
= (GLushort
*) dstAddr
;
1708 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 4)
1709 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1710 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 12)
1711 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) );
1715 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1716 if (dstFormat
== GL_RGBA
) {
1717 GLushort
*dst
= (GLushort
*) dstAddr
;
1719 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
1720 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1721 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1722 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1725 else if (dstFormat
== GL_BGRA
) {
1726 GLushort
*dst
= (GLushort
*) dstAddr
;
1728 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) )
1729 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1730 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 8)
1731 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1734 else if (dstFormat
== GL_ABGR_EXT
) {
1735 GLushort
*dst
= (GLushort
*) dstAddr
;
1737 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) )
1738 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1739 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1740 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12);
1744 case GL_UNSIGNED_SHORT_5_5_5_1
:
1745 if (dstFormat
== GL_RGBA
) {
1746 GLushort
*dst
= (GLushort
*) dstAddr
;
1748 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1749 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1750 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
1751 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1754 else if (dstFormat
== GL_BGRA
) {
1755 GLushort
*dst
= (GLushort
*) dstAddr
;
1757 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11)
1758 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1759 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 1)
1760 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1763 else if (dstFormat
== GL_ABGR_EXT
) {
1764 GLushort
*dst
= (GLushort
*) dstAddr
;
1766 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) << 11)
1767 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 6)
1768 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 1)
1769 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) );
1773 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1774 if (dstFormat
== GL_RGBA
) {
1775 GLushort
*dst
= (GLushort
*) dstAddr
;
1777 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1778 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1779 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
1780 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1783 else if (dstFormat
== GL_BGRA
) {
1784 GLushort
*dst
= (GLushort
*) dstAddr
;
1786 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) )
1787 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1788 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 10)
1789 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1792 else if (dstFormat
== GL_ABGR_EXT
) {
1793 GLushort
*dst
= (GLushort
*) dstAddr
;
1795 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) )
1796 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 5)
1797 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 10)
1798 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) << 15);
1802 case GL_UNSIGNED_INT_8_8_8_8
:
1803 if (dstFormat
== GL_RGBA
) {
1804 GLuint
*dst
= (GLuint
*) dstAddr
;
1806 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
1807 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1808 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1809 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1812 else if (dstFormat
== GL_BGRA
) {
1813 GLuint
*dst
= (GLuint
*) dstAddr
;
1815 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
1816 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1817 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
1818 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1821 else if (dstFormat
== GL_ABGR_EXT
) {
1822 GLuint
*dst
= (GLuint
*) dstAddr
;
1824 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
1825 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1826 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1827 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
1831 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1832 if (dstFormat
== GL_RGBA
) {
1833 GLuint
*dst
= (GLuint
*) dstAddr
;
1835 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
1836 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1837 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1838 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1841 else if (dstFormat
== GL_BGRA
) {
1842 GLuint
*dst
= (GLuint
*) dstAddr
;
1844 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
1845 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1846 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
1847 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1850 else if (dstFormat
== GL_ABGR_EXT
) {
1851 GLuint
*dst
= (GLuint
*) dstAddr
;
1853 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
1854 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1855 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1856 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
1860 case GL_UNSIGNED_INT_10_10_10_2
:
1861 if (dstFormat
== GL_RGBA
) {
1862 GLuint
*dst
= (GLuint
*) dstAddr
;
1864 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
1865 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1866 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
1867 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1870 else if (dstFormat
== GL_BGRA
) {
1871 GLuint
*dst
= (GLuint
*) dstAddr
;
1873 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
1874 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1875 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
1876 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1879 else if (dstFormat
== GL_ABGR_EXT
) {
1880 GLuint
*dst
= (GLuint
*) dstAddr
;
1882 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
1883 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
1884 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
1885 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
1889 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1890 if (dstFormat
== GL_RGBA
) {
1891 GLuint
*dst
= (GLuint
*) dstAddr
;
1893 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
1894 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1895 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
1896 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1899 else if (dstFormat
== GL_BGRA
) {
1900 GLuint
*dst
= (GLuint
*) dstAddr
;
1902 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
1903 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1904 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
1905 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1908 else if (dstFormat
== GL_ABGR_EXT
) {
1909 GLuint
*dst
= (GLuint
*) dstAddr
;
1911 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
1912 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
1913 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
1914 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
1919 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
1925 * Pack the given RGBA span into client memory at 'dest' address
1926 * in the given pixel format and type.
1927 * Optionally apply the enabled pixel transfer ops.
1928 * Pack into memory using the given packing params struct.
1929 * This is used by glReadPixels and glGetTexImage?D()
1930 * \param ctx - the context
1931 * n - number of pixels in the span
1933 * format - dest packing format
1934 * type - dest packing data type
1935 * destination - destination packing address
1936 * packing - pixel packing parameters
1937 * transferOps - bitmask of IMAGE_*_BIT operations to apply
1940 _mesa_pack_rgba_span_chan( GLcontext
*ctx
,
1941 GLuint n
, CONST GLchan srcRgba
[][4],
1942 GLenum dstFormat
, GLenum dstType
,
1944 const struct gl_pixelstore_attrib
*dstPacking
,
1947 ASSERT((ctx
->NewState
& _NEW_PIXEL
) == 0 || transferOps
== 0);
1949 /* Test for optimized case first */
1950 if (transferOps
== 0 && dstFormat
== GL_RGBA
&& dstType
== CHAN_TYPE
) {
1951 /* common simple case */
1952 MEMCPY(dstAddr
, srcRgba
, n
* 4 * sizeof(GLchan
));
1954 else if (transferOps
== 0 && dstFormat
== GL_RGB
&& dstType
== CHAN_TYPE
) {
1955 /* common simple case */
1957 GLchan
*dest
= (GLchan
*) dstAddr
;
1958 for (i
= 0; i
< n
; i
++) {
1959 dest
[0] = srcRgba
[i
][RCOMP
];
1960 dest
[1] = srcRgba
[i
][GCOMP
];
1961 dest
[2] = srcRgba
[i
][BCOMP
];
1965 else if (transferOps
== 0 && dstFormat
== GL_RGBA
&& dstType
== GL_UNSIGNED_BYTE
) {
1966 /* common simple case */
1968 GLubyte
*dest
= (GLubyte
*) dstAddr
;
1969 for (i
= 0; i
< n
; i
++) {
1970 dest
[0] = CHAN_TO_UBYTE(srcRgba
[i
][RCOMP
]);
1971 dest
[1] = CHAN_TO_UBYTE(srcRgba
[i
][GCOMP
]);
1972 dest
[2] = CHAN_TO_UBYTE(srcRgba
[i
][BCOMP
]);
1973 dest
[3] = CHAN_TO_UBYTE(srcRgba
[i
][ACOMP
]);
1978 /* general solution */
1980 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
1981 CHECKARRAY(rgba
, return); /* mac 32k limitation */
1983 assert(n
<= MAX_WIDTH
);
1984 /* convert color components to floating point */
1985 for (i
= 0; i
< n
; i
++) {
1986 rgba
[i
][RCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][RCOMP
]);
1987 rgba
[i
][GCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][GCOMP
]);
1988 rgba
[i
][BCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][BCOMP
]);
1989 rgba
[i
][ACOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][ACOMP
]);
1991 _mesa_pack_rgba_span_float(ctx
, n
, (const GLfloat (*)[4]) rgba
,
1992 dstFormat
, dstType
, dstAddr
,
1993 dstPacking
, transferOps
);
1994 UNDEFARRAY(rgba
); /* mac 32k limitation */
1999 #define SWAP2BYTE(VALUE) \
2001 GLubyte *bytes = (GLubyte *) &(VALUE); \
2002 GLubyte tmp = bytes[0]; \
2003 bytes[0] = bytes[1]; \
2007 #define SWAP4BYTE(VALUE) \
2009 GLubyte *bytes = (GLubyte *) &(VALUE); \
2010 GLubyte tmp = bytes[0]; \
2011 bytes[0] = bytes[3]; \
2014 bytes[1] = bytes[2]; \
2020 extract_uint_indexes(GLuint n
, GLuint indexes
[],
2021 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2022 const struct gl_pixelstore_attrib
*unpack
)
2024 assert(srcFormat
== GL_COLOR_INDEX
);
2026 ASSERT(srcType
== GL_BITMAP
||
2027 srcType
== GL_UNSIGNED_BYTE
||
2028 srcType
== GL_BYTE
||
2029 srcType
== GL_UNSIGNED_SHORT
||
2030 srcType
== GL_SHORT
||
2031 srcType
== GL_UNSIGNED_INT
||
2032 srcType
== GL_INT
||
2033 srcType
== GL_HALF_FLOAT_NV
||
2034 srcType
== GL_FLOAT
);
2039 GLubyte
*ubsrc
= (GLubyte
*) src
;
2040 if (unpack
->LsbFirst
) {
2041 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
2043 for (i
= 0; i
< n
; i
++) {
2044 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2055 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
2057 for (i
= 0; i
< n
; i
++) {
2058 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2070 case GL_UNSIGNED_BYTE
:
2073 const GLubyte
*s
= (const GLubyte
*) src
;
2074 for (i
= 0; i
< n
; i
++)
2081 const GLbyte
*s
= (const GLbyte
*) src
;
2082 for (i
= 0; i
< n
; i
++)
2086 case GL_UNSIGNED_SHORT
:
2089 const GLushort
*s
= (const GLushort
*) src
;
2090 if (unpack
->SwapBytes
) {
2091 for (i
= 0; i
< n
; i
++) {
2092 GLushort value
= s
[i
];
2098 for (i
= 0; i
< n
; i
++)
2106 const GLshort
*s
= (const GLshort
*) src
;
2107 if (unpack
->SwapBytes
) {
2108 for (i
= 0; i
< n
; i
++) {
2109 GLshort value
= s
[i
];
2115 for (i
= 0; i
< n
; i
++)
2120 case GL_UNSIGNED_INT
:
2123 const GLuint
*s
= (const GLuint
*) src
;
2124 if (unpack
->SwapBytes
) {
2125 for (i
= 0; i
< n
; i
++) {
2126 GLuint value
= s
[i
];
2132 for (i
= 0; i
< n
; i
++)
2140 const GLint
*s
= (const GLint
*) src
;
2141 if (unpack
->SwapBytes
) {
2142 for (i
= 0; i
< n
; i
++) {
2149 for (i
= 0; i
< n
; i
++)
2157 const GLfloat
*s
= (const GLfloat
*) src
;
2158 if (unpack
->SwapBytes
) {
2159 for (i
= 0; i
< n
; i
++) {
2160 GLfloat value
= s
[i
];
2162 indexes
[i
] = (GLuint
) value
;
2166 for (i
= 0; i
< n
; i
++)
2167 indexes
[i
] = (GLuint
) s
[i
];
2171 case GL_HALF_FLOAT_NV
:
2174 const GLhalfNV
*s
= (const GLhalfNV
*) src
;
2175 if (unpack
->SwapBytes
) {
2176 for (i
= 0; i
< n
; i
++) {
2177 GLhalfNV value
= s
[i
];
2179 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
2183 for (i
= 0; i
< n
; i
++)
2184 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
2189 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2196 * This function extracts floating point RGBA values from arbitrary
2197 * image data. srcFormat and srcType are the format and type parameters
2198 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2200 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2201 * implements the "Conversion to floating point", "Conversion to RGB",
2202 * and "Final Expansion to RGBA" operations.
2204 * Args: n - number of pixels
2205 * rgba - output colors
2206 * srcFormat - format of incoming data
2207 * srcType - data type of incoming data
2208 * src - source data pointer
2209 * swapBytes - perform byteswapping of incoming data?
2212 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2213 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2214 GLboolean swapBytes
)
2216 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2218 GLint rComp
, bComp
, gComp
, aComp
;
2220 ASSERT(srcFormat
== GL_RED
||
2221 srcFormat
== GL_GREEN
||
2222 srcFormat
== GL_BLUE
||
2223 srcFormat
== GL_ALPHA
||
2224 srcFormat
== GL_LUMINANCE
||
2225 srcFormat
== GL_LUMINANCE_ALPHA
||
2226 srcFormat
== GL_INTENSITY
||
2227 srcFormat
== GL_RGB
||
2228 srcFormat
== GL_BGR
||
2229 srcFormat
== GL_RGBA
||
2230 srcFormat
== GL_BGRA
||
2231 srcFormat
== GL_ABGR_EXT
);
2233 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2234 srcType
== GL_BYTE
||
2235 srcType
== GL_UNSIGNED_SHORT
||
2236 srcType
== GL_SHORT
||
2237 srcType
== GL_UNSIGNED_INT
||
2238 srcType
== GL_INT
||
2239 srcType
== GL_HALF_FLOAT_NV
||
2240 srcType
== GL_FLOAT
||
2241 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2242 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2243 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2244 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2245 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2246 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2247 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2248 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2249 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2250 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2251 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2252 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2254 rComp
= gComp
= bComp
= aComp
= -1;
2256 switch (srcFormat
) {
2259 greenIndex
= blueIndex
= alphaIndex
= -1;
2264 redIndex
= blueIndex
= alphaIndex
= -1;
2269 redIndex
= greenIndex
= alphaIndex
= -1;
2273 redIndex
= greenIndex
= blueIndex
= -1;
2278 redIndex
= greenIndex
= blueIndex
= 0;
2282 case GL_LUMINANCE_ALPHA
:
2283 redIndex
= greenIndex
= blueIndex
= 0;
2288 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
2339 _mesa_problem(NULL
, "bad srcFormat in extract float data");
2344 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
2345 if ((INDEX) < 0) { \
2347 for (i = 0; i < n; i++) { \
2348 rgba[i][CHANNEL] = DEFAULT; \
2351 else if (swapBytes) { \
2352 const TYPE *s = (const TYPE *) src; \
2354 for (i = 0; i < n; i++) { \
2355 TYPE value = s[INDEX]; \
2356 if (sizeof(TYPE) == 2) { \
2359 else if (sizeof(TYPE) == 4) { \
2362 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
2367 const TYPE *s = (const TYPE *) src; \
2369 for (i = 0; i < n; i++) { \
2370 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
2376 case GL_UNSIGNED_BYTE
:
2377 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2378 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2379 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2380 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2383 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2384 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2385 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2386 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
2388 case GL_UNSIGNED_SHORT
:
2389 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2390 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2391 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2392 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
2395 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2396 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2397 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2398 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
2400 case GL_UNSIGNED_INT
:
2401 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2402 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2403 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2404 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
2407 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2408 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2409 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2410 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
2413 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2414 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2415 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2416 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
2418 case GL_HALF_FLOAT_NV
:
2419 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfNV
, _mesa_half_to_float
);
2420 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfNV
, _mesa_half_to_float
);
2421 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfNV
, _mesa_half_to_float
);
2422 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfNV
, _mesa_half_to_float
);
2424 case GL_UNSIGNED_BYTE_3_3_2
:
2426 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2428 for (i
= 0; i
< n
; i
++) {
2429 GLubyte p
= ubsrc
[i
];
2430 rgba
[i
][RCOMP
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
2431 rgba
[i
][GCOMP
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
2432 rgba
[i
][BCOMP
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
2433 rgba
[i
][ACOMP
] = 1.0F
;
2437 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2439 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2441 for (i
= 0; i
< n
; i
++) {
2442 GLubyte p
= ubsrc
[i
];
2443 rgba
[i
][RCOMP
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
2444 rgba
[i
][GCOMP
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
2445 rgba
[i
][BCOMP
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
2446 rgba
[i
][ACOMP
] = 1.0F
;
2450 case GL_UNSIGNED_SHORT_5_6_5
:
2452 const GLushort
*ussrc
= (const GLushort
*) src
;
2454 for (i
= 0; i
< n
; i
++) {
2455 GLushort p
= ussrc
[i
];
2457 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2458 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2459 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2460 rgba
[i
][ACOMP
] = 1.0F
;
2464 const GLushort
*ussrc
= (const GLushort
*) src
;
2466 for (i
= 0; i
< n
; i
++) {
2467 GLushort p
= ussrc
[i
];
2468 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2469 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2470 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2471 rgba
[i
][ACOMP
] = 1.0F
;
2475 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2477 const GLushort
*ussrc
= (const GLushort
*) src
;
2479 for (i
= 0; i
< n
; i
++) {
2480 GLushort p
= ussrc
[i
];
2482 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2483 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2484 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2485 rgba
[i
][ACOMP
] = 1.0F
;
2489 const GLushort
*ussrc
= (const GLushort
*) src
;
2491 for (i
= 0; i
< n
; i
++) {
2492 GLushort p
= ussrc
[i
];
2493 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2494 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2495 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2496 rgba
[i
][ACOMP
] = 1.0F
;
2500 case GL_UNSIGNED_SHORT_4_4_4_4
:
2502 const GLushort
*ussrc
= (const GLushort
*) src
;
2504 for (i
= 0; i
< n
; i
++) {
2505 GLushort p
= ussrc
[i
];
2507 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2508 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2509 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2510 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2514 const GLushort
*ussrc
= (const GLushort
*) src
;
2516 for (i
= 0; i
< n
; i
++) {
2517 GLushort p
= ussrc
[i
];
2518 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2519 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2520 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2521 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2525 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2527 const GLushort
*ussrc
= (const GLushort
*) src
;
2529 for (i
= 0; i
< n
; i
++) {
2530 GLushort p
= ussrc
[i
];
2532 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2533 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2534 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2535 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2539 const GLushort
*ussrc
= (const GLushort
*) src
;
2541 for (i
= 0; i
< n
; i
++) {
2542 GLushort p
= ussrc
[i
];
2543 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2544 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2545 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2546 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2550 case GL_UNSIGNED_SHORT_5_5_5_1
:
2552 const GLushort
*ussrc
= (const GLushort
*) src
;
2554 for (i
= 0; i
< n
; i
++) {
2555 GLushort p
= ussrc
[i
];
2557 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2558 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2559 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2560 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2564 const GLushort
*ussrc
= (const GLushort
*) src
;
2566 for (i
= 0; i
< n
; i
++) {
2567 GLushort p
= ussrc
[i
];
2568 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2569 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2570 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2571 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2575 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2577 const GLushort
*ussrc
= (const GLushort
*) src
;
2579 for (i
= 0; i
< n
; i
++) {
2580 GLushort p
= ussrc
[i
];
2582 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2583 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2584 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2585 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2589 const GLushort
*ussrc
= (const GLushort
*) src
;
2591 for (i
= 0; i
< n
; i
++) {
2592 GLushort p
= ussrc
[i
];
2593 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2594 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2595 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2596 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2600 case GL_UNSIGNED_INT_8_8_8_8
:
2602 const GLuint
*uisrc
= (const GLuint
*) src
;
2604 for (i
= 0; i
< n
; i
++) {
2605 GLuint p
= uisrc
[i
];
2606 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2607 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2608 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2609 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2613 const GLuint
*uisrc
= (const GLuint
*) src
;
2615 for (i
= 0; i
< n
; i
++) {
2616 GLuint p
= uisrc
[i
];
2617 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2618 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2619 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2620 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2624 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2626 const GLuint
*uisrc
= (const GLuint
*) src
;
2628 for (i
= 0; i
< n
; i
++) {
2629 GLuint p
= uisrc
[i
];
2630 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2631 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2632 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2633 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2637 const GLuint
*uisrc
= (const GLuint
*) src
;
2639 for (i
= 0; i
< n
; i
++) {
2640 GLuint p
= uisrc
[i
];
2641 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2642 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2643 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2644 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2648 case GL_UNSIGNED_INT_10_10_10_2
:
2650 const GLuint
*uisrc
= (const GLuint
*) src
;
2652 for (i
= 0; i
< n
; i
++) {
2653 GLuint p
= uisrc
[i
];
2655 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2656 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2657 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2658 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2662 const GLuint
*uisrc
= (const GLuint
*) src
;
2664 for (i
= 0; i
< n
; i
++) {
2665 GLuint p
= uisrc
[i
];
2666 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2667 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2668 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2669 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2673 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2675 const GLuint
*uisrc
= (const GLuint
*) src
;
2677 for (i
= 0; i
< n
; i
++) {
2678 GLuint p
= uisrc
[i
];
2680 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2681 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2682 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2683 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2687 const GLuint
*uisrc
= (const GLuint
*) src
;
2689 for (i
= 0; i
< n
; i
++) {
2690 GLuint p
= uisrc
[i
];
2691 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2692 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2693 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2694 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2699 _mesa_problem(NULL
, "bad srcType in extract float data");
2706 * Unpack a row of color image data from a client buffer according to
2707 * the pixel unpacking parameters.
2708 * Return GLchan values in the specified dest image format.
2709 * This is used by glDrawPixels and glTexImage?D().
2710 * \param ctx - the context
2711 * n - number of pixels in the span
2712 * dstFormat - format of destination color array
2713 * dest - the destination color array
2714 * srcFormat - source image format
2715 * srcType - source image data type
2716 * source - source image pointer
2717 * srcPacking - pixel unpacking parameters
2718 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
2720 * XXX perhaps expand this to process whole images someday.
2723 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
2724 GLuint n
, GLenum dstFormat
, GLchan dest
[],
2725 GLenum srcFormat
, GLenum srcType
,
2726 const GLvoid
*source
,
2727 const struct gl_pixelstore_attrib
*srcPacking
,
2728 GLuint transferOps
)
2730 ASSERT(dstFormat
== GL_ALPHA
||
2731 dstFormat
== GL_LUMINANCE
||
2732 dstFormat
== GL_LUMINANCE_ALPHA
||
2733 dstFormat
== GL_INTENSITY
||
2734 dstFormat
== GL_RGB
||
2735 dstFormat
== GL_RGBA
||
2736 dstFormat
== GL_COLOR_INDEX
);
2738 ASSERT(srcFormat
== GL_RED
||
2739 srcFormat
== GL_GREEN
||
2740 srcFormat
== GL_BLUE
||
2741 srcFormat
== GL_ALPHA
||
2742 srcFormat
== GL_LUMINANCE
||
2743 srcFormat
== GL_LUMINANCE_ALPHA
||
2744 srcFormat
== GL_INTENSITY
||
2745 srcFormat
== GL_RGB
||
2746 srcFormat
== GL_BGR
||
2747 srcFormat
== GL_RGBA
||
2748 srcFormat
== GL_BGRA
||
2749 srcFormat
== GL_ABGR_EXT
||
2750 srcFormat
== GL_COLOR_INDEX
);
2752 ASSERT(srcType
== GL_BITMAP
||
2753 srcType
== GL_UNSIGNED_BYTE
||
2754 srcType
== GL_BYTE
||
2755 srcType
== GL_UNSIGNED_SHORT
||
2756 srcType
== GL_SHORT
||
2757 srcType
== GL_UNSIGNED_INT
||
2758 srcType
== GL_INT
||
2759 srcType
== GL_HALF_FLOAT_NV
||
2760 srcType
== GL_FLOAT
||
2761 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2762 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2763 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2764 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2765 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2766 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2767 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2768 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2769 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2770 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2771 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2772 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2774 /* Try simple cases first */
2775 if (transferOps
== 0 ){
2776 if (srcType
== CHAN_TYPE
) {
2777 if (dstFormat
== GL_RGBA
) {
2778 if (srcFormat
== GL_RGBA
) {
2779 MEMCPY( dest
, source
, n
* 4 * sizeof(GLchan
) );
2782 else if (srcFormat
== GL_RGB
) {
2784 const GLchan
*src
= (const GLchan
*) source
;
2786 for (i
= 0; i
< n
; i
++) {
2797 else if (dstFormat
== GL_RGB
) {
2798 if (srcFormat
== GL_RGB
) {
2799 MEMCPY( dest
, source
, n
* 3 * sizeof(GLchan
) );
2802 else if (srcFormat
== GL_RGBA
) {
2804 const GLchan
*src
= (const GLchan
*) source
;
2806 for (i
= 0; i
< n
; i
++) {
2816 else if (dstFormat
== srcFormat
) {
2817 GLint comps
= _mesa_components_in_format(srcFormat
);
2819 MEMCPY( dest
, source
, n
* comps
* sizeof(GLchan
) );
2824 * Common situation, loading 8bit RGBA/RGB source images
2825 * into 16/32 bit destination. (OSMesa16/32)
2827 else if (srcType
== GL_UNSIGNED_BYTE
) {
2828 if (dstFormat
== GL_RGBA
) {
2829 if (srcFormat
== GL_RGB
) {
2831 const GLubyte
*src
= (const GLubyte
*) source
;
2833 for (i
= 0; i
< n
; i
++) {
2834 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2835 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2836 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2843 else if (srcFormat
== GL_RGBA
) {
2845 const GLubyte
*src
= (const GLubyte
*) source
;
2847 for (i
= 0; i
< n
; i
++) {
2848 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2849 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2850 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2851 dst
[3] = UBYTE_TO_CHAN(src
[3]);
2858 else if (dstFormat
== GL_RGB
) {
2859 if (srcFormat
== GL_RGB
) {
2861 const GLubyte
*src
= (const GLubyte
*) source
;
2863 for (i
= 0; i
< n
; i
++) {
2864 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2865 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2866 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2872 else if (srcFormat
== GL_RGBA
) {
2874 const GLubyte
*src
= (const GLubyte
*) source
;
2876 for (i
= 0; i
< n
; i
++) {
2877 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2878 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2879 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2890 /* general solution begins here */
2892 GLint dstComponents
;
2893 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2894 GLint dstLuminanceIndex
, dstIntensityIndex
;
2895 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
2896 CHECKARRAY(rgba
, return); /* mac 32k limitation */
2898 dstComponents
= _mesa_components_in_format( dstFormat
);
2899 /* source & dest image formats should have been error checked by now */
2900 assert(dstComponents
> 0);
2903 * Extract image data and convert to RGBA floats
2905 assert(n
<= MAX_WIDTH
);
2906 if (srcFormat
== GL_COLOR_INDEX
) {
2907 GLuint indexes
[MAX_WIDTH
];
2908 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2911 if (dstFormat
== GL_COLOR_INDEX
2912 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
2913 _mesa_map_ci(ctx
, n
, indexes
);
2915 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
2916 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2919 if (dstFormat
== GL_COLOR_INDEX
) {
2920 /* convert to GLchan and return */
2922 for (i
= 0; i
< n
; i
++) {
2923 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
2925 UNDEFARRAY(rgba
); /* mac 32k limitation */
2929 /* Convert indexes to RGBA */
2930 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
2933 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
2934 * with color indexes.
2936 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
2939 /* non-color index data */
2940 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2941 srcPacking
->SwapBytes
);
2944 /* Need to clamp if returning GLubytes or GLushorts */
2945 #if CHAN_TYPE != GL_FLOAT
2946 transferOps
|= IMAGE_CLAMP_BIT
;
2950 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
2953 /* Now determine which color channels we need to produce.
2954 * And determine the dest index (offset) within each color tuple.
2956 switch (dstFormat
) {
2959 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2960 dstLuminanceIndex
= dstIntensityIndex
= -1;
2963 dstLuminanceIndex
= 0;
2964 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2965 dstIntensityIndex
= -1;
2967 case GL_LUMINANCE_ALPHA
:
2968 dstLuminanceIndex
= 0;
2970 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2971 dstIntensityIndex
= -1;
2974 dstIntensityIndex
= 0;
2975 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2976 dstLuminanceIndex
= -1;
2982 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
2989 dstLuminanceIndex
= dstIntensityIndex
= -1;
2992 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_chan_span()");
2993 UNDEFARRAY(rgba
); /* mac 32k limitation */
2998 /* Now return the GLchan data in the requested dstFormat */
3000 if (dstRedIndex
>= 0) {
3003 for (i
= 0; i
< n
; i
++) {
3004 CLAMPED_FLOAT_TO_CHAN(dst
[dstRedIndex
], rgba
[i
][RCOMP
]);
3005 dst
+= dstComponents
;
3009 if (dstGreenIndex
>= 0) {
3012 for (i
= 0; i
< n
; i
++) {
3013 CLAMPED_FLOAT_TO_CHAN(dst
[dstGreenIndex
], rgba
[i
][GCOMP
]);
3014 dst
+= dstComponents
;
3018 if (dstBlueIndex
>= 0) {
3021 for (i
= 0; i
< n
; i
++) {
3022 CLAMPED_FLOAT_TO_CHAN(dst
[dstBlueIndex
], rgba
[i
][BCOMP
]);
3023 dst
+= dstComponents
;
3027 if (dstAlphaIndex
>= 0) {
3030 for (i
= 0; i
< n
; i
++) {
3031 CLAMPED_FLOAT_TO_CHAN(dst
[dstAlphaIndex
], rgba
[i
][ACOMP
]);
3032 dst
+= dstComponents
;
3036 if (dstIntensityIndex
>= 0) {
3039 assert(dstIntensityIndex
== 0);
3040 assert(dstComponents
== 1);
3041 for (i
= 0; i
< n
; i
++) {
3042 /* Intensity comes from red channel */
3043 CLAMPED_FLOAT_TO_CHAN(dst
[i
], rgba
[i
][RCOMP
]);
3047 if (dstLuminanceIndex
>= 0) {
3050 assert(dstLuminanceIndex
== 0);
3051 for (i
= 0; i
< n
; i
++) {
3052 /* Luminance comes from red channel */
3053 CLAMPED_FLOAT_TO_CHAN(dst
[0], rgba
[i
][RCOMP
]);
3054 dst
+= dstComponents
;
3057 UNDEFARRAY(rgba
); /* mac 32k limitation */
3063 * Same as _mesa_unpack_color_span_chan(), but return GLfloat data
3064 * instead of GLchan.
3067 _mesa_unpack_color_span_float( GLcontext
*ctx
,
3068 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
3069 GLenum srcFormat
, GLenum srcType
,
3070 const GLvoid
*source
,
3071 const struct gl_pixelstore_attrib
*srcPacking
,
3072 GLuint transferOps
)
3074 ASSERT(dstFormat
== GL_ALPHA
||
3075 dstFormat
== GL_LUMINANCE
||
3076 dstFormat
== GL_LUMINANCE_ALPHA
||
3077 dstFormat
== GL_INTENSITY
||
3078 dstFormat
== GL_RGB
||
3079 dstFormat
== GL_RGBA
||
3080 dstFormat
== GL_COLOR_INDEX
);
3082 ASSERT(srcFormat
== GL_RED
||
3083 srcFormat
== GL_GREEN
||
3084 srcFormat
== GL_BLUE
||
3085 srcFormat
== GL_ALPHA
||
3086 srcFormat
== GL_LUMINANCE
||
3087 srcFormat
== GL_LUMINANCE_ALPHA
||
3088 srcFormat
== GL_INTENSITY
||
3089 srcFormat
== GL_RGB
||
3090 srcFormat
== GL_BGR
||
3091 srcFormat
== GL_RGBA
||
3092 srcFormat
== GL_BGRA
||
3093 srcFormat
== GL_ABGR_EXT
||
3094 srcFormat
== GL_COLOR_INDEX
);
3096 ASSERT(srcType
== GL_BITMAP
||
3097 srcType
== GL_UNSIGNED_BYTE
||
3098 srcType
== GL_BYTE
||
3099 srcType
== GL_UNSIGNED_SHORT
||
3100 srcType
== GL_SHORT
||
3101 srcType
== GL_UNSIGNED_INT
||
3102 srcType
== GL_INT
||
3103 srcType
== GL_HALF_FLOAT_NV
||
3104 srcType
== GL_FLOAT
||
3105 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
3106 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
3107 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
3108 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
3109 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
3110 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
3111 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
3112 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
3113 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
3114 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
3115 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
3116 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
3118 /* general solution, no special cases, yet */
3120 GLint dstComponents
;
3121 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
3122 GLint dstLuminanceIndex
, dstIntensityIndex
;
3123 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
3124 CHECKARRAY(rgba
, return); /* mac 32k limitation */
3126 dstComponents
= _mesa_components_in_format( dstFormat
);
3127 /* source & dest image formats should have been error checked by now */
3128 assert(dstComponents
> 0);
3131 * Extract image data and convert to RGBA floats
3133 assert(n
<= MAX_WIDTH
);
3134 if (srcFormat
== GL_COLOR_INDEX
) {
3135 GLuint indexes
[MAX_WIDTH
];
3136 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
3139 if (dstFormat
== GL_COLOR_INDEX
3140 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
3141 _mesa_map_ci(ctx
, n
, indexes
);
3143 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3144 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3147 if (dstFormat
== GL_COLOR_INDEX
) {
3148 /* convert to GLchan and return */
3150 for (i
= 0; i
< n
; i
++) {
3151 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
3153 UNDEFARRAY(rgba
); /* mac 32k limitation */
3157 /* Convert indexes to RGBA */
3158 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
3161 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3162 * with color indexes.
3164 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
3167 /* non-color index data */
3168 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
3169 srcPacking
->SwapBytes
);
3173 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3176 /* Now determine which color channels we need to produce.
3177 * And determine the dest index (offset) within each color tuple.
3179 switch (dstFormat
) {
3182 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3183 dstLuminanceIndex
= dstIntensityIndex
= -1;
3186 dstLuminanceIndex
= 0;
3187 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3188 dstIntensityIndex
= -1;
3190 case GL_LUMINANCE_ALPHA
:
3191 dstLuminanceIndex
= 0;
3193 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3194 dstIntensityIndex
= -1;
3197 dstIntensityIndex
= 0;
3198 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3199 dstLuminanceIndex
= -1;
3205 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3212 dstLuminanceIndex
= dstIntensityIndex
= -1;
3215 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
3216 UNDEFARRAY(rgba
); /* mac 32k limitation */
3220 /* Now pack results in the requested dstFormat */
3221 if (dstRedIndex
>= 0) {
3222 GLfloat
*dst
= dest
;
3224 for (i
= 0; i
< n
; i
++) {
3225 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3226 dst
+= dstComponents
;
3230 if (dstGreenIndex
>= 0) {
3231 GLfloat
*dst
= dest
;
3233 for (i
= 0; i
< n
; i
++) {
3234 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3235 dst
+= dstComponents
;
3239 if (dstBlueIndex
>= 0) {
3240 GLfloat
*dst
= dest
;
3242 for (i
= 0; i
< n
; i
++) {
3243 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3244 dst
+= dstComponents
;
3248 if (dstAlphaIndex
>= 0) {
3249 GLfloat
*dst
= dest
;
3251 for (i
= 0; i
< n
; i
++) {
3252 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3253 dst
+= dstComponents
;
3257 if (dstIntensityIndex
>= 0) {
3258 GLfloat
*dst
= dest
;
3260 assert(dstIntensityIndex
== 0);
3261 assert(dstComponents
== 1);
3262 for (i
= 0; i
< n
; i
++) {
3263 /* Intensity comes from red channel */
3264 dst
[i
] = rgba
[i
][RCOMP
];
3268 if (dstLuminanceIndex
>= 0) {
3269 GLfloat
*dst
= dest
;
3271 assert(dstLuminanceIndex
== 0);
3272 for (i
= 0; i
< n
; i
++) {
3273 /* Luminance comes from red channel */
3274 dst
[0] = rgba
[i
][RCOMP
];
3275 dst
+= dstComponents
;
3278 UNDEFARRAY(rgba
); /* mac 32k limitation */
3284 * Unpack a row of color index data from a client buffer according to
3285 * the pixel unpacking parameters.
3286 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
3288 * Args: ctx - the context
3289 * n - number of pixels
3290 * dstType - destination data type
3291 * dest - destination array
3292 * srcType - source pixel type
3293 * source - source data pointer
3294 * srcPacking - pixel unpacking parameters
3295 * transferOps - the pixel transfer operations to apply
3298 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
3299 GLenum dstType
, GLvoid
*dest
,
3300 GLenum srcType
, const GLvoid
*source
,
3301 const struct gl_pixelstore_attrib
*srcPacking
,
3302 GLuint transferOps
)
3304 ASSERT(srcType
== GL_BITMAP
||
3305 srcType
== GL_UNSIGNED_BYTE
||
3306 srcType
== GL_BYTE
||
3307 srcType
== GL_UNSIGNED_SHORT
||
3308 srcType
== GL_SHORT
||
3309 srcType
== GL_UNSIGNED_INT
||
3310 srcType
== GL_INT
||
3311 srcType
== GL_HALF_FLOAT_NV
||
3312 srcType
== GL_FLOAT
);
3314 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3315 dstType
== GL_UNSIGNED_SHORT
||
3316 dstType
== GL_UNSIGNED_INT
);
3319 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3322 * Try simple cases first
3324 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
3325 && dstType
== GL_UNSIGNED_BYTE
) {
3326 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
3328 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
3329 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
3330 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
3336 GLuint indexes
[MAX_WIDTH
];
3337 assert(n
<= MAX_WIDTH
);
3339 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3342 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3343 /* shift and offset indexes */
3344 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3346 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3347 /* Apply lookup table */
3348 _mesa_map_ci(ctx
, n
, indexes
);
3351 /* convert to dest type */
3353 case GL_UNSIGNED_BYTE
:
3355 GLubyte
*dst
= (GLubyte
*) dest
;
3357 for (i
= 0; i
< n
; i
++) {
3358 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3362 case GL_UNSIGNED_SHORT
:
3364 GLuint
*dst
= (GLuint
*) dest
;
3366 for (i
= 0; i
< n
; i
++) {
3367 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3371 case GL_UNSIGNED_INT
:
3372 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
3375 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
3382 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
3383 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
3384 const struct gl_pixelstore_attrib
*dstPacking
,
3385 GLuint transferOps
)
3387 GLuint indexes
[MAX_WIDTH
];
3389 ASSERT(n
<= MAX_WIDTH
);
3391 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3393 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
3394 /* make a copy of input */
3395 MEMCPY(indexes
, source
, n
* sizeof(GLuint
));
3396 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3397 _mesa_shift_and_offset_ci( ctx
, n
, indexes
);
3399 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3400 _mesa_map_ci(ctx
, n
, indexes
);
3406 case GL_UNSIGNED_BYTE
:
3408 GLubyte
*dst
= (GLubyte
*) dest
;
3410 for (i
= 0; i
< n
; i
++) {
3411 *dst
++ = (GLubyte
) source
[i
];
3417 GLbyte
*dst
= (GLbyte
*) dest
;
3419 for (i
= 0; i
< n
; i
++) {
3420 dst
[i
] = (GLbyte
) source
[i
];
3424 case GL_UNSIGNED_SHORT
:
3426 GLushort
*dst
= (GLushort
*) dest
;
3428 for (i
= 0; i
< n
; i
++) {
3429 dst
[i
] = (GLushort
) source
[i
];
3431 if (dstPacking
->SwapBytes
) {
3432 _mesa_swap2( (GLushort
*) dst
, n
);
3438 GLshort
*dst
= (GLshort
*) dest
;
3440 for (i
= 0; i
< n
; i
++) {
3441 dst
[i
] = (GLshort
) source
[i
];
3443 if (dstPacking
->SwapBytes
) {
3444 _mesa_swap2( (GLushort
*) dst
, n
);
3448 case GL_UNSIGNED_INT
:
3450 GLuint
*dst
= (GLuint
*) dest
;
3452 for (i
= 0; i
< n
; i
++) {
3453 dst
[i
] = (GLuint
) source
[i
];
3455 if (dstPacking
->SwapBytes
) {
3456 _mesa_swap4( (GLuint
*) dst
, n
);
3462 GLint
*dst
= (GLint
*) dest
;
3464 for (i
= 0; i
< n
; i
++) {
3465 dst
[i
] = (GLint
) source
[i
];
3467 if (dstPacking
->SwapBytes
) {
3468 _mesa_swap4( (GLuint
*) dst
, n
);
3474 GLfloat
*dst
= (GLfloat
*) dest
;
3476 for (i
= 0; i
< n
; i
++) {
3477 dst
[i
] = (GLfloat
) source
[i
];
3479 if (dstPacking
->SwapBytes
) {
3480 _mesa_swap4( (GLuint
*) dst
, n
);
3484 case GL_HALF_FLOAT_NV
:
3486 GLhalfNV
*dst
= (GLhalfNV
*) dest
;
3488 for (i
= 0; i
< n
; i
++) {
3489 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
3491 if (dstPacking
->SwapBytes
) {
3492 _mesa_swap2( (GLushort
*) dst
, n
);
3497 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3503 * Unpack a row of stencil data from a client buffer according to
3504 * the pixel unpacking parameters.
3505 * This is (or will be) used by glDrawPixels
3507 * Args: ctx - the context
3508 * n - number of pixels
3509 * dstType - destination data type
3510 * dest - destination array
3511 * srcType - source pixel type
3512 * source - source data pointer
3513 * srcPacking - pixel unpacking parameters
3514 * transferOps - apply offset/bias/lookup ops?
3517 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3518 GLenum dstType
, GLvoid
*dest
,
3519 GLenum srcType
, const GLvoid
*source
,
3520 const struct gl_pixelstore_attrib
*srcPacking
,
3521 GLuint transferOps
)
3523 ASSERT(srcType
== GL_BITMAP
||
3524 srcType
== GL_UNSIGNED_BYTE
||
3525 srcType
== GL_BYTE
||
3526 srcType
== GL_UNSIGNED_SHORT
||
3527 srcType
== GL_SHORT
||
3528 srcType
== GL_UNSIGNED_INT
||
3529 srcType
== GL_INT
||
3530 srcType
== GL_HALF_FLOAT_NV
||
3531 srcType
== GL_FLOAT
);
3533 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3534 dstType
== GL_UNSIGNED_SHORT
||
3535 dstType
== GL_UNSIGNED_INT
);
3537 /* only shift and offset apply to stencil */
3538 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
3541 * Try simple cases first
3543 if (transferOps
== 0 &&
3544 srcType
== GL_UNSIGNED_BYTE
&&
3545 dstType
== GL_UNSIGNED_BYTE
) {
3546 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
3548 else if (transferOps
== 0 &&
3549 srcType
== GL_UNSIGNED_INT
&&
3550 dstType
== GL_UNSIGNED_INT
&&
3551 !srcPacking
->SwapBytes
) {
3552 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
3558 GLuint indexes
[MAX_WIDTH
];
3559 assert(n
<= MAX_WIDTH
);
3561 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3565 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3566 /* shift and offset indexes */
3567 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3570 if (ctx
->Pixel
.MapStencilFlag
) {
3571 /* Apply stencil lookup table */
3572 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
3575 indexes
[i
] = ctx
->Pixel
.MapStoS
[ indexes
[i
] & mask
];
3580 /* convert to dest type */
3582 case GL_UNSIGNED_BYTE
:
3584 GLubyte
*dst
= (GLubyte
*) dest
;
3586 for (i
= 0; i
< n
; i
++) {
3587 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3591 case GL_UNSIGNED_SHORT
:
3593 GLuint
*dst
= (GLuint
*) dest
;
3595 for (i
= 0; i
< n
; i
++) {
3596 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3600 case GL_UNSIGNED_INT
:
3601 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
3604 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
3611 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3612 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
3613 const struct gl_pixelstore_attrib
*dstPacking
)
3615 GLstencil stencil
[MAX_WIDTH
];
3617 ASSERT(n
<= MAX_WIDTH
);
3619 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
3620 ctx
->Pixel
.MapStencilFlag
) {
3621 /* make a copy of input */
3622 MEMCPY(stencil
, source
, n
* sizeof(GLstencil
));
3623 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
3624 _mesa_shift_and_offset_stencil( ctx
, n
, stencil
);
3626 if (ctx
->Pixel
.MapStencilFlag
) {
3627 _mesa_map_stencil( ctx
, n
, stencil
);
3633 case GL_UNSIGNED_BYTE
:
3634 if (sizeof(GLstencil
) == 8) {
3635 MEMCPY( dest
, source
, n
);
3638 GLubyte
*dst
= (GLubyte
*) dest
;
3641 dst
[i
] = (GLubyte
) source
[i
];
3646 if (sizeof(GLstencil
) == 8) {
3647 MEMCPY( dest
, source
, n
);
3650 GLbyte
*dst
= (GLbyte
*) dest
;
3653 dst
[i
] = (GLbyte
) source
[i
];
3657 case GL_UNSIGNED_SHORT
:
3659 GLushort
*dst
= (GLushort
*) dest
;
3662 dst
[i
] = (GLushort
) source
[i
];
3664 if (dstPacking
->SwapBytes
) {
3665 _mesa_swap2( (GLushort
*) dst
, n
);
3671 GLshort
*dst
= (GLshort
*) dest
;
3674 dst
[i
] = (GLshort
) source
[i
];
3676 if (dstPacking
->SwapBytes
) {
3677 _mesa_swap2( (GLushort
*) dst
, n
);
3681 case GL_UNSIGNED_INT
:
3683 GLuint
*dst
= (GLuint
*) dest
;
3686 dst
[i
] = (GLuint
) source
[i
];
3688 if (dstPacking
->SwapBytes
) {
3689 _mesa_swap4( (GLuint
*) dst
, n
);
3695 GLint
*dst
= (GLint
*) dest
;
3698 *dst
++ = (GLint
) source
[i
];
3700 if (dstPacking
->SwapBytes
) {
3701 _mesa_swap4( (GLuint
*) dst
, n
);
3707 GLfloat
*dst
= (GLfloat
*) dest
;
3710 dst
[i
] = (GLfloat
) source
[i
];
3712 if (dstPacking
->SwapBytes
) {
3713 _mesa_swap4( (GLuint
*) dst
, n
);
3717 case GL_HALF_FLOAT_NV
:
3719 GLhalfNV
*dst
= (GLhalfNV
*) dest
;
3722 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
3724 if (dstPacking
->SwapBytes
) {
3725 _mesa_swap2( (GLushort
*) dst
, n
);
3730 if (dstPacking
->LsbFirst
) {
3731 GLubyte
*dst
= (GLubyte
*) dest
;
3734 for (i
= 0; i
< n
; i
++) {
3737 *dst
|= ((source
[i
] != 0) << shift
);
3746 GLubyte
*dst
= (GLubyte
*) dest
;
3749 for (i
= 0; i
< n
; i
++) {
3752 *dst
|= ((source
[i
] != 0) << shift
);
3762 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3768 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
, GLfloat
*dest
,
3769 GLenum srcType
, const GLvoid
*source
,
3770 const struct gl_pixelstore_attrib
*srcPacking
)
3776 const GLubyte
*src
= (const GLubyte
*) source
;
3777 for (i
= 0; i
< n
; i
++) {
3778 dest
[i
] = BYTE_TO_FLOAT(src
[i
]);
3782 case GL_UNSIGNED_BYTE
:
3785 const GLubyte
*src
= (const GLubyte
*) source
;
3786 for (i
= 0; i
< n
; i
++) {
3787 dest
[i
] = UBYTE_TO_FLOAT(src
[i
]);
3794 const GLshort
*src
= (const GLshort
*) source
;
3795 for (i
= 0; i
< n
; i
++) {
3796 dest
[i
] = SHORT_TO_FLOAT(src
[i
]);
3800 case GL_UNSIGNED_SHORT
:
3803 const GLushort
*src
= (const GLushort
*) source
;
3804 for (i
= 0; i
< n
; i
++) {
3805 dest
[i
] = USHORT_TO_FLOAT(src
[i
]);
3812 const GLint
*src
= (const GLint
*) source
;
3813 for (i
= 0; i
< n
; i
++) {
3814 dest
[i
] = INT_TO_FLOAT(src
[i
]);
3818 case GL_UNSIGNED_INT
:
3821 const GLuint
*src
= (const GLuint
*) source
;
3822 for (i
= 0; i
< n
; i
++) {
3823 dest
[i
] = UINT_TO_FLOAT(src
[i
]);
3828 MEMCPY(dest
, source
, n
* sizeof(GLfloat
));
3830 case GL_HALF_FLOAT_NV
:
3833 const GLhalfNV
*src
= (const GLhalfNV
*) source
;
3834 for (i
= 0; i
< n
; i
++) {
3835 dest
[i
] = _mesa_half_to_float(src
[i
]);
3840 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
3845 /* apply depth scale and bias and clamp to [0,1] */
3846 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
3848 for (i
= 0; i
< n
; i
++) {
3849 GLfloat d
= dest
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
3850 dest
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
3857 * Pack an array of depth values. The values are floats in [0,1].
3860 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
3861 GLenum dstType
, const GLfloat
*depthSpan
,
3862 const struct gl_pixelstore_attrib
*dstPacking
)
3864 GLfloat depthCopy
[MAX_WIDTH
];
3865 const GLboolean bias_or_scale
= ctx
->Pixel
.DepthBias
!= 0.0 ||
3866 ctx
->Pixel
.DepthScale
!= 1.0;
3868 ASSERT(n
<= MAX_WIDTH
);
3870 if (bias_or_scale
) {
3872 for (i
= 0; i
< n
; i
++) {
3874 d
= depthSpan
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
3875 depthCopy
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
3877 depthSpan
= depthCopy
;
3881 case GL_UNSIGNED_BYTE
:
3883 GLubyte
*dst
= (GLubyte
*) dest
;
3885 for (i
= 0; i
< n
; i
++) {
3886 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
3892 GLbyte
*dst
= (GLbyte
*) dest
;
3894 for (i
= 0; i
< n
; i
++) {
3895 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
3899 case GL_UNSIGNED_SHORT
:
3901 GLushort
*dst
= (GLushort
*) dest
;
3903 for (i
= 0; i
< n
; i
++) {
3904 dst
[i
] = FLOAT_TO_USHORT( depthSpan
[i
] );
3906 if (dstPacking
->SwapBytes
) {
3907 _mesa_swap2( (GLushort
*) dst
, n
);
3913 GLshort
*dst
= (GLshort
*) dest
;
3915 for (i
= 0; i
< n
; i
++) {
3916 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
3918 if (dstPacking
->SwapBytes
) {
3919 _mesa_swap2( (GLushort
*) dst
, n
);
3923 case GL_UNSIGNED_INT
:
3925 GLuint
*dst
= (GLuint
*) dest
;
3927 for (i
= 0; i
< n
; i
++) {
3928 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
3930 if (dstPacking
->SwapBytes
) {
3931 _mesa_swap4( (GLuint
*) dst
, n
);
3937 GLint
*dst
= (GLint
*) dest
;
3939 for (i
= 0; i
< n
; i
++) {
3940 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
3942 if (dstPacking
->SwapBytes
) {
3943 _mesa_swap4( (GLuint
*) dst
, n
);
3949 GLfloat
*dst
= (GLfloat
*) dest
;
3951 for (i
= 0; i
< n
; i
++) {
3952 dst
[i
] = depthSpan
[i
];
3954 if (dstPacking
->SwapBytes
) {
3955 _mesa_swap4( (GLuint
*) dst
, n
);
3959 case GL_HALF_FLOAT_NV
:
3961 GLhalfNV
*dst
= (GLhalfNV
*) dest
;
3963 for (i
= 0; i
< n
; i
++) {
3964 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
3966 if (dstPacking
->SwapBytes
) {
3967 _mesa_swap2( (GLushort
*) dst
, n
);
3972 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
3978 * Unpack image data. Apply byteswapping, byte flipping (bitmap).
3979 * Return all image data in a contiguous block.
3982 _mesa_unpack_image( GLsizei width
, GLsizei height
, GLsizei depth
,
3983 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3984 const struct gl_pixelstore_attrib
*unpack
)
3986 GLint bytesPerRow
, compsPerRow
;
3987 GLboolean flipBytes
, swap2
, swap4
;
3990 return NULL
; /* not necessarily an error */
3992 if (width
<= 0 || height
<= 0 || depth
<= 0)
3993 return NULL
; /* generate error later */
3995 if (format
== GL_BITMAP
) {
3996 bytesPerRow
= (width
+ 7) >> 3;
3997 flipBytes
= !unpack
->LsbFirst
;
3998 swap2
= swap4
= GL_FALSE
;
4002 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
4003 const GLint components
= _mesa_components_in_format(format
);
4005 if (bytesPerPixel
<= 0 || components
<= 0)
4006 return NULL
; /* bad format or type. generate error later */
4007 bytesPerRow
= bytesPerPixel
* width
;
4008 bytesPerComp
= bytesPerPixel
/ components
;
4009 flipBytes
= GL_FALSE
;
4010 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
4011 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
4012 compsPerRow
= components
* width
;
4013 assert(compsPerRow
>= width
);
4017 GLubyte
*destBuffer
= (GLubyte
*) MALLOC(bytesPerRow
* height
* depth
);
4021 return NULL
; /* generate GL_OUT_OF_MEMORY later */
4024 for (img
= 0; img
< depth
; img
++) {
4025 for (row
= 0; row
< height
; row
++) {
4026 const GLvoid
*src
= _mesa_image_address(unpack
, pixels
,
4027 width
, height
, format
, type
, img
, row
, 0);
4028 MEMCPY(dst
, src
, bytesPerRow
);
4029 /* byte flipping/swapping */
4031 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
4034 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
4037 _mesa_swap4((GLuint
*) dst
, compsPerRow
);