1 /* $Id: image.c,v 1.21 2000/03/21 00:48:53 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 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.
66 void gl_flip_bytes( GLubyte
*p
, GLuint n
)
68 register GLuint i
, a
, b
;
72 a
= ((b
& 0x01) << 7) |
86 * Flip the order of the 2 bytes in each word in the given array.
88 void gl_swap2( GLushort
*p
, GLuint n
)
93 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
100 * Flip the order of the 4 bytes in each word in the given array.
102 void gl_swap4( GLuint
*p
, GLuint n
)
104 register GLuint i
, a
, b
;
109 | ((b
>> 8) & 0xff00)
110 | ((b
<< 8) & 0xff0000)
111 | ((b
<< 24) & 0xff000000);
120 * Return the size, in bytes, of the given GL datatype.
121 * Return 0 if GL_BITMAP.
122 * Return -1 if invalid type enum.
124 GLint
gl_sizeof_type( GLenum type
)
129 case GL_UNSIGNED_BYTE
:
130 return sizeof(GLubyte
);
132 return sizeof(GLbyte
);
133 case GL_UNSIGNED_SHORT
:
134 return sizeof(GLushort
);
136 return sizeof(GLshort
);
137 case GL_UNSIGNED_INT
:
138 return sizeof(GLuint
);
140 return sizeof(GLint
);
142 return sizeof(GLfloat
);
150 * Same as gl_sizeof_packed_type() but we also accept the
151 * packed pixel format datatypes.
153 GLint
gl_sizeof_packed_type( GLenum type
)
158 case GL_UNSIGNED_BYTE
:
159 return sizeof(GLubyte
);
161 return sizeof(GLbyte
);
162 case GL_UNSIGNED_SHORT
:
163 return sizeof(GLushort
);
165 return sizeof(GLshort
);
166 case GL_UNSIGNED_INT
:
167 return sizeof(GLuint
);
169 return sizeof(GLint
);
171 return sizeof(GLfloat
);
172 case GL_UNSIGNED_BYTE_3_3_2
:
173 return sizeof(GLubyte
);
174 case GL_UNSIGNED_BYTE_2_3_3_REV
:
175 return sizeof(GLubyte
);
176 case GL_UNSIGNED_SHORT_5_6_5
:
177 return sizeof(GLshort
);
178 case GL_UNSIGNED_SHORT_5_6_5_REV
:
179 return sizeof(GLshort
);
180 case GL_UNSIGNED_SHORT_4_4_4_4
:
181 return sizeof(GLshort
);
182 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
183 return sizeof(GLshort
);
184 case GL_UNSIGNED_SHORT_5_5_5_1
:
185 return sizeof(GLshort
);
186 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
187 return sizeof(GLshort
);
188 case GL_UNSIGNED_INT_8_8_8_8
:
189 return sizeof(GLuint
);
190 case GL_UNSIGNED_INT_8_8_8_8_REV
:
191 return sizeof(GLuint
);
192 case GL_UNSIGNED_INT_10_10_10_2
:
193 return sizeof(GLuint
);
194 case GL_UNSIGNED_INT_2_10_10_10_REV
:
195 return sizeof(GLuint
);
204 * Return the number of components in a GL enum pixel type.
205 * Return -1 if bad format.
207 GLint
gl_components_in_format( GLenum format
)
211 case GL_COLOR_INDEX1_EXT
:
212 case GL_COLOR_INDEX2_EXT
:
213 case GL_COLOR_INDEX4_EXT
:
214 case GL_COLOR_INDEX8_EXT
:
215 case GL_COLOR_INDEX12_EXT
:
216 case GL_COLOR_INDEX16_EXT
:
217 case GL_STENCIL_INDEX
:
218 case GL_DEPTH_COMPONENT
:
225 case GL_LUMINANCE_ALPHA
:
244 * Return bytes per pixel for given format and type
245 * Return -1 if bad format or type.
247 GLint
gl_bytes_per_pixel( GLenum format
, GLenum type
)
249 GLint comps
= gl_components_in_format( format
);
255 return 0; /* special case */
257 case GL_UNSIGNED_BYTE
:
258 return comps
* sizeof(GLubyte
);
260 case GL_UNSIGNED_SHORT
:
261 return comps
* sizeof(GLshort
);
263 case GL_UNSIGNED_INT
:
264 return comps
* sizeof(GLint
);
266 return comps
* sizeof(GLfloat
);
267 case GL_UNSIGNED_BYTE_3_3_2
:
268 case GL_UNSIGNED_BYTE_2_3_3_REV
:
269 if (format
== GL_RGB
|| format
== GL_BGR
)
270 return sizeof(GLubyte
);
272 return -1; /* error */
273 case GL_UNSIGNED_SHORT_5_6_5
:
274 case GL_UNSIGNED_SHORT_5_6_5_REV
:
275 if (format
== GL_RGB
|| format
== GL_BGR
)
276 return sizeof(GLshort
);
278 return -1; /* error */
279 case GL_UNSIGNED_SHORT_4_4_4_4
:
280 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
281 case GL_UNSIGNED_SHORT_5_5_5_1
:
282 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
283 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
284 return sizeof(GLushort
);
287 case GL_UNSIGNED_INT_8_8_8_8
:
288 case GL_UNSIGNED_INT_8_8_8_8_REV
:
289 case GL_UNSIGNED_INT_10_10_10_2
:
290 case GL_UNSIGNED_INT_2_10_10_10_REV
:
291 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
292 return sizeof(GLuint
);
302 * Test if the given pixel format and type are legal.
303 * Return GL_TRUE for legal, GL_FALSE for illegal.
305 GLboolean
gl_is_legal_format_and_type( GLenum format
, GLenum type
)
309 case GL_STENCIL_INDEX
:
313 case GL_UNSIGNED_BYTE
:
315 case GL_UNSIGNED_SHORT
:
317 case GL_UNSIGNED_INT
:
328 case GL_LUMINANCE_ALPHA
:
329 case GL_DEPTH_COMPONENT
:
333 case GL_UNSIGNED_BYTE
:
335 case GL_UNSIGNED_SHORT
:
337 case GL_UNSIGNED_INT
:
346 case GL_UNSIGNED_BYTE
:
348 case GL_UNSIGNED_SHORT
:
350 case GL_UNSIGNED_INT
:
352 case GL_UNSIGNED_BYTE_3_3_2
:
353 case GL_UNSIGNED_BYTE_2_3_3_REV
:
354 case GL_UNSIGNED_SHORT_5_6_5
:
355 case GL_UNSIGNED_SHORT_5_6_5_REV
:
365 case GL_UNSIGNED_BYTE
:
367 case GL_UNSIGNED_SHORT
:
369 case GL_UNSIGNED_INT
:
371 case GL_UNSIGNED_SHORT_4_4_4_4
:
372 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
373 case GL_UNSIGNED_SHORT_5_5_5_1
:
374 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
375 case GL_UNSIGNED_INT_8_8_8_8
:
376 case GL_UNSIGNED_INT_8_8_8_8_REV
:
377 case GL_UNSIGNED_INT_10_10_10_2
:
378 case GL_UNSIGNED_INT_2_10_10_10_REV
:
392 * Return the address of a pixel in an image (actually a volume).
393 * Pixel unpacking/packing parameters are observed according to 'packing'.
394 * Input: image - start of image data
395 * width, height - size of image
396 * format - image format
397 * type - pixel component type
398 * packing - the pixelstore attributes
399 * img - which image in the volume (0 for 1D or 2D images)
400 * row, column - location of pixel in the image
401 * Return: address of pixel at (image,row,column) in image or NULL if error.
403 GLvoid
*gl_pixel_addr_in_image( const struct gl_pixelstore_attrib
*packing
,
404 const GLvoid
*image
, GLsizei width
,
405 GLsizei height
, GLenum format
, GLenum type
,
406 GLint img
, GLint row
, GLint column
)
408 GLint alignment
; /* 1, 2 or 4 */
409 GLint pixels_per_row
;
410 GLint rows_per_image
;
413 GLint skipimages
; /* for 3-D volume images */
416 alignment
= packing
->Alignment
;
417 if (packing
->RowLength
> 0) {
418 pixels_per_row
= packing
->RowLength
;
421 pixels_per_row
= width
;
423 if (packing
->ImageHeight
> 0) {
424 rows_per_image
= packing
->ImageHeight
;
427 rows_per_image
= height
;
429 skiprows
= packing
->SkipRows
;
430 skippixels
= packing
->SkipPixels
;
431 skipimages
= packing
->SkipImages
;
433 if (type
==GL_BITMAP
) {
435 GLint comp_per_pixel
; /* components per pixel */
436 GLint bytes_per_comp
; /* bytes per component */
438 GLint bytes_per_image
;
440 /* Compute bytes per component */
441 bytes_per_comp
= gl_sizeof_packed_type( type
);
442 if (bytes_per_comp
<0) {
446 /* Compute number of components per pixel */
447 comp_per_pixel
= gl_components_in_format( format
);
448 if (comp_per_pixel
<0 && type
!= GL_BITMAP
) {
452 bytes_per_row
= alignment
453 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
455 bytes_per_image
= bytes_per_row
* rows_per_image
;
457 pixel_addr
= (GLubyte
*) image
458 + (skipimages
+ img
) * bytes_per_image
459 + (skiprows
+ row
) * bytes_per_row
460 + (skippixels
+ column
) / 8;
463 /* Non-BITMAP data */
464 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
466 bytes_per_pixel
= gl_bytes_per_pixel( format
, type
);
468 /* The pixel type and format should have been error checked earlier */
469 assert(bytes_per_pixel
> 0);
471 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
472 remainder
= bytes_per_row
% alignment
;
474 bytes_per_row
+= (alignment
- remainder
);
476 ASSERT(bytes_per_row
% alignment
== 0);
478 bytes_per_image
= bytes_per_row
* rows_per_image
;
480 /* compute final pixel address */
481 pixel_addr
= (GLubyte
*) image
482 + (skipimages
+ img
) * bytes_per_image
483 + (skiprows
+ row
) * bytes_per_row
484 + (skippixels
+ column
) * bytes_per_pixel
;
487 return (GLvoid
*) pixel_addr
;
493 * Compute the stride between image rows (in bytes) for the given
494 * pixel packing parameters and image width, format and type.
497 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
498 GLint width
, GLenum format
, GLenum type
)
501 if (type
== GL_BITMAP
) {
503 if (packing
->RowLength
== 0) {
504 GLint bytes
= (width
+ 7) / 8;
508 GLint bytes
= (packing
->RowLength
+ 7) / 8;
513 /* Non-BITMAP data */
514 const GLint bytesPerPixel
= gl_bytes_per_pixel(format
, type
);
515 if (bytesPerPixel
<= 0)
516 return -1; /* error */
517 if (packing
->RowLength
== 0) {
518 GLint bytes
= bytesPerPixel
* width
;
522 GLint bytes
= bytesPerPixel
* packing
->RowLength
;
531 * Unpack a 32x32 pixel polygon stipple from user memory using the
532 * current pixel unpack settings.
535 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
536 const struct gl_pixelstore_attrib
*unpacking
)
538 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap( 32, 32, pattern
, unpacking
);
540 /* Convert pattern from GLubytes to GLuints and handle big/little
545 for (i
= 0; i
< 32; i
++) {
546 dest
[i
] = (p
[0] << 24)
559 * Pack polygon stipple into user memory given current pixel packing
563 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
564 const struct gl_pixelstore_attrib
*packing
)
566 /* Convert pattern from GLuints to GLubytes to handle big/little
567 * endian differences.
571 for (i
= 0; i
< 32; i
++) {
572 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
573 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
574 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
575 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
578 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
584 * Pack the given RGBA span into client memory at 'dest' address
585 * in the given pixel format and type.
586 * Optionally apply the enabled pixel transfer ops.
587 * Pack into memory using the given packing params struct.
588 * This is used by glReadPixels and glGetTexImage?D()
589 * Input: ctx - the context
590 * n - number of pixels in the span
592 * format - dest packing format
593 * type - dest packing datatype
594 * destination - destination packing address
595 * packing - pixel packing parameters
596 * applyTransferOps - apply scale/bias/lookup-table ops?
598 void gl_pack_rgba_span( const GLcontext
*ctx
,
599 GLuint n
, CONST GLubyte rgba
[][4],
600 GLenum format
, GLenum type
, GLvoid
*destination
,
601 const struct gl_pixelstore_attrib
*packing
,
602 GLboolean applyTransferOps
)
604 applyTransferOps
&= (ctx
->Pixel
.ScaleOrBiasRGBA
|| ctx
->Pixel
.MapColorFlag
);
606 /* Test for optimized case first */
607 if (!applyTransferOps
&& format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
608 /* common simple case */
609 MEMCPY( destination
, rgba
, n
* 4 * sizeof(GLubyte
) );
611 else if (!applyTransferOps
&& format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
612 /* common simple case */
614 GLubyte
*dest
= (GLubyte
*) destination
;
615 for (i
= 0; i
< n
; i
++) {
616 dest
[0] = rgba
[i
][RCOMP
];
617 dest
[1] = rgba
[i
][GCOMP
];
618 dest
[2] = rgba
[i
][BCOMP
];
623 /* general solution */
624 GLfloat red
[MAX_WIDTH
], green
[MAX_WIDTH
], blue
[MAX_WIDTH
];
625 GLfloat alpha
[MAX_WIDTH
], luminance
[MAX_WIDTH
];
626 const GLfloat rscale
= 1.0F
/ 255.0F
;
627 const GLfloat gscale
= 1.0F
/ 255.0F
;
628 const GLfloat bscale
= 1.0F
/ 255.0F
;
629 const GLfloat ascale
= 1.0F
/ 255.0F
;
630 const GLint comps
= gl_components_in_format(format
);
633 assert(n
<= MAX_WIDTH
);
635 /* convert color components to floating point */
637 red
[i
] = rgba
[i
][RCOMP
] * rscale
;
638 green
[i
] = rgba
[i
][GCOMP
] * gscale
;
639 blue
[i
] = rgba
[i
][BCOMP
] * bscale
;
640 alpha
[i
] = rgba
[i
][ACOMP
] * ascale
;
644 * Apply scale, bias and lookup-tables if enabled.
646 if (applyTransferOps
) {
647 if (ctx
->Pixel
.ScaleOrBiasRGBA
) {
648 gl_scale_and_bias_color( ctx
, n
, red
, green
, blue
, alpha
);
650 if (ctx
->Pixel
.MapColorFlag
) {
651 gl_map_color( ctx
, n
, red
, green
, blue
, alpha
);
655 if (format
==GL_LUMINANCE
|| format
==GL_LUMINANCE_ALPHA
) {
657 GLfloat sum
= red
[i
] + green
[i
] + blue
[i
];
658 luminance
[i
] = CLAMP( sum
, 0.0F
, 1.0F
);
663 * Pack/store the pixels. Ugh! Lots of cases!!!
666 case GL_UNSIGNED_BYTE
:
668 GLubyte
*dst
= (GLubyte
*) destination
;
672 dst
[i
] = FLOAT_TO_UBYTE(red
[i
]);
676 dst
[i
] = FLOAT_TO_UBYTE(green
[i
]);
680 dst
[i
] = FLOAT_TO_UBYTE(blue
[i
]);
684 dst
[i
] = FLOAT_TO_UBYTE(alpha
[i
]);
688 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
690 case GL_LUMINANCE_ALPHA
:
692 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
693 dst
[i
*2+1] = FLOAT_TO_UBYTE(alpha
[i
]);
698 dst
[i
*3+0] = FLOAT_TO_UBYTE(red
[i
]);
699 dst
[i
*3+1] = FLOAT_TO_UBYTE(green
[i
]);
700 dst
[i
*3+2] = FLOAT_TO_UBYTE(blue
[i
]);
705 dst
[i
*4+0] = FLOAT_TO_UBYTE(red
[i
]);
706 dst
[i
*4+1] = FLOAT_TO_UBYTE(green
[i
]);
707 dst
[i
*4+2] = FLOAT_TO_UBYTE(blue
[i
]);
708 dst
[i
*4+3] = FLOAT_TO_UBYTE(alpha
[i
]);
713 dst
[i
*3+0] = FLOAT_TO_UBYTE(blue
[i
]);
714 dst
[i
*3+1] = FLOAT_TO_UBYTE(green
[i
]);
715 dst
[i
*3+2] = FLOAT_TO_UBYTE(red
[i
]);
720 dst
[i
*4+0] = FLOAT_TO_UBYTE(blue
[i
]);
721 dst
[i
*4+1] = FLOAT_TO_UBYTE(green
[i
]);
722 dst
[i
*4+2] = FLOAT_TO_UBYTE(red
[i
]);
723 dst
[i
*4+3] = FLOAT_TO_UBYTE(alpha
[i
]);
728 dst
[i
*4+0] = FLOAT_TO_UBYTE(alpha
[i
]);
729 dst
[i
*4+1] = FLOAT_TO_UBYTE(blue
[i
]);
730 dst
[i
*4+2] = FLOAT_TO_UBYTE(green
[i
]);
731 dst
[i
*4+3] = FLOAT_TO_UBYTE(red
[i
]);
735 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
741 GLbyte
*dst
= (GLbyte
*) destination
;
745 dst
[i
] = FLOAT_TO_BYTE(red
[i
]);
749 dst
[i
] = FLOAT_TO_BYTE(green
[i
]);
753 dst
[i
] = FLOAT_TO_BYTE(blue
[i
]);
757 dst
[i
] = FLOAT_TO_BYTE(alpha
[i
]);
761 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
763 case GL_LUMINANCE_ALPHA
:
765 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
766 dst
[i
*2+1] = FLOAT_TO_BYTE(alpha
[i
]);
771 dst
[i
*3+0] = FLOAT_TO_BYTE(red
[i
]);
772 dst
[i
*3+1] = FLOAT_TO_BYTE(green
[i
]);
773 dst
[i
*3+2] = FLOAT_TO_BYTE(blue
[i
]);
778 dst
[i
*4+0] = FLOAT_TO_BYTE(red
[i
]);
779 dst
[i
*4+1] = FLOAT_TO_BYTE(green
[i
]);
780 dst
[i
*4+2] = FLOAT_TO_BYTE(blue
[i
]);
781 dst
[i
*4+3] = FLOAT_TO_BYTE(alpha
[i
]);
786 dst
[i
*3+0] = FLOAT_TO_BYTE(blue
[i
]);
787 dst
[i
*3+1] = FLOAT_TO_BYTE(green
[i
]);
788 dst
[i
*3+2] = FLOAT_TO_BYTE(red
[i
]);
793 dst
[i
*4+0] = FLOAT_TO_BYTE(blue
[i
]);
794 dst
[i
*4+1] = FLOAT_TO_BYTE(green
[i
]);
795 dst
[i
*4+2] = FLOAT_TO_BYTE(red
[i
]);
796 dst
[i
*4+3] = FLOAT_TO_BYTE(alpha
[i
]);
800 dst
[i
*4+0] = FLOAT_TO_BYTE(alpha
[i
]);
801 dst
[i
*4+1] = FLOAT_TO_BYTE(blue
[i
]);
802 dst
[i
*4+2] = FLOAT_TO_BYTE(green
[i
]);
803 dst
[i
*4+3] = FLOAT_TO_BYTE(red
[i
]);
807 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
811 case GL_UNSIGNED_SHORT
:
813 GLushort
*dst
= (GLushort
*) destination
;
817 dst
[i
] = FLOAT_TO_USHORT(red
[i
]);
821 dst
[i
] = FLOAT_TO_USHORT(green
[i
]);
825 dst
[i
] = FLOAT_TO_USHORT(blue
[i
]);
829 dst
[i
] = FLOAT_TO_USHORT(alpha
[i
]);
833 dst
[i
] = FLOAT_TO_USHORT(luminance
[i
]);
835 case GL_LUMINANCE_ALPHA
:
837 dst
[i
*2+0] = FLOAT_TO_USHORT(luminance
[i
]);
838 dst
[i
*2+1] = FLOAT_TO_USHORT(alpha
[i
]);
843 dst
[i
*3+0] = FLOAT_TO_USHORT(red
[i
]);
844 dst
[i
*3+1] = FLOAT_TO_USHORT(green
[i
]);
845 dst
[i
*3+2] = FLOAT_TO_USHORT(blue
[i
]);
850 dst
[i
*4+0] = FLOAT_TO_USHORT(red
[i
]);
851 dst
[i
*4+1] = FLOAT_TO_USHORT(green
[i
]);
852 dst
[i
*4+2] = FLOAT_TO_USHORT(blue
[i
]);
853 dst
[i
*4+3] = FLOAT_TO_USHORT(alpha
[i
]);
858 dst
[i
*3+0] = FLOAT_TO_USHORT(blue
[i
]);
859 dst
[i
*3+1] = FLOAT_TO_USHORT(green
[i
]);
860 dst
[i
*3+2] = FLOAT_TO_USHORT(red
[i
]);
865 dst
[i
*4+0] = FLOAT_TO_USHORT(blue
[i
]);
866 dst
[i
*4+1] = FLOAT_TO_USHORT(green
[i
]);
867 dst
[i
*4+2] = FLOAT_TO_USHORT(red
[i
]);
868 dst
[i
*4+3] = FLOAT_TO_USHORT(alpha
[i
]);
873 dst
[i
*4+0] = FLOAT_TO_USHORT(alpha
[i
]);
874 dst
[i
*4+1] = FLOAT_TO_USHORT(blue
[i
]);
875 dst
[i
*4+2] = FLOAT_TO_USHORT(green
[i
]);
876 dst
[i
*4+3] = FLOAT_TO_USHORT(red
[i
]);
880 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
882 if (packing
->SwapBytes
) {
883 gl_swap2( (GLushort
*) dst
, n
* comps
);
889 GLshort
*dst
= (GLshort
*) destination
;
893 dst
[i
] = FLOAT_TO_SHORT(red
[i
]);
897 dst
[i
] = FLOAT_TO_SHORT(green
[i
]);
901 dst
[i
] = FLOAT_TO_SHORT(blue
[i
]);
905 dst
[i
] = FLOAT_TO_SHORT(alpha
[i
]);
909 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
911 case GL_LUMINANCE_ALPHA
:
913 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
914 dst
[i
*2+1] = FLOAT_TO_SHORT(alpha
[i
]);
919 dst
[i
*3+0] = FLOAT_TO_SHORT(red
[i
]);
920 dst
[i
*3+1] = FLOAT_TO_SHORT(green
[i
]);
921 dst
[i
*3+2] = FLOAT_TO_SHORT(blue
[i
]);
926 dst
[i
*4+0] = FLOAT_TO_SHORT(red
[i
]);
927 dst
[i
*4+1] = FLOAT_TO_SHORT(green
[i
]);
928 dst
[i
*4+2] = FLOAT_TO_SHORT(blue
[i
]);
929 dst
[i
*4+3] = FLOAT_TO_SHORT(alpha
[i
]);
934 dst
[i
*3+0] = FLOAT_TO_SHORT(blue
[i
]);
935 dst
[i
*3+1] = FLOAT_TO_SHORT(green
[i
]);
936 dst
[i
*3+2] = FLOAT_TO_SHORT(red
[i
]);
941 dst
[i
*4+0] = FLOAT_TO_SHORT(blue
[i
]);
942 dst
[i
*4+1] = FLOAT_TO_SHORT(green
[i
]);
943 dst
[i
*4+2] = FLOAT_TO_SHORT(red
[i
]);
944 dst
[i
*4+3] = FLOAT_TO_SHORT(alpha
[i
]);
948 dst
[i
*4+0] = FLOAT_TO_SHORT(alpha
[i
]);
949 dst
[i
*4+1] = FLOAT_TO_SHORT(blue
[i
]);
950 dst
[i
*4+2] = FLOAT_TO_SHORT(green
[i
]);
951 dst
[i
*4+3] = FLOAT_TO_SHORT(red
[i
]);
955 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
957 if (packing
->SwapBytes
) {
958 gl_swap2( (GLushort
*) dst
, n
* comps
);
962 case GL_UNSIGNED_INT
:
964 GLuint
*dst
= (GLuint
*) destination
;
968 dst
[i
] = FLOAT_TO_UINT(red
[i
]);
972 dst
[i
] = FLOAT_TO_UINT(green
[i
]);
976 dst
[i
] = FLOAT_TO_UINT(blue
[i
]);
980 dst
[i
] = FLOAT_TO_UINT(alpha
[i
]);
984 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
986 case GL_LUMINANCE_ALPHA
:
988 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
989 dst
[i
*2+1] = FLOAT_TO_UINT(alpha
[i
]);
994 dst
[i
*3+0] = FLOAT_TO_UINT(red
[i
]);
995 dst
[i
*3+1] = FLOAT_TO_UINT(green
[i
]);
996 dst
[i
*3+2] = FLOAT_TO_UINT(blue
[i
]);
1001 dst
[i
*4+0] = FLOAT_TO_UINT(red
[i
]);
1002 dst
[i
*4+1] = FLOAT_TO_UINT(green
[i
]);
1003 dst
[i
*4+2] = FLOAT_TO_UINT(blue
[i
]);
1004 dst
[i
*4+3] = FLOAT_TO_UINT(alpha
[i
]);
1009 dst
[i
*3+0] = FLOAT_TO_UINT(blue
[i
]);
1010 dst
[i
*3+1] = FLOAT_TO_UINT(green
[i
]);
1011 dst
[i
*3+2] = FLOAT_TO_UINT(red
[i
]);
1016 dst
[i
*4+0] = FLOAT_TO_UINT(blue
[i
]);
1017 dst
[i
*4+1] = FLOAT_TO_UINT(green
[i
]);
1018 dst
[i
*4+2] = FLOAT_TO_UINT(red
[i
]);
1019 dst
[i
*4+3] = FLOAT_TO_UINT(alpha
[i
]);
1024 dst
[i
*4+0] = FLOAT_TO_UINT(alpha
[i
]);
1025 dst
[i
*4+1] = FLOAT_TO_UINT(blue
[i
]);
1026 dst
[i
*4+2] = FLOAT_TO_UINT(green
[i
]);
1027 dst
[i
*4+3] = FLOAT_TO_UINT(red
[i
]);
1031 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
1033 if (packing
->SwapBytes
) {
1034 gl_swap4( (GLuint
*) dst
, n
* comps
);
1040 GLint
*dst
= (GLint
*) destination
;
1044 dst
[i
] = FLOAT_TO_INT(red
[i
]);
1048 dst
[i
] = FLOAT_TO_INT(green
[i
]);
1052 dst
[i
] = FLOAT_TO_INT(blue
[i
]);
1056 dst
[i
] = FLOAT_TO_INT(alpha
[i
]);
1060 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1062 case GL_LUMINANCE_ALPHA
:
1064 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1065 dst
[i
*2+1] = FLOAT_TO_INT(alpha
[i
]);
1070 dst
[i
*3+0] = FLOAT_TO_INT(red
[i
]);
1071 dst
[i
*3+1] = FLOAT_TO_INT(green
[i
]);
1072 dst
[i
*3+2] = FLOAT_TO_INT(blue
[i
]);
1077 dst
[i
*4+0] = FLOAT_TO_INT(red
[i
]);
1078 dst
[i
*4+1] = FLOAT_TO_INT(green
[i
]);
1079 dst
[i
*4+2] = FLOAT_TO_INT(blue
[i
]);
1080 dst
[i
*4+3] = FLOAT_TO_INT(alpha
[i
]);
1085 dst
[i
*3+0] = FLOAT_TO_INT(blue
[i
]);
1086 dst
[i
*3+1] = FLOAT_TO_INT(green
[i
]);
1087 dst
[i
*3+2] = FLOAT_TO_INT(red
[i
]);
1092 dst
[i
*4+0] = FLOAT_TO_INT(blue
[i
]);
1093 dst
[i
*4+1] = FLOAT_TO_INT(green
[i
]);
1094 dst
[i
*4+2] = FLOAT_TO_INT(red
[i
]);
1095 dst
[i
*4+3] = FLOAT_TO_INT(alpha
[i
]);
1100 dst
[i
*4+0] = FLOAT_TO_INT(alpha
[i
]);
1101 dst
[i
*4+1] = FLOAT_TO_INT(blue
[i
]);
1102 dst
[i
*4+2] = FLOAT_TO_INT(green
[i
]);
1103 dst
[i
*4+3] = FLOAT_TO_INT(red
[i
]);
1107 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
1109 if (packing
->SwapBytes
) {
1110 gl_swap4( (GLuint
*) dst
, n
* comps
);
1116 GLfloat
*dst
= (GLfloat
*) destination
;
1136 dst
[i
] = luminance
[i
];
1138 case GL_LUMINANCE_ALPHA
:
1140 dst
[i
*2+0] = luminance
[i
];
1141 dst
[i
*2+1] = alpha
[i
];
1146 dst
[i
*3+0] = red
[i
];
1147 dst
[i
*3+1] = green
[i
];
1148 dst
[i
*3+2] = blue
[i
];
1153 dst
[i
*4+0] = red
[i
];
1154 dst
[i
*4+1] = green
[i
];
1155 dst
[i
*4+2] = blue
[i
];
1156 dst
[i
*4+3] = alpha
[i
];
1161 dst
[i
*3+0] = blue
[i
];
1162 dst
[i
*3+1] = green
[i
];
1163 dst
[i
*3+2] = red
[i
];
1168 dst
[i
*4+0] = blue
[i
];
1169 dst
[i
*4+1] = green
[i
];
1170 dst
[i
*4+2] = red
[i
];
1171 dst
[i
*4+3] = alpha
[i
];
1176 dst
[i
*4+0] = alpha
[i
];
1177 dst
[i
*4+1] = blue
[i
];
1178 dst
[i
*4+2] = green
[i
];
1179 dst
[i
*4+3] = red
[i
];
1183 gl_problem(ctx
, "bad format in gl_pack_rgba_span\n");
1185 if (packing
->SwapBytes
) {
1186 gl_swap4( (GLuint
*) dst
, n
* comps
);
1190 case GL_UNSIGNED_BYTE_3_3_2
:
1191 if (format
== GL_RGB
) {
1192 GLubyte
*dst
= (GLubyte
*) destination
;
1194 dst
[i
] = (((GLint
) (red
[i
] * 7.0F
)) << 5)
1195 | (((GLint
) (green
[i
] * 7.0F
)) << 2)
1196 | (((GLint
) (blue
[i
] * 3.0F
)) );
1200 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1201 if (format
== GL_RGB
) {
1202 GLubyte
*dst
= (GLubyte
*) destination
;
1204 dst
[i
] = (((GLint
) (red
[i
] * 7.0F
)) )
1205 | (((GLint
) (green
[i
] * 7.0F
)) << 3)
1206 | (((GLint
) (blue
[i
] * 3.0F
)) << 5);
1210 case GL_UNSIGNED_SHORT_5_6_5
:
1211 if (format
== GL_RGB
) {
1212 GLushort
*dst
= (GLushort
*) destination
;
1214 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) << 11)
1215 | (((GLint
) (green
[i
] * 63.0F
)) << 5)
1216 | (((GLint
) (blue
[i
] * 31.0F
)) );
1220 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1221 if (format
== GL_RGB
) {
1222 GLushort
*dst
= (GLushort
*) destination
;
1224 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) )
1225 | (((GLint
) (green
[i
] * 63.0F
)) << 5)
1226 | (((GLint
) (blue
[i
] * 31.0F
)) << 11);
1230 case GL_UNSIGNED_SHORT_4_4_4_4
:
1231 if (format
== GL_RGB
) {
1232 GLushort
*dst
= (GLushort
*) destination
;
1234 dst
[i
] = (((GLint
) (red
[i
] * 15.0F
)) << 12)
1235 | (((GLint
) (green
[i
] * 15.0F
)) << 8)
1236 | (((GLint
) (blue
[i
] * 15.0F
)) << 4)
1237 | (((GLint
) (alpha
[i
] * 15.0F
)) );
1241 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1242 if (format
== GL_RGB
) {
1243 GLushort
*dst
= (GLushort
*) destination
;
1245 dst
[i
] = (((GLint
) (red
[i
] * 15.0F
)) )
1246 | (((GLint
) (green
[i
] * 15.0F
)) << 4)
1247 | (((GLint
) (blue
[i
] * 15.0F
)) << 8)
1248 | (((GLint
) (alpha
[i
] * 15.0F
)) << 12);
1252 case GL_UNSIGNED_SHORT_5_5_5_1
:
1253 if (format
== GL_RGB
) {
1254 GLushort
*dst
= (GLushort
*) destination
;
1256 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) << 11)
1257 | (((GLint
) (green
[i
] * 31.0F
)) << 6)
1258 | (((GLint
) (blue
[i
] * 31.0F
)) << 1)
1259 | (((GLint
) (alpha
[i
] * 1.0F
)) );
1263 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1264 if (format
== GL_RGB
) {
1265 GLushort
*dst
= (GLushort
*) destination
;
1267 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) )
1268 | (((GLint
) (green
[i
] * 31.0F
)) << 5)
1269 | (((GLint
) (blue
[i
] * 31.0F
)) << 10)
1270 | (((GLint
) (alpha
[i
] * 1.0F
)) << 15);
1274 case GL_UNSIGNED_INT_8_8_8_8
:
1275 if (format
== GL_RGBA
) {
1276 GLuint
*dst
= (GLuint
*) destination
;
1278 dst
[i
] = (((GLuint
) (red
[i
] * 255.0F
)) << 24)
1279 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
1280 | (((GLuint
) (blue
[i
] * 255.0F
)) << 8)
1281 | (((GLuint
) (alpha
[i
] * 255.0F
)) );
1284 else if (format
== GL_BGRA
) {
1285 GLuint
*dst
= (GLuint
*) destination
;
1287 dst
[i
] = (((GLuint
) (blue
[i
] * 255.0F
)) << 24)
1288 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
1289 | (((GLuint
) (red
[i
] * 255.0F
)) << 8)
1290 | (((GLuint
) (alpha
[i
] * 255.0F
)) );
1293 else if (format
== GL_ABGR_EXT
) {
1294 GLuint
*dst
= (GLuint
*) destination
;
1296 dst
[i
] = (((GLuint
) (alpha
[i
] * 255.0F
)) << 24)
1297 | (((GLuint
) (blue
[i
] * 255.0F
)) << 16)
1298 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
1299 | (((GLuint
) (red
[i
] * 255.0F
)) );
1303 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1304 if (format
== GL_RGBA
) {
1305 GLuint
*dst
= (GLuint
*) destination
;
1307 dst
[i
] = (((GLuint
) (red
[i
] * 255.0F
)) )
1308 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
1309 | (((GLuint
) (blue
[i
] * 255.0F
)) << 16)
1310 | (((GLuint
) (alpha
[i
] * 255.0F
)) << 24);
1313 else if (format
== GL_BGRA
) {
1314 GLuint
*dst
= (GLuint
*) destination
;
1316 dst
[i
] = (((GLuint
) (blue
[i
] * 255.0F
)) )
1317 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
1318 | (((GLuint
) (red
[i
] * 255.0F
)) << 16)
1319 | (((GLuint
) (alpha
[i
] * 255.0F
)) << 24);
1322 else if (format
== GL_ABGR_EXT
) {
1323 GLuint
*dst
= (GLuint
*) destination
;
1325 dst
[i
] = (((GLuint
) (alpha
[i
] * 255.0F
)) )
1326 | (((GLuint
) (blue
[i
] * 255.0F
)) << 8)
1327 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
1328 | (((GLuint
) (red
[i
] * 255.0F
)) << 24);
1332 case GL_UNSIGNED_INT_10_10_10_2
:
1333 if (format
== GL_RGBA
) {
1334 GLuint
*dst
= (GLuint
*) destination
;
1336 dst
[i
] = (((GLuint
) (red
[i
] * 1023.0F
)) << 22)
1337 | (((GLuint
) (green
[i
] * 1023.0F
)) << 12)
1338 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 2)
1339 | (((GLuint
) (alpha
[i
] * 3.0F
)) );
1342 else if (format
== GL_BGRA
) {
1343 GLuint
*dst
= (GLuint
*) destination
;
1345 dst
[i
] = (((GLuint
) (blue
[i
] * 1023.0F
)) << 22)
1346 | (((GLuint
) (green
[i
] * 1023.0F
)) << 12)
1347 | (((GLuint
) (red
[i
] * 1023.0F
)) << 2)
1348 | (((GLuint
) (alpha
[i
] * 3.0F
)) );
1351 else if (format
== GL_ABGR_EXT
) {
1352 GLuint
*dst
= (GLuint
*) destination
;
1354 dst
[i
] = (((GLuint
) (alpha
[i
] * 1023.0F
)) << 22)
1355 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 12)
1356 | (((GLuint
) (green
[i
] * 1023.0F
)) << 2)
1357 | (((GLuint
) (red
[i
] * 3.0F
)) );
1361 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1362 if (format
== GL_RGBA
) {
1363 GLuint
*dst
= (GLuint
*) destination
;
1365 dst
[i
] = (((GLuint
) (red
[i
] * 1023.0F
)) )
1366 | (((GLuint
) (green
[i
] * 1023.0F
)) << 10)
1367 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 20)
1368 | (((GLuint
) (alpha
[i
] * 3.0F
)) << 30);
1371 else if (format
== GL_BGRA
) {
1372 GLuint
*dst
= (GLuint
*) destination
;
1374 dst
[i
] = (((GLuint
) (blue
[i
] * 1023.0F
)) )
1375 | (((GLuint
) (green
[i
] * 1023.0F
)) << 10)
1376 | (((GLuint
) (red
[i
] * 1023.0F
)) << 20)
1377 | (((GLuint
) (alpha
[i
] * 3.0F
)) << 30);
1380 else if (format
== GL_ABGR_EXT
) {
1381 GLuint
*dst
= (GLuint
*) destination
;
1383 dst
[i
] = (((GLuint
) (alpha
[i
] * 1023.0F
)) )
1384 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 10)
1385 | (((GLuint
) (green
[i
] * 1023.0F
)) << 20)
1386 | (((GLuint
) (red
[i
] * 3.0F
)) << 30);
1391 gl_problem( ctx
, "bad type in gl_pack_rgba_span" );
1397 #define SWAP2BYTE(VALUE) \
1399 GLubyte *bytes = (GLubyte *) &(VALUE); \
1400 GLubyte tmp = bytes[0]; \
1401 bytes[0] = bytes[1]; \
1405 #define SWAP4BYTE(VALUE) \
1407 GLubyte *bytes = (GLubyte *) &(VALUE); \
1408 GLubyte tmp = bytes[0]; \
1409 bytes[0] = bytes[3]; \
1412 bytes[1] = bytes[2]; \
1418 extract_uint_indexes(GLuint n
, GLuint indexes
[],
1419 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
1420 const struct gl_pixelstore_attrib
*unpack
)
1422 assert(srcFormat
== GL_COLOR_INDEX
);
1424 ASSERT(srcType
== GL_BITMAP
||
1425 srcType
== GL_UNSIGNED_BYTE
||
1426 srcType
== GL_BYTE
||
1427 srcType
== GL_UNSIGNED_SHORT
||
1428 srcType
== GL_SHORT
||
1429 srcType
== GL_UNSIGNED_INT
||
1430 srcType
== GL_INT
||
1431 srcType
== GL_FLOAT
);
1436 GLubyte
*ubsrc
= (GLubyte
*) src
;
1437 if (unpack
->LsbFirst
) {
1438 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
1440 for (i
= 0; i
< n
; i
++) {
1441 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
1452 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
1454 for (i
= 0; i
< n
; i
++) {
1455 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
1467 case GL_UNSIGNED_BYTE
:
1470 const GLubyte
*s
= (const GLubyte
*) src
;
1471 for (i
= 0; i
< n
; i
++)
1478 const GLbyte
*s
= (const GLbyte
*) src
;
1479 for (i
= 0; i
< n
; i
++)
1483 case GL_UNSIGNED_SHORT
:
1486 const GLushort
*s
= (const GLushort
*) src
;
1487 if (unpack
->SwapBytes
) {
1488 for (i
= 0; i
< n
; i
++) {
1489 GLushort value
= s
[i
];
1495 for (i
= 0; i
< n
; i
++)
1503 const GLshort
*s
= (const GLshort
*) src
;
1504 if (unpack
->SwapBytes
) {
1505 for (i
= 0; i
< n
; i
++) {
1506 GLshort value
= s
[i
];
1512 for (i
= 0; i
< n
; i
++)
1517 case GL_UNSIGNED_INT
:
1520 const GLuint
*s
= (const GLuint
*) src
;
1521 if (unpack
->SwapBytes
) {
1522 for (i
= 0; i
< n
; i
++) {
1523 GLuint value
= s
[i
];
1529 for (i
= 0; i
< n
; i
++)
1537 const GLint
*s
= (const GLint
*) src
;
1538 if (unpack
->SwapBytes
) {
1539 for (i
= 0; i
< n
; i
++) {
1546 for (i
= 0; i
< n
; i
++)
1554 const GLfloat
*s
= (const GLfloat
*) src
;
1555 if (unpack
->SwapBytes
) {
1556 for (i
= 0; i
< n
; i
++) {
1557 GLfloat value
= s
[i
];
1559 indexes
[i
] = (GLuint
) value
;
1563 for (i
= 0; i
< n
; i
++)
1564 indexes
[i
] = (GLuint
) s
[i
];
1569 gl_problem(NULL
, "bad srcType in extract_uint_indexes");
1577 * This function extracts floating point RGBA values from arbitrary
1578 * image data. srcFormat and srcType are the format and type parameters
1579 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
1581 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
1582 * implements the "Conversion to floating point", "Conversion to RGB",
1583 * and "Final Expansion to RGBA" operations.
1585 * Args: n - number of pixels
1586 * rgba - output colors
1587 * srcFormat - format of incoming data
1588 * srcType - datatype of incoming data
1589 * src - source data pointer
1590 * swapBytes - perform byteswapping of incoming data?
1593 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
1594 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
1595 GLboolean swapBytes
)
1597 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
1599 GLint rComp
, bComp
, gComp
, aComp
;
1601 ASSERT(srcFormat
== GL_RED
||
1602 srcFormat
== GL_GREEN
||
1603 srcFormat
== GL_BLUE
||
1604 srcFormat
== GL_ALPHA
||
1605 srcFormat
== GL_LUMINANCE
||
1606 srcFormat
== GL_LUMINANCE_ALPHA
||
1607 srcFormat
== GL_INTENSITY
||
1608 srcFormat
== GL_RGB
||
1609 srcFormat
== GL_BGR
||
1610 srcFormat
== GL_RGBA
||
1611 srcFormat
== GL_BGRA
||
1612 srcFormat
== GL_ABGR_EXT
);
1614 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
1615 srcType
== GL_BYTE
||
1616 srcType
== GL_UNSIGNED_SHORT
||
1617 srcType
== GL_SHORT
||
1618 srcType
== GL_UNSIGNED_INT
||
1619 srcType
== GL_INT
||
1620 srcType
== GL_FLOAT
||
1621 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
1622 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
1623 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
1624 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
1625 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
1626 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
1627 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
1628 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
1629 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1630 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
1631 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
1632 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1634 rComp
= gComp
= bComp
= aComp
= -1;
1636 switch (srcFormat
) {
1639 greenIndex
= blueIndex
= alphaIndex
= -1;
1644 redIndex
= blueIndex
= alphaIndex
= -1;
1649 redIndex
= greenIndex
= alphaIndex
= -1;
1653 redIndex
= greenIndex
= blueIndex
= -1;
1658 redIndex
= greenIndex
= blueIndex
= 0;
1662 case GL_LUMINANCE_ALPHA
:
1663 redIndex
= greenIndex
= blueIndex
= 0;
1669 greenIndex
= blueIndex
= alphaIndex
= -1;
1720 gl_problem(NULL
, "bad srcFormat in extract float data");
1725 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
1726 if ((INDEX) < 0) { \
1728 for (i = 0; i < n; i++) { \
1729 rgba[i][CHANNEL] = DEFAULT; \
1732 else if (swapBytes) { \
1733 const TYPE *s = (const TYPE *) src; \
1735 for (i = 0; i < n; i++) { \
1736 TYPE value = s[INDEX]; \
1737 if (sizeof(TYPE) == 2) { \
1740 else if (sizeof(TYPE) == 4) { \
1743 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
1748 const TYPE *s = (const TYPE *) src; \
1750 for (i = 0; i < n; i++) { \
1751 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
1757 case GL_UNSIGNED_BYTE
:
1758 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1759 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1760 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1761 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1764 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1765 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1766 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1767 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
1769 case GL_UNSIGNED_SHORT
:
1770 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1771 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1772 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1773 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
1776 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1777 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1778 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1779 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
1781 case GL_UNSIGNED_INT
:
1782 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1783 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1784 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1785 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
1788 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1789 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1790 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1791 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
1794 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1795 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1796 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1797 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
1799 case GL_UNSIGNED_BYTE_3_3_2
:
1801 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
1803 for (i
= 0; i
< n
; i
++) {
1804 GLubyte p
= ubsrc
[i
];
1805 rgba
[i
][RCOMP
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
1806 rgba
[i
][GCOMP
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
1807 rgba
[i
][BCOMP
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
1808 rgba
[i
][ACOMP
] = 1.0F
;
1812 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1814 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
1816 for (i
= 0; i
< n
; i
++) {
1817 GLubyte p
= ubsrc
[i
];
1818 rgba
[i
][RCOMP
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
1819 rgba
[i
][GCOMP
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
1820 rgba
[i
][BCOMP
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
1821 rgba
[i
][ACOMP
] = 1.0F
;
1825 case GL_UNSIGNED_SHORT_5_6_5
:
1827 const GLushort
*ussrc
= (const GLushort
*) src
;
1829 for (i
= 0; i
< n
; i
++) {
1830 GLushort p
= ussrc
[i
];
1832 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1833 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1834 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1835 rgba
[i
][ACOMP
] = 1.0F
;
1839 const GLushort
*ussrc
= (const GLushort
*) src
;
1841 for (i
= 0; i
< n
; i
++) {
1842 GLushort p
= ussrc
[i
];
1843 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1844 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1845 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1846 rgba
[i
][ACOMP
] = 1.0F
;
1850 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1852 const GLushort
*ussrc
= (const GLushort
*) src
;
1854 for (i
= 0; i
< n
; i
++) {
1855 GLushort p
= ussrc
[i
];
1857 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1858 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1859 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1860 rgba
[i
][ACOMP
] = 1.0F
;
1864 const GLushort
*ussrc
= (const GLushort
*) src
;
1866 for (i
= 0; i
< n
; i
++) {
1867 GLushort p
= ussrc
[i
];
1868 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1869 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1870 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1871 rgba
[i
][ACOMP
] = 1.0F
;
1875 case GL_UNSIGNED_SHORT_4_4_4_4
:
1877 const GLushort
*ussrc
= (const GLushort
*) src
;
1879 for (i
= 0; i
< n
; i
++) {
1880 GLushort p
= ussrc
[i
];
1882 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1883 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1884 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1885 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1889 const GLushort
*ussrc
= (const GLushort
*) src
;
1891 for (i
= 0; i
< n
; i
++) {
1892 GLushort p
= ussrc
[i
];
1893 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1894 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1895 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1896 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1900 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1902 const GLushort
*ussrc
= (const GLushort
*) src
;
1904 for (i
= 0; i
< n
; i
++) {
1905 GLushort p
= ussrc
[i
];
1907 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1908 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1909 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1910 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1914 const GLushort
*ussrc
= (const GLushort
*) src
;
1916 for (i
= 0; i
< n
; i
++) {
1917 GLushort p
= ussrc
[i
];
1918 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1919 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1920 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1921 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1925 case GL_UNSIGNED_SHORT_5_5_5_1
:
1927 const GLushort
*ussrc
= (const GLushort
*) src
;
1929 for (i
= 0; i
< n
; i
++) {
1930 GLushort p
= ussrc
[i
];
1932 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1933 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
1934 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
1935 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
1939 const GLushort
*ussrc
= (const GLushort
*) src
;
1941 for (i
= 0; i
< n
; i
++) {
1942 GLushort p
= ussrc
[i
];
1943 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1944 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
1945 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
1946 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
1950 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1952 const GLushort
*ussrc
= (const GLushort
*) src
;
1954 for (i
= 0; i
< n
; i
++) {
1955 GLushort p
= ussrc
[i
];
1957 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1958 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
1959 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
1960 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
1964 const GLushort
*ussrc
= (const GLushort
*) src
;
1966 for (i
= 0; i
< n
; i
++) {
1967 GLushort p
= ussrc
[i
];
1968 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1969 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
1970 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
1971 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
1975 case GL_UNSIGNED_INT_8_8_8_8
:
1977 const GLuint
*uisrc
= (const GLuint
*) src
;
1979 for (i
= 0; i
< n
; i
++) {
1980 GLuint p
= uisrc
[i
];
1981 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
1982 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
1983 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
1984 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
1988 const GLuint
*uisrc
= (const GLuint
*) src
;
1990 for (i
= 0; i
< n
; i
++) {
1991 GLuint p
= uisrc
[i
];
1992 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
1993 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
1994 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
1995 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
1999 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2001 const GLuint
*uisrc
= (const GLuint
*) src
;
2003 for (i
= 0; i
< n
; i
++) {
2004 GLuint p
= uisrc
[i
];
2005 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2006 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2007 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2008 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2012 const GLuint
*uisrc
= (const GLuint
*) src
;
2014 for (i
= 0; i
< n
; i
++) {
2015 GLuint p
= uisrc
[i
];
2016 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2017 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2018 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2019 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2023 case GL_UNSIGNED_INT_10_10_10_2
:
2025 const GLuint
*uisrc
= (const GLuint
*) src
;
2027 for (i
= 0; i
< n
; i
++) {
2028 GLuint p
= uisrc
[i
];
2030 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2031 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2032 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2033 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2037 const GLuint
*uisrc
= (const GLuint
*) src
;
2039 for (i
= 0; i
< n
; i
++) {
2040 GLuint p
= uisrc
[i
];
2041 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2042 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2043 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2044 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2048 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2050 const GLuint
*uisrc
= (const GLuint
*) src
;
2052 for (i
= 0; i
< n
; i
++) {
2053 GLuint p
= uisrc
[i
];
2055 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2056 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2057 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2058 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2062 const GLuint
*uisrc
= (const GLuint
*) src
;
2064 for (i
= 0; i
< n
; i
++) {
2065 GLuint p
= uisrc
[i
];
2066 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2067 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2068 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2069 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2074 gl_problem(NULL
, "bad srcType in extract float data");
2082 * Unpack a row of color image data from a client buffer according to
2083 * the pixel unpacking parameters. Apply any enabled pixel transfer
2084 * ops (PixelMap, scale/bias) if the applyTransferOps flag is enabled.
2085 * Return GLubyte values in the specified dest image format.
2086 * This is (or will be) used by glDrawPixels and glTexImage?D().
2087 * Input: ctx - the context
2088 * n - number of pixels in the span
2089 * dstFormat - format of destination color array
2090 * dest - the destination color array
2091 * srcFormat - source image format
2092 * srcType - source image datatype
2093 * source - source image pointer
2094 * unpacking - pixel unpacking parameters
2095 * applyTransferOps - apply scale/bias/lookup-table ops?
2097 * XXX perhaps expand this to process whole images someday.
2100 _mesa_unpack_ubyte_color_span( const GLcontext
*ctx
,
2101 GLuint n
, GLenum dstFormat
, GLubyte dest
[],
2102 GLenum srcFormat
, GLenum srcType
,
2103 const GLvoid
*source
,
2104 const struct gl_pixelstore_attrib
*unpacking
,
2105 GLboolean applyTransferOps
)
2107 ASSERT(dstFormat
== GL_ALPHA
||
2108 dstFormat
== GL_LUMINANCE
||
2109 dstFormat
== GL_LUMINANCE_ALPHA
||
2110 dstFormat
== GL_INTENSITY
||
2111 dstFormat
== GL_RGB
||
2112 dstFormat
== GL_RGBA
||
2113 dstFormat
== GL_COLOR_INDEX
);
2115 ASSERT(srcFormat
== GL_RED
||
2116 srcFormat
== GL_GREEN
||
2117 srcFormat
== GL_BLUE
||
2118 srcFormat
== GL_ALPHA
||
2119 srcFormat
== GL_LUMINANCE
||
2120 srcFormat
== GL_LUMINANCE_ALPHA
||
2121 srcFormat
== GL_INTENSITY
||
2122 srcFormat
== GL_RGB
||
2123 srcFormat
== GL_BGR
||
2124 srcFormat
== GL_RGBA
||
2125 srcFormat
== GL_BGRA
||
2126 srcFormat
== GL_ABGR_EXT
||
2127 srcFormat
== GL_COLOR_INDEX
);
2129 ASSERT(srcType
== GL_BITMAP
||
2130 srcType
== GL_UNSIGNED_BYTE
||
2131 srcType
== GL_BYTE
||
2132 srcType
== GL_UNSIGNED_SHORT
||
2133 srcType
== GL_SHORT
||
2134 srcType
== GL_UNSIGNED_INT
||
2135 srcType
== GL_INT
||
2136 srcType
== GL_FLOAT
||
2137 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2138 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2139 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2140 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2141 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2142 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2143 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2144 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2145 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2146 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2147 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2148 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2150 /* this is intended for RGBA mode */
2151 assert(ctx
->Visual
->RGBAflag
);
2153 applyTransferOps
&= (ctx
->Pixel
.ScaleOrBiasRGBA
||
2154 ctx
->Pixel
.MapColorFlag
||
2155 ctx
->Pixel
.MapColorFlag
);
2157 /* Try simple cases first */
2158 if (!applyTransferOps
&& srcType
== GL_UNSIGNED_BYTE
) {
2159 if (dstFormat
== GL_RGBA
) {
2160 if (srcFormat
== GL_RGBA
) {
2161 MEMCPY( dest
, source
, n
* 4 * sizeof(GLubyte
) );
2164 else if (srcFormat
== GL_RGB
) {
2166 const GLubyte
*src
= (const GLubyte
*) source
;
2167 GLubyte
*dst
= dest
;
2168 for (i
= 0; i
< n
; i
++) {
2179 else if (dstFormat
== GL_RGB
) {
2180 if (srcFormat
== GL_RGB
) {
2181 MEMCPY( dest
, source
, n
* 3 * sizeof(GLubyte
) );
2184 else if (srcFormat
== GL_RGBA
) {
2186 const GLubyte
*src
= (const GLubyte
*) source
;
2187 GLubyte
*dst
= dest
;
2188 for (i
= 0; i
< n
; i
++) {
2198 else if (dstFormat
== srcFormat
) {
2199 GLint comps
= gl_components_in_format(srcFormat
);
2201 MEMCPY( dest
, source
, n
* comps
* sizeof(GLubyte
) );
2208 /* general solution */
2209 GLfloat rgba
[MAX_WIDTH
][4];
2210 GLint dstComponents
;
2211 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2212 GLint dstLuminanceIndex
, dstIntensityIndex
;
2214 dstComponents
= gl_components_in_format( dstFormat
);
2215 /* source & dest image formats should have been error checked by now */
2216 assert(dstComponents
> 0);
2219 * Extract image data and convert to RGBA floats
2221 assert(n
<= MAX_WIDTH
);
2222 if (srcFormat
== GL_COLOR_INDEX
) {
2223 GLuint indexes
[MAX_WIDTH
];
2224 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2227 /* shift and offset indexes */
2228 gl_shift_and_offset_ci(ctx
, n
, indexes
);
2230 if (dstFormat
== GL_COLOR_INDEX
) {
2231 if (applyTransferOps
) {
2232 if (ctx
->Pixel
.MapColorFlag
) {
2233 /* Apply lookup table */
2234 gl_map_ci(ctx
, n
, indexes
);
2237 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2242 /* convert to GLubyte and return */
2245 for (i
= 0; i
< n
; i
++) {
2246 dest
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2251 /* Convert indexes to RGBA */
2252 gl_map_ci_to_rgba_float(ctx
, n
, indexes
, rgba
);
2256 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2257 unpacking
->SwapBytes
);
2259 if (applyTransferOps
) {
2260 /* scale and bias colors */
2261 gl_scale_and_bias_rgba_float(ctx
, n
, rgba
);
2263 /* color table lookup */
2264 if (ctx
->Pixel
.MapColorFlag
) {
2265 gl_map_rgba_float(ctx
, n
, rgba
);
2272 * XXX This is where more color table lookups, convolution,
2273 * histograms, minmax, color matrix, etc would take place if
2275 * See figure 3.7 in the OpenGL 1.2 specification for more info.
2279 /* clamp to [0,1] */
2282 for (i
= 0; i
< n
; i
++) {
2283 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
2284 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
2285 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
2286 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
2290 /* Now determine which color channels we need to produce.
2291 * And determine the dest index (offset) within each color tuple.
2293 switch (dstFormat
) {
2296 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2297 dstLuminanceIndex
= dstIntensityIndex
= -1;
2300 dstLuminanceIndex
= 0;
2301 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2302 dstIntensityIndex
= -1;
2304 case GL_LUMINANCE_ALPHA
:
2305 dstLuminanceIndex
= 0;
2307 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2308 dstIntensityIndex
= -1;
2311 dstIntensityIndex
= 0;
2312 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2313 dstLuminanceIndex
= -1;
2319 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
2326 dstLuminanceIndex
= dstIntensityIndex
= -1;
2329 gl_problem(ctx
, "bad dstFormat in _mesa_unpack_ubyte_span()");
2334 /* Now return the GLubyte data in the requested dstFormat */
2336 if (dstRedIndex
>= 0) {
2337 GLubyte
*dst
= dest
;
2339 for (i
= 0; i
< n
; i
++) {
2340 dst
[dstRedIndex
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2341 dst
+= dstComponents
;
2345 if (dstGreenIndex
>= 0) {
2346 GLubyte
*dst
= dest
;
2348 for (i
= 0; i
< n
; i
++) {
2349 dst
[dstGreenIndex
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2350 dst
+= dstComponents
;
2354 if (dstBlueIndex
>= 0) {
2355 GLubyte
*dst
= dest
;
2357 for (i
= 0; i
< n
; i
++) {
2358 dst
[dstBlueIndex
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2359 dst
+= dstComponents
;
2363 if (dstAlphaIndex
>= 0) {
2364 GLubyte
*dst
= dest
;
2366 for (i
= 0; i
< n
; i
++) {
2367 dst
[dstAlphaIndex
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2368 dst
+= dstComponents
;
2372 if (dstIntensityIndex
>= 0) {
2373 GLubyte
*dst
= dest
;
2375 assert(dstIntensityIndex
== 0);
2376 assert(dstComponents
== 1);
2377 for (i
= 0; i
< n
; i
++) {
2378 /* Intensity comes from red channel */
2379 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2383 if (dstLuminanceIndex
>= 0) {
2384 GLubyte
*dst
= dest
;
2386 assert(dstLuminanceIndex
== 0);
2387 for (i
= 0; i
< n
; i
++) {
2388 /* Luminance comes from red channel */
2389 dst
[0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2390 dst
+= dstComponents
;
2399 * Unpack a row of color index data from a client buffer according to
2400 * the pixel unpacking parameters. Apply pixel transfer ops if enabled
2401 * and applyTransferOps is true.
2402 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
2404 * Args: ctx - the context
2405 * n - number of pixels
2406 * dstType - destination datatype
2407 * dest - destination array
2408 * srcType - source pixel type
2409 * source - source data pointer
2410 * unpacking - pixel unpacking parameters
2411 * applyTransferOps - apply offset/bias/lookup ops?
2414 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
2415 GLenum dstType
, GLvoid
*dest
,
2416 GLenum srcType
, const GLvoid
*source
,
2417 const struct gl_pixelstore_attrib
*unpacking
,
2418 GLboolean applyTransferOps
)
2420 ASSERT(srcType
== GL_BITMAP
||
2421 srcType
== GL_UNSIGNED_BYTE
||
2422 srcType
== GL_BYTE
||
2423 srcType
== GL_UNSIGNED_SHORT
||
2424 srcType
== GL_SHORT
||
2425 srcType
== GL_UNSIGNED_INT
||
2426 srcType
== GL_INT
||
2427 srcType
== GL_FLOAT
);
2429 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
2430 dstType
== GL_UNSIGNED_SHORT
||
2431 dstType
== GL_UNSIGNED_INT
);
2433 applyTransferOps
&= (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
|| ctx
->Pixel
.MapColorFlag
);
2436 * Try simple cases first
2438 if (!applyTransferOps
&& srcType
== GL_UNSIGNED_BYTE
2439 && dstType
== GL_UNSIGNED_BYTE
) {
2440 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
2442 else if (!applyTransferOps
&& srcType
== GL_UNSIGNED_INT
2443 && dstType
== GL_UNSIGNED_INT
&& !unpacking
->SwapBytes
) {
2444 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
2450 GLuint indexes
[MAX_WIDTH
];
2451 assert(n
<= MAX_WIDTH
);
2453 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
2456 if (applyTransferOps
) {
2457 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2458 /* shift and offset indexes */
2459 gl_shift_and_offset_ci(ctx
, n
, indexes
);
2462 if (ctx
->Pixel
.MapColorFlag
) {
2463 /* Apply lookup table */
2464 gl_map_ci(ctx
, n
, indexes
);
2468 /* convert to dest type */
2470 case GL_UNSIGNED_BYTE
:
2472 GLubyte
*dst
= (GLubyte
*) dest
;
2474 for (i
= 0; i
< n
; i
++) {
2475 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2479 case GL_UNSIGNED_SHORT
:
2481 GLuint
*dst
= (GLuint
*) dest
;
2483 for (i
= 0; i
< n
; i
++) {
2484 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
2488 case GL_UNSIGNED_INT
:
2489 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
2492 gl_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
2499 * Unpack a row of stencil data from a client buffer according to
2500 * the pixel unpacking parameters. Apply pixel transfer ops if enabled
2501 * and applyTransferOps is true.
2502 * This is (or will be) used by glDrawPixels
2504 * Args: ctx - the context
2505 * n - number of pixels
2506 * dstType - destination datatype
2507 * dest - destination array
2508 * srcType - source pixel type
2509 * source - source data pointer
2510 * unpacking - pixel unpacking parameters
2511 * applyTransferOps - apply offset/bias/lookup ops?
2514 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
2515 GLenum dstType
, GLvoid
*dest
,
2516 GLenum srcType
, const GLvoid
*source
,
2517 const struct gl_pixelstore_attrib
*unpacking
,
2518 GLboolean applyTransferOps
)
2520 ASSERT(srcType
== GL_BITMAP
||
2521 srcType
== GL_UNSIGNED_BYTE
||
2522 srcType
== GL_BYTE
||
2523 srcType
== GL_UNSIGNED_SHORT
||
2524 srcType
== GL_SHORT
||
2525 srcType
== GL_UNSIGNED_INT
||
2526 srcType
== GL_INT
||
2527 srcType
== GL_FLOAT
);
2529 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
2530 dstType
== GL_UNSIGNED_SHORT
||
2531 dstType
== GL_UNSIGNED_INT
);
2533 applyTransferOps
&= (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
|| ctx
->Pixel
.MapColorFlag
);
2536 * Try simple cases first
2538 if (!applyTransferOps
&& srcType
== GL_UNSIGNED_BYTE
2539 && dstType
== GL_UNSIGNED_BYTE
) {
2540 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
2542 else if (!applyTransferOps
&& srcType
== GL_UNSIGNED_INT
2543 && dstType
== GL_UNSIGNED_INT
&& !unpacking
->SwapBytes
) {
2544 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
2550 GLuint indexes
[MAX_WIDTH
];
2551 assert(n
<= MAX_WIDTH
);
2553 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
2556 if (applyTransferOps
) {
2557 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2558 /* shift and offset indexes */
2559 gl_shift_and_offset_ci(ctx
, n
, indexes
);
2562 if (ctx
->Pixel
.MapStencilFlag
) {
2563 /* Apply stencil lookup table */
2564 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
2567 indexes
[i
] = ctx
->Pixel
.MapStoS
[ indexes
[i
] & mask
];
2572 /* convert to dest type */
2574 case GL_UNSIGNED_BYTE
:
2576 GLubyte
*dst
= (GLubyte
*) dest
;
2578 for (i
= 0; i
< n
; i
++) {
2579 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2583 case GL_UNSIGNED_SHORT
:
2585 GLuint
*dst
= (GLuint
*) dest
;
2587 for (i
= 0; i
< n
; i
++) {
2588 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
2592 case GL_UNSIGNED_INT
:
2593 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
2596 gl_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
2604 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
, GLdepth
*dest
,
2605 GLenum srcType
, const GLvoid
*source
,
2606 const struct gl_pixelstore_attrib
*unpacking
,
2607 GLboolean applyTransferOps
)
2609 GLfloat
*depth
= MALLOC(n
* sizeof(GLfloat
));
2617 const GLubyte
*src
= (const GLubyte
*) source
;
2618 for (i
= 0; i
< n
; i
++) {
2619 depth
[i
] = BYTE_TO_FLOAT(src
[i
]);
2623 case GL_UNSIGNED_BYTE
:
2626 const GLubyte
*src
= (const GLubyte
*) source
;
2627 for (i
= 0; i
< n
; i
++) {
2628 depth
[i
] = UBYTE_TO_FLOAT(src
[i
]);
2635 const GLshort
*src
= (const GLshort
*) source
;
2636 for (i
= 0; i
< n
; i
++) {
2637 depth
[i
] = SHORT_TO_FLOAT(src
[i
]);
2641 case GL_UNSIGNED_SHORT
:
2644 const GLushort
*src
= (const GLushort
*) source
;
2645 for (i
= 0; i
< n
; i
++) {
2646 depth
[i
] = USHORT_TO_FLOAT(src
[i
]);
2653 const GLint
*src
= (const GLint
*) source
;
2654 for (i
= 0; i
< n
; i
++) {
2655 depth
[i
] = INT_TO_FLOAT(src
[i
]);
2659 case GL_UNSIGNED_INT
:
2662 const GLuint
*src
= (const GLuint
*) source
;
2663 for (i
= 0; i
< n
; i
++) {
2664 depth
[i
] = UINT_TO_FLOAT(src
[i
]);
2669 MEMCPY(depth
, source
, n
* sizeof(GLfloat
));
2672 gl_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
2677 /* apply depth scale and bias */
2678 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
2680 for (i
= 0; i
< n
; i
++) {
2681 depth
[i
] = depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
2685 /* clamp depth values to [0,1] and convert from floats to integers */
2687 const GLfloat zs
= ctx
->Visual
->DepthMaxF
;
2689 for (i
= 0; i
< n
; i
++) {
2690 dest
[i
] = (GLdepth
) (CLAMP(depth
[i
], 0.0F
, 1.0F
) * zs
);
2700 * Unpack image data. Apply byteswapping, byte flipping (bitmap).
2701 * Return all image data in a contiguous block.
2704 _mesa_unpack_image( GLsizei width
, GLsizei height
, GLsizei depth
,
2705 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2706 const struct gl_pixelstore_attrib
*unpack
)
2708 GLint bytesPerRow
, compsPerRow
;
2709 GLboolean flipBytes
, swap2
, swap4
;
2712 return NULL
; /* not necessarily an error */
2714 if (width
<= 0 || height
<= 0 || depth
<= 0)
2715 return NULL
; /* generate error later */
2717 if (format
== GL_BITMAP
) {
2718 bytesPerRow
= (width
+ 7) >> 3;
2719 flipBytes
= !unpack
->LsbFirst
;
2720 swap2
= swap4
= GL_FALSE
;
2724 const GLint bytesPerPixel
= gl_bytes_per_pixel(format
, type
);
2725 const GLint components
= gl_components_in_format(format
);
2727 if (bytesPerPixel
<= 0 || components
<= 0)
2728 return NULL
; /* bad format or type. generate error later */
2729 bytesPerRow
= bytesPerPixel
* width
;
2730 bytesPerComp
= bytesPerPixel
/ components
;
2731 flipBytes
= GL_FALSE
;
2732 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
2733 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
2734 compsPerRow
= components
* width
;
2735 assert(compsPerRow
>= width
);
2739 GLubyte
*destBuffer
= MALLOC(bytesPerRow
* height
* depth
);
2743 return NULL
; /* generate GL_OUT_OF_MEMORY later */
2746 for (img
= 0; img
< depth
; img
++) {
2747 for (row
= 0; row
< height
; row
++) {
2748 const GLvoid
*src
= gl_pixel_addr_in_image(unpack
, pixels
,
2749 width
, height
, format
, type
, img
, row
, 0);
2750 MEMCPY(dst
, src
, bytesPerRow
);
2751 /* byte flipping/swapping */
2753 gl_flip_bytes((GLubyte
*) dst
, bytesPerRow
);
2756 gl_swap2((GLushort
*) dst
, compsPerRow
);
2759 gl_swap4((GLuint
*) dst
, compsPerRow
);
2770 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
2771 * order with row alignment = 1 byte.
2774 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
2775 const struct gl_pixelstore_attrib
*packing
)
2777 GLint bytes
, row
, width_in_bytes
;
2778 GLubyte
*buffer
, *dst
;
2783 /* Alloc dest storage */
2784 bytes
= ((width
+ 7) / 8 * height
);
2785 buffer
= (GLubyte
*) MALLOC( bytes
);
2790 width_in_bytes
= CEILING( width
, 8 );
2792 for (row
= 0; row
< height
; row
++) {
2793 GLubyte
*src
= gl_pixel_addr_in_image( packing
, pixels
, width
, height
,
2794 GL_COLOR_INDEX
, GL_BITMAP
,
2801 if (packing
->SkipPixels
== 0) {
2802 MEMCPY( dst
, src
, width_in_bytes
);
2803 if (packing
->LsbFirst
) {
2804 gl_flip_bytes( dst
, width_in_bytes
);
2808 /* handling SkipPixels is a bit tricky (no pun intended!) */
2810 if (packing
->LsbFirst
) {
2811 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
2812 GLubyte dstMask
= 128;
2816 for (i
= 0; i
< width
; i
++) {
2820 if (srcMask
== 128) {
2825 srcMask
= srcMask
<< 1;
2833 dstMask
= dstMask
>> 1;
2838 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
2839 GLubyte dstMask
= 128;
2843 for (i
= 0; i
< width
; i
++) {
2852 srcMask
= srcMask
>> 1;
2860 dstMask
= dstMask
>> 1;
2865 dst
+= width_in_bytes
;
2876 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
2877 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
2879 GLint row
, width_in_bytes
;
2885 width_in_bytes
= CEILING( width
, 8 );
2887 for (row
= 0; row
< height
; row
++) {
2888 GLubyte
*dst
= gl_pixel_addr_in_image( packing
, dest
, width
, height
,
2889 GL_COLOR_INDEX
, GL_BITMAP
,
2894 if (packing
->SkipPixels
== 0) {
2895 MEMCPY( dst
, src
, width_in_bytes
);
2896 if (packing
->LsbFirst
) {
2897 gl_flip_bytes( dst
, width_in_bytes
);
2901 /* handling SkipPixels is a bit tricky (no pun intended!) */
2903 if (packing
->LsbFirst
) {
2904 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
2905 GLubyte dstMask
= 128;
2906 const GLubyte
*s
= src
;
2909 for (i
= 0; i
< width
; i
++) {
2913 if (srcMask
== 128) {
2918 srcMask
= srcMask
<< 1;
2926 dstMask
= dstMask
>> 1;
2931 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
2932 GLubyte dstMask
= 128;
2933 const GLubyte
*s
= src
;
2936 for (i
= 0; i
< width
; i
++) {
2945 srcMask
= srcMask
>> 1;
2953 dstMask
= dstMask
>> 1;
2958 src
+= width_in_bytes
;