1 /* $Id: image.c,v 1.32 2000/05/19 22:35:44 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 * These are the image packing parameters for Mesa's internal images.
46 * That is, _mesa_unpack_image() returns image data in this format.
47 * When we execute image commands (glDrawPixels, glTexImage, etc)
48 * from within display lists we have to be sure to set the current
49 * unpacking params to these values!
51 const struct gl_pixelstore_attrib _mesa_native_packing
= {
58 GL_FALSE
, /* SwapBytes */
59 GL_FALSE
/* LsbFirst */
65 * Flip the 8 bits in each byte of the given array.
68 flip_bytes( GLubyte
*p
, GLuint n
)
70 register GLuint i
, a
, b
;
74 a
= ((b
& 0x01) << 7) |
88 * Flip the order of the 2 bytes in each word in the given array.
91 _mesa_swap2( GLushort
*p
, GLuint n
)
96 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
103 * Flip the order of the 4 bytes in each word in the given array.
106 _mesa_swap4( GLuint
*p
, GLuint n
)
108 register GLuint i
, a
, b
;
113 | ((b
>> 8) & 0xff00)
114 | ((b
<< 8) & 0xff0000)
115 | ((b
<< 24) & 0xff000000);
124 * Return the size, in bytes, of the given GL datatype.
125 * Return 0 if GL_BITMAP.
126 * Return -1 if invalid type enum.
128 GLint
_mesa_sizeof_type( GLenum type
)
133 case GL_UNSIGNED_BYTE
:
134 return sizeof(GLubyte
);
136 return sizeof(GLbyte
);
137 case GL_UNSIGNED_SHORT
:
138 return sizeof(GLushort
);
140 return sizeof(GLshort
);
141 case GL_UNSIGNED_INT
:
142 return sizeof(GLuint
);
144 return sizeof(GLint
);
146 return sizeof(GLfloat
);
154 * Same as _mesa_sizeof_packed_type() but we also accept the
155 * packed pixel format datatypes.
157 GLint
_mesa_sizeof_packed_type( GLenum type
)
162 case GL_UNSIGNED_BYTE
:
163 return sizeof(GLubyte
);
165 return sizeof(GLbyte
);
166 case GL_UNSIGNED_SHORT
:
167 return sizeof(GLushort
);
169 return sizeof(GLshort
);
170 case GL_UNSIGNED_INT
:
171 return sizeof(GLuint
);
173 return sizeof(GLint
);
175 return sizeof(GLfloat
);
176 case GL_UNSIGNED_BYTE_3_3_2
:
177 return sizeof(GLubyte
);
178 case GL_UNSIGNED_BYTE_2_3_3_REV
:
179 return sizeof(GLubyte
);
180 case GL_UNSIGNED_SHORT_5_6_5
:
181 return sizeof(GLshort
);
182 case GL_UNSIGNED_SHORT_5_6_5_REV
:
183 return sizeof(GLshort
);
184 case GL_UNSIGNED_SHORT_4_4_4_4
:
185 return sizeof(GLshort
);
186 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
187 return sizeof(GLshort
);
188 case GL_UNSIGNED_SHORT_5_5_5_1
:
189 return sizeof(GLshort
);
190 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
191 return sizeof(GLshort
);
192 case GL_UNSIGNED_INT_8_8_8_8
:
193 return sizeof(GLuint
);
194 case GL_UNSIGNED_INT_8_8_8_8_REV
:
195 return sizeof(GLuint
);
196 case GL_UNSIGNED_INT_10_10_10_2
:
197 return sizeof(GLuint
);
198 case GL_UNSIGNED_INT_2_10_10_10_REV
:
199 return sizeof(GLuint
);
208 * Return the number of components in a GL enum pixel type.
209 * Return -1 if bad format.
211 GLint
_mesa_components_in_format( GLenum format
)
215 case GL_COLOR_INDEX1_EXT
:
216 case GL_COLOR_INDEX2_EXT
:
217 case GL_COLOR_INDEX4_EXT
:
218 case GL_COLOR_INDEX8_EXT
:
219 case GL_COLOR_INDEX12_EXT
:
220 case GL_COLOR_INDEX16_EXT
:
221 case GL_STENCIL_INDEX
:
222 case GL_DEPTH_COMPONENT
:
230 case GL_LUMINANCE_ALPHA
:
249 * Return bytes per pixel for given format and type
250 * Return -1 if bad format or type.
252 GLint
_mesa_bytes_per_pixel( GLenum format
, GLenum type
)
254 GLint comps
= _mesa_components_in_format( format
);
260 return 0; /* special case */
262 case GL_UNSIGNED_BYTE
:
263 return comps
* sizeof(GLubyte
);
265 case GL_UNSIGNED_SHORT
:
266 return comps
* sizeof(GLshort
);
268 case GL_UNSIGNED_INT
:
269 return comps
* sizeof(GLint
);
271 return comps
* sizeof(GLfloat
);
272 case GL_UNSIGNED_BYTE_3_3_2
:
273 case GL_UNSIGNED_BYTE_2_3_3_REV
:
274 if (format
== GL_RGB
|| format
== GL_BGR
)
275 return sizeof(GLubyte
);
277 return -1; /* error */
278 case GL_UNSIGNED_SHORT_5_6_5
:
279 case GL_UNSIGNED_SHORT_5_6_5_REV
:
280 if (format
== GL_RGB
|| format
== GL_BGR
)
281 return sizeof(GLshort
);
283 return -1; /* error */
284 case GL_UNSIGNED_SHORT_4_4_4_4
:
285 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
286 case GL_UNSIGNED_SHORT_5_5_5_1
:
287 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
288 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
289 return sizeof(GLushort
);
292 case GL_UNSIGNED_INT_8_8_8_8
:
293 case GL_UNSIGNED_INT_8_8_8_8_REV
:
294 case GL_UNSIGNED_INT_10_10_10_2
:
295 case GL_UNSIGNED_INT_2_10_10_10_REV
:
296 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
297 return sizeof(GLuint
);
307 * Test if the given pixel format and type are legal.
308 * Return GL_TRUE for legal, GL_FALSE for illegal.
311 _mesa_is_legal_format_and_type( GLenum format
, GLenum type
)
315 case GL_STENCIL_INDEX
:
319 case GL_UNSIGNED_BYTE
:
321 case GL_UNSIGNED_SHORT
:
323 case GL_UNSIGNED_INT
:
334 case GL_LUMINANCE_ALPHA
:
335 case GL_DEPTH_COMPONENT
:
339 case GL_UNSIGNED_BYTE
:
341 case GL_UNSIGNED_SHORT
:
343 case GL_UNSIGNED_INT
:
352 case GL_UNSIGNED_BYTE
:
354 case GL_UNSIGNED_SHORT
:
356 case GL_UNSIGNED_INT
:
358 case GL_UNSIGNED_BYTE_3_3_2
:
359 case GL_UNSIGNED_BYTE_2_3_3_REV
:
360 case GL_UNSIGNED_SHORT_5_6_5
:
361 case GL_UNSIGNED_SHORT_5_6_5_REV
:
371 case GL_UNSIGNED_BYTE
:
373 case GL_UNSIGNED_SHORT
:
375 case GL_UNSIGNED_INT
:
377 case GL_UNSIGNED_SHORT_4_4_4_4
:
378 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
379 case GL_UNSIGNED_SHORT_5_5_5_1
:
380 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
381 case GL_UNSIGNED_INT_8_8_8_8
:
382 case GL_UNSIGNED_INT_8_8_8_8_REV
:
383 case GL_UNSIGNED_INT_10_10_10_2
:
384 case GL_UNSIGNED_INT_2_10_10_10_REV
:
398 * Return the address of a pixel in an image (actually a volume).
399 * Pixel unpacking/packing parameters are observed according to 'packing'.
400 * Input: image - start of image data
401 * width, height - size of image
402 * format - image format
403 * type - pixel component type
404 * packing - the pixelstore attributes
405 * img - which image in the volume (0 for 1D or 2D images)
406 * row, column - location of pixel in the image
407 * Return: address of pixel at (image,row,column) in image or NULL if error.
410 _mesa_image_address( const struct gl_pixelstore_attrib
*packing
,
411 const GLvoid
*image
, GLsizei width
,
412 GLsizei height
, GLenum format
, GLenum type
,
413 GLint img
, GLint row
, GLint column
)
415 GLint alignment
; /* 1, 2 or 4 */
416 GLint pixels_per_row
;
417 GLint rows_per_image
;
420 GLint skipimages
; /* for 3-D volume images */
423 alignment
= packing
->Alignment
;
424 if (packing
->RowLength
> 0) {
425 pixels_per_row
= packing
->RowLength
;
428 pixels_per_row
= width
;
430 if (packing
->ImageHeight
> 0) {
431 rows_per_image
= packing
->ImageHeight
;
434 rows_per_image
= height
;
436 skiprows
= packing
->SkipRows
;
437 skippixels
= packing
->SkipPixels
;
438 skipimages
= packing
->SkipImages
;
440 if (type
==GL_BITMAP
) {
442 GLint comp_per_pixel
; /* components per pixel */
443 GLint bytes_per_comp
; /* bytes per component */
445 GLint bytes_per_image
;
447 /* Compute bytes per component */
448 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
449 if (bytes_per_comp
<0) {
453 /* Compute number of components per pixel */
454 comp_per_pixel
= _mesa_components_in_format( format
);
455 if (comp_per_pixel
<0 && type
!= GL_BITMAP
) {
459 bytes_per_row
= alignment
460 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
462 bytes_per_image
= bytes_per_row
* rows_per_image
;
464 pixel_addr
= (GLubyte
*) image
465 + (skipimages
+ img
) * bytes_per_image
466 + (skiprows
+ row
) * bytes_per_row
467 + (skippixels
+ column
) / 8;
470 /* Non-BITMAP data */
471 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
473 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
475 /* The pixel type and format should have been error checked earlier */
476 assert(bytes_per_pixel
> 0);
478 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
479 remainder
= bytes_per_row
% alignment
;
481 bytes_per_row
+= (alignment
- remainder
);
483 ASSERT(bytes_per_row
% alignment
== 0);
485 bytes_per_image
= bytes_per_row
* rows_per_image
;
487 /* compute final pixel address */
488 pixel_addr
= (GLubyte
*) image
489 + (skipimages
+ img
) * bytes_per_image
490 + (skiprows
+ row
) * bytes_per_row
491 + (skippixels
+ column
) * bytes_per_pixel
;
494 return (GLvoid
*) pixel_addr
;
500 * Compute the stride between image rows (in bytes) for the given
501 * pixel packing parameters and image width, format and type.
504 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
505 GLint width
, GLenum format
, GLenum type
)
508 if (type
== GL_BITMAP
) {
510 if (packing
->RowLength
== 0) {
511 GLint bytes
= (width
+ 7) / 8;
515 GLint bytes
= (packing
->RowLength
+ 7) / 8;
520 /* Non-BITMAP data */
521 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
522 GLint bytesPerRow
, remainder
;
523 if (bytesPerPixel
<= 0)
524 return -1; /* error */
525 if (packing
->RowLength
== 0) {
526 bytesPerRow
= bytesPerPixel
* width
;
529 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
531 remainder
= bytesPerRow
% packing
->Alignment
;
533 bytesPerRow
+= (packing
->Alignment
- remainder
);
541 * Unpack a 32x32 pixel polygon stipple from user memory using the
542 * current pixel unpack settings.
545 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
546 const struct gl_pixelstore_attrib
*unpacking
)
548 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap( 32, 32, pattern
, unpacking
);
550 /* Convert pattern from GLubytes to GLuints and handle big/little
555 for (i
= 0; i
< 32; i
++) {
556 dest
[i
] = (p
[0] << 24)
569 * Pack polygon stipple into user memory given current pixel packing
573 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
574 const struct gl_pixelstore_attrib
*packing
)
576 /* Convert pattern from GLuints to GLubytes to handle big/little
577 * endian differences.
581 for (i
= 0; i
< 32; i
++) {
582 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
583 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
584 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
585 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
588 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
594 * Pack the given RGBA span into client memory at 'dest' address
595 * in the given pixel format and type.
596 * Optionally apply the enabled pixel transfer ops.
597 * Pack into memory using the given packing params struct.
598 * This is used by glReadPixels and glGetTexImage?D()
599 * Input: ctx - the context
600 * n - number of pixels in the span
602 * format - dest packing format
603 * type - dest packing datatype
604 * destination - destination packing address
605 * packing - pixel packing parameters
606 * applyTransferOps - apply scale/bias/lookup-table ops?
609 _mesa_pack_rgba_span( GLcontext
*ctx
,
610 GLuint n
, CONST GLubyte srcRgba
[][4],
611 GLenum format
, GLenum type
, GLvoid
*destination
,
612 const struct gl_pixelstore_attrib
*packing
,
613 GLboolean applyTransferOps
)
615 applyTransferOps
&= (ctx
->Pixel
.ScaleOrBiasRGBA
||
616 ctx
->Pixel
.MapColorFlag
||
617 ctx
->ColorMatrix
.type
!= MATRIX_IDENTITY
||
618 ctx
->Pixel
.ScaleOrBiasRGBApcm
||
619 ctx
->Pixel
.ColorTableEnabled
||
620 ctx
->Pixel
.PostColorMatrixColorTableEnabled
||
621 ctx
->Pixel
.MinMaxEnabled
||
622 ctx
->Pixel
.HistogramEnabled
);
624 /* Test for optimized case first */
625 if (!applyTransferOps
&& format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
626 /* common simple case */
627 MEMCPY( destination
, srcRgba
, n
* 4 * sizeof(GLubyte
) );
629 else if (!applyTransferOps
&& format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
630 /* common simple case */
632 GLubyte
*dest
= (GLubyte
*) destination
;
633 for (i
= 0; i
< n
; i
++) {
634 dest
[0] = srcRgba
[i
][RCOMP
];
635 dest
[1] = srcRgba
[i
][GCOMP
];
636 dest
[2] = srcRgba
[i
][BCOMP
];
641 /* general solution */
642 GLfloat rgba
[MAX_WIDTH
][4], luminance
[MAX_WIDTH
];
643 const GLfloat rscale
= 1.0F
/ 255.0F
;
644 const GLfloat gscale
= 1.0F
/ 255.0F
;
645 const GLfloat bscale
= 1.0F
/ 255.0F
;
646 const GLfloat ascale
= 1.0F
/ 255.0F
;
647 const GLint comps
= _mesa_components_in_format(format
);
650 assert(n
<= MAX_WIDTH
);
652 /* convert color components to floating point */
654 rgba
[i
][RCOMP
] = srcRgba
[i
][RCOMP
] * rscale
;
655 rgba
[i
][GCOMP
] = srcRgba
[i
][GCOMP
] * gscale
;
656 rgba
[i
][BCOMP
] = srcRgba
[i
][BCOMP
] * bscale
;
657 rgba
[i
][ACOMP
] = srcRgba
[i
][ACOMP
] * ascale
;
661 * Apply scale, bias and lookup-tables if enabled.
663 if (applyTransferOps
) {
665 if (ctx
->Pixel
.ScaleOrBiasRGBA
) {
666 _mesa_scale_and_bias_rgba( ctx
, n
, rgba
);
668 /* color map lookup */
669 if (ctx
->Pixel
.MapColorFlag
) {
670 _mesa_map_rgba( ctx
, n
, rgba
);
672 /* GL_COLOR_TABLE lookup */
673 if (ctx
->Pixel
.ColorTableEnabled
) {
674 _mesa_lookup_rgba(&ctx
->ColorTable
, n
, rgba
);
676 /* XXX convolution here */
677 /* XXX post-convolution color table look-up here */
679 if (ctx
->ColorMatrix
.type
!= MATRIX_IDENTITY
||
680 ctx
->Pixel
.ScaleOrBiasRGBApcm
) {
681 _mesa_transform_rgba(ctx
, n
, rgba
);
683 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
684 if (ctx
->Pixel
.PostColorMatrixColorTableEnabled
) {
685 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
687 /* update histogram count */
688 if (ctx
->Pixel
.HistogramEnabled
) {
689 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
691 /* XXX min/max here */
692 if (ctx
->Pixel
.MinMaxEnabled
) {
693 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
694 if (ctx
->MinMax
.Sink
)
699 if (format
==GL_LUMINANCE
|| format
==GL_LUMINANCE_ALPHA
) {
701 GLfloat sum
= rgba
[i
][RCOMP
] + rgba
[i
][GCOMP
] + rgba
[i
][BCOMP
];
702 luminance
[i
] = CLAMP( sum
, 0.0F
, 1.0F
);
707 * Pack/store the pixels. Ugh! Lots of cases!!!
710 case GL_UNSIGNED_BYTE
:
712 GLubyte
*dst
= (GLubyte
*) destination
;
716 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
720 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
724 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
728 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
732 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
734 case GL_LUMINANCE_ALPHA
:
736 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
737 dst
[i
*2+1] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
742 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
743 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
744 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
749 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
750 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
751 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
752 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
757 dst
[i
*3+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
758 dst
[i
*3+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
759 dst
[i
*3+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
764 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
765 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
766 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
767 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
772 dst
[i
*4+0] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
773 dst
[i
*4+1] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
774 dst
[i
*4+2] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
775 dst
[i
*4+3] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
779 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
785 GLbyte
*dst
= (GLbyte
*) destination
;
789 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
793 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
797 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
801 dst
[i
] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
805 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
807 case GL_LUMINANCE_ALPHA
:
809 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
810 dst
[i
*2+1] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
815 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
816 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
817 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
822 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
823 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
824 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
825 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
830 dst
[i
*3+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
831 dst
[i
*3+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
832 dst
[i
*3+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
837 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
838 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
839 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
840 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
844 dst
[i
*4+0] = FLOAT_TO_BYTE(rgba
[i
][ACOMP
]);
845 dst
[i
*4+1] = FLOAT_TO_BYTE(rgba
[i
][BCOMP
]);
846 dst
[i
*4+2] = FLOAT_TO_BYTE(rgba
[i
][GCOMP
]);
847 dst
[i
*4+3] = FLOAT_TO_BYTE(rgba
[i
][RCOMP
]);
851 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
855 case GL_UNSIGNED_SHORT
:
857 GLushort
*dst
= (GLushort
*) destination
;
861 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
865 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
869 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
873 dst
[i
] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
877 dst
[i
] = FLOAT_TO_USHORT(luminance
[i
]);
879 case GL_LUMINANCE_ALPHA
:
881 dst
[i
*2+0] = FLOAT_TO_USHORT(luminance
[i
]);
882 dst
[i
*2+1] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
887 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
888 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
889 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
894 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
895 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
896 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
897 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
902 dst
[i
*3+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
903 dst
[i
*3+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
904 dst
[i
*3+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
909 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
910 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
911 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
912 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
917 dst
[i
*4+0] = FLOAT_TO_USHORT(rgba
[i
][ACOMP
]);
918 dst
[i
*4+1] = FLOAT_TO_USHORT(rgba
[i
][BCOMP
]);
919 dst
[i
*4+2] = FLOAT_TO_USHORT(rgba
[i
][GCOMP
]);
920 dst
[i
*4+3] = FLOAT_TO_USHORT(rgba
[i
][RCOMP
]);
924 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
926 if (packing
->SwapBytes
) {
927 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
933 GLshort
*dst
= (GLshort
*) destination
;
937 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
941 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
945 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
949 dst
[i
] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
953 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
955 case GL_LUMINANCE_ALPHA
:
957 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
958 dst
[i
*2+1] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
963 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
964 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
965 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
970 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
971 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
972 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
973 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
978 dst
[i
*3+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
979 dst
[i
*3+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
980 dst
[i
*3+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
985 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
986 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
987 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
988 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
992 dst
[i
*4+0] = FLOAT_TO_SHORT(rgba
[i
][ACOMP
]);
993 dst
[i
*4+1] = FLOAT_TO_SHORT(rgba
[i
][BCOMP
]);
994 dst
[i
*4+2] = FLOAT_TO_SHORT(rgba
[i
][GCOMP
]);
995 dst
[i
*4+3] = FLOAT_TO_SHORT(rgba
[i
][RCOMP
]);
999 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1001 if (packing
->SwapBytes
) {
1002 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
1006 case GL_UNSIGNED_INT
:
1008 GLuint
*dst
= (GLuint
*) destination
;
1012 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1016 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1020 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1024 dst
[i
] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1028 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
1030 case GL_LUMINANCE_ALPHA
:
1032 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
1033 dst
[i
*2+1] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1038 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1039 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1040 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1045 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1046 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1047 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1048 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1053 dst
[i
*3+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1054 dst
[i
*3+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1055 dst
[i
*3+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1060 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1061 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1062 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1063 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1068 dst
[i
*4+0] = FLOAT_TO_UINT(rgba
[i
][ACOMP
]);
1069 dst
[i
*4+1] = FLOAT_TO_UINT(rgba
[i
][BCOMP
]);
1070 dst
[i
*4+2] = FLOAT_TO_UINT(rgba
[i
][GCOMP
]);
1071 dst
[i
*4+3] = FLOAT_TO_UINT(rgba
[i
][RCOMP
]);
1075 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1077 if (packing
->SwapBytes
) {
1078 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1084 GLint
*dst
= (GLint
*) destination
;
1088 dst
[i
] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1092 dst
[i
] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1096 dst
[i
] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1100 dst
[i
] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1104 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1106 case GL_LUMINANCE_ALPHA
:
1108 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1109 dst
[i
*2+1] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1114 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1115 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1116 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1121 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1122 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1123 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1124 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1129 dst
[i
*3+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1130 dst
[i
*3+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1131 dst
[i
*3+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1136 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1137 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1138 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1139 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1144 dst
[i
*4+0] = FLOAT_TO_INT(rgba
[i
][ACOMP
]);
1145 dst
[i
*4+1] = FLOAT_TO_INT(rgba
[i
][BCOMP
]);
1146 dst
[i
*4+2] = FLOAT_TO_INT(rgba
[i
][GCOMP
]);
1147 dst
[i
*4+3] = FLOAT_TO_INT(rgba
[i
][RCOMP
]);
1151 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1153 if (packing
->SwapBytes
) {
1154 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1160 GLfloat
*dst
= (GLfloat
*) destination
;
1164 dst
[i
] = rgba
[i
][RCOMP
];
1168 dst
[i
] = rgba
[i
][GCOMP
];
1172 dst
[i
] = rgba
[i
][BCOMP
];
1176 dst
[i
] = rgba
[i
][ACOMP
];
1180 dst
[i
] = luminance
[i
];
1182 case GL_LUMINANCE_ALPHA
:
1184 dst
[i
*2+0] = luminance
[i
];
1185 dst
[i
*2+1] = rgba
[i
][ACOMP
];
1190 dst
[i
*3+0] = rgba
[i
][RCOMP
];
1191 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1192 dst
[i
*3+2] = rgba
[i
][BCOMP
];
1197 dst
[i
*4+0] = rgba
[i
][RCOMP
];
1198 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1199 dst
[i
*4+2] = rgba
[i
][BCOMP
];
1200 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1205 dst
[i
*3+0] = rgba
[i
][BCOMP
];
1206 dst
[i
*3+1] = rgba
[i
][GCOMP
];
1207 dst
[i
*3+2] = rgba
[i
][RCOMP
];
1212 dst
[i
*4+0] = rgba
[i
][BCOMP
];
1213 dst
[i
*4+1] = rgba
[i
][GCOMP
];
1214 dst
[i
*4+2] = rgba
[i
][RCOMP
];
1215 dst
[i
*4+3] = rgba
[i
][ACOMP
];
1220 dst
[i
*4+0] = rgba
[i
][ACOMP
];
1221 dst
[i
*4+1] = rgba
[i
][BCOMP
];
1222 dst
[i
*4+2] = rgba
[i
][GCOMP
];
1223 dst
[i
*4+3] = rgba
[i
][RCOMP
];
1227 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1229 if (packing
->SwapBytes
) {
1230 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1234 case GL_UNSIGNED_BYTE_3_3_2
:
1235 if (format
== GL_RGB
) {
1236 GLubyte
*dst
= (GLubyte
*) destination
;
1238 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) << 5)
1239 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 2)
1240 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) );
1244 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1245 if (format
== GL_RGB
) {
1246 GLubyte
*dst
= (GLubyte
*) destination
;
1248 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 7.0F
)) )
1249 | (((GLint
) (rgba
[i
][GCOMP
] * 7.0F
)) << 3)
1250 | (((GLint
) (rgba
[i
][BCOMP
] * 3.0F
)) << 5);
1254 case GL_UNSIGNED_SHORT_5_6_5
:
1255 if (format
== GL_RGB
) {
1256 GLushort
*dst
= (GLushort
*) destination
;
1258 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1259 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1260 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) );
1264 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1265 if (format
== GL_RGB
) {
1266 GLushort
*dst
= (GLushort
*) destination
;
1268 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1269 | (((GLint
) (rgba
[i
][GCOMP
] * 63.0F
)) << 5)
1270 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 11);
1274 case GL_UNSIGNED_SHORT_4_4_4_4
:
1275 if (format
== GL_RGB
) {
1276 GLushort
*dst
= (GLushort
*) destination
;
1278 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) << 12)
1279 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 8)
1280 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 4)
1281 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) );
1285 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1286 if (format
== GL_RGB
) {
1287 GLushort
*dst
= (GLushort
*) destination
;
1289 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 15.0F
)) )
1290 | (((GLint
) (rgba
[i
][GCOMP
] * 15.0F
)) << 4)
1291 | (((GLint
) (rgba
[i
][BCOMP
] * 15.0F
)) << 8)
1292 | (((GLint
) (rgba
[i
][ACOMP
] * 15.0F
)) << 12);
1296 case GL_UNSIGNED_SHORT_5_5_5_1
:
1297 if (format
== GL_RGB
) {
1298 GLushort
*dst
= (GLushort
*) destination
;
1300 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) << 11)
1301 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 6)
1302 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 1)
1303 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) );
1307 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1308 if (format
== GL_RGB
) {
1309 GLushort
*dst
= (GLushort
*) destination
;
1311 dst
[i
] = (((GLint
) (rgba
[i
][RCOMP
] * 31.0F
)) )
1312 | (((GLint
) (rgba
[i
][GCOMP
] * 31.0F
)) << 5)
1313 | (((GLint
) (rgba
[i
][BCOMP
] * 31.0F
)) << 10)
1314 | (((GLint
) (rgba
[i
][ACOMP
] * 1.0F
)) << 15);
1318 case GL_UNSIGNED_INT_8_8_8_8
:
1319 if (format
== GL_RGBA
) {
1320 GLuint
*dst
= (GLuint
*) destination
;
1322 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24)
1323 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1324 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1325 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1328 else if (format
== GL_BGRA
) {
1329 GLuint
*dst
= (GLuint
*) destination
;
1331 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 24)
1332 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1333 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 8)
1334 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) );
1337 else if (format
== GL_ABGR_EXT
) {
1338 GLuint
*dst
= (GLuint
*) destination
;
1340 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24)
1341 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1342 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1343 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) );
1347 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1348 if (format
== GL_RGBA
) {
1349 GLuint
*dst
= (GLuint
*) destination
;
1351 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) )
1352 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1353 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 16)
1354 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1357 else if (format
== GL_BGRA
) {
1358 GLuint
*dst
= (GLuint
*) destination
;
1360 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) )
1361 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 8)
1362 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 16)
1363 | (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) << 24);
1366 else if (format
== GL_ABGR_EXT
) {
1367 GLuint
*dst
= (GLuint
*) destination
;
1369 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 255.0F
)) )
1370 | (((GLuint
) (rgba
[i
][BCOMP
] * 255.0F
)) << 8)
1371 | (((GLuint
) (rgba
[i
][GCOMP
] * 255.0F
)) << 16)
1372 | (((GLuint
) (rgba
[i
][RCOMP
] * 255.0F
)) << 24);
1376 case GL_UNSIGNED_INT_10_10_10_2
:
1377 if (format
== GL_RGBA
) {
1378 GLuint
*dst
= (GLuint
*) destination
;
1380 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 22)
1381 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1382 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 2)
1383 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1386 else if (format
== GL_BGRA
) {
1387 GLuint
*dst
= (GLuint
*) destination
;
1389 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 22)
1390 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 12)
1391 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 2)
1392 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) );
1395 else if (format
== GL_ABGR_EXT
) {
1396 GLuint
*dst
= (GLuint
*) destination
;
1398 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) << 22)
1399 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 12)
1400 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 2)
1401 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) );
1405 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1406 if (format
== GL_RGBA
) {
1407 GLuint
*dst
= (GLuint
*) destination
;
1409 dst
[i
] = (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) )
1410 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1411 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 20)
1412 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1415 else if (format
== GL_BGRA
) {
1416 GLuint
*dst
= (GLuint
*) destination
;
1418 dst
[i
] = (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) )
1419 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 10)
1420 | (((GLuint
) (rgba
[i
][RCOMP
] * 1023.0F
)) << 20)
1421 | (((GLuint
) (rgba
[i
][ACOMP
] * 3.0F
)) << 30);
1424 else if (format
== GL_ABGR_EXT
) {
1425 GLuint
*dst
= (GLuint
*) destination
;
1427 dst
[i
] = (((GLuint
) (rgba
[i
][ACOMP
] * 1023.0F
)) )
1428 | (((GLuint
) (rgba
[i
][BCOMP
] * 1023.0F
)) << 10)
1429 | (((GLuint
) (rgba
[i
][GCOMP
] * 1023.0F
)) << 20)
1430 | (((GLuint
) (rgba
[i
][RCOMP
] * 3.0F
)) << 30);
1435 gl_problem( ctx
, "bad type in _mesa_pack_rgba_span" );
1442 #define SWAP2BYTE(VALUE) \
1444 GLubyte *bytes = (GLubyte *) &(VALUE); \
1445 GLubyte tmp = bytes[0]; \
1446 bytes[0] = bytes[1]; \
1450 #define SWAP4BYTE(VALUE) \
1452 GLubyte *bytes = (GLubyte *) &(VALUE); \
1453 GLubyte tmp = bytes[0]; \
1454 bytes[0] = bytes[3]; \
1457 bytes[1] = bytes[2]; \
1463 extract_uint_indexes(GLuint n
, GLuint indexes
[],
1464 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
1465 const struct gl_pixelstore_attrib
*unpack
)
1467 assert(srcFormat
== GL_COLOR_INDEX
);
1469 ASSERT(srcType
== GL_BITMAP
||
1470 srcType
== GL_UNSIGNED_BYTE
||
1471 srcType
== GL_BYTE
||
1472 srcType
== GL_UNSIGNED_SHORT
||
1473 srcType
== GL_SHORT
||
1474 srcType
== GL_UNSIGNED_INT
||
1475 srcType
== GL_INT
||
1476 srcType
== GL_FLOAT
);
1481 GLubyte
*ubsrc
= (GLubyte
*) src
;
1482 if (unpack
->LsbFirst
) {
1483 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
1485 for (i
= 0; i
< n
; i
++) {
1486 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
1497 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
1499 for (i
= 0; i
< n
; i
++) {
1500 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
1512 case GL_UNSIGNED_BYTE
:
1515 const GLubyte
*s
= (const GLubyte
*) src
;
1516 for (i
= 0; i
< n
; i
++)
1523 const GLbyte
*s
= (const GLbyte
*) src
;
1524 for (i
= 0; i
< n
; i
++)
1528 case GL_UNSIGNED_SHORT
:
1531 const GLushort
*s
= (const GLushort
*) src
;
1532 if (unpack
->SwapBytes
) {
1533 for (i
= 0; i
< n
; i
++) {
1534 GLushort value
= s
[i
];
1540 for (i
= 0; i
< n
; i
++)
1548 const GLshort
*s
= (const GLshort
*) src
;
1549 if (unpack
->SwapBytes
) {
1550 for (i
= 0; i
< n
; i
++) {
1551 GLshort value
= s
[i
];
1557 for (i
= 0; i
< n
; i
++)
1562 case GL_UNSIGNED_INT
:
1565 const GLuint
*s
= (const GLuint
*) src
;
1566 if (unpack
->SwapBytes
) {
1567 for (i
= 0; i
< n
; i
++) {
1568 GLuint value
= s
[i
];
1574 for (i
= 0; i
< n
; i
++)
1582 const GLint
*s
= (const GLint
*) src
;
1583 if (unpack
->SwapBytes
) {
1584 for (i
= 0; i
< n
; i
++) {
1591 for (i
= 0; i
< n
; i
++)
1599 const GLfloat
*s
= (const GLfloat
*) src
;
1600 if (unpack
->SwapBytes
) {
1601 for (i
= 0; i
< n
; i
++) {
1602 GLfloat value
= s
[i
];
1604 indexes
[i
] = (GLuint
) value
;
1608 for (i
= 0; i
< n
; i
++)
1609 indexes
[i
] = (GLuint
) s
[i
];
1614 gl_problem(NULL
, "bad srcType in extract_uint_indexes");
1622 * This function extracts floating point RGBA values from arbitrary
1623 * image data. srcFormat and srcType are the format and type parameters
1624 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
1626 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
1627 * implements the "Conversion to floating point", "Conversion to RGB",
1628 * and "Final Expansion to RGBA" operations.
1630 * Args: n - number of pixels
1631 * rgba - output colors
1632 * srcFormat - format of incoming data
1633 * srcType - datatype of incoming data
1634 * src - source data pointer
1635 * swapBytes - perform byteswapping of incoming data?
1638 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
1639 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
1640 GLboolean swapBytes
)
1642 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
1644 GLint rComp
, bComp
, gComp
, aComp
;
1646 ASSERT(srcFormat
== GL_RED
||
1647 srcFormat
== GL_GREEN
||
1648 srcFormat
== GL_BLUE
||
1649 srcFormat
== GL_ALPHA
||
1650 srcFormat
== GL_LUMINANCE
||
1651 srcFormat
== GL_LUMINANCE_ALPHA
||
1652 srcFormat
== GL_INTENSITY
||
1653 srcFormat
== GL_RGB
||
1654 srcFormat
== GL_BGR
||
1655 srcFormat
== GL_RGBA
||
1656 srcFormat
== GL_BGRA
||
1657 srcFormat
== GL_ABGR_EXT
);
1659 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
1660 srcType
== GL_BYTE
||
1661 srcType
== GL_UNSIGNED_SHORT
||
1662 srcType
== GL_SHORT
||
1663 srcType
== GL_UNSIGNED_INT
||
1664 srcType
== GL_INT
||
1665 srcType
== GL_FLOAT
||
1666 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
1667 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
1668 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
1669 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
1670 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
1671 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
1672 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
1673 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
1674 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1675 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
1676 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
1677 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1679 rComp
= gComp
= bComp
= aComp
= -1;
1681 switch (srcFormat
) {
1684 greenIndex
= blueIndex
= alphaIndex
= -1;
1689 redIndex
= blueIndex
= alphaIndex
= -1;
1694 redIndex
= greenIndex
= alphaIndex
= -1;
1698 redIndex
= greenIndex
= blueIndex
= -1;
1703 redIndex
= greenIndex
= blueIndex
= 0;
1707 case GL_LUMINANCE_ALPHA
:
1708 redIndex
= greenIndex
= blueIndex
= 0;
1714 greenIndex
= blueIndex
= alphaIndex
= -1;
1765 gl_problem(NULL
, "bad srcFormat in extract float data");
1770 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
1771 if ((INDEX) < 0) { \
1773 for (i = 0; i < n; i++) { \
1774 rgba[i][CHANNEL] = DEFAULT; \
1777 else if (swapBytes) { \
1778 const TYPE *s = (const TYPE *) src; \
1780 for (i = 0; i < n; i++) { \
1781 TYPE value = s[INDEX]; \
1782 if (sizeof(TYPE) == 2) { \
1785 else if (sizeof(TYPE) == 4) { \
1788 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
1793 const TYPE *s = (const TYPE *) src; \
1795 for (i = 0; i < n; i++) { \
1796 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
1802 case GL_UNSIGNED_BYTE
:
1803 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1804 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1805 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1806 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1809 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1810 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1811 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1812 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
1814 case GL_UNSIGNED_SHORT
:
1815 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1816 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1817 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1818 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
1821 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1822 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1823 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1824 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
1826 case GL_UNSIGNED_INT
:
1827 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1828 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1829 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1830 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
1833 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1834 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1835 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1836 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
1839 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1840 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1841 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1842 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
1844 case GL_UNSIGNED_BYTE_3_3_2
:
1846 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
1848 for (i
= 0; i
< n
; i
++) {
1849 GLubyte p
= ubsrc
[i
];
1850 rgba
[i
][RCOMP
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
1851 rgba
[i
][GCOMP
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
1852 rgba
[i
][BCOMP
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
1853 rgba
[i
][ACOMP
] = 1.0F
;
1857 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1859 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
1861 for (i
= 0; i
< n
; i
++) {
1862 GLubyte p
= ubsrc
[i
];
1863 rgba
[i
][RCOMP
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
1864 rgba
[i
][GCOMP
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
1865 rgba
[i
][BCOMP
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
1866 rgba
[i
][ACOMP
] = 1.0F
;
1870 case GL_UNSIGNED_SHORT_5_6_5
:
1872 const GLushort
*ussrc
= (const GLushort
*) src
;
1874 for (i
= 0; i
< n
; i
++) {
1875 GLushort p
= ussrc
[i
];
1877 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1878 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1879 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1880 rgba
[i
][ACOMP
] = 1.0F
;
1884 const GLushort
*ussrc
= (const GLushort
*) src
;
1886 for (i
= 0; i
< n
; i
++) {
1887 GLushort p
= ussrc
[i
];
1888 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1889 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1890 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1891 rgba
[i
][ACOMP
] = 1.0F
;
1895 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1897 const GLushort
*ussrc
= (const GLushort
*) src
;
1899 for (i
= 0; i
< n
; i
++) {
1900 GLushort p
= ussrc
[i
];
1902 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1903 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1904 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1905 rgba
[i
][ACOMP
] = 1.0F
;
1909 const GLushort
*ussrc
= (const GLushort
*) src
;
1911 for (i
= 0; i
< n
; i
++) {
1912 GLushort p
= ussrc
[i
];
1913 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1914 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1915 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1916 rgba
[i
][ACOMP
] = 1.0F
;
1920 case GL_UNSIGNED_SHORT_4_4_4_4
:
1922 const GLushort
*ussrc
= (const GLushort
*) src
;
1924 for (i
= 0; i
< n
; i
++) {
1925 GLushort p
= ussrc
[i
];
1927 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1928 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1929 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1930 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1934 const GLushort
*ussrc
= (const GLushort
*) src
;
1936 for (i
= 0; i
< n
; i
++) {
1937 GLushort p
= ussrc
[i
];
1938 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1939 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1940 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1941 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1945 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1947 const GLushort
*ussrc
= (const GLushort
*) src
;
1949 for (i
= 0; i
< n
; i
++) {
1950 GLushort p
= ussrc
[i
];
1952 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1953 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1954 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1955 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1959 const GLushort
*ussrc
= (const GLushort
*) src
;
1961 for (i
= 0; i
< n
; i
++) {
1962 GLushort p
= ussrc
[i
];
1963 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1964 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1965 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1966 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1970 case GL_UNSIGNED_SHORT_5_5_5_1
:
1972 const GLushort
*ussrc
= (const GLushort
*) src
;
1974 for (i
= 0; i
< n
; i
++) {
1975 GLushort p
= ussrc
[i
];
1977 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1978 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
1979 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
1980 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
1984 const GLushort
*ussrc
= (const GLushort
*) src
;
1986 for (i
= 0; i
< n
; i
++) {
1987 GLushort p
= ussrc
[i
];
1988 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1989 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
1990 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
1991 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
1995 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1997 const GLushort
*ussrc
= (const GLushort
*) src
;
1999 for (i
= 0; i
< n
; i
++) {
2000 GLushort p
= ussrc
[i
];
2002 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2003 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2004 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2005 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2009 const GLushort
*ussrc
= (const GLushort
*) src
;
2011 for (i
= 0; i
< n
; i
++) {
2012 GLushort p
= ussrc
[i
];
2013 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
2014 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
2015 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
2016 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
2020 case GL_UNSIGNED_INT_8_8_8_8
:
2022 const GLuint
*uisrc
= (const GLuint
*) src
;
2024 for (i
= 0; i
< n
; i
++) {
2025 GLuint p
= uisrc
[i
];
2026 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2027 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2028 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2029 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2033 const GLuint
*uisrc
= (const GLuint
*) src
;
2035 for (i
= 0; i
< n
; i
++) {
2036 GLuint p
= uisrc
[i
];
2037 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2038 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2039 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2040 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2044 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2046 const GLuint
*uisrc
= (const GLuint
*) src
;
2048 for (i
= 0; i
< n
; i
++) {
2049 GLuint p
= uisrc
[i
];
2050 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2051 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2052 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2053 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2057 const GLuint
*uisrc
= (const GLuint
*) src
;
2059 for (i
= 0; i
< n
; i
++) {
2060 GLuint p
= uisrc
[i
];
2061 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2062 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2063 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2064 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2068 case GL_UNSIGNED_INT_10_10_10_2
:
2070 const GLuint
*uisrc
= (const GLuint
*) src
;
2072 for (i
= 0; i
< n
; i
++) {
2073 GLuint p
= uisrc
[i
];
2075 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2076 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2077 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2078 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2082 const GLuint
*uisrc
= (const GLuint
*) src
;
2084 for (i
= 0; i
< n
; i
++) {
2085 GLuint p
= uisrc
[i
];
2086 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2087 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2088 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2089 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2093 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2095 const GLuint
*uisrc
= (const GLuint
*) src
;
2097 for (i
= 0; i
< n
; i
++) {
2098 GLuint p
= uisrc
[i
];
2100 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2101 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2102 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2103 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2107 const GLuint
*uisrc
= (const GLuint
*) src
;
2109 for (i
= 0; i
< n
; i
++) {
2110 GLuint p
= uisrc
[i
];
2111 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2112 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2113 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2114 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2119 gl_problem(NULL
, "bad srcType in extract float data");
2127 * Unpack a row of color image data from a client buffer according to
2128 * the pixel unpacking parameters. Apply any enabled pixel transfer
2129 * ops (PixelMap, scale/bias) if the applyTransferOps flag is enabled.
2130 * Return GLubyte values in the specified dest image format.
2131 * This is (or will be) used by glDrawPixels and glTexImage?D().
2132 * Input: ctx - the context
2133 * n - number of pixels in the span
2134 * dstFormat - format of destination color array
2135 * dest - the destination color array
2136 * srcFormat - source image format
2137 * srcType - source image datatype
2138 * source - source image pointer
2139 * unpacking - pixel unpacking parameters
2140 * applyTransferOps - apply scale/bias/lookup-table ops?
2142 * XXX perhaps expand this to process whole images someday.
2145 _mesa_unpack_ubyte_color_span( GLcontext
*ctx
,
2146 GLuint n
, GLenum dstFormat
, GLubyte dest
[],
2147 GLenum srcFormat
, GLenum srcType
,
2148 const GLvoid
*source
,
2149 const struct gl_pixelstore_attrib
*unpacking
,
2150 GLboolean applyTransferOps
)
2152 ASSERT(dstFormat
== GL_ALPHA
||
2153 dstFormat
== GL_LUMINANCE
||
2154 dstFormat
== GL_LUMINANCE_ALPHA
||
2155 dstFormat
== GL_INTENSITY
||
2156 dstFormat
== GL_RGB
||
2157 dstFormat
== GL_RGBA
||
2158 dstFormat
== GL_COLOR_INDEX
);
2160 ASSERT(srcFormat
== GL_RED
||
2161 srcFormat
== GL_GREEN
||
2162 srcFormat
== GL_BLUE
||
2163 srcFormat
== GL_ALPHA
||
2164 srcFormat
== GL_LUMINANCE
||
2165 srcFormat
== GL_LUMINANCE_ALPHA
||
2166 srcFormat
== GL_INTENSITY
||
2167 srcFormat
== GL_RGB
||
2168 srcFormat
== GL_BGR
||
2169 srcFormat
== GL_RGBA
||
2170 srcFormat
== GL_BGRA
||
2171 srcFormat
== GL_ABGR_EXT
||
2172 srcFormat
== GL_COLOR_INDEX
);
2174 ASSERT(srcType
== GL_BITMAP
||
2175 srcType
== GL_UNSIGNED_BYTE
||
2176 srcType
== GL_BYTE
||
2177 srcType
== GL_UNSIGNED_SHORT
||
2178 srcType
== GL_SHORT
||
2179 srcType
== GL_UNSIGNED_INT
||
2180 srcType
== GL_INT
||
2181 srcType
== GL_FLOAT
||
2182 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2183 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2184 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2185 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2186 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2187 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2188 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2189 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2190 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2191 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2192 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2193 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2195 /* this is intended for RGBA mode only */
2196 assert(ctx
->Visual
->RGBAflag
);
2198 applyTransferOps
&= (ctx
->Pixel
.ScaleOrBiasRGBA
||
2199 ctx
->Pixel
.MapColorFlag
||
2200 ctx
->ColorMatrix
.type
!= MATRIX_IDENTITY
||
2201 ctx
->Pixel
.ScaleOrBiasRGBApcm
||
2202 ctx
->Pixel
.ColorTableEnabled
||
2203 ctx
->Pixel
.PostColorMatrixColorTableEnabled
||
2204 ctx
->Pixel
.MinMaxEnabled
||
2205 ctx
->Pixel
.HistogramEnabled
);
2207 /* Try simple cases first */
2208 if (!applyTransferOps
&& srcType
== GL_UNSIGNED_BYTE
) {
2209 if (dstFormat
== GL_RGBA
) {
2210 if (srcFormat
== GL_RGBA
) {
2211 MEMCPY( dest
, source
, n
* 4 * sizeof(GLubyte
) );
2214 else if (srcFormat
== GL_RGB
) {
2216 const GLubyte
*src
= (const GLubyte
*) source
;
2217 GLubyte
*dst
= dest
;
2218 for (i
= 0; i
< n
; i
++) {
2229 else if (dstFormat
== GL_RGB
) {
2230 if (srcFormat
== GL_RGB
) {
2231 MEMCPY( dest
, source
, n
* 3 * sizeof(GLubyte
) );
2234 else if (srcFormat
== GL_RGBA
) {
2236 const GLubyte
*src
= (const GLubyte
*) source
;
2237 GLubyte
*dst
= dest
;
2238 for (i
= 0; i
< n
; i
++) {
2248 else if (dstFormat
== srcFormat
) {
2249 GLint comps
= _mesa_components_in_format(srcFormat
);
2251 MEMCPY( dest
, source
, n
* comps
* sizeof(GLubyte
) );
2257 /* general solution begins here */
2259 GLfloat rgba
[MAX_WIDTH
][4];
2260 GLint dstComponents
;
2261 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2262 GLint dstLuminanceIndex
, dstIntensityIndex
;
2264 dstComponents
= _mesa_components_in_format( dstFormat
);
2265 /* source & dest image formats should have been error checked by now */
2266 assert(dstComponents
> 0);
2269 * Extract image data and convert to RGBA floats
2271 assert(n
<= MAX_WIDTH
);
2272 if (srcFormat
== GL_COLOR_INDEX
) {
2273 GLuint indexes
[MAX_WIDTH
];
2274 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2277 if (applyTransferOps
) {
2278 if (ctx
->Pixel
.MapColorFlag
) {
2279 _mesa_map_ci(ctx
, n
, indexes
);
2281 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2282 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2286 if (dstFormat
== GL_COLOR_INDEX
) {
2287 /* convert to GLubyte and return */
2289 for (i
= 0; i
< n
; i
++) {
2290 dest
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2295 /* Convert indexes to RGBA */
2296 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
2300 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2301 unpacking
->SwapBytes
);
2303 if (applyTransferOps
) {
2304 /* scale and bias colors */
2305 if (ctx
->Pixel
.ScaleOrBiasRGBA
) {
2306 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
);
2308 /* color map lookup */
2309 if (ctx
->Pixel
.MapColorFlag
) {
2310 _mesa_map_rgba(ctx
, n
, rgba
);
2315 if (applyTransferOps
) {
2316 /* GL_COLOR_TABLE lookup */
2317 if (ctx
->Pixel
.ColorTableEnabled
) {
2318 _mesa_lookup_rgba(&ctx
->ColorTable
, n
, rgba
);
2320 /* XXX convolution here */
2321 /* XXX post-convolution color table look-up here */
2322 /* color matrix transform */
2323 if (ctx
->ColorMatrix
.type
!= MATRIX_IDENTITY
||
2324 ctx
->Pixel
.ScaleOrBiasRGBApcm
) {
2325 _mesa_transform_rgba(ctx
, n
, rgba
);
2327 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
2328 if (ctx
->Pixel
.PostColorMatrixColorTableEnabled
) {
2329 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
2331 /* update histogram count */
2332 if (ctx
->Pixel
.HistogramEnabled
) {
2333 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
2335 /* XXX min/max here */
2336 if (ctx
->Pixel
.MinMaxEnabled
) {
2337 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
2341 /* clamp to [0,1] */
2344 for (i
= 0; i
< n
; i
++) {
2345 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
2346 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
2347 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
2348 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
2352 /* Now determine which color channels we need to produce.
2353 * And determine the dest index (offset) within each color tuple.
2355 switch (dstFormat
) {
2358 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2359 dstLuminanceIndex
= dstIntensityIndex
= -1;
2362 dstLuminanceIndex
= 0;
2363 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2364 dstIntensityIndex
= -1;
2366 case GL_LUMINANCE_ALPHA
:
2367 dstLuminanceIndex
= 0;
2369 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2370 dstIntensityIndex
= -1;
2373 dstIntensityIndex
= 0;
2374 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2375 dstLuminanceIndex
= -1;
2381 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
2388 dstLuminanceIndex
= dstIntensityIndex
= -1;
2391 gl_problem(ctx
, "bad dstFormat in _mesa_unpack_ubyte_span()");
2396 /* Now return the GLubyte data in the requested dstFormat */
2398 if (dstRedIndex
>= 0) {
2399 GLubyte
*dst
= dest
;
2401 for (i
= 0; i
< n
; i
++) {
2402 dst
[dstRedIndex
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2403 dst
+= dstComponents
;
2407 if (dstGreenIndex
>= 0) {
2408 GLubyte
*dst
= dest
;
2410 for (i
= 0; i
< n
; i
++) {
2411 dst
[dstGreenIndex
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2412 dst
+= dstComponents
;
2416 if (dstBlueIndex
>= 0) {
2417 GLubyte
*dst
= dest
;
2419 for (i
= 0; i
< n
; i
++) {
2420 dst
[dstBlueIndex
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2421 dst
+= dstComponents
;
2425 if (dstAlphaIndex
>= 0) {
2426 GLubyte
*dst
= dest
;
2428 for (i
= 0; i
< n
; i
++) {
2429 dst
[dstAlphaIndex
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2430 dst
+= dstComponents
;
2434 if (dstIntensityIndex
>= 0) {
2435 GLubyte
*dst
= dest
;
2437 assert(dstIntensityIndex
== 0);
2438 assert(dstComponents
== 1);
2439 for (i
= 0; i
< n
; i
++) {
2440 /* Intensity comes from red channel */
2441 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2445 if (dstLuminanceIndex
>= 0) {
2446 GLubyte
*dst
= dest
;
2448 assert(dstLuminanceIndex
== 0);
2449 for (i
= 0; i
< n
; i
++) {
2450 /* Luminance comes from red channel */
2451 dst
[0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2452 dst
+= dstComponents
;
2460 _mesa_unpack_float_color_span( GLcontext
*ctx
,
2461 GLuint n
, GLenum dstFormat
, GLfloat dest
[],
2462 GLenum srcFormat
, GLenum srcType
,
2463 const GLvoid
*source
,
2464 const struct gl_pixelstore_attrib
*unpacking
,
2465 GLboolean applyTransferOps
, GLboolean clamp
)
2467 ASSERT(dstFormat
== GL_ALPHA
||
2468 dstFormat
== GL_LUMINANCE
||
2469 dstFormat
== GL_LUMINANCE_ALPHA
||
2470 dstFormat
== GL_INTENSITY
||
2471 dstFormat
== GL_RGB
||
2472 dstFormat
== GL_RGBA
||
2473 dstFormat
== GL_COLOR_INDEX
);
2475 ASSERT(srcFormat
== GL_RED
||
2476 srcFormat
== GL_GREEN
||
2477 srcFormat
== GL_BLUE
||
2478 srcFormat
== GL_ALPHA
||
2479 srcFormat
== GL_LUMINANCE
||
2480 srcFormat
== GL_LUMINANCE_ALPHA
||
2481 srcFormat
== GL_INTENSITY
||
2482 srcFormat
== GL_RGB
||
2483 srcFormat
== GL_BGR
||
2484 srcFormat
== GL_RGBA
||
2485 srcFormat
== GL_BGRA
||
2486 srcFormat
== GL_ABGR_EXT
||
2487 srcFormat
== GL_COLOR_INDEX
);
2489 ASSERT(srcType
== GL_BITMAP
||
2490 srcType
== GL_UNSIGNED_BYTE
||
2491 srcType
== GL_BYTE
||
2492 srcType
== GL_UNSIGNED_SHORT
||
2493 srcType
== GL_SHORT
||
2494 srcType
== GL_UNSIGNED_INT
||
2495 srcType
== GL_INT
||
2496 srcType
== GL_FLOAT
||
2497 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2498 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2499 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2500 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2501 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2502 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2503 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2504 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2505 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2506 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2507 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2508 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2510 /* this is intended for RGBA mode only */
2511 assert(ctx
->Visual
->RGBAflag
);
2513 applyTransferOps
&= (ctx
->Pixel
.ScaleOrBiasRGBA
||
2514 ctx
->Pixel
.MapColorFlag
||
2515 ctx
->ColorMatrix
.type
!= MATRIX_IDENTITY
||
2516 ctx
->Pixel
.ScaleOrBiasRGBApcm
||
2517 ctx
->Pixel
.ColorTableEnabled
||
2518 ctx
->Pixel
.PostColorMatrixColorTableEnabled
||
2519 ctx
->Pixel
.MinMaxEnabled
||
2520 ctx
->Pixel
.HistogramEnabled
);
2522 /* general solution, no special cases, yet */
2524 GLfloat rgba
[MAX_WIDTH
][4];
2525 GLint dstComponents
;
2526 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2527 GLint dstLuminanceIndex
, dstIntensityIndex
;
2529 dstComponents
= _mesa_components_in_format( dstFormat
);
2530 /* source & dest image formats should have been error checked by now */
2531 assert(dstComponents
> 0);
2534 * Extract image data and convert to RGBA floats
2536 assert(n
<= MAX_WIDTH
);
2537 if (srcFormat
== GL_COLOR_INDEX
) {
2538 GLuint indexes
[MAX_WIDTH
];
2539 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2542 if (applyTransferOps
) {
2543 if (ctx
->Pixel
.MapColorFlag
) {
2544 _mesa_map_ci(ctx
, n
, indexes
);
2546 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2547 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2551 if (dstFormat
== GL_COLOR_INDEX
) {
2552 /* convert to GLubyte and return */
2554 for (i
= 0; i
< n
; i
++) {
2555 dest
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2560 /* Convert indexes to RGBA */
2561 _mesa_map_ci_to_rgba(ctx
, n
, indexes
, rgba
);
2565 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2566 unpacking
->SwapBytes
);
2568 if (applyTransferOps
) {
2569 /* scale and bias colors */
2570 if (ctx
->Pixel
.ScaleOrBiasRGBA
) {
2571 _mesa_scale_and_bias_rgba(ctx
, n
, rgba
);
2573 /* color map lookup */
2574 if (ctx
->Pixel
.MapColorFlag
) {
2575 _mesa_map_rgba(ctx
, n
, rgba
);
2580 if (applyTransferOps
) {
2581 /* GL_COLOR_TABLE lookup */
2582 if (ctx
->Pixel
.ColorTableEnabled
) {
2583 _mesa_lookup_rgba(&ctx
->ColorTable
, n
, rgba
);
2585 /* XXX convolution here */
2586 /* XXX post-convolution color table look-up here */
2587 /* color matrix transform */
2588 if (ctx
->ColorMatrix
.type
!= MATRIX_IDENTITY
||
2589 ctx
->Pixel
.ScaleOrBiasRGBApcm
) {
2590 _mesa_transform_rgba(ctx
, n
, rgba
);
2592 /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */
2593 if (ctx
->Pixel
.PostColorMatrixColorTableEnabled
) {
2594 _mesa_lookup_rgba(&ctx
->PostColorMatrixColorTable
, n
, rgba
);
2596 /* update histogram count */
2597 if (ctx
->Pixel
.HistogramEnabled
) {
2598 _mesa_update_histogram(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
2600 /* XXX min/max here */
2601 if (ctx
->Pixel
.MinMaxEnabled
) {
2602 _mesa_update_minmax(ctx
, n
, (CONST
GLfloat (*)[4]) rgba
);
2606 /* clamp to [0,1] */
2609 for (i
= 0; i
< n
; i
++) {
2610 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
2611 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
2612 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
2613 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
2617 /* Now determine which color channels we need to produce.
2618 * And determine the dest index (offset) within each color tuple.
2620 switch (dstFormat
) {
2623 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2624 dstLuminanceIndex
= dstIntensityIndex
= -1;
2627 dstLuminanceIndex
= 0;
2628 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2629 dstIntensityIndex
= -1;
2631 case GL_LUMINANCE_ALPHA
:
2632 dstLuminanceIndex
= 0;
2634 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2635 dstIntensityIndex
= -1;
2638 dstIntensityIndex
= 0;
2639 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2640 dstLuminanceIndex
= -1;
2646 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
2653 dstLuminanceIndex
= dstIntensityIndex
= -1;
2656 gl_problem(ctx
, "bad dstFormat in _mesa_unpack_float_span()");
2660 /* Now pack results in teh requested dstFormat */
2661 if (dstRedIndex
>= 0) {
2662 GLfloat
*dst
= dest
;
2664 for (i
= 0; i
< n
; i
++) {
2665 dst
[dstRedIndex
] = rgba
[i
][RCOMP
];
2666 dst
+= dstComponents
;
2670 if (dstGreenIndex
>= 0) {
2671 GLfloat
*dst
= dest
;
2673 for (i
= 0; i
< n
; i
++) {
2674 dst
[dstGreenIndex
] = rgba
[i
][GCOMP
];
2675 dst
+= dstComponents
;
2679 if (dstBlueIndex
>= 0) {
2680 GLfloat
*dst
= dest
;
2682 for (i
= 0; i
< n
; i
++) {
2683 dst
[dstBlueIndex
] = rgba
[i
][BCOMP
];
2684 dst
+= dstComponents
;
2688 if (dstAlphaIndex
>= 0) {
2689 GLfloat
*dst
= dest
;
2691 for (i
= 0; i
< n
; i
++) {
2692 dst
[dstAlphaIndex
] = rgba
[i
][ACOMP
];
2693 dst
+= dstComponents
;
2697 if (dstIntensityIndex
>= 0) {
2698 GLfloat
*dst
= dest
;
2700 assert(dstIntensityIndex
== 0);
2701 assert(dstComponents
== 1);
2702 for (i
= 0; i
< n
; i
++) {
2703 /* Intensity comes from red channel */
2704 dst
[i
] = rgba
[i
][RCOMP
];
2708 if (dstLuminanceIndex
>= 0) {
2709 GLfloat
*dst
= dest
;
2711 assert(dstLuminanceIndex
== 0);
2712 for (i
= 0; i
< n
; i
++) {
2713 /* Luminance comes from red channel */
2714 dst
[0] = rgba
[i
][RCOMP
];
2715 dst
+= dstComponents
;
2725 * Unpack a row of color index data from a client buffer according to
2726 * the pixel unpacking parameters. Apply pixel transfer ops if enabled
2727 * and applyTransferOps is true.
2728 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
2730 * Args: ctx - the context
2731 * n - number of pixels
2732 * dstType - destination datatype
2733 * dest - destination array
2734 * srcType - source pixel type
2735 * source - source data pointer
2736 * unpacking - pixel unpacking parameters
2737 * applyTransferOps - apply offset/bias/lookup ops?
2740 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
2741 GLenum dstType
, GLvoid
*dest
,
2742 GLenum srcType
, const GLvoid
*source
,
2743 const struct gl_pixelstore_attrib
*unpacking
,
2744 GLboolean applyTransferOps
)
2746 ASSERT(srcType
== GL_BITMAP
||
2747 srcType
== GL_UNSIGNED_BYTE
||
2748 srcType
== GL_BYTE
||
2749 srcType
== GL_UNSIGNED_SHORT
||
2750 srcType
== GL_SHORT
||
2751 srcType
== GL_UNSIGNED_INT
||
2752 srcType
== GL_INT
||
2753 srcType
== GL_FLOAT
);
2755 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
2756 dstType
== GL_UNSIGNED_SHORT
||
2757 dstType
== GL_UNSIGNED_INT
);
2759 applyTransferOps
&= (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
|| ctx
->Pixel
.MapColorFlag
);
2762 * Try simple cases first
2764 if (!applyTransferOps
&& srcType
== GL_UNSIGNED_BYTE
2765 && dstType
== GL_UNSIGNED_BYTE
) {
2766 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
2768 else if (!applyTransferOps
&& srcType
== GL_UNSIGNED_INT
2769 && dstType
== GL_UNSIGNED_INT
&& !unpacking
->SwapBytes
) {
2770 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
2776 GLuint indexes
[MAX_WIDTH
];
2777 assert(n
<= MAX_WIDTH
);
2779 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
2782 if (applyTransferOps
) {
2783 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2784 /* shift and offset indexes */
2785 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2787 if (ctx
->Pixel
.MapColorFlag
) {
2788 /* Apply lookup table */
2789 _mesa_map_ci(ctx
, n
, indexes
);
2793 /* convert to dest type */
2795 case GL_UNSIGNED_BYTE
:
2797 GLubyte
*dst
= (GLubyte
*) dest
;
2799 for (i
= 0; i
< n
; i
++) {
2800 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2804 case GL_UNSIGNED_SHORT
:
2806 GLuint
*dst
= (GLuint
*) dest
;
2808 for (i
= 0; i
< n
; i
++) {
2809 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
2813 case GL_UNSIGNED_INT
:
2814 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
2817 gl_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
2824 * Unpack a row of stencil data from a client buffer according to
2825 * the pixel unpacking parameters. Apply pixel transfer ops if enabled
2826 * and applyTransferOps is true.
2827 * This is (or will be) used by glDrawPixels
2829 * Args: ctx - the context
2830 * n - number of pixels
2831 * dstType - destination datatype
2832 * dest - destination array
2833 * srcType - source pixel type
2834 * source - source data pointer
2835 * unpacking - pixel unpacking parameters
2836 * applyTransferOps - apply offset/bias/lookup ops?
2839 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
2840 GLenum dstType
, GLvoid
*dest
,
2841 GLenum srcType
, const GLvoid
*source
,
2842 const struct gl_pixelstore_attrib
*unpacking
,
2843 GLboolean applyTransferOps
)
2845 ASSERT(srcType
== GL_BITMAP
||
2846 srcType
== GL_UNSIGNED_BYTE
||
2847 srcType
== GL_BYTE
||
2848 srcType
== GL_UNSIGNED_SHORT
||
2849 srcType
== GL_SHORT
||
2850 srcType
== GL_UNSIGNED_INT
||
2851 srcType
== GL_INT
||
2852 srcType
== GL_FLOAT
);
2854 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
2855 dstType
== GL_UNSIGNED_SHORT
||
2856 dstType
== GL_UNSIGNED_INT
);
2858 applyTransferOps
&= (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
|| ctx
->Pixel
.MapColorFlag
);
2861 * Try simple cases first
2863 if (!applyTransferOps
&& srcType
== GL_UNSIGNED_BYTE
2864 && dstType
== GL_UNSIGNED_BYTE
) {
2865 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
2867 else if (!applyTransferOps
&& srcType
== GL_UNSIGNED_INT
2868 && dstType
== GL_UNSIGNED_INT
&& !unpacking
->SwapBytes
) {
2869 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
2875 GLuint indexes
[MAX_WIDTH
];
2876 assert(n
<= MAX_WIDTH
);
2878 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
2881 if (applyTransferOps
) {
2882 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2883 /* shift and offset indexes */
2884 _mesa_shift_and_offset_ci(ctx
, n
, indexes
);
2887 if (ctx
->Pixel
.MapStencilFlag
) {
2888 /* Apply stencil lookup table */
2889 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
2892 indexes
[i
] = ctx
->Pixel
.MapStoS
[ indexes
[i
] & mask
];
2897 /* convert to dest type */
2899 case GL_UNSIGNED_BYTE
:
2901 GLubyte
*dst
= (GLubyte
*) dest
;
2903 for (i
= 0; i
< n
; i
++) {
2904 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2908 case GL_UNSIGNED_SHORT
:
2910 GLuint
*dst
= (GLuint
*) dest
;
2912 for (i
= 0; i
< n
; i
++) {
2913 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
2917 case GL_UNSIGNED_INT
:
2918 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
2921 gl_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
2929 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
, GLdepth
*dest
,
2930 GLenum srcType
, const GLvoid
*source
,
2931 const struct gl_pixelstore_attrib
*unpacking
,
2932 GLboolean applyTransferOps
)
2934 GLfloat
*depth
= MALLOC(n
* sizeof(GLfloat
));
2942 const GLubyte
*src
= (const GLubyte
*) source
;
2943 for (i
= 0; i
< n
; i
++) {
2944 depth
[i
] = BYTE_TO_FLOAT(src
[i
]);
2948 case GL_UNSIGNED_BYTE
:
2951 const GLubyte
*src
= (const GLubyte
*) source
;
2952 for (i
= 0; i
< n
; i
++) {
2953 depth
[i
] = UBYTE_TO_FLOAT(src
[i
]);
2960 const GLshort
*src
= (const GLshort
*) source
;
2961 for (i
= 0; i
< n
; i
++) {
2962 depth
[i
] = SHORT_TO_FLOAT(src
[i
]);
2966 case GL_UNSIGNED_SHORT
:
2969 const GLushort
*src
= (const GLushort
*) source
;
2970 for (i
= 0; i
< n
; i
++) {
2971 depth
[i
] = USHORT_TO_FLOAT(src
[i
]);
2978 const GLint
*src
= (const GLint
*) source
;
2979 for (i
= 0; i
< n
; i
++) {
2980 depth
[i
] = INT_TO_FLOAT(src
[i
]);
2984 case GL_UNSIGNED_INT
:
2987 const GLuint
*src
= (const GLuint
*) source
;
2988 for (i
= 0; i
< n
; i
++) {
2989 depth
[i
] = UINT_TO_FLOAT(src
[i
]);
2994 MEMCPY(depth
, source
, n
* sizeof(GLfloat
));
2997 gl_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
3002 /* apply depth scale and bias */
3003 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
3005 for (i
= 0; i
< n
; i
++) {
3006 depth
[i
] = depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
3010 /* clamp depth values to [0,1] and convert from floats to integers */
3012 const GLfloat zs
= ctx
->Visual
->DepthMaxF
;
3014 for (i
= 0; i
< n
; i
++) {
3015 dest
[i
] = (GLdepth
) (CLAMP(depth
[i
], 0.0F
, 1.0F
) * zs
);
3025 * Unpack image data. Apply byteswapping, byte flipping (bitmap).
3026 * Return all image data in a contiguous block.
3029 _mesa_unpack_image( GLsizei width
, GLsizei height
, GLsizei depth
,
3030 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3031 const struct gl_pixelstore_attrib
*unpack
)
3033 GLint bytesPerRow
, compsPerRow
;
3034 GLboolean flipBytes
, swap2
, swap4
;
3037 return NULL
; /* not necessarily an error */
3039 if (width
<= 0 || height
<= 0 || depth
<= 0)
3040 return NULL
; /* generate error later */
3042 if (format
== GL_BITMAP
) {
3043 bytesPerRow
= (width
+ 7) >> 3;
3044 flipBytes
= !unpack
->LsbFirst
;
3045 swap2
= swap4
= GL_FALSE
;
3049 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
3050 const GLint components
= _mesa_components_in_format(format
);
3052 if (bytesPerPixel
<= 0 || components
<= 0)
3053 return NULL
; /* bad format or type. generate error later */
3054 bytesPerRow
= bytesPerPixel
* width
;
3055 bytesPerComp
= bytesPerPixel
/ components
;
3056 flipBytes
= GL_FALSE
;
3057 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
3058 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
3059 compsPerRow
= components
* width
;
3060 assert(compsPerRow
>= width
);
3064 GLubyte
*destBuffer
= MALLOC(bytesPerRow
* height
* depth
);
3068 return NULL
; /* generate GL_OUT_OF_MEMORY later */
3071 for (img
= 0; img
< depth
; img
++) {
3072 for (row
= 0; row
< height
; row
++) {
3073 const GLvoid
*src
= _mesa_image_address(unpack
, pixels
,
3074 width
, height
, format
, type
, img
, row
, 0);
3075 MEMCPY(dst
, src
, bytesPerRow
);
3076 /* byte flipping/swapping */
3078 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
3081 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
3084 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
3095 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
3096 * order with row alignment = 1 byte.
3099 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
3100 const struct gl_pixelstore_attrib
*packing
)
3102 GLint bytes
, row
, width_in_bytes
;
3103 GLubyte
*buffer
, *dst
;
3108 /* Alloc dest storage */
3109 bytes
= ((width
+ 7) / 8 * height
);
3110 buffer
= (GLubyte
*) MALLOC( bytes
);
3115 width_in_bytes
= CEILING( width
, 8 );
3117 for (row
= 0; row
< height
; row
++) {
3118 GLubyte
*src
= _mesa_image_address( packing
, pixels
, width
, height
,
3119 GL_COLOR_INDEX
, GL_BITMAP
,
3126 if (packing
->SkipPixels
== 0) {
3127 MEMCPY( dst
, src
, width_in_bytes
);
3128 if (packing
->LsbFirst
) {
3129 flip_bytes( dst
, width_in_bytes
);
3133 /* handling SkipPixels is a bit tricky (no pun intended!) */
3135 if (packing
->LsbFirst
) {
3136 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
3137 GLubyte dstMask
= 128;
3141 for (i
= 0; i
< width
; i
++) {
3145 if (srcMask
== 128) {
3150 srcMask
= srcMask
<< 1;
3158 dstMask
= dstMask
>> 1;
3163 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
3164 GLubyte dstMask
= 128;
3168 for (i
= 0; i
< width
; i
++) {
3177 srcMask
= srcMask
>> 1;
3185 dstMask
= dstMask
>> 1;
3190 dst
+= width_in_bytes
;
3201 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
3202 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
3204 GLint row
, width_in_bytes
;
3210 width_in_bytes
= CEILING( width
, 8 );
3212 for (row
= 0; row
< height
; row
++) {
3213 GLubyte
*dst
= _mesa_image_address( packing
, dest
, width
, height
,
3214 GL_COLOR_INDEX
, GL_BITMAP
,
3219 if (packing
->SkipPixels
== 0) {
3220 MEMCPY( dst
, src
, width_in_bytes
);
3221 if (packing
->LsbFirst
) {
3222 flip_bytes( dst
, width_in_bytes
);
3226 /* handling SkipPixels is a bit tricky (no pun intended!) */
3228 if (packing
->LsbFirst
) {
3229 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
3230 GLubyte dstMask
= 128;
3231 const GLubyte
*s
= src
;
3234 for (i
= 0; i
< width
; i
++) {
3238 if (srcMask
== 128) {
3243 srcMask
= srcMask
<< 1;
3251 dstMask
= dstMask
>> 1;
3256 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
3257 GLubyte dstMask
= 128;
3258 const GLubyte
*s
= src
;
3261 for (i
= 0; i
< width
; i
++) {
3270 srcMask
= srcMask
>> 1;
3278 dstMask
= dstMask
>> 1;
3283 src
+= width_in_bytes
;