1 /* $Id: image.c,v 1.25 2000/04/08 18:57:45 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.
44 * These are the image packing parameters for Mesa's internal images.
45 * That is, _mesa_unpack_image() returns image data in this format.
46 * When we execute image commands (glDrawPixels, glTexImage, etc)
47 * from within display lists we have to be sure to set the current
48 * unpacking params to these values!
50 const struct gl_pixelstore_attrib _mesa_native_packing
= {
57 GL_FALSE
, /* SwapBytes */
58 GL_FALSE
/* LsbFirst */
64 * Flip the 8 bits in each byte of the given array.
67 flip_bytes( GLubyte
*p
, GLuint n
)
69 register GLuint i
, a
, b
;
73 a
= ((b
& 0x01) << 7) |
87 * Flip the order of the 2 bytes in each word in the given array.
90 _mesa_swap2( GLushort
*p
, GLuint n
)
95 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
102 * Flip the order of the 4 bytes in each word in the given array.
105 _mesa_swap4( GLuint
*p
, GLuint n
)
107 register GLuint i
, a
, b
;
112 | ((b
>> 8) & 0xff00)
113 | ((b
<< 8) & 0xff0000)
114 | ((b
<< 24) & 0xff000000);
123 * Return the size, in bytes, of the given GL datatype.
124 * Return 0 if GL_BITMAP.
125 * Return -1 if invalid type enum.
127 GLint
_mesa_sizeof_type( GLenum type
)
132 case GL_UNSIGNED_BYTE
:
133 return sizeof(GLubyte
);
135 return sizeof(GLbyte
);
136 case GL_UNSIGNED_SHORT
:
137 return sizeof(GLushort
);
139 return sizeof(GLshort
);
140 case GL_UNSIGNED_INT
:
141 return sizeof(GLuint
);
143 return sizeof(GLint
);
145 return sizeof(GLfloat
);
153 * Same as _mesa_sizeof_packed_type() but we also accept the
154 * packed pixel format datatypes.
156 GLint
_mesa_sizeof_packed_type( GLenum type
)
161 case GL_UNSIGNED_BYTE
:
162 return sizeof(GLubyte
);
164 return sizeof(GLbyte
);
165 case GL_UNSIGNED_SHORT
:
166 return sizeof(GLushort
);
168 return sizeof(GLshort
);
169 case GL_UNSIGNED_INT
:
170 return sizeof(GLuint
);
172 return sizeof(GLint
);
174 return sizeof(GLfloat
);
175 case GL_UNSIGNED_BYTE_3_3_2
:
176 return sizeof(GLubyte
);
177 case GL_UNSIGNED_BYTE_2_3_3_REV
:
178 return sizeof(GLubyte
);
179 case GL_UNSIGNED_SHORT_5_6_5
:
180 return sizeof(GLshort
);
181 case GL_UNSIGNED_SHORT_5_6_5_REV
:
182 return sizeof(GLshort
);
183 case GL_UNSIGNED_SHORT_4_4_4_4
:
184 return sizeof(GLshort
);
185 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
186 return sizeof(GLshort
);
187 case GL_UNSIGNED_SHORT_5_5_5_1
:
188 return sizeof(GLshort
);
189 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
190 return sizeof(GLshort
);
191 case GL_UNSIGNED_INT_8_8_8_8
:
192 return sizeof(GLuint
);
193 case GL_UNSIGNED_INT_8_8_8_8_REV
:
194 return sizeof(GLuint
);
195 case GL_UNSIGNED_INT_10_10_10_2
:
196 return sizeof(GLuint
);
197 case GL_UNSIGNED_INT_2_10_10_10_REV
:
198 return sizeof(GLuint
);
207 * Return the number of components in a GL enum pixel type.
208 * Return -1 if bad format.
210 GLint
_mesa_components_in_format( GLenum format
)
214 case GL_COLOR_INDEX1_EXT
:
215 case GL_COLOR_INDEX2_EXT
:
216 case GL_COLOR_INDEX4_EXT
:
217 case GL_COLOR_INDEX8_EXT
:
218 case GL_COLOR_INDEX12_EXT
:
219 case GL_COLOR_INDEX16_EXT
:
220 case GL_STENCIL_INDEX
:
221 case GL_DEPTH_COMPONENT
:
229 case GL_LUMINANCE_ALPHA
:
248 * Return bytes per pixel for given format and type
249 * Return -1 if bad format or type.
251 GLint
_mesa_bytes_per_pixel( GLenum format
, GLenum type
)
253 GLint comps
= _mesa_components_in_format( format
);
259 return 0; /* special case */
261 case GL_UNSIGNED_BYTE
:
262 return comps
* sizeof(GLubyte
);
264 case GL_UNSIGNED_SHORT
:
265 return comps
* sizeof(GLshort
);
267 case GL_UNSIGNED_INT
:
268 return comps
* sizeof(GLint
);
270 return comps
* sizeof(GLfloat
);
271 case GL_UNSIGNED_BYTE_3_3_2
:
272 case GL_UNSIGNED_BYTE_2_3_3_REV
:
273 if (format
== GL_RGB
|| format
== GL_BGR
)
274 return sizeof(GLubyte
);
276 return -1; /* error */
277 case GL_UNSIGNED_SHORT_5_6_5
:
278 case GL_UNSIGNED_SHORT_5_6_5_REV
:
279 if (format
== GL_RGB
|| format
== GL_BGR
)
280 return sizeof(GLshort
);
282 return -1; /* error */
283 case GL_UNSIGNED_SHORT_4_4_4_4
:
284 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
285 case GL_UNSIGNED_SHORT_5_5_5_1
:
286 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
287 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
288 return sizeof(GLushort
);
291 case GL_UNSIGNED_INT_8_8_8_8
:
292 case GL_UNSIGNED_INT_8_8_8_8_REV
:
293 case GL_UNSIGNED_INT_10_10_10_2
:
294 case GL_UNSIGNED_INT_2_10_10_10_REV
:
295 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
296 return sizeof(GLuint
);
306 * Test if the given pixel format and type are legal.
307 * Return GL_TRUE for legal, GL_FALSE for illegal.
310 _mesa_is_legal_format_and_type( GLenum format
, GLenum type
)
314 case GL_STENCIL_INDEX
:
318 case GL_UNSIGNED_BYTE
:
320 case GL_UNSIGNED_SHORT
:
322 case GL_UNSIGNED_INT
:
333 case GL_LUMINANCE_ALPHA
:
334 case GL_DEPTH_COMPONENT
:
338 case GL_UNSIGNED_BYTE
:
340 case GL_UNSIGNED_SHORT
:
342 case GL_UNSIGNED_INT
:
351 case GL_UNSIGNED_BYTE
:
353 case GL_UNSIGNED_SHORT
:
355 case GL_UNSIGNED_INT
:
357 case GL_UNSIGNED_BYTE_3_3_2
:
358 case GL_UNSIGNED_BYTE_2_3_3_REV
:
359 case GL_UNSIGNED_SHORT_5_6_5
:
360 case GL_UNSIGNED_SHORT_5_6_5_REV
:
370 case GL_UNSIGNED_BYTE
:
372 case GL_UNSIGNED_SHORT
:
374 case GL_UNSIGNED_INT
:
376 case GL_UNSIGNED_SHORT_4_4_4_4
:
377 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
378 case GL_UNSIGNED_SHORT_5_5_5_1
:
379 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
380 case GL_UNSIGNED_INT_8_8_8_8
:
381 case GL_UNSIGNED_INT_8_8_8_8_REV
:
382 case GL_UNSIGNED_INT_10_10_10_2
:
383 case GL_UNSIGNED_INT_2_10_10_10_REV
:
397 * Return the address of a pixel in an image (actually a volume).
398 * Pixel unpacking/packing parameters are observed according to 'packing'.
399 * Input: image - start of image data
400 * width, height - size of image
401 * format - image format
402 * type - pixel component type
403 * packing - the pixelstore attributes
404 * img - which image in the volume (0 for 1D or 2D images)
405 * row, column - location of pixel in the image
406 * Return: address of pixel at (image,row,column) in image or NULL if error.
409 _mesa_image_address( const struct gl_pixelstore_attrib
*packing
,
410 const GLvoid
*image
, GLsizei width
,
411 GLsizei height
, GLenum format
, GLenum type
,
412 GLint img
, GLint row
, GLint column
)
414 GLint alignment
; /* 1, 2 or 4 */
415 GLint pixels_per_row
;
416 GLint rows_per_image
;
419 GLint skipimages
; /* for 3-D volume images */
422 alignment
= packing
->Alignment
;
423 if (packing
->RowLength
> 0) {
424 pixels_per_row
= packing
->RowLength
;
427 pixels_per_row
= width
;
429 if (packing
->ImageHeight
> 0) {
430 rows_per_image
= packing
->ImageHeight
;
433 rows_per_image
= height
;
435 skiprows
= packing
->SkipRows
;
436 skippixels
= packing
->SkipPixels
;
437 skipimages
= packing
->SkipImages
;
439 if (type
==GL_BITMAP
) {
441 GLint comp_per_pixel
; /* components per pixel */
442 GLint bytes_per_comp
; /* bytes per component */
444 GLint bytes_per_image
;
446 /* Compute bytes per component */
447 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
448 if (bytes_per_comp
<0) {
452 /* Compute number of components per pixel */
453 comp_per_pixel
= _mesa_components_in_format( format
);
454 if (comp_per_pixel
<0 && type
!= GL_BITMAP
) {
458 bytes_per_row
= alignment
459 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
461 bytes_per_image
= bytes_per_row
* rows_per_image
;
463 pixel_addr
= (GLubyte
*) image
464 + (skipimages
+ img
) * bytes_per_image
465 + (skiprows
+ row
) * bytes_per_row
466 + (skippixels
+ column
) / 8;
469 /* Non-BITMAP data */
470 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
472 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
474 /* The pixel type and format should have been error checked earlier */
475 assert(bytes_per_pixel
> 0);
477 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
478 remainder
= bytes_per_row
% alignment
;
480 bytes_per_row
+= (alignment
- remainder
);
482 ASSERT(bytes_per_row
% alignment
== 0);
484 bytes_per_image
= bytes_per_row
* rows_per_image
;
486 /* compute final pixel address */
487 pixel_addr
= (GLubyte
*) image
488 + (skipimages
+ img
) * bytes_per_image
489 + (skiprows
+ row
) * bytes_per_row
490 + (skippixels
+ column
) * bytes_per_pixel
;
493 return (GLvoid
*) pixel_addr
;
499 * Compute the stride between image rows (in bytes) for the given
500 * pixel packing parameters and image width, format and type.
503 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
504 GLint width
, GLenum format
, GLenum type
)
507 if (type
== GL_BITMAP
) {
509 if (packing
->RowLength
== 0) {
510 GLint bytes
= (width
+ 7) / 8;
514 GLint bytes
= (packing
->RowLength
+ 7) / 8;
519 /* Non-BITMAP data */
520 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
521 if (bytesPerPixel
<= 0)
522 return -1; /* error */
523 if (packing
->RowLength
== 0) {
524 GLint bytes
= bytesPerPixel
* width
;
528 GLint bytes
= bytesPerPixel
* packing
->RowLength
;
537 * Unpack a 32x32 pixel polygon stipple from user memory using the
538 * current pixel unpack settings.
541 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
542 const struct gl_pixelstore_attrib
*unpacking
)
544 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap( 32, 32, pattern
, unpacking
);
546 /* Convert pattern from GLubytes to GLuints and handle big/little
551 for (i
= 0; i
< 32; i
++) {
552 dest
[i
] = (p
[0] << 24)
565 * Pack polygon stipple into user memory given current pixel packing
569 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
570 const struct gl_pixelstore_attrib
*packing
)
572 /* Convert pattern from GLuints to GLubytes to handle big/little
573 * endian differences.
577 for (i
= 0; i
< 32; i
++) {
578 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
579 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
580 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
581 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
584 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
590 * Pack the given RGBA span into client memory at 'dest' address
591 * in the given pixel format and type.
592 * Optionally apply the enabled pixel transfer ops.
593 * Pack into memory using the given packing params struct.
594 * This is used by glReadPixels and glGetTexImage?D()
595 * Input: ctx - the context
596 * n - number of pixels in the span
598 * format - dest packing format
599 * type - dest packing datatype
600 * destination - destination packing address
601 * packing - pixel packing parameters
602 * applyTransferOps - apply scale/bias/lookup-table ops?
605 _mesa_pack_rgba_span( const GLcontext
*ctx
,
606 GLuint n
, CONST GLubyte rgba
[][4],
607 GLenum format
, GLenum type
, GLvoid
*destination
,
608 const struct gl_pixelstore_attrib
*packing
,
609 GLboolean applyTransferOps
)
611 applyTransferOps
&= (ctx
->Pixel
.ScaleOrBiasRGBA
|| ctx
->Pixel
.MapColorFlag
);
613 /* Test for optimized case first */
614 if (!applyTransferOps
&& format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
615 /* common simple case */
616 MEMCPY( destination
, rgba
, n
* 4 * sizeof(GLubyte
) );
618 else if (!applyTransferOps
&& format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
619 /* common simple case */
621 GLubyte
*dest
= (GLubyte
*) destination
;
622 for (i
= 0; i
< n
; i
++) {
623 dest
[0] = rgba
[i
][RCOMP
];
624 dest
[1] = rgba
[i
][GCOMP
];
625 dest
[2] = rgba
[i
][BCOMP
];
630 /* general solution */
631 GLfloat red
[MAX_WIDTH
], green
[MAX_WIDTH
], blue
[MAX_WIDTH
];
632 GLfloat alpha
[MAX_WIDTH
], luminance
[MAX_WIDTH
];
633 const GLfloat rscale
= 1.0F
/ 255.0F
;
634 const GLfloat gscale
= 1.0F
/ 255.0F
;
635 const GLfloat bscale
= 1.0F
/ 255.0F
;
636 const GLfloat ascale
= 1.0F
/ 255.0F
;
637 const GLint comps
= _mesa_components_in_format(format
);
640 assert(n
<= MAX_WIDTH
);
642 /* convert color components to floating point */
644 red
[i
] = rgba
[i
][RCOMP
] * rscale
;
645 green
[i
] = rgba
[i
][GCOMP
] * gscale
;
646 blue
[i
] = rgba
[i
][BCOMP
] * bscale
;
647 alpha
[i
] = rgba
[i
][ACOMP
] * ascale
;
651 * Apply scale, bias and lookup-tables if enabled.
653 if (applyTransferOps
) {
654 if (ctx
->Pixel
.ScaleOrBiasRGBA
) {
655 gl_scale_and_bias_color( ctx
, n
, red
, green
, blue
, alpha
);
657 if (ctx
->Pixel
.MapColorFlag
) {
658 gl_map_color( ctx
, n
, red
, green
, blue
, alpha
);
662 if (format
==GL_LUMINANCE
|| format
==GL_LUMINANCE_ALPHA
) {
664 GLfloat sum
= red
[i
] + green
[i
] + blue
[i
];
665 luminance
[i
] = CLAMP( sum
, 0.0F
, 1.0F
);
670 * Pack/store the pixels. Ugh! Lots of cases!!!
673 case GL_UNSIGNED_BYTE
:
675 GLubyte
*dst
= (GLubyte
*) destination
;
679 dst
[i
] = FLOAT_TO_UBYTE(red
[i
]);
683 dst
[i
] = FLOAT_TO_UBYTE(green
[i
]);
687 dst
[i
] = FLOAT_TO_UBYTE(blue
[i
]);
691 dst
[i
] = FLOAT_TO_UBYTE(alpha
[i
]);
695 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
697 case GL_LUMINANCE_ALPHA
:
699 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
700 dst
[i
*2+1] = FLOAT_TO_UBYTE(alpha
[i
]);
705 dst
[i
*3+0] = FLOAT_TO_UBYTE(red
[i
]);
706 dst
[i
*3+1] = FLOAT_TO_UBYTE(green
[i
]);
707 dst
[i
*3+2] = FLOAT_TO_UBYTE(blue
[i
]);
712 dst
[i
*4+0] = FLOAT_TO_UBYTE(red
[i
]);
713 dst
[i
*4+1] = FLOAT_TO_UBYTE(green
[i
]);
714 dst
[i
*4+2] = FLOAT_TO_UBYTE(blue
[i
]);
715 dst
[i
*4+3] = FLOAT_TO_UBYTE(alpha
[i
]);
720 dst
[i
*3+0] = FLOAT_TO_UBYTE(blue
[i
]);
721 dst
[i
*3+1] = FLOAT_TO_UBYTE(green
[i
]);
722 dst
[i
*3+2] = FLOAT_TO_UBYTE(red
[i
]);
727 dst
[i
*4+0] = FLOAT_TO_UBYTE(blue
[i
]);
728 dst
[i
*4+1] = FLOAT_TO_UBYTE(green
[i
]);
729 dst
[i
*4+2] = FLOAT_TO_UBYTE(red
[i
]);
730 dst
[i
*4+3] = FLOAT_TO_UBYTE(alpha
[i
]);
735 dst
[i
*4+0] = FLOAT_TO_UBYTE(alpha
[i
]);
736 dst
[i
*4+1] = FLOAT_TO_UBYTE(blue
[i
]);
737 dst
[i
*4+2] = FLOAT_TO_UBYTE(green
[i
]);
738 dst
[i
*4+3] = FLOAT_TO_UBYTE(red
[i
]);
742 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
748 GLbyte
*dst
= (GLbyte
*) destination
;
752 dst
[i
] = FLOAT_TO_BYTE(red
[i
]);
756 dst
[i
] = FLOAT_TO_BYTE(green
[i
]);
760 dst
[i
] = FLOAT_TO_BYTE(blue
[i
]);
764 dst
[i
] = FLOAT_TO_BYTE(alpha
[i
]);
768 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
770 case GL_LUMINANCE_ALPHA
:
772 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
773 dst
[i
*2+1] = FLOAT_TO_BYTE(alpha
[i
]);
778 dst
[i
*3+0] = FLOAT_TO_BYTE(red
[i
]);
779 dst
[i
*3+1] = FLOAT_TO_BYTE(green
[i
]);
780 dst
[i
*3+2] = FLOAT_TO_BYTE(blue
[i
]);
785 dst
[i
*4+0] = FLOAT_TO_BYTE(red
[i
]);
786 dst
[i
*4+1] = FLOAT_TO_BYTE(green
[i
]);
787 dst
[i
*4+2] = FLOAT_TO_BYTE(blue
[i
]);
788 dst
[i
*4+3] = FLOAT_TO_BYTE(alpha
[i
]);
793 dst
[i
*3+0] = FLOAT_TO_BYTE(blue
[i
]);
794 dst
[i
*3+1] = FLOAT_TO_BYTE(green
[i
]);
795 dst
[i
*3+2] = FLOAT_TO_BYTE(red
[i
]);
800 dst
[i
*4+0] = FLOAT_TO_BYTE(blue
[i
]);
801 dst
[i
*4+1] = FLOAT_TO_BYTE(green
[i
]);
802 dst
[i
*4+2] = FLOAT_TO_BYTE(red
[i
]);
803 dst
[i
*4+3] = FLOAT_TO_BYTE(alpha
[i
]);
807 dst
[i
*4+0] = FLOAT_TO_BYTE(alpha
[i
]);
808 dst
[i
*4+1] = FLOAT_TO_BYTE(blue
[i
]);
809 dst
[i
*4+2] = FLOAT_TO_BYTE(green
[i
]);
810 dst
[i
*4+3] = FLOAT_TO_BYTE(red
[i
]);
814 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
818 case GL_UNSIGNED_SHORT
:
820 GLushort
*dst
= (GLushort
*) destination
;
824 dst
[i
] = FLOAT_TO_USHORT(red
[i
]);
828 dst
[i
] = FLOAT_TO_USHORT(green
[i
]);
832 dst
[i
] = FLOAT_TO_USHORT(blue
[i
]);
836 dst
[i
] = FLOAT_TO_USHORT(alpha
[i
]);
840 dst
[i
] = FLOAT_TO_USHORT(luminance
[i
]);
842 case GL_LUMINANCE_ALPHA
:
844 dst
[i
*2+0] = FLOAT_TO_USHORT(luminance
[i
]);
845 dst
[i
*2+1] = FLOAT_TO_USHORT(alpha
[i
]);
850 dst
[i
*3+0] = FLOAT_TO_USHORT(red
[i
]);
851 dst
[i
*3+1] = FLOAT_TO_USHORT(green
[i
]);
852 dst
[i
*3+2] = FLOAT_TO_USHORT(blue
[i
]);
857 dst
[i
*4+0] = FLOAT_TO_USHORT(red
[i
]);
858 dst
[i
*4+1] = FLOAT_TO_USHORT(green
[i
]);
859 dst
[i
*4+2] = FLOAT_TO_USHORT(blue
[i
]);
860 dst
[i
*4+3] = FLOAT_TO_USHORT(alpha
[i
]);
865 dst
[i
*3+0] = FLOAT_TO_USHORT(blue
[i
]);
866 dst
[i
*3+1] = FLOAT_TO_USHORT(green
[i
]);
867 dst
[i
*3+2] = FLOAT_TO_USHORT(red
[i
]);
872 dst
[i
*4+0] = FLOAT_TO_USHORT(blue
[i
]);
873 dst
[i
*4+1] = FLOAT_TO_USHORT(green
[i
]);
874 dst
[i
*4+2] = FLOAT_TO_USHORT(red
[i
]);
875 dst
[i
*4+3] = FLOAT_TO_USHORT(alpha
[i
]);
880 dst
[i
*4+0] = FLOAT_TO_USHORT(alpha
[i
]);
881 dst
[i
*4+1] = FLOAT_TO_USHORT(blue
[i
]);
882 dst
[i
*4+2] = FLOAT_TO_USHORT(green
[i
]);
883 dst
[i
*4+3] = FLOAT_TO_USHORT(red
[i
]);
887 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
889 if (packing
->SwapBytes
) {
890 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
896 GLshort
*dst
= (GLshort
*) destination
;
900 dst
[i
] = FLOAT_TO_SHORT(red
[i
]);
904 dst
[i
] = FLOAT_TO_SHORT(green
[i
]);
908 dst
[i
] = FLOAT_TO_SHORT(blue
[i
]);
912 dst
[i
] = FLOAT_TO_SHORT(alpha
[i
]);
916 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
918 case GL_LUMINANCE_ALPHA
:
920 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
921 dst
[i
*2+1] = FLOAT_TO_SHORT(alpha
[i
]);
926 dst
[i
*3+0] = FLOAT_TO_SHORT(red
[i
]);
927 dst
[i
*3+1] = FLOAT_TO_SHORT(green
[i
]);
928 dst
[i
*3+2] = FLOAT_TO_SHORT(blue
[i
]);
933 dst
[i
*4+0] = FLOAT_TO_SHORT(red
[i
]);
934 dst
[i
*4+1] = FLOAT_TO_SHORT(green
[i
]);
935 dst
[i
*4+2] = FLOAT_TO_SHORT(blue
[i
]);
936 dst
[i
*4+3] = FLOAT_TO_SHORT(alpha
[i
]);
941 dst
[i
*3+0] = FLOAT_TO_SHORT(blue
[i
]);
942 dst
[i
*3+1] = FLOAT_TO_SHORT(green
[i
]);
943 dst
[i
*3+2] = FLOAT_TO_SHORT(red
[i
]);
948 dst
[i
*4+0] = FLOAT_TO_SHORT(blue
[i
]);
949 dst
[i
*4+1] = FLOAT_TO_SHORT(green
[i
]);
950 dst
[i
*4+2] = FLOAT_TO_SHORT(red
[i
]);
951 dst
[i
*4+3] = FLOAT_TO_SHORT(alpha
[i
]);
955 dst
[i
*4+0] = FLOAT_TO_SHORT(alpha
[i
]);
956 dst
[i
*4+1] = FLOAT_TO_SHORT(blue
[i
]);
957 dst
[i
*4+2] = FLOAT_TO_SHORT(green
[i
]);
958 dst
[i
*4+3] = FLOAT_TO_SHORT(red
[i
]);
962 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
964 if (packing
->SwapBytes
) {
965 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
969 case GL_UNSIGNED_INT
:
971 GLuint
*dst
= (GLuint
*) destination
;
975 dst
[i
] = FLOAT_TO_UINT(red
[i
]);
979 dst
[i
] = FLOAT_TO_UINT(green
[i
]);
983 dst
[i
] = FLOAT_TO_UINT(blue
[i
]);
987 dst
[i
] = FLOAT_TO_UINT(alpha
[i
]);
991 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
993 case GL_LUMINANCE_ALPHA
:
995 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
996 dst
[i
*2+1] = FLOAT_TO_UINT(alpha
[i
]);
1001 dst
[i
*3+0] = FLOAT_TO_UINT(red
[i
]);
1002 dst
[i
*3+1] = FLOAT_TO_UINT(green
[i
]);
1003 dst
[i
*3+2] = FLOAT_TO_UINT(blue
[i
]);
1008 dst
[i
*4+0] = FLOAT_TO_UINT(red
[i
]);
1009 dst
[i
*4+1] = FLOAT_TO_UINT(green
[i
]);
1010 dst
[i
*4+2] = FLOAT_TO_UINT(blue
[i
]);
1011 dst
[i
*4+3] = FLOAT_TO_UINT(alpha
[i
]);
1016 dst
[i
*3+0] = FLOAT_TO_UINT(blue
[i
]);
1017 dst
[i
*3+1] = FLOAT_TO_UINT(green
[i
]);
1018 dst
[i
*3+2] = FLOAT_TO_UINT(red
[i
]);
1023 dst
[i
*4+0] = FLOAT_TO_UINT(blue
[i
]);
1024 dst
[i
*4+1] = FLOAT_TO_UINT(green
[i
]);
1025 dst
[i
*4+2] = FLOAT_TO_UINT(red
[i
]);
1026 dst
[i
*4+3] = FLOAT_TO_UINT(alpha
[i
]);
1031 dst
[i
*4+0] = FLOAT_TO_UINT(alpha
[i
]);
1032 dst
[i
*4+1] = FLOAT_TO_UINT(blue
[i
]);
1033 dst
[i
*4+2] = FLOAT_TO_UINT(green
[i
]);
1034 dst
[i
*4+3] = FLOAT_TO_UINT(red
[i
]);
1038 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1040 if (packing
->SwapBytes
) {
1041 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1047 GLint
*dst
= (GLint
*) destination
;
1051 dst
[i
] = FLOAT_TO_INT(red
[i
]);
1055 dst
[i
] = FLOAT_TO_INT(green
[i
]);
1059 dst
[i
] = FLOAT_TO_INT(blue
[i
]);
1063 dst
[i
] = FLOAT_TO_INT(alpha
[i
]);
1067 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1069 case GL_LUMINANCE_ALPHA
:
1071 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1072 dst
[i
*2+1] = FLOAT_TO_INT(alpha
[i
]);
1077 dst
[i
*3+0] = FLOAT_TO_INT(red
[i
]);
1078 dst
[i
*3+1] = FLOAT_TO_INT(green
[i
]);
1079 dst
[i
*3+2] = FLOAT_TO_INT(blue
[i
]);
1084 dst
[i
*4+0] = FLOAT_TO_INT(red
[i
]);
1085 dst
[i
*4+1] = FLOAT_TO_INT(green
[i
]);
1086 dst
[i
*4+2] = FLOAT_TO_INT(blue
[i
]);
1087 dst
[i
*4+3] = FLOAT_TO_INT(alpha
[i
]);
1092 dst
[i
*3+0] = FLOAT_TO_INT(blue
[i
]);
1093 dst
[i
*3+1] = FLOAT_TO_INT(green
[i
]);
1094 dst
[i
*3+2] = FLOAT_TO_INT(red
[i
]);
1099 dst
[i
*4+0] = FLOAT_TO_INT(blue
[i
]);
1100 dst
[i
*4+1] = FLOAT_TO_INT(green
[i
]);
1101 dst
[i
*4+2] = FLOAT_TO_INT(red
[i
]);
1102 dst
[i
*4+3] = FLOAT_TO_INT(alpha
[i
]);
1107 dst
[i
*4+0] = FLOAT_TO_INT(alpha
[i
]);
1108 dst
[i
*4+1] = FLOAT_TO_INT(blue
[i
]);
1109 dst
[i
*4+2] = FLOAT_TO_INT(green
[i
]);
1110 dst
[i
*4+3] = FLOAT_TO_INT(red
[i
]);
1114 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1116 if (packing
->SwapBytes
) {
1117 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1123 GLfloat
*dst
= (GLfloat
*) destination
;
1143 dst
[i
] = luminance
[i
];
1145 case GL_LUMINANCE_ALPHA
:
1147 dst
[i
*2+0] = luminance
[i
];
1148 dst
[i
*2+1] = alpha
[i
];
1153 dst
[i
*3+0] = red
[i
];
1154 dst
[i
*3+1] = green
[i
];
1155 dst
[i
*3+2] = blue
[i
];
1160 dst
[i
*4+0] = red
[i
];
1161 dst
[i
*4+1] = green
[i
];
1162 dst
[i
*4+2] = blue
[i
];
1163 dst
[i
*4+3] = alpha
[i
];
1168 dst
[i
*3+0] = blue
[i
];
1169 dst
[i
*3+1] = green
[i
];
1170 dst
[i
*3+2] = red
[i
];
1175 dst
[i
*4+0] = blue
[i
];
1176 dst
[i
*4+1] = green
[i
];
1177 dst
[i
*4+2] = red
[i
];
1178 dst
[i
*4+3] = alpha
[i
];
1183 dst
[i
*4+0] = alpha
[i
];
1184 dst
[i
*4+1] = blue
[i
];
1185 dst
[i
*4+2] = green
[i
];
1186 dst
[i
*4+3] = red
[i
];
1190 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1192 if (packing
->SwapBytes
) {
1193 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1197 case GL_UNSIGNED_BYTE_3_3_2
:
1198 if (format
== GL_RGB
) {
1199 GLubyte
*dst
= (GLubyte
*) destination
;
1201 dst
[i
] = (((GLint
) (red
[i
] * 7.0F
)) << 5)
1202 | (((GLint
) (green
[i
] * 7.0F
)) << 2)
1203 | (((GLint
) (blue
[i
] * 3.0F
)) );
1207 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1208 if (format
== GL_RGB
) {
1209 GLubyte
*dst
= (GLubyte
*) destination
;
1211 dst
[i
] = (((GLint
) (red
[i
] * 7.0F
)) )
1212 | (((GLint
) (green
[i
] * 7.0F
)) << 3)
1213 | (((GLint
) (blue
[i
] * 3.0F
)) << 5);
1217 case GL_UNSIGNED_SHORT_5_6_5
:
1218 if (format
== GL_RGB
) {
1219 GLushort
*dst
= (GLushort
*) destination
;
1221 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) << 11)
1222 | (((GLint
) (green
[i
] * 63.0F
)) << 5)
1223 | (((GLint
) (blue
[i
] * 31.0F
)) );
1227 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1228 if (format
== GL_RGB
) {
1229 GLushort
*dst
= (GLushort
*) destination
;
1231 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) )
1232 | (((GLint
) (green
[i
] * 63.0F
)) << 5)
1233 | (((GLint
) (blue
[i
] * 31.0F
)) << 11);
1237 case GL_UNSIGNED_SHORT_4_4_4_4
:
1238 if (format
== GL_RGB
) {
1239 GLushort
*dst
= (GLushort
*) destination
;
1241 dst
[i
] = (((GLint
) (red
[i
] * 15.0F
)) << 12)
1242 | (((GLint
) (green
[i
] * 15.0F
)) << 8)
1243 | (((GLint
) (blue
[i
] * 15.0F
)) << 4)
1244 | (((GLint
) (alpha
[i
] * 15.0F
)) );
1248 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1249 if (format
== GL_RGB
) {
1250 GLushort
*dst
= (GLushort
*) destination
;
1252 dst
[i
] = (((GLint
) (red
[i
] * 15.0F
)) )
1253 | (((GLint
) (green
[i
] * 15.0F
)) << 4)
1254 | (((GLint
) (blue
[i
] * 15.0F
)) << 8)
1255 | (((GLint
) (alpha
[i
] * 15.0F
)) << 12);
1259 case GL_UNSIGNED_SHORT_5_5_5_1
:
1260 if (format
== GL_RGB
) {
1261 GLushort
*dst
= (GLushort
*) destination
;
1263 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) << 11)
1264 | (((GLint
) (green
[i
] * 31.0F
)) << 6)
1265 | (((GLint
) (blue
[i
] * 31.0F
)) << 1)
1266 | (((GLint
) (alpha
[i
] * 1.0F
)) );
1270 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1271 if (format
== GL_RGB
) {
1272 GLushort
*dst
= (GLushort
*) destination
;
1274 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) )
1275 | (((GLint
) (green
[i
] * 31.0F
)) << 5)
1276 | (((GLint
) (blue
[i
] * 31.0F
)) << 10)
1277 | (((GLint
) (alpha
[i
] * 1.0F
)) << 15);
1281 case GL_UNSIGNED_INT_8_8_8_8
:
1282 if (format
== GL_RGBA
) {
1283 GLuint
*dst
= (GLuint
*) destination
;
1285 dst
[i
] = (((GLuint
) (red
[i
] * 255.0F
)) << 24)
1286 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
1287 | (((GLuint
) (blue
[i
] * 255.0F
)) << 8)
1288 | (((GLuint
) (alpha
[i
] * 255.0F
)) );
1291 else if (format
== GL_BGRA
) {
1292 GLuint
*dst
= (GLuint
*) destination
;
1294 dst
[i
] = (((GLuint
) (blue
[i
] * 255.0F
)) << 24)
1295 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
1296 | (((GLuint
) (red
[i
] * 255.0F
)) << 8)
1297 | (((GLuint
) (alpha
[i
] * 255.0F
)) );
1300 else if (format
== GL_ABGR_EXT
) {
1301 GLuint
*dst
= (GLuint
*) destination
;
1303 dst
[i
] = (((GLuint
) (alpha
[i
] * 255.0F
)) << 24)
1304 | (((GLuint
) (blue
[i
] * 255.0F
)) << 16)
1305 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
1306 | (((GLuint
) (red
[i
] * 255.0F
)) );
1310 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1311 if (format
== GL_RGBA
) {
1312 GLuint
*dst
= (GLuint
*) destination
;
1314 dst
[i
] = (((GLuint
) (red
[i
] * 255.0F
)) )
1315 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
1316 | (((GLuint
) (blue
[i
] * 255.0F
)) << 16)
1317 | (((GLuint
) (alpha
[i
] * 255.0F
)) << 24);
1320 else if (format
== GL_BGRA
) {
1321 GLuint
*dst
= (GLuint
*) destination
;
1323 dst
[i
] = (((GLuint
) (blue
[i
] * 255.0F
)) )
1324 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
1325 | (((GLuint
) (red
[i
] * 255.0F
)) << 16)
1326 | (((GLuint
) (alpha
[i
] * 255.0F
)) << 24);
1329 else if (format
== GL_ABGR_EXT
) {
1330 GLuint
*dst
= (GLuint
*) destination
;
1332 dst
[i
] = (((GLuint
) (alpha
[i
] * 255.0F
)) )
1333 | (((GLuint
) (blue
[i
] * 255.0F
)) << 8)
1334 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
1335 | (((GLuint
) (red
[i
] * 255.0F
)) << 24);
1339 case GL_UNSIGNED_INT_10_10_10_2
:
1340 if (format
== GL_RGBA
) {
1341 GLuint
*dst
= (GLuint
*) destination
;
1343 dst
[i
] = (((GLuint
) (red
[i
] * 1023.0F
)) << 22)
1344 | (((GLuint
) (green
[i
] * 1023.0F
)) << 12)
1345 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 2)
1346 | (((GLuint
) (alpha
[i
] * 3.0F
)) );
1349 else if (format
== GL_BGRA
) {
1350 GLuint
*dst
= (GLuint
*) destination
;
1352 dst
[i
] = (((GLuint
) (blue
[i
] * 1023.0F
)) << 22)
1353 | (((GLuint
) (green
[i
] * 1023.0F
)) << 12)
1354 | (((GLuint
) (red
[i
] * 1023.0F
)) << 2)
1355 | (((GLuint
) (alpha
[i
] * 3.0F
)) );
1358 else if (format
== GL_ABGR_EXT
) {
1359 GLuint
*dst
= (GLuint
*) destination
;
1361 dst
[i
] = (((GLuint
) (alpha
[i
] * 1023.0F
)) << 22)
1362 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 12)
1363 | (((GLuint
) (green
[i
] * 1023.0F
)) << 2)
1364 | (((GLuint
) (red
[i
] * 3.0F
)) );
1368 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1369 if (format
== GL_RGBA
) {
1370 GLuint
*dst
= (GLuint
*) destination
;
1372 dst
[i
] = (((GLuint
) (red
[i
] * 1023.0F
)) )
1373 | (((GLuint
) (green
[i
] * 1023.0F
)) << 10)
1374 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 20)
1375 | (((GLuint
) (alpha
[i
] * 3.0F
)) << 30);
1378 else if (format
== GL_BGRA
) {
1379 GLuint
*dst
= (GLuint
*) destination
;
1381 dst
[i
] = (((GLuint
) (blue
[i
] * 1023.0F
)) )
1382 | (((GLuint
) (green
[i
] * 1023.0F
)) << 10)
1383 | (((GLuint
) (red
[i
] * 1023.0F
)) << 20)
1384 | (((GLuint
) (alpha
[i
] * 3.0F
)) << 30);
1387 else if (format
== GL_ABGR_EXT
) {
1388 GLuint
*dst
= (GLuint
*) destination
;
1390 dst
[i
] = (((GLuint
) (alpha
[i
] * 1023.0F
)) )
1391 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 10)
1392 | (((GLuint
) (green
[i
] * 1023.0F
)) << 20)
1393 | (((GLuint
) (red
[i
] * 3.0F
)) << 30);
1398 gl_problem( ctx
, "bad type in _mesa_pack_rgba_span" );
1404 #define SWAP2BYTE(VALUE) \
1406 GLubyte *bytes = (GLubyte *) &(VALUE); \
1407 GLubyte tmp = bytes[0]; \
1408 bytes[0] = bytes[1]; \
1412 #define SWAP4BYTE(VALUE) \
1414 GLubyte *bytes = (GLubyte *) &(VALUE); \
1415 GLubyte tmp = bytes[0]; \
1416 bytes[0] = bytes[3]; \
1419 bytes[1] = bytes[2]; \
1425 extract_uint_indexes(GLuint n
, GLuint indexes
[],
1426 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
1427 const struct gl_pixelstore_attrib
*unpack
)
1429 assert(srcFormat
== GL_COLOR_INDEX
);
1431 ASSERT(srcType
== GL_BITMAP
||
1432 srcType
== GL_UNSIGNED_BYTE
||
1433 srcType
== GL_BYTE
||
1434 srcType
== GL_UNSIGNED_SHORT
||
1435 srcType
== GL_SHORT
||
1436 srcType
== GL_UNSIGNED_INT
||
1437 srcType
== GL_INT
||
1438 srcType
== GL_FLOAT
);
1443 GLubyte
*ubsrc
= (GLubyte
*) src
;
1444 if (unpack
->LsbFirst
) {
1445 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
1447 for (i
= 0; i
< n
; i
++) {
1448 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
1459 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
1461 for (i
= 0; i
< n
; i
++) {
1462 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
1474 case GL_UNSIGNED_BYTE
:
1477 const GLubyte
*s
= (const GLubyte
*) src
;
1478 for (i
= 0; i
< n
; i
++)
1485 const GLbyte
*s
= (const GLbyte
*) src
;
1486 for (i
= 0; i
< n
; i
++)
1490 case GL_UNSIGNED_SHORT
:
1493 const GLushort
*s
= (const GLushort
*) src
;
1494 if (unpack
->SwapBytes
) {
1495 for (i
= 0; i
< n
; i
++) {
1496 GLushort value
= s
[i
];
1502 for (i
= 0; i
< n
; i
++)
1510 const GLshort
*s
= (const GLshort
*) src
;
1511 if (unpack
->SwapBytes
) {
1512 for (i
= 0; i
< n
; i
++) {
1513 GLshort value
= s
[i
];
1519 for (i
= 0; i
< n
; i
++)
1524 case GL_UNSIGNED_INT
:
1527 const GLuint
*s
= (const GLuint
*) src
;
1528 if (unpack
->SwapBytes
) {
1529 for (i
= 0; i
< n
; i
++) {
1530 GLuint value
= s
[i
];
1536 for (i
= 0; i
< n
; i
++)
1544 const GLint
*s
= (const GLint
*) src
;
1545 if (unpack
->SwapBytes
) {
1546 for (i
= 0; i
< n
; i
++) {
1553 for (i
= 0; i
< n
; i
++)
1561 const GLfloat
*s
= (const GLfloat
*) src
;
1562 if (unpack
->SwapBytes
) {
1563 for (i
= 0; i
< n
; i
++) {
1564 GLfloat value
= s
[i
];
1566 indexes
[i
] = (GLuint
) value
;
1570 for (i
= 0; i
< n
; i
++)
1571 indexes
[i
] = (GLuint
) s
[i
];
1576 gl_problem(NULL
, "bad srcType in extract_uint_indexes");
1584 * This function extracts floating point RGBA values from arbitrary
1585 * image data. srcFormat and srcType are the format and type parameters
1586 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
1588 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
1589 * implements the "Conversion to floating point", "Conversion to RGB",
1590 * and "Final Expansion to RGBA" operations.
1592 * Args: n - number of pixels
1593 * rgba - output colors
1594 * srcFormat - format of incoming data
1595 * srcType - datatype of incoming data
1596 * src - source data pointer
1597 * swapBytes - perform byteswapping of incoming data?
1600 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
1601 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
1602 GLboolean swapBytes
)
1604 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
1606 GLint rComp
, bComp
, gComp
, aComp
;
1608 ASSERT(srcFormat
== GL_RED
||
1609 srcFormat
== GL_GREEN
||
1610 srcFormat
== GL_BLUE
||
1611 srcFormat
== GL_ALPHA
||
1612 srcFormat
== GL_LUMINANCE
||
1613 srcFormat
== GL_LUMINANCE_ALPHA
||
1614 srcFormat
== GL_INTENSITY
||
1615 srcFormat
== GL_RGB
||
1616 srcFormat
== GL_BGR
||
1617 srcFormat
== GL_RGBA
||
1618 srcFormat
== GL_BGRA
||
1619 srcFormat
== GL_ABGR_EXT
);
1621 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
1622 srcType
== GL_BYTE
||
1623 srcType
== GL_UNSIGNED_SHORT
||
1624 srcType
== GL_SHORT
||
1625 srcType
== GL_UNSIGNED_INT
||
1626 srcType
== GL_INT
||
1627 srcType
== GL_FLOAT
||
1628 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
1629 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
1630 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
1631 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
1632 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
1633 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
1634 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
1635 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
1636 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1637 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
1638 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
1639 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1641 rComp
= gComp
= bComp
= aComp
= -1;
1643 switch (srcFormat
) {
1646 greenIndex
= blueIndex
= alphaIndex
= -1;
1651 redIndex
= blueIndex
= alphaIndex
= -1;
1656 redIndex
= greenIndex
= alphaIndex
= -1;
1660 redIndex
= greenIndex
= blueIndex
= -1;
1665 redIndex
= greenIndex
= blueIndex
= 0;
1669 case GL_LUMINANCE_ALPHA
:
1670 redIndex
= greenIndex
= blueIndex
= 0;
1676 greenIndex
= blueIndex
= alphaIndex
= -1;
1727 gl_problem(NULL
, "bad srcFormat in extract float data");
1732 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
1733 if ((INDEX) < 0) { \
1735 for (i = 0; i < n; i++) { \
1736 rgba[i][CHANNEL] = DEFAULT; \
1739 else if (swapBytes) { \
1740 const TYPE *s = (const TYPE *) src; \
1742 for (i = 0; i < n; i++) { \
1743 TYPE value = s[INDEX]; \
1744 if (sizeof(TYPE) == 2) { \
1747 else if (sizeof(TYPE) == 4) { \
1750 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
1755 const TYPE *s = (const TYPE *) src; \
1757 for (i = 0; i < n; i++) { \
1758 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
1764 case GL_UNSIGNED_BYTE
:
1765 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1766 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1767 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1768 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1771 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1772 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1773 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1774 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
1776 case GL_UNSIGNED_SHORT
:
1777 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1778 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1779 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1780 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
1783 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1784 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1785 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1786 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
1788 case GL_UNSIGNED_INT
:
1789 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1790 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1791 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1792 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
1795 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1796 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1797 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1798 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
1801 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1802 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1803 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1804 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
1806 case GL_UNSIGNED_BYTE_3_3_2
:
1808 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
1810 for (i
= 0; i
< n
; i
++) {
1811 GLubyte p
= ubsrc
[i
];
1812 rgba
[i
][RCOMP
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
1813 rgba
[i
][GCOMP
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
1814 rgba
[i
][BCOMP
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
1815 rgba
[i
][ACOMP
] = 1.0F
;
1819 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1821 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
1823 for (i
= 0; i
< n
; i
++) {
1824 GLubyte p
= ubsrc
[i
];
1825 rgba
[i
][RCOMP
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
1826 rgba
[i
][GCOMP
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
1827 rgba
[i
][BCOMP
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
1828 rgba
[i
][ACOMP
] = 1.0F
;
1832 case GL_UNSIGNED_SHORT_5_6_5
:
1834 const GLushort
*ussrc
= (const GLushort
*) src
;
1836 for (i
= 0; i
< n
; i
++) {
1837 GLushort p
= ussrc
[i
];
1839 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1840 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1841 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1842 rgba
[i
][ACOMP
] = 1.0F
;
1846 const GLushort
*ussrc
= (const GLushort
*) src
;
1848 for (i
= 0; i
< n
; i
++) {
1849 GLushort p
= ussrc
[i
];
1850 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1851 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1852 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1853 rgba
[i
][ACOMP
] = 1.0F
;
1857 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1859 const GLushort
*ussrc
= (const GLushort
*) src
;
1861 for (i
= 0; i
< n
; i
++) {
1862 GLushort p
= ussrc
[i
];
1864 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1865 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1866 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1867 rgba
[i
][ACOMP
] = 1.0F
;
1871 const GLushort
*ussrc
= (const GLushort
*) src
;
1873 for (i
= 0; i
< n
; i
++) {
1874 GLushort p
= ussrc
[i
];
1875 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1876 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1877 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1878 rgba
[i
][ACOMP
] = 1.0F
;
1882 case GL_UNSIGNED_SHORT_4_4_4_4
:
1884 const GLushort
*ussrc
= (const GLushort
*) src
;
1886 for (i
= 0; i
< n
; i
++) {
1887 GLushort p
= ussrc
[i
];
1889 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1890 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1891 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1892 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1896 const GLushort
*ussrc
= (const GLushort
*) src
;
1898 for (i
= 0; i
< n
; i
++) {
1899 GLushort p
= ussrc
[i
];
1900 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1901 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1902 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1903 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1907 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1909 const GLushort
*ussrc
= (const GLushort
*) src
;
1911 for (i
= 0; i
< n
; i
++) {
1912 GLushort p
= ussrc
[i
];
1914 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1915 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1916 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1917 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1921 const GLushort
*ussrc
= (const GLushort
*) src
;
1923 for (i
= 0; i
< n
; i
++) {
1924 GLushort p
= ussrc
[i
];
1925 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1926 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1927 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1928 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1932 case GL_UNSIGNED_SHORT_5_5_5_1
:
1934 const GLushort
*ussrc
= (const GLushort
*) src
;
1936 for (i
= 0; i
< n
; i
++) {
1937 GLushort p
= ussrc
[i
];
1939 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1940 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
1941 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
1942 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
1946 const GLushort
*ussrc
= (const GLushort
*) src
;
1948 for (i
= 0; i
< n
; i
++) {
1949 GLushort p
= ussrc
[i
];
1950 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1951 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
1952 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
1953 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
1957 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1959 const GLushort
*ussrc
= (const GLushort
*) src
;
1961 for (i
= 0; i
< n
; i
++) {
1962 GLushort p
= ussrc
[i
];
1964 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1965 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
1966 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
1967 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
1971 const GLushort
*ussrc
= (const GLushort
*) src
;
1973 for (i
= 0; i
< n
; i
++) {
1974 GLushort p
= ussrc
[i
];
1975 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1976 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
1977 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
1978 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
1982 case GL_UNSIGNED_INT_8_8_8_8
:
1984 const GLuint
*uisrc
= (const GLuint
*) src
;
1986 for (i
= 0; i
< n
; i
++) {
1987 GLuint p
= uisrc
[i
];
1988 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
1989 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
1990 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
1991 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
1995 const GLuint
*uisrc
= (const GLuint
*) src
;
1997 for (i
= 0; i
< n
; i
++) {
1998 GLuint p
= uisrc
[i
];
1999 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2000 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2001 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2002 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2006 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2008 const GLuint
*uisrc
= (const GLuint
*) src
;
2010 for (i
= 0; i
< n
; i
++) {
2011 GLuint p
= uisrc
[i
];
2012 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2013 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2014 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2015 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2019 const GLuint
*uisrc
= (const GLuint
*) src
;
2021 for (i
= 0; i
< n
; i
++) {
2022 GLuint p
= uisrc
[i
];
2023 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2024 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2025 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2026 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2030 case GL_UNSIGNED_INT_10_10_10_2
:
2032 const GLuint
*uisrc
= (const GLuint
*) src
;
2034 for (i
= 0; i
< n
; i
++) {
2035 GLuint p
= uisrc
[i
];
2037 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2038 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2039 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2040 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2044 const GLuint
*uisrc
= (const GLuint
*) src
;
2046 for (i
= 0; i
< n
; i
++) {
2047 GLuint p
= uisrc
[i
];
2048 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2049 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2050 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2051 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2055 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2057 const GLuint
*uisrc
= (const GLuint
*) src
;
2059 for (i
= 0; i
< n
; i
++) {
2060 GLuint p
= uisrc
[i
];
2062 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2063 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2064 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2065 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2069 const GLuint
*uisrc
= (const GLuint
*) src
;
2071 for (i
= 0; i
< n
; i
++) {
2072 GLuint p
= uisrc
[i
];
2073 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2074 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2075 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2076 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2081 gl_problem(NULL
, "bad srcType in extract float data");
2089 * Unpack a row of color image data from a client buffer according to
2090 * the pixel unpacking parameters. Apply any enabled pixel transfer
2091 * ops (PixelMap, scale/bias) if the applyTransferOps flag is enabled.
2092 * Return GLubyte values in the specified dest image format.
2093 * This is (or will be) used by glDrawPixels and glTexImage?D().
2094 * Input: ctx - the context
2095 * n - number of pixels in the span
2096 * dstFormat - format of destination color array
2097 * dest - the destination color array
2098 * srcFormat - source image format
2099 * srcType - source image datatype
2100 * source - source image pointer
2101 * unpacking - pixel unpacking parameters
2102 * applyTransferOps - apply scale/bias/lookup-table ops?
2104 * XXX perhaps expand this to process whole images someday.
2107 _mesa_unpack_ubyte_color_span( const GLcontext
*ctx
,
2108 GLuint n
, GLenum dstFormat
, GLubyte dest
[],
2109 GLenum srcFormat
, GLenum srcType
,
2110 const GLvoid
*source
,
2111 const struct gl_pixelstore_attrib
*unpacking
,
2112 GLboolean applyTransferOps
)
2114 ASSERT(dstFormat
== GL_ALPHA
||
2115 dstFormat
== GL_LUMINANCE
||
2116 dstFormat
== GL_LUMINANCE_ALPHA
||
2117 dstFormat
== GL_INTENSITY
||
2118 dstFormat
== GL_RGB
||
2119 dstFormat
== GL_RGBA
||
2120 dstFormat
== GL_COLOR_INDEX
);
2122 ASSERT(srcFormat
== GL_RED
||
2123 srcFormat
== GL_GREEN
||
2124 srcFormat
== GL_BLUE
||
2125 srcFormat
== GL_ALPHA
||
2126 srcFormat
== GL_LUMINANCE
||
2127 srcFormat
== GL_LUMINANCE_ALPHA
||
2128 srcFormat
== GL_INTENSITY
||
2129 srcFormat
== GL_RGB
||
2130 srcFormat
== GL_BGR
||
2131 srcFormat
== GL_RGBA
||
2132 srcFormat
== GL_BGRA
||
2133 srcFormat
== GL_ABGR_EXT
||
2134 srcFormat
== GL_COLOR_INDEX
);
2136 ASSERT(srcType
== GL_BITMAP
||
2137 srcType
== GL_UNSIGNED_BYTE
||
2138 srcType
== GL_BYTE
||
2139 srcType
== GL_UNSIGNED_SHORT
||
2140 srcType
== GL_SHORT
||
2141 srcType
== GL_UNSIGNED_INT
||
2142 srcType
== GL_INT
||
2143 srcType
== GL_FLOAT
||
2144 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2145 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2146 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2147 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2148 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2149 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2150 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2151 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2152 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2153 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2154 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2155 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2157 /* this is intended for RGBA mode only */
2158 assert(ctx
->Visual
->RGBAflag
);
2160 applyTransferOps
&= (ctx
->Pixel
.ScaleOrBiasRGBA
||
2161 ctx
->Pixel
.MapColorFlag
||
2162 ctx
->ColorMatrix
.type
!= MATRIX_IDENTITY
||
2163 ctx
->Pixel
.ScaleOrBiasRGBApcm
);
2165 /* Try simple cases first */
2166 if (!applyTransferOps
&& srcType
== GL_UNSIGNED_BYTE
) {
2167 if (dstFormat
== GL_RGBA
) {
2168 if (srcFormat
== GL_RGBA
) {
2169 MEMCPY( dest
, source
, n
* 4 * sizeof(GLubyte
) );
2172 else if (srcFormat
== GL_RGB
) {
2174 const GLubyte
*src
= (const GLubyte
*) source
;
2175 GLubyte
*dst
= dest
;
2176 for (i
= 0; i
< n
; i
++) {
2187 else if (dstFormat
== GL_RGB
) {
2188 if (srcFormat
== GL_RGB
) {
2189 MEMCPY( dest
, source
, n
* 3 * sizeof(GLubyte
) );
2192 else if (srcFormat
== GL_RGBA
) {
2194 const GLubyte
*src
= (const GLubyte
*) source
;
2195 GLubyte
*dst
= dest
;
2196 for (i
= 0; i
< n
; i
++) {
2206 else if (dstFormat
== srcFormat
) {
2207 GLint comps
= _mesa_components_in_format(srcFormat
);
2209 MEMCPY( dest
, source
, n
* comps
* sizeof(GLubyte
) );
2216 /* general solution */
2217 GLfloat rgba
[MAX_WIDTH
][4];
2218 GLint dstComponents
;
2219 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2220 GLint dstLuminanceIndex
, dstIntensityIndex
;
2222 dstComponents
= _mesa_components_in_format( dstFormat
);
2223 /* source & dest image formats should have been error checked by now */
2224 assert(dstComponents
> 0);
2227 * Extract image data and convert to RGBA floats
2229 assert(n
<= MAX_WIDTH
);
2230 if (srcFormat
== GL_COLOR_INDEX
) {
2231 GLuint indexes
[MAX_WIDTH
];
2232 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2235 /* shift and offset indexes */
2236 gl_shift_and_offset_ci(ctx
, n
, indexes
);
2238 if (dstFormat
== GL_COLOR_INDEX
) {
2239 if (applyTransferOps
) {
2240 if (ctx
->Pixel
.MapColorFlag
) {
2241 /* Apply lookup table */
2242 gl_map_ci(ctx
, n
, indexes
);
2245 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2250 /* convert to GLubyte and return */
2253 for (i
= 0; i
< n
; i
++) {
2254 dest
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2259 /* Convert indexes to RGBA */
2260 gl_map_ci_to_rgba_float(ctx
, n
, indexes
, rgba
);
2264 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2265 unpacking
->SwapBytes
);
2267 if (applyTransferOps
) {
2268 /* scale and bias colors */
2269 _mesa_scale_and_bias_rgba_float(ctx
, n
, rgba
);
2271 /* color table lookup */
2272 if (ctx
->Pixel
.MapColorFlag
) {
2273 _mesa_map_rgba_float(ctx
, n
, rgba
);
2276 if (ctx
->ColorMatrix
.type
!= MATRIX_IDENTITY
||
2277 ctx
->Pixel
.ScaleOrBiasRGBApcm
) {
2278 _mesa_transform_rgba(ctx
, n
, rgba
);
2285 * XXX This is where more color table lookups, convolution,
2286 * histograms, minmax, color matrix, etc would take place if
2288 * See figure 3.7 in the OpenGL 1.2 specification for more info.
2292 /* clamp to [0,1] */
2295 for (i
= 0; i
< n
; i
++) {
2296 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
2297 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
2298 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
2299 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
2303 /* Now determine which color channels we need to produce.
2304 * And determine the dest index (offset) within each color tuple.
2306 switch (dstFormat
) {
2309 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2310 dstLuminanceIndex
= dstIntensityIndex
= -1;
2313 dstLuminanceIndex
= 0;
2314 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2315 dstIntensityIndex
= -1;
2317 case GL_LUMINANCE_ALPHA
:
2318 dstLuminanceIndex
= 0;
2320 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2321 dstIntensityIndex
= -1;
2324 dstIntensityIndex
= 0;
2325 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2326 dstLuminanceIndex
= -1;
2332 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
2339 dstLuminanceIndex
= dstIntensityIndex
= -1;
2342 gl_problem(ctx
, "bad dstFormat in _mesa_unpack_ubyte_span()");
2347 /* Now return the GLubyte data in the requested dstFormat */
2349 if (dstRedIndex
>= 0) {
2350 GLubyte
*dst
= dest
;
2352 for (i
= 0; i
< n
; i
++) {
2353 dst
[dstRedIndex
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2354 dst
+= dstComponents
;
2358 if (dstGreenIndex
>= 0) {
2359 GLubyte
*dst
= dest
;
2361 for (i
= 0; i
< n
; i
++) {
2362 dst
[dstGreenIndex
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2363 dst
+= dstComponents
;
2367 if (dstBlueIndex
>= 0) {
2368 GLubyte
*dst
= dest
;
2370 for (i
= 0; i
< n
; i
++) {
2371 dst
[dstBlueIndex
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2372 dst
+= dstComponents
;
2376 if (dstAlphaIndex
>= 0) {
2377 GLubyte
*dst
= dest
;
2379 for (i
= 0; i
< n
; i
++) {
2380 dst
[dstAlphaIndex
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2381 dst
+= dstComponents
;
2385 if (dstIntensityIndex
>= 0) {
2386 GLubyte
*dst
= dest
;
2388 assert(dstIntensityIndex
== 0);
2389 assert(dstComponents
== 1);
2390 for (i
= 0; i
< n
; i
++) {
2391 /* Intensity comes from red channel */
2392 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2396 if (dstLuminanceIndex
>= 0) {
2397 GLubyte
*dst
= dest
;
2399 assert(dstLuminanceIndex
== 0);
2400 for (i
= 0; i
< n
; i
++) {
2401 /* Luminance comes from red channel */
2402 dst
[0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2403 dst
+= dstComponents
;
2412 * Unpack a row of color index data from a client buffer according to
2413 * the pixel unpacking parameters. Apply pixel transfer ops if enabled
2414 * and applyTransferOps is true.
2415 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
2417 * Args: ctx - the context
2418 * n - number of pixels
2419 * dstType - destination datatype
2420 * dest - destination array
2421 * srcType - source pixel type
2422 * source - source data pointer
2423 * unpacking - pixel unpacking parameters
2424 * applyTransferOps - apply offset/bias/lookup ops?
2427 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
2428 GLenum dstType
, GLvoid
*dest
,
2429 GLenum srcType
, const GLvoid
*source
,
2430 const struct gl_pixelstore_attrib
*unpacking
,
2431 GLboolean applyTransferOps
)
2433 ASSERT(srcType
== GL_BITMAP
||
2434 srcType
== GL_UNSIGNED_BYTE
||
2435 srcType
== GL_BYTE
||
2436 srcType
== GL_UNSIGNED_SHORT
||
2437 srcType
== GL_SHORT
||
2438 srcType
== GL_UNSIGNED_INT
||
2439 srcType
== GL_INT
||
2440 srcType
== GL_FLOAT
);
2442 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
2443 dstType
== GL_UNSIGNED_SHORT
||
2444 dstType
== GL_UNSIGNED_INT
);
2446 applyTransferOps
&= (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
|| ctx
->Pixel
.MapColorFlag
);
2449 * Try simple cases first
2451 if (!applyTransferOps
&& srcType
== GL_UNSIGNED_BYTE
2452 && dstType
== GL_UNSIGNED_BYTE
) {
2453 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
2455 else if (!applyTransferOps
&& srcType
== GL_UNSIGNED_INT
2456 && dstType
== GL_UNSIGNED_INT
&& !unpacking
->SwapBytes
) {
2457 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
2463 GLuint indexes
[MAX_WIDTH
];
2464 assert(n
<= MAX_WIDTH
);
2466 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
2469 if (applyTransferOps
) {
2470 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2471 /* shift and offset indexes */
2472 gl_shift_and_offset_ci(ctx
, n
, indexes
);
2475 if (ctx
->Pixel
.MapColorFlag
) {
2476 /* Apply lookup table */
2477 gl_map_ci(ctx
, n
, indexes
);
2481 /* convert to dest type */
2483 case GL_UNSIGNED_BYTE
:
2485 GLubyte
*dst
= (GLubyte
*) dest
;
2487 for (i
= 0; i
< n
; i
++) {
2488 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2492 case GL_UNSIGNED_SHORT
:
2494 GLuint
*dst
= (GLuint
*) dest
;
2496 for (i
= 0; i
< n
; i
++) {
2497 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
2501 case GL_UNSIGNED_INT
:
2502 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
2505 gl_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
2512 * Unpack a row of stencil data from a client buffer according to
2513 * the pixel unpacking parameters. Apply pixel transfer ops if enabled
2514 * and applyTransferOps is true.
2515 * This is (or will be) used by glDrawPixels
2517 * Args: ctx - the context
2518 * n - number of pixels
2519 * dstType - destination datatype
2520 * dest - destination array
2521 * srcType - source pixel type
2522 * source - source data pointer
2523 * unpacking - pixel unpacking parameters
2524 * applyTransferOps - apply offset/bias/lookup ops?
2527 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
2528 GLenum dstType
, GLvoid
*dest
,
2529 GLenum srcType
, const GLvoid
*source
,
2530 const struct gl_pixelstore_attrib
*unpacking
,
2531 GLboolean applyTransferOps
)
2533 ASSERT(srcType
== GL_BITMAP
||
2534 srcType
== GL_UNSIGNED_BYTE
||
2535 srcType
== GL_BYTE
||
2536 srcType
== GL_UNSIGNED_SHORT
||
2537 srcType
== GL_SHORT
||
2538 srcType
== GL_UNSIGNED_INT
||
2539 srcType
== GL_INT
||
2540 srcType
== GL_FLOAT
);
2542 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
2543 dstType
== GL_UNSIGNED_SHORT
||
2544 dstType
== GL_UNSIGNED_INT
);
2546 applyTransferOps
&= (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
|| ctx
->Pixel
.MapColorFlag
);
2549 * Try simple cases first
2551 if (!applyTransferOps
&& srcType
== GL_UNSIGNED_BYTE
2552 && dstType
== GL_UNSIGNED_BYTE
) {
2553 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
2555 else if (!applyTransferOps
&& srcType
== GL_UNSIGNED_INT
2556 && dstType
== GL_UNSIGNED_INT
&& !unpacking
->SwapBytes
) {
2557 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
2563 GLuint indexes
[MAX_WIDTH
];
2564 assert(n
<= MAX_WIDTH
);
2566 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
2569 if (applyTransferOps
) {
2570 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2571 /* shift and offset indexes */
2572 gl_shift_and_offset_ci(ctx
, n
, indexes
);
2575 if (ctx
->Pixel
.MapStencilFlag
) {
2576 /* Apply stencil lookup table */
2577 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
2580 indexes
[i
] = ctx
->Pixel
.MapStoS
[ indexes
[i
] & mask
];
2585 /* convert to dest type */
2587 case GL_UNSIGNED_BYTE
:
2589 GLubyte
*dst
= (GLubyte
*) dest
;
2591 for (i
= 0; i
< n
; i
++) {
2592 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2596 case GL_UNSIGNED_SHORT
:
2598 GLuint
*dst
= (GLuint
*) dest
;
2600 for (i
= 0; i
< n
; i
++) {
2601 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
2605 case GL_UNSIGNED_INT
:
2606 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
2609 gl_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
2617 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
, GLdepth
*dest
,
2618 GLenum srcType
, const GLvoid
*source
,
2619 const struct gl_pixelstore_attrib
*unpacking
,
2620 GLboolean applyTransferOps
)
2622 GLfloat
*depth
= MALLOC(n
* sizeof(GLfloat
));
2630 const GLubyte
*src
= (const GLubyte
*) source
;
2631 for (i
= 0; i
< n
; i
++) {
2632 depth
[i
] = BYTE_TO_FLOAT(src
[i
]);
2636 case GL_UNSIGNED_BYTE
:
2639 const GLubyte
*src
= (const GLubyte
*) source
;
2640 for (i
= 0; i
< n
; i
++) {
2641 depth
[i
] = UBYTE_TO_FLOAT(src
[i
]);
2648 const GLshort
*src
= (const GLshort
*) source
;
2649 for (i
= 0; i
< n
; i
++) {
2650 depth
[i
] = SHORT_TO_FLOAT(src
[i
]);
2654 case GL_UNSIGNED_SHORT
:
2657 const GLushort
*src
= (const GLushort
*) source
;
2658 for (i
= 0; i
< n
; i
++) {
2659 depth
[i
] = USHORT_TO_FLOAT(src
[i
]);
2666 const GLint
*src
= (const GLint
*) source
;
2667 for (i
= 0; i
< n
; i
++) {
2668 depth
[i
] = INT_TO_FLOAT(src
[i
]);
2672 case GL_UNSIGNED_INT
:
2675 const GLuint
*src
= (const GLuint
*) source
;
2676 for (i
= 0; i
< n
; i
++) {
2677 depth
[i
] = UINT_TO_FLOAT(src
[i
]);
2682 MEMCPY(depth
, source
, n
* sizeof(GLfloat
));
2685 gl_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
2690 /* apply depth scale and bias */
2691 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
2693 for (i
= 0; i
< n
; i
++) {
2694 depth
[i
] = depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
2698 /* clamp depth values to [0,1] and convert from floats to integers */
2700 const GLfloat zs
= ctx
->Visual
->DepthMaxF
;
2702 for (i
= 0; i
< n
; i
++) {
2703 dest
[i
] = (GLdepth
) (CLAMP(depth
[i
], 0.0F
, 1.0F
) * zs
);
2713 * Unpack image data. Apply byteswapping, byte flipping (bitmap).
2714 * Return all image data in a contiguous block.
2717 _mesa_unpack_image( GLsizei width
, GLsizei height
, GLsizei depth
,
2718 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2719 const struct gl_pixelstore_attrib
*unpack
)
2721 GLint bytesPerRow
, compsPerRow
;
2722 GLboolean flipBytes
, swap2
, swap4
;
2725 return NULL
; /* not necessarily an error */
2727 if (width
<= 0 || height
<= 0 || depth
<= 0)
2728 return NULL
; /* generate error later */
2730 if (format
== GL_BITMAP
) {
2731 bytesPerRow
= (width
+ 7) >> 3;
2732 flipBytes
= !unpack
->LsbFirst
;
2733 swap2
= swap4
= GL_FALSE
;
2737 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
2738 const GLint components
= _mesa_components_in_format(format
);
2740 if (bytesPerPixel
<= 0 || components
<= 0)
2741 return NULL
; /* bad format or type. generate error later */
2742 bytesPerRow
= bytesPerPixel
* width
;
2743 bytesPerComp
= bytesPerPixel
/ components
;
2744 flipBytes
= GL_FALSE
;
2745 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
2746 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
2747 compsPerRow
= components
* width
;
2748 assert(compsPerRow
>= width
);
2752 GLubyte
*destBuffer
= MALLOC(bytesPerRow
* height
* depth
);
2756 return NULL
; /* generate GL_OUT_OF_MEMORY later */
2759 for (img
= 0; img
< depth
; img
++) {
2760 for (row
= 0; row
< height
; row
++) {
2761 const GLvoid
*src
= _mesa_image_address(unpack
, pixels
,
2762 width
, height
, format
, type
, img
, row
, 0);
2763 MEMCPY(dst
, src
, bytesPerRow
);
2764 /* byte flipping/swapping */
2766 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
2769 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
2772 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
2783 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
2784 * order with row alignment = 1 byte.
2787 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
2788 const struct gl_pixelstore_attrib
*packing
)
2790 GLint bytes
, row
, width_in_bytes
;
2791 GLubyte
*buffer
, *dst
;
2796 /* Alloc dest storage */
2797 bytes
= ((width
+ 7) / 8 * height
);
2798 buffer
= (GLubyte
*) MALLOC( bytes
);
2803 width_in_bytes
= CEILING( width
, 8 );
2805 for (row
= 0; row
< height
; row
++) {
2806 GLubyte
*src
= _mesa_image_address( packing
, pixels
, width
, height
,
2807 GL_COLOR_INDEX
, GL_BITMAP
,
2814 if (packing
->SkipPixels
== 0) {
2815 MEMCPY( dst
, src
, width_in_bytes
);
2816 if (packing
->LsbFirst
) {
2817 flip_bytes( dst
, width_in_bytes
);
2821 /* handling SkipPixels is a bit tricky (no pun intended!) */
2823 if (packing
->LsbFirst
) {
2824 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
2825 GLubyte dstMask
= 128;
2829 for (i
= 0; i
< width
; i
++) {
2833 if (srcMask
== 128) {
2838 srcMask
= srcMask
<< 1;
2846 dstMask
= dstMask
>> 1;
2851 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
2852 GLubyte dstMask
= 128;
2856 for (i
= 0; i
< width
; i
++) {
2865 srcMask
= srcMask
>> 1;
2873 dstMask
= dstMask
>> 1;
2878 dst
+= width_in_bytes
;
2889 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
2890 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
2892 GLint row
, width_in_bytes
;
2898 width_in_bytes
= CEILING( width
, 8 );
2900 for (row
= 0; row
< height
; row
++) {
2901 GLubyte
*dst
= _mesa_image_address( packing
, dest
, width
, height
,
2902 GL_COLOR_INDEX
, GL_BITMAP
,
2907 if (packing
->SkipPixels
== 0) {
2908 MEMCPY( dst
, src
, width_in_bytes
);
2909 if (packing
->LsbFirst
) {
2910 flip_bytes( dst
, width_in_bytes
);
2914 /* handling SkipPixels is a bit tricky (no pun intended!) */
2916 if (packing
->LsbFirst
) {
2917 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
2918 GLubyte dstMask
= 128;
2919 const GLubyte
*s
= src
;
2922 for (i
= 0; i
< width
; i
++) {
2926 if (srcMask
== 128) {
2931 srcMask
= srcMask
<< 1;
2939 dstMask
= dstMask
>> 1;
2944 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
2945 GLubyte dstMask
= 128;
2946 const GLubyte
*s
= src
;
2949 for (i
= 0; i
< width
; i
++) {
2958 srcMask
= srcMask
>> 1;
2966 dstMask
= dstMask
>> 1;
2971 src
+= width_in_bytes
;