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
);
976 #if CHAN_TYPE != GL_FLOAT
977 if (transferOps
& IMAGE_CLAMP_BIT
) {
979 for (i
= 0; i
< n
; i
++) {
980 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
981 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
982 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
983 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
992 * Used to pack an array [][4] of RGBA GLchan colors as specified
993 * by the dstFormat, dstType and dstPacking. Used by glReadPixels,
994 * glGetConvolutionFilter(), etc.
997 _mesa_pack_rgba_span_float( GLcontext
*ctx
,
998 GLuint n
, CONST GLfloat rgbaIn
[][4],
999 GLenum dstFormat
, GLenum dstType
,
1001 const struct gl_pixelstore_attrib
*dstPacking
,
1002 GLuint transferOps
)
1004 const GLint comps
= _mesa_components_in_format(dstFormat
);
1005 GLfloat luminance
[MAX_WIDTH
];
1006 const GLfloat (*rgba
)[4];
1010 /* make copy of incoming data */
1011 DEFMARRAY(GLfloat
, rgbaCopy
, MAX_WIDTH
, 4); /* mac 32k limitation */
1012 CHECKARRAY(rgbaCopy
, return); /* mac 32k limitation */
1014 _mesa_memcpy(rgbaCopy
, rgbaIn
, n
* 4 * sizeof(GLfloat
));
1015 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgbaCopy
);
1016 rgba
= (const GLfloat (*)[4]) rgbaCopy
;
1018 if ((transferOps
& IMAGE_MIN_MAX_BIT
) && ctx
->MinMax
.Sink
) {
1019 UNDEFARRAY(rgbaCopy
); /* mac 32k limitation */
1022 UNDEFARRAY(rgbaCopy
); /* mac 32k limitation */
1025 /* use incoming data, not a copy */
1026 rgba
= (const GLfloat (*)[4]) rgbaIn
;
1029 /* XXX clamp rgba to [0,1]? */
1031 if (dstFormat
== GL_LUMINANCE
|| dstFormat
== GL_LUMINANCE_ALPHA
) {
1032 /* compute luminance values */
1033 for (i
= 0; i
< n
; i
++) {
1034 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
1035 #if CHAN_TYPE == GL_FLOAT
1038 luminance
[i
] = CLAMP(sum
, 0.0F
, 1.0F
);
1044 * Pack/store the pixels. Ugh! Lots of cases!!!
1047 case GL_UNSIGNED_BYTE
:
1049 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1050 switch (dstFormat
) {
1053 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1057 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1061 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1065 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1069 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
1071 case GL_LUMINANCE_ALPHA
:
1073 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
1074 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1079 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1080 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1081 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1086 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1087 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1088 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1089 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1094 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1095 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1096 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1101 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1102 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1103 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1104 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1109 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
1110 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
1111 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
1112 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
1116 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1122 GLbyte
*dst
= (GLbyte
*) dstAddr
;
1123 switch (dstFormat
) {
1126 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1130 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1134 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1138 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1142 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
1144 case GL_LUMINANCE_ALPHA
:
1146 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
1147 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1152 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1153 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1154 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1159 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1160 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1161 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1162 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1167 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1168 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1169 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1174 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1175 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1176 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1177 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1181 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
1182 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
1183 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
1184 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
1188 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1192 case GL_UNSIGNED_SHORT
:
1194 GLushort
*dst
= (GLushort
*) dstAddr
;
1195 switch (dstFormat
) {
1198 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1202 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1206 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1210 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1214 dst
[i
] = FLOAT_TO_USHORT(luminance
[i
]);
1216 case GL_LUMINANCE_ALPHA
:
1218 dst
[i
*2+0] = FLOAT_TO_USHORT(luminance
[i
]);
1219 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1224 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1225 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1226 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1231 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1232 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1233 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1234 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1239 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1240 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1241 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1246 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1247 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1248 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1249 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1254 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
1255 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
1256 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
1257 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
1261 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1263 if (dstPacking
->SwapBytes
) {
1264 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1270 GLshort
*dst
= (GLshort
*) dstAddr
;
1271 switch (dstFormat
) {
1274 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1278 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1282 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1286 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1290 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
1292 case GL_LUMINANCE_ALPHA
:
1294 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
1295 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1300 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1301 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1302 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1307 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1308 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1309 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1310 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1315 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1316 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1317 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1322 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1323 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1324 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1325 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1329 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
1330 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
1331 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
1332 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
1336 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1338 if (dstPacking
->SwapBytes
) {
1339 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1343 case GL_UNSIGNED_INT
:
1345 GLuint
*dst
= (GLuint
*) dstAddr
;
1346 switch (dstFormat
) {
1349 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1353 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1357 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1361 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1365 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
1367 case GL_LUMINANCE_ALPHA
:
1369 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
1370 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1375 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1376 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1377 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1382 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1383 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1384 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1385 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1390 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1391 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1392 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1397 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1398 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1399 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1400 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1405 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1406 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1407 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1408 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1412 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1414 if (dstPacking
->SwapBytes
) {
1415 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1421 GLint
*dst
= (GLint
*) dstAddr
;
1422 switch (dstFormat
) {
1425 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1429 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1433 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1437 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1441 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1443 case GL_LUMINANCE_ALPHA
:
1445 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1446 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1451 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1452 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1453 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1458 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1459 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1460 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1461 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1466 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1467 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1468 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1473 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1474 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1475 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1476 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1481 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1482 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1483 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1484 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1488 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1490 if (dstPacking
->SwapBytes
) {
1491 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1497 GLfloat
*dst
= (GLfloat
*) dstAddr
;
1498 switch (dstFormat
) {
1501 dst
[i
] = rgba
[i
][RCOMP
];
1505 dst
[i
] = rgba
[i
][GCOMP
];
1509 dst
[i
] = rgba
[i
][BCOMP
];
1513 dst
[i
] = rgba
[i
][ACOMP
];
1517 dst
[i
] = luminance
[i
];
1519 case GL_LUMINANCE_ALPHA
:
1521 dst
[i
*2+0] = luminance
[i
];
1522 dst
[i
*2+1] = rgba
[i
][ACOMP
];
1527 dst
[i
*3+0] = rgba
[i
][RCOMP
];
1528 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1529 dst
[i
*3+2] = rgba
[i
][BCOMP
];
1534 dst
[i
*4+0] = rgba
[i
][RCOMP
];
1535 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1536 dst
[i
*4+2] = rgba
[i
][BCOMP
];
1537 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1542 dst
[i
*3+0] = rgba
[i
][BCOMP
];
1543 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1544 dst
[i
*3+2] = rgba
[i
][RCOMP
];
1549 dst
[i
*4+0] = rgba
[i
][BCOMP
];
1550 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1551 dst
[i
*4+2] = rgba
[i
][RCOMP
];
1552 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1557 dst
[i
*4+0] = rgba
[i
][ACOMP
];
1558 dst
[i
*4+1] = rgba
[i
][BCOMP
];
1559 dst
[i
*4+2] = rgba
[i
][GCOMP
];
1560 dst
[i
*4+3] = rgba
[i
][RCOMP
];
1564 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1566 if (dstPacking
->SwapBytes
) {
1567 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1571 case GL_HALF_FLOAT_NV
:
1573 GLhalfNV
*dst
= (GLhalfNV
*) dstAddr
;
1574 switch (dstFormat
) {
1577 dst
[i
] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1581 dst
[i
] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1585 dst
[i
] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1589 dst
[i
] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1593 dst
[i
] = _mesa_float_to_half(luminance
[i
]);
1595 case GL_LUMINANCE_ALPHA
:
1597 dst
[i
*2+0] = _mesa_float_to_half(luminance
[i
]);
1598 dst
[i
*2+1] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1603 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1604 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1605 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1610 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1611 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1612 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1613 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1618 dst
[i
*3+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1619 dst
[i
*3+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1620 dst
[i
*3+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1625 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1626 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1627 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1628 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1633 dst
[i
*4+0] = _mesa_float_to_half(rgba
[i
][ACOMP
]);
1634 dst
[i
*4+1] = _mesa_float_to_half(rgba
[i
][BCOMP
]);
1635 dst
[i
*4+2] = _mesa_float_to_half(rgba
[i
][GCOMP
]);
1636 dst
[i
*4+3] = _mesa_float_to_half(rgba
[i
][RCOMP
]);
1640 _mesa_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1642 if (dstPacking
->SwapBytes
) {
1643 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1647 case GL_UNSIGNED_BYTE_3_3_2
:
1648 if (dstFormat
== GL_RGB
) {
1649 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1651 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
1652 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
1653 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
1657 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1658 if (dstFormat
== GL_RGB
) {
1659 GLubyte
*dst
= (GLubyte
*) dstAddr
;
1661 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
1662 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
1663 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 5);
1667 case GL_UNSIGNED_SHORT_5_6_5
:
1668 if (dstFormat
== GL_RGB
) {
1669 GLushort
*dst
= (GLushort
*) dstAddr
;
1671 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1672 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1673 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
1677 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1678 if (dstFormat
== GL_RGB
) {
1679 GLushort
*dst
= (GLushort
*) dstAddr
;
1681 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1682 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1683 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
1687 case GL_UNSIGNED_SHORT_4_4_4_4
:
1688 if (dstFormat
== GL_RGBA
) {
1689 GLushort
*dst
= (GLushort
*) dstAddr
;
1691 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
1692 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1693 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1694 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1697 else if (dstFormat
== GL_BGRA
) {
1698 GLushort
*dst
= (GLushort
*) dstAddr
;
1700 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 12)
1701 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1702 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 4)
1703 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1706 else if (dstFormat
== GL_ABGR_EXT
) {
1707 GLushort
*dst
= (GLushort
*) dstAddr
;
1709 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 4)
1710 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1711 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 12)
1712 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) );
1716 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1717 if (dstFormat
== GL_RGBA
) {
1718 GLushort
*dst
= (GLushort
*) dstAddr
;
1720 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
1721 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1722 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1723 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1726 else if (dstFormat
== GL_BGRA
) {
1727 GLushort
*dst
= (GLushort
*) dstAddr
;
1729 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) )
1730 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1731 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 8)
1732 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1735 else if (dstFormat
== GL_ABGR_EXT
) {
1736 GLushort
*dst
= (GLushort
*) dstAddr
;
1738 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) )
1739 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1740 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1741 | (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12);
1745 case GL_UNSIGNED_SHORT_5_5_5_1
:
1746 if (dstFormat
== GL_RGBA
) {
1747 GLushort
*dst
= (GLushort
*) dstAddr
;
1749 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1750 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1751 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
1752 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1755 else if (dstFormat
== GL_BGRA
) {
1756 GLushort
*dst
= (GLushort
*) dstAddr
;
1758 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11)
1759 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1760 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 1)
1761 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1764 else if (dstFormat
== GL_ABGR_EXT
) {
1765 GLushort
*dst
= (GLushort
*) dstAddr
;
1767 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) << 11)
1768 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 6)
1769 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 1)
1770 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) );
1774 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1775 if (dstFormat
== GL_RGBA
) {
1776 GLushort
*dst
= (GLushort
*) dstAddr
;
1778 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1779 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1780 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
1781 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1784 else if (dstFormat
== GL_BGRA
) {
1785 GLushort
*dst
= (GLushort
*) dstAddr
;
1787 dst
[i
] = (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) )
1788 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1789 | (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 10)
1790 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1793 else if (dstFormat
== GL_ABGR_EXT
) {
1794 GLushort
*dst
= (GLushort
*) dstAddr
;
1796 dst
[i
] = (((GLint
) (rgba
[i
][ACOMP
] * 31.0F
)) )
1797 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 5)
1798 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 10)
1799 | (((GLint
) (rgba
[i
][RCOMP
] * 1.0F
)) << 15);
1803 case GL_UNSIGNED_INT_8_8_8_8
:
1804 if (dstFormat
== GL_RGBA
) {
1805 GLuint
*dst
= (GLuint
*) dstAddr
;
1807 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
1808 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1809 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1810 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1813 else if (dstFormat
== GL_BGRA
) {
1814 GLuint
*dst
= (GLuint
*) dstAddr
;
1816 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
1817 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1818 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
1819 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1822 else if (dstFormat
== GL_ABGR_EXT
) {
1823 GLuint
*dst
= (GLuint
*) dstAddr
;
1825 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
1826 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1827 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1828 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
1832 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1833 if (dstFormat
== GL_RGBA
) {
1834 GLuint
*dst
= (GLuint
*) dstAddr
;
1836 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
1837 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1838 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1839 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1842 else if (dstFormat
== GL_BGRA
) {
1843 GLuint
*dst
= (GLuint
*) dstAddr
;
1845 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
1846 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1847 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
1848 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1851 else if (dstFormat
== GL_ABGR_EXT
) {
1852 GLuint
*dst
= (GLuint
*) dstAddr
;
1854 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
1855 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1856 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1857 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
1861 case GL_UNSIGNED_INT_10_10_10_2
:
1862 if (dstFormat
== GL_RGBA
) {
1863 GLuint
*dst
= (GLuint
*) dstAddr
;
1865 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
1866 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1867 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
1868 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1871 else if (dstFormat
== GL_BGRA
) {
1872 GLuint
*dst
= (GLuint
*) dstAddr
;
1874 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
1875 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1876 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
1877 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1880 else if (dstFormat
== GL_ABGR_EXT
) {
1881 GLuint
*dst
= (GLuint
*) dstAddr
;
1883 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
1884 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
1885 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
1886 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
1890 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1891 if (dstFormat
== GL_RGBA
) {
1892 GLuint
*dst
= (GLuint
*) dstAddr
;
1894 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
1895 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1896 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
1897 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1900 else if (dstFormat
== GL_BGRA
) {
1901 GLuint
*dst
= (GLuint
*) dstAddr
;
1903 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
1904 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1905 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
1906 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1909 else if (dstFormat
== GL_ABGR_EXT
) {
1910 GLuint
*dst
= (GLuint
*) dstAddr
;
1912 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
1913 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
1914 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
1915 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
1920 _mesa_problem(ctx
, "bad type in _mesa_pack_rgba_span_float");
1926 * Pack the given RGBA span into client memory at 'dest' address
1927 * in the given pixel format and type.
1928 * Optionally apply the enabled pixel transfer ops.
1929 * Pack into memory using the given packing params struct.
1930 * This is used by glReadPixels and glGetTexImage?D()
1931 * \param ctx - the context
1932 * n - number of pixels in the span
1934 * format - dest packing format
1935 * type - dest packing data type
1936 * destination - destination packing address
1937 * packing - pixel packing parameters
1938 * transferOps - bitmask of IMAGE_*_BIT operations to apply
1941 _mesa_pack_rgba_span_chan( GLcontext
*ctx
,
1942 GLuint n
, CONST GLchan srcRgba
[][4],
1943 GLenum dstFormat
, GLenum dstType
,
1945 const struct gl_pixelstore_attrib
*dstPacking
,
1948 ASSERT((ctx
->NewState
& _NEW_PIXEL
) == 0 || transferOps
== 0);
1950 /* Test for optimized case first */
1951 if (transferOps
== 0 && dstFormat
== GL_RGBA
&& dstType
== CHAN_TYPE
) {
1952 /* common simple case */
1953 MEMCPY(dstAddr
, srcRgba
, n
* 4 * sizeof(GLchan
));
1955 else if (transferOps
== 0 && dstFormat
== GL_RGB
&& dstType
== CHAN_TYPE
) {
1956 /* common simple case */
1958 GLchan
*dest
= (GLchan
*) dstAddr
;
1959 for (i
= 0; i
< n
; i
++) {
1960 dest
[0] = srcRgba
[i
][RCOMP
];
1961 dest
[1] = srcRgba
[i
][GCOMP
];
1962 dest
[2] = srcRgba
[i
][BCOMP
];
1966 else if (transferOps
== 0 && dstFormat
== GL_RGBA
&& dstType
== GL_UNSIGNED_BYTE
) {
1967 /* common simple case */
1969 GLubyte
*dest
= (GLubyte
*) dstAddr
;
1970 for (i
= 0; i
< n
; i
++) {
1971 dest
[0] = CHAN_TO_UBYTE(srcRgba
[i
][RCOMP
]);
1972 dest
[1] = CHAN_TO_UBYTE(srcRgba
[i
][GCOMP
]);
1973 dest
[2] = CHAN_TO_UBYTE(srcRgba
[i
][BCOMP
]);
1974 dest
[3] = CHAN_TO_UBYTE(srcRgba
[i
][ACOMP
]);
1979 /* general solution */
1981 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
1982 CHECKARRAY(rgba
, return); /* mac 32k limitation */
1984 assert(n
<= MAX_WIDTH
);
1985 /* convert color components to floating point */
1986 for (i
= 0; i
< n
; i
++) {
1987 rgba
[i
][RCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][RCOMP
]);
1988 rgba
[i
][GCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][GCOMP
]);
1989 rgba
[i
][BCOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][BCOMP
]);
1990 rgba
[i
][ACOMP
] = CHAN_TO_FLOAT(srcRgba
[i
][ACOMP
]);
1992 _mesa_pack_rgba_span_float(ctx
, n
, (const GLfloat (*)[4]) rgba
,
1993 dstFormat
, dstType
, dstAddr
,
1994 dstPacking
, transferOps
);
1995 UNDEFARRAY(rgba
); /* mac 32k limitation */
2000 #define SWAP2BYTE(VALUE) \
2002 GLubyte *bytes = (GLubyte *) &(VALUE); \
2003 GLubyte tmp = bytes[0]; \
2004 bytes[0] = bytes[1]; \
2008 #define SWAP4BYTE(VALUE) \
2010 GLubyte *bytes = (GLubyte *) &(VALUE); \
2011 GLubyte tmp = bytes[0]; \
2012 bytes[0] = bytes[3]; \
2015 bytes[1] = bytes[2]; \
2021 extract_uint_indexes(GLuint n
, GLuint indexes
[],
2022 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2023 const struct gl_pixelstore_attrib
*unpack
)
2025 assert(srcFormat
== GL_COLOR_INDEX
);
2027 ASSERT(srcType
== GL_BITMAP
||
2028 srcType
== GL_UNSIGNED_BYTE
||
2029 srcType
== GL_BYTE
||
2030 srcType
== GL_UNSIGNED_SHORT
||
2031 srcType
== GL_SHORT
||
2032 srcType
== GL_UNSIGNED_INT
||
2033 srcType
== GL_INT
||
2034 srcType
== GL_HALF_FLOAT_NV
||
2035 srcType
== GL_FLOAT
);
2040 GLubyte
*ubsrc
= (GLubyte
*) src
;
2041 if (unpack
->LsbFirst
) {
2042 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
2044 for (i
= 0; i
< n
; i
++) {
2045 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2056 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
2058 for (i
= 0; i
< n
; i
++) {
2059 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
2071 case GL_UNSIGNED_BYTE
:
2074 const GLubyte
*s
= (const GLubyte
*) src
;
2075 for (i
= 0; i
< n
; i
++)
2082 const GLbyte
*s
= (const GLbyte
*) src
;
2083 for (i
= 0; i
< n
; i
++)
2087 case GL_UNSIGNED_SHORT
:
2090 const GLushort
*s
= (const GLushort
*) src
;
2091 if (unpack
->SwapBytes
) {
2092 for (i
= 0; i
< n
; i
++) {
2093 GLushort value
= s
[i
];
2099 for (i
= 0; i
< n
; i
++)
2107 const GLshort
*s
= (const GLshort
*) src
;
2108 if (unpack
->SwapBytes
) {
2109 for (i
= 0; i
< n
; i
++) {
2110 GLshort value
= s
[i
];
2116 for (i
= 0; i
< n
; i
++)
2121 case GL_UNSIGNED_INT
:
2124 const GLuint
*s
= (const GLuint
*) src
;
2125 if (unpack
->SwapBytes
) {
2126 for (i
= 0; i
< n
; i
++) {
2127 GLuint value
= s
[i
];
2133 for (i
= 0; i
< n
; i
++)
2141 const GLint
*s
= (const GLint
*) src
;
2142 if (unpack
->SwapBytes
) {
2143 for (i
= 0; i
< n
; i
++) {
2150 for (i
= 0; i
< n
; i
++)
2158 const GLfloat
*s
= (const GLfloat
*) src
;
2159 if (unpack
->SwapBytes
) {
2160 for (i
= 0; i
< n
; i
++) {
2161 GLfloat value
= s
[i
];
2163 indexes
[i
] = (GLuint
) value
;
2167 for (i
= 0; i
< n
; i
++)
2168 indexes
[i
] = (GLuint
) s
[i
];
2172 case GL_HALF_FLOAT_NV
:
2175 const GLhalfNV
*s
= (const GLhalfNV
*) src
;
2176 if (unpack
->SwapBytes
) {
2177 for (i
= 0; i
< n
; i
++) {
2178 GLhalfNV value
= s
[i
];
2180 indexes
[i
] = (GLuint
) _mesa_half_to_float(value
);
2184 for (i
= 0; i
< n
; i
++)
2185 indexes
[i
] = (GLuint
) _mesa_half_to_float(s
[i
]);
2190 _mesa_problem(NULL
, "bad srcType in extract_uint_indexes");
2197 * This function extracts floating point RGBA values from arbitrary
2198 * image data. srcFormat and srcType are the format and type parameters
2199 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
2201 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
2202 * implements the "Conversion to floating point", "Conversion to RGB",
2203 * and "Final Expansion to RGBA" operations.
2205 * Args: n - number of pixels
2206 * rgba - output colors
2207 * srcFormat - format of incoming data
2208 * srcType - data type of incoming data
2209 * src - source data pointer
2210 * swapBytes - perform byteswapping of incoming data?
2213 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
2214 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
2215 GLboolean swapBytes
)
2217 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
2219 GLint rComp
, bComp
, gComp
, aComp
;
2221 ASSERT(srcFormat
== GL_RED
||
2222 srcFormat
== GL_GREEN
||
2223 srcFormat
== GL_BLUE
||
2224 srcFormat
== GL_ALPHA
||
2225 srcFormat
== GL_LUMINANCE
||
2226 srcFormat
== GL_LUMINANCE_ALPHA
||
2227 srcFormat
== GL_INTENSITY
||
2228 srcFormat
== GL_RGB
||
2229 srcFormat
== GL_BGR
||
2230 srcFormat
== GL_RGBA
||
2231 srcFormat
== GL_BGRA
||
2232 srcFormat
== GL_ABGR_EXT
);
2234 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
2235 srcType
== GL_BYTE
||
2236 srcType
== GL_UNSIGNED_SHORT
||
2237 srcType
== GL_SHORT
||
2238 srcType
== GL_UNSIGNED_INT
||
2239 srcType
== GL_INT
||
2240 srcType
== GL_HALF_FLOAT_NV
||
2241 srcType
== GL_FLOAT
||
2242 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2243 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2244 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2245 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2246 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2247 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2248 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2249 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2250 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2251 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2252 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2253 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2255 rComp
= gComp
= bComp
= aComp
= -1;
2257 switch (srcFormat
) {
2260 greenIndex
= blueIndex
= alphaIndex
= -1;
2265 redIndex
= blueIndex
= alphaIndex
= -1;
2270 redIndex
= greenIndex
= alphaIndex
= -1;
2274 redIndex
= greenIndex
= blueIndex
= -1;
2279 redIndex
= greenIndex
= blueIndex
= 0;
2283 case GL_LUMINANCE_ALPHA
:
2284 redIndex
= greenIndex
= blueIndex
= 0;
2289 redIndex
= greenIndex
= blueIndex
= alphaIndex
= 0;
2340 _mesa_problem(NULL
, "bad srcFormat in extract float data");
2345 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
2346 if ((INDEX) < 0) { \
2348 for (i = 0; i < n; i++) { \
2349 rgba[i][CHANNEL] = DEFAULT; \
2352 else if (swapBytes) { \
2353 const TYPE *s = (const TYPE *) src; \
2355 for (i = 0; i < n; i++) { \
2356 TYPE value = s[INDEX]; \
2357 if (sizeof(TYPE) == 2) { \
2360 else if (sizeof(TYPE) == 4) { \
2363 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
2368 const TYPE *s = (const TYPE *) src; \
2370 for (i = 0; i < n; i++) { \
2371 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
2377 case GL_UNSIGNED_BYTE
:
2378 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2379 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2380 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2381 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
2384 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2385 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2386 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
2387 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
2389 case GL_UNSIGNED_SHORT
:
2390 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2391 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2392 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
2393 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
2396 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2397 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2398 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
2399 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
2401 case GL_UNSIGNED_INT
:
2402 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2403 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2404 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
2405 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
2408 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2409 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2410 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
2411 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
2414 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2415 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2416 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
2417 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
2419 case GL_HALF_FLOAT_NV
:
2420 PROCESS(redIndex
, RCOMP
, 0.0F
, GLhalfNV
, _mesa_half_to_float
);
2421 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLhalfNV
, _mesa_half_to_float
);
2422 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLhalfNV
, _mesa_half_to_float
);
2423 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLhalfNV
, _mesa_half_to_float
);
2425 case GL_UNSIGNED_BYTE_3_3_2
:
2427 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2429 for (i
= 0; i
< n
; i
++) {
2430 GLubyte p
= ubsrc
[i
];
2431 rgba
[i
][RCOMP
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
2432 rgba
[i
][GCOMP
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
2433 rgba
[i
][BCOMP
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
2434 rgba
[i
][ACOMP
] = 1.0F
;
2438 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2440 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
2442 for (i
= 0; i
< n
; i
++) {
2443 GLubyte p
= ubsrc
[i
];
2444 rgba
[i
][RCOMP
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
2445 rgba
[i
][GCOMP
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
2446 rgba
[i
][BCOMP
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
2447 rgba
[i
][ACOMP
] = 1.0F
;
2451 case GL_UNSIGNED_SHORT_5_6_5
:
2453 const GLushort
*ussrc
= (const GLushort
*) src
;
2455 for (i
= 0; i
< n
; i
++) {
2456 GLushort p
= ussrc
[i
];
2458 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2459 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2460 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2461 rgba
[i
][ACOMP
] = 1.0F
;
2465 const GLushort
*ussrc
= (const GLushort
*) src
;
2467 for (i
= 0; i
< n
; i
++) {
2468 GLushort p
= ussrc
[i
];
2469 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2470 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2471 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2472 rgba
[i
][ACOMP
] = 1.0F
;
2476 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2478 const GLushort
*ussrc
= (const GLushort
*) src
;
2480 for (i
= 0; i
< n
; i
++) {
2481 GLushort p
= ussrc
[i
];
2483 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2484 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2485 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2486 rgba
[i
][ACOMP
] = 1.0F
;
2490 const GLushort
*ussrc
= (const GLushort
*) src
;
2492 for (i
= 0; i
< n
; i
++) {
2493 GLushort p
= ussrc
[i
];
2494 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2495 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
2496 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2497 rgba
[i
][ACOMP
] = 1.0F
;
2501 case GL_UNSIGNED_SHORT_4_4_4_4
:
2503 const GLushort
*ussrc
= (const GLushort
*) src
;
2505 for (i
= 0; i
< n
; i
++) {
2506 GLushort p
= ussrc
[i
];
2508 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2509 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2510 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2511 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2515 const GLushort
*ussrc
= (const GLushort
*) src
;
2517 for (i
= 0; i
< n
; i
++) {
2518 GLushort p
= ussrc
[i
];
2519 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2520 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2521 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2522 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2526 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2528 const GLushort
*ussrc
= (const GLushort
*) src
;
2530 for (i
= 0; i
< n
; i
++) {
2531 GLushort p
= ussrc
[i
];
2533 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2534 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2535 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2536 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2540 const GLushort
*ussrc
= (const GLushort
*) src
;
2542 for (i
= 0; i
< n
; i
++) {
2543 GLushort p
= ussrc
[i
];
2544 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
2545 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
2546 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
2547 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
2551 case GL_UNSIGNED_SHORT_5_5_5_1
:
2553 const GLushort
*ussrc
= (const GLushort
*) src
;
2555 for (i
= 0; i
< n
; i
++) {
2556 GLushort p
= ussrc
[i
];
2558 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2559 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2560 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2561 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2565 const GLushort
*ussrc
= (const GLushort
*) src
;
2567 for (i
= 0; i
< n
; i
++) {
2568 GLushort p
= ussrc
[i
];
2569 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
2570 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
2571 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
2572 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
2576 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2578 const GLushort
*ussrc
= (const GLushort
*) src
;
2580 for (i
= 0; i
< n
; i
++) {
2581 GLushort p
= ussrc
[i
];
2583 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2584 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2585 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2586 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2590 const GLushort
*ussrc
= (const GLushort
*) src
;
2592 for (i
= 0; i
< n
; i
++) {
2593 GLushort p
= ussrc
[i
];
2594 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2595 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2596 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2597 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2601 case GL_UNSIGNED_INT_8_8_8_8
:
2603 const GLuint
*uisrc
= (const GLuint
*) src
;
2605 for (i
= 0; i
< n
; i
++) {
2606 GLuint p
= uisrc
[i
];
2607 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2608 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2609 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2610 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2614 const GLuint
*uisrc
= (const GLuint
*) src
;
2616 for (i
= 0; i
< n
; i
++) {
2617 GLuint p
= uisrc
[i
];
2618 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2619 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2620 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2621 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2625 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2627 const GLuint
*uisrc
= (const GLuint
*) src
;
2629 for (i
= 0; i
< n
; i
++) {
2630 GLuint p
= uisrc
[i
];
2631 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2632 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2633 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2634 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2638 const GLuint
*uisrc
= (const GLuint
*) src
;
2640 for (i
= 0; i
< n
; i
++) {
2641 GLuint p
= uisrc
[i
];
2642 rgba
[i
][rComp
] = UBYTE_TO_FLOAT((p
) & 0xff);
2643 rgba
[i
][gComp
] = UBYTE_TO_FLOAT((p
>> 8) & 0xff);
2644 rgba
[i
][bComp
] = UBYTE_TO_FLOAT((p
>> 16) & 0xff);
2645 rgba
[i
][aComp
] = UBYTE_TO_FLOAT((p
>> 24) );
2649 case GL_UNSIGNED_INT_10_10_10_2
:
2651 const GLuint
*uisrc
= (const GLuint
*) src
;
2653 for (i
= 0; i
< n
; i
++) {
2654 GLuint p
= uisrc
[i
];
2656 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2657 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2658 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2659 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2663 const GLuint
*uisrc
= (const GLuint
*) src
;
2665 for (i
= 0; i
< n
; i
++) {
2666 GLuint p
= uisrc
[i
];
2667 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2668 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2669 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2670 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2674 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2676 const GLuint
*uisrc
= (const GLuint
*) src
;
2678 for (i
= 0; i
< n
; i
++) {
2679 GLuint p
= uisrc
[i
];
2681 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2682 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2683 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2684 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2688 const GLuint
*uisrc
= (const GLuint
*) src
;
2690 for (i
= 0; i
< n
; i
++) {
2691 GLuint p
= uisrc
[i
];
2692 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2693 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2694 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2695 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2700 _mesa_problem(NULL
, "bad srcType in extract float data");
2707 * Unpack a row of color image data from a client buffer according to
2708 * the pixel unpacking parameters.
2709 * Return GLchan values in the specified dest image format.
2710 * This is used by glDrawPixels and glTexImage?D().
2711 * \param ctx - the context
2712 * n - number of pixels in the span
2713 * dstFormat - format of destination color array
2714 * dest - the destination color array
2715 * srcFormat - source image format
2716 * srcType - source image data type
2717 * source - source image pointer
2718 * srcPacking - pixel unpacking parameters
2719 * transferOps - bitmask of IMAGE_*_BIT values of operations to apply
2721 * XXX perhaps expand this to process whole images someday.
2724 _mesa_unpack_color_span_chan( GLcontext
*ctx
,
2725 GLuint n
, GLenum dstFormat
, GLchan dest
[],
2726 GLenum srcFormat
, GLenum srcType
,
2727 const GLvoid
*source
,
2728 const struct gl_pixelstore_attrib
*srcPacking
,
2729 GLuint transferOps
)
2731 ASSERT(dstFormat
== GL_ALPHA
||
2732 dstFormat
== GL_LUMINANCE
||
2733 dstFormat
== GL_LUMINANCE_ALPHA
||
2734 dstFormat
== GL_INTENSITY
||
2735 dstFormat
== GL_RGB
||
2736 dstFormat
== GL_RGBA
||
2737 dstFormat
== GL_COLOR_INDEX
);
2739 ASSERT(srcFormat
== GL_RED
||
2740 srcFormat
== GL_GREEN
||
2741 srcFormat
== GL_BLUE
||
2742 srcFormat
== GL_ALPHA
||
2743 srcFormat
== GL_LUMINANCE
||
2744 srcFormat
== GL_LUMINANCE_ALPHA
||
2745 srcFormat
== GL_INTENSITY
||
2746 srcFormat
== GL_RGB
||
2747 srcFormat
== GL_BGR
||
2748 srcFormat
== GL_RGBA
||
2749 srcFormat
== GL_BGRA
||
2750 srcFormat
== GL_ABGR_EXT
||
2751 srcFormat
== GL_COLOR_INDEX
);
2753 ASSERT(srcType
== GL_BITMAP
||
2754 srcType
== GL_UNSIGNED_BYTE
||
2755 srcType
== GL_BYTE
||
2756 srcType
== GL_UNSIGNED_SHORT
||
2757 srcType
== GL_SHORT
||
2758 srcType
== GL_UNSIGNED_INT
||
2759 srcType
== GL_INT
||
2760 srcType
== GL_HALF_FLOAT_NV
||
2761 srcType
== GL_FLOAT
||
2762 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2763 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2764 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2765 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2766 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2767 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2768 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2769 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2770 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2771 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2772 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2773 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2775 /* Try simple cases first */
2776 if (transferOps
== 0 ){
2777 if (srcType
== CHAN_TYPE
) {
2778 if (dstFormat
== GL_RGBA
) {
2779 if (srcFormat
== GL_RGBA
) {
2780 MEMCPY( dest
, source
, n
* 4 * sizeof(GLchan
) );
2783 else if (srcFormat
== GL_RGB
) {
2785 const GLchan
*src
= (const GLchan
*) source
;
2787 for (i
= 0; i
< n
; i
++) {
2798 else if (dstFormat
== GL_RGB
) {
2799 if (srcFormat
== GL_RGB
) {
2800 MEMCPY( dest
, source
, n
* 3 * sizeof(GLchan
) );
2803 else if (srcFormat
== GL_RGBA
) {
2805 const GLchan
*src
= (const GLchan
*) source
;
2807 for (i
= 0; i
< n
; i
++) {
2817 else if (dstFormat
== srcFormat
) {
2818 GLint comps
= _mesa_components_in_format(srcFormat
);
2820 MEMCPY( dest
, source
, n
* comps
* sizeof(GLchan
) );
2825 * Common situation, loading 8bit RGBA/RGB source images
2826 * into 16/32 bit destination. (OSMesa16/32)
2828 else if (srcType
== GL_UNSIGNED_BYTE
) {
2829 if (dstFormat
== GL_RGBA
) {
2830 if (srcFormat
== GL_RGB
) {
2832 const GLubyte
*src
= (const GLubyte
*) source
;
2834 for (i
= 0; i
< n
; i
++) {
2835 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2836 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2837 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2844 else if (srcFormat
== GL_RGBA
) {
2846 const GLubyte
*src
= (const GLubyte
*) source
;
2848 for (i
= 0; i
< n
; i
++) {
2849 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2850 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2851 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2852 dst
[3] = UBYTE_TO_CHAN(src
[3]);
2859 else if (dstFormat
== GL_RGB
) {
2860 if (srcFormat
== GL_RGB
) {
2862 const GLubyte
*src
= (const GLubyte
*) source
;
2864 for (i
= 0; i
< n
; i
++) {
2865 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2866 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2867 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2873 else if (srcFormat
== GL_RGBA
) {
2875 const GLubyte
*src
= (const GLubyte
*) source
;
2877 for (i
= 0; i
< n
; i
++) {
2878 dst
[0] = UBYTE_TO_CHAN(src
[0]);
2879 dst
[1] = UBYTE_TO_CHAN(src
[1]);
2880 dst
[2] = UBYTE_TO_CHAN(src
[2]);
2891 /* general solution begins here */
2893 GLint dstComponents
;
2894 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2895 GLint dstLuminanceIndex
, dstIntensityIndex
;
2896 DEFMARRAY(GLfloat
, rgba
, MAX_WIDTH
, 4); /* mac 32k limitation */
2897 CHECKARRAY(rgba
, return); /* mac 32k limitation */
2899 dstComponents
= _mesa_components_in_format( dstFormat
);
2900 /* source & dest image formats should have been error checked by now */
2901 assert(dstComponents
> 0);
2904 * Extract image data and convert to RGBA floats
2906 assert(n
<= MAX_WIDTH
);
2907 if (srcFormat
== GL_COLOR_INDEX
) {
2908 GLuint indexes
[MAX_WIDTH
];
2909 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2912 if (dstFormat
== GL_COLOR_INDEX
2913 && (transferOps
& IMAGE_MAP_COLOR_BIT
)) {
2914 _mesa_map_ci(ctx
, n
, indexes
);
2916 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
2917 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2920 if (dstFormat
== GL_COLOR_INDEX
) {
2921 /* convert to GLchan and return */
2923 for (i
= 0; i
< n
; i
++) {
2924 dest
[i
] = (GLchan
) (indexes
[i
] & 0xff);
2926 UNDEFARRAY(rgba
); /* mac 32k limitation */
2930 /* Convert indexes to RGBA */
2931 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
2934 /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
2935 * with color indexes.
2937 transferOps
&= ~(IMAGE_SCALE_BIAS_BIT
| IMAGE_MAP_COLOR_BIT
);
2940 /* non-color index data */
2941 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2942 srcPacking
->SwapBytes
);
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
, GLboolean clamp
)
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
);
3172 #if CHAN_TYPE != GL_FLOAT
3174 transferOps
|= IMAGE_CLAMP_BIT
;
3179 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, n
, rgba
);
3182 /* Now determine which color channels we need to produce.
3183 * And determine the dest index (offset) within each color tuple.
3185 switch (dstFormat
) {
3188 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3189 dstLuminanceIndex
= dstIntensityIndex
= -1;
3192 dstLuminanceIndex
= 0;
3193 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3194 dstIntensityIndex
= -1;
3196 case GL_LUMINANCE_ALPHA
:
3197 dstLuminanceIndex
= 0;
3199 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
3200 dstIntensityIndex
= -1;
3203 dstIntensityIndex
= 0;
3204 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
3205 dstLuminanceIndex
= -1;
3211 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
3218 dstLuminanceIndex
= dstIntensityIndex
= -1;
3221 _mesa_problem(ctx
, "bad dstFormat in _mesa_unpack_color_span_float()");
3222 UNDEFARRAY(rgba
); /* mac 32k limitation */
3226 /* Now pack results in the requested dstFormat */
3227 if (dstRedIndex
>= 0) {
3228 GLfloat
*dst
= dest
;
3230 for (i
= 0; i
< n
; i
++) {
3231 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
3232 dst
+= dstComponents
;
3236 if (dstGreenIndex
>= 0) {
3237 GLfloat
*dst
= dest
;
3239 for (i
= 0; i
< n
; i
++) {
3240 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
3241 dst
+= dstComponents
;
3245 if (dstBlueIndex
>= 0) {
3246 GLfloat
*dst
= dest
;
3248 for (i
= 0; i
< n
; i
++) {
3249 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
3250 dst
+= dstComponents
;
3254 if (dstAlphaIndex
>= 0) {
3255 GLfloat
*dst
= dest
;
3257 for (i
= 0; i
< n
; i
++) {
3258 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
3259 dst
+= dstComponents
;
3263 if (dstIntensityIndex
>= 0) {
3264 GLfloat
*dst
= dest
;
3266 assert(dstIntensityIndex
== 0);
3267 assert(dstComponents
== 1);
3268 for (i
= 0; i
< n
; i
++) {
3269 /* Intensity comes from red channel */
3270 dst
[i
] = rgba
[i
][RCOMP
];
3274 if (dstLuminanceIndex
>= 0) {
3275 GLfloat
*dst
= dest
;
3277 assert(dstLuminanceIndex
== 0);
3278 for (i
= 0; i
< n
; i
++) {
3279 /* Luminance comes from red channel */
3280 dst
[0] = rgba
[i
][RCOMP
];
3281 dst
+= dstComponents
;
3284 UNDEFARRAY(rgba
); /* mac 32k limitation */
3290 * Unpack a row of color index data from a client buffer according to
3291 * the pixel unpacking parameters.
3292 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
3294 * Args: ctx - the context
3295 * n - number of pixels
3296 * dstType - destination data type
3297 * dest - destination array
3298 * srcType - source pixel type
3299 * source - source data pointer
3300 * srcPacking - pixel unpacking parameters
3301 * transferOps - the pixel transfer operations to apply
3304 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
3305 GLenum dstType
, GLvoid
*dest
,
3306 GLenum srcType
, const GLvoid
*source
,
3307 const struct gl_pixelstore_attrib
*srcPacking
,
3308 GLuint transferOps
)
3310 ASSERT(srcType
== GL_BITMAP
||
3311 srcType
== GL_UNSIGNED_BYTE
||
3312 srcType
== GL_BYTE
||
3313 srcType
== GL_UNSIGNED_SHORT
||
3314 srcType
== GL_SHORT
||
3315 srcType
== GL_UNSIGNED_INT
||
3316 srcType
== GL_INT
||
3317 srcType
== GL_HALF_FLOAT_NV
||
3318 srcType
== GL_FLOAT
);
3320 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3321 dstType
== GL_UNSIGNED_SHORT
||
3322 dstType
== GL_UNSIGNED_INT
);
3325 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3328 * Try simple cases first
3330 if (transferOps
== 0 && srcType
== GL_UNSIGNED_BYTE
3331 && dstType
== GL_UNSIGNED_BYTE
) {
3332 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
3334 else if (transferOps
== 0 && srcType
== GL_UNSIGNED_INT
3335 && dstType
== GL_UNSIGNED_INT
&& !srcPacking
->SwapBytes
) {
3336 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
3342 GLuint indexes
[MAX_WIDTH
];
3343 assert(n
<= MAX_WIDTH
);
3345 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3348 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3349 /* shift and offset indexes */
3350 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3352 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3353 /* Apply lookup table */
3354 _mesa_map_ci(ctx
, n
, indexes
);
3357 /* convert to dest type */
3359 case GL_UNSIGNED_BYTE
:
3361 GLubyte
*dst
= (GLubyte
*) dest
;
3363 for (i
= 0; i
< n
; i
++) {
3364 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3368 case GL_UNSIGNED_SHORT
:
3370 GLuint
*dst
= (GLuint
*) dest
;
3372 for (i
= 0; i
< n
; i
++) {
3373 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3377 case GL_UNSIGNED_INT
:
3378 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
3381 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
3388 _mesa_pack_index_span( const GLcontext
*ctx
, GLuint n
,
3389 GLenum dstType
, GLvoid
*dest
, const GLuint
*source
,
3390 const struct gl_pixelstore_attrib
*dstPacking
,
3391 GLuint transferOps
)
3393 GLuint indexes
[MAX_WIDTH
];
3395 ASSERT(n
<= MAX_WIDTH
);
3397 transferOps
&= (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
);
3399 if (transferOps
& (IMAGE_MAP_COLOR_BIT
| IMAGE_SHIFT_OFFSET_BIT
)) {
3400 /* make a copy of input */
3401 MEMCPY(indexes
, source
, n
* sizeof(GLuint
));
3402 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3403 _mesa_shift_and_offset_ci( ctx
, n
, indexes
);
3405 if (transferOps
& IMAGE_MAP_COLOR_BIT
) {
3406 _mesa_map_ci(ctx
, n
, indexes
);
3412 case GL_UNSIGNED_BYTE
:
3414 GLubyte
*dst
= (GLubyte
*) dest
;
3416 for (i
= 0; i
< n
; i
++) {
3417 *dst
++ = (GLubyte
) source
[i
];
3423 GLbyte
*dst
= (GLbyte
*) dest
;
3425 for (i
= 0; i
< n
; i
++) {
3426 dst
[i
] = (GLbyte
) source
[i
];
3430 case GL_UNSIGNED_SHORT
:
3432 GLushort
*dst
= (GLushort
*) dest
;
3434 for (i
= 0; i
< n
; i
++) {
3435 dst
[i
] = (GLushort
) source
[i
];
3437 if (dstPacking
->SwapBytes
) {
3438 _mesa_swap2( (GLushort
*) dst
, n
);
3444 GLshort
*dst
= (GLshort
*) dest
;
3446 for (i
= 0; i
< n
; i
++) {
3447 dst
[i
] = (GLshort
) source
[i
];
3449 if (dstPacking
->SwapBytes
) {
3450 _mesa_swap2( (GLushort
*) dst
, n
);
3454 case GL_UNSIGNED_INT
:
3456 GLuint
*dst
= (GLuint
*) dest
;
3458 for (i
= 0; i
< n
; i
++) {
3459 dst
[i
] = (GLuint
) source
[i
];
3461 if (dstPacking
->SwapBytes
) {
3462 _mesa_swap4( (GLuint
*) dst
, n
);
3468 GLint
*dst
= (GLint
*) dest
;
3470 for (i
= 0; i
< n
; i
++) {
3471 dst
[i
] = (GLint
) source
[i
];
3473 if (dstPacking
->SwapBytes
) {
3474 _mesa_swap4( (GLuint
*) dst
, n
);
3480 GLfloat
*dst
= (GLfloat
*) dest
;
3482 for (i
= 0; i
< n
; i
++) {
3483 dst
[i
] = (GLfloat
) source
[i
];
3485 if (dstPacking
->SwapBytes
) {
3486 _mesa_swap4( (GLuint
*) dst
, n
);
3490 case GL_HALF_FLOAT_NV
:
3492 GLhalfNV
*dst
= (GLhalfNV
*) dest
;
3494 for (i
= 0; i
< n
; i
++) {
3495 dst
[i
] = _mesa_float_to_half((GLfloat
) source
[i
]);
3497 if (dstPacking
->SwapBytes
) {
3498 _mesa_swap2( (GLushort
*) dst
, n
);
3503 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3509 * Unpack a row of stencil data from a client buffer according to
3510 * the pixel unpacking parameters.
3511 * This is (or will be) used by glDrawPixels
3513 * Args: ctx - the context
3514 * n - number of pixels
3515 * dstType - destination data type
3516 * dest - destination array
3517 * srcType - source pixel type
3518 * source - source data pointer
3519 * srcPacking - pixel unpacking parameters
3520 * transferOps - apply offset/bias/lookup ops?
3523 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3524 GLenum dstType
, GLvoid
*dest
,
3525 GLenum srcType
, const GLvoid
*source
,
3526 const struct gl_pixelstore_attrib
*srcPacking
,
3527 GLuint transferOps
)
3529 ASSERT(srcType
== GL_BITMAP
||
3530 srcType
== GL_UNSIGNED_BYTE
||
3531 srcType
== GL_BYTE
||
3532 srcType
== GL_UNSIGNED_SHORT
||
3533 srcType
== GL_SHORT
||
3534 srcType
== GL_UNSIGNED_INT
||
3535 srcType
== GL_INT
||
3536 srcType
== GL_HALF_FLOAT_NV
||
3537 srcType
== GL_FLOAT
);
3539 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
3540 dstType
== GL_UNSIGNED_SHORT
||
3541 dstType
== GL_UNSIGNED_INT
);
3543 /* only shift and offset apply to stencil */
3544 transferOps
&= IMAGE_SHIFT_OFFSET_BIT
;
3547 * Try simple cases first
3549 if (transferOps
== 0 &&
3550 srcType
== GL_UNSIGNED_BYTE
&&
3551 dstType
== GL_UNSIGNED_BYTE
) {
3552 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
3554 else if (transferOps
== 0 &&
3555 srcType
== GL_UNSIGNED_INT
&&
3556 dstType
== GL_UNSIGNED_INT
&&
3557 !srcPacking
->SwapBytes
) {
3558 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
3564 GLuint indexes
[MAX_WIDTH
];
3565 assert(n
<= MAX_WIDTH
);
3567 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
3571 if (transferOps
& IMAGE_SHIFT_OFFSET_BIT
) {
3572 /* shift and offset indexes */
3573 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
3576 if (ctx
->Pixel
.MapStencilFlag
) {
3577 /* Apply stencil lookup table */
3578 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
3581 indexes
[i
] = ctx
->Pixel
.MapStoS
[ indexes
[i
] & mask
];
3586 /* convert to dest type */
3588 case GL_UNSIGNED_BYTE
:
3590 GLubyte
*dst
= (GLubyte
*) dest
;
3592 for (i
= 0; i
< n
; i
++) {
3593 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
3597 case GL_UNSIGNED_SHORT
:
3599 GLuint
*dst
= (GLuint
*) dest
;
3601 for (i
= 0; i
< n
; i
++) {
3602 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
3606 case GL_UNSIGNED_INT
:
3607 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
3610 _mesa_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
3617 _mesa_pack_stencil_span( const GLcontext
*ctx
, GLuint n
,
3618 GLenum dstType
, GLvoid
*dest
, const GLstencil
*source
,
3619 const struct gl_pixelstore_attrib
*dstPacking
)
3621 GLstencil stencil
[MAX_WIDTH
];
3623 ASSERT(n
<= MAX_WIDTH
);
3625 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
||
3626 ctx
->Pixel
.MapStencilFlag
) {
3627 /* make a copy of input */
3628 MEMCPY(stencil
, source
, n
* sizeof(GLstencil
));
3629 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
3630 _mesa_shift_and_offset_stencil( ctx
, n
, stencil
);
3632 if (ctx
->Pixel
.MapStencilFlag
) {
3633 _mesa_map_stencil( ctx
, n
, stencil
);
3639 case GL_UNSIGNED_BYTE
:
3640 if (sizeof(GLstencil
) == 8) {
3641 MEMCPY( dest
, source
, n
);
3644 GLubyte
*dst
= (GLubyte
*) dest
;
3647 dst
[i
] = (GLubyte
) source
[i
];
3652 if (sizeof(GLstencil
) == 8) {
3653 MEMCPY( dest
, source
, n
);
3656 GLbyte
*dst
= (GLbyte
*) dest
;
3659 dst
[i
] = (GLbyte
) source
[i
];
3663 case GL_UNSIGNED_SHORT
:
3665 GLushort
*dst
= (GLushort
*) dest
;
3668 dst
[i
] = (GLushort
) source
[i
];
3670 if (dstPacking
->SwapBytes
) {
3671 _mesa_swap2( (GLushort
*) dst
, n
);
3677 GLshort
*dst
= (GLshort
*) dest
;
3680 dst
[i
] = (GLshort
) source
[i
];
3682 if (dstPacking
->SwapBytes
) {
3683 _mesa_swap2( (GLushort
*) dst
, n
);
3687 case GL_UNSIGNED_INT
:
3689 GLuint
*dst
= (GLuint
*) dest
;
3692 dst
[i
] = (GLuint
) source
[i
];
3694 if (dstPacking
->SwapBytes
) {
3695 _mesa_swap4( (GLuint
*) dst
, n
);
3701 GLint
*dst
= (GLint
*) dest
;
3704 *dst
++ = (GLint
) source
[i
];
3706 if (dstPacking
->SwapBytes
) {
3707 _mesa_swap4( (GLuint
*) dst
, n
);
3713 GLfloat
*dst
= (GLfloat
*) dest
;
3716 dst
[i
] = (GLfloat
) source
[i
];
3718 if (dstPacking
->SwapBytes
) {
3719 _mesa_swap4( (GLuint
*) dst
, n
);
3723 case GL_HALF_FLOAT_NV
:
3725 GLhalfNV
*dst
= (GLhalfNV
*) dest
;
3728 dst
[i
] = _mesa_float_to_half( (float) source
[i
] );
3730 if (dstPacking
->SwapBytes
) {
3731 _mesa_swap2( (GLushort
*) dst
, n
);
3736 if (dstPacking
->LsbFirst
) {
3737 GLubyte
*dst
= (GLubyte
*) dest
;
3740 for (i
= 0; i
< n
; i
++) {
3743 *dst
|= ((source
[i
] != 0) << shift
);
3752 GLubyte
*dst
= (GLubyte
*) dest
;
3755 for (i
= 0; i
< n
; i
++) {
3758 *dst
|= ((source
[i
] != 0) << shift
);
3768 _mesa_problem(ctx
, "bad type in _mesa_pack_index_span");
3774 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
, GLfloat
*dest
,
3775 GLenum srcType
, const GLvoid
*source
,
3776 const struct gl_pixelstore_attrib
*srcPacking
)
3782 const GLubyte
*src
= (const GLubyte
*) source
;
3783 for (i
= 0; i
< n
; i
++) {
3784 dest
[i
] = BYTE_TO_FLOAT(src
[i
]);
3788 case GL_UNSIGNED_BYTE
:
3791 const GLubyte
*src
= (const GLubyte
*) source
;
3792 for (i
= 0; i
< n
; i
++) {
3793 dest
[i
] = UBYTE_TO_FLOAT(src
[i
]);
3800 const GLshort
*src
= (const GLshort
*) source
;
3801 for (i
= 0; i
< n
; i
++) {
3802 dest
[i
] = SHORT_TO_FLOAT(src
[i
]);
3806 case GL_UNSIGNED_SHORT
:
3809 const GLushort
*src
= (const GLushort
*) source
;
3810 for (i
= 0; i
< n
; i
++) {
3811 dest
[i
] = USHORT_TO_FLOAT(src
[i
]);
3818 const GLint
*src
= (const GLint
*) source
;
3819 for (i
= 0; i
< n
; i
++) {
3820 dest
[i
] = INT_TO_FLOAT(src
[i
]);
3824 case GL_UNSIGNED_INT
:
3827 const GLuint
*src
= (const GLuint
*) source
;
3828 for (i
= 0; i
< n
; i
++) {
3829 dest
[i
] = UINT_TO_FLOAT(src
[i
]);
3834 MEMCPY(dest
, source
, n
* sizeof(GLfloat
));
3836 case GL_HALF_FLOAT_NV
:
3839 const GLhalfNV
*src
= (const GLhalfNV
*) source
;
3840 for (i
= 0; i
< n
; i
++) {
3841 dest
[i
] = _mesa_half_to_float(src
[i
]);
3846 _mesa_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
3851 /* apply depth scale and bias and clamp to [0,1] */
3852 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
3854 for (i
= 0; i
< n
; i
++) {
3855 GLfloat d
= dest
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
3856 dest
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
3863 * Pack an array of depth values. The values are floats in [0,1].
3866 _mesa_pack_depth_span( const GLcontext
*ctx
, GLuint n
, GLvoid
*dest
,
3867 GLenum dstType
, const GLfloat
*depthSpan
,
3868 const struct gl_pixelstore_attrib
*dstPacking
)
3870 GLfloat depthCopy
[MAX_WIDTH
];
3871 const GLboolean bias_or_scale
= ctx
->Pixel
.DepthBias
!= 0.0 ||
3872 ctx
->Pixel
.DepthScale
!= 1.0;
3874 ASSERT(n
<= MAX_WIDTH
);
3876 if (bias_or_scale
) {
3878 for (i
= 0; i
< n
; i
++) {
3880 d
= depthSpan
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
3881 depthCopy
[i
] = CLAMP(d
, 0.0F
, 1.0F
);
3883 depthSpan
= depthCopy
;
3887 case GL_UNSIGNED_BYTE
:
3889 GLubyte
*dst
= (GLubyte
*) dest
;
3891 for (i
= 0; i
< n
; i
++) {
3892 dst
[i
] = FLOAT_TO_UBYTE( depthSpan
[i
] );
3898 GLbyte
*dst
= (GLbyte
*) dest
;
3900 for (i
= 0; i
< n
; i
++) {
3901 dst
[i
] = FLOAT_TO_BYTE( depthSpan
[i
] );
3905 case GL_UNSIGNED_SHORT
:
3907 GLushort
*dst
= (GLushort
*) dest
;
3909 for (i
= 0; i
< n
; i
++) {
3910 dst
[i
] = FLOAT_TO_USHORT( depthSpan
[i
] );
3912 if (dstPacking
->SwapBytes
) {
3913 _mesa_swap2( (GLushort
*) dst
, n
);
3919 GLshort
*dst
= (GLshort
*) dest
;
3921 for (i
= 0; i
< n
; i
++) {
3922 dst
[i
] = FLOAT_TO_SHORT( depthSpan
[i
] );
3924 if (dstPacking
->SwapBytes
) {
3925 _mesa_swap2( (GLushort
*) dst
, n
);
3929 case GL_UNSIGNED_INT
:
3931 GLuint
*dst
= (GLuint
*) dest
;
3933 for (i
= 0; i
< n
; i
++) {
3934 dst
[i
] = FLOAT_TO_UINT( depthSpan
[i
] );
3936 if (dstPacking
->SwapBytes
) {
3937 _mesa_swap4( (GLuint
*) dst
, n
);
3943 GLint
*dst
= (GLint
*) dest
;
3945 for (i
= 0; i
< n
; i
++) {
3946 dst
[i
] = FLOAT_TO_INT( depthSpan
[i
] );
3948 if (dstPacking
->SwapBytes
) {
3949 _mesa_swap4( (GLuint
*) dst
, n
);
3955 GLfloat
*dst
= (GLfloat
*) dest
;
3957 for (i
= 0; i
< n
; i
++) {
3958 dst
[i
] = depthSpan
[i
];
3960 if (dstPacking
->SwapBytes
) {
3961 _mesa_swap4( (GLuint
*) dst
, n
);
3965 case GL_HALF_FLOAT_NV
:
3967 GLhalfNV
*dst
= (GLhalfNV
*) dest
;
3969 for (i
= 0; i
< n
; i
++) {
3970 dst
[i
] = _mesa_float_to_half(depthSpan
[i
]);
3972 if (dstPacking
->SwapBytes
) {
3973 _mesa_swap2( (GLushort
*) dst
, n
);
3978 _mesa_problem(ctx
, "bad type in _mesa_pack_depth_span");
3984 * Unpack image data. Apply byteswapping, byte flipping (bitmap).
3985 * Return all image data in a contiguous block.
3988 _mesa_unpack_image( GLsizei width
, GLsizei height
, GLsizei depth
,
3989 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3990 const struct gl_pixelstore_attrib
*unpack
)
3992 GLint bytesPerRow
, compsPerRow
;
3993 GLboolean flipBytes
, swap2
, swap4
;
3996 return NULL
; /* not necessarily an error */
3998 if (width
<= 0 || height
<= 0 || depth
<= 0)
3999 return NULL
; /* generate error later */
4001 if (format
== GL_BITMAP
) {
4002 bytesPerRow
= (width
+ 7) >> 3;
4003 flipBytes
= !unpack
->LsbFirst
;
4004 swap2
= swap4
= GL_FALSE
;
4008 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
4009 const GLint components
= _mesa_components_in_format(format
);
4011 if (bytesPerPixel
<= 0 || components
<= 0)
4012 return NULL
; /* bad format or type. generate error later */
4013 bytesPerRow
= bytesPerPixel
* width
;
4014 bytesPerComp
= bytesPerPixel
/ components
;
4015 flipBytes
= GL_FALSE
;
4016 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
4017 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
4018 compsPerRow
= components
* width
;
4019 assert(compsPerRow
>= width
);
4023 GLubyte
*destBuffer
= (GLubyte
*) MALLOC(bytesPerRow
* height
* depth
);
4027 return NULL
; /* generate GL_OUT_OF_MEMORY later */
4030 for (img
= 0; img
< depth
; img
++) {
4031 for (row
= 0; row
< height
; row
++) {
4032 const GLvoid
*src
= _mesa_image_address(unpack
, pixels
,
4033 width
, height
, format
, type
, img
, row
, 0);
4034 MEMCPY(dst
, src
, bytesPerRow
);
4035 /* byte flipping/swapping */
4037 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
4040 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
4043 _mesa_swap4((GLuint
*) dst
, compsPerRow
);