1 /* $Id: image.c,v 1.22 2000/03/21 01:03:40 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.
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
:
228 case GL_LUMINANCE_ALPHA
:
247 * Return bytes per pixel for given format and type
248 * Return -1 if bad format or type.
250 GLint
_mesa_bytes_per_pixel( GLenum format
, GLenum type
)
252 GLint comps
= _mesa_components_in_format( format
);
258 return 0; /* special case */
260 case GL_UNSIGNED_BYTE
:
261 return comps
* sizeof(GLubyte
);
263 case GL_UNSIGNED_SHORT
:
264 return comps
* sizeof(GLshort
);
266 case GL_UNSIGNED_INT
:
267 return comps
* sizeof(GLint
);
269 return comps
* sizeof(GLfloat
);
270 case GL_UNSIGNED_BYTE_3_3_2
:
271 case GL_UNSIGNED_BYTE_2_3_3_REV
:
272 if (format
== GL_RGB
|| format
== GL_BGR
)
273 return sizeof(GLubyte
);
275 return -1; /* error */
276 case GL_UNSIGNED_SHORT_5_6_5
:
277 case GL_UNSIGNED_SHORT_5_6_5_REV
:
278 if (format
== GL_RGB
|| format
== GL_BGR
)
279 return sizeof(GLshort
);
281 return -1; /* error */
282 case GL_UNSIGNED_SHORT_4_4_4_4
:
283 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
284 case GL_UNSIGNED_SHORT_5_5_5_1
:
285 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
286 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
287 return sizeof(GLushort
);
290 case GL_UNSIGNED_INT_8_8_8_8
:
291 case GL_UNSIGNED_INT_8_8_8_8_REV
:
292 case GL_UNSIGNED_INT_10_10_10_2
:
293 case GL_UNSIGNED_INT_2_10_10_10_REV
:
294 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
295 return sizeof(GLuint
);
305 * Test if the given pixel format and type are legal.
306 * Return GL_TRUE for legal, GL_FALSE for illegal.
309 _mesa_is_legal_format_and_type( GLenum format
, GLenum type
)
313 case GL_STENCIL_INDEX
:
317 case GL_UNSIGNED_BYTE
:
319 case GL_UNSIGNED_SHORT
:
321 case GL_UNSIGNED_INT
:
332 case GL_LUMINANCE_ALPHA
:
333 case GL_DEPTH_COMPONENT
:
337 case GL_UNSIGNED_BYTE
:
339 case GL_UNSIGNED_SHORT
:
341 case GL_UNSIGNED_INT
:
350 case GL_UNSIGNED_BYTE
:
352 case GL_UNSIGNED_SHORT
:
354 case GL_UNSIGNED_INT
:
356 case GL_UNSIGNED_BYTE_3_3_2
:
357 case GL_UNSIGNED_BYTE_2_3_3_REV
:
358 case GL_UNSIGNED_SHORT_5_6_5
:
359 case GL_UNSIGNED_SHORT_5_6_5_REV
:
369 case GL_UNSIGNED_BYTE
:
371 case GL_UNSIGNED_SHORT
:
373 case GL_UNSIGNED_INT
:
375 case GL_UNSIGNED_SHORT_4_4_4_4
:
376 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
377 case GL_UNSIGNED_SHORT_5_5_5_1
:
378 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
379 case GL_UNSIGNED_INT_8_8_8_8
:
380 case GL_UNSIGNED_INT_8_8_8_8_REV
:
381 case GL_UNSIGNED_INT_10_10_10_2
:
382 case GL_UNSIGNED_INT_2_10_10_10_REV
:
396 * Return the address of a pixel in an image (actually a volume).
397 * Pixel unpacking/packing parameters are observed according to 'packing'.
398 * Input: image - start of image data
399 * width, height - size of image
400 * format - image format
401 * type - pixel component type
402 * packing - the pixelstore attributes
403 * img - which image in the volume (0 for 1D or 2D images)
404 * row, column - location of pixel in the image
405 * Return: address of pixel at (image,row,column) in image or NULL if error.
408 _mesa_image_address( const struct gl_pixelstore_attrib
*packing
,
409 const GLvoid
*image
, GLsizei width
,
410 GLsizei height
, GLenum format
, GLenum type
,
411 GLint img
, GLint row
, GLint column
)
413 GLint alignment
; /* 1, 2 or 4 */
414 GLint pixels_per_row
;
415 GLint rows_per_image
;
418 GLint skipimages
; /* for 3-D volume images */
421 alignment
= packing
->Alignment
;
422 if (packing
->RowLength
> 0) {
423 pixels_per_row
= packing
->RowLength
;
426 pixels_per_row
= width
;
428 if (packing
->ImageHeight
> 0) {
429 rows_per_image
= packing
->ImageHeight
;
432 rows_per_image
= height
;
434 skiprows
= packing
->SkipRows
;
435 skippixels
= packing
->SkipPixels
;
436 skipimages
= packing
->SkipImages
;
438 if (type
==GL_BITMAP
) {
440 GLint comp_per_pixel
; /* components per pixel */
441 GLint bytes_per_comp
; /* bytes per component */
443 GLint bytes_per_image
;
445 /* Compute bytes per component */
446 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
447 if (bytes_per_comp
<0) {
451 /* Compute number of components per pixel */
452 comp_per_pixel
= _mesa_components_in_format( format
);
453 if (comp_per_pixel
<0 && type
!= GL_BITMAP
) {
457 bytes_per_row
= alignment
458 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
460 bytes_per_image
= bytes_per_row
* rows_per_image
;
462 pixel_addr
= (GLubyte
*) image
463 + (skipimages
+ img
) * bytes_per_image
464 + (skiprows
+ row
) * bytes_per_row
465 + (skippixels
+ column
) / 8;
468 /* Non-BITMAP data */
469 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
471 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
473 /* The pixel type and format should have been error checked earlier */
474 assert(bytes_per_pixel
> 0);
476 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
477 remainder
= bytes_per_row
% alignment
;
479 bytes_per_row
+= (alignment
- remainder
);
481 ASSERT(bytes_per_row
% alignment
== 0);
483 bytes_per_image
= bytes_per_row
* rows_per_image
;
485 /* compute final pixel address */
486 pixel_addr
= (GLubyte
*) image
487 + (skipimages
+ img
) * bytes_per_image
488 + (skiprows
+ row
) * bytes_per_row
489 + (skippixels
+ column
) * bytes_per_pixel
;
492 return (GLvoid
*) pixel_addr
;
498 * Compute the stride between image rows (in bytes) for the given
499 * pixel packing parameters and image width, format and type.
502 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
503 GLint width
, GLenum format
, GLenum type
)
506 if (type
== GL_BITMAP
) {
508 if (packing
->RowLength
== 0) {
509 GLint bytes
= (width
+ 7) / 8;
513 GLint bytes
= (packing
->RowLength
+ 7) / 8;
518 /* Non-BITMAP data */
519 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
520 if (bytesPerPixel
<= 0)
521 return -1; /* error */
522 if (packing
->RowLength
== 0) {
523 GLint bytes
= bytesPerPixel
* width
;
527 GLint bytes
= bytesPerPixel
* packing
->RowLength
;
536 * Unpack a 32x32 pixel polygon stipple from user memory using the
537 * current pixel unpack settings.
540 _mesa_unpack_polygon_stipple( const GLubyte
*pattern
, GLuint dest
[32],
541 const struct gl_pixelstore_attrib
*unpacking
)
543 GLubyte
*ptrn
= (GLubyte
*) _mesa_unpack_bitmap( 32, 32, pattern
, unpacking
);
545 /* Convert pattern from GLubytes to GLuints and handle big/little
550 for (i
= 0; i
< 32; i
++) {
551 dest
[i
] = (p
[0] << 24)
564 * Pack polygon stipple into user memory given current pixel packing
568 _mesa_pack_polygon_stipple( const GLuint pattern
[32], GLubyte
*dest
,
569 const struct gl_pixelstore_attrib
*packing
)
571 /* Convert pattern from GLuints to GLubytes to handle big/little
572 * endian differences.
576 for (i
= 0; i
< 32; i
++) {
577 ptrn
[i
* 4 + 0] = (GLubyte
) ((pattern
[i
] >> 24) & 0xff);
578 ptrn
[i
* 4 + 1] = (GLubyte
) ((pattern
[i
] >> 16) & 0xff);
579 ptrn
[i
* 4 + 2] = (GLubyte
) ((pattern
[i
] >> 8 ) & 0xff);
580 ptrn
[i
* 4 + 3] = (GLubyte
) ((pattern
[i
] ) & 0xff);
583 _mesa_pack_bitmap(32, 32, ptrn
, dest
, packing
);
589 * Pack the given RGBA span into client memory at 'dest' address
590 * in the given pixel format and type.
591 * Optionally apply the enabled pixel transfer ops.
592 * Pack into memory using the given packing params struct.
593 * This is used by glReadPixels and glGetTexImage?D()
594 * Input: ctx - the context
595 * n - number of pixels in the span
597 * format - dest packing format
598 * type - dest packing datatype
599 * destination - destination packing address
600 * packing - pixel packing parameters
601 * applyTransferOps - apply scale/bias/lookup-table ops?
604 _mesa_pack_rgba_span( const GLcontext
*ctx
,
605 GLuint n
, CONST GLubyte rgba
[][4],
606 GLenum format
, GLenum type
, GLvoid
*destination
,
607 const struct gl_pixelstore_attrib
*packing
,
608 GLboolean applyTransferOps
)
610 applyTransferOps
&= (ctx
->Pixel
.ScaleOrBiasRGBA
|| ctx
->Pixel
.MapColorFlag
);
612 /* Test for optimized case first */
613 if (!applyTransferOps
&& format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
) {
614 /* common simple case */
615 MEMCPY( destination
, rgba
, n
* 4 * sizeof(GLubyte
) );
617 else if (!applyTransferOps
&& format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
) {
618 /* common simple case */
620 GLubyte
*dest
= (GLubyte
*) destination
;
621 for (i
= 0; i
< n
; i
++) {
622 dest
[0] = rgba
[i
][RCOMP
];
623 dest
[1] = rgba
[i
][GCOMP
];
624 dest
[2] = rgba
[i
][BCOMP
];
629 /* general solution */
630 GLfloat red
[MAX_WIDTH
], green
[MAX_WIDTH
], blue
[MAX_WIDTH
];
631 GLfloat alpha
[MAX_WIDTH
], luminance
[MAX_WIDTH
];
632 const GLfloat rscale
= 1.0F
/ 255.0F
;
633 const GLfloat gscale
= 1.0F
/ 255.0F
;
634 const GLfloat bscale
= 1.0F
/ 255.0F
;
635 const GLfloat ascale
= 1.0F
/ 255.0F
;
636 const GLint comps
= _mesa_components_in_format(format
);
639 assert(n
<= MAX_WIDTH
);
641 /* convert color components to floating point */
643 red
[i
] = rgba
[i
][RCOMP
] * rscale
;
644 green
[i
] = rgba
[i
][GCOMP
] * gscale
;
645 blue
[i
] = rgba
[i
][BCOMP
] * bscale
;
646 alpha
[i
] = rgba
[i
][ACOMP
] * ascale
;
650 * Apply scale, bias and lookup-tables if enabled.
652 if (applyTransferOps
) {
653 if (ctx
->Pixel
.ScaleOrBiasRGBA
) {
654 gl_scale_and_bias_color( ctx
, n
, red
, green
, blue
, alpha
);
656 if (ctx
->Pixel
.MapColorFlag
) {
657 gl_map_color( ctx
, n
, red
, green
, blue
, alpha
);
661 if (format
==GL_LUMINANCE
|| format
==GL_LUMINANCE_ALPHA
) {
663 GLfloat sum
= red
[i
] + green
[i
] + blue
[i
];
664 luminance
[i
] = CLAMP( sum
, 0.0F
, 1.0F
);
669 * Pack/store the pixels. Ugh! Lots of cases!!!
672 case GL_UNSIGNED_BYTE
:
674 GLubyte
*dst
= (GLubyte
*) destination
;
678 dst
[i
] = FLOAT_TO_UBYTE(red
[i
]);
682 dst
[i
] = FLOAT_TO_UBYTE(green
[i
]);
686 dst
[i
] = FLOAT_TO_UBYTE(blue
[i
]);
690 dst
[i
] = FLOAT_TO_UBYTE(alpha
[i
]);
694 dst
[i
] = FLOAT_TO_UBYTE(luminance
[i
]);
696 case GL_LUMINANCE_ALPHA
:
698 dst
[i
*2+0] = FLOAT_TO_UBYTE(luminance
[i
]);
699 dst
[i
*2+1] = FLOAT_TO_UBYTE(alpha
[i
]);
704 dst
[i
*3+0] = FLOAT_TO_UBYTE(red
[i
]);
705 dst
[i
*3+1] = FLOAT_TO_UBYTE(green
[i
]);
706 dst
[i
*3+2] = FLOAT_TO_UBYTE(blue
[i
]);
711 dst
[i
*4+0] = FLOAT_TO_UBYTE(red
[i
]);
712 dst
[i
*4+1] = FLOAT_TO_UBYTE(green
[i
]);
713 dst
[i
*4+2] = FLOAT_TO_UBYTE(blue
[i
]);
714 dst
[i
*4+3] = FLOAT_TO_UBYTE(alpha
[i
]);
719 dst
[i
*3+0] = FLOAT_TO_UBYTE(blue
[i
]);
720 dst
[i
*3+1] = FLOAT_TO_UBYTE(green
[i
]);
721 dst
[i
*3+2] = FLOAT_TO_UBYTE(red
[i
]);
726 dst
[i
*4+0] = FLOAT_TO_UBYTE(blue
[i
]);
727 dst
[i
*4+1] = FLOAT_TO_UBYTE(green
[i
]);
728 dst
[i
*4+2] = FLOAT_TO_UBYTE(red
[i
]);
729 dst
[i
*4+3] = FLOAT_TO_UBYTE(alpha
[i
]);
734 dst
[i
*4+0] = FLOAT_TO_UBYTE(alpha
[i
]);
735 dst
[i
*4+1] = FLOAT_TO_UBYTE(blue
[i
]);
736 dst
[i
*4+2] = FLOAT_TO_UBYTE(green
[i
]);
737 dst
[i
*4+3] = FLOAT_TO_UBYTE(red
[i
]);
741 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
747 GLbyte
*dst
= (GLbyte
*) destination
;
751 dst
[i
] = FLOAT_TO_BYTE(red
[i
]);
755 dst
[i
] = FLOAT_TO_BYTE(green
[i
]);
759 dst
[i
] = FLOAT_TO_BYTE(blue
[i
]);
763 dst
[i
] = FLOAT_TO_BYTE(alpha
[i
]);
767 dst
[i
] = FLOAT_TO_BYTE(luminance
[i
]);
769 case GL_LUMINANCE_ALPHA
:
771 dst
[i
*2+0] = FLOAT_TO_BYTE(luminance
[i
]);
772 dst
[i
*2+1] = FLOAT_TO_BYTE(alpha
[i
]);
777 dst
[i
*3+0] = FLOAT_TO_BYTE(red
[i
]);
778 dst
[i
*3+1] = FLOAT_TO_BYTE(green
[i
]);
779 dst
[i
*3+2] = FLOAT_TO_BYTE(blue
[i
]);
784 dst
[i
*4+0] = FLOAT_TO_BYTE(red
[i
]);
785 dst
[i
*4+1] = FLOAT_TO_BYTE(green
[i
]);
786 dst
[i
*4+2] = FLOAT_TO_BYTE(blue
[i
]);
787 dst
[i
*4+3] = FLOAT_TO_BYTE(alpha
[i
]);
792 dst
[i
*3+0] = FLOAT_TO_BYTE(blue
[i
]);
793 dst
[i
*3+1] = FLOAT_TO_BYTE(green
[i
]);
794 dst
[i
*3+2] = FLOAT_TO_BYTE(red
[i
]);
799 dst
[i
*4+0] = FLOAT_TO_BYTE(blue
[i
]);
800 dst
[i
*4+1] = FLOAT_TO_BYTE(green
[i
]);
801 dst
[i
*4+2] = FLOAT_TO_BYTE(red
[i
]);
802 dst
[i
*4+3] = FLOAT_TO_BYTE(alpha
[i
]);
806 dst
[i
*4+0] = FLOAT_TO_BYTE(alpha
[i
]);
807 dst
[i
*4+1] = FLOAT_TO_BYTE(blue
[i
]);
808 dst
[i
*4+2] = FLOAT_TO_BYTE(green
[i
]);
809 dst
[i
*4+3] = FLOAT_TO_BYTE(red
[i
]);
813 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
817 case GL_UNSIGNED_SHORT
:
819 GLushort
*dst
= (GLushort
*) destination
;
823 dst
[i
] = FLOAT_TO_USHORT(red
[i
]);
827 dst
[i
] = FLOAT_TO_USHORT(green
[i
]);
831 dst
[i
] = FLOAT_TO_USHORT(blue
[i
]);
835 dst
[i
] = FLOAT_TO_USHORT(alpha
[i
]);
839 dst
[i
] = FLOAT_TO_USHORT(luminance
[i
]);
841 case GL_LUMINANCE_ALPHA
:
843 dst
[i
*2+0] = FLOAT_TO_USHORT(luminance
[i
]);
844 dst
[i
*2+1] = FLOAT_TO_USHORT(alpha
[i
]);
849 dst
[i
*3+0] = FLOAT_TO_USHORT(red
[i
]);
850 dst
[i
*3+1] = FLOAT_TO_USHORT(green
[i
]);
851 dst
[i
*3+2] = FLOAT_TO_USHORT(blue
[i
]);
856 dst
[i
*4+0] = FLOAT_TO_USHORT(red
[i
]);
857 dst
[i
*4+1] = FLOAT_TO_USHORT(green
[i
]);
858 dst
[i
*4+2] = FLOAT_TO_USHORT(blue
[i
]);
859 dst
[i
*4+3] = FLOAT_TO_USHORT(alpha
[i
]);
864 dst
[i
*3+0] = FLOAT_TO_USHORT(blue
[i
]);
865 dst
[i
*3+1] = FLOAT_TO_USHORT(green
[i
]);
866 dst
[i
*3+2] = FLOAT_TO_USHORT(red
[i
]);
871 dst
[i
*4+0] = FLOAT_TO_USHORT(blue
[i
]);
872 dst
[i
*4+1] = FLOAT_TO_USHORT(green
[i
]);
873 dst
[i
*4+2] = FLOAT_TO_USHORT(red
[i
]);
874 dst
[i
*4+3] = FLOAT_TO_USHORT(alpha
[i
]);
879 dst
[i
*4+0] = FLOAT_TO_USHORT(alpha
[i
]);
880 dst
[i
*4+1] = FLOAT_TO_USHORT(blue
[i
]);
881 dst
[i
*4+2] = FLOAT_TO_USHORT(green
[i
]);
882 dst
[i
*4+3] = FLOAT_TO_USHORT(red
[i
]);
886 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
888 if (packing
->SwapBytes
) {
889 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
895 GLshort
*dst
= (GLshort
*) destination
;
899 dst
[i
] = FLOAT_TO_SHORT(red
[i
]);
903 dst
[i
] = FLOAT_TO_SHORT(green
[i
]);
907 dst
[i
] = FLOAT_TO_SHORT(blue
[i
]);
911 dst
[i
] = FLOAT_TO_SHORT(alpha
[i
]);
915 dst
[i
] = FLOAT_TO_SHORT(luminance
[i
]);
917 case GL_LUMINANCE_ALPHA
:
919 dst
[i
*2+0] = FLOAT_TO_SHORT(luminance
[i
]);
920 dst
[i
*2+1] = FLOAT_TO_SHORT(alpha
[i
]);
925 dst
[i
*3+0] = FLOAT_TO_SHORT(red
[i
]);
926 dst
[i
*3+1] = FLOAT_TO_SHORT(green
[i
]);
927 dst
[i
*3+2] = FLOAT_TO_SHORT(blue
[i
]);
932 dst
[i
*4+0] = FLOAT_TO_SHORT(red
[i
]);
933 dst
[i
*4+1] = FLOAT_TO_SHORT(green
[i
]);
934 dst
[i
*4+2] = FLOAT_TO_SHORT(blue
[i
]);
935 dst
[i
*4+3] = FLOAT_TO_SHORT(alpha
[i
]);
940 dst
[i
*3+0] = FLOAT_TO_SHORT(blue
[i
]);
941 dst
[i
*3+1] = FLOAT_TO_SHORT(green
[i
]);
942 dst
[i
*3+2] = FLOAT_TO_SHORT(red
[i
]);
947 dst
[i
*4+0] = FLOAT_TO_SHORT(blue
[i
]);
948 dst
[i
*4+1] = FLOAT_TO_SHORT(green
[i
]);
949 dst
[i
*4+2] = FLOAT_TO_SHORT(red
[i
]);
950 dst
[i
*4+3] = FLOAT_TO_SHORT(alpha
[i
]);
954 dst
[i
*4+0] = FLOAT_TO_SHORT(alpha
[i
]);
955 dst
[i
*4+1] = FLOAT_TO_SHORT(blue
[i
]);
956 dst
[i
*4+2] = FLOAT_TO_SHORT(green
[i
]);
957 dst
[i
*4+3] = FLOAT_TO_SHORT(red
[i
]);
961 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
963 if (packing
->SwapBytes
) {
964 _mesa_swap2( (GLushort
*) dst
, n
* comps
);
968 case GL_UNSIGNED_INT
:
970 GLuint
*dst
= (GLuint
*) destination
;
974 dst
[i
] = FLOAT_TO_UINT(red
[i
]);
978 dst
[i
] = FLOAT_TO_UINT(green
[i
]);
982 dst
[i
] = FLOAT_TO_UINT(blue
[i
]);
986 dst
[i
] = FLOAT_TO_UINT(alpha
[i
]);
990 dst
[i
] = FLOAT_TO_UINT(luminance
[i
]);
992 case GL_LUMINANCE_ALPHA
:
994 dst
[i
*2+0] = FLOAT_TO_UINT(luminance
[i
]);
995 dst
[i
*2+1] = FLOAT_TO_UINT(alpha
[i
]);
1000 dst
[i
*3+0] = FLOAT_TO_UINT(red
[i
]);
1001 dst
[i
*3+1] = FLOAT_TO_UINT(green
[i
]);
1002 dst
[i
*3+2] = FLOAT_TO_UINT(blue
[i
]);
1007 dst
[i
*4+0] = FLOAT_TO_UINT(red
[i
]);
1008 dst
[i
*4+1] = FLOAT_TO_UINT(green
[i
]);
1009 dst
[i
*4+2] = FLOAT_TO_UINT(blue
[i
]);
1010 dst
[i
*4+3] = FLOAT_TO_UINT(alpha
[i
]);
1015 dst
[i
*3+0] = FLOAT_TO_UINT(blue
[i
]);
1016 dst
[i
*3+1] = FLOAT_TO_UINT(green
[i
]);
1017 dst
[i
*3+2] = FLOAT_TO_UINT(red
[i
]);
1022 dst
[i
*4+0] = FLOAT_TO_UINT(blue
[i
]);
1023 dst
[i
*4+1] = FLOAT_TO_UINT(green
[i
]);
1024 dst
[i
*4+2] = FLOAT_TO_UINT(red
[i
]);
1025 dst
[i
*4+3] = FLOAT_TO_UINT(alpha
[i
]);
1030 dst
[i
*4+0] = FLOAT_TO_UINT(alpha
[i
]);
1031 dst
[i
*4+1] = FLOAT_TO_UINT(blue
[i
]);
1032 dst
[i
*4+2] = FLOAT_TO_UINT(green
[i
]);
1033 dst
[i
*4+3] = FLOAT_TO_UINT(red
[i
]);
1037 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1039 if (packing
->SwapBytes
) {
1040 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1046 GLint
*dst
= (GLint
*) destination
;
1050 dst
[i
] = FLOAT_TO_INT(red
[i
]);
1054 dst
[i
] = FLOAT_TO_INT(green
[i
]);
1058 dst
[i
] = FLOAT_TO_INT(blue
[i
]);
1062 dst
[i
] = FLOAT_TO_INT(alpha
[i
]);
1066 dst
[i
] = FLOAT_TO_INT(luminance
[i
]);
1068 case GL_LUMINANCE_ALPHA
:
1070 dst
[i
*2+0] = FLOAT_TO_INT(luminance
[i
]);
1071 dst
[i
*2+1] = FLOAT_TO_INT(alpha
[i
]);
1076 dst
[i
*3+0] = FLOAT_TO_INT(red
[i
]);
1077 dst
[i
*3+1] = FLOAT_TO_INT(green
[i
]);
1078 dst
[i
*3+2] = FLOAT_TO_INT(blue
[i
]);
1083 dst
[i
*4+0] = FLOAT_TO_INT(red
[i
]);
1084 dst
[i
*4+1] = FLOAT_TO_INT(green
[i
]);
1085 dst
[i
*4+2] = FLOAT_TO_INT(blue
[i
]);
1086 dst
[i
*4+3] = FLOAT_TO_INT(alpha
[i
]);
1091 dst
[i
*3+0] = FLOAT_TO_INT(blue
[i
]);
1092 dst
[i
*3+1] = FLOAT_TO_INT(green
[i
]);
1093 dst
[i
*3+2] = FLOAT_TO_INT(red
[i
]);
1098 dst
[i
*4+0] = FLOAT_TO_INT(blue
[i
]);
1099 dst
[i
*4+1] = FLOAT_TO_INT(green
[i
]);
1100 dst
[i
*4+2] = FLOAT_TO_INT(red
[i
]);
1101 dst
[i
*4+3] = FLOAT_TO_INT(alpha
[i
]);
1106 dst
[i
*4+0] = FLOAT_TO_INT(alpha
[i
]);
1107 dst
[i
*4+1] = FLOAT_TO_INT(blue
[i
]);
1108 dst
[i
*4+2] = FLOAT_TO_INT(green
[i
]);
1109 dst
[i
*4+3] = FLOAT_TO_INT(red
[i
]);
1113 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1115 if (packing
->SwapBytes
) {
1116 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1122 GLfloat
*dst
= (GLfloat
*) destination
;
1142 dst
[i
] = luminance
[i
];
1144 case GL_LUMINANCE_ALPHA
:
1146 dst
[i
*2+0] = luminance
[i
];
1147 dst
[i
*2+1] = alpha
[i
];
1152 dst
[i
*3+0] = red
[i
];
1153 dst
[i
*3+1] = green
[i
];
1154 dst
[i
*3+2] = blue
[i
];
1159 dst
[i
*4+0] = red
[i
];
1160 dst
[i
*4+1] = green
[i
];
1161 dst
[i
*4+2] = blue
[i
];
1162 dst
[i
*4+3] = alpha
[i
];
1167 dst
[i
*3+0] = blue
[i
];
1168 dst
[i
*3+1] = green
[i
];
1169 dst
[i
*3+2] = red
[i
];
1174 dst
[i
*4+0] = blue
[i
];
1175 dst
[i
*4+1] = green
[i
];
1176 dst
[i
*4+2] = red
[i
];
1177 dst
[i
*4+3] = alpha
[i
];
1182 dst
[i
*4+0] = alpha
[i
];
1183 dst
[i
*4+1] = blue
[i
];
1184 dst
[i
*4+2] = green
[i
];
1185 dst
[i
*4+3] = red
[i
];
1189 gl_problem(ctx
, "bad format in _mesa_pack_rgba_span\n");
1191 if (packing
->SwapBytes
) {
1192 _mesa_swap4( (GLuint
*) dst
, n
* comps
);
1196 case GL_UNSIGNED_BYTE_3_3_2
:
1197 if (format
== GL_RGB
) {
1198 GLubyte
*dst
= (GLubyte
*) destination
;
1200 dst
[i
] = (((GLint
) (red
[i
] * 7.0F
)) << 5)
1201 | (((GLint
) (green
[i
] * 7.0F
)) << 2)
1202 | (((GLint
) (blue
[i
] * 3.0F
)) );
1206 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1207 if (format
== GL_RGB
) {
1208 GLubyte
*dst
= (GLubyte
*) destination
;
1210 dst
[i
] = (((GLint
) (red
[i
] * 7.0F
)) )
1211 | (((GLint
) (green
[i
] * 7.0F
)) << 3)
1212 | (((GLint
) (blue
[i
] * 3.0F
)) << 5);
1216 case GL_UNSIGNED_SHORT_5_6_5
:
1217 if (format
== GL_RGB
) {
1218 GLushort
*dst
= (GLushort
*) destination
;
1220 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) << 11)
1221 | (((GLint
) (green
[i
] * 63.0F
)) << 5)
1222 | (((GLint
) (blue
[i
] * 31.0F
)) );
1226 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1227 if (format
== GL_RGB
) {
1228 GLushort
*dst
= (GLushort
*) destination
;
1230 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) )
1231 | (((GLint
) (green
[i
] * 63.0F
)) << 5)
1232 | (((GLint
) (blue
[i
] * 31.0F
)) << 11);
1236 case GL_UNSIGNED_SHORT_4_4_4_4
:
1237 if (format
== GL_RGB
) {
1238 GLushort
*dst
= (GLushort
*) destination
;
1240 dst
[i
] = (((GLint
) (red
[i
] * 15.0F
)) << 12)
1241 | (((GLint
) (green
[i
] * 15.0F
)) << 8)
1242 | (((GLint
) (blue
[i
] * 15.0F
)) << 4)
1243 | (((GLint
) (alpha
[i
] * 15.0F
)) );
1247 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1248 if (format
== GL_RGB
) {
1249 GLushort
*dst
= (GLushort
*) destination
;
1251 dst
[i
] = (((GLint
) (red
[i
] * 15.0F
)) )
1252 | (((GLint
) (green
[i
] * 15.0F
)) << 4)
1253 | (((GLint
) (blue
[i
] * 15.0F
)) << 8)
1254 | (((GLint
) (alpha
[i
] * 15.0F
)) << 12);
1258 case GL_UNSIGNED_SHORT_5_5_5_1
:
1259 if (format
== GL_RGB
) {
1260 GLushort
*dst
= (GLushort
*) destination
;
1262 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) << 11)
1263 | (((GLint
) (green
[i
] * 31.0F
)) << 6)
1264 | (((GLint
) (blue
[i
] * 31.0F
)) << 1)
1265 | (((GLint
) (alpha
[i
] * 1.0F
)) );
1269 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1270 if (format
== GL_RGB
) {
1271 GLushort
*dst
= (GLushort
*) destination
;
1273 dst
[i
] = (((GLint
) (red
[i
] * 31.0F
)) )
1274 | (((GLint
) (green
[i
] * 31.0F
)) << 5)
1275 | (((GLint
) (blue
[i
] * 31.0F
)) << 10)
1276 | (((GLint
) (alpha
[i
] * 1.0F
)) << 15);
1280 case GL_UNSIGNED_INT_8_8_8_8
:
1281 if (format
== GL_RGBA
) {
1282 GLuint
*dst
= (GLuint
*) destination
;
1284 dst
[i
] = (((GLuint
) (red
[i
] * 255.0F
)) << 24)
1285 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
1286 | (((GLuint
) (blue
[i
] * 255.0F
)) << 8)
1287 | (((GLuint
) (alpha
[i
] * 255.0F
)) );
1290 else if (format
== GL_BGRA
) {
1291 GLuint
*dst
= (GLuint
*) destination
;
1293 dst
[i
] = (((GLuint
) (blue
[i
] * 255.0F
)) << 24)
1294 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
1295 | (((GLuint
) (red
[i
] * 255.0F
)) << 8)
1296 | (((GLuint
) (alpha
[i
] * 255.0F
)) );
1299 else if (format
== GL_ABGR_EXT
) {
1300 GLuint
*dst
= (GLuint
*) destination
;
1302 dst
[i
] = (((GLuint
) (alpha
[i
] * 255.0F
)) << 24)
1303 | (((GLuint
) (blue
[i
] * 255.0F
)) << 16)
1304 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
1305 | (((GLuint
) (red
[i
] * 255.0F
)) );
1309 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1310 if (format
== GL_RGBA
) {
1311 GLuint
*dst
= (GLuint
*) destination
;
1313 dst
[i
] = (((GLuint
) (red
[i
] * 255.0F
)) )
1314 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
1315 | (((GLuint
) (blue
[i
] * 255.0F
)) << 16)
1316 | (((GLuint
) (alpha
[i
] * 255.0F
)) << 24);
1319 else if (format
== GL_BGRA
) {
1320 GLuint
*dst
= (GLuint
*) destination
;
1322 dst
[i
] = (((GLuint
) (blue
[i
] * 255.0F
)) )
1323 | (((GLuint
) (green
[i
] * 255.0F
)) << 8)
1324 | (((GLuint
) (red
[i
] * 255.0F
)) << 16)
1325 | (((GLuint
) (alpha
[i
] * 255.0F
)) << 24);
1328 else if (format
== GL_ABGR_EXT
) {
1329 GLuint
*dst
= (GLuint
*) destination
;
1331 dst
[i
] = (((GLuint
) (alpha
[i
] * 255.0F
)) )
1332 | (((GLuint
) (blue
[i
] * 255.0F
)) << 8)
1333 | (((GLuint
) (green
[i
] * 255.0F
)) << 16)
1334 | (((GLuint
) (red
[i
] * 255.0F
)) << 24);
1338 case GL_UNSIGNED_INT_10_10_10_2
:
1339 if (format
== GL_RGBA
) {
1340 GLuint
*dst
= (GLuint
*) destination
;
1342 dst
[i
] = (((GLuint
) (red
[i
] * 1023.0F
)) << 22)
1343 | (((GLuint
) (green
[i
] * 1023.0F
)) << 12)
1344 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 2)
1345 | (((GLuint
) (alpha
[i
] * 3.0F
)) );
1348 else if (format
== GL_BGRA
) {
1349 GLuint
*dst
= (GLuint
*) destination
;
1351 dst
[i
] = (((GLuint
) (blue
[i
] * 1023.0F
)) << 22)
1352 | (((GLuint
) (green
[i
] * 1023.0F
)) << 12)
1353 | (((GLuint
) (red
[i
] * 1023.0F
)) << 2)
1354 | (((GLuint
) (alpha
[i
] * 3.0F
)) );
1357 else if (format
== GL_ABGR_EXT
) {
1358 GLuint
*dst
= (GLuint
*) destination
;
1360 dst
[i
] = (((GLuint
) (alpha
[i
] * 1023.0F
)) << 22)
1361 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 12)
1362 | (((GLuint
) (green
[i
] * 1023.0F
)) << 2)
1363 | (((GLuint
) (red
[i
] * 3.0F
)) );
1367 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1368 if (format
== GL_RGBA
) {
1369 GLuint
*dst
= (GLuint
*) destination
;
1371 dst
[i
] = (((GLuint
) (red
[i
] * 1023.0F
)) )
1372 | (((GLuint
) (green
[i
] * 1023.0F
)) << 10)
1373 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 20)
1374 | (((GLuint
) (alpha
[i
] * 3.0F
)) << 30);
1377 else if (format
== GL_BGRA
) {
1378 GLuint
*dst
= (GLuint
*) destination
;
1380 dst
[i
] = (((GLuint
) (blue
[i
] * 1023.0F
)) )
1381 | (((GLuint
) (green
[i
] * 1023.0F
)) << 10)
1382 | (((GLuint
) (red
[i
] * 1023.0F
)) << 20)
1383 | (((GLuint
) (alpha
[i
] * 3.0F
)) << 30);
1386 else if (format
== GL_ABGR_EXT
) {
1387 GLuint
*dst
= (GLuint
*) destination
;
1389 dst
[i
] = (((GLuint
) (alpha
[i
] * 1023.0F
)) )
1390 | (((GLuint
) (blue
[i
] * 1023.0F
)) << 10)
1391 | (((GLuint
) (green
[i
] * 1023.0F
)) << 20)
1392 | (((GLuint
) (red
[i
] * 3.0F
)) << 30);
1397 gl_problem( ctx
, "bad type in _mesa_pack_rgba_span" );
1403 #define SWAP2BYTE(VALUE) \
1405 GLubyte *bytes = (GLubyte *) &(VALUE); \
1406 GLubyte tmp = bytes[0]; \
1407 bytes[0] = bytes[1]; \
1411 #define SWAP4BYTE(VALUE) \
1413 GLubyte *bytes = (GLubyte *) &(VALUE); \
1414 GLubyte tmp = bytes[0]; \
1415 bytes[0] = bytes[3]; \
1418 bytes[1] = bytes[2]; \
1424 extract_uint_indexes(GLuint n
, GLuint indexes
[],
1425 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
1426 const struct gl_pixelstore_attrib
*unpack
)
1428 assert(srcFormat
== GL_COLOR_INDEX
);
1430 ASSERT(srcType
== GL_BITMAP
||
1431 srcType
== GL_UNSIGNED_BYTE
||
1432 srcType
== GL_BYTE
||
1433 srcType
== GL_UNSIGNED_SHORT
||
1434 srcType
== GL_SHORT
||
1435 srcType
== GL_UNSIGNED_INT
||
1436 srcType
== GL_INT
||
1437 srcType
== GL_FLOAT
);
1442 GLubyte
*ubsrc
= (GLubyte
*) src
;
1443 if (unpack
->LsbFirst
) {
1444 GLubyte mask
= 1 << (unpack
->SkipPixels
& 0x7);
1446 for (i
= 0; i
< n
; i
++) {
1447 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
1458 GLubyte mask
= 128 >> (unpack
->SkipPixels
& 0x7);
1460 for (i
= 0; i
< n
; i
++) {
1461 indexes
[i
] = (*ubsrc
& mask
) ? 1 : 0;
1473 case GL_UNSIGNED_BYTE
:
1476 const GLubyte
*s
= (const GLubyte
*) src
;
1477 for (i
= 0; i
< n
; i
++)
1484 const GLbyte
*s
= (const GLbyte
*) src
;
1485 for (i
= 0; i
< n
; i
++)
1489 case GL_UNSIGNED_SHORT
:
1492 const GLushort
*s
= (const GLushort
*) src
;
1493 if (unpack
->SwapBytes
) {
1494 for (i
= 0; i
< n
; i
++) {
1495 GLushort value
= s
[i
];
1501 for (i
= 0; i
< n
; i
++)
1509 const GLshort
*s
= (const GLshort
*) src
;
1510 if (unpack
->SwapBytes
) {
1511 for (i
= 0; i
< n
; i
++) {
1512 GLshort value
= s
[i
];
1518 for (i
= 0; i
< n
; i
++)
1523 case GL_UNSIGNED_INT
:
1526 const GLuint
*s
= (const GLuint
*) src
;
1527 if (unpack
->SwapBytes
) {
1528 for (i
= 0; i
< n
; i
++) {
1529 GLuint value
= s
[i
];
1535 for (i
= 0; i
< n
; i
++)
1543 const GLint
*s
= (const GLint
*) src
;
1544 if (unpack
->SwapBytes
) {
1545 for (i
= 0; i
< n
; i
++) {
1552 for (i
= 0; i
< n
; i
++)
1560 const GLfloat
*s
= (const GLfloat
*) src
;
1561 if (unpack
->SwapBytes
) {
1562 for (i
= 0; i
< n
; i
++) {
1563 GLfloat value
= s
[i
];
1565 indexes
[i
] = (GLuint
) value
;
1569 for (i
= 0; i
< n
; i
++)
1570 indexes
[i
] = (GLuint
) s
[i
];
1575 gl_problem(NULL
, "bad srcType in extract_uint_indexes");
1583 * This function extracts floating point RGBA values from arbitrary
1584 * image data. srcFormat and srcType are the format and type parameters
1585 * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc.
1587 * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function
1588 * implements the "Conversion to floating point", "Conversion to RGB",
1589 * and "Final Expansion to RGBA" operations.
1591 * Args: n - number of pixels
1592 * rgba - output colors
1593 * srcFormat - format of incoming data
1594 * srcType - datatype of incoming data
1595 * src - source data pointer
1596 * swapBytes - perform byteswapping of incoming data?
1599 extract_float_rgba(GLuint n
, GLfloat rgba
[][4],
1600 GLenum srcFormat
, GLenum srcType
, const GLvoid
*src
,
1601 GLboolean swapBytes
)
1603 GLint redIndex
, greenIndex
, blueIndex
, alphaIndex
;
1605 GLint rComp
, bComp
, gComp
, aComp
;
1607 ASSERT(srcFormat
== GL_RED
||
1608 srcFormat
== GL_GREEN
||
1609 srcFormat
== GL_BLUE
||
1610 srcFormat
== GL_ALPHA
||
1611 srcFormat
== GL_LUMINANCE
||
1612 srcFormat
== GL_LUMINANCE_ALPHA
||
1613 srcFormat
== GL_INTENSITY
||
1614 srcFormat
== GL_RGB
||
1615 srcFormat
== GL_BGR
||
1616 srcFormat
== GL_RGBA
||
1617 srcFormat
== GL_BGRA
||
1618 srcFormat
== GL_ABGR_EXT
);
1620 ASSERT(srcType
== GL_UNSIGNED_BYTE
||
1621 srcType
== GL_BYTE
||
1622 srcType
== GL_UNSIGNED_SHORT
||
1623 srcType
== GL_SHORT
||
1624 srcType
== GL_UNSIGNED_INT
||
1625 srcType
== GL_INT
||
1626 srcType
== GL_FLOAT
||
1627 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
1628 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
1629 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
1630 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
1631 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
1632 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
1633 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
1634 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
1635 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1636 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
1637 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
1638 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1640 rComp
= gComp
= bComp
= aComp
= -1;
1642 switch (srcFormat
) {
1645 greenIndex
= blueIndex
= alphaIndex
= -1;
1650 redIndex
= blueIndex
= alphaIndex
= -1;
1655 redIndex
= greenIndex
= alphaIndex
= -1;
1659 redIndex
= greenIndex
= blueIndex
= -1;
1664 redIndex
= greenIndex
= blueIndex
= 0;
1668 case GL_LUMINANCE_ALPHA
:
1669 redIndex
= greenIndex
= blueIndex
= 0;
1675 greenIndex
= blueIndex
= alphaIndex
= -1;
1726 gl_problem(NULL
, "bad srcFormat in extract float data");
1731 #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \
1732 if ((INDEX) < 0) { \
1734 for (i = 0; i < n; i++) { \
1735 rgba[i][CHANNEL] = DEFAULT; \
1738 else if (swapBytes) { \
1739 const TYPE *s = (const TYPE *) src; \
1741 for (i = 0; i < n; i++) { \
1742 TYPE value = s[INDEX]; \
1743 if (sizeof(TYPE) == 2) { \
1746 else if (sizeof(TYPE) == 4) { \
1749 rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \
1754 const TYPE *s = (const TYPE *) src; \
1756 for (i = 0; i < n; i++) { \
1757 rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \
1763 case GL_UNSIGNED_BYTE
:
1764 PROCESS(redIndex
, RCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1765 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1766 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1767 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLubyte
, UBYTE_TO_FLOAT
);
1770 PROCESS(redIndex
, RCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1771 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1772 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLbyte
, BYTE_TO_FLOAT
);
1773 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLbyte
, BYTE_TO_FLOAT
);
1775 case GL_UNSIGNED_SHORT
:
1776 PROCESS(redIndex
, RCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1777 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1778 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLushort
, USHORT_TO_FLOAT
);
1779 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLushort
, USHORT_TO_FLOAT
);
1782 PROCESS(redIndex
, RCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1783 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1784 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLshort
, SHORT_TO_FLOAT
);
1785 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLshort
, SHORT_TO_FLOAT
);
1787 case GL_UNSIGNED_INT
:
1788 PROCESS(redIndex
, RCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1789 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1790 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLuint
, UINT_TO_FLOAT
);
1791 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLuint
, UINT_TO_FLOAT
);
1794 PROCESS(redIndex
, RCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1795 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1796 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLint
, INT_TO_FLOAT
);
1797 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLint
, INT_TO_FLOAT
);
1800 PROCESS(redIndex
, RCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1801 PROCESS(greenIndex
, GCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1802 PROCESS(blueIndex
, BCOMP
, 0.0F
, GLfloat
, (GLfloat
));
1803 PROCESS(alphaIndex
, ACOMP
, 1.0F
, GLfloat
, (GLfloat
));
1805 case GL_UNSIGNED_BYTE_3_3_2
:
1807 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
1809 for (i
= 0; i
< n
; i
++) {
1810 GLubyte p
= ubsrc
[i
];
1811 rgba
[i
][RCOMP
] = ((p
>> 5) ) * (1.0F
/ 7.0F
);
1812 rgba
[i
][GCOMP
] = ((p
>> 2) & 0x7) * (1.0F
/ 7.0F
);
1813 rgba
[i
][BCOMP
] = ((p
) & 0x3) * (1.0F
/ 3.0F
);
1814 rgba
[i
][ACOMP
] = 1.0F
;
1818 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1820 const GLubyte
*ubsrc
= (const GLubyte
*) src
;
1822 for (i
= 0; i
< n
; i
++) {
1823 GLubyte p
= ubsrc
[i
];
1824 rgba
[i
][RCOMP
] = ((p
) & 0x7) * (1.0F
/ 7.0F
);
1825 rgba
[i
][GCOMP
] = ((p
>> 3) & 0x7) * (1.0F
/ 7.0F
);
1826 rgba
[i
][BCOMP
] = ((p
>> 6) ) * (1.0F
/ 3.0F
);
1827 rgba
[i
][ACOMP
] = 1.0F
;
1831 case GL_UNSIGNED_SHORT_5_6_5
:
1833 const GLushort
*ussrc
= (const GLushort
*) src
;
1835 for (i
= 0; i
< n
; i
++) {
1836 GLushort p
= ussrc
[i
];
1838 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1839 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1840 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1841 rgba
[i
][ACOMP
] = 1.0F
;
1845 const GLushort
*ussrc
= (const GLushort
*) src
;
1847 for (i
= 0; i
< n
; i
++) {
1848 GLushort p
= ussrc
[i
];
1849 rgba
[i
][RCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1850 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1851 rgba
[i
][BCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1852 rgba
[i
][ACOMP
] = 1.0F
;
1856 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1858 const GLushort
*ussrc
= (const GLushort
*) src
;
1860 for (i
= 0; i
< n
; i
++) {
1861 GLushort p
= ussrc
[i
];
1863 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1864 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1865 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1866 rgba
[i
][ACOMP
] = 1.0F
;
1870 const GLushort
*ussrc
= (const GLushort
*) src
;
1872 for (i
= 0; i
< n
; i
++) {
1873 GLushort p
= ussrc
[i
];
1874 rgba
[i
][RCOMP
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1875 rgba
[i
][GCOMP
] = ((p
>> 5) & 0x3f) * (1.0F
/ 63.0F
);
1876 rgba
[i
][BCOMP
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1877 rgba
[i
][ACOMP
] = 1.0F
;
1881 case GL_UNSIGNED_SHORT_4_4_4_4
:
1883 const GLushort
*ussrc
= (const GLushort
*) src
;
1885 for (i
= 0; i
< n
; i
++) {
1886 GLushort p
= ussrc
[i
];
1888 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1889 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1890 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1891 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1895 const GLushort
*ussrc
= (const GLushort
*) src
;
1897 for (i
= 0; i
< n
; i
++) {
1898 GLushort p
= ussrc
[i
];
1899 rgba
[i
][rComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1900 rgba
[i
][gComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1901 rgba
[i
][bComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1902 rgba
[i
][aComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1906 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1908 const GLushort
*ussrc
= (const GLushort
*) src
;
1910 for (i
= 0; i
< n
; i
++) {
1911 GLushort p
= ussrc
[i
];
1913 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1914 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1915 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1916 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1920 const GLushort
*ussrc
= (const GLushort
*) src
;
1922 for (i
= 0; i
< n
; i
++) {
1923 GLushort p
= ussrc
[i
];
1924 rgba
[i
][rComp
] = ((p
) & 0xf) * (1.0F
/ 15.0F
);
1925 rgba
[i
][gComp
] = ((p
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1926 rgba
[i
][bComp
] = ((p
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1927 rgba
[i
][aComp
] = ((p
>> 12) ) * (1.0F
/ 15.0F
);
1931 case GL_UNSIGNED_SHORT_5_5_5_1
:
1933 const GLushort
*ussrc
= (const GLushort
*) src
;
1935 for (i
= 0; i
< n
; i
++) {
1936 GLushort p
= ussrc
[i
];
1938 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1939 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
1940 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
1941 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
1945 const GLushort
*ussrc
= (const GLushort
*) src
;
1947 for (i
= 0; i
< n
; i
++) {
1948 GLushort p
= ussrc
[i
];
1949 rgba
[i
][rComp
] = ((p
>> 11) ) * (1.0F
/ 31.0F
);
1950 rgba
[i
][gComp
] = ((p
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
1951 rgba
[i
][bComp
] = ((p
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
1952 rgba
[i
][aComp
] = ((p
) & 0x1) * (1.0F
/ 1.0F
);
1956 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1958 const GLushort
*ussrc
= (const GLushort
*) src
;
1960 for (i
= 0; i
< n
; i
++) {
1961 GLushort p
= ussrc
[i
];
1963 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1964 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
1965 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
1966 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
1970 const GLushort
*ussrc
= (const GLushort
*) src
;
1972 for (i
= 0; i
< n
; i
++) {
1973 GLushort p
= ussrc
[i
];
1974 rgba
[i
][rComp
] = ((p
) & 0x1f) * (1.0F
/ 31.0F
);
1975 rgba
[i
][gComp
] = ((p
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
1976 rgba
[i
][bComp
] = ((p
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
1977 rgba
[i
][aComp
] = ((p
>> 15) ) * (1.0F
/ 1.0F
);
1981 case GL_UNSIGNED_INT_8_8_8_8
:
1983 const GLuint
*uisrc
= (const GLuint
*) src
;
1985 for (i
= 0; i
< n
; i
++) {
1986 GLuint p
= uisrc
[i
];
1987 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
1988 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
1989 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
1990 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
1994 const GLuint
*uisrc
= (const GLuint
*) src
;
1996 for (i
= 0; i
< n
; i
++) {
1997 GLuint p
= uisrc
[i
];
1998 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
1999 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2000 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2001 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2005 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2007 const GLuint
*uisrc
= (const GLuint
*) src
;
2009 for (i
= 0; i
< n
; i
++) {
2010 GLuint p
= uisrc
[i
];
2011 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2012 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2013 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2014 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2018 const GLuint
*uisrc
= (const GLuint
*) src
;
2020 for (i
= 0; i
< n
; i
++) {
2021 GLuint p
= uisrc
[i
];
2022 rgba
[i
][rComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
) & 0xff);
2023 rgba
[i
][gComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 8) & 0xff);
2024 rgba
[i
][bComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 16) & 0xff);
2025 rgba
[i
][aComp
] = UBYTE_COLOR_TO_FLOAT_COLOR((p
>> 24) );
2029 case GL_UNSIGNED_INT_10_10_10_2
:
2031 const GLuint
*uisrc
= (const GLuint
*) src
;
2033 for (i
= 0; i
< n
; i
++) {
2034 GLuint p
= uisrc
[i
];
2036 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2037 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2038 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2039 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2043 const GLuint
*uisrc
= (const GLuint
*) src
;
2045 for (i
= 0; i
< n
; i
++) {
2046 GLuint p
= uisrc
[i
];
2047 rgba
[i
][rComp
] = ((p
>> 22) ) * (1.0F
/ 1023.0F
);
2048 rgba
[i
][gComp
] = ((p
>> 12) & 0x3ff) * (1.0F
/ 1023.0F
);
2049 rgba
[i
][bComp
] = ((p
>> 2) & 0x3ff) * (1.0F
/ 1023.0F
);
2050 rgba
[i
][aComp
] = ((p
) & 0x3 ) * (1.0F
/ 3.0F
);
2054 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2056 const GLuint
*uisrc
= (const GLuint
*) src
;
2058 for (i
= 0; i
< n
; i
++) {
2059 GLuint p
= uisrc
[i
];
2061 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2062 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2063 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2064 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2068 const GLuint
*uisrc
= (const GLuint
*) src
;
2070 for (i
= 0; i
< n
; i
++) {
2071 GLuint p
= uisrc
[i
];
2072 rgba
[i
][rComp
] = ((p
) & 0x3ff) * (1.0F
/ 1023.0F
);
2073 rgba
[i
][gComp
] = ((p
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
2074 rgba
[i
][bComp
] = ((p
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
2075 rgba
[i
][aComp
] = ((p
>> 30) ) * (1.0F
/ 3.0F
);
2080 gl_problem(NULL
, "bad srcType in extract float data");
2088 * Unpack a row of color image data from a client buffer according to
2089 * the pixel unpacking parameters. Apply any enabled pixel transfer
2090 * ops (PixelMap, scale/bias) if the applyTransferOps flag is enabled.
2091 * Return GLubyte values in the specified dest image format.
2092 * This is (or will be) used by glDrawPixels and glTexImage?D().
2093 * Input: ctx - the context
2094 * n - number of pixels in the span
2095 * dstFormat - format of destination color array
2096 * dest - the destination color array
2097 * srcFormat - source image format
2098 * srcType - source image datatype
2099 * source - source image pointer
2100 * unpacking - pixel unpacking parameters
2101 * applyTransferOps - apply scale/bias/lookup-table ops?
2103 * XXX perhaps expand this to process whole images someday.
2106 _mesa_unpack_ubyte_color_span( const GLcontext
*ctx
,
2107 GLuint n
, GLenum dstFormat
, GLubyte dest
[],
2108 GLenum srcFormat
, GLenum srcType
,
2109 const GLvoid
*source
,
2110 const struct gl_pixelstore_attrib
*unpacking
,
2111 GLboolean applyTransferOps
)
2113 ASSERT(dstFormat
== GL_ALPHA
||
2114 dstFormat
== GL_LUMINANCE
||
2115 dstFormat
== GL_LUMINANCE_ALPHA
||
2116 dstFormat
== GL_INTENSITY
||
2117 dstFormat
== GL_RGB
||
2118 dstFormat
== GL_RGBA
||
2119 dstFormat
== GL_COLOR_INDEX
);
2121 ASSERT(srcFormat
== GL_RED
||
2122 srcFormat
== GL_GREEN
||
2123 srcFormat
== GL_BLUE
||
2124 srcFormat
== GL_ALPHA
||
2125 srcFormat
== GL_LUMINANCE
||
2126 srcFormat
== GL_LUMINANCE_ALPHA
||
2127 srcFormat
== GL_INTENSITY
||
2128 srcFormat
== GL_RGB
||
2129 srcFormat
== GL_BGR
||
2130 srcFormat
== GL_RGBA
||
2131 srcFormat
== GL_BGRA
||
2132 srcFormat
== GL_ABGR_EXT
||
2133 srcFormat
== GL_COLOR_INDEX
);
2135 ASSERT(srcType
== GL_BITMAP
||
2136 srcType
== GL_UNSIGNED_BYTE
||
2137 srcType
== GL_BYTE
||
2138 srcType
== GL_UNSIGNED_SHORT
||
2139 srcType
== GL_SHORT
||
2140 srcType
== GL_UNSIGNED_INT
||
2141 srcType
== GL_INT
||
2142 srcType
== GL_FLOAT
||
2143 srcType
== GL_UNSIGNED_BYTE_3_3_2
||
2144 srcType
== GL_UNSIGNED_BYTE_2_3_3_REV
||
2145 srcType
== GL_UNSIGNED_SHORT_5_6_5
||
2146 srcType
== GL_UNSIGNED_SHORT_5_6_5_REV
||
2147 srcType
== GL_UNSIGNED_SHORT_4_4_4_4
||
2148 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
2149 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
||
2150 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
2151 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
2152 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
||
2153 srcType
== GL_UNSIGNED_INT_10_10_10_2
||
2154 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2156 /* this is intended for RGBA mode */
2157 assert(ctx
->Visual
->RGBAflag
);
2159 applyTransferOps
&= (ctx
->Pixel
.ScaleOrBiasRGBA
||
2160 ctx
->Pixel
.MapColorFlag
||
2161 ctx
->Pixel
.MapColorFlag
);
2163 /* Try simple cases first */
2164 if (!applyTransferOps
&& srcType
== GL_UNSIGNED_BYTE
) {
2165 if (dstFormat
== GL_RGBA
) {
2166 if (srcFormat
== GL_RGBA
) {
2167 MEMCPY( dest
, source
, n
* 4 * sizeof(GLubyte
) );
2170 else if (srcFormat
== GL_RGB
) {
2172 const GLubyte
*src
= (const GLubyte
*) source
;
2173 GLubyte
*dst
= dest
;
2174 for (i
= 0; i
< n
; i
++) {
2185 else if (dstFormat
== GL_RGB
) {
2186 if (srcFormat
== GL_RGB
) {
2187 MEMCPY( dest
, source
, n
* 3 * sizeof(GLubyte
) );
2190 else if (srcFormat
== GL_RGBA
) {
2192 const GLubyte
*src
= (const GLubyte
*) source
;
2193 GLubyte
*dst
= dest
;
2194 for (i
= 0; i
< n
; i
++) {
2204 else if (dstFormat
== srcFormat
) {
2205 GLint comps
= _mesa_components_in_format(srcFormat
);
2207 MEMCPY( dest
, source
, n
* comps
* sizeof(GLubyte
) );
2214 /* general solution */
2215 GLfloat rgba
[MAX_WIDTH
][4];
2216 GLint dstComponents
;
2217 GLint dstRedIndex
, dstGreenIndex
, dstBlueIndex
, dstAlphaIndex
;
2218 GLint dstLuminanceIndex
, dstIntensityIndex
;
2220 dstComponents
= _mesa_components_in_format( dstFormat
);
2221 /* source & dest image formats should have been error checked by now */
2222 assert(dstComponents
> 0);
2225 * Extract image data and convert to RGBA floats
2227 assert(n
<= MAX_WIDTH
);
2228 if (srcFormat
== GL_COLOR_INDEX
) {
2229 GLuint indexes
[MAX_WIDTH
];
2230 extract_uint_indexes(n
, indexes
, srcFormat
, srcType
, source
,
2233 /* shift and offset indexes */
2234 gl_shift_and_offset_ci(ctx
, n
, indexes
);
2236 if (dstFormat
== GL_COLOR_INDEX
) {
2237 if (applyTransferOps
) {
2238 if (ctx
->Pixel
.MapColorFlag
) {
2239 /* Apply lookup table */
2240 gl_map_ci(ctx
, n
, indexes
);
2243 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2248 /* convert to GLubyte and return */
2251 for (i
= 0; i
< n
; i
++) {
2252 dest
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2257 /* Convert indexes to RGBA */
2258 gl_map_ci_to_rgba_float(ctx
, n
, indexes
, rgba
);
2262 extract_float_rgba(n
, rgba
, srcFormat
, srcType
, source
,
2263 unpacking
->SwapBytes
);
2265 if (applyTransferOps
) {
2266 /* scale and bias colors */
2267 gl_scale_and_bias_rgba_float(ctx
, n
, rgba
);
2269 /* color table lookup */
2270 if (ctx
->Pixel
.MapColorFlag
) {
2271 gl_map_rgba_float(ctx
, n
, rgba
);
2278 * XXX This is where more color table lookups, convolution,
2279 * histograms, minmax, color matrix, etc would take place if
2281 * See figure 3.7 in the OpenGL 1.2 specification for more info.
2285 /* clamp to [0,1] */
2288 for (i
= 0; i
< n
; i
++) {
2289 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
2290 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
2291 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
2292 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
2296 /* Now determine which color channels we need to produce.
2297 * And determine the dest index (offset) within each color tuple.
2299 switch (dstFormat
) {
2302 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2303 dstLuminanceIndex
= dstIntensityIndex
= -1;
2306 dstLuminanceIndex
= 0;
2307 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2308 dstIntensityIndex
= -1;
2310 case GL_LUMINANCE_ALPHA
:
2311 dstLuminanceIndex
= 0;
2313 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= -1;
2314 dstIntensityIndex
= -1;
2317 dstIntensityIndex
= 0;
2318 dstRedIndex
= dstGreenIndex
= dstBlueIndex
= dstAlphaIndex
= -1;
2319 dstLuminanceIndex
= -1;
2325 dstAlphaIndex
= dstLuminanceIndex
= dstIntensityIndex
= -1;
2332 dstLuminanceIndex
= dstIntensityIndex
= -1;
2335 gl_problem(ctx
, "bad dstFormat in _mesa_unpack_ubyte_span()");
2340 /* Now return the GLubyte data in the requested dstFormat */
2342 if (dstRedIndex
>= 0) {
2343 GLubyte
*dst
= dest
;
2345 for (i
= 0; i
< n
; i
++) {
2346 dst
[dstRedIndex
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2347 dst
+= dstComponents
;
2351 if (dstGreenIndex
>= 0) {
2352 GLubyte
*dst
= dest
;
2354 for (i
= 0; i
< n
; i
++) {
2355 dst
[dstGreenIndex
] = FLOAT_TO_UBYTE(rgba
[i
][GCOMP
]);
2356 dst
+= dstComponents
;
2360 if (dstBlueIndex
>= 0) {
2361 GLubyte
*dst
= dest
;
2363 for (i
= 0; i
< n
; i
++) {
2364 dst
[dstBlueIndex
] = FLOAT_TO_UBYTE(rgba
[i
][BCOMP
]);
2365 dst
+= dstComponents
;
2369 if (dstAlphaIndex
>= 0) {
2370 GLubyte
*dst
= dest
;
2372 for (i
= 0; i
< n
; i
++) {
2373 dst
[dstAlphaIndex
] = FLOAT_TO_UBYTE(rgba
[i
][ACOMP
]);
2374 dst
+= dstComponents
;
2378 if (dstIntensityIndex
>= 0) {
2379 GLubyte
*dst
= dest
;
2381 assert(dstIntensityIndex
== 0);
2382 assert(dstComponents
== 1);
2383 for (i
= 0; i
< n
; i
++) {
2384 /* Intensity comes from red channel */
2385 dst
[i
] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2389 if (dstLuminanceIndex
>= 0) {
2390 GLubyte
*dst
= dest
;
2392 assert(dstLuminanceIndex
== 0);
2393 for (i
= 0; i
< n
; i
++) {
2394 /* Luminance comes from red channel */
2395 dst
[0] = FLOAT_TO_UBYTE(rgba
[i
][RCOMP
]);
2396 dst
+= dstComponents
;
2405 * Unpack a row of color index data from a client buffer according to
2406 * the pixel unpacking parameters. Apply pixel transfer ops if enabled
2407 * and applyTransferOps is true.
2408 * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
2410 * Args: ctx - the context
2411 * n - number of pixels
2412 * dstType - destination datatype
2413 * dest - destination array
2414 * srcType - source pixel type
2415 * source - source data pointer
2416 * unpacking - pixel unpacking parameters
2417 * applyTransferOps - apply offset/bias/lookup ops?
2420 _mesa_unpack_index_span( const GLcontext
*ctx
, GLuint n
,
2421 GLenum dstType
, GLvoid
*dest
,
2422 GLenum srcType
, const GLvoid
*source
,
2423 const struct gl_pixelstore_attrib
*unpacking
,
2424 GLboolean applyTransferOps
)
2426 ASSERT(srcType
== GL_BITMAP
||
2427 srcType
== GL_UNSIGNED_BYTE
||
2428 srcType
== GL_BYTE
||
2429 srcType
== GL_UNSIGNED_SHORT
||
2430 srcType
== GL_SHORT
||
2431 srcType
== GL_UNSIGNED_INT
||
2432 srcType
== GL_INT
||
2433 srcType
== GL_FLOAT
);
2435 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
2436 dstType
== GL_UNSIGNED_SHORT
||
2437 dstType
== GL_UNSIGNED_INT
);
2439 applyTransferOps
&= (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
|| ctx
->Pixel
.MapColorFlag
);
2442 * Try simple cases first
2444 if (!applyTransferOps
&& srcType
== GL_UNSIGNED_BYTE
2445 && dstType
== GL_UNSIGNED_BYTE
) {
2446 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
2448 else if (!applyTransferOps
&& srcType
== GL_UNSIGNED_INT
2449 && dstType
== GL_UNSIGNED_INT
&& !unpacking
->SwapBytes
) {
2450 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
2456 GLuint indexes
[MAX_WIDTH
];
2457 assert(n
<= MAX_WIDTH
);
2459 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
2462 if (applyTransferOps
) {
2463 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2464 /* shift and offset indexes */
2465 gl_shift_and_offset_ci(ctx
, n
, indexes
);
2468 if (ctx
->Pixel
.MapColorFlag
) {
2469 /* Apply lookup table */
2470 gl_map_ci(ctx
, n
, indexes
);
2474 /* convert to dest type */
2476 case GL_UNSIGNED_BYTE
:
2478 GLubyte
*dst
= (GLubyte
*) dest
;
2480 for (i
= 0; i
< n
; i
++) {
2481 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2485 case GL_UNSIGNED_SHORT
:
2487 GLuint
*dst
= (GLuint
*) dest
;
2489 for (i
= 0; i
< n
; i
++) {
2490 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
2494 case GL_UNSIGNED_INT
:
2495 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
2498 gl_problem(ctx
, "bad dstType in _mesa_unpack_index_span");
2505 * Unpack a row of stencil data from a client buffer according to
2506 * the pixel unpacking parameters. Apply pixel transfer ops if enabled
2507 * and applyTransferOps is true.
2508 * This is (or will be) used by glDrawPixels
2510 * Args: ctx - the context
2511 * n - number of pixels
2512 * dstType - destination datatype
2513 * dest - destination array
2514 * srcType - source pixel type
2515 * source - source data pointer
2516 * unpacking - pixel unpacking parameters
2517 * applyTransferOps - apply offset/bias/lookup ops?
2520 _mesa_unpack_stencil_span( const GLcontext
*ctx
, GLuint n
,
2521 GLenum dstType
, GLvoid
*dest
,
2522 GLenum srcType
, const GLvoid
*source
,
2523 const struct gl_pixelstore_attrib
*unpacking
,
2524 GLboolean applyTransferOps
)
2526 ASSERT(srcType
== GL_BITMAP
||
2527 srcType
== GL_UNSIGNED_BYTE
||
2528 srcType
== GL_BYTE
||
2529 srcType
== GL_UNSIGNED_SHORT
||
2530 srcType
== GL_SHORT
||
2531 srcType
== GL_UNSIGNED_INT
||
2532 srcType
== GL_INT
||
2533 srcType
== GL_FLOAT
);
2535 ASSERT(dstType
== GL_UNSIGNED_BYTE
||
2536 dstType
== GL_UNSIGNED_SHORT
||
2537 dstType
== GL_UNSIGNED_INT
);
2539 applyTransferOps
&= (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
|| ctx
->Pixel
.MapColorFlag
);
2542 * Try simple cases first
2544 if (!applyTransferOps
&& srcType
== GL_UNSIGNED_BYTE
2545 && dstType
== GL_UNSIGNED_BYTE
) {
2546 MEMCPY(dest
, source
, n
* sizeof(GLubyte
));
2548 else if (!applyTransferOps
&& srcType
== GL_UNSIGNED_INT
2549 && dstType
== GL_UNSIGNED_INT
&& !unpacking
->SwapBytes
) {
2550 MEMCPY(dest
, source
, n
* sizeof(GLuint
));
2556 GLuint indexes
[MAX_WIDTH
];
2557 assert(n
<= MAX_WIDTH
);
2559 extract_uint_indexes(n
, indexes
, GL_COLOR_INDEX
, srcType
, source
,
2562 if (applyTransferOps
) {
2563 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
) {
2564 /* shift and offset indexes */
2565 gl_shift_and_offset_ci(ctx
, n
, indexes
);
2568 if (ctx
->Pixel
.MapStencilFlag
) {
2569 /* Apply stencil lookup table */
2570 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
2573 indexes
[i
] = ctx
->Pixel
.MapStoS
[ indexes
[i
] & mask
];
2578 /* convert to dest type */
2580 case GL_UNSIGNED_BYTE
:
2582 GLubyte
*dst
= (GLubyte
*) dest
;
2584 for (i
= 0; i
< n
; i
++) {
2585 dst
[i
] = (GLubyte
) (indexes
[i
] & 0xff);
2589 case GL_UNSIGNED_SHORT
:
2591 GLuint
*dst
= (GLuint
*) dest
;
2593 for (i
= 0; i
< n
; i
++) {
2594 dst
[i
] = (GLushort
) (indexes
[i
] & 0xffff);
2598 case GL_UNSIGNED_INT
:
2599 MEMCPY(dest
, indexes
, n
* sizeof(GLuint
));
2602 gl_problem(ctx
, "bad dstType in _mesa_unpack_stencil_span");
2610 _mesa_unpack_depth_span( const GLcontext
*ctx
, GLuint n
, GLdepth
*dest
,
2611 GLenum srcType
, const GLvoid
*source
,
2612 const struct gl_pixelstore_attrib
*unpacking
,
2613 GLboolean applyTransferOps
)
2615 GLfloat
*depth
= MALLOC(n
* sizeof(GLfloat
));
2623 const GLubyte
*src
= (const GLubyte
*) source
;
2624 for (i
= 0; i
< n
; i
++) {
2625 depth
[i
] = BYTE_TO_FLOAT(src
[i
]);
2629 case GL_UNSIGNED_BYTE
:
2632 const GLubyte
*src
= (const GLubyte
*) source
;
2633 for (i
= 0; i
< n
; i
++) {
2634 depth
[i
] = UBYTE_TO_FLOAT(src
[i
]);
2641 const GLshort
*src
= (const GLshort
*) source
;
2642 for (i
= 0; i
< n
; i
++) {
2643 depth
[i
] = SHORT_TO_FLOAT(src
[i
]);
2647 case GL_UNSIGNED_SHORT
:
2650 const GLushort
*src
= (const GLushort
*) source
;
2651 for (i
= 0; i
< n
; i
++) {
2652 depth
[i
] = USHORT_TO_FLOAT(src
[i
]);
2659 const GLint
*src
= (const GLint
*) source
;
2660 for (i
= 0; i
< n
; i
++) {
2661 depth
[i
] = INT_TO_FLOAT(src
[i
]);
2665 case GL_UNSIGNED_INT
:
2668 const GLuint
*src
= (const GLuint
*) source
;
2669 for (i
= 0; i
< n
; i
++) {
2670 depth
[i
] = UINT_TO_FLOAT(src
[i
]);
2675 MEMCPY(depth
, source
, n
* sizeof(GLfloat
));
2678 gl_problem(NULL
, "bad type in _mesa_unpack_depth_span()");
2683 /* apply depth scale and bias */
2684 if (ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0) {
2686 for (i
= 0; i
< n
; i
++) {
2687 depth
[i
] = depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
2691 /* clamp depth values to [0,1] and convert from floats to integers */
2693 const GLfloat zs
= ctx
->Visual
->DepthMaxF
;
2695 for (i
= 0; i
< n
; i
++) {
2696 dest
[i
] = (GLdepth
) (CLAMP(depth
[i
], 0.0F
, 1.0F
) * zs
);
2706 * Unpack image data. Apply byteswapping, byte flipping (bitmap).
2707 * Return all image data in a contiguous block.
2710 _mesa_unpack_image( GLsizei width
, GLsizei height
, GLsizei depth
,
2711 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2712 const struct gl_pixelstore_attrib
*unpack
)
2714 GLint bytesPerRow
, compsPerRow
;
2715 GLboolean flipBytes
, swap2
, swap4
;
2718 return NULL
; /* not necessarily an error */
2720 if (width
<= 0 || height
<= 0 || depth
<= 0)
2721 return NULL
; /* generate error later */
2723 if (format
== GL_BITMAP
) {
2724 bytesPerRow
= (width
+ 7) >> 3;
2725 flipBytes
= !unpack
->LsbFirst
;
2726 swap2
= swap4
= GL_FALSE
;
2730 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
2731 const GLint components
= _mesa_components_in_format(format
);
2733 if (bytesPerPixel
<= 0 || components
<= 0)
2734 return NULL
; /* bad format or type. generate error later */
2735 bytesPerRow
= bytesPerPixel
* width
;
2736 bytesPerComp
= bytesPerPixel
/ components
;
2737 flipBytes
= GL_FALSE
;
2738 swap2
= (bytesPerComp
== 2) && unpack
->SwapBytes
;
2739 swap4
= (bytesPerComp
== 4) && unpack
->SwapBytes
;
2740 compsPerRow
= components
* width
;
2741 assert(compsPerRow
>= width
);
2745 GLubyte
*destBuffer
= MALLOC(bytesPerRow
* height
* depth
);
2749 return NULL
; /* generate GL_OUT_OF_MEMORY later */
2752 for (img
= 0; img
< depth
; img
++) {
2753 for (row
= 0; row
< height
; row
++) {
2754 const GLvoid
*src
= _mesa_image_address(unpack
, pixels
,
2755 width
, height
, format
, type
, img
, row
, 0);
2756 MEMCPY(dst
, src
, bytesPerRow
);
2757 /* byte flipping/swapping */
2759 flip_bytes((GLubyte
*) dst
, bytesPerRow
);
2762 _mesa_swap2((GLushort
*) dst
, compsPerRow
);
2765 _mesa_swap4((GLuint
*) dst
, compsPerRow
);
2776 * Unpack bitmap data. Resulting data will be in most-significant-bit-first
2777 * order with row alignment = 1 byte.
2780 _mesa_unpack_bitmap( GLint width
, GLint height
, const GLubyte
*pixels
,
2781 const struct gl_pixelstore_attrib
*packing
)
2783 GLint bytes
, row
, width_in_bytes
;
2784 GLubyte
*buffer
, *dst
;
2789 /* Alloc dest storage */
2790 bytes
= ((width
+ 7) / 8 * height
);
2791 buffer
= (GLubyte
*) MALLOC( bytes
);
2796 width_in_bytes
= CEILING( width
, 8 );
2798 for (row
= 0; row
< height
; row
++) {
2799 GLubyte
*src
= _mesa_image_address( packing
, pixels
, width
, height
,
2800 GL_COLOR_INDEX
, GL_BITMAP
,
2807 if (packing
->SkipPixels
== 0) {
2808 MEMCPY( dst
, src
, width_in_bytes
);
2809 if (packing
->LsbFirst
) {
2810 flip_bytes( dst
, width_in_bytes
);
2814 /* handling SkipPixels is a bit tricky (no pun intended!) */
2816 if (packing
->LsbFirst
) {
2817 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
2818 GLubyte dstMask
= 128;
2822 for (i
= 0; i
< width
; i
++) {
2826 if (srcMask
== 128) {
2831 srcMask
= srcMask
<< 1;
2839 dstMask
= dstMask
>> 1;
2844 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
2845 GLubyte dstMask
= 128;
2849 for (i
= 0; i
< width
; i
++) {
2858 srcMask
= srcMask
>> 1;
2866 dstMask
= dstMask
>> 1;
2871 dst
+= width_in_bytes
;
2882 _mesa_pack_bitmap( GLint width
, GLint height
, const GLubyte
*source
,
2883 GLubyte
*dest
, const struct gl_pixelstore_attrib
*packing
)
2885 GLint row
, width_in_bytes
;
2891 width_in_bytes
= CEILING( width
, 8 );
2893 for (row
= 0; row
< height
; row
++) {
2894 GLubyte
*dst
= _mesa_image_address( packing
, dest
, width
, height
,
2895 GL_COLOR_INDEX
, GL_BITMAP
,
2900 if (packing
->SkipPixels
== 0) {
2901 MEMCPY( dst
, src
, width_in_bytes
);
2902 if (packing
->LsbFirst
) {
2903 flip_bytes( dst
, width_in_bytes
);
2907 /* handling SkipPixels is a bit tricky (no pun intended!) */
2909 if (packing
->LsbFirst
) {
2910 GLubyte srcMask
= 1 << (packing
->SkipPixels
& 0x7);
2911 GLubyte dstMask
= 128;
2912 const GLubyte
*s
= src
;
2915 for (i
= 0; i
< width
; i
++) {
2919 if (srcMask
== 128) {
2924 srcMask
= srcMask
<< 1;
2932 dstMask
= dstMask
>> 1;
2937 GLubyte srcMask
= 128 >> (packing
->SkipPixels
& 0x7);
2938 GLubyte dstMask
= 128;
2939 const GLubyte
*s
= src
;
2942 for (i
= 0; i
< width
; i
++) {
2951 srcMask
= srcMask
>> 1;
2959 dstMask
= dstMask
>> 1;
2964 src
+= width_in_bytes
;